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
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> int -> int -> int -> (int * string) -> int =
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
115 if platform = Pcygwin
117 let sh = "/bin/sh" in
118 let args = [|sh; "-c"; cmd
|] in
119 let rec std si so se
= function
121 | (fd
, 0) :: rest
-> std fd so se rest
122 | (fd
, -1) :: rest
->
123 Unix.set_close_on_exec fd
;
126 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
128 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
129 ignore
(Unix.create_process
sh args si so se
)
138 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
141 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
143 type mpos
= int * int
145 | Msel
of (mpos
* mpos
)
147 | Mscrolly
| Mscrollx
148 | Mzoom
of (int * int)
149 | Mzoomrect
of (mpos
* mpos
)
153 type textentry
= string * string * onhist
option * onkey
* ondone
154 and onkey
= string -> int -> te
155 and ondone
= string -> unit
156 and histcancel
= unit -> unit
157 and onhist
= ((histcmd
-> string) * histcancel
)
158 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
163 | TEswitch
of textentry
174 let bound v minv maxv
=
175 max minv
(min maxv v
);
179 { store
= Array.create n v
186 let drawstring size x y s
=
188 Gl.enable `texture_2d
;
189 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
190 ignore
(drawstr size x y s
);
192 Gl.disable `texture_2d
;
195 let drawstring1 size x y s
=
199 let drawstring2 size x y fmt
=
200 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
203 let cbcap b
= Array.length b
.store
;;
208 b
.wc
<- (b
.wc
+ 1) mod cap;
210 b
.len
<- min
(b
.len
+ 1) cap;
213 let cbempty b
= b
.len
= 0;;
215 let cbgetg b circular dir
=
219 let rc = b
.rc + dir
in
231 else max
0 (min
rc (b
.len
-1))
237 let cbget b
= cbgetg b
false;;
238 let cbgetc b
= cbgetg b
true;;
256 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
257 dolog " WxH %dx%d" l
.pagew l
.pageh
;
258 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
259 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
260 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
261 dolog " column %d" l
.pagecol
;
265 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
267 dolog " x0,y0=(% f, % f)" x0 y0
;
268 dolog " x1,y1=(% f, % f)" x1 y1
;
269 dolog " x2,y2=(% f, % f)" x2 y2
;
270 dolog " x3,y3=(% f, % f)" x3 y3
;
274 type multicolumns
= multicol
* pagegeom
275 and splitcolumns
= columncount
* pagegeom
276 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
277 and multicol
= columncount
* covercount
* covercount
279 and columncount
= int
280 and covercount
= int;;
283 { mutable scrollbw
: int
284 ; mutable scrollh
: int
285 ; mutable icase
: bool
286 ; mutable preload
: bool
287 ; mutable pagebias
: int
288 ; mutable verbose
: bool
289 ; mutable debug
: bool
290 ; mutable scrollstep
: int
291 ; mutable maxhfit
: bool
292 ; mutable crophack
: bool
293 ; mutable autoscrollstep
: int
294 ; mutable maxwait
: float option
295 ; mutable hlinks
: bool
296 ; mutable underinfo
: bool
297 ; mutable interpagespace
: interpagespace
298 ; mutable zoom
: float
299 ; mutable presentation
: bool
300 ; mutable angle
: angle
303 ; mutable savebmarks
: bool
304 ; mutable proportional
: proportional
305 ; mutable trimmargins
: trimmargins
306 ; mutable trimfuzz
: irect
307 ; mutable memlimit
: memsize
308 ; mutable texcount
: texcount
309 ; mutable sliceheight
: sliceheight
310 ; mutable thumbw
: width
311 ; mutable jumpback
: bool
312 ; mutable bgcolor
: float * float * float
313 ; mutable bedefault
: bool
314 ; mutable scrollbarinpm
: bool
315 ; mutable tilew
: int
316 ; mutable tileh
: int
317 ; mutable mustoresize
: memsize
318 ; mutable checkers
: bool
319 ; mutable aalevel
: int
320 ; mutable urilauncher
: string
321 ; mutable pathlauncher
: string
322 ; mutable colorspace
: colorspace
323 ; mutable invert
: bool
324 ; mutable colorscale
: float
325 ; mutable redirectstderr
: bool
326 ; mutable ghyllscroll
: (int * int * int) option
327 ; mutable columns
: columns
328 ; mutable beyecolumns
: columncount
option
329 ; mutable selcmd
: string
330 ; mutable updatecurs
: bool
331 ; mutable keyhashes
: (string * keyhash
) list
335 | Cmulti
of multicolumns
336 | Csplit
of splitcolumns
339 type anchor
= pageno
* top
;;
341 type outline
= string * int * anchor
;;
343 type rect
= float * float * float * float * float * float * float * float;;
345 type tile
= opaque
* pixmapsize
* elapsed
346 and elapsed
= float;;
347 type pagemapkey
= pageno
* gen
;;
348 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
352 let emptyanchor = (0, 0.0);;
354 type infochange
= | Memused
| Docinfo
| Pdim
;;
356 class type uioh
= object
357 method display
: unit
358 method key
: int -> int -> uioh
359 method button
: int -> bool -> int -> int -> int -> uioh
360 method motion
: int -> int -> uioh
361 method pmotion
: int -> int -> uioh
362 method infochanged
: infochange
-> unit
363 method scrollpw
: (int * float * float)
364 method scrollph
: (int * float * float)
365 method modehash
: keyhash
369 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
370 | Textentry
of (textentry
* onleave
)
372 | LinkNav
of linktarget
373 and onleave
= leavetextentrystatus
-> unit
374 and leavetextentrystatus
= | Cancel
| Confirm
375 and helpitem
= string * int * action
378 | Action
of (uioh
-> uioh
)
380 | Ltexact
of (pageno
* int)
384 let isbirdseye = function Birdseye _
-> true | _
-> false;;
385 let istextentry = function Textentry _
-> true | _
-> false;;
389 | Loading
of (page
* gen
)
391 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
393 | Outlining
of outline list
396 let emptykeyhash = Hashtbl.create
0;;
397 let nouioh : uioh
= object (self
)
399 method key _ _
= self
400 method button _ _ _ _ _
= self
401 method motion _ _
= self
402 method pmotion _ _
= self
403 method infochanged _
= ()
404 method scrollpw
= (0, nan
, nan
)
405 method scrollph
= (0, nan
, nan
)
406 method modehash
= emptykeyhash
410 { mutable sr
: Unix.file_descr
411 ; mutable sw
: Unix.file_descr
412 ; mutable wsfd
: Unix.file_descr
413 ; mutable errfd
: Unix.file_descr
option
414 ; mutable stderr
: Unix.file_descr
415 ; mutable errmsgs
: Buffer.t
416 ; mutable newerrmsgs
: bool
420 ; mutable scrollw
: int
421 ; mutable hscrollh
: int
422 ; mutable anchor
: anchor
423 ; mutable ranchors
: (string * string * anchor
) list
425 ; mutable layout
: page list
426 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
427 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
428 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
429 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
430 ; mutable pagecount
: int
431 ; mutable currently
: currently
432 ; mutable mstate
: mstate
433 ; mutable searchpattern
: string
434 ; mutable rects
: (pageno
* recttype
* rect
) list
435 ; mutable rects1
: (pageno
* recttype
* rect
) list
436 ; mutable text
: string
437 ; mutable fullscreen
: (width
* height
) option
438 ; mutable mode
: mode
439 ; mutable uioh
: uioh
440 ; mutable outlines
: outline array
441 ; mutable bookmarks
: outline list
442 ; mutable path
: string
443 ; mutable password
: string
444 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
445 ; mutable memused
: memsize
447 ; mutable throttle
: (page list
* int * float) option
448 ; mutable autoscroll
: int option
449 ; mutable ghyll
: (int option -> unit)
450 ; mutable help
: helpitem array
451 ; mutable docinfo
: (int * string) list
452 ; mutable texid
: GlTex.texture_id
option
454 ; mutable prevzoom
: float
455 ; mutable progress
: float
456 ; mutable redisplay
: bool
457 ; mutable mpos
: mpos
458 ; mutable keystate
: keystate
459 ; mutable glinks
: bool
462 { pat
: string circbuf
463 ; pag
: string circbuf
464 ; nav
: anchor circbuf
465 ; sel
: string circbuf
486 ; presentation
= false
491 ; proportional
= true
492 ; trimmargins
= false
493 ; trimfuzz
= (0,0,0,0)
494 ; memlimit
= 32 lsl 20
499 ; bgcolor
= (0.5, 0.5, 0.5)
501 ; scrollbarinpm
= true
504 ; mustoresize
= 256 lsl 20
509 | Plinux
| Pfreebsd
| Pdragonflybsd
510 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
511 | Posx
-> "open \"%s\""
512 | Pcygwin
-> "cygstart \"%s\""
513 | Punknown
-> "echo %s")
514 ; pathlauncher
= "lp \"%s\""
517 | Plinux
| Pfreebsd
| Pdragonflybsd
518 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
525 ; redirectstderr
= false
531 let mk n
= (n
, Hashtbl.create
1) in
544 let findkeyhash c name
=
545 try List.assoc name c
.keyhashes
546 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
549 let conf = { defconf with angle
= defconf.angle
};;
552 { mutable fontsize
: int
553 ; mutable wwidth
: float
554 ; mutable maxrows
: int
566 fstate.fontsize
<- n
;
567 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
568 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
572 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
573 let len = String.length s
in
574 if colonpos >= 0 && colonpos + 3 < len
576 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
579 try String.rindex_from s
colonpos ' '
583 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
586 | "http" | "ftp" | "mailto" ->
588 try String.index_from s
colonpos ' '
589 with Not_found
-> len
591 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
599 if String.length
conf.urilauncher
= 0
600 then print_endline uri
602 let url = geturl uri
in
603 if String.length
url = 0
604 then print_endline uri
606 let re = Str.regexp
"%s" in
607 let command = Str.global_replace
re url conf.urilauncher
in
611 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
617 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
618 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
622 let strings = version () :: "" :: Help.keys
in
625 let url = geturl s
in
626 if String.length
url > 0
627 then (s
, 0, Action
(fun u
-> gotouri url; u
))
628 else (s
, 0, Noaction
)
633 let firstgeomcmds = "", [];;
640 ; stderr
= Unix.stderr
641 ; errmsgs
= Buffer.create
0
648 ; anchor
= emptyanchor
652 ; tilelru
= Queue.create
()
653 ; pagemap
= Hashtbl.create
10
654 ; tilemap
= Hashtbl.create
10
669 ; geomcmds
= firstgeomcmds
671 { nav
= cbnew 10 (0, 0.0)
697 Printf.kprintf prerr_endline fmt
699 Printf.kprintf ignore fmt
703 if String.length
conf.pathlauncher
= 0
704 then print_endline
state.path
706 let re = Str.regexp
"%s" in
707 let command = Str.global_replace
re state.path
conf.pathlauncher
in
711 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
717 type 'a t
= | Res
of 'a
| Exn
of exn
;;
720 try Res
(Unix.pipe ())
726 with exn
-> f
(Printexc.to_string exn
)
730 try Res
(Unix.dup fd
)
735 try Res
(Unix.dup2 fd1 fd2
)
740 let redirectstderr () =
741 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
742 if conf.redirectstderr
744 match Ne.pipe () with
746 dolog "failed to create stderr redirection pipes: %s"
747 (Printexc.to_string exn
)
750 begin match Ne.dup Unix.stderr
with
752 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
753 Ne.clo r
(clofail "pipe/r");
754 Ne.clo w
(clofail "pipe/w");
756 | Ne.Res dupstderr
->
757 begin match Ne.dup2 w
Unix.stderr
with
759 dolog "failed to dup2 to stderr: %s"
760 (Printexc.to_string exn
);
761 Ne.clo dupstderr
(clofail "stderr duplicate");
762 Ne.clo r
(clofail "redir pipe/r");
763 Ne.clo w
(clofail "redir pipe/w");
766 state.stderr
<- dupstderr
;
767 state.errfd
<- Some r
;
771 state.newerrmsgs
<- false;
772 begin match state.errfd
with
774 begin match Ne.dup2 state.stderr
Unix.stderr
with
776 dolog "failed to dup2 original stderr: %s"
777 (Printexc.to_string exn
)
779 Ne.clo fd
(clofail "dup of stderr");
780 Unix.dup2 state.stderr
Unix.stderr
;
785 prerr_string
(Buffer.contents
state.errmsgs
);
787 Buffer.clear
state.errmsgs
;
793 let postRedisplay who
=
795 then prerr_endline
("redisplay for " ^ who
);
796 state.redisplay
<- true;
800 let getopaque pageno
=
801 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
802 with Not_found
-> None
805 let putopaque pageno opaque
=
806 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
809 let pagetranslatepoint l x y
=
810 let dy = y
- l
.pagedispy
in
811 let y = dy + l
.pagey
in
812 let dx = x
- l
.pagedispx
in
813 let x = dx + l
.pagex
in
820 begin match getopaque l
.pageno
with
822 let x0 = l
.pagedispx
in
823 let x1 = x0 + l
.pagevw
in
824 let y0 = l
.pagedispy
in
825 let y1 = y0 + l
.pagevh
in
826 if y >= y0 && y <= y1 && x >= x0 && x <= x1
828 let px, py
= pagetranslatepoint l
x y in
829 match whatsunder opaque
px py
with
842 state.text
<- Printf.sprintf
"%c%s" c s
;
843 G.postRedisplay "showtext";
846 let undertext = function
849 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
850 | Utext s
-> "font: " ^ s
851 | Uunexpected s
-> "unexpected: " ^ s
852 | Ulaunch s
-> "launch: " ^ s
853 | Unamed s
-> "named: " ^ s
854 | Uremote
(filename
, pageno
) ->
855 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
858 let updateunder x y =
859 match getunder x y with
860 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
862 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
863 Wsi.setcursor
Wsi.CURSOR_INFO
864 | Ulinkgoto
(pageno
, _
) ->
866 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
867 Wsi.setcursor
Wsi.CURSOR_INFO
869 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
870 Wsi.setcursor
Wsi.CURSOR_TEXT
872 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
873 Wsi.setcursor
Wsi.CURSOR_INHERIT
875 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
876 Wsi.setcursor
Wsi.CURSOR_INHERIT
878 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
879 Wsi.setcursor
Wsi.CURSOR_INHERIT
880 | Uremote
(filename
, pageno
) ->
881 if conf.underinfo
then showtext 'r'
882 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
883 Wsi.setcursor
Wsi.CURSOR_INFO
886 let showlinktype under
=
892 let s = undertext under
in
897 let b = Buffer.create
(String.length
s + 1) in
898 Buffer.add_string
b s;
903 let colorspace_of_string s =
904 match String.lowercase
s with
908 | _
-> failwith
"invalid colorspace"
911 let int_of_colorspace = function
917 let colorspace_of_int = function
921 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
924 let colorspace_to_string = function
930 let intentry_with_suffix text key
=
932 if key
>= 32 && key
< 127
936 match Char.lowercase
c with
938 let text = addchar text c in
942 let text = addchar text c in
946 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
950 let multicolumns_to_string (n
, a
, b) =
952 then Printf.sprintf
"%d" n
953 else Printf.sprintf
"%d,%d,%d" n a
b;
956 let multicolumns_of_string s =
958 (int_of_string
s, 0, 0)
960 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
965 let n = Unix.read fd
s 0 4 in
966 if n != 4 then failwith
"incomplete read(len)";
968 lor (Char.code
s.[0] lsl 24)
969 lor (Char.code
s.[1] lsl 16)
970 lor (Char.code
s.[2] lsl 8)
971 lor (Char.code
s.[3] lsl 0)
973 let s = String.create
len in
974 let n = Unix.read fd
s 0 len in
975 if n != len then failwith
"incomplete read(data)";
979 let btod b = if b then 1 else 0;;
982 let b = Buffer.create
16 in
983 Buffer.add_string
b "llll";
986 let s = Buffer.contents
b in
987 let n = String.length
s in
989 (* dolog "wcmd %S" (String.sub s 4 len); *)
990 s.[0] <- Char.chr
((len lsr 24) land 0xff);
991 s.[1] <- Char.chr
((len lsr 16) land 0xff);
992 s.[2] <- Char.chr
((len lsr 8) land 0xff);
993 s.[3] <- Char.chr
(len land 0xff);
994 let n'
= Unix.write
state.sw
s 0 n in
995 if n'
!= n then failwith
"write failed";
1000 if conf.presentation
1002 let d = conf.winh
- h
in
1009 let rec f pn ph pi fh l
=
1011 | (n, _
, h
, _
) :: rest
->
1012 let ips = calcips h
in
1014 if conf.presentation
1017 if isbirdseye state.mode
&& pn
= 0
1022 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1027 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1031 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1034 let fh = f 0 0 0 0 state.pdims
in
1039 match conf.columns
with
1040 | Csingle
-> calcheight ()
1041 | Cmulti
((c, _
, _
), b) ->
1042 let rec loop y h
n =
1046 if n = Array.length
b
1049 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1055 loop max_int
0 (((Array.length
b - 1) / c) * c)
1057 if Array.length
b > 0
1059 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1064 let getpageyh pageno
=
1065 let rec f pn ph pi
y l
=
1067 | (n, _
, h
, _
) :: rest
->
1068 let ips = calcips h
in
1071 let h = if n = pageno
then h else ph
in
1072 if conf.presentation
&& n = pageno
1074 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1076 y + (pageno
- pn
) * (ph
+ pi
), h
1078 let y = y + (if conf.presentation
then pi
else 0) in
1079 let y = y + (n - pn
) * (ph
+ pi
) in
1083 y + (pageno
- pn
) * (ph
+ pi
), ph
1085 f 0 0 0 0 state.pdims
1088 let getpageyh pageno
=
1089 match conf.columns
with
1090 | Csingle
-> getpageyh pageno
1092 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1096 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1100 let getpagedim pageno
=
1103 | (n, _
, _
, _
) as pdim
:: rest
->
1105 then (if n = pageno
then pdim
else ppdim
)
1110 f (-1, -1, -1, -1) state.pdims
1113 let getpagey pageno
= fst
(getpageyh pageno
);;
1115 let nogeomcmds cmds
=
1117 | s, [] -> String.length
s = 0
1122 let sh = sh - state.hscrollh
in
1123 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1124 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1126 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1127 let ips = calcips h in
1129 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1133 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1135 prev
, pdims
, pdimno
, 0
1137 let dy = dy + yinc in
1138 let py = py + yinc in
1139 if pageno
= state.pagecount
|| dy >= sh
1144 if py + h <= vy - yinc
1146 let py = py + h + ips in
1147 let dy = max
0 (py - y) in
1148 f ~pageno
:(pageno
+1)
1156 let pagey = vy - py in
1157 let pagevh = h - pagey in
1158 let pagevh = min
(sh - dy) pagevh in
1159 let off = if yinc > 0 then py - vy else 0 in
1160 let py = py + h + ips in
1163 if state.w
< conf.winw
- state.scrollw
1164 then (conf.winw
- state.scrollw
- state.w
) / 2
1167 let dispx = xoff + state.x in
1173 let lw = w
- pagex in
1174 min
lw (conf.winw
- state.scrollw
)
1178 ; pagedimno
= pdimno
1182 ; pagey = pagey + off
1184 ; pagevh = pagevh - off
1186 ; pagedispy
= dy + off
1190 let accu = e :: accu in
1191 f ~pageno
:(pageno
+1)
1212 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1213 let sh = sh - state.hscrollh
in
1214 let rec fold accu n =
1215 if n = Array.length
b
1218 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1221 || n = state.pagecount
- coverB
1222 || (n - coverA
) mod columns
= columns
- 1)
1228 let pagey = max
0 (y - vy) in
1229 let pagedispy = if pagey > 0 then 0 else vy - y in
1230 let pagedispx, pagex =
1232 if n = coverA
- 1 || n = state.pagecount
- coverB
1233 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1234 else dx + xoff + state.x
1241 let vw = conf.winw
- state.scrollw
- pagedispx in
1242 let pw = w
- pagex in
1245 let pagevh = min
(h - pagey) (sh - pagedispy) in
1246 if pagevw > 0 && pagevh > 0
1250 ; pagedimno
= pdimno
1257 ; pagedispx = pagedispx
1258 ; pagedispy = pagedispy
1270 List.rev
(fold [] 0)
1273 let layoutS (columns
, b) y sh =
1274 let sh = sh - state.hscrollh
in
1275 let rec fold accu n =
1276 if n = Array.length
b
1279 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1286 let x = xoff + state.x in
1287 let pagey = max
0 (y - vy) in
1288 let pagedispy = if pagey > 0 then 0 else vy - y in
1289 let pagedispx, pagex =
1304 let vw = conf.winw
- pagedispx - state.scrollw
in
1305 let pw = pagew
- pagex in
1308 let pagevw = min
pagevw (pagew
/columns
) in
1309 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1310 if pagevw > 0 && pagevh > 0
1313 { pageno
= n/columns
1314 ; pagedimno
= pdimno
1321 ; pagedispx = pagedispx
1322 ; pagedispy = pagedispy
1323 ; pagecol
= n mod columns
1334 List.rev
(fold [] 0)
1338 if nogeomcmds state.geomcmds
1340 match conf.columns
with
1341 | Csingle
-> layout1 y sh
1342 | Cmulti
c -> layoutN c y sh
1343 | Csplit
s -> layoutS s y sh
1348 let y = state.y + incr
in
1350 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1355 let tilex = l
.pagex mod conf.tilew
in
1356 let tiley = l
.pagey mod conf.tileh
in
1358 let col = l
.pagex / conf.tilew
in
1359 let row = l
.pagey / conf.tileh
in
1361 let rec rowloop row y0 dispy
h =
1365 let dh = conf.tileh
- y0 in
1366 let dh = min
h dh in
1367 let rec colloop col x0 dispx w
=
1371 let dw = conf.tilew
- x0 in
1372 let dw = min w
dw in
1374 f col row dispx dispy
x0 y0 dw dh;
1375 colloop (col+1) 0 (dispx+dw) (w
-dw)
1378 colloop col tilex l
.pagedispx l
.pagevw;
1379 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1382 if l
.pagevw > 0 && l
.pagevh > 0
1383 then rowloop row tiley l
.pagedispy l
.pagevh;
1386 let gettileopaque l
col row =
1388 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1390 try Some
(Hashtbl.find
state.tilemap
key)
1391 with Not_found
-> None
1394 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1395 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1396 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1399 let drawtiles l color
=
1401 let f col row x y tilex tiley w
h =
1402 match gettileopaque l
col row with
1403 | Some
(opaque
, _
, t
) ->
1404 let params = x, y, w
, h, tilex, tiley in
1408 GlFunc.blend_func `zero `one_minus_src_color
;
1410 drawtile
params opaque
;
1412 then Gl.disable `blend
;
1415 let s = Printf.sprintf
1419 let w = measurestr
fstate.fontsize
s in
1420 GlMisc.push_attrib
[`current
];
1421 GlDraw.color
(0.0, 0.0, 0.0);
1423 (float (x-2), float (y-2))
1424 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1425 GlDraw.color
(1.0, 1.0, 1.0);
1426 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1427 GlMisc.pop_attrib
();
1432 let lw = conf.winw
- state.scrollw
- x in
1435 let lh = conf.winh
- y in
1438 Gl.enable `texture_2d
;
1439 begin match state.texid
with
1441 GlTex.bind_texture `texture_2d id
;
1444 and x1 = float (x+w)
1445 and y1 = float (y+h) in
1447 let tw = float w /. 64.0
1448 and th
= float h /. 64.0 in
1449 let tx0 = float tilex /. 64.0
1450 and ty0
= float tiley /. 64.0 in
1452 and ty1
= ty0
+. th
in
1453 GlDraw.begins `quads
;
1454 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1455 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1456 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1457 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1460 Gl.disable `texture_2d
;
1462 GlDraw.color
(1.0, 1.0, 1.0);
1465 (float (x+w), float (y+h));
1467 if w > 128 && h > fstate.fontsize
+ 10
1469 GlDraw.color
(0.0, 0.0, 0.0);
1472 then (col*conf.tilew
, row*conf.tileh
)
1475 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1482 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1484 let tilevisible1 l
x y =
1486 and ax1
= l
.pagex + l
.pagevw
1488 and ay1
= l
.pagey + l
.pagevh in
1492 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1493 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1495 let rx0 = max
ax0 bx0
1496 and ry0
= max ay0 by0
1497 and rx1
= min ax1
bx1
1498 and ry1
= min ay1 by1
in
1500 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1501 nonemptyintersection
1504 let tilevisible layout n x y =
1505 let rec findpageinlayout m
= function
1506 | l
:: rest
when l
.pageno
= n ->
1507 tilevisible1 l
x y || (
1508 match conf.columns
with
1509 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1512 | _
:: rest
-> findpageinlayout 0 rest
1515 findpageinlayout 0 layout;
1518 let tileready l
x y =
1519 tilevisible1 l
x y &&
1520 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1523 let tilepage n p
layout =
1524 let rec loop = function
1528 let f col row _ _ _ _ _ _
=
1529 if state.currently
= Idle
1531 match gettileopaque l
col row with
1534 let x = col*conf.tilew
1535 and y = row*conf.tileh
in
1537 let w = l
.pagew
- x in
1541 let h = l
.pageh
- y in
1544 wcmd "tile %s %d %d %d %d" p
x y w h;
1547 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1548 conf.tilew
, conf.tileh
1557 if nogeomcmds state.geomcmds
1561 let preloadlayout visiblepages
=
1562 let presentation = conf.presentation in
1563 let interpagespace = conf.interpagespace in
1564 let maxy = state.maxy in
1565 conf.presentation <- false;
1566 conf.interpagespace <- 0;
1567 state.maxy <- calcheight ();
1569 match visiblepages
with
1570 | [] -> if state.y >= maxy then maxy else 0
1571 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1573 let y = if y < conf.winh
then 0 else y - conf.winh
in
1574 let h = state.y - y + conf.winh
*3 in
1575 let pages = layout y h in
1576 conf.presentation <- presentation;
1577 conf.interpagespace <- interpagespace;
1583 let rec loop pages =
1584 if state.currently
!= Idle
1589 begin match getopaque l
.pageno
with
1591 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1592 state.currently
<- Loading
(l
, state.gen
);
1594 tilepage l
.pageno opaque
pages;
1599 if nogeomcmds state.geomcmds
1605 if conf.preload && state.currently
= Idle
1606 then load (preloadlayout pages);
1609 let layoutready layout =
1610 let rec fold all ls
=
1611 all
&& match ls
with
1613 let seen = ref false in
1614 let allvisible = ref true in
1615 let foo col row _ _ _ _ _ _
=
1617 allvisible := !allvisible &&
1618 begin match gettileopaque l
col row with
1624 fold (!seen && !allvisible) rest
1627 let alltilesvisible = fold true layout in
1632 let y = bound y 0 state.maxy in
1633 let y, layout, proceed
=
1634 match conf.maxwait
with
1635 | Some time
when state.ghyll
== noghyll ->
1636 begin match state.throttle
with
1638 let layout = layout y conf.winh
in
1639 let ready = layoutready layout in
1643 state.throttle
<- Some
(layout, y, now ());
1645 else G.postRedisplay "gotoy showall (None)";
1647 | Some
(_
, _
, started
) ->
1648 let dt = now () -. started
in
1651 state.throttle
<- None
;
1652 let layout = layout y conf.winh
in
1654 G.postRedisplay "maxwait";
1661 let layout = layout y conf.winh
in
1662 if true || layoutready layout
1663 then G.postRedisplay "gotoy ready";
1669 state.layout <- layout;
1670 begin match state.mode
with
1671 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1672 let rec loop = function
1674 state.mode
<- LinkNav
(Ltgendir
0)
1675 | l
:: _
when l
.pageno
= pageno
->
1676 begin match getopaque pageno
with
1678 state.mode
<- LinkNav
(Ltgendir
0)
1680 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1681 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1682 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1683 then state.mode
<- LinkNav
(Ltgendir
0)
1685 | _
:: rest
-> loop rest
1690 begin match state.mode
with
1691 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1692 if not
(pagevisible layout pageno
)
1694 match state.layout with
1697 state.mode
<- Birdseye
(
1698 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1701 | LinkNav
(Ltgendir dir
as lt
) ->
1703 let rec loop = function
1706 match getopaque l
.pageno
with
1712 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1714 if dir
> 0 then LDfirst
else LDlast
1720 | Lnotfound
-> loop rest
1722 showlinktype (getlink opaque
n);
1723 Ltexact
(l
.pageno
, n)
1727 state.mode
<- LinkNav
linknav
1732 state.ghyll
<- noghyll;
1735 let mx, my
= state.mpos
in
1740 let conttiling pageno opaque
=
1741 tilepage pageno opaque
1742 (if conf.preload then preloadlayout state.layout else state.layout)
1745 let gotoy_and_clear_text y =
1746 if not
conf.verbose
then state.text <- "";
1751 match state.layout with
1754 let coloff = l
.pagecol
* l
.pageh
in
1755 (l
.pageno
, (float l
.pagey +. float coloff) /. float l
.pageh
)
1758 let getanchory (n, top
) =
1759 let y, h = getpageyh n in
1760 y + (truncate
(top
*. float h));
1763 let gotoanchor anchor
=
1764 gotoy (getanchory anchor
);
1768 cbput state.hists
.nav
(getanchor ());
1772 let anchor = cbgetc state.hists
.nav dir
in
1777 let rec scroll f n a
b =
1778 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1780 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1782 then s (float f /. float a
)
1785 then 1.0 -. s ((float (f-b) /. float (n-b)))
1792 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1793 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1795 let ins = float a
*. iv1
1796 and outs
= float (n-b) *. iv1 in
1798 ins +. outs
+. float ones
1800 let rec set (_N
, _A
, _B
) y sy
=
1801 let sum = summa
1.0 _N _A _B
in
1802 let dy = float (y - sy
) in
1806 then state.ghyll
<- noghyll
1809 let s = scroll n _N _A _B
in
1810 let y1 = y1 +. ((s *. dy) /. sum) in
1811 gotoy_and_clear_text (truncate
y1);
1812 state.ghyll
<- gf (n+1) y1;
1816 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1818 gf 0 (float state.y)
1821 match conf.ghyllscroll
with
1823 gotoy_and_clear_text y
1825 if state.ghyll
== noghyll
1826 then set nab
y state.y
1827 else state.ghyll
(Some
y)
1830 let gotopage n top
=
1831 let y, h = getpageyh n in
1832 let y = y + (truncate
(top
*. float h)) in
1836 let gotopage1 n top
=
1837 let y = getpagey n in
1842 let invalidate s f =
1847 match state.geomcmds
with
1848 | ps
, [] when String.length ps
= 0 ->
1850 state.geomcmds
<- s, [];
1853 state.geomcmds
<- ps
, [s, f];
1855 | ps
, (s'
, _
) :: rest
when s'
= s ->
1856 state.geomcmds
<- ps
, ((s, f) :: rest
);
1859 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1862 let opendoc path password
=
1864 state.password
<- password
;
1865 state.gen
<- state.gen
+ 1;
1866 state.docinfo
<- [];
1868 setaalevel
conf.aalevel
;
1869 Wsi.settitle
("llpp " ^
Filename.basename path
);
1870 wcmd "open %s\000%s\000" path password
;
1871 invalidate "reqlayout"
1873 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1877 let c = c *. conf.colorscale
in
1881 let scalecolor2 (r
, g
, b) =
1882 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1886 let docolumns = function
1889 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1890 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1891 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1892 let rec fixrow m
= if m
= pageno
then () else
1893 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1896 let y = y + (rowh
- h) / 2 in
1897 a.(m
) <- (pdimno, x, y, pdim
);
1901 if pageno
= state.pagecount
1902 then fixrow (((pageno
- 1) / columns
) * columns
)
1904 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1906 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1907 pdimno+1, pdim
, rest
1912 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1914 (conf.winw
- state.scrollw
- w) / 2,
1915 y + rowh
+ conf.interpagespace, h
1918 if (pageno
- coverA
) mod columns
= 0
1919 then 0, y + rowh
+ conf.interpagespace, h
1920 else x, y, max rowh
h
1923 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1924 then fixrow (pageno
- columns
);
1925 a.(pageno
) <- (pdimno, x, y, pdim
);
1926 let x = x + w + xoff*2 + conf.interpagespace in
1927 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1929 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1930 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1933 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1934 let rec loop pageno
pdimno pdim
y pdims
=
1935 if pageno
= state.pagecount
1938 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1940 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1941 pdimno+1, pdim
, rest
1946 let rec loop1 n x y =
1947 if n = c then y else (
1948 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1949 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1952 let y = loop1 0 0 y in
1953 loop (pageno
+1) pdimno pdim
y pdims
1955 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1956 conf.columns
<- Csplit
(c, a);
1958 docolumns conf.columns
;
1959 state.maxy <- calcheight ();
1961 if state.w <= conf.winw
- state.scrollw
1965 match state.mode
with
1966 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1967 let y, h = getpageyh pageno
in
1968 let top = (conf.winh
- h) / 2 in
1969 gotoy (max
0 (y - top))
1970 | _
-> gotoanchor state.anchor
1974 GlDraw.viewport
0 0 w h;
1975 let firsttime = state.geomcmds
== firstgeomcmds in
1976 if not
firsttime && nogeomcmds state.geomcmds
1977 then state.anchor <- getanchor ();
1980 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1983 setfontsize fstate.fontsize
;
1984 GlMat.mode `modelview
;
1985 GlMat.load_identity
();
1987 GlMat.mode `projection
;
1988 GlMat.load_identity
();
1989 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1990 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1991 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1996 else float state.x /. float state.w
1998 invalidate "geometry"
2002 then state.x <- truncate
(relx *. float w);
2004 match conf.columns
with
2006 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2007 | Csplit
(c, _
) -> w * c
2009 wcmd "geometry %d %d" w h);
2013 let len = String.length
state.text in
2016 match state.mode
with
2019 let h, _
, _
= state.uioh#scrollpw
in
2025 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2026 (x+.w, float (conf.winh
- hscrollh))
2029 let w = float (conf.winw
- state.scrollw
- 1) in
2030 if state.progress
>= 0.0 && state.progress
< 1.0
2032 GlDraw.color
(0.3, 0.3, 0.3);
2033 let w1 = w *. state.progress
in
2035 GlDraw.color
(0.0, 0.0, 0.0);
2039 GlDraw.color
(0.0, 0.0, 0.0);
2043 GlDraw.color
(1.0, 1.0, 1.0);
2044 drawstring fstate.fontsize
2045 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2048 match state.mode
with
2049 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
2053 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2055 Printf.sprintf
"%s%s_" prefix
text
2064 if not
(istextentry state.mode
)
2066 let s1 = "(press 'e' to review error messasges)" in
2067 if String.length
s > 0 then s ^
" " ^
s1 else s1
2072 if String.length
s > 0
2077 let len = Queue.length
state.tilelru
in
2079 if state.memused
<= conf.memlimit
2084 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2085 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2086 let (_
, pw, ph
, _
) = getpagedim n in
2089 && colorspace
= conf.colorspace
2090 && angle
= conf.angle
2095 match state.throttle
with
2098 then preloadlayout state.layout
2100 | Some
(layout, _
, _
) ->
2103 let x = col*conf.tilew
2104 and y = row*conf.tileh
in
2105 tilevisible layout n x y
2107 then Queue.push lruitem
state.tilelru
2109 wcmd "freetile %s" p
;
2110 state.memused
<- state.memused
- s;
2111 state.uioh#infochanged Memused
;
2112 Hashtbl.remove
state.tilemap k
;
2121 Queue.iter
(fun (k
, p
, s) ->
2122 wcmd "freetile %s" p
;
2123 state.memused
<- state.memused
- s;
2124 state.uioh#infochanged Memused
;
2125 Hashtbl.remove
state.tilemap k
;
2127 Queue.clear
state.tilelru
;
2131 let logcurrently = function
2132 | Idle
-> dolog "Idle"
2133 | Loading
(l
, gen
) ->
2134 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2135 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2137 "Tiling %d[%d,%d] page=%s cs=%s angle"
2138 l
.pageno
col row pageopaque
2139 (colorspace_to_string colorspace
)
2141 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2142 angle gen
conf.angle
state.gen
2144 conf.tilew
conf.tileh
2151 (* dolog "%S" cmds; *)
2154 try String.index cmds ' '
2155 with Not_found
-> -1
2160 let l = String.length cmds
in
2161 let op = String.sub cmds
0 spacepos in
2163 if l - spacepos < 2 then ""
2164 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2169 state.uioh#infochanged Pdim
;
2173 state.rects
<- state.rects1
;
2174 G.postRedisplay "clearrects";
2178 try Scanf.sscanf
args "%u" (fun n -> n)
2180 dolog "error processing 'continue' %S: %s"
2181 cmds
(Printexc.to_string exn
);
2184 state.pagecount
<- n;
2185 begin match state.currently
with
2187 state.currently
<- Idle
;
2188 state.outlines
<- Array.of_list
(List.rev
l)
2192 let cur, cmds
= state.geomcmds
in
2193 if String.length
cur = 0
2194 then failwith
"umpossible";
2196 begin match List.rev cmds
with
2198 state.geomcmds
<- "", [];
2202 state.geomcmds
<- s, List.rev rest
;
2204 if conf.maxwait
= None
2205 then G.postRedisplay "continue";
2215 then showtext ' '
args
2218 let progress, text =
2220 Scanf.sscanf
args "%f %n"
2222 f, String.sub
args pos
(String.length
args - pos
))
2224 dolog "error processing 'progress' %S: %s"
2225 cmds
(Printexc.to_string exn
);
2229 state.progress <- progress;
2230 G.postRedisplay "progress"
2233 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2235 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2236 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2237 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2239 dolog "error processing 'firstmatch' %S: %s"
2240 cmds
(Printexc.to_string exn
);
2243 let y = (getpagey pageno) + truncate
y0 in
2246 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2249 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2251 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2252 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2253 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2255 dolog "error processing 'match' %S: %s"
2256 cmds
(Printexc.to_string exn
);
2260 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2265 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2267 dolog "error processing 'page' %S: %s"
2268 cmds
(Printexc.to_string exn
);
2271 begin match state.currently
with
2272 | Loading
(l, gen
) ->
2273 vlog "page %d took %f sec" l.pageno t
;
2274 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2275 begin match state.throttle
with
2277 let preloadedpages =
2279 then preloadlayout state.layout
2284 Set.Make
(struct type t
= int let compare = (-) end) in
2286 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2287 IntSet.empty
preloadedpages
2290 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2291 if not
(IntSet.mem
pageno set)
2293 wcmd "freepage %s" opaque
;
2299 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2302 state.currently
<- Idle
;
2305 tilepage l.pageno pageopaque state.layout;
2307 load preloadedpages;
2308 if pagevisible state.layout l.pageno
2309 && layoutready state.layout
2310 then G.postRedisplay "page";
2313 | Some
(layout, _
, _
) ->
2314 state.currently
<- Idle
;
2315 tilepage l.pageno pageopaque layout;
2320 dolog "Inconsistent loading state";
2321 logcurrently state.currently
;
2326 let (x, y, opaque
, size
, t
) =
2328 Scanf.sscanf
args "%u %u %s %u %f"
2329 (fun x y p size t
-> (x, y, p
, size
, t
))
2331 dolog "error processing 'tile' %S: %s"
2332 cmds
(Printexc.to_string exn
);
2335 begin match state.currently
with
2336 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2337 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2339 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2341 wcmd "freetile %s" opaque
;
2342 state.currently
<- Idle
;
2346 puttileopaque l col row gen cs angle opaque size t
;
2347 state.memused
<- state.memused
+ size
;
2348 state.uioh#infochanged Memused
;
2350 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2351 opaque
, size
) state.tilelru
;
2354 match state.throttle
with
2355 | None
-> state.layout
2356 | Some
(layout, _
, _
) -> layout
2359 state.currently
<- Idle
;
2361 && conf.colorspace
= cs
2362 && conf.angle
= angle
2363 && tilevisible layout l.pageno x y
2364 then conttiling l.pageno pageopaque;
2366 begin match state.throttle
with
2368 preload state.layout;
2370 && conf.colorspace
= cs
2371 && conf.angle
= angle
2372 && tilevisible state.layout l.pageno x y
2373 then G.postRedisplay "tile nothrottle";
2375 | Some
(layout, y, _
) ->
2376 let ready = layoutready layout in
2380 state.layout <- layout;
2381 state.throttle
<- None
;
2382 G.postRedisplay "throttle";
2389 dolog "Inconsistent tiling state";
2390 logcurrently state.currently
;
2397 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2399 dolog "error processing 'pdim' %S: %s"
2400 cmds
(Printexc.to_string exn
);
2403 state.uioh#infochanged Pdim
;
2404 state.pdims
<- pdim :: state.pdims
2407 let (l, n, t
, h, pos
) =
2409 Scanf.sscanf
args "%u %u %d %u %n"
2410 (fun l n t
h pos
-> l, n, t
, h, pos
)
2412 dolog "error processing 'o' %S: %s"
2413 cmds
(Printexc.to_string exn
);
2416 let s = String.sub
args pos
(String.length
args - pos
) in
2417 let outline = (s, l, (n, float t
/. float h)) in
2418 begin match state.currently
with
2419 | Outlining outlines
->
2420 state.currently
<- Outlining
(outline :: outlines
)
2422 state.currently
<- Outlining
[outline]
2424 dolog "invalid outlining state";
2425 logcurrently currently
2429 state.docinfo
<- (1, args) :: state.docinfo
2432 state.uioh#infochanged Docinfo
;
2433 state.docinfo
<- List.rev
state.docinfo
2436 dolog "unknown cmd `%S'" cmds
2441 let action = function
2442 | HCprev
-> cbget cb ~
-1
2443 | HCnext
-> cbget cb
1
2444 | HCfirst
-> cbget cb ~
-(cb
.rc)
2445 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2446 and cancel
() = cb
.rc <- rc
2450 let search pattern forward
=
2451 if String.length pattern
> 0
2454 match state.layout with
2457 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2459 wcmd "search %d %d %d %d,%s\000"
2460 (btod conf.icase
) pn py (btod forward
) pattern
;
2463 let intentry text key =
2465 if key >= 32 && key < 127
2471 let text = addchar text c in
2475 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2479 let linknentry text key =
2481 if key >= 32 && key < 127
2487 let text = addchar text c in
2491 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2496 if String.length
s > 0
2499 let l = String.length
s in
2500 let rec loop pos
n = if pos
= l then n else
2501 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2502 loop (pos
+1) (n*26 + m)
2505 let rec loop n = function
2508 match getopaque l.pageno with
2509 | None
-> loop n rest
2511 let m = getlinkcount opaque
in
2514 let under = getlink opaque
n in
2517 else loop (n-m) rest
2519 loop n state.layout;
2523 let textentry text key =
2524 if key land 0xff00 = 0xff00
2526 else TEcont
(text ^
Wsi.toutf8
key)
2529 let reqlayout angle proportional
=
2530 match state.throttle
with
2532 if nogeomcmds state.geomcmds
2533 then state.anchor <- getanchor ();
2534 conf.angle
<- angle
mod 360;
2537 match state.mode
with
2538 | LinkNav _
-> state.mode
<- View
2541 conf.proportional
<- proportional
;
2542 invalidate "reqlayout"
2543 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2547 let settrim trimmargins trimfuzz
=
2548 if nogeomcmds state.geomcmds
2549 then state.anchor <- getanchor ();
2550 conf.trimmargins
<- trimmargins
;
2551 conf.trimfuzz
<- trimfuzz
;
2552 let x0, y0, x1, y1 = trimfuzz
in
2553 invalidate "settrim"
2555 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2556 Hashtbl.iter
(fun _ opaque
->
2557 wcmd "freepage %s" opaque
;
2559 Hashtbl.clear
state.pagemap
;
2563 match state.throttle
with
2565 let zoom = max
0.01 zoom in
2566 if zoom <> conf.zoom
2568 state.prevzoom
<- conf.zoom;
2570 reshape conf.winw
conf.winh
;
2571 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2574 | Some
(layout, y, started
) ->
2576 match conf.maxwait
with
2580 let dt = now () -. started
in
2588 let setcolumns mode columns coverA coverB
=
2592 then showtext '
!'
"split mode doesn't work in bird's eye"
2594 conf.columns
<- Csplit
(-columns
, [||]);
2602 conf.columns
<- Csingle
;
2607 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2611 reshape conf.winw
conf.winh
;
2614 let enterbirdseye () =
2615 let zoom = float conf.thumbw
/. float conf.winw
in
2616 let birdseyepageno =
2617 let cy = conf.winh
/ 2 in
2621 let rec fold best
= function
2624 let d = cy - (l.pagedispy + l.pagevh/2)
2625 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2626 if abs
d < abs dbest
2633 state.mode
<- Birdseye
(
2634 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2637 conf.presentation <- false;
2638 conf.interpagespace <- 10;
2639 conf.hlinks
<- false;
2641 state.mstate
<- Mnone
;
2642 conf.maxwait
<- None
;
2644 match conf.beyecolumns
with
2647 Cmulti
((c, 0, 0), [||])
2650 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2653 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2658 reshape conf.winw
conf.winh
;
2661 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2663 conf.zoom <- c.zoom;
2664 conf.presentation <- c.presentation;
2665 conf.interpagespace <- c.interpagespace;
2666 conf.maxwait
<- c.maxwait
;
2667 conf.hlinks
<- c.hlinks
;
2668 conf.beyecolumns
<- (
2669 match conf.columns
with
2670 | Cmulti
((c, _
, _
), _
) -> Some
c
2672 | Csplit _
-> assert false
2675 match c.columns
with
2676 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2677 | Csingle
-> Csingle
2678 | Csplit _
-> failwith
"leaving bird's eye split mode"
2683 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2686 reshape conf.winw
conf.winh
;
2687 state.anchor <- if goback
then anchor else (pageno, 0.0);
2690 let togglebirdseye () =
2691 match state.mode
with
2692 | Birdseye vals
-> leavebirdseye vals
true
2693 | View
-> enterbirdseye ()
2697 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2698 let pageno = max
0 (pageno - incr
) in
2699 let rec loop = function
2700 | [] -> gotopage1 pageno 0
2701 | l :: _
when l.pageno = pageno ->
2702 if l.pagedispy >= 0 && l.pagey = 0
2703 then G.postRedisplay "upbirdseye"
2704 else gotopage1 pageno 0
2705 | _
:: rest
-> loop rest
2708 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2711 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2712 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2713 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2714 let rec loop = function
2716 let y, h = getpageyh pageno in
2717 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2719 | l :: _
when l.pageno = pageno ->
2720 if l.pagevh != l.pageh
2721 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2722 else G.postRedisplay "downbirdseye"
2723 | _
:: rest
-> loop rest
2728 let optentry mode _
key =
2729 let btos b = if b then "on" else "off" in
2730 if key >= 32 && key < 127
2732 let c = Char.chr
key in
2736 try conf.scrollstep
<- int_of_string
s with exc
->
2737 state.text <- Printf.sprintf
"bad integer `%s': %s"
2738 s (Printexc.to_string exc
)
2740 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2745 conf.autoscrollstep
<- int_of_string
s;
2746 if state.autoscroll
<> None
2747 then state.autoscroll
<- Some
conf.autoscrollstep
2749 state.text <- Printf.sprintf
"bad integer `%s': %s"
2750 s (Printexc.to_string exc
)
2752 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2755 let mode = state.mode in
2758 let n, a, b = multicolumns_of_string s in
2759 setcolumns mode n a b;
2761 state.text <- Printf.sprintf
"bad columns `%s': %s"
2762 s (Printexc.to_string exc
)
2764 TEswitch
("columns: ", "", None
, textentry, ondone)
2769 let zoom = float (int_of_string
s) /. 100.0 in
2772 state.text <- Printf.sprintf
"bad integer `%s': %s"
2773 s (Printexc.to_string exc
)
2775 TEswitch
("zoom: ", "", None
, intentry, ondone)
2780 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2782 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2783 begin match mode with
2785 leavebirdseye beye
false;
2790 state.text <- Printf.sprintf
"bad integer `%s': %s"
2791 s (Printexc.to_string exc
)
2793 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2798 Some
(int_of_string
s)
2800 state.text <- Printf.sprintf
"bad integer `%s': %s"
2801 s (Printexc.to_string exc
);
2804 | Some angle
-> reqlayout angle
conf.proportional
2807 TEswitch
("rotation: ", "", None
, intentry, ondone)
2810 conf.icase
<- not
conf.icase
;
2811 TEdone
("case insensitive search " ^
(btos conf.icase
))
2814 conf.preload <- not
conf.preload;
2816 TEdone
("preload " ^
(btos conf.preload))
2819 conf.verbose
<- not
conf.verbose
;
2820 TEdone
("verbose " ^
(btos conf.verbose
))
2823 conf.debug
<- not
conf.debug
;
2824 TEdone
("debug " ^
(btos conf.debug
))
2827 conf.maxhfit
<- not
conf.maxhfit
;
2828 state.maxy <- calcheight ();
2829 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2832 conf.crophack
<- not
conf.crophack
;
2833 TEdone
("crophack " ^
btos conf.crophack
)
2837 match conf.maxwait
with
2839 conf.maxwait
<- Some infinity
;
2840 "always wait for page to complete"
2842 conf.maxwait
<- None
;
2843 "show placeholder if page is not ready"
2848 conf.underinfo
<- not
conf.underinfo
;
2849 TEdone
("underinfo " ^
btos conf.underinfo
)
2852 conf.savebmarks
<- not
conf.savebmarks
;
2853 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2859 match state.layout with
2864 conf.interpagespace <- int_of_string
s;
2865 state.maxy <- calcheight ();
2866 let y = getpagey pageno in
2869 state.text <- Printf.sprintf
"bad integer `%s': %s"
2870 s (Printexc.to_string exc
)
2872 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2875 reqlayout conf.angle
(not
conf.proportional
);
2876 TEdone
("proportional display " ^
btos conf.proportional
)
2879 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2880 TEdone
("trim margins " ^
btos conf.trimmargins
)
2883 conf.invert
<- not
conf.invert
;
2884 TEdone
("invert colors " ^
btos conf.invert
)
2888 cbput state.hists
.sel
s;
2891 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2895 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2901 class type lvsource
= object
2902 method getitemcount
: int
2903 method getitem
: int -> (string * int)
2904 method hasaction
: int -> bool
2913 method getactive
: int
2914 method getfirst
: int
2915 method getqsearch
: string
2916 method setqsearch
: string -> unit
2920 class virtual lvsourcebase
= object
2921 val mutable m_active
= 0
2922 val mutable m_first
= 0
2923 val mutable m_qsearch
= ""
2924 val mutable m_pan
= 0
2925 method getactive
= m_active
2926 method getfirst
= m_first
2927 method getqsearch
= m_qsearch
2928 method getpan
= m_pan
2929 method setqsearch
s = m_qsearch
<- s
2932 let withoutlastutf8 s =
2933 let len = String.length
s in
2941 let b = Char.code
s.[pos
] in
2942 if b land 0b110000 = 0b11000000
2947 if Char.code
s.[len-1] land 0x80 = 0
2951 String.sub
s 0 first;
2954 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2956 state.mode <- Textentry
(te
, onleave
);
2959 G.postRedisplay "textentrykeyboard enttext";
2961 let histaction cmd
=
2964 | Some
(action, _
) ->
2965 state.mode <- Textentry
(
2966 (c, action cmd
, opthist
, onkey
, ondone), onleave
2968 G.postRedisplay "textentry histaction"
2971 | 0xff08 -> (* backspace *)
2972 let s = withoutlastutf8 text in
2973 let len = String.length
s in
2977 G.postRedisplay "textentrykeyboard after cancel";
2980 enttext (c, s, opthist
, onkey
, ondone)
2986 G.postRedisplay "textentrykeyboard after confirm"
2988 | 0xff52 -> histaction HCprev
2989 | 0xff54 -> histaction HCnext
2990 | 0xff50 -> histaction HCfirst
2991 | 0xff57 -> histaction HClast
2993 | 0xff1b -> (* escape*)
2994 if String.length
text = 0
2996 begin match opthist
with
2998 | Some
(_
, onhistcancel
) -> onhistcancel
()
3002 G.postRedisplay "textentrykeyboard after cancel2"
3005 enttext (c, "", opthist
, onkey
, ondone)
3008 | 0xff9f | 0xffff -> () (* delete *)
3010 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3011 begin match onkey
text key with
3015 G.postRedisplay "textentrykeyboard after confirm2";
3018 enttext (c, text, opthist
, onkey
, ondone);
3022 G.postRedisplay "textentrykeyboard after cancel3"
3025 state.mode <- Textentry
(te
, onleave
);
3026 G.postRedisplay "textentrykeyboard switch";
3030 vlog "unhandled key %s" (Wsi.keyname
key)
3033 let firstof first active
=
3034 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3035 then max
0 (active
- (fstate.maxrows
/2))
3039 let calcfirst first active
=
3042 let rows = active
- first in
3043 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3047 let scrollph y maxy =
3048 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3049 let sh = float conf.winh
/. sh in
3050 let sh = max
sh (float conf.scrollh
) in
3055 else float y /. float maxy
3057 let position = (float conf.winh
-. sh) *. percent in
3060 if position +. sh > float conf.winh
3061 then float conf.winh
-. sh
3067 let coe s = (s :> uioh
);;
3069 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3071 val m_pan
= source#getpan
3072 val m_first
= source#getfirst
3073 val m_active
= source#getactive
3074 val m_qsearch
= source#getqsearch
3075 val m_prev_uioh
= state.uioh
3077 method private elemunder
y =
3078 let n = y / (fstate.fontsize
+1) in
3079 if m_first
+ n < source#getitemcount
3081 if source#hasaction
(m_first
+ n)
3082 then Some
(m_first
+ n)
3089 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3090 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3091 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3092 GlDraw.color
(1., 1., 1.);
3093 Gl.enable `texture_2d
;
3094 let fs = fstate.fontsize
in
3096 let ww = fstate.wwidth
in
3097 let tabw = 30.0*.ww in
3098 let itemcount = source#getitemcount
in
3100 if (row - m_first
) * nfs > conf.winh
3103 if row >= 0 && row < itemcount
3105 let (s, level
) = source#getitem
row in
3106 let y = (row - m_first
) * nfs in
3107 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3110 Gl.disable `texture_2d
;
3111 GlDraw.polygon_mode `both `line
;
3112 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3113 GlDraw.rect (1., float (y + 1))
3114 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3115 GlDraw.polygon_mode `both `fill
;
3116 GlDraw.color
(1., 1., 1.);
3117 Gl.enable `texture_2d
;
3120 let drawtabularstring s =
3121 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3124 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3127 let len = String.length
s - tabpos - 1 in
3128 let s1 = String.sub
s 0 tabpos
3129 and s2
= String.sub
s (tabpos + 1) len in
3130 let nx = drawstr x s1 in
3132 let x = x +. (max
tabw sw) in
3139 let _ = drawtabularstring s in
3146 Gl.disable `texture_2d
;
3148 method updownlevel incr
=
3149 let len = source#getitemcount
in
3151 if m_active
>= 0 && m_active
< len
3152 then snd
(source#getitem m_active
)
3156 if i
= len then i
-1 else if i
= -1 then 0 else
3157 let _, l = source#getitem i
in
3158 if l != curlevel then i
else flow (i
+incr
)
3160 let active = flow m_active
in
3161 let first = calcfirst m_first
active in
3162 G.postRedisplay "outline updownlevel";
3163 {< m_active
= active; m_first
= first >}
3165 method private key1
key mask
=
3166 let set1 active first qsearch
=
3167 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3169 let search active pattern incr
=
3172 if n >= 0 && n < source#getitemcount
3174 let s, _ = source#getitem
n in
3176 (try ignore
(Str.search_forward
re s 0); true
3177 with Not_found
-> false)
3179 else loop (n + incr
)
3186 let re = Str.regexp_case_fold pattern
in
3192 let itemcount = source#getitemcount
in
3193 let find start incr
=
3195 if i
= -1 || i
= itemcount
3198 if source#hasaction i
3200 else find (i
+ incr
)
3205 let set active first =
3206 let first = bound first 0 (itemcount - fstate.maxrows
) in
3208 coe {< m_active
= active; m_first
= first >}
3211 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3213 let incr1 = if incr
> 0 then 1 else -1 in
3214 if isvisible m_first m_active
3217 let next = m_active
+ incr
in
3219 if next < 0 || next >= itemcount
3221 else find next incr1
3223 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3229 let first = m_first
+ incr
in
3230 let first = bound first 0 (itemcount - 1) in
3232 let next = m_active
+ incr
in
3233 let next = bound next 0 (itemcount - 1) in
3236 let active = if next = -1 then m_active
else next in
3239 let first = min
next m_first
in
3241 if abs
(next - first) > fstate.maxrows
3247 let first = m_first
+ incr
in
3248 let first = bound first 0 (itemcount - 1) in
3250 let next = m_active
+ incr
in
3251 let next = bound next 0 (itemcount - 1) in
3252 let next = find next incr1 in
3254 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3256 let active = if m_active
= -1 then next else m_active
in
3261 if isvisible first active
3267 G.postRedisplay "listview navigate";
3271 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3272 let incr = if key = 0x72 then -1 else 1 in
3274 match search (m_active
+ incr) m_qsearch
incr with
3276 state.text <- m_qsearch ^
" [not found]";
3279 state.text <- m_qsearch
;
3280 active, firstof m_first
active
3282 G.postRedisplay "listview ctrl-r/s";
3283 set1 active first m_qsearch
;
3285 | 0xff08 -> (* backspace *)
3286 if String.length m_qsearch
= 0
3289 let qsearch = withoutlastutf8 m_qsearch
in
3290 let len = String.length
qsearch in
3294 G.postRedisplay "listview empty qsearch";
3295 set1 m_active m_first
"";
3299 match search m_active
qsearch ~
-1 with
3301 state.text <- qsearch ^
" [not found]";
3304 state.text <- qsearch;
3305 active, firstof m_first
active
3307 G.postRedisplay "listview backspace qsearch";
3308 set1 active first qsearch
3311 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3312 let pattern = m_qsearch ^
Wsi.toutf8
key in
3314 match search m_active
pattern 1 with
3316 state.text <- pattern ^
" [not found]";
3319 state.text <- pattern;
3320 active, firstof m_first
active
3322 G.postRedisplay "listview qsearch add";
3323 set1 active first pattern;
3325 | 0xff1b -> (* escape *)
3327 if String.length m_qsearch
= 0
3329 G.postRedisplay "list view escape";
3332 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3334 | None
-> m_prev_uioh
3339 G.postRedisplay "list view kill qsearch";
3340 source#setqsearch
"";
3341 coe {< m_qsearch
= "" >}
3344 | 0xff0d -> (* return *)
3346 let self = {< m_qsearch
= "" >} in
3347 source#setqsearch
"";
3349 G.postRedisplay "listview enter";
3350 if m_active
>= 0 && m_active
< source#getitemcount
3352 source#exit
(coe self) false m_active m_first m_pan
"";
3355 source#exit
(coe self) true m_active m_first m_pan
"";
3358 begin match opt with
3359 | None
-> m_prev_uioh
3363 | 0xff9f | 0xffff -> (* delete *)
3366 | 0xff52 -> navigate ~
-1 (* up *)
3367 | 0xff54 -> navigate 1 (* down *)
3368 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3369 | 0xff56 -> navigate fstate.maxrows
(* next *)
3371 | 0xff53 -> (* right *)
3373 G.postRedisplay "listview right";
3374 coe {< m_pan
= m_pan
- 1 >}
3376 | 0xff51 -> (* left *)
3378 G.postRedisplay "listview left";
3379 coe {< m_pan
= m_pan
+ 1 >}
3381 | 0xff50 -> (* home *)
3382 let active = find 0 1 in
3383 G.postRedisplay "listview home";
3386 | 0xff57 -> (* end *)
3387 let first = max
0 (itemcount - fstate.maxrows
) in
3388 let active = find (itemcount - 1) ~
-1 in
3389 G.postRedisplay "listview end";
3392 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3396 dolog "listview unknown key %#x" key; coe self
3398 method key key mask
=
3399 match state.mode with
3400 | Textentry te
-> textentrykeyboard key mask te
; coe self
3401 | _ -> self#key1
key mask
3403 method button button down
x y _ =
3406 | 1 when x > conf.winw
- conf.scrollbw
->
3407 G.postRedisplay "listview scroll";
3410 let _, position, sh = self#
scrollph in
3411 if y > truncate
position && y < truncate
(position +. sh)
3413 state.mstate
<- Mscrolly
;
3417 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3418 let first = truncate
(s *. float source#getitemcount
) in
3419 let first = min source#getitemcount
first in
3420 Some
(coe {< m_first
= first; m_active
= first >})
3422 state.mstate
<- Mnone
;
3425 | 1 when not down
->
3426 begin match self#elemunder
y with
3428 G.postRedisplay "listview click";
3430 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3434 | n when (n == 4 || n == 5) && not down
->
3435 let len = source#getitemcount
in
3437 if n = 5 && m_first
+ fstate.maxrows
>= len
3441 let first = m_first
+ (if n == 4 then -1 else 1) in
3442 bound first 0 (len - 1)
3444 G.postRedisplay "listview wheel";
3445 Some
(coe {< m_first
= first >})
3450 | None
-> m_prev_uioh
3454 match state.mstate
with
3456 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3457 let first = truncate
(s *. float source#getitemcount
) in
3458 let first = min source#getitemcount
first in
3459 G.postRedisplay "listview motion";
3460 coe {< m_first
= first; m_active
= first >}
3463 method pmotion
x y =
3464 if x < conf.winw
- conf.scrollbw
3467 match self#elemunder
y with
3468 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3469 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3473 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3478 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3482 method infochanged
_ = ()
3484 method scrollpw
= (0, 0.0, 0.0)
3486 let nfs = fstate.fontsize
+ 1 in
3487 let y = m_first
* nfs in
3488 let itemcount = source#getitemcount
in
3489 let maxi = max
0 (itemcount - fstate.maxrows
) in
3490 let maxy = maxi * nfs in
3491 let p, h = scrollph y maxy in
3494 method modehash
= modehash
3497 class outlinelistview ~source
=
3500 ~source
:(source
:> lvsource
)
3502 ~modehash
:(findkeyhash conf "outline")
3505 method key key mask
=
3506 let calcfirst first active =
3509 let rows = active - first in
3510 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3514 let active = m_active
+ incr in
3515 let active = bound active 0 (source#getitemcount
- 1) in
3516 let first = calcfirst m_first
active in
3517 G.postRedisplay "outline navigate";
3518 coe {< m_active
= active; m_first
= first >}
3520 let ctrl = Wsi.withctrl mask
in
3522 | 110 when ctrl -> (* ctrl-n *)
3523 source#narrow m_qsearch
;
3524 G.postRedisplay "outline ctrl-n";
3525 coe {< m_first
= 0; m_active
= 0 >}
3527 | 117 when ctrl -> (* ctrl-u *)
3529 G.postRedisplay "outline ctrl-u";
3531 coe {< m_first
= 0; m_active
= 0 >}
3533 | 108 when ctrl -> (* ctrl-l *)
3534 let first = m_active
- (fstate.maxrows
/ 2) in
3535 G.postRedisplay "outline ctrl-l";
3536 coe {< m_first
= first >}
3538 | 0xff9f | 0xffff -> (* delete *)
3539 source#remove m_active
;
3540 G.postRedisplay "outline delete";
3541 let active = max
0 (m_active
-1) in
3542 coe {< m_first
= firstof m_first
active;
3543 m_active
= active >}
3545 | 0xff52 -> navigate ~
-1 (* up *)
3546 | 0xff54 -> navigate 1 (* down *)
3547 | 0xff55 -> (* prior *)
3548 navigate ~
-(fstate.maxrows
)
3549 | 0xff56 -> (* next *)
3550 navigate fstate.maxrows
3552 | 0xff53 -> (* [ctrl-]right *)
3556 G.postRedisplay "outline ctrl right";
3557 {< m_pan
= m_pan
+ 1 >}
3559 else self#updownlevel
1
3563 | 0xff51 -> (* [ctrl-]left *)
3567 G.postRedisplay "outline ctrl left";
3568 {< m_pan
= m_pan
- 1 >}
3570 else self#updownlevel ~
-1
3574 | 0xff50 -> (* home *)
3575 G.postRedisplay "outline home";
3576 coe {< m_first
= 0; m_active
= 0 >}
3578 | 0xff57 -> (* end *)
3579 let active = source#getitemcount
- 1 in
3580 let first = max
0 (active - fstate.maxrows
) in
3581 G.postRedisplay "outline end";
3582 coe {< m_active
= active; m_first
= first >}
3584 | _ -> super#
key key mask
3587 let outlinesource usebookmarks
=
3590 inherit lvsourcebase
3591 val mutable m_items
= empty
3592 val mutable m_orig_items
= empty
3593 val mutable m_prev_items
= empty
3594 val mutable m_narrow_pattern
= ""
3595 val mutable m_hadremovals
= false
3597 method getitemcount
=
3598 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3601 if n == Array.length m_items
&& m_hadremovals
3603 ("[Confirm removal]", 0)
3605 let s, n, _ = m_items
.(n) in
3608 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3609 ignore
(uioh
, first, qsearch);
3610 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3612 if String.length m_narrow_pattern
= 0
3618 if not
confrimremoval
3620 let _, _, anchor = m_items
.(active) in
3625 state.bookmarks
<- Array.to_list m_items
;
3626 m_orig_items
<- m_items
;
3629 else m_items
<- items;
3633 method hasaction
_ = true
3636 if Array.length m_items
!= Array.length m_orig_items
3637 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3640 method narrow
pattern =
3641 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3645 let rec loop accu n =
3648 m_narrow_pattern
<- pattern;
3649 m_items
<- Array.of_list
accu
3652 let (s, _, _) as o = m_items
.(n) in
3654 if (try ignore
(Str.search_forward
re s 0); true
3655 with Not_found
-> false)
3661 loop [] (Array.length m_items
- 1)
3666 then Array.of_list
state.bookmarks
3669 m_items
<- m_orig_items
3674 if m >= 0 && m < Array.length m_items
3676 m_hadremovals
<- true;
3677 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3678 let n = if n >= m then n+1 else n in
3683 method reset
anchor items =
3684 m_hadremovals
<- false;
3685 if m_orig_items
== empty || m_prev_items
!= items
3687 m_orig_items
<- items;
3688 if String.length m_narrow_pattern
= 0
3689 then m_items
<- items;
3691 m_prev_items
<- items;
3692 let rely = getanchory anchor in
3694 let rec loop n best bestd
=
3695 if n = Array.length m_items
3698 let (_, _, anchor) = m_items
.(n) in
3699 let orely = getanchory anchor in
3700 let d = abs
(orely - rely) in
3703 else loop (n+1) best bestd
3708 m_first
<- firstof m_first
active
3712 let enterselector usebookmarks
=
3713 let source = outlinesource usebookmarks
in
3717 then Array.of_list
state.bookmarks
3720 if Array.length
outlines = 0
3722 showtext ' ' errmsg
;
3725 state.text <- source#greetmsg
;
3726 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3727 let anchor = getanchor () in
3728 source#reset
anchor outlines;
3729 state.uioh
<- coe (new outlinelistview ~
source);
3730 G.postRedisplay "enter selector";
3734 let enteroutlinemode =
3735 let f = enterselector false in
3736 fun ()-> f "Document has no outline";
3739 let enterbookmarkmode =
3740 let f = enterselector true in
3741 fun () -> f "Document has no bookmarks (yet)";
3744 let color_of_string s =
3745 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3746 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3750 let color_to_string (r
, g
, b) =
3751 let r = truncate
(r *. 256.0)
3752 and g
= truncate
(g
*. 256.0)
3753 and b = truncate
(b *. 256.0) in
3754 Printf.sprintf
"%d/%d/%d" r g
b
3757 let irect_of_string s =
3758 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3761 let irect_to_string (x0,y0,x1,y1) =
3762 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3765 let makecheckers () =
3766 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3768 converted by Issac Trotts. July 25, 2002 *)
3769 let image_height = 64
3770 and image_width
= 64 in
3774 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3776 for i
= 0 to image_width
- 1 do
3777 for j
= 0 to image_height - 1 do
3778 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3779 (if (i
land 8 ) lxor (j
land 8) = 0
3780 then [|255;255;255|] else [|200;200;200|])
3785 let image = make_image () in
3786 let id = GlTex.gen_texture
() in
3787 GlTex.bind_texture `texture_2d
id;
3788 GlPix.store
(`unpack_alignment
1);
3789 GlTex.image2d
image;
3790 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3793 `mag_filter `nearest
;
3794 `min_filter `nearest
];
3798 let setcheckers enabled
=
3799 match state.texid
with
3801 if enabled
then state.texid
<- Some
(makecheckers ())
3806 GlTex.delete_texture texid
;
3807 state.texid
<- None
;
3811 let int_of_string_with_suffix s =
3812 let l = String.length
s in
3816 let suffix = Char.lowercase
s.[l-1] in
3818 | 'k'
-> String.sub
s 0 (l-1), 10
3819 | '
m'
-> String.sub
s 0 (l-1), 20
3820 | 'g'
-> String.sub
s 0 (l-1), 30
3824 let n = int_of_string
s1 in
3825 let m = n lsl shift
in
3827 then raise
(Failure
"value too large")
3831 let string_with_suffix_of_int n =
3839 if n land ((1 lsl 20) - 1) = 0
3842 if n land ((1 lsl 10) - 1) = 0
3849 let h = n mod 1000 in
3852 then string_of_int
h ^
s
3854 let s = Printf.sprintf
"_%03d%s" h s in
3861 let defghyllscroll = (40, 8, 32);;
3862 let ghyllscroll_of_string s =
3863 let (n, a, b) as nab
=
3866 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3868 if n <= a || n <= b || a >= b
3869 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3873 let ghyllscroll_to_string ((n, a, b) as nab
) =
3874 if nab
= defghyllscroll
3876 else Printf.sprintf
"%d,%d,%d" n a b;
3879 let describe_location () =
3881 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3883 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3884 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3888 else (100. *. (float state.y /. float maxy))
3892 Printf.sprintf
"page %d of %d [%.2f%%]"
3893 (fn+1) state.pagecount
percent
3896 "pages %d-%d of %d [%.2f%%]"
3897 (fn+1) (ln
+1) state.pagecount
percent
3901 let btos b = if b then "\xe2\x88\x9a" else "" in
3902 let showextended = ref false in
3903 let leave mode = function
3904 | Confirm
-> state.mode <- mode
3905 | Cancel
-> state.mode <- mode in
3908 val mutable m_first_time
= true
3909 val mutable m_l
= []
3910 val mutable m_a
= [||]
3911 val mutable m_prev_uioh
= nouioh
3912 val mutable m_prev_mode
= View
3914 inherit lvsourcebase
3916 method reset prev_mode prev_uioh
=
3917 m_a
<- Array.of_list
(List.rev m_l
);
3919 m_prev_mode
<- prev_mode
;
3920 m_prev_uioh
<- prev_uioh
;
3924 if n >= Array.length m_a
3928 | _, _, _, Action
_ -> m_active
<- n
3932 m_first_time
<- false;
3935 method int name get
set =
3937 (name
, `
int get
, 1, Action
(
3940 try set (int_of_string
s)
3942 state.text <- Printf.sprintf
"bad integer `%s': %s"
3943 s (Printexc.to_string exn
)
3946 let te = name ^
": ", "", None
, intentry, ondone in
3947 state.mode <- Textentry
(te, leave m_prev_mode
);
3951 method int_with_suffix name get
set =
3953 (name
, `intws get
, 1, Action
(
3956 try set (int_of_string_with_suffix s)
3958 state.text <- Printf.sprintf
"bad integer `%s': %s"
3959 s (Printexc.to_string exn
)
3963 name ^
": ", "", None
, intentry_with_suffix, ondone
3965 state.mode <- Textentry
(te, leave m_prev_mode
);
3969 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3971 (name
, `
bool (btos, get
), offset
, Action
(
3978 method color name get
set =
3980 (name
, `color get
, 1, Action
(
3982 let invalid = (nan
, nan
, nan
) in
3985 try color_of_string s
3987 state.text <- Printf.sprintf
"bad color `%s': %s"
3988 s (Printexc.to_string exn
);
3994 let te = name ^
": ", "", None
, textentry, ondone in
3995 state.text <- color_to_string (get
());
3996 state.mode <- Textentry
(te, leave m_prev_mode
);
4000 method string name get
set =
4002 (name
, `
string get
, 1, Action
(
4004 let ondone s = set s in
4005 let te = name ^
": ", "", None
, textentry, ondone in
4006 state.mode <- Textentry
(te, leave m_prev_mode
);
4010 method colorspace name get
set =
4012 (name
, `
string get
, 1, Action
(
4015 let vals = [| "rgb"; "bgr"; "gray" |] in
4017 inherit lvsourcebase
4020 m_active
<- int_of_colorspace conf.colorspace
;
4023 method getitemcount
= Array.length
vals
4024 method getitem
n = (vals.(n), 0)
4025 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4026 ignore
(uioh
, first, pan
, qsearch);
4027 if not cancel
then set active;
4029 method hasaction
_ = true
4033 let modehash = findkeyhash conf "info" in
4034 coe (new listview ~
source ~trusted
:true ~
modehash)
4037 method caption
s offset
=
4038 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4040 method caption2
s f offset
=
4041 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4043 method getitemcount
= Array.length m_a
4046 let tostr = function
4047 | `
int f -> string_of_int
(f ())
4048 | `intws
f -> string_with_suffix_of_int (f ())
4050 | `color
f -> color_to_string (f ())
4051 | `
bool (btos, f) -> btos (f ())
4054 let name, t
, offset
, _ = m_a
.(n) in
4055 ((let s = tostr t
in
4056 if String.length
s > 0
4057 then Printf.sprintf
"%s\t%s" name s
4061 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4065 m_qsearch
<- qsearch;
4067 match m_a
.(active) with
4068 | _, _, _, Action
f -> f uioh
4080 method hasaction
n =
4082 | _, _, _, Action
_ -> true
4086 let rec fillsrc prevmode prevuioh
=
4087 let sep () = src#caption
"" 0 in
4088 let colorp name get
set =
4090 (fun () -> color_to_string (get
()))
4093 let c = color_of_string v in
4096 state.text <- Printf.sprintf
"bad color `%s': %s"
4097 v (Printexc.to_string exn
);
4100 let oldmode = state.mode in
4101 let birdseye = isbirdseye state.mode in
4103 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4105 src#
bool "presentation mode"
4106 (fun () -> conf.presentation)
4108 conf.presentation <- v;
4109 state.anchor <- getanchor ();
4112 src#
bool "ignore case in searches"
4113 (fun () -> conf.icase
)
4114 (fun v -> conf.icase
<- v);
4117 (fun () -> conf.preload)
4118 (fun v -> conf.preload <- v);
4120 src#
bool "highlight links"
4121 (fun () -> conf.hlinks
)
4122 (fun v -> conf.hlinks
<- v);
4124 src#
bool "under info"
4125 (fun () -> conf.underinfo
)
4126 (fun v -> conf.underinfo
<- v);
4128 src#
bool "persistent bookmarks"
4129 (fun () -> conf.savebmarks
)
4130 (fun v -> conf.savebmarks
<- v);
4132 src#
bool "proportional display"
4133 (fun () -> conf.proportional
)
4134 (fun v -> reqlayout conf.angle
v);
4136 src#
bool "trim margins"
4137 (fun () -> conf.trimmargins
)
4138 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4140 src#
bool "persistent location"
4141 (fun () -> conf.jumpback
)
4142 (fun v -> conf.jumpback
<- v);
4145 src#
int "inter-page space"
4146 (fun () -> conf.interpagespace)
4148 conf.interpagespace <- n;
4150 match state.layout with
4155 state.maxy <- calcheight ();
4156 let y = getpagey pageno in
4161 (fun () -> conf.pagebias
)
4162 (fun v -> conf.pagebias
<- v);
4164 src#
int "scroll step"
4165 (fun () -> conf.scrollstep
)
4166 (fun n -> conf.scrollstep
<- n);
4168 src#
int "auto scroll step"
4170 match state.autoscroll
with
4172 | _ -> conf.autoscrollstep
)
4174 if state.autoscroll
<> None
4175 then state.autoscroll
<- Some
n;
4176 conf.autoscrollstep
<- n);
4179 (fun () -> truncate
(conf.zoom *. 100.))
4180 (fun v -> setzoom ((float v) /. 100.));
4183 (fun () -> conf.angle
)
4184 (fun v -> reqlayout v conf.proportional
);
4186 src#
int "scroll bar width"
4187 (fun () -> state.scrollw
)
4191 reshape conf.winw
conf.winh
;
4194 src#
int "scroll handle height"
4195 (fun () -> conf.scrollh
)
4196 (fun v -> conf.scrollh
<- v;);
4198 src#
int "thumbnail width"
4199 (fun () -> conf.thumbw
)
4201 conf.thumbw
<- min
4096 v;
4204 leavebirdseye beye
false;
4209 let mode = state.mode in
4210 src#
string "columns"
4212 match conf.columns
with
4214 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4215 | Csplit
(count
, _) -> "-" ^ string_of_int count
4218 let n, a, b = multicolumns_of_string v in
4219 setcolumns mode n a b);
4222 src#caption
"Presentation mode" 0;
4223 src#
bool "scrollbar visible"
4224 (fun () -> conf.scrollbarinpm
)
4226 if v != conf.scrollbarinpm
4228 conf.scrollbarinpm
<- v;
4229 if conf.presentation
4231 state.scrollw
<- if v then conf.scrollbw
else 0;
4232 reshape conf.winw
conf.winh
;
4238 src#caption
"Pixmap cache" 0;
4239 src#int_with_suffix
"size (advisory)"
4240 (fun () -> conf.memlimit
)
4241 (fun v -> conf.memlimit
<- v);
4244 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4245 (string_with_suffix_of_int state.memused
)
4246 (Hashtbl.length
state.tilemap
)) 1;
4249 src#caption
"Layout" 0;
4250 src#caption2
"Dimension"
4252 Printf.sprintf
"%dx%d (virtual %dx%d)"
4258 src#caption2
"Position" (fun () ->
4259 Printf.sprintf
"%dx%d" state.x state.y
4262 src#caption2
"Visible" (fun () -> describe_location ()) 1
4266 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4267 "Save these parameters as global defaults at exit"
4268 (fun () -> conf.bedefault
)
4269 (fun v -> conf.bedefault
<- v)
4273 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4274 src#
bool ~offset
:0 ~
btos "Extended parameters"
4275 (fun () -> !showextended)
4276 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4280 (fun () -> conf.checkers
)
4281 (fun v -> conf.checkers
<- v; setcheckers v);
4282 src#
bool "update cursor"
4283 (fun () -> conf.updatecurs
)
4284 (fun v -> conf.updatecurs
<- v);
4286 (fun () -> conf.verbose
)
4287 (fun v -> conf.verbose
<- v);
4288 src#
bool "invert colors"
4289 (fun () -> conf.invert
)
4290 (fun v -> conf.invert
<- v);
4292 (fun () -> conf.maxhfit
)
4293 (fun v -> conf.maxhfit
<- v);
4294 src#
bool "redirect stderr"
4295 (fun () -> conf.redirectstderr)
4296 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4297 src#
string "uri launcher"
4298 (fun () -> conf.urilauncher
)
4299 (fun v -> conf.urilauncher
<- v);
4300 src#
string "path launcher"
4301 (fun () -> conf.pathlauncher
)
4302 (fun v -> conf.pathlauncher
<- v);
4303 src#
string "tile size"
4304 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4307 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4308 conf.tilew
<- max
64 w;
4309 conf.tileh
<- max
64 h;
4312 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4313 v (Printexc.to_string exn
));
4314 src#
int "texture count"
4315 (fun () -> conf.texcount
)
4318 then conf.texcount
<- v
4319 else showtext '
!'
" Failed to set texture count please retry later"
4321 src#
int "slice height"
4322 (fun () -> conf.sliceheight
)
4324 conf.sliceheight
<- v;
4325 wcmd "sliceh %d" conf.sliceheight
;
4327 src#
int "anti-aliasing level"
4328 (fun () -> conf.aalevel
)
4330 conf.aalevel
<- bound v 0 8;
4331 state.anchor <- getanchor ();
4332 opendoc state.path
state.password
;
4334 src#
int "ui font size"
4335 (fun () -> fstate.fontsize
)
4336 (fun v -> setfontsize (bound v 5 100));
4337 colorp "background color"
4338 (fun () -> conf.bgcolor
)
4339 (fun v -> conf.bgcolor
<- v);
4340 src#
bool "crop hack"
4341 (fun () -> conf.crophack
)
4342 (fun v -> conf.crophack
<- v);
4343 src#
string "trim fuzz"
4344 (fun () -> irect_to_string conf.trimfuzz
)
4347 conf.trimfuzz
<- irect_of_string v;
4349 then settrim true conf.trimfuzz
;
4351 state.text <- Printf.sprintf
"bad irect `%s': %s"
4352 v (Printexc.to_string exn
)
4354 src#
string "throttle"
4356 match conf.maxwait
with
4357 | None
-> "show place holder if page is not ready"
4360 then "wait for page to fully render"
4362 "wait " ^ string_of_float
time
4363 ^
" seconds before showing placeholder"
4367 let f = float_of_string
v in
4369 then conf.maxwait
<- None
4370 else conf.maxwait
<- Some
f
4372 state.text <- Printf.sprintf
"bad time `%s': %s"
4373 v (Printexc.to_string exn
)
4375 src#
string "ghyll scroll"
4377 match conf.ghyllscroll
with
4379 | Some nab
-> ghyllscroll_to_string nab
4384 if String.length
v = 0
4386 else Some
(ghyllscroll_of_string v)
4388 conf.ghyllscroll
<- gs
4390 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4391 v (Printexc.to_string exn
)
4393 src#
string "selection command"
4394 (fun () -> conf.selcmd
)
4395 (fun v -> conf.selcmd
<- v);
4396 src#colorspace
"color space"
4397 (fun () -> colorspace_to_string conf.colorspace
)
4399 conf.colorspace
<- colorspace_of_int v;
4406 src#caption
"Document" 0;
4407 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4408 src#caption2
"Pages"
4409 (fun () -> string_of_int
state.pagecount
) 1;
4410 src#caption2
"Dimensions"
4411 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4415 src#caption
"Trimmed margins" 0;
4416 src#caption2
"Dimensions"
4417 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4420 src#reset prevmode prevuioh
;
4424 let prevmode = state.mode
4425 and prevuioh
= state.uioh in
4426 fillsrc prevmode prevuioh
;
4427 let source = (src :> lvsource
) in
4428 let modehash = findkeyhash conf "info" in
4429 state.uioh <- coe (object (self)
4430 inherit listview ~
source ~trusted
:true ~
modehash as super
4431 val mutable m_prevmemused
= 0
4432 method infochanged
= function
4434 if m_prevmemused
!= state.memused
4436 m_prevmemused
<- state.memused
;
4437 G.postRedisplay "memusedchanged";
4439 | Pdim
-> G.postRedisplay "pdimchanged"
4440 | Docinfo
-> fillsrc prevmode prevuioh
4442 method key key mask
=
4443 if not
(Wsi.withctrl mask
)
4446 | 0xff51 -> coe (self#updownlevel ~
-1)
4447 | 0xff53 -> coe (self#updownlevel
1)
4448 | _ -> super#
key key mask
4449 else super#
key key mask
4451 G.postRedisplay "info";
4457 inherit lvsourcebase
4458 method getitemcount
= Array.length
state.help
4460 let s, n, _ = state.help
.(n) in
4463 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4467 m_qsearch
<- qsearch;
4468 match state.help
.(active) with
4469 | _, _, Action
f -> Some
(f uioh)
4479 method hasaction
n =
4480 match state.help
.(n) with
4481 | _, _, Action
_ -> true
4488 let modehash = findkeyhash conf "help" in
4489 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4490 G.postRedisplay "help";
4495 let re = Str.regexp
"[\r\n]" in
4497 inherit lvsourcebase
4498 val mutable m_items
= [||]
4500 method getitemcount
= 1 + Array.length m_items
4505 else m_items
.(n-1), 0
4507 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4512 then Buffer.clear
state.errmsgs
;
4513 m_qsearch
<- qsearch;
4520 method hasaction
n =
4524 state.newerrmsgs
<- false;
4525 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4526 m_items
<- Array.of_list
l
4534 let source = (msgsource :> lvsource
) in
4535 let modehash = findkeyhash conf "listview" in
4536 state.uioh <- coe (object
4537 inherit listview ~
source ~trusted
:false ~
modehash as super
4540 then msgsource#reset
;
4543 G.postRedisplay "msgs";
4546 let quickbookmark ?title
() =
4547 match state.layout with
4553 let sec = Unix.gettimeofday
() in
4554 let tm = Unix.localtime
sec in
4555 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4559 (tm.Unix.tm_year
+ 1900)
4562 | Some
title -> title
4565 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4570 state.fullscreen
<- None
;
4574 let setautoscrollspeed step goingdown
=
4575 let incr = max
1 ((abs step
) / 2) in
4576 let incr = if goingdown
then incr else -incr in
4577 let astep = step
+ incr in
4578 state.autoscroll
<- Some
astep;
4581 let gotounder = function
4582 | Ulinkgoto
(pageno, top) ->
4586 gotopage1 pageno top;
4592 | Uremote
(filename
, pageno) ->
4594 if Sys.file_exists filename
4597 let dir = Filename.dirname
state.path in
4598 let path = Filename.concat
dir filename
in
4599 if Sys.file_exists
path
4603 if String.length
path > 0
4605 let anchor = getanchor () in
4606 let ranchor = state.path, state.password
, anchor in
4607 state.anchor <- (pageno, 0.0);
4608 state.ranchors
<- ranchor :: state.ranchors
;
4611 else showtext '
!'
("Could not find " ^ filename
)
4613 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4617 match conf.columns
with
4619 | _ -> conf.zoom > 1.0
4622 let viewkeyboard key mask
=
4624 let mode = state.mode in
4625 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4628 G.postRedisplay "view:enttext"
4630 let ctrl = Wsi.withctrl mask
in
4635 | 0xff63 -> (* insert *)
4636 if conf.angle
mod 360 = 0
4638 state.mode <- LinkNav
(Ltgendir
0);
4641 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4643 | 0xff1b | 113 -> (* escape / q *)
4644 begin match state.mstate
with
4646 state.mstate
<- Mnone
;
4647 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4648 G.postRedisplay "kill zoom rect";
4650 match state.ranchors
with
4652 | (path, password
, anchor) :: rest
->
4653 state.ranchors
<- rest
;
4654 state.anchor <- anchor;
4655 opendoc path password
4658 | 0xff08 -> (* backspace *)
4659 let y = getnav ~
-1 in
4660 gotoy_and_clear_text y
4668 G.postRedisplay "dehighlight";
4670 | 47 | 63 -> (* / ? *)
4671 let ondone isforw
s =
4672 cbput state.hists
.pat
s;
4673 state.searchpattern
<- s;
4676 let s = String.create
1 in
4677 s.[0] <- Char.chr
key;
4678 enttext (s, "", Some
(onhist state.hists
.pat
),
4679 textentry, ondone (key = 47))
4681 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4682 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4683 setzoom (conf.zoom +. incr)
4685 | 43 | 0xffab -> (* + *)
4688 try int_of_string
s with exc
->
4689 state.text <- Printf.sprintf
"bad integer `%s': %s"
4690 s (Printexc.to_string exc
);
4696 state.text <- "page bias is now " ^ string_of_int
n;
4699 enttext ("page bias: ", "", None
, intentry, ondone)
4701 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4702 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4703 setzoom (max
0.01 (conf.zoom -. decr))
4705 | 45 | 0xffad -> (* - *)
4706 let ondone msg
= state.text <- msg
in
4708 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4709 optentry state.mode, ondone
4712 | 48 when ctrl -> (* ctrl-0 *)
4715 | 49 when ctrl -> (* 1 *)
4716 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4720 | 0xffc6 -> (* f9 *)
4723 | 57 when ctrl -> (* ctrl-9 *)
4726 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4727 when not
ctrl -> (* 0..9 *)
4730 try int_of_string
s with exc
->
4731 state.text <- Printf.sprintf
"bad integer `%s': %s"
4732 s (Printexc.to_string exc
);
4738 cbput state.hists
.pag
(string_of_int
n);
4739 gotopage1 (n + conf.pagebias
- 1) 0;
4742 let pageentry text key =
4743 match Char.unsafe_chr
key with
4744 | 'g'
-> TEdone
text
4745 | _ -> intentry text key
4747 let text = "x" in text.[0] <- Char.chr
key;
4748 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4751 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4752 reshape conf.winw
conf.winh
;
4755 conf.hlinks
<- not
conf.hlinks
;
4756 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4757 G.postRedisplay "toggle highlightlinks";
4760 state.glinks
<- true;
4761 let mode = state.mode in
4762 state.mode <- Textentry
(
4763 (":", "", None
, linknentry, linkndone (fun under ->
4768 state.glinks
<- false;
4772 G.postRedisplay "view:linkent(F)"
4775 state.glinks
<- true;
4776 let mode = state.mode in
4777 state.mode <- Textentry
(
4778 (":", "", None
, linknentry, linkndone (fun under ->
4779 match Ne.pipe () with
4781 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4782 (Printexc.to_string exn
));
4785 popen conf.selcmd
[r, 0; w, -1]
4788 (Printf.sprintf
"failed to execute %s: %s"
4789 conf.selcmd
(Printexc.to_string exn
))
4792 Ne.clo fd
(fun msg
->
4793 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4796 let s = undertext under in
4798 let l = String.length
s in
4799 let n = Unix.write
w s 0 l in
4804 "failed to write %d characters to sel pipe, wrote %d"
4809 (Printf.sprintf
"failed to write to sel pipe: %s"
4810 (Printexc.to_string exn
)
4818 state.glinks
<- false;
4822 G.postRedisplay "view:linkent"
4825 begin match state.autoscroll
with
4827 conf.autoscrollstep
<- step
;
4828 state.autoscroll
<- None
4830 if conf.autoscrollstep
= 0
4831 then state.autoscroll
<- Some
1
4832 else state.autoscroll
<- Some
conf.autoscrollstep
4835 | 112 when ctrl -> (* ctrl-p *)
4839 conf.presentation <- not
conf.presentation;
4840 if conf.presentation
4842 if not
conf.scrollbarinpm
4843 then state.scrollw
<- 0;
4846 state.scrollw
<- conf.scrollbw
;
4848 showtext ' '
("presentation mode " ^
4849 if conf.presentation then "on" else "off");
4850 state.anchor <- getanchor ();
4854 begin match state.fullscreen
with
4856 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4859 state.fullscreen
<- None
;
4864 gotoy_and_clear_text 0
4867 gotopage1 (state.pagecount
- 1) 0
4869 | 112 | 78 -> (* p|N *)
4870 search state.searchpattern
false
4872 | 110 | 0xffc0 -> (* n|F3 *)
4873 search state.searchpattern
true
4876 begin match state.layout with
4879 gotoy_and_clear_text (getpagey l.pageno)
4883 begin match List.rev
state.layout with
4886 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4887 gotoy_and_clear_text (getpagey pageno)
4890 | 0xff9f | 0xffff -> (* delete *)
4891 begin match state.layout with
4894 let pageno = max
0 (l.pageno-1) in
4895 gotoy_and_clear_text (getpagey pageno)
4899 showtext ' '
(describe_location ());
4902 begin match state.layout with
4905 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4910 enterbookmarkmode ()
4912 | 104 | 0xffbe -> (* h|F1 *)
4918 | 101 when conf.redirectstderr -> (* e *)
4923 match state.layout with
4926 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4930 enttext ("bookmark: ", "", None
, textentry, ondone)
4934 showtext ' '
"Quick bookmark added";
4937 begin match state.layout with
4939 let rect = getpdimrect
l.pagedimno
in
4943 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4944 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4946 (truncate
(rect.(1) -. rect.(0)),
4947 truncate
(rect.(3) -. rect.(0)))
4949 let w = truncate
((float w)*.conf.zoom)
4950 and h = truncate
((float h)*.conf.zoom) in
4953 state.anchor <- getanchor ();
4954 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4956 G.postRedisplay "z";
4961 | 50 when ctrl -> (* ctrl-2 *)
4962 let maxw = getmaxw
() in
4964 then setzoom (maxw /. float conf.winw
)
4966 | 60 | 62 -> (* < > *)
4967 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4969 | 91 | 93 -> (* [ ] *)
4971 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4973 G.postRedisplay "brightness";
4975 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4976 setzoom state.prevzoom
4978 | 107 | 0xff52 -> (* k up *)
4979 begin match state.autoscroll
with
4981 begin match state.mode with
4982 | Birdseye beye
-> upbirdseye 1 beye
4985 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4986 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4989 setautoscrollspeed n false
4992 | 106 | 0xff54 -> (* j down *)
4993 begin match state.autoscroll
with
4995 begin match state.mode with
4996 | Birdseye beye
-> downbirdseye 1 beye
4999 then gotoy_and_clear_text (clamp (conf.winh
/2))
5000 else gotoy_and_clear_text (clamp conf.scrollstep
)
5003 setautoscrollspeed n true
5006 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5014 let dx = if key = 0xff51 then dx else -dx in
5015 state.x <- state.x + dx;
5016 gotoy_and_clear_text state.y
5019 G.postRedisplay "lef/right"
5022 | 0xff55 -> (* prior *)
5026 match state.layout with
5028 | l :: _ -> state.y - l.pagey
5034 | 0xff56 -> (* next *)
5038 match List.rev
state.layout with
5040 | l :: _ -> getpagey l.pageno
5046 | 0xff50 -> gotoghyll 0
5047 | 0xff57 -> gotoghyll (clamp state.maxy)
5048 | 0xff53 when Wsi.withalt mask
->
5049 gotoghyll (getnav ~
-1)
5050 | 0xff51 when Wsi.withalt mask
->
5051 gotoghyll (getnav 1)
5054 state.anchor <- getanchor ();
5055 opendoc state.path state.password
5057 | 118 when conf.debug
-> (* v *)
5060 match getopaque l.pageno with
5063 let x0, y0, x1, y1 = pagebbox opaque
in
5064 let a,b = float x0, float y0 in
5065 let c,d = float x1, float y0 in
5066 let e,f = float x1, float y1 in
5067 let h,j
= float x0, float y1 in
5068 let rect = (a,b,c,d,e,f,h,j
) in
5070 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5072 G.postRedisplay "v";
5075 vlog "huh? %s" (Wsi.keyname
key)
5078 let linknavkeyboard key mask
linknav =
5079 let getpage pageno =
5080 let rec loop = function
5082 | l :: _ when l.pageno = pageno -> Some
l
5083 | _ :: rest
-> loop rest
5084 in loop state.layout
5086 let doexact (pageno, n) =
5087 match getopaque pageno, getpage pageno with
5088 | Some opaque
, Some
l ->
5091 let under = getlink opaque
n in
5092 G.postRedisplay "link gotounder";
5098 | 0xff50 -> (* home *)
5099 Some
(findlink opaque LDfirst
), -1
5101 | 0xff57 -> (* end *)
5102 Some
(findlink opaque LDlast
), 1
5104 | 0xff51 -> (* left *)
5105 Some
(findlink opaque
(LDleft
n)), -1
5107 | 0xff53 -> (* right *)
5108 Some
(findlink opaque
(LDright
n)), 1
5110 | 0xff52 -> (* up *)
5111 Some
(findlink opaque
(LDup
n)), -1
5113 | 0xff54 -> (* down *)
5114 Some
(findlink opaque
(LDdown
n)), 1
5119 begin match findpwl
l.pageno dir with
5123 state.mode <- LinkNav
(Ltgendir
dir);
5124 let y, h = getpageyh pageno in
5127 then y + h - conf.winh
5132 begin match getopaque pageno, getpage pageno with
5133 | Some opaque
, Some
_ ->
5135 let ld = if dir > 0 then LDfirst
else LDlast
in
5138 begin match link with
5140 showlinktype (getlink opaque
m);
5141 state.mode <- LinkNav
(Ltexact
(pageno, m));
5142 G.postRedisplay "linknav jpage";
5149 begin match opt with
5150 | Some Lnotfound
-> pwl l dir;
5151 | Some
(Lfound
m) ->
5155 let _, y0, _, y1 = getlinkrect opaque
m in
5157 then gotopage1 l.pageno y0
5159 let d = fstate.fontsize
+ 1 in
5160 if y1 - l.pagey > l.pagevh - d
5161 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5162 else G.postRedisplay "linknav";
5164 showlinktype (getlink opaque
m);
5165 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5168 | None
-> viewkeyboard key mask
5170 | _ -> viewkeyboard key mask
5175 G.postRedisplay "leave linknav"
5179 | Ltgendir
_ -> viewkeyboard key mask
5180 | Ltexact exact
-> doexact exact
5183 let keyboard key mask
=
5184 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5185 then wcmd "interrupt"
5186 else state.uioh <- state.uioh#
key key mask
5189 let birdseyekeyboard key mask
5190 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5192 match conf.columns
with
5194 | Cmulti
((c, _, _), _) -> c
5195 | Csplit
_ -> failwith
"bird's eye split mode"
5198 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5199 let y, h = getpageyh pageno in
5200 let top = (conf.winh
- h) / 2 in
5201 gotoy (max
0 (y - top))
5202 | 0xff0d -> leavebirdseye beye
false
5203 | 0xff1b -> leavebirdseye beye
true (* escape *)
5204 | 0xff52 -> upbirdseye incr beye
(* prior *)
5205 | 0xff54 -> downbirdseye incr beye
(* next *)
5206 | 0xff51 -> upbirdseye 1 beye
(* up *)
5207 | 0xff53 -> downbirdseye 1 beye
(* down *)
5210 begin match state.layout with
5214 state.mode <- Birdseye
(
5215 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5217 gotopage1 l.pageno 0;
5220 let layout = layout (state.y-conf.winh
) conf.winh
in
5222 | [] -> gotoy (clamp (-conf.winh
))
5224 state.mode <- Birdseye
(
5225 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5227 gotopage1 l.pageno 0
5230 | [] -> gotoy (clamp (-conf.winh
))
5234 begin match List.rev
state.layout with
5236 let layout = layout (state.y + conf.winh
) conf.winh
in
5237 begin match layout with
5239 let incr = l.pageh
- l.pagevh in
5244 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5246 G.postRedisplay "birdseye pagedown";
5248 else gotoy (clamp (incr + conf.interpagespace*2));
5252 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5253 gotopage1 l.pageno 0;
5256 | [] -> gotoy (clamp conf.winh
)
5260 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5264 let pageno = state.pagecount
- 1 in
5265 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5266 if not
(pagevisible state.layout pageno)
5269 match List.rev
state.pdims
with
5271 | (_, _, h, _) :: _ -> h
5273 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5274 else G.postRedisplay "birdseye end";
5275 | _ -> viewkeyboard key mask
5278 let drawpage l linkindexbase
=
5280 match state.mode with
5281 | Textentry
_ -> scalecolor 0.4
5283 | View
-> scalecolor 1.0
5284 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5285 if l.pageno = hooverpageno
5288 if l.pageno = pageno
5294 begin match getopaque l.pageno with
5296 if tileready l l.pagex l.pagey
5298 let x = l.pagedispx - l.pagex
5299 and y = l.pagedispy - l.pagey in
5300 let hlmask = (if conf.hlinks
then 1 else 0)
5301 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5304 match state.mode with
5305 | Textentry
((_, s, _, _, _), _) when state.glinks
-> s
5308 postprocess opaque
hlmask x y (linkindexbase
, s);
5315 let scrollindicator () =
5316 let sbw, ph
, sh = state.uioh#
scrollph in
5317 let sbh, pw, sw = state.uioh#scrollpw
in
5319 GlDraw.color (0.64, 0.64, 0.64);
5321 (float (conf.winw
- sbw), 0.)
5322 (float conf.winw
, float conf.winh
)
5325 (0., float (conf.winh
- sbh))
5326 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5328 GlDraw.color (0.0, 0.0, 0.0);
5331 (float (conf.winw
- sbw), ph
)
5332 (float conf.winw
, ph
+. sh)
5335 (pw, float (conf.winh
- sbh))
5336 (pw +. sw, float conf.winh
)
5341 match state.mstate
with
5342 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5345 | Msel
((x0, y0), (x1, y1)) ->
5346 let rec loop = function
5348 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5349 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5350 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5351 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5353 match getopaque l.pageno with
5355 let x0, y0 = pagetranslatepoint l x0 y0 in
5356 let x1, y1 = pagetranslatepoint l x1 y1 in
5357 seltext opaque
(x0, y0, x1, y1);
5365 let showrects rects
=
5367 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5368 GlDraw.polygon_mode `both `fill
;
5369 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5371 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5373 if l.pageno = pageno
5375 let dx = float (l.pagedispx - l.pagex) in
5376 let dy = float (l.pagedispy - l.pagey) in
5377 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5378 GlDraw.begins `quads
;
5380 GlDraw.vertex2
(x0+.dx, y0+.dy);
5381 GlDraw.vertex2
(x1+.dx, y1+.dy);
5382 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5383 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5394 GlClear.color (scalecolor2 conf.bgcolor
);
5395 GlClear.clear
[`
color];
5396 let rec loop linkindexbase
= function
5398 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5399 loop linkindexbase rest
5402 loop 0 state.layout;
5404 match state.mode with
5405 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5406 begin match getopaque pageno with
5408 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5415 | None
-> state.rects
5422 begin match state.mstate
with
5423 | Mzoomrect
((x0, y0), (x1, y1)) ->
5425 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5426 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5427 GlDraw.rect (float x0, float y0)
5428 (float x1, float y1);
5437 let zoomrect x y x1 y1 =
5440 and y0 = min
y y1 in
5441 gotoy (state.y + y0);
5442 state.anchor <- getanchor ();
5443 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5445 if state.w < conf.winw
- state.scrollw
5446 then (conf.winw
- state.scrollw
- state.w) / 2
5449 state.x <- (state.x + margin) - x0;
5451 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5452 state.mstate
<- Mnone
;
5456 let winw = conf.winw - state.scrollw
- 1 in
5457 let s = float x /. float winw in
5458 let destx = truncate
(float (state.w + winw) *. s) in
5459 state.x <- winw - destx;
5460 gotoy_and_clear_text state.y;
5461 state.mstate
<- Mscrollx
;
5465 let s = float y /. float conf.winh
in
5466 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5467 gotoy_and_clear_text desty;
5468 state.mstate
<- Mscrolly
;
5471 let viewmouse button down
x y mask
=
5473 | n when (n == 4 || n == 5) && not down
->
5474 if Wsi.withctrl mask
5476 match state.mstate
with
5477 | Mzoom
(oldn
, i
) ->
5485 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5487 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5489 let zoom = conf.zoom -. incr in
5491 state.mstate
<- Mzoom
(n, 0);
5493 state.mstate
<- Mzoom
(n, i
+1);
5495 else state.mstate
<- Mzoom
(n, 0)
5497 | _ -> state.mstate
<- Mzoom
(n, 0)
5500 match state.autoscroll
with
5501 | Some step
-> setautoscrollspeed step
(n=4)
5505 then -conf.scrollstep
5506 else conf.scrollstep
5508 let incr = incr * 2 in
5509 let y = clamp incr in
5510 gotoy_and_clear_text y
5513 | 1 when Wsi.withctrl mask
->
5516 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5517 state.mstate
<- Mpan
(x, y)
5520 state.mstate
<- Mnone
5525 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5527 state.mstate
<- Mzoomrect
(p, p)
5530 match state.mstate
with
5531 | Mzoomrect
((x0, y0), _) ->
5532 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5533 then zoomrect x0 y0 x y
5535 state.mstate
<- Mnone
;
5536 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5537 G.postRedisplay "kill accidental zoom rect";
5540 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5541 state.mstate
<- Mnone
5544 | 1 when x > conf.winw - state.scrollw
->
5547 let _, position, sh = state.uioh#
scrollph in
5548 if y > truncate
position && y < truncate
(position +. sh)
5549 then state.mstate
<- Mscrolly
5552 state.mstate
<- Mnone
5554 | 1 when y > conf.winh
- state.hscrollh ->
5557 let _, position, sw = state.uioh#scrollpw
in
5558 if x > truncate
position && x < truncate
(position +. sw)
5559 then state.mstate
<- Mscrollx
5562 state.mstate
<- Mnone
5565 let dest = if down
then getunder x y else Unone
in
5566 begin match dest with
5570 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5573 | Unone
when down
->
5574 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5575 state.mstate
<- Mpan
(x, y);
5577 | Unone
| Utext
_ ->
5580 if conf.angle
mod 360 = 0
5582 state.mstate
<- Msel
((x, y), (x, y));
5583 G.postRedisplay "mouse select";
5587 match state.mstate
with
5590 | Mzoom
_ | Mscrollx
| Mscrolly
->
5591 state.mstate
<- Mnone
5593 | Mzoomrect
((x0, y0), _) ->
5597 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5598 state.mstate
<- Mnone
5600 | Msel
((_, y0), (_, y1)) ->
5601 let rec loop = function
5604 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5605 || ((y1 >= l.pagedispy
5606 && y1 <= (l.pagedispy + l.pagevh)))
5608 match getopaque l.pageno with
5611 match Ne.pipe () with
5615 "can not create sel pipe: %s"
5616 (Printexc.to_string exn
));
5618 let doclose what fd
=
5619 Ne.clo fd
(fun msg
->
5620 dolog "%s close failed: %s" what msg
)
5623 popen conf.selcmd
[r, 0; w, -1];
5626 G.postRedisplay "copysel";
5628 dolog "can not exectute %S: %s"
5629 conf.selcmd
(Printexc.to_string exn
);
5637 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5638 state.mstate
<- Mnone
;
5645 let birdseyemouse button down
x y mask
5646 (conf, leftx
, _, hooverpageno
, anchor) =
5649 let rec loop = function
5652 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5653 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5655 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5661 | _ -> viewmouse button down
x y mask
5664 let mouse button down
x y mask
=
5665 state.uioh <- state.uioh#button button down
x y mask
;
5669 state.uioh <- state.uioh#
motion x y
5673 state.uioh <- state.uioh#
pmotion x y;
5679 method key key mask
=
5680 begin match state.mode with
5681 | Textentry
textentry -> textentrykeyboard key mask
textentry
5682 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5683 | View
-> viewkeyboard key mask
5684 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5688 method button button bstate
x y mask
=
5689 begin match state.mode with
5691 | View
-> viewmouse button bstate
x y mask
5692 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5698 begin match state.mode with
5700 | View
| Birdseye
_ | LinkNav
_ ->
5701 match state.mstate
with
5702 | Mzoom
_ | Mnone
-> ()
5707 state.mstate
<- Mpan
(x, y);
5709 then state.x <- state.x + dx;
5711 gotoy_and_clear_text y
5714 state.mstate
<- Msel
(a, (x, y));
5715 G.postRedisplay "motion select";
5718 let y = min
conf.winh
(max
0 y) in
5722 let x = min
conf.winw (max
0 x) in
5725 | Mzoomrect
(p0
, _) ->
5726 state.mstate
<- Mzoomrect
(p0
, (x, y));
5727 G.postRedisplay "motion zoomrect";
5731 method pmotion x y =
5732 begin match state.mode with
5733 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5734 let rec loop = function
5736 if hooverpageno
!= -1
5738 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5739 G.postRedisplay "pmotion birdseye no hoover";
5742 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5743 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5745 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5746 G.postRedisplay "pmotion birdseye hoover";
5756 match state.mstate
with
5757 | Mnone
-> updateunder x y
5758 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5763 method infochanged
_ = ()
5766 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5767 let p, h = scrollph state.y maxy in
5771 let winw = conf.winw - state.scrollw
- 1 in
5772 let fwinw = float winw in
5774 let sw = fwinw /. float state.w in
5775 let sw = fwinw *. sw in
5776 max
sw (float conf.scrollh
)
5779 let f = state.w+winw in
5780 let r = float (winw-state.x) /. float f in
5781 let p = fwinw *. r in
5785 if position +. sw > fwinw
5786 then fwinw -. position
5789 state.hscrollh, position, sw
5793 match state.mode with
5794 | LinkNav
_ -> "links"
5795 | Textentry
_ -> "textentry"
5796 | Birdseye
_ -> "birdseye"
5799 findkeyhash conf modename
5806 let fontpath = ref "";;
5809 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5812 let l = String.length
s in
5813 let b = Buffer.create
l in
5819 try Sys.getenv
"HOME"
5822 ("Can not determine home directory location: " ^
5823 Printexc.to_string exn
);
5827 let modifier_of_string = function
5828 | "alt" -> Wsi.altmask
5829 | "shift" -> Wsi.shiftmask
5830 | "ctrl" | "control" -> Wsi.ctrlmask
5831 | "meta" -> Wsi.metamask
5836 let r = Str.regexp
"-" in
5838 let elems = Str.full_split
r s in
5841 let m1 = modifier_of_string s in
5843 then (Wsi.namekey
s, m)
5846 | Str.Delim
s when n land 1 = 0 -> g s
5848 | Str.Delim
_ -> (k
, m)
5850 let rec loop n k
m = function
5853 let k, m = f n k m x in
5859 let keys_of_string =
5860 let r = Str.regexp
"[ \t]" in
5862 let elems = Str.split
r s in
5863 List.map
key_of_string elems
5866 let copykeyhashes c =
5867 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5870 let config_of c attrs
=
5874 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5875 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5876 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5877 | "preload" -> { c with preload = bool_of_string
v }
5878 | "page-bias" -> { c with pagebias
= int_of_string
v }
5879 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5880 | "auto-scroll-step" ->
5881 { c with autoscrollstep
= max
0 (int_of_string
v) }
5882 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5883 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5886 match String.lowercase
v with
5887 | "true" -> Some infinity
5889 | f -> Some
(float_of_string
f)
5891 { c with maxwait
= mw}
5892 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5893 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5894 | "vertical-margin" ->
5895 { c with interpagespace = max
0 (int_of_string
v) }
5897 let zoom = float_of_string
v /. 100. in
5898 let zoom = max
zoom 0.0 in
5899 { c with zoom = zoom }
5900 | "presentation" -> { c with presentation = bool_of_string
v }
5901 | "rotation-angle" -> { c with angle
= int_of_string
v }
5902 | "width" -> { c with winw = max
20 (int_of_string
v) }
5903 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5904 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5905 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5906 | "pixmap-cache-size" ->
5907 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5908 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5909 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5910 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5911 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5912 | "background-color" -> { c with bgcolor
= color_of_string v }
5913 | "scrollbar-in-presentation" ->
5914 { c with scrollbarinpm
= bool_of_string
v }
5915 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5916 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5917 | "mupdf-store-size" ->
5918 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5919 | "checkers" -> { c with checkers
= bool_of_string
v }
5920 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5921 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5922 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5923 | "uri-launcher" -> { c with urilauncher
= unent v }
5924 | "path-launcher" -> { c with pathlauncher
= unent v }
5925 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5926 | "invert-colors" -> { c with invert
= bool_of_string
v }
5927 | "brightness" -> { c with colorscale
= float_of_string
v }
5928 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5930 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5932 let (n, _, _) as nab
= multicolumns_of_string v in
5934 then { c with columns
= Csplit
(-n, [||]) }
5935 else { c with columns
= Cmulti
(nab
, [||]) }
5936 | "birds-eye-columns" ->
5937 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5938 | "selection-command" -> { c with selcmd
= unent v }
5939 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5942 prerr_endline
("Error processing attribute (`" ^
5943 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5946 let rec fold c = function
5949 let c = apply c k v in
5952 fold { c with keyhashes
= copykeyhashes c } attrs
;
5955 let fromstring f pos
n v d =
5958 dolog "Error processing attribute (%S=%S) at %d\n%s"
5959 n v pos
(Printexc.to_string exn
)
5964 let bookmark_of attrs
=
5965 let rec fold title page
rely = function
5966 | ("title", v) :: rest
-> fold v page
rely rest
5967 | ("page", v) :: rest
-> fold title v rely rest
5968 | ("rely", v) :: rest
-> fold title page
v rest
5969 | _ :: rest
-> fold title page
rely rest
5970 | [] -> title, page
, rely
5972 fold "invalid" "0" "0" attrs
5976 let rec fold path page
rely pan
= function
5977 | ("path", v) :: rest
-> fold v page
rely pan rest
5978 | ("page", v) :: rest
-> fold path v rely pan rest
5979 | ("rely", v) :: rest
-> fold path page
v pan rest
5980 | ("pan", v) :: rest
-> fold path page
rely v rest
5981 | _ :: rest
-> fold path page
rely pan rest
5982 | [] -> path, page
, rely, pan
5984 fold "" "0" "0" "0" attrs
5988 let rec fold rs ls
= function
5989 | ("out", v) :: rest
-> fold v ls rest
5990 | ("in", v) :: rest
-> fold rs
v rest
5991 | _ :: rest
-> fold ls rs rest
5997 let setconf dst
src =
5998 dst
.scrollbw
<- src.scrollbw
;
5999 dst
.scrollh
<- src.scrollh
;
6000 dst
.icase
<- src.icase
;
6001 dst
.preload <- src.preload;
6002 dst
.pagebias
<- src.pagebias
;
6003 dst
.verbose
<- src.verbose
;
6004 dst
.scrollstep
<- src.scrollstep
;
6005 dst
.maxhfit
<- src.maxhfit
;
6006 dst
.crophack
<- src.crophack
;
6007 dst
.autoscrollstep
<- src.autoscrollstep
;
6008 dst
.maxwait
<- src.maxwait
;
6009 dst
.hlinks
<- src.hlinks
;
6010 dst
.underinfo
<- src.underinfo
;
6011 dst
.interpagespace <- src.interpagespace;
6012 dst
.zoom <- src.zoom;
6013 dst
.presentation <- src.presentation;
6014 dst
.angle
<- src.angle
;
6015 dst
.winw <- src.winw;
6016 dst
.winh
<- src.winh
;
6017 dst
.savebmarks
<- src.savebmarks
;
6018 dst
.memlimit
<- src.memlimit
;
6019 dst
.proportional
<- src.proportional
;
6020 dst
.texcount
<- src.texcount
;
6021 dst
.sliceheight
<- src.sliceheight
;
6022 dst
.thumbw
<- src.thumbw
;
6023 dst
.jumpback
<- src.jumpback
;
6024 dst
.bgcolor
<- src.bgcolor
;
6025 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6026 dst
.tilew
<- src.tilew
;
6027 dst
.tileh
<- src.tileh
;
6028 dst
.mustoresize
<- src.mustoresize
;
6029 dst
.checkers
<- src.checkers
;
6030 dst
.aalevel
<- src.aalevel
;
6031 dst
.trimmargins
<- src.trimmargins
;
6032 dst
.trimfuzz
<- src.trimfuzz
;
6033 dst
.urilauncher
<- src.urilauncher
;
6034 dst
.colorspace
<- src.colorspace
;
6035 dst
.invert
<- src.invert
;
6036 dst
.colorscale
<- src.colorscale
;
6037 dst
.redirectstderr <- src.redirectstderr;
6038 dst
.ghyllscroll
<- src.ghyllscroll
;
6039 dst
.columns
<- src.columns
;
6040 dst
.beyecolumns
<- src.beyecolumns
;
6041 dst
.selcmd
<- src.selcmd
;
6042 dst
.updatecurs
<- src.updatecurs
;
6043 dst
.pathlauncher
<- src.pathlauncher
;
6044 dst
.keyhashes
<- copykeyhashes src;
6048 let h = Hashtbl.create
10 in
6049 let dc = { defconf with angle
= defconf.angle
} in
6050 let rec toplevel v t spos
_ =
6052 | Vdata
| Vcdata
| Vend
-> v
6053 | Vopen
("llppconfig", _, closed
) ->
6056 else { v with f = llppconfig
}
6058 error
"unexpected subelement at top level" s spos
6059 | Vclose
_ -> error
"unexpected close at top level" s spos
6061 and llppconfig
v t spos
_ =
6063 | Vdata
| Vcdata
-> v
6064 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6065 | Vopen
("defaults", attrs
, closed
) ->
6066 let c = config_of dc attrs
in
6070 else { v with f = defaults
}
6072 | Vopen
("ui-font", attrs
, closed
) ->
6073 let rec getsize size
= function
6075 | ("size", v) :: rest
->
6077 fromstring int_of_string spos
"size" v fstate.fontsize
in
6079 | l -> getsize size l
6081 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6084 else { v with f = uifont
(Buffer.create
10) }
6086 | Vopen
("doc", attrs
, closed
) ->
6087 let pathent, spage
, srely
, span
= doc_of attrs
in
6088 let path = unent pathent
6089 and pageno = fromstring int_of_string spos
"page" spage
0
6090 and rely = fromstring float_of_string spos
"rely" srely
0.0
6091 and pan
= fromstring int_of_string spos
"pan" span
0 in
6092 let c = config_of dc attrs
in
6093 let anchor = (pageno, rely) in
6095 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6096 else { v with f = doc
path pan
anchor c [] }
6099 error
"unexpected subelement in llppconfig" s spos
6101 | Vclose
"llppconfig" -> { v with f = toplevel }
6102 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6104 and defaults
v t spos
_ =
6106 | Vdata
| Vcdata
-> v
6107 | Vend
-> error
"unexpected end of input in defaults" s spos
6108 | Vopen
("keymap", attrs
, closed
) ->
6110 try List.assoc
"mode" attrs
6111 with Not_found
-> "global" in
6116 let h = findkeyhash dc modename in
6117 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6120 { v with f = pkeymap
ret KeyMap.empty }
6122 | Vopen
(_, _, _) ->
6123 error
"unexpected subelement in defaults" s spos
6125 | Vclose
"defaults" ->
6126 { v with f = llppconfig
}
6128 | Vclose
_ -> error
"unexpected close in defaults" s spos
6130 and uifont
b v t spos
epos =
6133 Buffer.add_substring
b s spos
(epos - spos
);
6135 | Vopen
(_, _, _) ->
6136 error
"unexpected subelement in ui-font" s spos
6137 | Vclose
"ui-font" ->
6138 if String.length
!fontpath = 0
6139 then fontpath := Buffer.contents
b;
6140 { v with f = llppconfig
}
6141 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6142 | Vend
-> error
"unexpected end of input in ui-font" s spos
6144 and doc
path pan
anchor c bookmarks
v t spos
_ =
6146 | Vdata
| Vcdata
-> v
6147 | Vend
-> error
"unexpected end of input in doc" s spos
6148 | Vopen
("bookmarks", _, closed
) ->
6151 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6153 | Vopen
("keymap", attrs
, closed
) ->
6155 try List.assoc
"mode" attrs
6156 with Not_found
-> "global"
6162 let h = findkeyhash c modename in
6163 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6164 doc
path pan
anchor c bookmarks
6166 { v with f = pkeymap
ret KeyMap.empty }
6168 | Vopen
(_, _, _) ->
6169 error
"unexpected subelement in doc" s spos
6172 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6173 { v with f = llppconfig
}
6175 | Vclose
_ -> error
"unexpected close in doc" s spos
6177 and pkeymap
ret keymap
v t spos
_ =
6179 | Vdata
| Vcdata
-> v
6180 | Vend
-> error
"unexpected end of input in keymap" s spos
6181 | Vopen
("map", attrs
, closed
) ->
6182 let r, l = map_of attrs
in
6183 let kss = fromstring keys_of_string spos
"in" r [] in
6184 let lss = fromstring keys_of_string spos
"out" l [] in
6188 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6189 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6192 then { v with f = pkeymap
ret keymap }
6195 { v with f = skip
"map" f }
6198 error
"unexpected subelement in keymap" s spos
6200 | Vclose
"keymap" ->
6201 { v with f = ret keymap }
6203 | Vclose
_ -> error
"unexpected close in keymap" s spos
6205 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6207 | Vdata
| Vcdata
-> v
6208 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6209 | Vopen
("item", attrs
, closed
) ->
6210 let titleent, spage
, srely
= bookmark_of attrs
in
6211 let page = fromstring int_of_string spos
"page" spage
0
6212 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6213 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6215 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6218 { v with f = skip
"item" f }
6221 error
"unexpected subelement in bookmarks" s spos
6223 | Vclose
"bookmarks" ->
6224 { v with f = doc
path pan
anchor c bookmarks }
6226 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6228 and skip tag
f v t spos
_ =
6230 | Vdata
| Vcdata
-> v
6232 error
("unexpected end of input in skipped " ^ tag
) s spos
6233 | Vopen
(tag'
, _, closed
) ->
6237 let f'
() = { v with f = skip tag
f } in
6238 { v with f = skip tag'
f'
}
6242 else error
("unexpected close in skipped " ^ tag
) s spos
6245 parse
{ f = toplevel; accu = () } s;
6251 let len = in_channel_length ic
in
6252 let s = String.create
len in
6253 really_input ic
s 0 len;
6256 | Parse_error
(msg
, s, pos
) ->
6257 let subs = subs s pos
in
6258 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6259 failwith
("parse error: " ^
s)
6262 failwith
("config load error: " ^
Printexc.to_string exn
)
6268 let dir = Filename.concat
home ".config" in
6269 if Sys.is_directory
dir then dir else home
6272 Filename.concat
dir "llpp.conf"
6275 let confpath = ref defconfpath;;
6278 if Sys.file_exists
!confpath
6281 (try Some
(open_in_bin
!confpath)
6284 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6285 Printexc.to_string exn
);
6294 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6295 Printexc.to_string exn
);
6301 f (Hashtbl.create
0, defconf)
6306 let pc, pb
, px, pa
=
6308 Hashtbl.find h (Filename.basename
state.path)
6309 with Not_found
-> dc, [], 0, (0, 0.0)
6313 state.bookmarks <- pb
;
6315 state.scrollw
<- conf.scrollbw
;
6317 then state.anchor <- pa
;
6318 cbput state.hists
.nav pa
;
6323 let add_attrs bb always
dc c =
6326 then Printf.bprintf bb
"\n %s='%b'" s a
6329 then Printf.bprintf bb
"\n %s='%d'" s a
6332 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6335 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6338 then Printf.bprintf bb
"\n %s='%f'" s a
6342 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6346 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6350 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6354 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6360 | Some
(_N
, _A
, _B
) ->
6361 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6371 else string_of_float
f
6373 Printf.bprintf bb
"\n %s='%s'" s v
6378 | Cmulti
((n, a, b), _) when n > 1 ->
6379 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6380 | Csplit
(n, _) when n > 1 ->
6381 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6387 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6392 then dc.winw, dc.winh
6394 match state.fullscreen
with
6396 | None
-> c.winw, c.winh
6398 let zoom, presentation, interpagespace, maxwait
=
6400 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6402 match state.mode with
6403 | Birdseye
(bc
, _, _, _, _) ->
6404 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6405 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6407 oi
"width" w dc.winw;
6408 oi
"height" h dc.winh
;
6409 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6410 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6411 ob "case-insensitive-search" c.icase
dc.icase
;
6412 ob "preload" c.preload dc.preload;
6413 oi
"page-bias" c.pagebias
dc.pagebias
;
6414 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6415 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6416 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6417 ob "crop-hack" c.crophack
dc.crophack
;
6418 oW
"throttle" maxwait
dc.maxwait
;
6419 ob "highlight-links" c.hlinks
dc.hlinks
;
6420 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6421 oi
"vertical-margin" interpagespace dc.interpagespace;
6422 oz
"zoom" zoom dc.zoom;
6423 ob "presentation" presentation dc.presentation;
6424 oi
"rotation-angle" c.angle
dc.angle
;
6425 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6426 ob "proportional-display" c.proportional
dc.proportional
;
6427 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6428 oi
"tex-count" c.texcount
dc.texcount
;
6429 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6430 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6431 ob "persistent-location" c.jumpback
dc.jumpback
;
6432 oc
"background-color" c.bgcolor
dc.bgcolor
;
6433 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6434 oi
"tile-width" c.tilew
dc.tilew
;
6435 oi
"tile-height" c.tileh
dc.tileh
;
6436 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6437 ob "checkers" c.checkers
dc.checkers
;
6438 oi
"aalevel" c.aalevel
dc.aalevel
;
6439 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6440 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6441 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6442 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6443 oC
"color-space" c.colorspace
dc.colorspace
;
6444 ob "invert-colors" c.invert
dc.invert
;
6445 oF
"brightness" c.colorscale
dc.colorscale
;
6446 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6447 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6448 oco
"columns" c.columns
dc.columns
;
6449 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6450 os
"selection-command" c.selcmd
dc.selcmd
;
6451 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6454 let keymapsbuf always
dc c =
6455 let bb = Buffer.create
16 in
6456 let rec loop = function
6458 | (modename, h) :: rest
->
6459 let dh = findkeyhash dc modename in
6460 if always
|| h <> dh
6462 if Hashtbl.length
h > 0
6464 if Buffer.length
bb > 0
6465 then Buffer.add_char
bb '
\n'
;
6466 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6467 Hashtbl.iter
(fun i
o ->
6468 let isdifferent = always
||
6470 let dO = Hashtbl.find dh i
in
6472 with Not_found
-> true
6477 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6478 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6479 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6480 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6481 Buffer.add_string
bb (Wsi.keyname
k);
6484 let rec loop = function
6486 | km
:: [] -> addkm km
6487 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6491 Buffer.add_string
bb "<map in='";
6495 Buffer.add_string
bb "' out='";
6497 Buffer.add_string
bb "'/>\n"
6500 Buffer.add_string
bb "' out='";
6502 Buffer.add_string
bb "'/>\n"
6504 | KMmulti
(ins, kms
) ->
6505 Buffer.add_char
bb ' '
;
6507 Buffer.add_string
bb "' out='";
6509 Buffer.add_string
bb "'/>\n"
6511 Buffer.add_string
bb "</keymap>";
6521 let uifontsize = fstate.fontsize
in
6522 let bb = Buffer.create
32768 in
6524 let dc = if conf.bedefault
then conf else dc in
6525 Buffer.add_string
bb "<llppconfig>\n";
6527 if String.length
!fontpath > 0
6529 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6535 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6538 Buffer.add_string
bb "<defaults ";
6539 add_attrs bb true dc dc;
6540 let kb = keymapsbuf true dc dc in
6541 if Buffer.length
kb > 0
6543 Buffer.add_string
bb ">\n";
6544 Buffer.add_buffer
bb kb;
6545 Buffer.add_string
bb "\n</defaults>\n";
6547 else Buffer.add_string
bb "/>\n";
6549 let adddoc path pan
anchor c bookmarks =
6550 if bookmarks == [] && c = dc && anchor = emptyanchor
6553 Printf.bprintf
bb "<doc path='%s'"
6554 (enent
path 0 (String.length
path));
6556 if anchor <> emptyanchor
6558 let n, y = anchor in
6559 Printf.bprintf
bb " page='%d'" n;
6562 Printf.bprintf
bb " rely='%f'" y
6567 then Printf.bprintf
bb " pan='%d'" pan
;
6569 add_attrs bb false dc c;
6570 let kb = keymapsbuf false dc c in
6572 begin match bookmarks with
6574 if Buffer.length
kb > 0
6576 Buffer.add_string
bb ">\n";
6577 Buffer.add_buffer
bb kb;
6578 Buffer.add_string
bb "</doc>\n";
6580 else Buffer.add_string
bb "/>\n"
6582 Buffer.add_string
bb ">\n<bookmarks>\n";
6583 List.iter
(fun (title, _level
, (page, rely)) ->
6585 "<item title='%s' page='%d'"
6586 (enent
title 0 (String.length
title))
6591 Printf.bprintf
bb " rely='%f'" rely
6593 Buffer.add_string
bb "/>\n";
6595 Buffer.add_string
bb "</bookmarks>";
6596 if Buffer.length
kb > 0
6598 Buffer.add_string
bb "\n";
6599 Buffer.add_buffer
bb kb;
6601 Buffer.add_string
bb "\n</doc>\n";
6607 match state.mode with
6608 | Birdseye
(c, pan, _, _, _) ->
6610 match conf.columns
with
6611 | Cmulti
((c, _, _), _) -> Some
c
6615 match c.columns
with
6616 | Cmulti
(c, _) -> Cmulti
(c, [||])
6617 | Csingle
-> Csingle
6618 | Csplit
_ -> failwith
"quit from bird's eye while split"
6620 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6621 | _ -> state.x, conf
6623 let basename = Filename.basename state.path in
6624 adddoc basename pan (getanchor ())
6627 match state.autoscroll
with
6629 | None
-> conf.autoscrollstep
}
6630 (if conf.savebmarks
then state.bookmarks else []);
6632 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6634 then adddoc path x y c bookmarks
6636 Buffer.add_string
bb "</llppconfig>";
6639 if Buffer.length
bb > 0
6642 let tmp = !confpath ^
".tmp" in
6643 let oc = open_out_bin
tmp in
6644 Buffer.output_buffer
oc bb;
6646 Unix.rename
tmp !confpath;
6649 ("error while saving configuration: " ^
Printexc.to_string exn
)
6656 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6657 "<password> Set password");
6659 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6660 "<path> Set path to the user interface font");
6662 ("-c", Arg.String
(fun s -> Config.confpath := s),
6663 "<path> Set path to the configuration file");
6665 ("-v", Arg.Unit
(fun () ->
6667 "%s\nconfiguration path: %s\n"
6671 exit
0), " Print version and exit");
6674 (fun s -> state.path <- s)
6675 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6677 if String.length
state.path = 0
6678 then (prerr_endline
"file name missing"; exit
1);
6682 let globalkeyhash = findkeyhash conf "global" in
6683 let wsfd, winw, winh
= Wsi.init
(object
6685 if nogeomcmds state.geomcmds
|| platform == Posx
6688 GlFunc.draw_buffer `front
;
6689 GlClear.color (scalecolor2 conf.bgcolor
);
6690 GlClear.clear
[`
color];
6691 GlFunc.draw_buffer `back
;
6693 method display = display ()
6694 method reshape w h = reshape w h
6695 method mouse b d x y m = mouse b d x y m
6696 method motion x y = state.mpos
<- (x, y); motion x y
6697 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6699 let mascm = m land (
6700 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6702 match state.keystate
with
6704 let km = k, mascm in
6707 try Hashtbl.find globalkeyhash km
6709 let modehash = state.uioh#
modehash in
6710 try Hashtbl.find modehash km
6711 with Not_found
-> KMinsrt
(k, m)
6713 | KMinsrt
(k, m) -> keyboard k m
6714 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6715 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6717 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6718 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6719 state.keystate
<- KSnone
6720 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6721 state.keystate
<- KSinto
(keys
, insrt
)
6723 state.keystate
<- KSnone
6725 method enter
x y = state.mpos
<- (x, y); pmotion x y
6726 method leave = state.mpos
<- (-1, -1)
6727 method quit
= raise Quit
6728 end) conf.winw conf.winh
(platform = Posx
) in
6733 List.exists
GlMisc.check_extension
6734 [ "GL_ARB_texture_rectangle"
6735 ; "GL_EXT_texture_recangle"
6736 ; "GL_NV_texture_rectangle" ]
6738 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6741 match Ne.pipe () with
6743 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6747 match Ne.pipe () with
6749 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6759 setcheckers conf.checkers
;
6763 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6764 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6769 state.text <- "Opening " ^
state.path;
6771 opendoc state.path state.password
;
6774 let rec loop deadline
=
6776 match state.errfd
with
6777 | None
-> [state.sr
; state.wsfd]
6778 | Some fd
-> [state.sr
; state.wsfd; fd
]
6782 state.redisplay
<- false;
6789 if deadline
= infinity
6791 else max
0.0 (deadline
-. now)
6796 try Unix.select
r [] [] timeout
6797 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6803 if state.ghyll
== noghyll
6805 match state.autoscroll
with
6806 | Some step
when step
!= 0 ->
6807 let y = state.y + step
in
6811 else if y >= state.maxy then 0 else y
6814 if state.mode = View
6815 then state.text <- "";
6818 else deadline
+. 0.01
6823 let rec checkfds = function
6825 | fd
:: rest
when fd
= state.sr
->
6826 let cmd = readcmd state.sr
in
6830 | fd
:: rest
when fd
= state.wsfd ->
6835 let s = String.create
80 in
6836 let n = Unix.read fd
s 0 80 in
6837 if conf.redirectstderr
6839 Buffer.add_substring
state.errmsgs
s 0 n;
6840 state.newerrmsgs
<- true;
6841 state.redisplay
<- true;
6844 prerr_string
(String.sub
s 0 n);
6852 if deadline
= infinity
6856 match state.autoscroll
with
6857 | Some step
when step
!= 0 -> deadline1
6858 | _ -> if state.ghyll
== noghyll then infinity
else deadline1