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
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
;
2829 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2830 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2833 conf.crophack
<- not
conf.crophack
;
2834 TEdone
("crophack " ^
btos conf.crophack
)
2838 match conf.maxwait
with
2840 conf.maxwait
<- Some infinity
;
2841 "always wait for page to complete"
2843 conf.maxwait
<- None
;
2844 "show placeholder if page is not ready"
2849 conf.underinfo
<- not
conf.underinfo
;
2850 TEdone
("underinfo " ^
btos conf.underinfo
)
2853 conf.savebmarks
<- not
conf.savebmarks
;
2854 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2860 match state.layout with
2865 conf.interpagespace <- int_of_string
s;
2866 state.maxy <- calcheight ();
2867 let y = getpagey pageno in
2870 state.text <- Printf.sprintf
"bad integer `%s': %s"
2871 s (Printexc.to_string exc
)
2873 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2876 reqlayout conf.angle
(not
conf.proportional
);
2877 TEdone
("proportional display " ^
btos conf.proportional
)
2880 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2881 TEdone
("trim margins " ^
btos conf.trimmargins
)
2884 conf.invert
<- not
conf.invert
;
2885 TEdone
("invert colors " ^
btos conf.invert
)
2889 cbput state.hists
.sel
s;
2892 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2896 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2902 class type lvsource
= object
2903 method getitemcount
: int
2904 method getitem
: int -> (string * int)
2905 method hasaction
: int -> bool
2914 method getactive
: int
2915 method getfirst
: int
2916 method getqsearch
: string
2917 method setqsearch
: string -> unit
2921 class virtual lvsourcebase
= object
2922 val mutable m_active
= 0
2923 val mutable m_first
= 0
2924 val mutable m_qsearch
= ""
2925 val mutable m_pan
= 0
2926 method getactive
= m_active
2927 method getfirst
= m_first
2928 method getqsearch
= m_qsearch
2929 method getpan
= m_pan
2930 method setqsearch
s = m_qsearch
<- s
2933 let withoutlastutf8 s =
2934 let len = String.length
s in
2942 let b = Char.code
s.[pos
] in
2943 if b land 0b110000 = 0b11000000
2948 if Char.code
s.[len-1] land 0x80 = 0
2952 String.sub
s 0 first;
2955 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2957 state.mode <- Textentry
(te
, onleave
);
2960 G.postRedisplay "textentrykeyboard enttext";
2962 let histaction cmd
=
2965 | Some
(action, _
) ->
2966 state.mode <- Textentry
(
2967 (c, action cmd
, opthist
, onkey
, ondone), onleave
2969 G.postRedisplay "textentry histaction"
2972 | 0xff08 -> (* backspace *)
2973 let s = withoutlastutf8 text in
2974 let len = String.length
s in
2978 G.postRedisplay "textentrykeyboard after cancel";
2981 enttext (c, s, opthist
, onkey
, ondone)
2987 G.postRedisplay "textentrykeyboard after confirm"
2989 | 0xff52 -> histaction HCprev
2990 | 0xff54 -> histaction HCnext
2991 | 0xff50 -> histaction HCfirst
2992 | 0xff57 -> histaction HClast
2994 | 0xff1b -> (* escape*)
2995 if String.length
text = 0
2997 begin match opthist
with
2999 | Some
(_
, onhistcancel
) -> onhistcancel
()
3003 G.postRedisplay "textentrykeyboard after cancel2"
3006 enttext (c, "", opthist
, onkey
, ondone)
3009 | 0xff9f | 0xffff -> () (* delete *)
3011 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3012 begin match onkey
text key with
3016 G.postRedisplay "textentrykeyboard after confirm2";
3019 enttext (c, text, opthist
, onkey
, ondone);
3023 G.postRedisplay "textentrykeyboard after cancel3"
3026 state.mode <- Textentry
(te
, onleave
);
3027 G.postRedisplay "textentrykeyboard switch";
3031 vlog "unhandled key %s" (Wsi.keyname
key)
3034 let firstof first active
=
3035 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3036 then max
0 (active
- (fstate.maxrows
/2))
3040 let calcfirst first active
=
3043 let rows = active
- first in
3044 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3048 let scrollph y maxy =
3049 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3050 let sh = float conf.winh
/. sh in
3051 let sh = max
sh (float conf.scrollh
) in
3056 else float y /. float maxy
3058 let position = (float conf.winh
-. sh) *. percent in
3061 if position +. sh > float conf.winh
3062 then float conf.winh
-. sh
3068 let coe s = (s :> uioh
);;
3070 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3072 val m_pan
= source#getpan
3073 val m_first
= source#getfirst
3074 val m_active
= source#getactive
3075 val m_qsearch
= source#getqsearch
3076 val m_prev_uioh
= state.uioh
3078 method private elemunder
y =
3079 let n = y / (fstate.fontsize
+1) in
3080 if m_first
+ n < source#getitemcount
3082 if source#hasaction
(m_first
+ n)
3083 then Some
(m_first
+ n)
3090 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3091 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3092 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3093 GlDraw.color
(1., 1., 1.);
3094 Gl.enable `texture_2d
;
3095 let fs = fstate.fontsize
in
3097 let ww = fstate.wwidth
in
3098 let tabw = 30.0*.ww in
3099 let itemcount = source#getitemcount
in
3101 if (row - m_first
) * nfs > conf.winh
3104 if row >= 0 && row < itemcount
3106 let (s, level
) = source#getitem
row in
3107 let y = (row - m_first
) * nfs in
3108 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3111 Gl.disable `texture_2d
;
3112 GlDraw.polygon_mode `both `line
;
3113 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3114 GlDraw.rect (1., float (y + 1))
3115 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3116 GlDraw.polygon_mode `both `fill
;
3117 GlDraw.color
(1., 1., 1.);
3118 Gl.enable `texture_2d
;
3121 let drawtabularstring s =
3122 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3125 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3128 let len = String.length
s - tabpos - 1 in
3129 let s1 = String.sub
s 0 tabpos
3130 and s2
= String.sub
s (tabpos + 1) len in
3131 let nx = drawstr x s1 in
3133 let x = x +. (max
tabw sw) in
3140 let _ = drawtabularstring s in
3147 Gl.disable `texture_2d
;
3149 method updownlevel incr
=
3150 let len = source#getitemcount
in
3152 if m_active
>= 0 && m_active
< len
3153 then snd
(source#getitem m_active
)
3157 if i
= len then i
-1 else if i
= -1 then 0 else
3158 let _, l = source#getitem i
in
3159 if l != curlevel then i
else flow (i
+incr
)
3161 let active = flow m_active
in
3162 let first = calcfirst m_first
active in
3163 G.postRedisplay "outline updownlevel";
3164 {< m_active
= active; m_first
= first >}
3166 method private key1
key mask
=
3167 let set1 active first qsearch
=
3168 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3170 let search active pattern incr
=
3173 if n >= 0 && n < source#getitemcount
3175 let s, _ = source#getitem
n in
3177 (try ignore
(Str.search_forward
re s 0); true
3178 with Not_found
-> false)
3180 else loop (n + incr
)
3187 let re = Str.regexp_case_fold pattern
in
3193 let itemcount = source#getitemcount
in
3194 let find start incr
=
3196 if i
= -1 || i
= itemcount
3199 if source#hasaction i
3201 else find (i
+ incr
)
3206 let set active first =
3207 let first = bound first 0 (itemcount - fstate.maxrows
) in
3209 coe {< m_active
= active; m_first
= first >}
3212 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3214 let incr1 = if incr
> 0 then 1 else -1 in
3215 if isvisible m_first m_active
3218 let next = m_active
+ incr
in
3220 if next < 0 || next >= itemcount
3222 else find next incr1
3224 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3230 let first = m_first
+ incr
in
3231 let first = bound first 0 (itemcount - 1) in
3233 let next = m_active
+ incr
in
3234 let next = bound next 0 (itemcount - 1) in
3237 let active = if next = -1 then m_active
else next in
3240 let first = min
next m_first
in
3242 if abs
(next - first) > fstate.maxrows
3248 let first = m_first
+ incr
in
3249 let first = bound first 0 (itemcount - 1) in
3251 let next = m_active
+ incr
in
3252 let next = bound next 0 (itemcount - 1) in
3253 let next = find next incr1 in
3255 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3257 let active = if m_active
= -1 then next else m_active
in
3262 if isvisible first active
3268 G.postRedisplay "listview navigate";
3272 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3273 let incr = if key = 0x72 then -1 else 1 in
3275 match search (m_active
+ incr) m_qsearch
incr with
3277 state.text <- m_qsearch ^
" [not found]";
3280 state.text <- m_qsearch
;
3281 active, firstof m_first
active
3283 G.postRedisplay "listview ctrl-r/s";
3284 set1 active first m_qsearch
;
3286 | 0xff08 -> (* backspace *)
3287 if String.length m_qsearch
= 0
3290 let qsearch = withoutlastutf8 m_qsearch
in
3291 let len = String.length
qsearch in
3295 G.postRedisplay "listview empty qsearch";
3296 set1 m_active m_first
"";
3300 match search m_active
qsearch ~
-1 with
3302 state.text <- qsearch ^
" [not found]";
3305 state.text <- qsearch;
3306 active, firstof m_first
active
3308 G.postRedisplay "listview backspace qsearch";
3309 set1 active first qsearch
3312 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3313 let pattern = m_qsearch ^
Wsi.toutf8
key in
3315 match search m_active
pattern 1 with
3317 state.text <- pattern ^
" [not found]";
3320 state.text <- pattern;
3321 active, firstof m_first
active
3323 G.postRedisplay "listview qsearch add";
3324 set1 active first pattern;
3326 | 0xff1b -> (* escape *)
3328 if String.length m_qsearch
= 0
3330 G.postRedisplay "list view escape";
3333 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3335 | None
-> m_prev_uioh
3340 G.postRedisplay "list view kill qsearch";
3341 source#setqsearch
"";
3342 coe {< m_qsearch
= "" >}
3345 | 0xff0d -> (* return *)
3347 let self = {< m_qsearch
= "" >} in
3348 source#setqsearch
"";
3350 G.postRedisplay "listview enter";
3351 if m_active
>= 0 && m_active
< source#getitemcount
3353 source#exit
(coe self) false m_active m_first m_pan
"";
3356 source#exit
(coe self) true m_active m_first m_pan
"";
3359 begin match opt with
3360 | None
-> m_prev_uioh
3364 | 0xff9f | 0xffff -> (* delete *)
3367 | 0xff52 -> navigate ~
-1 (* up *)
3368 | 0xff54 -> navigate 1 (* down *)
3369 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3370 | 0xff56 -> navigate fstate.maxrows
(* next *)
3372 | 0xff53 -> (* right *)
3374 G.postRedisplay "listview right";
3375 coe {< m_pan
= m_pan
- 1 >}
3377 | 0xff51 -> (* left *)
3379 G.postRedisplay "listview left";
3380 coe {< m_pan
= m_pan
+ 1 >}
3382 | 0xff50 -> (* home *)
3383 let active = find 0 1 in
3384 G.postRedisplay "listview home";
3387 | 0xff57 -> (* end *)
3388 let first = max
0 (itemcount - fstate.maxrows
) in
3389 let active = find (itemcount - 1) ~
-1 in
3390 G.postRedisplay "listview end";
3393 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3397 dolog "listview unknown key %#x" key; coe self
3399 method key key mask
=
3400 match state.mode with
3401 | Textentry te
-> textentrykeyboard key mask te
; coe self
3402 | _ -> self#key1
key mask
3404 method button button down
x y _ =
3407 | 1 when x > conf.winw
- conf.scrollbw
->
3408 G.postRedisplay "listview scroll";
3411 let _, position, sh = self#
scrollph in
3412 if y > truncate
position && y < truncate
(position +. sh)
3414 state.mstate
<- Mscrolly
;
3418 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3419 let first = truncate
(s *. float source#getitemcount
) in
3420 let first = min source#getitemcount
first in
3421 Some
(coe {< m_first
= first; m_active
= first >})
3423 state.mstate
<- Mnone
;
3426 | 1 when not down
->
3427 begin match self#elemunder
y with
3429 G.postRedisplay "listview click";
3431 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3435 | n when (n == 4 || n == 5) && not down
->
3436 let len = source#getitemcount
in
3438 if n = 5 && m_first
+ fstate.maxrows
>= len
3442 let first = m_first
+ (if n == 4 then -1 else 1) in
3443 bound first 0 (len - 1)
3445 G.postRedisplay "listview wheel";
3446 Some
(coe {< m_first
= first >})
3451 | None
-> m_prev_uioh
3455 match state.mstate
with
3457 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3458 let first = truncate
(s *. float source#getitemcount
) in
3459 let first = min source#getitemcount
first in
3460 G.postRedisplay "listview motion";
3461 coe {< m_first
= first; m_active
= first >}
3464 method pmotion
x y =
3465 if x < conf.winw
- conf.scrollbw
3468 match self#elemunder
y with
3469 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3470 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3474 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3479 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3483 method infochanged
_ = ()
3485 method scrollpw
= (0, 0.0, 0.0)
3487 let nfs = fstate.fontsize
+ 1 in
3488 let y = m_first
* nfs in
3489 let itemcount = source#getitemcount
in
3490 let maxi = max
0 (itemcount - fstate.maxrows
) in
3491 let maxy = maxi * nfs in
3492 let p, h = scrollph y maxy in
3495 method modehash
= modehash
3498 class outlinelistview ~source
=
3501 ~source
:(source
:> lvsource
)
3503 ~modehash
:(findkeyhash conf "outline")
3506 method key key mask
=
3507 let calcfirst first active =
3510 let rows = active - first in
3511 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3515 let active = m_active
+ incr in
3516 let active = bound active 0 (source#getitemcount
- 1) in
3517 let first = calcfirst m_first
active in
3518 G.postRedisplay "outline navigate";
3519 coe {< m_active
= active; m_first
= first >}
3521 let ctrl = Wsi.withctrl mask
in
3523 | 110 when ctrl -> (* ctrl-n *)
3524 source#narrow m_qsearch
;
3525 G.postRedisplay "outline ctrl-n";
3526 coe {< m_first
= 0; m_active
= 0 >}
3528 | 117 when ctrl -> (* ctrl-u *)
3530 G.postRedisplay "outline ctrl-u";
3532 coe {< m_first
= 0; m_active
= 0 >}
3534 | 108 when ctrl -> (* ctrl-l *)
3535 let first = m_active
- (fstate.maxrows
/ 2) in
3536 G.postRedisplay "outline ctrl-l";
3537 coe {< m_first
= first >}
3539 | 0xff9f | 0xffff -> (* delete *)
3540 source#remove m_active
;
3541 G.postRedisplay "outline delete";
3542 let active = max
0 (m_active
-1) in
3543 coe {< m_first
= firstof m_first
active;
3544 m_active
= active >}
3546 | 0xff52 -> navigate ~
-1 (* up *)
3547 | 0xff54 -> navigate 1 (* down *)
3548 | 0xff55 -> (* prior *)
3549 navigate ~
-(fstate.maxrows
)
3550 | 0xff56 -> (* next *)
3551 navigate fstate.maxrows
3553 | 0xff53 -> (* [ctrl-]right *)
3557 G.postRedisplay "outline ctrl right";
3558 {< m_pan
= m_pan
+ 1 >}
3560 else self#updownlevel
1
3564 | 0xff51 -> (* [ctrl-]left *)
3568 G.postRedisplay "outline ctrl left";
3569 {< m_pan
= m_pan
- 1 >}
3571 else self#updownlevel ~
-1
3575 | 0xff50 -> (* home *)
3576 G.postRedisplay "outline home";
3577 coe {< m_first
= 0; m_active
= 0 >}
3579 | 0xff57 -> (* end *)
3580 let active = source#getitemcount
- 1 in
3581 let first = max
0 (active - fstate.maxrows
) in
3582 G.postRedisplay "outline end";
3583 coe {< m_active
= active; m_first
= first >}
3585 | _ -> super#
key key mask
3588 let outlinesource usebookmarks
=
3591 inherit lvsourcebase
3592 val mutable m_items
= empty
3593 val mutable m_orig_items
= empty
3594 val mutable m_prev_items
= empty
3595 val mutable m_narrow_pattern
= ""
3596 val mutable m_hadremovals
= false
3598 method getitemcount
=
3599 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3602 if n == Array.length m_items
&& m_hadremovals
3604 ("[Confirm removal]", 0)
3606 let s, n, _ = m_items
.(n) in
3609 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3610 ignore
(uioh
, first, qsearch);
3611 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3613 if String.length m_narrow_pattern
= 0
3619 if not
confrimremoval
3621 let _, _, anchor = m_items
.(active) in
3626 state.bookmarks
<- Array.to_list m_items
;
3627 m_orig_items
<- m_items
;
3630 else m_items
<- items;
3634 method hasaction
_ = true
3637 if Array.length m_items
!= Array.length m_orig_items
3638 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3641 method narrow
pattern =
3642 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3646 let rec loop accu n =
3649 m_narrow_pattern
<- pattern;
3650 m_items
<- Array.of_list
accu
3653 let (s, _, _) as o = m_items
.(n) in
3655 if (try ignore
(Str.search_forward
re s 0); true
3656 with Not_found
-> false)
3662 loop [] (Array.length m_items
- 1)
3667 then Array.of_list
state.bookmarks
3670 m_items
<- m_orig_items
3675 if m >= 0 && m < Array.length m_items
3677 m_hadremovals
<- true;
3678 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3679 let n = if n >= m then n+1 else n in
3684 method reset
anchor items =
3685 m_hadremovals
<- false;
3686 if m_orig_items
== empty || m_prev_items
!= items
3688 m_orig_items
<- items;
3689 if String.length m_narrow_pattern
= 0
3690 then m_items
<- items;
3692 m_prev_items
<- items;
3693 let rely = getanchory anchor in
3695 let rec loop n best bestd
=
3696 if n = Array.length m_items
3699 let (_, _, anchor) = m_items
.(n) in
3700 let orely = getanchory anchor in
3701 let d = abs
(orely - rely) in
3704 else loop (n+1) best bestd
3709 m_first
<- firstof m_first
active
3713 let enterselector usebookmarks
=
3714 let source = outlinesource usebookmarks
in
3718 then Array.of_list
state.bookmarks
3721 if Array.length
outlines = 0
3723 showtext ' ' errmsg
;
3726 state.text <- source#greetmsg
;
3727 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3728 let anchor = getanchor () in
3729 source#reset
anchor outlines;
3730 state.uioh
<- coe (new outlinelistview ~
source);
3731 G.postRedisplay "enter selector";
3735 let enteroutlinemode =
3736 let f = enterselector false in
3737 fun ()-> f "Document has no outline";
3740 let enterbookmarkmode =
3741 let f = enterselector true in
3742 fun () -> f "Document has no bookmarks (yet)";
3745 let color_of_string s =
3746 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3747 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3751 let color_to_string (r
, g
, b) =
3752 let r = truncate
(r *. 256.0)
3753 and g
= truncate
(g
*. 256.0)
3754 and b = truncate
(b *. 256.0) in
3755 Printf.sprintf
"%d/%d/%d" r g
b
3758 let irect_of_string s =
3759 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3762 let irect_to_string (x0,y0,x1,y1) =
3763 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3766 let makecheckers () =
3767 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3769 converted by Issac Trotts. July 25, 2002 *)
3770 let image_height = 64
3771 and image_width
= 64 in
3775 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3777 for i
= 0 to image_width
- 1 do
3778 for j
= 0 to image_height - 1 do
3779 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3780 (if (i
land 8 ) lxor (j
land 8) = 0
3781 then [|255;255;255|] else [|200;200;200|])
3786 let image = make_image () in
3787 let id = GlTex.gen_texture
() in
3788 GlTex.bind_texture `texture_2d
id;
3789 GlPix.store
(`unpack_alignment
1);
3790 GlTex.image2d
image;
3791 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3794 `mag_filter `nearest
;
3795 `min_filter `nearest
];
3799 let setcheckers enabled
=
3800 match state.texid
with
3802 if enabled
then state.texid
<- Some
(makecheckers ())
3807 GlTex.delete_texture texid
;
3808 state.texid
<- None
;
3812 let int_of_string_with_suffix s =
3813 let l = String.length
s in
3817 let suffix = Char.lowercase
s.[l-1] in
3819 | 'k'
-> String.sub
s 0 (l-1), 10
3820 | '
m'
-> String.sub
s 0 (l-1), 20
3821 | 'g'
-> String.sub
s 0 (l-1), 30
3825 let n = int_of_string
s1 in
3826 let m = n lsl shift
in
3828 then raise
(Failure
"value too large")
3832 let string_with_suffix_of_int n =
3840 if n land ((1 lsl 20) - 1) = 0
3843 if n land ((1 lsl 10) - 1) = 0
3850 let h = n mod 1000 in
3853 then string_of_int
h ^
s
3855 let s = Printf.sprintf
"_%03d%s" h s in
3862 let defghyllscroll = (40, 8, 32);;
3863 let ghyllscroll_of_string s =
3864 let (n, a, b) as nab
=
3867 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3869 if n <= a || n <= b || a >= b
3870 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3874 let ghyllscroll_to_string ((n, a, b) as nab
) =
3875 if nab
= defghyllscroll
3877 else Printf.sprintf
"%d,%d,%d" n a b;
3880 let describe_location () =
3882 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3884 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3885 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3889 else (100. *. (float state.y /. float maxy))
3893 Printf.sprintf
"page %d of %d [%.2f%%]"
3894 (fn+1) state.pagecount
percent
3897 "pages %d-%d of %d [%.2f%%]"
3898 (fn+1) (ln
+1) state.pagecount
percent
3902 let btos b = if b then "\xe2\x88\x9a" else "" in
3903 let showextended = ref false in
3904 let leave mode = function
3905 | Confirm
-> state.mode <- mode
3906 | Cancel
-> state.mode <- mode in
3909 val mutable m_first_time
= true
3910 val mutable m_l
= []
3911 val mutable m_a
= [||]
3912 val mutable m_prev_uioh
= nouioh
3913 val mutable m_prev_mode
= View
3915 inherit lvsourcebase
3917 method reset prev_mode prev_uioh
=
3918 m_a
<- Array.of_list
(List.rev m_l
);
3920 m_prev_mode
<- prev_mode
;
3921 m_prev_uioh
<- prev_uioh
;
3925 if n >= Array.length m_a
3929 | _, _, _, Action
_ -> m_active
<- n
3933 m_first_time
<- false;
3936 method int name get
set =
3938 (name
, `
int get
, 1, Action
(
3941 try set (int_of_string
s)
3943 state.text <- Printf.sprintf
"bad integer `%s': %s"
3944 s (Printexc.to_string exn
)
3947 let te = name ^
": ", "", None
, intentry, ondone in
3948 state.mode <- Textentry
(te, leave m_prev_mode
);
3952 method int_with_suffix name get
set =
3954 (name
, `intws get
, 1, Action
(
3957 try set (int_of_string_with_suffix s)
3959 state.text <- Printf.sprintf
"bad integer `%s': %s"
3960 s (Printexc.to_string exn
)
3964 name ^
": ", "", None
, intentry_with_suffix, ondone
3966 state.mode <- Textentry
(te, leave m_prev_mode
);
3970 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3972 (name
, `
bool (btos, get
), offset
, Action
(
3979 method color name get
set =
3981 (name
, `color get
, 1, Action
(
3983 let invalid = (nan
, nan
, nan
) in
3986 try color_of_string s
3988 state.text <- Printf.sprintf
"bad color `%s': %s"
3989 s (Printexc.to_string exn
);
3995 let te = name ^
": ", "", None
, textentry, ondone in
3996 state.text <- color_to_string (get
());
3997 state.mode <- Textentry
(te, leave m_prev_mode
);
4001 method string name get
set =
4003 (name
, `
string get
, 1, Action
(
4005 let ondone s = set s in
4006 let te = name ^
": ", "", None
, textentry, ondone in
4007 state.mode <- Textentry
(te, leave m_prev_mode
);
4011 method colorspace name get
set =
4013 (name
, `
string get
, 1, Action
(
4016 let vals = [| "rgb"; "bgr"; "gray" |] in
4018 inherit lvsourcebase
4021 m_active
<- int_of_colorspace conf.colorspace
;
4024 method getitemcount
= Array.length
vals
4025 method getitem
n = (vals.(n), 0)
4026 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4027 ignore
(uioh
, first, pan
, qsearch);
4028 if not cancel
then set active;
4030 method hasaction
_ = true
4034 let modehash = findkeyhash conf "info" in
4035 coe (new listview ~
source ~trusted
:true ~
modehash)
4038 method caption
s offset
=
4039 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4041 method caption2
s f offset
=
4042 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4044 method getitemcount
= Array.length m_a
4047 let tostr = function
4048 | `
int f -> string_of_int
(f ())
4049 | `intws
f -> string_with_suffix_of_int (f ())
4051 | `color
f -> color_to_string (f ())
4052 | `
bool (btos, f) -> btos (f ())
4055 let name, t
, offset
, _ = m_a
.(n) in
4056 ((let s = tostr t
in
4057 if String.length
s > 0
4058 then Printf.sprintf
"%s\t%s" name s
4062 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4066 m_qsearch
<- qsearch;
4068 match m_a
.(active) with
4069 | _, _, _, Action
f -> f uioh
4081 method hasaction
n =
4083 | _, _, _, Action
_ -> true
4087 let rec fillsrc prevmode prevuioh
=
4088 let sep () = src#caption
"" 0 in
4089 let colorp name get
set =
4091 (fun () -> color_to_string (get
()))
4094 let c = color_of_string v in
4097 state.text <- Printf.sprintf
"bad color `%s': %s"
4098 v (Printexc.to_string exn
);
4101 let oldmode = state.mode in
4102 let birdseye = isbirdseye state.mode in
4104 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4106 src#
bool "presentation mode"
4107 (fun () -> conf.presentation)
4109 conf.presentation <- v;
4110 state.anchor <- getanchor ();
4113 src#
bool "ignore case in searches"
4114 (fun () -> conf.icase
)
4115 (fun v -> conf.icase
<- v);
4118 (fun () -> conf.preload)
4119 (fun v -> conf.preload <- v);
4121 src#
bool "highlight links"
4122 (fun () -> conf.hlinks
)
4123 (fun v -> conf.hlinks
<- v);
4125 src#
bool "under info"
4126 (fun () -> conf.underinfo
)
4127 (fun v -> conf.underinfo
<- v);
4129 src#
bool "persistent bookmarks"
4130 (fun () -> conf.savebmarks
)
4131 (fun v -> conf.savebmarks
<- v);
4133 src#
bool "proportional display"
4134 (fun () -> conf.proportional
)
4135 (fun v -> reqlayout conf.angle
v);
4137 src#
bool "trim margins"
4138 (fun () -> conf.trimmargins
)
4139 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4141 src#
bool "persistent location"
4142 (fun () -> conf.jumpback
)
4143 (fun v -> conf.jumpback
<- v);
4146 src#
int "inter-page space"
4147 (fun () -> conf.interpagespace)
4149 conf.interpagespace <- n;
4151 match state.layout with
4156 state.maxy <- calcheight ();
4157 let y = getpagey pageno in
4162 (fun () -> conf.pagebias
)
4163 (fun v -> conf.pagebias
<- v);
4165 src#
int "scroll step"
4166 (fun () -> conf.scrollstep
)
4167 (fun n -> conf.scrollstep
<- n);
4169 src#
int "auto scroll step"
4171 match state.autoscroll
with
4173 | _ -> conf.autoscrollstep
)
4175 if state.autoscroll
<> None
4176 then state.autoscroll
<- Some
n;
4177 conf.autoscrollstep
<- n);
4180 (fun () -> truncate
(conf.zoom *. 100.))
4181 (fun v -> setzoom ((float v) /. 100.));
4184 (fun () -> conf.angle
)
4185 (fun v -> reqlayout v conf.proportional
);
4187 src#
int "scroll bar width"
4188 (fun () -> state.scrollw
)
4192 reshape conf.winw
conf.winh
;
4195 src#
int "scroll handle height"
4196 (fun () -> conf.scrollh
)
4197 (fun v -> conf.scrollh
<- v;);
4199 src#
int "thumbnail width"
4200 (fun () -> conf.thumbw
)
4202 conf.thumbw
<- min
4096 v;
4205 leavebirdseye beye
false;
4210 let mode = state.mode in
4211 src#
string "columns"
4213 match conf.columns
with
4215 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4216 | Csplit
(count
, _) -> "-" ^ string_of_int count
4219 let n, a, b = multicolumns_of_string v in
4220 setcolumns mode n a b);
4223 src#caption
"Presentation mode" 0;
4224 src#
bool "scrollbar visible"
4225 (fun () -> conf.scrollbarinpm
)
4227 if v != conf.scrollbarinpm
4229 conf.scrollbarinpm
<- v;
4230 if conf.presentation
4232 state.scrollw
<- if v then conf.scrollbw
else 0;
4233 reshape conf.winw
conf.winh
;
4239 src#caption
"Pixmap cache" 0;
4240 src#int_with_suffix
"size (advisory)"
4241 (fun () -> conf.memlimit
)
4242 (fun v -> conf.memlimit
<- v);
4245 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4246 (string_with_suffix_of_int state.memused
)
4247 (Hashtbl.length
state.tilemap
)) 1;
4250 src#caption
"Layout" 0;
4251 src#caption2
"Dimension"
4253 Printf.sprintf
"%dx%d (virtual %dx%d)"
4259 src#caption2
"Position" (fun () ->
4260 Printf.sprintf
"%dx%d" state.x state.y
4263 src#caption2
"Visible" (fun () -> describe_location ()) 1
4267 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4268 "Save these parameters as global defaults at exit"
4269 (fun () -> conf.bedefault
)
4270 (fun v -> conf.bedefault
<- v)
4274 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4275 src#
bool ~offset
:0 ~
btos "Extended parameters"
4276 (fun () -> !showextended)
4277 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4281 (fun () -> conf.checkers
)
4282 (fun v -> conf.checkers
<- v; setcheckers v);
4283 src#
bool "update cursor"
4284 (fun () -> conf.updatecurs
)
4285 (fun v -> conf.updatecurs
<- v);
4287 (fun () -> conf.verbose
)
4288 (fun v -> conf.verbose
<- v);
4289 src#
bool "invert colors"
4290 (fun () -> conf.invert
)
4291 (fun v -> conf.invert
<- v);
4293 (fun () -> conf.maxhfit
)
4294 (fun v -> conf.maxhfit
<- v);
4295 src#
bool "redirect stderr"
4296 (fun () -> conf.redirectstderr)
4297 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4298 src#
string "uri launcher"
4299 (fun () -> conf.urilauncher
)
4300 (fun v -> conf.urilauncher
<- v);
4301 src#
string "path launcher"
4302 (fun () -> conf.pathlauncher
)
4303 (fun v -> conf.pathlauncher
<- v);
4304 src#
string "tile size"
4305 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4308 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4309 conf.tilew
<- max
64 w;
4310 conf.tileh
<- max
64 h;
4313 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4314 v (Printexc.to_string exn
));
4315 src#
int "texture count"
4316 (fun () -> conf.texcount
)
4319 then conf.texcount
<- v
4320 else showtext '
!'
" Failed to set texture count please retry later"
4322 src#
int "slice height"
4323 (fun () -> conf.sliceheight
)
4325 conf.sliceheight
<- v;
4326 wcmd "sliceh %d" conf.sliceheight
;
4328 src#
int "anti-aliasing level"
4329 (fun () -> conf.aalevel
)
4331 conf.aalevel
<- bound v 0 8;
4332 state.anchor <- getanchor ();
4333 opendoc state.path
state.password
;
4335 src#
int "ui font size"
4336 (fun () -> fstate.fontsize
)
4337 (fun v -> setfontsize (bound v 5 100));
4338 colorp "background color"
4339 (fun () -> conf.bgcolor
)
4340 (fun v -> conf.bgcolor
<- v);
4341 src#
bool "crop hack"
4342 (fun () -> conf.crophack
)
4343 (fun v -> conf.crophack
<- v);
4344 src#
string "trim fuzz"
4345 (fun () -> irect_to_string conf.trimfuzz
)
4348 conf.trimfuzz
<- irect_of_string v;
4350 then settrim true conf.trimfuzz
;
4352 state.text <- Printf.sprintf
"bad irect `%s': %s"
4353 v (Printexc.to_string exn
)
4355 src#
string "throttle"
4357 match conf.maxwait
with
4358 | None
-> "show place holder if page is not ready"
4361 then "wait for page to fully render"
4363 "wait " ^ string_of_float
time
4364 ^
" seconds before showing placeholder"
4368 let f = float_of_string
v in
4370 then conf.maxwait
<- None
4371 else conf.maxwait
<- Some
f
4373 state.text <- Printf.sprintf
"bad time `%s': %s"
4374 v (Printexc.to_string exn
)
4376 src#
string "ghyll scroll"
4378 match conf.ghyllscroll
with
4380 | Some nab
-> ghyllscroll_to_string nab
4385 if String.length
v = 0
4387 else Some
(ghyllscroll_of_string v)
4389 conf.ghyllscroll
<- gs
4391 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4392 v (Printexc.to_string exn
)
4394 src#
string "selection command"
4395 (fun () -> conf.selcmd
)
4396 (fun v -> conf.selcmd
<- v);
4397 src#colorspace
"color space"
4398 (fun () -> colorspace_to_string conf.colorspace
)
4400 conf.colorspace
<- colorspace_of_int v;
4407 src#caption
"Document" 0;
4408 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4409 src#caption2
"Pages"
4410 (fun () -> string_of_int
state.pagecount
) 1;
4411 src#caption2
"Dimensions"
4412 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4416 src#caption
"Trimmed margins" 0;
4417 src#caption2
"Dimensions"
4418 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4421 src#reset prevmode prevuioh
;
4425 let prevmode = state.mode
4426 and prevuioh
= state.uioh in
4427 fillsrc prevmode prevuioh
;
4428 let source = (src :> lvsource
) in
4429 let modehash = findkeyhash conf "info" in
4430 state.uioh <- coe (object (self)
4431 inherit listview ~
source ~trusted
:true ~
modehash as super
4432 val mutable m_prevmemused
= 0
4433 method infochanged
= function
4435 if m_prevmemused
!= state.memused
4437 m_prevmemused
<- state.memused
;
4438 G.postRedisplay "memusedchanged";
4440 | Pdim
-> G.postRedisplay "pdimchanged"
4441 | Docinfo
-> fillsrc prevmode prevuioh
4443 method key key mask
=
4444 if not
(Wsi.withctrl mask
)
4447 | 0xff51 -> coe (self#updownlevel ~
-1)
4448 | 0xff53 -> coe (self#updownlevel
1)
4449 | _ -> super#
key key mask
4450 else super#
key key mask
4452 G.postRedisplay "info";
4458 inherit lvsourcebase
4459 method getitemcount
= Array.length
state.help
4461 let s, n, _ = state.help
.(n) in
4464 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4468 m_qsearch
<- qsearch;
4469 match state.help
.(active) with
4470 | _, _, Action
f -> Some
(f uioh)
4480 method hasaction
n =
4481 match state.help
.(n) with
4482 | _, _, Action
_ -> true
4489 let modehash = findkeyhash conf "help" in
4490 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4491 G.postRedisplay "help";
4496 let re = Str.regexp
"[\r\n]" in
4498 inherit lvsourcebase
4499 val mutable m_items
= [||]
4501 method getitemcount
= 1 + Array.length m_items
4506 else m_items
.(n-1), 0
4508 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4513 then Buffer.clear
state.errmsgs
;
4514 m_qsearch
<- qsearch;
4521 method hasaction
n =
4525 state.newerrmsgs
<- false;
4526 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4527 m_items
<- Array.of_list
l
4535 let source = (msgsource :> lvsource
) in
4536 let modehash = findkeyhash conf "listview" in
4537 state.uioh <- coe (object
4538 inherit listview ~
source ~trusted
:false ~
modehash as super
4541 then msgsource#reset
;
4544 G.postRedisplay "msgs";
4547 let quickbookmark ?title
() =
4548 match state.layout with
4554 let sec = Unix.gettimeofday
() in
4555 let tm = Unix.localtime
sec in
4556 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4560 (tm.Unix.tm_year
+ 1900)
4563 | Some
title -> title
4566 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4571 state.fullscreen
<- None
;
4575 let setautoscrollspeed step goingdown
=
4576 let incr = max
1 ((abs step
) / 2) in
4577 let incr = if goingdown
then incr else -incr in
4578 let astep = step
+ incr in
4579 state.autoscroll
<- Some
astep;
4582 let gotounder = function
4583 | Ulinkgoto
(pageno, top) ->
4587 gotopage1 pageno top;
4593 | Uremote
(filename
, pageno) ->
4595 if Sys.file_exists filename
4598 let dir = Filename.dirname
state.path in
4599 let path = Filename.concat
dir filename
in
4600 if Sys.file_exists
path
4604 if String.length
path > 0
4606 let anchor = getanchor () in
4607 let ranchor = state.path, state.password
, anchor in
4608 state.anchor <- (pageno, 0.0);
4609 state.ranchors
<- ranchor :: state.ranchors
;
4612 else showtext '
!'
("Could not find " ^ filename
)
4614 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4618 match conf.columns
with
4620 | _ -> conf.zoom > 1.0
4623 let viewkeyboard key mask
=
4625 let mode = state.mode in
4626 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4629 G.postRedisplay "view:enttext"
4631 let ctrl = Wsi.withctrl mask
in
4636 | 0xff63 -> (* insert *)
4637 if conf.angle
mod 360 = 0
4639 state.mode <- LinkNav
(Ltgendir
0);
4642 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4644 | 0xff1b | 113 -> (* escape / q *)
4645 begin match state.mstate
with
4647 state.mstate
<- Mnone
;
4648 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4649 G.postRedisplay "kill zoom rect";
4651 match state.ranchors
with
4653 | (path, password
, anchor) :: rest
->
4654 state.ranchors
<- rest
;
4655 state.anchor <- anchor;
4656 opendoc path password
4659 | 0xff08 -> (* backspace *)
4660 let y = getnav ~
-1 in
4661 gotoy_and_clear_text y
4669 G.postRedisplay "dehighlight";
4671 | 47 | 63 -> (* / ? *)
4672 let ondone isforw
s =
4673 cbput state.hists
.pat
s;
4674 state.searchpattern
<- s;
4677 let s = String.create
1 in
4678 s.[0] <- Char.chr
key;
4679 enttext (s, "", Some
(onhist state.hists
.pat
),
4680 textentry, ondone (key = 47))
4682 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4683 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4684 setzoom (conf.zoom +. incr)
4686 | 43 | 0xffab -> (* + *)
4689 try int_of_string
s with exc
->
4690 state.text <- Printf.sprintf
"bad integer `%s': %s"
4691 s (Printexc.to_string exc
);
4697 state.text <- "page bias is now " ^ string_of_int
n;
4700 enttext ("page bias: ", "", None
, intentry, ondone)
4702 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4703 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4704 setzoom (max
0.01 (conf.zoom -. decr))
4706 | 45 | 0xffad -> (* - *)
4707 let ondone msg
= state.text <- msg
in
4709 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4710 optentry state.mode, ondone
4713 | 48 when ctrl -> (* ctrl-0 *)
4716 | 49 when ctrl -> (* 1 *)
4717 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4721 | 0xffc6 -> (* f9 *)
4724 | 57 when ctrl -> (* ctrl-9 *)
4727 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4728 when not
ctrl -> (* 0..9 *)
4731 try int_of_string
s with exc
->
4732 state.text <- Printf.sprintf
"bad integer `%s': %s"
4733 s (Printexc.to_string exc
);
4739 cbput state.hists
.pag
(string_of_int
n);
4740 gotopage1 (n + conf.pagebias
- 1) 0;
4743 let pageentry text key =
4744 match Char.unsafe_chr
key with
4745 | 'g'
-> TEdone
text
4746 | _ -> intentry text key
4748 let text = "x" in text.[0] <- Char.chr
key;
4749 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4752 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4753 reshape conf.winw
conf.winh
;
4756 conf.hlinks
<- not
conf.hlinks
;
4757 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4758 G.postRedisplay "toggle highlightlinks";
4761 state.glinks
<- true;
4762 let mode = state.mode in
4763 state.mode <- Textentry
(
4764 (":", "", None
, linknentry, linkndone (fun under ->
4769 state.glinks
<- false;
4773 G.postRedisplay "view:linkent(F)"
4776 state.glinks
<- true;
4777 let mode = state.mode in
4778 state.mode <- Textentry
(
4779 (":", "", None
, linknentry, linkndone (fun under ->
4780 match Ne.pipe () with
4782 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4783 (Printexc.to_string exn
));
4786 popen conf.selcmd
[r, 0; w, -1]
4789 (Printf.sprintf
"failed to execute %s: %s"
4790 conf.selcmd
(Printexc.to_string exn
))
4793 Ne.clo fd
(fun msg
->
4794 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4797 let s = undertext under in
4799 let l = String.length
s in
4800 let n = Unix.write
w s 0 l in
4805 "failed to write %d characters to sel pipe, wrote %d"
4810 (Printf.sprintf
"failed to write to sel pipe: %s"
4811 (Printexc.to_string exn
)
4819 state.glinks
<- false;
4823 G.postRedisplay "view:linkent"
4826 begin match state.autoscroll
with
4828 conf.autoscrollstep
<- step
;
4829 state.autoscroll
<- None
4831 if conf.autoscrollstep
= 0
4832 then state.autoscroll
<- Some
1
4833 else state.autoscroll
<- Some
conf.autoscrollstep
4836 | 112 when ctrl -> (* ctrl-p *)
4840 conf.presentation <- not
conf.presentation;
4841 if conf.presentation
4843 if not
conf.scrollbarinpm
4844 then state.scrollw
<- 0;
4847 state.scrollw
<- conf.scrollbw
;
4849 showtext ' '
("presentation mode " ^
4850 if conf.presentation then "on" else "off");
4851 state.anchor <- getanchor ();
4855 begin match state.fullscreen
with
4857 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4860 state.fullscreen
<- None
;
4865 gotoy_and_clear_text 0
4868 gotopage1 (state.pagecount
- 1) 0
4870 | 112 | 78 -> (* p|N *)
4871 search state.searchpattern
false
4873 | 110 | 0xffc0 -> (* n|F3 *)
4874 search state.searchpattern
true
4877 begin match state.layout with
4880 gotoy_and_clear_text (getpagey l.pageno)
4884 begin match List.rev
state.layout with
4887 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4888 gotoy_and_clear_text (getpagey pageno)
4891 | 0xff9f | 0xffff -> (* delete *)
4892 begin match state.layout with
4895 let pageno = max
0 (l.pageno-1) in
4896 gotoy_and_clear_text (getpagey pageno)
4900 showtext ' '
(describe_location ());
4903 begin match state.layout with
4906 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4911 enterbookmarkmode ()
4913 | 104 | 0xffbe -> (* h|F1 *)
4919 | 101 when conf.redirectstderr -> (* e *)
4924 match state.layout with
4927 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4931 enttext ("bookmark: ", "", None
, textentry, ondone)
4935 showtext ' '
"Quick bookmark added";
4938 begin match state.layout with
4940 let rect = getpdimrect
l.pagedimno
in
4944 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4945 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4947 (truncate
(rect.(1) -. rect.(0)),
4948 truncate
(rect.(3) -. rect.(0)))
4950 let w = truncate
((float w)*.conf.zoom)
4951 and h = truncate
((float h)*.conf.zoom) in
4954 state.anchor <- getanchor ();
4955 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4957 G.postRedisplay "z";
4962 | 50 when ctrl -> (* ctrl-2 *)
4963 let maxw = getmaxw
() in
4965 then setzoom (maxw /. float conf.winw
)
4967 | 60 | 62 -> (* < > *)
4968 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4970 | 91 | 93 -> (* [ ] *)
4972 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4974 G.postRedisplay "brightness";
4976 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4977 setzoom state.prevzoom
4979 | 107 | 0xff52 -> (* k up *)
4980 begin match state.autoscroll
with
4982 begin match state.mode with
4983 | Birdseye beye
-> upbirdseye 1 beye
4986 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4987 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4990 setautoscrollspeed n false
4993 | 106 | 0xff54 -> (* j down *)
4994 begin match state.autoscroll
with
4996 begin match state.mode with
4997 | Birdseye beye
-> downbirdseye 1 beye
5000 then gotoy_and_clear_text (clamp (conf.winh
/2))
5001 else gotoy_and_clear_text (clamp conf.scrollstep
)
5004 setautoscrollspeed n true
5007 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5015 let dx = if key = 0xff51 then dx else -dx in
5016 state.x <- state.x + dx;
5017 gotoy_and_clear_text state.y
5020 G.postRedisplay "lef/right"
5023 | 0xff55 -> (* prior *)
5027 match state.layout with
5029 | l :: _ -> state.y - l.pagey
5035 | 0xff56 -> (* next *)
5039 match List.rev
state.layout with
5041 | l :: _ -> getpagey l.pageno
5047 | 0xff50 -> gotoghyll 0
5048 | 0xff57 -> gotoghyll (clamp state.maxy)
5049 | 0xff53 when Wsi.withalt mask
->
5050 gotoghyll (getnav ~
-1)
5051 | 0xff51 when Wsi.withalt mask
->
5052 gotoghyll (getnav 1)
5055 state.anchor <- getanchor ();
5056 opendoc state.path state.password
5058 | 118 when conf.debug
-> (* v *)
5061 match getopaque l.pageno with
5064 let x0, y0, x1, y1 = pagebbox opaque
in
5065 let a,b = float x0, float y0 in
5066 let c,d = float x1, float y0 in
5067 let e,f = float x1, float y1 in
5068 let h,j
= float x0, float y1 in
5069 let rect = (a,b,c,d,e,f,h,j
) in
5071 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5073 G.postRedisplay "v";
5076 vlog "huh? %s" (Wsi.keyname
key)
5079 let linknavkeyboard key mask
linknav =
5080 let getpage pageno =
5081 let rec loop = function
5083 | l :: _ when l.pageno = pageno -> Some
l
5084 | _ :: rest
-> loop rest
5085 in loop state.layout
5087 let doexact (pageno, n) =
5088 match getopaque pageno, getpage pageno with
5089 | Some opaque
, Some
l ->
5092 let under = getlink opaque
n in
5093 G.postRedisplay "link gotounder";
5099 | 0xff50 -> (* home *)
5100 Some
(findlink opaque LDfirst
), -1
5102 | 0xff57 -> (* end *)
5103 Some
(findlink opaque LDlast
), 1
5105 | 0xff51 -> (* left *)
5106 Some
(findlink opaque
(LDleft
n)), -1
5108 | 0xff53 -> (* right *)
5109 Some
(findlink opaque
(LDright
n)), 1
5111 | 0xff52 -> (* up *)
5112 Some
(findlink opaque
(LDup
n)), -1
5114 | 0xff54 -> (* down *)
5115 Some
(findlink opaque
(LDdown
n)), 1
5120 begin match findpwl
l.pageno dir with
5124 state.mode <- LinkNav
(Ltgendir
dir);
5125 let y, h = getpageyh pageno in
5128 then y + h - conf.winh
5133 begin match getopaque pageno, getpage pageno with
5134 | Some opaque
, Some
_ ->
5136 let ld = if dir > 0 then LDfirst
else LDlast
in
5139 begin match link with
5141 showlinktype (getlink opaque
m);
5142 state.mode <- LinkNav
(Ltexact
(pageno, m));
5143 G.postRedisplay "linknav jpage";
5150 begin match opt with
5151 | Some Lnotfound
-> pwl l dir;
5152 | Some
(Lfound
m) ->
5156 let _, y0, _, y1 = getlinkrect opaque
m in
5158 then gotopage1 l.pageno y0
5160 let d = fstate.fontsize
+ 1 in
5161 if y1 - l.pagey > l.pagevh - d
5162 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5163 else G.postRedisplay "linknav";
5165 showlinktype (getlink opaque
m);
5166 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5169 | None
-> viewkeyboard key mask
5171 | _ -> viewkeyboard key mask
5176 G.postRedisplay "leave linknav"
5180 | Ltgendir
_ -> viewkeyboard key mask
5181 | Ltexact exact
-> doexact exact
5184 let keyboard key mask
=
5185 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5186 then wcmd "interrupt"
5187 else state.uioh <- state.uioh#
key key mask
5190 let birdseyekeyboard key mask
5191 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5193 match conf.columns
with
5195 | Cmulti
((c, _, _), _) -> c
5196 | Csplit
_ -> failwith
"bird's eye split mode"
5199 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5200 let y, h = getpageyh pageno in
5201 let top = (conf.winh
- h) / 2 in
5202 gotoy (max
0 (y - top))
5203 | 0xff0d -> leavebirdseye beye
false
5204 | 0xff1b -> leavebirdseye beye
true (* escape *)
5205 | 0xff52 -> upbirdseye incr beye
(* prior *)
5206 | 0xff54 -> downbirdseye incr beye
(* next *)
5207 | 0xff51 -> upbirdseye 1 beye
(* up *)
5208 | 0xff53 -> downbirdseye 1 beye
(* down *)
5211 begin match state.layout with
5215 state.mode <- Birdseye
(
5216 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5218 gotopage1 l.pageno 0;
5221 let layout = layout (state.y-conf.winh
) conf.winh
in
5223 | [] -> gotoy (clamp (-conf.winh
))
5225 state.mode <- Birdseye
(
5226 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5228 gotopage1 l.pageno 0
5231 | [] -> gotoy (clamp (-conf.winh
))
5235 begin match List.rev
state.layout with
5237 let layout = layout (state.y + conf.winh
) conf.winh
in
5238 begin match layout with
5240 let incr = l.pageh
- l.pagevh in
5245 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5247 G.postRedisplay "birdseye pagedown";
5249 else gotoy (clamp (incr + conf.interpagespace*2));
5253 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5254 gotopage1 l.pageno 0;
5257 | [] -> gotoy (clamp conf.winh
)
5261 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5265 let pageno = state.pagecount
- 1 in
5266 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5267 if not
(pagevisible state.layout pageno)
5270 match List.rev
state.pdims
with
5272 | (_, _, h, _) :: _ -> h
5274 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5275 else G.postRedisplay "birdseye end";
5276 | _ -> viewkeyboard key mask
5279 let drawpage l linkindexbase
=
5281 match state.mode with
5282 | Textentry
_ -> scalecolor 0.4
5284 | View
-> scalecolor 1.0
5285 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5286 if l.pageno = hooverpageno
5289 if l.pageno = pageno
5295 begin match getopaque l.pageno with
5297 if tileready l l.pagex l.pagey
5299 let x = l.pagedispx - l.pagex
5300 and y = l.pagedispy - l.pagey in
5301 let hlmask = (if conf.hlinks
then 1 else 0)
5302 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5305 match state.mode with
5306 | Textentry
((_, s, _, _, _), _) when state.glinks
-> s
5309 postprocess opaque
hlmask x y (linkindexbase
, s);
5316 let scrollindicator () =
5317 let sbw, ph
, sh = state.uioh#
scrollph in
5318 let sbh, pw, sw = state.uioh#scrollpw
in
5320 GlDraw.color (0.64, 0.64, 0.64);
5322 (float (conf.winw
- sbw), 0.)
5323 (float conf.winw
, float conf.winh
)
5326 (0., float (conf.winh
- sbh))
5327 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5329 GlDraw.color (0.0, 0.0, 0.0);
5332 (float (conf.winw
- sbw), ph
)
5333 (float conf.winw
, ph
+. sh)
5336 (pw, float (conf.winh
- sbh))
5337 (pw +. sw, float conf.winh
)
5342 match state.mstate
with
5343 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5346 | Msel
((x0, y0), (x1, y1)) ->
5347 let rec loop = function
5349 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5350 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5351 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5352 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5354 match getopaque l.pageno with
5356 let x0, y0 = pagetranslatepoint l x0 y0 in
5357 let x1, y1 = pagetranslatepoint l x1 y1 in
5358 seltext opaque
(x0, y0, x1, y1);
5366 let showrects rects
=
5368 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5369 GlDraw.polygon_mode `both `fill
;
5370 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5372 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5374 if l.pageno = pageno
5376 let dx = float (l.pagedispx - l.pagex) in
5377 let dy = float (l.pagedispy - l.pagey) in
5378 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5379 GlDraw.begins `quads
;
5381 GlDraw.vertex2
(x0+.dx, y0+.dy);
5382 GlDraw.vertex2
(x1+.dx, y1+.dy);
5383 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5384 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5395 GlClear.color (scalecolor2 conf.bgcolor
);
5396 GlClear.clear
[`
color];
5397 let rec loop linkindexbase
= function
5399 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5400 loop linkindexbase rest
5403 loop 0 state.layout;
5405 match state.mode with
5406 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5407 begin match getopaque pageno with
5409 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5416 | None
-> state.rects
5423 begin match state.mstate
with
5424 | Mzoomrect
((x0, y0), (x1, y1)) ->
5426 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5427 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5428 GlDraw.rect (float x0, float y0)
5429 (float x1, float y1);
5438 let zoomrect x y x1 y1 =
5441 and y0 = min
y y1 in
5442 gotoy (state.y + y0);
5443 state.anchor <- getanchor ();
5444 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5446 if state.w < conf.winw
- state.scrollw
5447 then (conf.winw
- state.scrollw
- state.w) / 2
5450 state.x <- (state.x + margin) - x0;
5452 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5453 state.mstate
<- Mnone
;
5457 let winw = conf.winw - state.scrollw
- 1 in
5458 let s = float x /. float winw in
5459 let destx = truncate
(float (state.w + winw) *. s) in
5460 state.x <- winw - destx;
5461 gotoy_and_clear_text state.y;
5462 state.mstate
<- Mscrollx
;
5466 let s = float y /. float conf.winh
in
5467 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5468 gotoy_and_clear_text desty;
5469 state.mstate
<- Mscrolly
;
5472 let viewmouse button down
x y mask
=
5474 | n when (n == 4 || n == 5) && not down
->
5475 if Wsi.withctrl mask
5477 match state.mstate
with
5478 | Mzoom
(oldn
, i
) ->
5486 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5488 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5490 let zoom = conf.zoom -. incr in
5492 state.mstate
<- Mzoom
(n, 0);
5494 state.mstate
<- Mzoom
(n, i
+1);
5496 else state.mstate
<- Mzoom
(n, 0)
5498 | _ -> state.mstate
<- Mzoom
(n, 0)
5501 match state.autoscroll
with
5502 | Some step
-> setautoscrollspeed step
(n=4)
5506 then -conf.scrollstep
5507 else conf.scrollstep
5509 let incr = incr * 2 in
5510 let y = clamp incr in
5511 gotoy_and_clear_text y
5514 | 1 when Wsi.withctrl mask
->
5517 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5518 state.mstate
<- Mpan
(x, y)
5521 state.mstate
<- Mnone
5526 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5528 state.mstate
<- Mzoomrect
(p, p)
5531 match state.mstate
with
5532 | Mzoomrect
((x0, y0), _) ->
5533 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5534 then zoomrect x0 y0 x y
5536 state.mstate
<- Mnone
;
5537 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5538 G.postRedisplay "kill accidental zoom rect";
5541 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5542 state.mstate
<- Mnone
5545 | 1 when x > conf.winw - state.scrollw
->
5548 let _, position, sh = state.uioh#
scrollph in
5549 if y > truncate
position && y < truncate
(position +. sh)
5550 then state.mstate
<- Mscrolly
5553 state.mstate
<- Mnone
5555 | 1 when y > conf.winh
- state.hscrollh ->
5558 let _, position, sw = state.uioh#scrollpw
in
5559 if x > truncate
position && x < truncate
(position +. sw)
5560 then state.mstate
<- Mscrollx
5563 state.mstate
<- Mnone
5566 let dest = if down
then getunder x y else Unone
in
5567 begin match dest with
5571 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5574 | Unone
when down
->
5575 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5576 state.mstate
<- Mpan
(x, y);
5578 | Unone
| Utext
_ ->
5581 if conf.angle
mod 360 = 0
5583 state.mstate
<- Msel
((x, y), (x, y));
5584 G.postRedisplay "mouse select";
5588 match state.mstate
with
5591 | Mzoom
_ | Mscrollx
| Mscrolly
->
5592 state.mstate
<- Mnone
5594 | Mzoomrect
((x0, y0), _) ->
5598 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5599 state.mstate
<- Mnone
5601 | Msel
((_, y0), (_, y1)) ->
5602 let rec loop = function
5605 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5606 || ((y1 >= l.pagedispy
5607 && y1 <= (l.pagedispy + l.pagevh)))
5609 match getopaque l.pageno with
5612 match Ne.pipe () with
5616 "can not create sel pipe: %s"
5617 (Printexc.to_string exn
));
5619 let doclose what fd
=
5620 Ne.clo fd
(fun msg
->
5621 dolog "%s close failed: %s" what msg
)
5626 G.postRedisplay "copysel"
5629 popen conf.selcmd
[r, 0; w, -1];
5633 dolog "can not exectute %S: %s"
5634 conf.selcmd
(Printexc.to_string exn
);
5642 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5643 state.mstate
<- Mnone
;
5650 let birdseyemouse button down
x y mask
5651 (conf, leftx
, _, hooverpageno
, anchor) =
5654 let rec loop = function
5657 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5658 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5660 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5666 | _ -> viewmouse button down
x y mask
5669 let mouse button down
x y mask
=
5670 state.uioh <- state.uioh#button button down
x y mask
;
5674 state.uioh <- state.uioh#
motion x y
5678 state.uioh <- state.uioh#
pmotion x y;
5684 method key key mask
=
5685 begin match state.mode with
5686 | Textentry
textentry -> textentrykeyboard key mask
textentry
5687 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5688 | View
-> viewkeyboard key mask
5689 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5693 method button button bstate
x y mask
=
5694 begin match state.mode with
5696 | View
-> viewmouse button bstate
x y mask
5697 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5703 begin match state.mode with
5705 | View
| Birdseye
_ | LinkNav
_ ->
5706 match state.mstate
with
5707 | Mzoom
_ | Mnone
-> ()
5712 state.mstate
<- Mpan
(x, y);
5714 then state.x <- state.x + dx;
5716 gotoy_and_clear_text y
5719 state.mstate
<- Msel
(a, (x, y));
5720 G.postRedisplay "motion select";
5723 let y = min
conf.winh
(max
0 y) in
5727 let x = min
conf.winw (max
0 x) in
5730 | Mzoomrect
(p0
, _) ->
5731 state.mstate
<- Mzoomrect
(p0
, (x, y));
5732 G.postRedisplay "motion zoomrect";
5736 method pmotion x y =
5737 begin match state.mode with
5738 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5739 let rec loop = function
5741 if hooverpageno
!= -1
5743 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5744 G.postRedisplay "pmotion birdseye no hoover";
5747 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5748 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5750 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5751 G.postRedisplay "pmotion birdseye hoover";
5761 match state.mstate
with
5762 | Mnone
-> updateunder x y
5763 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5768 method infochanged
_ = ()
5771 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5772 let p, h = scrollph state.y maxy in
5776 let winw = conf.winw - state.scrollw
- 1 in
5777 let fwinw = float winw in
5779 let sw = fwinw /. float state.w in
5780 let sw = fwinw *. sw in
5781 max
sw (float conf.scrollh
)
5784 let f = state.w+winw in
5785 let r = float (winw-state.x) /. float f in
5786 let p = fwinw *. r in
5790 if position +. sw > fwinw
5791 then fwinw -. position
5794 state.hscrollh, position, sw
5798 match state.mode with
5799 | LinkNav
_ -> "links"
5800 | Textentry
_ -> "textentry"
5801 | Birdseye
_ -> "birdseye"
5804 findkeyhash conf modename
5811 let fontpath = ref "";;
5814 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5817 let l = String.length
s in
5818 let b = Buffer.create
l in
5824 try Sys.getenv
"HOME"
5827 ("Can not determine home directory location: " ^
5828 Printexc.to_string exn
);
5832 let modifier_of_string = function
5833 | "alt" -> Wsi.altmask
5834 | "shift" -> Wsi.shiftmask
5835 | "ctrl" | "control" -> Wsi.ctrlmask
5836 | "meta" -> Wsi.metamask
5841 let r = Str.regexp
"-" in
5843 let elems = Str.full_split
r s in
5846 let m1 = modifier_of_string s in
5848 then (Wsi.namekey
s, m)
5851 | Str.Delim
s when n land 1 = 0 -> g s
5853 | Str.Delim
_ -> (k
, m)
5855 let rec loop n k
m = function
5858 let k, m = f n k m x in
5864 let keys_of_string =
5865 let r = Str.regexp
"[ \t]" in
5867 let elems = Str.split
r s in
5868 List.map
key_of_string elems
5871 let copykeyhashes c =
5872 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5875 let config_of c attrs
=
5879 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5880 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5881 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5882 | "preload" -> { c with preload = bool_of_string
v }
5883 | "page-bias" -> { c with pagebias
= int_of_string
v }
5884 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5885 | "auto-scroll-step" ->
5886 { c with autoscrollstep
= max
0 (int_of_string
v) }
5887 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5888 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5891 match String.lowercase
v with
5892 | "true" -> Some infinity
5894 | f -> Some
(float_of_string
f)
5896 { c with maxwait
= mw}
5897 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5898 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5899 | "vertical-margin" ->
5900 { c with interpagespace = max
0 (int_of_string
v) }
5902 let zoom = float_of_string
v /. 100. in
5903 let zoom = max
zoom 0.0 in
5904 { c with zoom = zoom }
5905 | "presentation" -> { c with presentation = bool_of_string
v }
5906 | "rotation-angle" -> { c with angle
= int_of_string
v }
5907 | "width" -> { c with winw = max
20 (int_of_string
v) }
5908 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5909 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5910 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5911 | "pixmap-cache-size" ->
5912 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5913 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5914 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5915 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5916 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5917 | "background-color" -> { c with bgcolor
= color_of_string v }
5918 | "scrollbar-in-presentation" ->
5919 { c with scrollbarinpm
= bool_of_string
v }
5920 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5921 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5922 | "mupdf-store-size" ->
5923 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5924 | "checkers" -> { c with checkers
= bool_of_string
v }
5925 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5926 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5927 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5928 | "uri-launcher" -> { c with urilauncher
= unent v }
5929 | "path-launcher" -> { c with pathlauncher
= unent v }
5930 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5931 | "invert-colors" -> { c with invert
= bool_of_string
v }
5932 | "brightness" -> { c with colorscale
= float_of_string
v }
5933 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5935 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5937 let (n, _, _) as nab
= multicolumns_of_string v in
5939 then { c with columns
= Csplit
(-n, [||]) }
5940 else { c with columns
= Cmulti
(nab
, [||]) }
5941 | "birds-eye-columns" ->
5942 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5943 | "selection-command" -> { c with selcmd
= unent v }
5944 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5947 prerr_endline
("Error processing attribute (`" ^
5948 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5951 let rec fold c = function
5954 let c = apply c k v in
5957 fold { c with keyhashes
= copykeyhashes c } attrs
;
5960 let fromstring f pos
n v d =
5963 dolog "Error processing attribute (%S=%S) at %d\n%s"
5964 n v pos
(Printexc.to_string exn
)
5969 let bookmark_of attrs
=
5970 let rec fold title page
rely = function
5971 | ("title", v) :: rest
-> fold v page
rely rest
5972 | ("page", v) :: rest
-> fold title v rely rest
5973 | ("rely", v) :: rest
-> fold title page
v rest
5974 | _ :: rest
-> fold title page
rely rest
5975 | [] -> title, page
, rely
5977 fold "invalid" "0" "0" attrs
5981 let rec fold path page
rely pan
= function
5982 | ("path", v) :: rest
-> fold v page
rely pan rest
5983 | ("page", v) :: rest
-> fold path v rely pan rest
5984 | ("rely", v) :: rest
-> fold path page
v pan rest
5985 | ("pan", v) :: rest
-> fold path page
rely v rest
5986 | _ :: rest
-> fold path page
rely pan rest
5987 | [] -> path, page
, rely, pan
5989 fold "" "0" "0" "0" attrs
5993 let rec fold rs ls
= function
5994 | ("out", v) :: rest
-> fold v ls rest
5995 | ("in", v) :: rest
-> fold rs
v rest
5996 | _ :: rest
-> fold ls rs rest
6002 let setconf dst
src =
6003 dst
.scrollbw
<- src.scrollbw
;
6004 dst
.scrollh
<- src.scrollh
;
6005 dst
.icase
<- src.icase
;
6006 dst
.preload <- src.preload;
6007 dst
.pagebias
<- src.pagebias
;
6008 dst
.verbose
<- src.verbose
;
6009 dst
.scrollstep
<- src.scrollstep
;
6010 dst
.maxhfit
<- src.maxhfit
;
6011 dst
.crophack
<- src.crophack
;
6012 dst
.autoscrollstep
<- src.autoscrollstep
;
6013 dst
.maxwait
<- src.maxwait
;
6014 dst
.hlinks
<- src.hlinks
;
6015 dst
.underinfo
<- src.underinfo
;
6016 dst
.interpagespace <- src.interpagespace;
6017 dst
.zoom <- src.zoom;
6018 dst
.presentation <- src.presentation;
6019 dst
.angle
<- src.angle
;
6020 dst
.winw <- src.winw;
6021 dst
.winh
<- src.winh
;
6022 dst
.savebmarks
<- src.savebmarks
;
6023 dst
.memlimit
<- src.memlimit
;
6024 dst
.proportional
<- src.proportional
;
6025 dst
.texcount
<- src.texcount
;
6026 dst
.sliceheight
<- src.sliceheight
;
6027 dst
.thumbw
<- src.thumbw
;
6028 dst
.jumpback
<- src.jumpback
;
6029 dst
.bgcolor
<- src.bgcolor
;
6030 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6031 dst
.tilew
<- src.tilew
;
6032 dst
.tileh
<- src.tileh
;
6033 dst
.mustoresize
<- src.mustoresize
;
6034 dst
.checkers
<- src.checkers
;
6035 dst
.aalevel
<- src.aalevel
;
6036 dst
.trimmargins
<- src.trimmargins
;
6037 dst
.trimfuzz
<- src.trimfuzz
;
6038 dst
.urilauncher
<- src.urilauncher
;
6039 dst
.colorspace
<- src.colorspace
;
6040 dst
.invert
<- src.invert
;
6041 dst
.colorscale
<- src.colorscale
;
6042 dst
.redirectstderr <- src.redirectstderr;
6043 dst
.ghyllscroll
<- src.ghyllscroll
;
6044 dst
.columns
<- src.columns
;
6045 dst
.beyecolumns
<- src.beyecolumns
;
6046 dst
.selcmd
<- src.selcmd
;
6047 dst
.updatecurs
<- src.updatecurs
;
6048 dst
.pathlauncher
<- src.pathlauncher
;
6049 dst
.keyhashes
<- copykeyhashes src;
6053 let h = Hashtbl.create
10 in
6054 let dc = { defconf with angle
= defconf.angle
} in
6055 let rec toplevel v t spos
_ =
6057 | Vdata
| Vcdata
| Vend
-> v
6058 | Vopen
("llppconfig", _, closed
) ->
6061 else { v with f = llppconfig
}
6063 error
"unexpected subelement at top level" s spos
6064 | Vclose
_ -> error
"unexpected close at top level" s spos
6066 and llppconfig
v t spos
_ =
6068 | Vdata
| Vcdata
-> v
6069 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6070 | Vopen
("defaults", attrs
, closed
) ->
6071 let c = config_of dc attrs
in
6075 else { v with f = defaults
}
6077 | Vopen
("ui-font", attrs
, closed
) ->
6078 let rec getsize size
= function
6080 | ("size", v) :: rest
->
6082 fromstring int_of_string spos
"size" v fstate.fontsize
in
6084 | l -> getsize size l
6086 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6089 else { v with f = uifont
(Buffer.create
10) }
6091 | Vopen
("doc", attrs
, closed
) ->
6092 let pathent, spage
, srely
, span
= doc_of attrs
in
6093 let path = unent pathent
6094 and pageno = fromstring int_of_string spos
"page" spage
0
6095 and rely = fromstring float_of_string spos
"rely" srely
0.0
6096 and pan
= fromstring int_of_string spos
"pan" span
0 in
6097 let c = config_of dc attrs
in
6098 let anchor = (pageno, rely) in
6100 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6101 else { v with f = doc
path pan
anchor c [] }
6104 error
"unexpected subelement in llppconfig" s spos
6106 | Vclose
"llppconfig" -> { v with f = toplevel }
6107 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6109 and defaults
v t spos
_ =
6111 | Vdata
| Vcdata
-> v
6112 | Vend
-> error
"unexpected end of input in defaults" s spos
6113 | Vopen
("keymap", attrs
, closed
) ->
6115 try List.assoc
"mode" attrs
6116 with Not_found
-> "global" in
6121 let h = findkeyhash dc modename in
6122 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6125 { v with f = pkeymap
ret KeyMap.empty }
6127 | Vopen
(_, _, _) ->
6128 error
"unexpected subelement in defaults" s spos
6130 | Vclose
"defaults" ->
6131 { v with f = llppconfig
}
6133 | Vclose
_ -> error
"unexpected close in defaults" s spos
6135 and uifont
b v t spos
epos =
6138 Buffer.add_substring
b s spos
(epos - spos
);
6140 | Vopen
(_, _, _) ->
6141 error
"unexpected subelement in ui-font" s spos
6142 | Vclose
"ui-font" ->
6143 if String.length
!fontpath = 0
6144 then fontpath := Buffer.contents
b;
6145 { v with f = llppconfig
}
6146 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6147 | Vend
-> error
"unexpected end of input in ui-font" s spos
6149 and doc
path pan
anchor c bookmarks
v t spos
_ =
6151 | Vdata
| Vcdata
-> v
6152 | Vend
-> error
"unexpected end of input in doc" s spos
6153 | Vopen
("bookmarks", _, closed
) ->
6156 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6158 | Vopen
("keymap", attrs
, closed
) ->
6160 try List.assoc
"mode" attrs
6161 with Not_found
-> "global"
6167 let h = findkeyhash c modename in
6168 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6169 doc
path pan
anchor c bookmarks
6171 { v with f = pkeymap
ret KeyMap.empty }
6173 | Vopen
(_, _, _) ->
6174 error
"unexpected subelement in doc" s spos
6177 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6178 { v with f = llppconfig
}
6180 | Vclose
_ -> error
"unexpected close in doc" s spos
6182 and pkeymap
ret keymap
v t spos
_ =
6184 | Vdata
| Vcdata
-> v
6185 | Vend
-> error
"unexpected end of input in keymap" s spos
6186 | Vopen
("map", attrs
, closed
) ->
6187 let r, l = map_of attrs
in
6188 let kss = fromstring keys_of_string spos
"in" r [] in
6189 let lss = fromstring keys_of_string spos
"out" l [] in
6193 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6194 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6197 then { v with f = pkeymap
ret keymap }
6200 { v with f = skip
"map" f }
6203 error
"unexpected subelement in keymap" s spos
6205 | Vclose
"keymap" ->
6206 { v with f = ret keymap }
6208 | Vclose
_ -> error
"unexpected close in keymap" s spos
6210 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6212 | Vdata
| Vcdata
-> v
6213 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6214 | Vopen
("item", attrs
, closed
) ->
6215 let titleent, spage
, srely
= bookmark_of attrs
in
6216 let page = fromstring int_of_string spos
"page" spage
0
6217 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6218 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6220 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6223 { v with f = skip
"item" f }
6226 error
"unexpected subelement in bookmarks" s spos
6228 | Vclose
"bookmarks" ->
6229 { v with f = doc
path pan
anchor c bookmarks }
6231 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6233 and skip tag
f v t spos
_ =
6235 | Vdata
| Vcdata
-> v
6237 error
("unexpected end of input in skipped " ^ tag
) s spos
6238 | Vopen
(tag'
, _, closed
) ->
6242 let f'
() = { v with f = skip tag
f } in
6243 { v with f = skip tag'
f'
}
6247 else error
("unexpected close in skipped " ^ tag
) s spos
6250 parse
{ f = toplevel; accu = () } s;
6256 let len = in_channel_length ic
in
6257 let s = String.create
len in
6258 really_input ic
s 0 len;
6261 | Parse_error
(msg
, s, pos
) ->
6262 let subs = subs s pos
in
6263 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6264 failwith
("parse error: " ^
s)
6267 failwith
("config load error: " ^
Printexc.to_string exn
)
6273 let dir = Filename.concat
home ".config" in
6274 if Sys.is_directory
dir then dir else home
6277 Filename.concat
dir "llpp.conf"
6280 let confpath = ref defconfpath;;
6283 if Sys.file_exists
!confpath
6286 (try Some
(open_in_bin
!confpath)
6289 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6290 Printexc.to_string exn
);
6299 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6300 Printexc.to_string exn
);
6306 f (Hashtbl.create
0, defconf)
6311 let pc, pb
, px, pa
=
6313 Hashtbl.find h (Filename.basename
state.path)
6314 with Not_found
-> dc, [], 0, (0, 0.0)
6318 state.bookmarks <- pb
;
6320 state.scrollw
<- conf.scrollbw
;
6322 then state.anchor <- pa
;
6323 cbput state.hists
.nav pa
;
6328 let add_attrs bb always
dc c =
6331 then Printf.bprintf bb
"\n %s='%b'" s a
6334 then Printf.bprintf bb
"\n %s='%d'" s a
6337 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6340 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6343 then Printf.bprintf bb
"\n %s='%f'" s a
6347 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6351 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6355 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6359 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6365 | Some
(_N
, _A
, _B
) ->
6366 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6376 else string_of_float
f
6378 Printf.bprintf bb
"\n %s='%s'" s v
6383 | Cmulti
((n, a, b), _) when n > 1 ->
6384 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6385 | Csplit
(n, _) when n > 1 ->
6386 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6392 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6397 then dc.winw, dc.winh
6399 match state.fullscreen
with
6401 | None
-> c.winw, c.winh
6403 let zoom, presentation, interpagespace, maxwait
=
6405 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6407 match state.mode with
6408 | Birdseye
(bc
, _, _, _, _) ->
6409 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6410 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6412 oi
"width" w dc.winw;
6413 oi
"height" h dc.winh
;
6414 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6415 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6416 ob "case-insensitive-search" c.icase
dc.icase
;
6417 ob "preload" c.preload dc.preload;
6418 oi
"page-bias" c.pagebias
dc.pagebias
;
6419 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6420 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6421 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6422 ob "crop-hack" c.crophack
dc.crophack
;
6423 oW
"throttle" maxwait
dc.maxwait
;
6424 ob "highlight-links" c.hlinks
dc.hlinks
;
6425 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6426 oi
"vertical-margin" interpagespace dc.interpagespace;
6427 oz
"zoom" zoom dc.zoom;
6428 ob "presentation" presentation dc.presentation;
6429 oi
"rotation-angle" c.angle
dc.angle
;
6430 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6431 ob "proportional-display" c.proportional
dc.proportional
;
6432 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6433 oi
"tex-count" c.texcount
dc.texcount
;
6434 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6435 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6436 ob "persistent-location" c.jumpback
dc.jumpback
;
6437 oc
"background-color" c.bgcolor
dc.bgcolor
;
6438 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6439 oi
"tile-width" c.tilew
dc.tilew
;
6440 oi
"tile-height" c.tileh
dc.tileh
;
6441 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6442 ob "checkers" c.checkers
dc.checkers
;
6443 oi
"aalevel" c.aalevel
dc.aalevel
;
6444 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6445 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6446 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6447 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6448 oC
"color-space" c.colorspace
dc.colorspace
;
6449 ob "invert-colors" c.invert
dc.invert
;
6450 oF
"brightness" c.colorscale
dc.colorscale
;
6451 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6452 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6453 oco
"columns" c.columns
dc.columns
;
6454 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6455 os
"selection-command" c.selcmd
dc.selcmd
;
6456 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6459 let keymapsbuf always
dc c =
6460 let bb = Buffer.create
16 in
6461 let rec loop = function
6463 | (modename, h) :: rest
->
6464 let dh = findkeyhash dc modename in
6465 if always
|| h <> dh
6467 if Hashtbl.length
h > 0
6469 if Buffer.length
bb > 0
6470 then Buffer.add_char
bb '
\n'
;
6471 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6472 Hashtbl.iter
(fun i
o ->
6473 let isdifferent = always
||
6475 let dO = Hashtbl.find dh i
in
6477 with Not_found
-> true
6482 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6483 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6484 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6485 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6486 Buffer.add_string
bb (Wsi.keyname
k);
6489 let rec loop = function
6491 | km
:: [] -> addkm km
6492 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6496 Buffer.add_string
bb "<map in='";
6500 Buffer.add_string
bb "' out='";
6502 Buffer.add_string
bb "'/>\n"
6505 Buffer.add_string
bb "' out='";
6507 Buffer.add_string
bb "'/>\n"
6509 | KMmulti
(ins, kms
) ->
6510 Buffer.add_char
bb ' '
;
6512 Buffer.add_string
bb "' out='";
6514 Buffer.add_string
bb "'/>\n"
6516 Buffer.add_string
bb "</keymap>";
6526 let uifontsize = fstate.fontsize
in
6527 let bb = Buffer.create
32768 in
6529 let dc = if conf.bedefault
then conf else dc in
6530 Buffer.add_string
bb "<llppconfig>\n";
6532 if String.length
!fontpath > 0
6534 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6540 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6543 Buffer.add_string
bb "<defaults ";
6544 add_attrs bb true dc dc;
6545 let kb = keymapsbuf true dc dc in
6546 if Buffer.length
kb > 0
6548 Buffer.add_string
bb ">\n";
6549 Buffer.add_buffer
bb kb;
6550 Buffer.add_string
bb "\n</defaults>\n";
6552 else Buffer.add_string
bb "/>\n";
6554 let adddoc path pan
anchor c bookmarks =
6555 if bookmarks == [] && c = dc && anchor = emptyanchor
6558 Printf.bprintf
bb "<doc path='%s'"
6559 (enent
path 0 (String.length
path));
6561 if anchor <> emptyanchor
6563 let n, y = anchor in
6564 Printf.bprintf
bb " page='%d'" n;
6567 Printf.bprintf
bb " rely='%f'" y
6572 then Printf.bprintf
bb " pan='%d'" pan
;
6574 add_attrs bb false dc c;
6575 let kb = keymapsbuf false dc c in
6577 begin match bookmarks with
6579 if Buffer.length
kb > 0
6581 Buffer.add_string
bb ">\n";
6582 Buffer.add_buffer
bb kb;
6583 Buffer.add_string
bb "</doc>\n";
6585 else Buffer.add_string
bb "/>\n"
6587 Buffer.add_string
bb ">\n<bookmarks>\n";
6588 List.iter
(fun (title, _level
, (page, rely)) ->
6590 "<item title='%s' page='%d'"
6591 (enent
title 0 (String.length
title))
6596 Printf.bprintf
bb " rely='%f'" rely
6598 Buffer.add_string
bb "/>\n";
6600 Buffer.add_string
bb "</bookmarks>";
6601 if Buffer.length
kb > 0
6603 Buffer.add_string
bb "\n";
6604 Buffer.add_buffer
bb kb;
6606 Buffer.add_string
bb "\n</doc>\n";
6612 match state.mode with
6613 | Birdseye
(c, pan, _, _, _) ->
6615 match conf.columns
with
6616 | Cmulti
((c, _, _), _) -> Some
c
6620 match c.columns
with
6621 | Cmulti
(c, _) -> Cmulti
(c, [||])
6622 | Csingle
-> Csingle
6623 | Csplit
_ -> failwith
"quit from bird's eye while split"
6625 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6626 | _ -> state.x, conf
6628 let basename = Filename.basename state.path in
6629 adddoc basename pan (getanchor ())
6632 match state.autoscroll
with
6634 | None
-> conf.autoscrollstep
}
6635 (if conf.savebmarks
then state.bookmarks else []);
6637 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6639 then adddoc path x y c bookmarks
6641 Buffer.add_string
bb "</llppconfig>";
6644 if Buffer.length
bb > 0
6647 let tmp = !confpath ^
".tmp" in
6648 let oc = open_out_bin
tmp in
6649 Buffer.output_buffer
oc bb;
6651 Unix.rename
tmp !confpath;
6654 ("error while saving configuration: " ^
Printexc.to_string exn
)
6661 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6662 "<password> Set password");
6664 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6665 "<path> Set path to the user interface font");
6667 ("-c", Arg.String
(fun s -> Config.confpath := s),
6668 "<path> Set path to the configuration file");
6670 ("-v", Arg.Unit
(fun () ->
6672 "%s\nconfiguration path: %s\n"
6676 exit
0), " Print version and exit");
6679 (fun s -> state.path <- s)
6680 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6682 if String.length
state.path = 0
6683 then (prerr_endline
"file name missing"; exit
1);
6687 let globalkeyhash = findkeyhash conf "global" in
6688 let wsfd, winw, winh
= Wsi.init
(object
6690 if nogeomcmds state.geomcmds
|| platform == Posx
6693 GlFunc.draw_buffer `front
;
6694 GlClear.color (scalecolor2 conf.bgcolor
);
6695 GlClear.clear
[`
color];
6696 GlFunc.draw_buffer `back
;
6698 method display = display ()
6699 method reshape w h = reshape w h
6700 method mouse b d x y m = mouse b d x y m
6701 method motion x y = state.mpos
<- (x, y); motion x y
6702 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6704 let mascm = m land (
6705 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6707 match state.keystate
with
6709 let km = k, mascm in
6712 try Hashtbl.find globalkeyhash km
6714 let modehash = state.uioh#
modehash in
6715 try Hashtbl.find modehash km
6716 with Not_found
-> KMinsrt
(k, m)
6718 | KMinsrt
(k, m) -> keyboard k m
6719 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6720 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6722 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6723 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6724 state.keystate
<- KSnone
6725 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6726 state.keystate
<- KSinto
(keys
, insrt
)
6728 state.keystate
<- KSnone
6730 method enter
x y = state.mpos
<- (x, y); pmotion x y
6731 method leave = state.mpos
<- (-1, -1)
6732 method quit
= raise Quit
6733 end) conf.winw conf.winh
(platform = Posx
) in
6738 List.exists
GlMisc.check_extension
6739 [ "GL_ARB_texture_rectangle"
6740 ; "GL_EXT_texture_recangle"
6741 ; "GL_NV_texture_rectangle" ]
6743 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6746 match Ne.pipe () with
6748 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6752 match Ne.pipe () with
6754 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6764 setcheckers conf.checkers
;
6768 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6769 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6774 state.text <- "Opening " ^
state.path;
6776 opendoc state.path state.password
;
6779 let rec loop deadline
=
6781 match state.errfd
with
6782 | None
-> [state.sr
; state.wsfd]
6783 | Some fd
-> [state.sr
; state.wsfd; fd
]
6787 state.redisplay
<- false;
6794 if deadline
= infinity
6796 else max
0.0 (deadline
-. now)
6801 try Unix.select
r [] [] timeout
6802 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6808 if state.ghyll
== noghyll
6810 match state.autoscroll
with
6811 | Some step
when step
!= 0 ->
6812 let y = state.y + step
in
6816 else if y >= state.maxy then 0 else y
6819 if state.mode = View
6820 then state.text <- "";
6823 else deadline
+. 0.01
6828 let rec checkfds = function
6830 | fd
:: rest
when fd
= state.sr
->
6831 let cmd = readcmd state.sr
in
6835 | fd
:: rest
when fd
= state.wsfd ->
6840 let s = String.create
80 in
6841 let n = Unix.read fd
s 0 80 in
6842 if conf.redirectstderr
6844 Buffer.add_substring
state.errmsgs
s 0 n;
6845 state.newerrmsgs
<- true;
6846 state.redisplay
<- true;
6849 prerr_string
(String.sub
s 0 n);
6857 if deadline
= infinity
6861 match state.autoscroll
with
6862 | Some step
when step
!= 0 -> deadline1
6863 | _ -> if state.ghyll
== noghyll then infinity
else deadline1