3 let tempfailureretry = Wsi.tempfailureretry;;
8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
17 let now = Unix.gettimeofday
;;
19 type params
= (angle
* proportional
* trimparams
20 * texcount
* sliceheight
* memsize
21 * colorspace
* fontpath
* trimcachepath
31 and proportional
= bool
32 and trimmargins
= bool
33 and interpagespace
= int
40 and trimcachepath
= string
43 and irect
= (int * int * int * int)
44 and trimparams
= (trimmargins
* irect
)
45 and colorspace
= | Rgb
| Bgr
| Gray
55 | LDfirstvisible
of (int * int * int)
70 | KMmulti
of key list
* key list
72 and keyhash
= (key
, keymap
) Hashtbl.t
75 | KSinto
of (key list
* key list
)
78 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
79 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
81 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
83 external init
: pipe
-> params
-> unit = "ml_init";;
84 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
85 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
86 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
87 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
88 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
89 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
90 external measurestr
: int -> string -> float = "ml_measure_string";;
91 external getmaxw
: unit -> float = "ml_getmaxw";;
92 external postprocess
:
93 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
94 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
95 external platform
: unit -> platform
= "ml_platform";;
96 external setaalevel
: int -> unit = "ml_setaalevel";;
97 external realloctexts
: int -> bool = "ml_realloctexts";;
98 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
99 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
100 external getlink
: opaque
-> int -> under
= "ml_getlink";;
101 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
102 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
103 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
104 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
105 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
106 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
107 external freepbo
: string -> unit = "ml_freepbo";;
108 external unmappbo
: string -> unit = "ml_unmappbo";;
109 external pbousable
: unit -> bool = "ml_pbo_usable";;
111 let platform_to_string = function
112 | Punknown
-> "unknown"
116 | Pfreebsd
-> "FreeBSD"
117 | Pdragonflybsd
-> "DragonflyBSD"
118 | Popenbsd
-> "OpenBSD"
119 | Pnetbsd
-> "NetBSD"
120 | Pcygwin
-> "Cygwin"
123 let platform = platform ();;
126 if platform = Pcygwin
128 let sh = "/bin/sh" in
129 let args = [|sh; "-c"; cmd
|] in
130 let rec std si so se
= function
132 | (fd
, 0) :: rest
-> std fd so se rest
133 | (fd
, -1) :: rest
->
134 Unix.set_close_on_exec fd
;
137 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
139 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
140 ignore
(Unix.create_process
sh args si so se
)
149 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
152 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
154 type mpos
= int * int
156 | Msel
of (mpos
* mpos
)
158 | Mscrolly
| Mscrollx
159 | Mzoom
of (int * int)
160 | Mzoomrect
of (mpos
* mpos
)
164 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
165 and onkey
= string -> int -> te
166 and ondone
= string -> unit
167 and histcancel
= unit -> unit
168 and onhist
= ((histcmd
-> string) * histcancel
)
169 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
170 and cancelonempty
= bool
175 | TEswitch
of textentry
186 let bound v minv maxv
=
187 max minv
(min maxv v
);
191 { store
= Array.create n v
198 let cbcap b
= Array.length b
.store
;;
203 b
.wc
<- (b
.wc
+ 1) mod cap;
205 b
.len
<- min
(b
.len
+ 1) cap;
208 let cbempty b
= b
.len
= 0;;
210 let cbgetg b circular dir
=
214 let rc = b
.rc + dir
in
226 else bound rc 0 (b
.len
-1)
232 let cbget b
= cbgetg b
false;;
233 let cbgetc b
= cbgetg b
true;;
235 let drawstring size x y s
=
237 Gl.enable `texture_2d
;
238 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
239 ignore
(drawstr size x y s
);
241 Gl.disable `texture_2d
;
244 let drawstring1 size x y s
=
248 let drawstring2 size x y fmt
=
249 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
268 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
269 dolog " WxH %dx%d" l
.pagew l
.pageh
;
270 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
271 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
272 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
273 dolog " column %d" l
.pagecol
;
277 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
279 dolog " x0,y0=(% f, % f)" x0 y0
;
280 dolog " x1,y1=(% f, % f)" x1 y1
;
281 dolog " x2,y2=(% f, % f)" x2 y2
;
282 dolog " x3,y3=(% f, % f)" x3 y3
;
286 type multicolumns
= multicol
* pagegeom
287 and singlecolumn
= pagegeom
288 and splitcolumns
= columncount
* pagegeom
289 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
290 and multicol
= columncount
* covercount
* covercount
292 and columncount
= int
293 and covercount
= int;;
296 { mutable scrollbw
: int
297 ; mutable scrollh
: int
298 ; mutable icase
: bool
299 ; mutable preload
: bool
300 ; mutable pagebias
: int
301 ; mutable verbose
: bool
302 ; mutable debug
: bool
303 ; mutable scrollstep
: int
304 ; mutable hscrollstep
: int
305 ; mutable maxhfit
: bool
306 ; mutable crophack
: bool
307 ; mutable autoscrollstep
: int
308 ; mutable maxwait
: float option
309 ; mutable hlinks
: bool
310 ; mutable underinfo
: bool
311 ; mutable interpagespace
: interpagespace
312 ; mutable zoom
: float
313 ; mutable presentation
: bool
314 ; mutable angle
: angle
317 ; mutable savebmarks
: bool
318 ; mutable proportional
: proportional
319 ; mutable trimmargins
: trimmargins
320 ; mutable trimfuzz
: irect
321 ; mutable memlimit
: memsize
322 ; mutable texcount
: texcount
323 ; mutable sliceheight
: sliceheight
324 ; mutable thumbw
: width
325 ; mutable jumpback
: bool
326 ; mutable bgcolor
: float * float * float
327 ; mutable bedefault
: bool
328 ; mutable scrollbarinpm
: bool
329 ; mutable tilew
: int
330 ; mutable tileh
: int
331 ; mutable mustoresize
: memsize
332 ; mutable checkers
: bool
333 ; mutable aalevel
: int
334 ; mutable urilauncher
: string
335 ; mutable pathlauncher
: string
336 ; mutable colorspace
: colorspace
337 ; mutable invert
: bool
338 ; mutable colorscale
: float
339 ; mutable redirectstderr
: bool
340 ; mutable ghyllscroll
: (int * int * int) option
341 ; mutable columns
: columns
342 ; mutable beyecolumns
: columncount
option
343 ; mutable selcmd
: string
344 ; mutable updatecurs
: bool
345 ; mutable keyhashes
: (string * keyhash
) list
346 ; mutable hfsize
: int
347 ; mutable pgscale
: float
348 ; mutable usepbo
: bool
349 ; mutable wheelbypage
: bool
352 | Csingle
of singlecolumn
353 | Cmulti
of multicolumns
354 | Csplit
of splitcolumns
357 type anchor
= pageno
* top
* dtop
;;
359 type outline
= string * int * anchor
;;
361 type rect
= float * float * float * float * float * float * float * float;;
363 type tile
= opaque
* pixmapsize
* elapsed
364 and elapsed
= float;;
365 type pagemapkey
= pageno
* gen
;;
366 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
370 let emptyanchor = (0, 0.0, 0.0);;
372 type infochange
= | Memused
| Docinfo
| Pdim
;;
374 class type uioh
= object
375 method display
: unit
376 method key
: int -> int -> uioh
377 method button
: int -> bool -> int -> int -> int -> uioh
378 method motion
: int -> int -> uioh
379 method pmotion
: int -> int -> uioh
380 method infochanged
: infochange
-> unit
381 method scrollpw
: (int * float * float)
382 method scrollph
: (int * float * float)
383 method modehash
: keyhash
387 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
388 | Textentry
of (textentry
* onleave
)
390 | LinkNav
of linktarget
391 and onleave
= leavetextentrystatus
-> unit
392 and leavetextentrystatus
= | Cancel
| Confirm
393 and helpitem
= string * int * action
396 | Action
of (uioh
-> uioh
)
398 | Ltexact
of (pageno
* int)
402 let isbirdseye = function Birdseye _
-> true | _
-> false;;
403 let istextentry = function Textentry _
-> true | _
-> false;;
407 | Loading
of (page
* gen
)
409 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
411 | Outlining
of outline list
414 let emptykeyhash = Hashtbl.create
0;;
415 let nouioh : uioh
= object (self
)
417 method key _ _
= self
418 method button _ _ _ _ _
= self
419 method motion _ _
= self
420 method pmotion _ _
= self
421 method infochanged _
= ()
422 method scrollpw
= (0, nan
, nan
)
423 method scrollph
= (0, nan
, nan
)
424 method modehash
= emptykeyhash
428 { mutable sr
: Unix.file_descr
429 ; mutable sw
: Unix.file_descr
430 ; mutable wsfd
: Unix.file_descr
431 ; mutable errfd
: Unix.file_descr
option
432 ; mutable stderr
: Unix.file_descr
433 ; mutable errmsgs
: Buffer.t
434 ; mutable newerrmsgs
: bool
438 ; mutable scrollw
: int
439 ; mutable hscrollh
: int
440 ; mutable anchor
: anchor
441 ; mutable ranchors
: (string * string * anchor
) list
443 ; mutable layout
: page list
444 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
445 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
446 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
447 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
448 ; mutable pagecount
: int
449 ; mutable currently
: currently
450 ; mutable mstate
: mstate
451 ; mutable searchpattern
: string
452 ; mutable rects
: (pageno
* recttype
* rect
) list
453 ; mutable rects1
: (pageno
* recttype
* rect
) list
454 ; mutable text
: string
455 ; mutable fullscreen
: (width
* height
) option
456 ; mutable mode
: mode
457 ; mutable uioh
: uioh
458 ; mutable outlines
: outline array
459 ; mutable bookmarks
: outline list
460 ; mutable path
: string
461 ; mutable password
: string
462 ; mutable nameddest
: string
463 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
464 ; mutable memused
: memsize
466 ; mutable throttle
: (page list
* int * float) option
467 ; mutable autoscroll
: int option
468 ; mutable ghyll
: (int option -> unit)
469 ; mutable help
: helpitem array
470 ; mutable docinfo
: (int * string) list
471 ; mutable texid
: GlTex.texture_id
option
473 ; mutable prevzoom
: float
474 ; mutable progress
: float
475 ; mutable redisplay
: bool
476 ; mutable mpos
: mpos
477 ; mutable keystate
: keystate
478 ; mutable glinks
: bool
479 ; mutable prevcolumns
: (columns
* float) option
480 ; mutable wthack
: bool
483 { pat
: string circbuf
484 ; pag
: string circbuf
485 ; nav
: anchor circbuf
486 ; sel
: string circbuf
508 ; presentation
= false
513 ; proportional
= true
514 ; trimmargins
= false
515 ; trimfuzz
= (0,0,0,0)
516 ; memlimit
= 32 lsl 20
521 ; bgcolor
= (0.5, 0.5, 0.5)
523 ; scrollbarinpm
= true
526 ; mustoresize
= 256 lsl 20
531 | Plinux
| Pfreebsd
| Pdragonflybsd
532 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
533 | Posx
-> "open \"%s\""
534 | Pcygwin
-> "cygstart \"%s\""
535 | Punknown
-> "echo %s")
536 ; pathlauncher
= "lp \"%s\""
539 | Plinux
| Pfreebsd
| Pdragonflybsd
540 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
547 ; redirectstderr
= false
549 ; columns
= Csingle
[||]
555 ; wheelbypage
= false
557 let mk n
= (n
, Hashtbl.create
1) in
571 let findkeyhash c name
=
572 try List.assoc name c
.keyhashes
573 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
576 let conf = { defconf with angle
= defconf.angle
};;
578 let pgscale h
= truncate
(float h
*. conf.pgscale);;
581 { mutable fontsize
: int
582 ; mutable wwidth
: float
583 ; mutable maxrows
: int
595 fstate.fontsize
<- n
;
596 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
597 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
601 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
602 let len = String.length s
in
603 if colonpos >= 0 && colonpos + 3 < len
605 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
608 try String.rindex_from s
colonpos ' '
612 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
615 | "http" | "ftp" | "mailto" ->
617 try String.index_from s
colonpos ' '
618 with Not_found
-> len
620 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
628 if String.length
conf.urilauncher
= 0
629 then print_endline uri
631 let url = geturl uri
in
632 if String.length
url = 0
633 then print_endline uri
635 let re = Str.regexp
"%s" in
636 let command = Str.global_replace
re url conf.urilauncher
in
640 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
646 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
647 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
651 let strings = version () :: "" :: Help.keys
in
654 let url = geturl s
in
655 if String.length
url > 0
656 then (s
, 0, Action
(fun u
-> gotouri url; u
))
657 else (s
, 0, Noaction
)
662 let firstgeomcmds = "", [];;
669 ; stderr
= Unix.stderr
670 ; errmsgs
= Buffer.create
0
677 ; anchor
= emptyanchor
681 ; tilelru
= Queue.create
()
682 ; pagemap
= Hashtbl.create
10
683 ; tilemap
= Hashtbl.create
10
699 ; geomcmds
= firstgeomcmds
701 { nav
= cbnew 10 emptyanchor
729 Printf.kprintf prerr_endline fmt
731 Printf.kprintf ignore fmt
735 if String.length
conf.pathlauncher
= 0
736 then print_endline
state.path
738 let re = Str.regexp
"%s" in
739 let command = Str.global_replace
re state.path
conf.pathlauncher
in
743 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
749 type 'a t
= | Res
of 'a
| Exn
of exn
;;
752 try Res
(Unix.pipe ())
757 try tempfailureretry Unix.close fd
758 with exn
-> f
(Printexc.to_string exn
)
762 try Res
(tempfailureretry Unix.dup fd
)
767 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
772 let redirectstderr () =
773 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
774 if conf.redirectstderr
776 match Ne.pipe () with
778 dolog "failed to create stderr redirection pipes: %s"
779 (Printexc.to_string exn
)
782 begin match Ne.dup Unix.stderr
with
784 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
785 Ne.clo r
(clofail "pipe/r");
786 Ne.clo w
(clofail "pipe/w");
788 | Ne.Res dupstderr
->
789 begin match Ne.dup2 w
Unix.stderr
with
791 dolog "failed to dup2 to stderr: %s"
792 (Printexc.to_string exn
);
793 Ne.clo dupstderr
(clofail "stderr duplicate");
794 Ne.clo r
(clofail "redir pipe/r");
795 Ne.clo w
(clofail "redir pipe/w");
798 state.stderr
<- dupstderr
;
799 state.errfd
<- Some r
;
803 state.newerrmsgs
<- false;
804 begin match state.errfd
with
806 begin match Ne.dup2 state.stderr
Unix.stderr
with
808 dolog "failed to dup2 original stderr: %s"
809 (Printexc.to_string exn
)
811 Ne.clo fd
(clofail "dup of stderr");
812 ignore
(Ne.dup2 state.stderr
Unix.stderr
);
817 prerr_string
(Buffer.contents
state.errmsgs
);
819 Buffer.clear
state.errmsgs
;
825 let postRedisplay who
=
827 then prerr_endline
("redisplay for " ^ who
);
828 state.redisplay
<- true;
832 let getopaque pageno
=
833 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
834 with Not_found
-> None
837 let putopaque pageno opaque
=
838 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
841 let pagetranslatepoint l x y
=
842 let dy = y
- l
.pagedispy
in
843 let y = dy + l
.pagey
in
844 let dx = x
- l
.pagedispx
in
845 let x = dx + l
.pagex
in
852 begin match getopaque l
.pageno
with
854 let x0 = l
.pagedispx
in
855 let x1 = x0 + l
.pagevw
in
856 let y0 = l
.pagedispy
in
857 let y1 = y0 + l
.pagevh
in
858 if y >= y0 && y <= y1 && x >= x0 && x <= x1
860 let px, py
= pagetranslatepoint l
x y in
861 match whatsunder opaque
px py
with
874 state.text
<- Printf.sprintf
"%c%s" c s
;
875 G.postRedisplay "showtext";
878 let undertext = function
881 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
882 | Utext s
-> "font: " ^ s
883 | Uunexpected s
-> "unexpected: " ^ s
884 | Ulaunch s
-> "launch: " ^ s
885 | Unamed s
-> "named: " ^ s
886 | Uremote
(filename
, pageno
) ->
887 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
890 let updateunder x y =
891 match getunder x y with
892 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
894 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
895 Wsi.setcursor
Wsi.CURSOR_INFO
896 | Ulinkgoto
(pageno
, _
) ->
898 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
899 Wsi.setcursor
Wsi.CURSOR_INFO
901 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
902 Wsi.setcursor
Wsi.CURSOR_TEXT
904 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
905 Wsi.setcursor
Wsi.CURSOR_INHERIT
907 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
908 Wsi.setcursor
Wsi.CURSOR_INHERIT
910 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
911 Wsi.setcursor
Wsi.CURSOR_INHERIT
912 | Uremote
(filename
, pageno
) ->
913 if conf.underinfo
then showtext 'r'
914 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
915 Wsi.setcursor
Wsi.CURSOR_INFO
918 let showlinktype under
=
924 let s = undertext under
in
929 let b = Buffer.create
(String.length
s + 1) in
930 Buffer.add_string
b s;
935 let colorspace_of_string s =
936 match String.lowercase
s with
940 | _
-> failwith
"invalid colorspace"
943 let int_of_colorspace = function
949 let colorspace_of_int = function
953 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
956 let colorspace_to_string = function
962 let intentry_with_suffix text key
=
964 if key
>= 32 && key
< 127
968 match Char.lowercase
c with
970 let text = addchar text c in
974 let text = addchar text c in
978 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
982 let multicolumns_to_string (n
, a
, b) =
984 then Printf.sprintf
"%d" n
985 else Printf.sprintf
"%d,%d,%d" n a
b;
988 let multicolumns_of_string s =
990 (int_of_string
s, 0, 0)
992 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
994 then failwith
"subtly broken"; (n
, a
, b)
1000 let n = tempfailureretry (Unix.read fd
s 0) 4 in
1001 if n != 4 then failwith
"incomplete read(len)";
1003 lor (Char.code
s.[0] lsl 24)
1004 lor (Char.code
s.[1] lsl 16)
1005 lor (Char.code
s.[2] lsl 8)
1006 lor (Char.code
s.[3] lsl 0)
1008 let s = String.create
len in
1009 let n = tempfailureretry (Unix.read fd
s 0) len in
1010 if n != len then failwith
"incomplete read(data)";
1014 let btod b = if b then 1 else 0;;
1017 let b = Buffer.create
16 in
1018 Buffer.add_string
b "llll";
1021 let s = Buffer.contents
b in
1022 let n = String.length
s in
1024 (* dolog "wcmd %S" (String.sub s 4 len); *)
1025 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1026 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1027 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1028 s.[3] <- Char.chr
(len land 0xff);
1029 let n'
= tempfailureretry (Unix.write
state.sw
s 0) n in
1030 if n'
!= n then failwith
"write failed";
1035 let d = conf.winh
- h
in
1036 max
conf.interpagespace
((d + 1) / 2)
1039 let rowyh (c, coverA
, coverB
) b n =
1040 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1042 let _, _, vy
, (_, _, h
, _) = b.(n) in
1045 let n'
= n - coverA
in
1048 let e = min
state.pagecount
(s + c) in
1049 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1050 let _, _, y, (_, _, h
, _) = b.(m
) in
1051 let miny = min
miny y in
1052 let maxh = max
maxh h
in
1053 find (m
+1) miny maxh
1058 match conf.columns
with
1059 | Cmulti
((_, _, _) as cl
, b) ->
1060 if Array.length
b > 0
1062 let y, h
= rowyh cl
b (Array.length
b - 1) in
1063 y + h
+ (if conf.presentation
then calcips h
else 0)
1066 if Array.length
b > 0
1068 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1069 y + h
+ (if conf.presentation
then calcips h
else 0)
1072 if Array.length
b > 0
1074 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1079 let getpageyh pageno
=
1080 let pageno = bound pageno 0 (state.pagecount
-1) in
1081 match conf.columns
with
1083 if Array.length
b = 0
1086 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1088 if conf.presentation
1094 if Array.length
b = 0
1097 let y, h
= rowyh cl
b pageno in
1099 if conf.presentation
1105 if Array.length
b = 0
1109 let (_, _, y, (_, _, h
, _)) = b.(n) in
1113 let getpagedim pageno =
1116 | (n, _, _, _) as pdim
:: rest
->
1118 then (if n = pageno then pdim
else ppdim
)
1123 f (-1, -1, -1, -1) state.pdims
1126 let getpagey pageno = fst
(getpageyh pageno);;
1128 let nogeomcmds cmds
=
1130 | s, [] -> String.length
s = 0
1135 let ((c, coverA
, coverB
) as cl
), b =
1136 match conf.columns
with
1137 | Csingle
b -> (1, 0, 0), b
1138 | Cmulti
(c, b) -> c, b
1139 | Csplit
(_, b) -> (1, 0, 0), b
1141 let rec bsearch nmin nmax
=
1143 then bound nmin
0 (state.pagecount
-1)
1145 let n = (nmax
+ nmin
) / 2 in
1146 let vy, h
= rowyh cl
b n in
1148 if conf.presentation
1150 let ips = calcips h
in
1151 let y0 = vy - ips in
1152 let y1 = vy + h
+ ips in
1156 then 0, vy + h
+ conf.interpagespace
1158 let y0 = vy - conf.interpagespace
in
1159 y0, y0 + h
+ conf.interpagespace
1162 if y >= y0 && y < y1
1169 if n < state.pagecount
- coverB
1170 then ((n-coverA
)/c)*c + coverA
1177 then bsearch (n+1) nmax
1178 else bsearch nmin
(n-1)
1181 let r = bsearch 0 (state.pagecount
-1) in
1185 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1186 let sh = sh - state.hscrollh
in
1187 let rec fold accu
n =
1188 if n = Array.length
b
1191 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1194 || n = state.pagecount
- coverB
1195 || (n - coverA
) mod columns
= columns
- 1)
1201 let pagey = max
0 (y - vy) in
1202 let pagedispy = if pagey > 0 then 0 else vy - y in
1203 let pagedispx, pagex
=
1205 if n = coverA
- 1 || n = state.pagecount
- coverB
1206 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1207 else dx + xoff
+ state.x
1214 let vw = conf.winw
- state.scrollw
- pagedispx in
1215 let pw = w
- pagex
in
1218 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1219 if pagevw > 0 && pagevh > 0
1223 ; pagedimno
= pdimno
1230 ; pagedispx = pagedispx
1231 ; pagedispy = pagedispy
1243 List.rev
(fold [] (page_of_y y));
1246 let layoutS (columns
, b) y sh =
1247 let sh = sh - state.hscrollh
in
1248 let rec fold accu n =
1249 if n = Array.length
b
1252 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1259 let x = xoff
+ state.x in
1260 let pagey = max
0 (y - vy) in
1261 let pagedispy = if pagey > 0 then 0 else vy - y in
1262 let pagedispx, pagex
=
1276 let pagecolw = pagew
/columns
in
1278 if pagecolw < conf.winw
1279 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1283 let vw = conf.winw
- pagedispx - state.scrollw
in
1284 let pw = pagew
- pagex
in
1287 let pagevw = min
pagevw pagecolw in
1288 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1289 if pagevw > 0 && pagevh > 0
1292 { pageno = n/columns
1293 ; pagedimno
= pdimno
1300 ; pagedispx = pagedispx
1301 ; pagedispy = pagedispy
1302 ; pagecol
= n mod columns
1313 List.rev
(fold [] 0)
1317 if nogeomcmds state.geomcmds
1319 match conf.columns
with
1320 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1321 | Cmulti
c -> layoutN c y sh
1322 | Csplit
s -> layoutS s y sh
1327 let y = state.y + incr
in
1329 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1334 let tilex = l
.pagex
mod conf.tilew
in
1335 let tiley = l
.pagey mod conf.tileh
in
1337 let col = l
.pagex
/ conf.tilew
in
1338 let row = l
.pagey / conf.tileh
in
1340 let rec rowloop row y0 dispy h
=
1344 let dh = conf.tileh
- y0 in
1345 let dh = min h
dh in
1346 let rec colloop col x0 dispx w
=
1350 let dw = conf.tilew
- x0 in
1351 let dw = min w
dw in
1353 f col row dispx dispy
x0 y0 dw dh;
1354 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1357 colloop col tilex l
.pagedispx l
.pagevw;
1358 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1361 if l
.pagevw > 0 && l
.pagevh > 0
1362 then rowloop row tiley l
.pagedispy l
.pagevh;
1365 let gettileopaque l
col row =
1367 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1369 try Some
(Hashtbl.find state.tilemap
key)
1370 with Not_found
-> None
1373 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1374 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1375 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1378 let drawtiles l color
=
1380 let f col row x y tilex tiley w h
=
1381 match gettileopaque l
col row with
1382 | Some
(opaque
, _, t
) ->
1383 let params = x, y, w
, h
, tilex, tiley in
1387 GlFunc.blend_func `zero `one_minus_src_color
;
1389 drawtile
params opaque
;
1391 then Gl.disable `blend
;
1394 let s = Printf.sprintf
1398 let w = measurestr
fstate.fontsize
s in
1399 GlMisc.push_attrib
[`current
];
1400 GlDraw.color
(0.0, 0.0, 0.0);
1402 (float (x-2), float (y-2))
1403 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1404 GlDraw.color
(1.0, 1.0, 1.0);
1405 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1406 GlMisc.pop_attrib
();
1411 let lw = conf.winw
- state.scrollw
- x in
1414 let lh = conf.winh
- y in
1417 begin match state.texid
with
1419 Gl.enable `texture_2d
;
1420 GlTex.bind_texture `texture_2d id
;
1423 and x1 = float (x+w)
1424 and y1 = float (y+h
) in
1426 let tw = float w /. 16.0
1427 and th
= float h
/. 16.0 in
1428 let tx0 = float tilex /. 16.0
1429 and ty0
= float tiley /. 16.0 in
1431 and ty1
= ty0
+. th
in
1432 GlDraw.begins `quads
;
1433 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1434 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1435 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1436 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1439 Gl.disable `texture_2d
;
1441 GlDraw.color
(1.0, 1.0, 1.0);
1444 (float (x+w), float (y+h
));
1446 if w > 128 && h
> fstate.fontsize
+ 10
1448 GlDraw.color
(0.0, 0.0, 0.0);
1451 then (col*conf.tilew
, row*conf.tileh
)
1454 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1461 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1463 let tilevisible1 l
x y =
1465 and ax1
= l
.pagex
+ l
.pagevw
1467 and ay1
= l
.pagey + l
.pagevh in
1471 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1472 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1474 let rx0 = max
ax0 bx0
1475 and ry0
= max ay0 by0
1476 and rx1
= min ax1
bx1
1477 and ry1
= min ay1 by1
in
1479 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1480 nonemptyintersection
1483 let tilevisible layout n x y =
1484 let rec findpageinlayout m
= function
1485 | l
:: rest
when l
.pageno = n ->
1486 tilevisible1 l
x y || (
1487 match conf.columns
with
1488 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1491 | _ :: rest
-> findpageinlayout 0 rest
1494 findpageinlayout 0 layout;
1497 let tileready l
x y =
1498 tilevisible1 l
x y &&
1499 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1502 let tilepage n p
layout =
1503 let rec loop = function
1507 let f col row _ _ _ _ _ _ =
1508 if state.currently
= Idle
1510 match gettileopaque l
col row with
1513 let x = col*conf.tilew
1514 and y = row*conf.tileh
in
1516 let w = l
.pagew
- x in
1520 let h = l
.pageh
- y in
1525 then getpbo
w h conf.colorspace
1528 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1531 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1532 conf.tilew
, conf.tileh
1541 if nogeomcmds state.geomcmds
1545 let preloadlayout y =
1546 let y = if y < conf.winh
then 0 else y - conf.winh
in
1547 let h = conf.winh
*3 in
1552 let rec loop pages
=
1553 if state.currently
!= Idle
1558 begin match getopaque l
.pageno with
1560 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1561 state.currently
<- Loading
(l
, state.gen
);
1563 tilepage l
.pageno opaque pages
;
1568 if nogeomcmds state.geomcmds
1574 if conf.preload && state.currently
= Idle
1575 then load (preloadlayout state.y);
1578 let layoutready layout =
1579 let rec fold all ls
=
1580 all
&& match ls
with
1582 let seen = ref false in
1583 let allvisible = ref true in
1584 let foo col row _ _ _ _ _ _ =
1586 allvisible := !allvisible &&
1587 begin match gettileopaque l
col row with
1593 fold (!seen && !allvisible) rest
1596 let alltilesvisible = fold true layout in
1601 let y = bound y 0 state.maxy
in
1602 let y, layout, proceed
=
1603 match conf.maxwait
with
1604 | Some time
when state.ghyll
== noghyll ->
1605 begin match state.throttle
with
1607 let layout = layout y conf.winh
in
1608 let ready = layoutready layout in
1612 state.throttle
<- Some
(layout, y, now ());
1614 else G.postRedisplay "gotoy showall (None)";
1616 | Some
(_, _, started
) ->
1617 let dt = now () -. started
in
1620 state.throttle
<- None
;
1621 let layout = layout y conf.winh
in
1623 G.postRedisplay "maxwait";
1630 let layout = layout y conf.winh
in
1631 if true || layoutready layout
1632 then G.postRedisplay "gotoy ready";
1638 state.layout <- layout;
1639 begin match state.mode
with
1640 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1641 let rec loop = function
1643 state.mode
<- LinkNav
(Ltgendir
0)
1644 | l
:: _ when l
.pageno = pageno ->
1645 begin match getopaque pageno with
1647 state.mode
<- LinkNav
(Ltgendir
0)
1649 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1650 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1651 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1652 then state.mode
<- LinkNav
(Ltgendir
0)
1654 | _ :: rest
-> loop rest
1659 begin match state.mode
with
1660 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1661 if not
(pagevisible layout pageno)
1663 match state.layout with
1666 state.mode
<- Birdseye
(
1667 conf, leftx
, l
.pageno, hooverpageno
, anchor
1670 | LinkNav
(Ltgendir dir
as lt
) ->
1672 let rec loop = function
1675 match getopaque l
.pageno with
1681 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1683 if dir
> 0 then LDfirst
else LDlast
1689 | Lnotfound
-> loop rest
1691 showlinktype (getlink opaque
n);
1692 Ltexact
(l
.pageno, n)
1696 state.mode
<- LinkNav
linknav
1701 state.ghyll
<- noghyll;
1704 let mx, my
= state.mpos
in
1709 let conttiling pageno opaque
=
1710 tilepage pageno opaque
1711 (if conf.preload then preloadlayout state.y else state.layout)
1714 let gotoy_and_clear_text y =
1715 if not
conf.verbose
then state.text <- "";
1721 let coloff = l
.pagecol
* l
.pageh
in
1722 float (l
.pagey + coloff) /. float l
.pageh
1729 if conf.presentation
1730 then float l
.pagedispy /. float (calcips l
.pageh
)
1731 else float l
.pagedispy /. float conf.interpagespace
1733 (l
.pageno, top, dtop)
1737 match state.layout with
1738 | l
:: _ -> getanchor1 l
1740 let n = page_of_y state.y in
1741 let y, h = getpageyh n in
1742 let dy = y - state.y in
1744 if conf.presentation
1746 let ips = calcips h in
1747 float (dy + ips) /. float ips
1749 float dy /. float conf.interpagespace
1754 let getanchory (n, top, dtop) =
1755 let y, h = getpageyh n in
1756 if conf.presentation
1758 let ips = calcips h in
1759 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1761 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1764 let gotoanchor anchor
=
1765 gotoy (getanchory anchor
);
1769 cbput state.hists
.nav
(getanchor ());
1773 let anchor = cbgetc state.hists
.nav dir
in
1778 let scroll f n a
b =
1779 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1781 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1783 then s (float f /. float a
)
1786 then 1.0 -. s ((float (f-b) /. float (n-b)))
1793 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1794 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1796 let ins = float a
*. iv1
1797 and outs
= float (n-b) *. iv1 in
1799 ins +. outs
+. float ones
1801 let rec set (_N
, _A
, _B
) y sy
=
1802 let sum = summa
1.0 _N _A _B
in
1803 let dy = float (y - sy
) in
1807 then state.ghyll
<- noghyll
1810 let s = scroll n _N _A _B
in
1811 let y1 = y1 +. ((s *. dy) /. sum) in
1812 gotoy_and_clear_text (truncate
y1);
1813 state.ghyll
<- gf (n+1) y1;
1817 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1819 gf 0 (float state.y)
1822 match conf.ghyllscroll
with
1824 gotoy_and_clear_text y
1826 if state.ghyll
== noghyll
1827 then set nab
y state.y
1828 else state.ghyll
(Some
y)
1831 let gotopage n top =
1832 let y, h = getpageyh n in
1833 let y = y + (truncate
(top *. float h)) in
1837 let gotopage1 n top =
1838 let y = getpagey n in
1843 let invalidate s f =
1848 match state.geomcmds
with
1849 | ps
, [] when String.length ps
= 0 ->
1851 state.geomcmds
<- s, [];
1854 state.geomcmds
<- ps
, [s, f];
1856 | ps
, (s'
, _) :: rest
when s'
= s ->
1857 state.geomcmds
<- ps
, ((s, f) :: rest
);
1860 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1864 Hashtbl.iter
(fun _ opaque
->
1865 wcmd "freepage %s" opaque
;
1867 Hashtbl.clear
state.pagemap
;
1870 let opendoc path password nameddest
=
1872 state.password
<- password
;
1873 state.gen
<- state.gen
+ 1;
1874 state.docinfo
<- [];
1875 state.nameddest
<- nameddest
;
1878 setaalevel
conf.aalevel
;
1879 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1880 wcmd "open %d %s\000%s\000%s\000" (btod state.wthack
) path password nameddest
;
1881 invalidate "reqlayout"
1883 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1887 state.anchor <- getanchor ();
1888 state.wthack
<- true;
1889 opendoc state.path
state.password
state.nameddest
;
1893 let c = c *. conf.colorscale
in
1897 let scalecolor2 (r, g
, b) =
1898 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1901 let docolumns = function
1903 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1904 let rec loop pageno pdimno pdim
y ph pdims
=
1905 if pageno = state.pagecount
1908 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1910 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1911 pdimno+1, pdim
, rest
1915 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1917 (if conf.presentation
1918 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1919 else (if pageno = 0 then 0 else conf.interpagespace
)
1922 a.(pageno) <- (pdimno, x, y, pdim
);
1923 loop (pageno+1) pdimno pdim
(y + h) h pdims
1925 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1926 conf.columns
<- Csingle
a;
1928 | Cmulti
((columns
, coverA
, coverB
), _) ->
1929 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1930 let rec loop pageno pdimno pdim
x y rowh pdims
=
1931 let rec fixrow m
= if m
= pageno then () else
1932 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1935 let y = y + (rowh
- h) / 2 in
1936 a.(m
) <- (pdimno, x, y, pdim
);
1940 if pageno = state.pagecount
1941 then fixrow (((pageno - 1) / columns
) * columns
)
1943 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1945 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1946 pdimno+1, pdim
, rest
1951 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1953 let x = (conf.winw
- state.scrollw
- w) / 2 in
1955 if conf.presentation
then calcips h else conf.interpagespace
in
1956 x, y + ips + rowh
, h
1959 if (pageno - coverA
) mod columns
= 0
1961 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1963 if conf.presentation
1965 let ips = calcips h in
1966 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1968 y + (if pageno = 0 then 0 else conf.interpagespace
)
1972 else x, y, max rowh
h
1976 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1979 if pageno = columns
&& conf.presentation
1981 let ips = calcips rowh
in
1982 for i
= 0 to pred columns
1984 let (pdimno, x, y, pdim
) = a.(i
) in
1985 a.(i
) <- (pdimno, x, y+ips, pdim
)
1991 fixrow (pageno - columns
);
1996 a.(pageno) <- (pdimno, x, y, pdim
);
1997 let x = x + w + xoff
*2 + conf.interpagespace
in
1998 loop (pageno+1) pdimno pdim
x y rowh' pdims
2000 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2001 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2004 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2005 let rec loop pageno pdimno pdim
y pdims
=
2006 if pageno = state.pagecount
2009 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2011 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2012 pdimno+1, pdim
, rest
2017 let rec loop1 n x y =
2018 if n = c then y else (
2019 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2020 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2023 let y = loop1 0 0 y in
2024 loop (pageno+1) pdimno pdim
y pdims
2026 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2027 conf.columns
<- Csplit
(c, a);
2031 docolumns conf.columns
;
2032 state.maxy
<- calcheight ();
2034 if state.w <= conf.winw
- state.scrollw
2038 match state.mode
with
2039 | Birdseye
(_, _, pageno, _, _) ->
2040 let y, h = getpageyh pageno in
2041 let top = (conf.winh
- h) / 2 in
2042 gotoy (max
0 (y - top))
2043 | _ -> gotoanchor state.anchor
2047 state.wthack
<- false;
2048 GlDraw.viewport
0 0 w h;
2049 let firsttime = state.geomcmds
== firstgeomcmds in
2050 if not
firsttime && nogeomcmds state.geomcmds
2051 then state.anchor <- getanchor ();
2054 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2057 setfontsize fstate.fontsize
;
2058 GlMat.mode `modelview
;
2059 GlMat.load_identity
();
2061 GlMat.mode `projection
;
2062 GlMat.load_identity
();
2063 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2064 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2065 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2070 else float state.x /. float state.w
2072 invalidate "geometry"
2076 then state.x <- truncate
(relx *. float w);
2078 match conf.columns
with
2080 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2081 | Csplit
(c, _) -> w * c
2083 wcmd "geometry %d %d" w h);
2087 let len = String.length
state.text in
2090 match state.mode
with
2093 let h, _, _ = state.uioh#scrollpw
in
2099 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2100 (x+.w, float (conf.winh
- hscrollh))
2103 let w = float (conf.winw
- state.scrollw
- 1) in
2104 if state.progress
>= 0.0 && state.progress
< 1.0
2106 GlDraw.color
(0.3, 0.3, 0.3);
2107 let w1 = w *. state.progress
in
2109 GlDraw.color
(0.0, 0.0, 0.0);
2113 GlDraw.color
(0.0, 0.0, 0.0);
2117 GlDraw.color
(1.0, 1.0, 1.0);
2118 drawstring fstate.fontsize
2119 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2122 match state.mode
with
2123 | Textentry
((prefix
, text, _, _, _, _), _) ->
2127 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2129 Printf.sprintf
"%s%s_" prefix
text
2138 if not
(istextentry state.mode
)
2140 let s1 = "(press 'e' to review error messasges)" in
2141 if String.length
s > 0 then s ^
" " ^
s1 else s1
2146 if String.length
s > 0
2151 let len = Queue.length
state.tilelru
in
2153 match state.throttle
with
2156 then preloadlayout state.y
2158 | Some
(layout, _, _) ->
2162 if state.memused
<= conf.memlimit
2167 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2168 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2169 let (_, pw, ph
, _) = getpagedim n in
2172 && colorspace
= conf.colorspace
2173 && angle
= conf.angle
2177 let x = col*conf.tilew
2178 and y = row*conf.tileh
in
2179 tilevisible (Lazy.force_val
layout) n x y
2181 then Queue.push lruitem
state.tilelru
2184 wcmd "freetile %s" p
;
2185 state.memused
<- state.memused
- s;
2186 state.uioh#infochanged Memused
;
2187 Hashtbl.remove
state.tilemap k
;
2196 Queue.iter
(fun (k
, p
, s) ->
2197 wcmd "freetile %s" p
;
2198 state.memused
<- state.memused
- s;
2199 state.uioh#infochanged Memused
;
2200 Hashtbl.remove
state.tilemap k
;
2202 Queue.clear
state.tilelru
;
2206 let logcurrently = function
2207 | Idle
-> dolog "Idle"
2208 | Loading
(l
, gen
) ->
2209 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2210 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2212 "Tiling %d[%d,%d] page=%s cs=%s angle"
2213 l
.pageno col row pageopaque
2214 (colorspace_to_string colorspace
)
2216 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2217 angle gen
conf.angle
state.gen
2219 conf.tilew
conf.tileh
2226 (* dolog "%S" cmds; *)
2229 try String.index cmds ' '
2230 with Not_found
-> -1
2235 let l = String.length cmds
in
2236 let op = String.sub cmds
0 spacepos in
2238 if l - spacepos < 2 then ""
2239 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2244 state.uioh#infochanged Pdim
;
2248 state.rects
<- state.rects1
;
2249 G.postRedisplay "clearrects";
2253 try Scanf.sscanf
args "%u" (fun n -> n)
2255 dolog "error processing 'continue' %S: %s"
2256 cmds
(Printexc.to_string exn
);
2259 state.pagecount
<- n;
2260 begin match state.currently
with
2262 state.currently
<- Idle
;
2263 state.outlines
<- Array.of_list
(List.rev
l)
2267 let cur, cmds
= state.geomcmds
in
2268 if String.length
cur = 0
2269 then failwith
"umpossible";
2271 begin match List.rev cmds
with
2273 state.geomcmds
<- "", [];
2277 state.geomcmds
<- s, List.rev rest
;
2279 if conf.maxwait
= None
2280 then G.postRedisplay "continue";
2290 then showtext ' '
args
2293 Buffer.add_string
state.errmsgs
args;
2294 state.newerrmsgs
<- true;
2295 G.postRedisplay "error message"
2298 let progress, text =
2300 Scanf.sscanf
args "%f %n"
2302 f, String.sub
args pos
(String.length
args - pos
))
2304 dolog "error processing 'progress' %S: %s"
2305 cmds
(Printexc.to_string exn
);
2309 state.progress <- progress;
2310 G.postRedisplay "progress"
2313 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2315 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2316 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2317 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2319 dolog "error processing 'firstmatch' %S: %s"
2320 cmds
(Printexc.to_string exn
);
2323 let y = (getpagey pageno) + truncate
y0 in
2326 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2329 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2331 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2332 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2333 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2335 dolog "error processing 'match' %S: %s"
2336 cmds
(Printexc.to_string exn
);
2340 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2345 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2347 dolog "error processing 'page' %S: %s"
2348 cmds
(Printexc.to_string exn
);
2351 begin match state.currently
with
2352 | Loading
(l, gen
) ->
2353 vlog "page %d took %f sec" l.pageno t
;
2354 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2355 begin match state.throttle
with
2357 let preloadedpages =
2359 then preloadlayout state.y
2364 Set.Make
(struct type t
= int let compare = (-) end) in
2366 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2367 IntSet.empty
preloadedpages
2370 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2371 if not
(IntSet.mem
pageno set)
2373 wcmd "freepage %s" opaque
;
2379 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2382 state.currently
<- Idle
;
2385 tilepage l.pageno pageopaque state.layout;
2387 load preloadedpages;
2388 if pagevisible state.layout l.pageno
2389 && layoutready state.layout
2390 then G.postRedisplay "page";
2393 | Some
(layout, _, _) ->
2394 state.currently
<- Idle
;
2395 tilepage l.pageno pageopaque layout;
2400 dolog "Inconsistent loading state";
2401 logcurrently state.currently
;
2406 let (x, y, opaque
, size
, t
) =
2408 Scanf.sscanf
args "%u %u %s %u %f"
2409 (fun x y p size t
-> (x, y, p
, size
, t
))
2411 dolog "error processing 'tile' %S: %s"
2412 cmds
(Printexc.to_string exn
);
2415 begin match state.currently
with
2416 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2417 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2420 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2422 wcmd "freetile %s" opaque
;
2423 state.currently
<- Idle
;
2427 puttileopaque l col row gen cs angle opaque size t
;
2428 state.memused
<- state.memused
+ size
;
2429 state.uioh#infochanged Memused
;
2431 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2432 opaque
, size
) state.tilelru
;
2435 match state.throttle
with
2436 | None
-> state.layout
2437 | Some
(layout, _, _) -> layout
2440 state.currently
<- Idle
;
2442 && conf.colorspace
= cs
2443 && conf.angle
= angle
2444 && tilevisible layout l.pageno x y
2445 then conttiling l.pageno pageopaque;
2447 begin match state.throttle
with
2449 state.wthack
<- false;
2450 preload state.layout;
2452 && conf.colorspace
= cs
2453 && conf.angle
= angle
2454 && tilevisible state.layout l.pageno x y
2455 then G.postRedisplay "tile nothrottle";
2457 | Some
(layout, y, _) ->
2458 let ready = layoutready layout in
2461 state.wthack
<- false;
2463 state.layout <- layout;
2464 state.throttle
<- None
;
2465 G.postRedisplay "throttle";
2472 dolog "Inconsistent tiling state";
2473 logcurrently state.currently
;
2480 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2482 dolog "error processing 'pdim' %S: %s"
2483 cmds
(Printexc.to_string exn
);
2486 state.uioh#infochanged Pdim
;
2487 state.pdims
<- pdim :: state.pdims
2490 let (l, n, t
, h, pos
) =
2492 Scanf.sscanf
args "%u %u %d %u %n"
2493 (fun l n t
h pos
-> l, n, t
, h, pos
)
2495 dolog "error processing 'o' %S: %s"
2496 cmds
(Printexc.to_string exn
);
2499 let s = String.sub
args pos
(String.length
args - pos
) in
2500 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2501 begin match state.currently
with
2502 | Outlining outlines
->
2503 state.currently
<- Outlining
(outline :: outlines
)
2505 state.currently
<- Outlining
[outline]
2507 dolog "invalid outlining state";
2508 logcurrently currently
2514 Scanf.sscanf
args "%u %u %d"
2515 (fun n t
h -> n, t
, h)
2517 dolog "error processing 'a' %S: %s"
2518 cmds
(Printexc.to_string exn
);
2521 state.anchor <- (n, float t
/. float h, 0.0)
2524 state.docinfo
<- (1, args) :: state.docinfo
2527 state.uioh#infochanged Docinfo
;
2528 state.docinfo
<- List.rev
state.docinfo
2531 dolog "unknown cmd `%S'" cmds
2536 let action = function
2537 | HCprev
-> cbget cb ~
-1
2538 | HCnext
-> cbget cb
1
2539 | HCfirst
-> cbget cb ~
-(cb
.rc)
2540 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2541 and cancel
() = cb
.rc <- rc
2545 let search pattern forward
=
2546 if String.length pattern
> 0
2549 match state.layout with
2552 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2554 wcmd "search %d %d %d %d,%s\000"
2555 (btod conf.icase
) pn py
(btod forward
) pattern
;
2558 let intentry text key =
2560 if key >= 32 && key < 127
2566 let text = addchar text c in
2570 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2574 let linknentry text key =
2576 if key >= 32 && key < 127
2582 let text = addchar text c in
2586 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2591 if String.length
s > 0
2594 let l = String.length
s in
2595 let rec loop pos
n = if pos
= l then n else
2596 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2597 loop (pos
+1) (n*26 + m)
2600 let rec loop n = function
2603 match getopaque l.pageno with
2604 | None
-> loop n rest
2606 let m = getlinkcount opaque
in
2609 let under = getlink opaque
n in
2612 else loop (n-m) rest
2614 loop n state.layout;
2618 let textentry text key =
2619 if key land 0xff00 = 0xff00
2621 else TEcont
(text ^
Wsi.toutf8
key)
2624 let reqlayout angle proportional
=
2625 match state.throttle
with
2627 if nogeomcmds state.geomcmds
2628 then state.anchor <- getanchor ();
2629 conf.angle
<- angle
mod 360;
2632 match state.mode
with
2633 | LinkNav
_ -> state.mode
<- View
2636 conf.proportional
<- proportional
;
2637 invalidate "reqlayout"
2638 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2642 let settrim trimmargins trimfuzz
=
2643 if nogeomcmds state.geomcmds
2644 then state.anchor <- getanchor ();
2645 conf.trimmargins
<- trimmargins
;
2646 conf.trimfuzz
<- trimfuzz
;
2647 let x0, y0, x1, y1 = trimfuzz
in
2648 invalidate "settrim"
2650 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2655 match state.throttle
with
2657 let zoom = max
0.01 zoom in
2658 if zoom <> conf.zoom
2660 state.prevzoom
<- conf.zoom;
2662 reshape conf.winw
conf.winh
;
2663 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2666 | Some
(layout, y, started
) ->
2668 match conf.maxwait
with
2672 let dt = now () -. started
in
2680 let setcolumns mode columns coverA coverB
=
2681 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2685 then showtext '
!'
"split mode doesn't work in bird's eye"
2687 conf.columns
<- Csplit
(-columns
, [||]);
2695 conf.columns
<- Csingle
[||];
2700 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2704 reshape conf.winw
conf.winh
;
2707 let enterbirdseye () =
2708 let zoom = float conf.thumbw
/. float conf.winw
in
2709 let birdseyepageno =
2710 let cy = conf.winh
/ 2 in
2714 let rec fold best
= function
2717 let d = cy - (l.pagedispy + l.pagevh/2)
2718 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2719 if abs
d < abs dbest
2726 state.mode
<- Birdseye
(
2727 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2730 conf.presentation
<- false;
2731 conf.interpagespace
<- 10;
2732 conf.hlinks
<- false;
2734 state.mstate
<- Mnone
;
2735 conf.maxwait
<- None
;
2737 match conf.beyecolumns
with
2740 Cmulti
((c, 0, 0), [||])
2741 | None
-> Csingle
[||]
2743 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2746 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2751 reshape conf.winw
conf.winh
;
2754 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2756 conf.zoom <- c.zoom;
2757 conf.presentation
<- c.presentation
;
2758 conf.interpagespace
<- c.interpagespace
;
2759 conf.maxwait
<- c.maxwait
;
2760 conf.hlinks
<- c.hlinks
;
2761 conf.beyecolumns
<- (
2762 match conf.columns
with
2763 | Cmulti
((c, _, _), _) -> Some
c
2765 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2768 match c.columns
with
2769 | Cmulti
(c, _) -> Cmulti
(c, [||])
2770 | Csingle
_ -> Csingle
[||]
2771 | Csplit
(c, _) -> Csplit
(c, [||])
2776 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2779 reshape conf.winw
conf.winh
;
2780 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2783 let togglebirdseye () =
2784 match state.mode
with
2785 | Birdseye vals
-> leavebirdseye vals
true
2786 | View
-> enterbirdseye ()
2790 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2791 let pageno = max
0 (pageno - incr
) in
2792 let rec loop = function
2793 | [] -> gotopage1 pageno 0
2794 | l :: _ when l.pageno = pageno ->
2795 if l.pagedispy >= 0 && l.pagey = 0
2796 then G.postRedisplay "upbirdseye"
2797 else gotopage1 pageno 0
2798 | _ :: rest
-> loop rest
2801 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2804 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2805 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2806 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2807 let rec loop = function
2809 let y, h = getpageyh pageno in
2810 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2812 | l :: _ when l.pageno = pageno ->
2813 if l.pagevh != l.pageh
2814 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2815 else G.postRedisplay "downbirdseye"
2816 | _ :: rest
-> loop rest
2821 let optentry mode
_ key =
2822 let btos b = if b then "on" else "off" in
2823 if key >= 32 && key < 127
2825 let c = Char.chr
key in
2829 try conf.scrollstep
<- int_of_string
s with exc
->
2830 state.text <- Printf.sprintf
"bad integer `%s': %s"
2831 s (Printexc.to_string exc
)
2833 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2838 conf.autoscrollstep
<- int_of_string
s;
2839 if state.autoscroll
<> None
2840 then state.autoscroll
<- Some
conf.autoscrollstep
2842 state.text <- Printf.sprintf
"bad integer `%s': %s"
2843 s (Printexc.to_string exc
)
2845 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2850 let n, a, b = multicolumns_of_string s in
2851 setcolumns mode
n a b;
2853 state.text <- Printf.sprintf
"bad columns `%s': %s"
2854 s (Printexc.to_string exc
)
2856 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2861 let zoom = float (int_of_string
s) /. 100.0 in
2864 state.text <- Printf.sprintf
"bad integer `%s': %s"
2865 s (Printexc.to_string exc
)
2867 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2872 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2874 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2875 begin match mode
with
2877 leavebirdseye beye
false;
2882 state.text <- Printf.sprintf
"bad integer `%s': %s"
2883 s (Printexc.to_string exc
)
2885 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2890 Some
(int_of_string
s)
2892 state.text <- Printf.sprintf
"bad integer `%s': %s"
2893 s (Printexc.to_string exc
);
2896 | Some angle
-> reqlayout angle
conf.proportional
2899 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2902 conf.icase
<- not
conf.icase
;
2903 TEdone
("case insensitive search " ^
(btos conf.icase
))
2906 conf.preload <- not
conf.preload;
2908 TEdone
("preload " ^
(btos conf.preload))
2911 conf.verbose
<- not
conf.verbose
;
2912 TEdone
("verbose " ^
(btos conf.verbose
))
2915 conf.debug
<- not
conf.debug
;
2916 TEdone
("debug " ^
(btos conf.debug
))
2919 conf.maxhfit
<- not
conf.maxhfit
;
2920 state.maxy
<- calcheight ();
2921 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2924 conf.crophack
<- not
conf.crophack
;
2925 TEdone
("crophack " ^
btos conf.crophack
)
2929 match conf.maxwait
with
2931 conf.maxwait
<- Some infinity
;
2932 "always wait for page to complete"
2934 conf.maxwait
<- None
;
2935 "show placeholder if page is not ready"
2940 conf.underinfo
<- not
conf.underinfo
;
2941 TEdone
("underinfo " ^
btos conf.underinfo
)
2944 conf.savebmarks
<- not
conf.savebmarks
;
2945 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2951 match state.layout with
2956 conf.interpagespace
<- int_of_string
s;
2957 docolumns conf.columns
;
2958 state.maxy
<- calcheight ();
2959 let y = getpagey pageno in
2962 state.text <- Printf.sprintf
"bad integer `%s': %s"
2963 s (Printexc.to_string exc
)
2965 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2968 reqlayout conf.angle
(not
conf.proportional
);
2969 TEdone
("proportional display " ^
btos conf.proportional
)
2972 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2973 TEdone
("trim margins " ^
btos conf.trimmargins
)
2976 conf.invert
<- not
conf.invert
;
2977 TEdone
("invert colors " ^
btos conf.invert
)
2981 cbput state.hists
.sel
s;
2984 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2985 textentry, ondone, true)
2988 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2994 class type lvsource
= object
2995 method getitemcount
: int
2996 method getitem
: int -> (string * int)
2997 method hasaction
: int -> bool
3006 method getactive
: int
3007 method getfirst
: int
3008 method getqsearch
: string
3009 method setqsearch
: string -> unit
3013 class virtual lvsourcebase
= object
3014 val mutable m_active
= 0
3015 val mutable m_first
= 0
3016 val mutable m_qsearch
= ""
3017 val mutable m_pan
= 0
3018 method getactive
= m_active
3019 method getfirst
= m_first
3020 method getqsearch
= m_qsearch
3021 method getpan
= m_pan
3022 method setqsearch
s = m_qsearch
<- s
3025 let withoutlastutf8 s =
3026 let len = String.length
s in
3034 let b = Char.code
s.[pos
] in
3035 if b land 0b11000000 = 0b11000000
3040 if Char.code
s.[len-1] land 0x80 = 0
3044 String.sub
s 0 first;
3047 let textentrykeyboard
3048 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3050 if key >= 0xffb0 && key <= 0xffb9
3051 then key - 0xffb0 + 48 else key
3054 state.mode
<- Textentry
(te
, onleave
);
3057 G.postRedisplay "textentrykeyboard enttext";
3059 let histaction cmd
=
3062 | Some
(action, _) ->
3063 state.mode
<- Textentry
(
3064 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3066 G.postRedisplay "textentry histaction"
3069 | 0xff08 -> (* backspace *)
3070 let s = withoutlastutf8 text in
3071 let len = String.length
s in
3072 if cancelonempty
&& len = 0
3075 G.postRedisplay "textentrykeyboard after cancel";
3078 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3081 | 0xff0d | 0xff8d -> (* (kp) enter *)
3084 G.postRedisplay "textentrykeyboard after confirm"
3086 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3087 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3088 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3089 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3091 | 0xff1b -> (* escape*)
3092 if String.length
text = 0
3094 begin match opthist
with
3096 | Some
(_, onhistcancel
) -> onhistcancel
()
3100 G.postRedisplay "textentrykeyboard after cancel2"
3103 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3106 | 0xff9f | 0xffff -> () (* delete *)
3109 && key land 0xff00 != 0xff00 (* keyboard *)
3110 && key land 0xfe00 != 0xfe00 (* xkb *)
3111 && key land 0xfd00 != 0xfd00 (* 3270 *)
3113 begin match onkey
text key with
3117 G.postRedisplay "textentrykeyboard after confirm2";
3120 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3124 G.postRedisplay "textentrykeyboard after cancel3"
3127 state.mode
<- Textentry
(te
, onleave
);
3128 G.postRedisplay "textentrykeyboard switch";
3132 vlog "unhandled key %s" (Wsi.keyname
key)
3135 let firstof first active
=
3136 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3137 then max
0 (active
- (fstate.maxrows
/2))
3141 let calcfirst first active
=
3144 let rows = active
- first in
3145 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3149 let scrollph y maxy
=
3150 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3151 let sh = float conf.winh
/. sh in
3152 let sh = max
sh (float conf.scrollh
) in
3157 else float y /. float maxy
3159 let position = (float conf.winh
-. sh) *. percent in
3162 if position +. sh > float conf.winh
3163 then float conf.winh
-. sh
3169 let coe s = (s :> uioh
);;
3171 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3173 val m_pan
= source#getpan
3174 val m_first
= source#getfirst
3175 val m_active
= source#getactive
3176 val m_qsearch
= source#getqsearch
3177 val m_prev_uioh
= state.uioh
3179 method private elemunder
y =
3180 let n = y / (fstate.fontsize
+1) in
3181 if m_first
+ n < source#getitemcount
3183 if source#hasaction
(m_first
+ n)
3184 then Some
(m_first
+ n)
3191 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3192 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3193 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3194 GlDraw.color
(1., 1., 1.);
3195 Gl.enable `texture_2d
;
3196 let fs = fstate.fontsize
in
3198 let ww = fstate.wwidth
in
3199 let tabw = 30.0*.ww in
3200 let itemcount = source#getitemcount
in
3202 if (row - m_first
) > fstate.maxrows
3205 if row >= 0 && row < itemcount
3207 let (s, level
) = source#getitem
row in
3208 let y = (row - m_first
) * nfs in
3209 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3212 Gl.disable `texture_2d
;
3213 GlDraw.polygon_mode `both `line
;
3214 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3215 GlDraw.rect (1., float (y + 1))
3216 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3217 GlDraw.polygon_mode `both `fill
;
3218 GlDraw.color
(1., 1., 1.);
3219 Gl.enable `texture_2d
;
3222 let drawtabularstring s =
3223 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3226 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3229 let len = String.length
s - tabpos - 1 in
3230 let s1 = String.sub
s 0 tabpos
3231 and s2
= String.sub
s (tabpos + 1) len in
3232 let nx = drawstr x s1 in
3234 let x = x +. (max
tabw sw) in
3241 let _ = drawtabularstring s in
3248 Gl.disable `texture_2d
;
3250 method updownlevel incr
=
3251 let len = source#getitemcount
in
3253 if m_active
>= 0 && m_active
< len
3254 then snd
(source#getitem m_active
)
3258 if i
= len then i
-1 else if i
= -1 then 0 else
3259 let _, l = source#getitem i
in
3260 if l != curlevel then i
else flow (i
+incr
)
3262 let active = flow m_active
in
3263 let first = calcfirst m_first
active in
3264 G.postRedisplay "outline updownlevel";
3265 {< m_active
= active; m_first
= first >}
3267 method private key1
key mask
=
3268 let set1 active first qsearch
=
3269 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3271 let search active pattern incr
=
3274 if n >= 0 && n < source#getitemcount
3276 let s, _ = source#getitem
n in
3278 (try ignore
(Str.search_forward
re s 0); true
3279 with Not_found
-> false)
3281 else loop (n + incr
)
3288 let re = Str.regexp_case_fold pattern
in
3294 let itemcount = source#getitemcount
in
3295 let find start incr
=
3297 if i
= -1 || i
= itemcount
3300 if source#hasaction i
3302 else find (i
+ incr
)
3307 let set active first =
3308 let first = bound first 0 (itemcount - fstate.maxrows
) in
3310 coe {< m_active
= active; m_first
= first >}
3313 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3315 let incr1 = if incr
> 0 then 1 else -1 in
3316 if isvisible m_first m_active
3319 let next = m_active
+ incr
in
3321 if next < 0 || next >= itemcount
3323 else find next incr1
3325 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3331 let first = m_first
+ incr
in
3332 let first = bound first 0 (itemcount - 1) in
3334 let next = m_active
+ incr
in
3335 let next = bound next 0 (itemcount - 1) in
3338 let active = if next = -1 then m_active
else next in
3341 let first = min
next m_first
in
3343 if abs
(next - first) > fstate.maxrows
3349 let first = m_first
+ incr
in
3350 let first = bound first 0 (itemcount - 1) in
3352 let next = m_active
+ incr
in
3353 let next = bound next 0 (itemcount - 1) in
3354 let next = find next incr1 in
3356 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3358 let active = if m_active
= -1 then next else m_active
in
3363 if isvisible first active
3369 G.postRedisplay "listview navigate";
3373 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3374 let incr = if key = 0x72 then -1 else 1 in
3376 match search (m_active
+ incr) m_qsearch
incr with
3378 state.text <- m_qsearch ^
" [not found]";
3381 state.text <- m_qsearch
;
3382 active, firstof m_first
active
3384 G.postRedisplay "listview ctrl-r/s";
3385 set1 active first m_qsearch
;
3387 | 0xff08 -> (* backspace *)
3388 if String.length m_qsearch
= 0
3391 let qsearch = withoutlastutf8 m_qsearch
in
3392 let len = String.length
qsearch in
3396 G.postRedisplay "listview empty qsearch";
3397 set1 m_active m_first
"";
3401 match search m_active
qsearch ~
-1 with
3403 state.text <- qsearch ^
" [not found]";
3406 state.text <- qsearch;
3407 active, firstof m_first
active
3409 G.postRedisplay "listview backspace qsearch";
3410 set1 active first qsearch
3413 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3414 let pattern = m_qsearch ^
Wsi.toutf8
key in
3416 match search m_active
pattern 1 with
3418 state.text <- pattern ^
" [not found]";
3421 state.text <- pattern;
3422 active, firstof m_first
active
3424 G.postRedisplay "listview qsearch add";
3425 set1 active first pattern;
3427 | 0xff1b -> (* escape *)
3429 if String.length m_qsearch
= 0
3431 G.postRedisplay "list view escape";
3434 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3436 | None
-> m_prev_uioh
3441 G.postRedisplay "list view kill qsearch";
3442 source#setqsearch
"";
3443 coe {< m_qsearch
= "" >}
3446 | 0xff0d | 0xff8d -> (* (kp) enter *)
3448 let self = {< m_qsearch
= "" >} in
3449 source#setqsearch
"";
3451 G.postRedisplay "listview enter";
3452 if m_active
>= 0 && m_active
< source#getitemcount
3454 source#exit
(coe self) false m_active m_first m_pan
"";
3457 source#exit
(coe self) true m_active m_first m_pan
"";
3460 begin match opt with
3461 | None
-> m_prev_uioh
3465 | 0xff9f | 0xffff -> (* (kp) delete *)
3468 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3469 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3470 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3471 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3473 | 0xff53 | 0xff98 -> (* (kp) right *)
3475 G.postRedisplay "listview right";
3476 coe {< m_pan
= m_pan
- 1 >}
3478 | 0xff51 | 0xff96 -> (* (kp) left *)
3480 G.postRedisplay "listview left";
3481 coe {< m_pan
= m_pan
+ 1 >}
3483 | 0xff50 | 0xff95 -> (* (kp) home *)
3484 let active = find 0 1 in
3485 G.postRedisplay "listview home";
3488 | 0xff57 | 0xff9c -> (* (kp) end *)
3489 let first = max
0 (itemcount - fstate.maxrows
) in
3490 let active = find (itemcount - 1) ~
-1 in
3491 G.postRedisplay "listview end";
3494 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3498 dolog "listview unknown key %#x" key; coe self
3500 method key key mask
=
3501 match state.mode
with
3502 | Textentry te
-> textentrykeyboard key mask te
; coe self
3503 | _ -> self#key1
key mask
3505 method button button down
x y _ =
3508 | 1 when x > conf.winw
- conf.scrollbw
->
3509 G.postRedisplay "listview scroll";
3512 let _, position, sh = self#
scrollph in
3513 if y > truncate
position && y < truncate
(position +. sh)
3515 state.mstate
<- Mscrolly
;
3519 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3520 let first = truncate
(s *. float source#getitemcount
) in
3521 let first = min source#getitemcount
first in
3522 Some
(coe {< m_first
= first; m_active
= first >})
3524 state.mstate
<- Mnone
;
3527 | 1 when not down
->
3528 begin match self#elemunder
y with
3530 G.postRedisplay "listview click";
3532 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3536 | n when (n == 4 || n == 5) && not down
->
3537 let len = source#getitemcount
in
3539 if n = 5 && m_first
+ fstate.maxrows
>= len
3543 let first = m_first
+ (if n == 4 then -1 else 1) in
3544 bound first 0 (len - 1)
3546 G.postRedisplay "listview wheel";
3547 Some
(coe {< m_first
= first >})
3548 | n when (n = 6 || n = 7) && not down
->
3549 let inc = m_first
+ (if n = 7 then -1 else 1) in
3550 G.postRedisplay "listview hwheel";
3551 Some
(coe {< m_pan
= m_pan
+ inc >})
3556 | None
-> m_prev_uioh
3560 match state.mstate
with
3562 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3563 let first = truncate
(s *. float source#getitemcount
) in
3564 let first = min source#getitemcount
first in
3565 G.postRedisplay "listview motion";
3566 coe {< m_first
= first; m_active
= first >}
3569 method pmotion
x y =
3570 if x < conf.winw
- conf.scrollbw
3573 match self#elemunder
y with
3574 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3575 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3579 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3584 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3588 method infochanged
_ = ()
3590 method scrollpw
= (0, 0.0, 0.0)
3592 let nfs = fstate.fontsize
+ 1 in
3593 let y = m_first
* nfs in
3594 let itemcount = source#getitemcount
in
3595 let maxi = max
0 (itemcount - fstate.maxrows
) in
3596 let maxy = maxi * nfs in
3597 let p, h = scrollph y maxy in
3600 method modehash
= modehash
3603 class outlinelistview ~source
=
3606 ~source
:(source
:> lvsource
)
3608 ~modehash
:(findkeyhash conf "outline")
3611 method key key mask
=
3612 let calcfirst first active =
3615 let rows = active - first in
3617 if String.length
state.text = 0
3619 else fstate.maxrows - 2
3621 if rows > maxrows then active - maxrows else first
3625 let active = m_active
+ incr in
3626 let active = bound active 0 (source#getitemcount
- 1) in
3627 let first = calcfirst m_first
active in
3628 G.postRedisplay "outline navigate";
3629 coe {< m_active
= active; m_first
= first >}
3631 let ctrl = Wsi.withctrl mask
in
3633 | 110 when ctrl -> (* ctrl-n *)
3634 source#narrow m_qsearch
;
3635 G.postRedisplay "outline ctrl-n";
3636 coe {< m_first
= 0; m_active
= 0 >}
3638 | 117 when ctrl -> (* ctrl-u *)
3640 G.postRedisplay "outline ctrl-u";
3642 coe {< m_first
= 0; m_active
= 0 >}
3644 | 108 when ctrl -> (* ctrl-l *)
3645 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3646 G.postRedisplay "outline ctrl-l";
3647 coe {< m_first
= first >}
3649 | 0xff9f | 0xffff -> (* (kp) delete *)
3650 source#remove m_active
;
3651 G.postRedisplay "outline delete";
3652 let active = max
0 (m_active
-1) in
3653 coe {< m_first
= firstof m_first
active;
3654 m_active
= active >}
3656 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3657 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3658 | 0xff55 | 0xff9a -> (* (kp) prior *)
3659 navigate ~
-(fstate.maxrows)
3660 | 0xff56 | 0xff9b -> (* (kp) next *)
3661 navigate fstate.maxrows
3663 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3667 G.postRedisplay "outline ctrl right";
3668 {< m_pan
= m_pan
+ 1 >}
3670 else self#updownlevel
1
3674 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3678 G.postRedisplay "outline ctrl left";
3679 {< m_pan
= m_pan
- 1 >}
3681 else self#updownlevel ~
-1
3685 | 0xff50 | 0xff95 -> (* (kp) home *)
3686 G.postRedisplay "outline home";
3687 coe {< m_first
= 0; m_active
= 0 >}
3689 | 0xff57 | 0xff9c -> (* (kp) end *)
3690 let active = source#getitemcount
- 1 in
3691 let first = max
0 (active - fstate.maxrows) in
3692 G.postRedisplay "outline end";
3693 coe {< m_active
= active; m_first
= first >}
3695 | _ -> super#
key key mask
3698 let outlinesource usebookmarks
=
3701 inherit lvsourcebase
3702 val mutable m_items
= empty
3703 val mutable m_orig_items
= empty
3704 val mutable m_prev_items
= empty
3705 val mutable m_narrow_pattern
= ""
3706 val mutable m_hadremovals
= false
3708 method getitemcount
=
3709 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3712 if n == Array.length m_items
&& m_hadremovals
3714 ("[Confirm removal]", 0)
3716 let s, n, _ = m_items
.(n) in
3719 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3720 ignore
(uioh
, first, qsearch);
3721 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3723 if String.length m_narrow_pattern
= 0
3729 if not
confrimremoval
3731 let _, _, anchor = m_items
.(active) in
3732 gotoghyll (getanchory anchor);
3736 state.bookmarks
<- Array.to_list m_items
;
3737 m_orig_items
<- m_items
;
3740 else m_items
<- items;
3744 method hasaction
_ = true
3747 if Array.length m_items
!= Array.length m_orig_items
3748 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3751 method narrow
pattern =
3752 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3756 let rec loop accu n =
3759 m_narrow_pattern
<- pattern;
3760 m_items
<- Array.of_list
accu
3763 let (s, _, _) as o = m_items
.(n) in
3765 if (try ignore
(Str.search_forward
re s 0); true
3766 with Not_found
-> false)
3772 loop [] (Array.length m_items
- 1)
3777 then Array.of_list
state.bookmarks
3780 m_items
<- m_orig_items
3785 if m >= 0 && m < Array.length m_items
3787 m_hadremovals
<- true;
3788 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3789 let n = if n >= m then n+1 else n in
3794 method reset
anchor items =
3795 m_hadremovals
<- false;
3796 if m_orig_items
== empty || m_prev_items
!= items
3798 m_orig_items
<- items;
3799 if String.length m_narrow_pattern
= 0
3800 then m_items
<- items;
3802 m_prev_items
<- items;
3803 let rely = getanchory anchor in
3805 let rec loop n best bestd
=
3806 if n = Array.length m_items
3809 let (_, _, anchor) = m_items
.(n) in
3810 let orely = getanchory anchor in
3811 let d = abs
(orely - rely) in
3814 else loop (n+1) best bestd
3819 m_first
<- firstof m_first
active
3823 let enterselector usebookmarks
=
3824 let source = outlinesource usebookmarks
in
3828 then Array.of_list
state.bookmarks
3831 if Array.length
outlines = 0
3833 showtext ' ' errmsg
;
3836 state.text <- source#greetmsg
;
3837 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3838 let anchor = getanchor () in
3839 source#reset
anchor outlines;
3840 state.uioh
<- coe (new outlinelistview ~
source);
3841 G.postRedisplay "enter selector";
3845 let enteroutlinemode =
3846 let f = enterselector false in
3847 fun ()-> f "Document has no outline";
3850 let enterbookmarkmode =
3851 let f = enterselector true in
3852 fun () -> f "Document has no bookmarks (yet)";
3855 let color_of_string s =
3856 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3857 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3861 let color_to_string (r, g
, b) =
3862 let r = truncate
(r *. 256.0)
3863 and g
= truncate
(g
*. 256.0)
3864 and b = truncate
(b *. 256.0) in
3865 Printf.sprintf
"%d/%d/%d" r g
b
3868 let irect_of_string s =
3869 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3872 let irect_to_string (x0,y0,x1,y1) =
3873 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3876 let makecheckers () =
3877 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3879 converted by Issac Trotts. July 25, 2002 *)
3880 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3881 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3882 let id = GlTex.gen_texture
() in
3883 GlTex.bind_texture `texture_2d
id;
3884 GlPix.store
(`unpack_alignment
1);
3885 GlTex.image2d
image;
3886 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3889 `mag_filter `nearest
;
3890 `min_filter `nearest
];
3894 let setcheckers enabled
=
3895 match state.texid
with
3897 if enabled
then state.texid
<- Some
(makecheckers ())
3902 GlTex.delete_texture texid
;
3903 state.texid
<- None
;
3907 let int_of_string_with_suffix s =
3908 let l = String.length
s in
3912 let suffix = Char.lowercase
s.[l-1] in
3914 | 'k'
-> String.sub
s 0 (l-1), 10
3915 | '
m'
-> String.sub
s 0 (l-1), 20
3916 | 'g'
-> String.sub
s 0 (l-1), 30
3920 let n = int_of_string
s1 in
3921 let m = n lsl shift
in
3923 then raise
(Failure
"value too large")
3927 let string_with_suffix_of_int n =
3932 if n land ((1 lsl 30) - 1) = 0
3935 if n land ((1 lsl 20) - 1) = 0
3938 if n land ((1 lsl 10) - 1) = 0
3945 let h = n mod 1000 in
3948 then string_of_int
h ^
s
3950 let s = Printf.sprintf
"_%03d%s" h s in
3957 let defghyllscroll = (40, 8, 32);;
3958 let ghyllscroll_of_string s =
3959 let (n, a, b) as nab
=
3962 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3964 if n <= a || n <= b || a >= b
3965 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3969 let ghyllscroll_to_string ((n, a, b) as nab
) =
3970 if nab
= defghyllscroll
3972 else Printf.sprintf
"%d,%d,%d" n a b;
3975 let describe_location () =
3977 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3979 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3980 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3984 else (100. *. (float state.y /. float maxy))
3988 Printf.sprintf
"page %d of %d [%.2f%%]"
3989 (fn+1) state.pagecount
percent
3992 "pages %d-%d of %d [%.2f%%]"
3993 (fn+1) (ln
+1) state.pagecount
percent
3996 let setpresentationmode v
=
3997 let (n, _, _) = getanchor () in
3998 let _, h = getpageyh n in
3999 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
4000 state.anchor <- (n, 0.0, float ips);
4001 conf.presentation
<- v
;
4002 if conf.presentation
4004 if not
conf.scrollbarinpm
4005 then state.scrollw
<- 0;
4007 else state.scrollw
<- conf.scrollbw
;
4012 let btos b = if b then "\xe2\x88\x9a" else "" in
4013 let showextended = ref false in
4014 let leave mode
= function
4015 | Confirm
-> state.mode
<- mode
4016 | Cancel
-> state.mode
<- mode
in
4019 val mutable m_first_time
= true
4020 val mutable m_l
= []
4021 val mutable m_a
= [||]
4022 val mutable m_prev_uioh
= nouioh
4023 val mutable m_prev_mode
= View
4025 inherit lvsourcebase
4027 method reset prev_mode prev_uioh
=
4028 m_a
<- Array.of_list
(List.rev m_l
);
4030 m_prev_mode
<- prev_mode
;
4031 m_prev_uioh
<- prev_uioh
;
4035 if n >= Array.length m_a
4039 | _, _, _, Action
_ -> m_active
<- n
4043 m_first_time
<- false;
4046 method int name get
set =
4048 (name
, `
int get
, 1, Action
(
4051 try set (int_of_string
s)
4053 state.text <- Printf.sprintf
"bad integer `%s': %s"
4054 s (Printexc.to_string exn
)
4057 let te = name ^
": ", "", None
, intentry, ondone, true in
4058 state.mode
<- Textentry
(te, leave m_prev_mode
);
4062 method int_with_suffix name get
set =
4064 (name
, `intws get
, 1, Action
(
4067 try set (int_of_string_with_suffix s)
4069 state.text <- Printf.sprintf
"bad integer `%s': %s"
4070 s (Printexc.to_string exn
)
4074 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4076 state.mode
<- Textentry
(te, leave m_prev_mode
);
4080 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4082 (name
, `
bool (btos, get
), offset
, Action
(
4089 method color name get
set =
4091 (name
, `color get
, 1, Action
(
4093 let invalid = (nan
, nan
, nan
) in
4096 try color_of_string s
4098 state.text <- Printf.sprintf
"bad color `%s': %s"
4099 s (Printexc.to_string exn
);
4105 let te = name ^
": ", "", None
, textentry, ondone, true in
4106 state.text <- color_to_string (get
());
4107 state.mode
<- Textentry
(te, leave m_prev_mode
);
4111 method string name get
set =
4113 (name
, `
string get
, 1, Action
(
4115 let ondone s = set s in
4116 let te = name ^
": ", "", None
, textentry, ondone, true in
4117 state.mode
<- Textentry
(te, leave m_prev_mode
);
4121 method colorspace name get
set =
4123 (name
, `
string get
, 1, Action
(
4126 let vals = [| "rgb"; "bgr"; "gray" |] in
4128 inherit lvsourcebase
4131 m_active
<- int_of_colorspace conf.colorspace
;
4134 method getitemcount
= Array.length
vals
4135 method getitem
n = (vals.(n), 0)
4136 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4137 ignore
(uioh
, first, pan
, qsearch);
4138 if not cancel
then set active;
4140 method hasaction
_ = true
4144 let modehash = findkeyhash conf "info" in
4145 coe (new listview ~
source ~trusted
:true ~
modehash)
4148 method caption
s offset
=
4149 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4151 method caption2
s f offset
=
4152 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4154 method getitemcount
= Array.length m_a
4157 let tostr = function
4158 | `
int f -> string_of_int
(f ())
4159 | `intws
f -> string_with_suffix_of_int (f ())
4161 | `color
f -> color_to_string (f ())
4162 | `
bool (btos, f) -> btos (f ())
4165 let name, t
, offset
, _ = m_a
.(n) in
4166 ((let s = tostr t
in
4167 if String.length
s > 0
4168 then Printf.sprintf
"%s\t%s" name s
4172 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4176 m_qsearch
<- qsearch;
4178 match m_a
.(active) with
4179 | _, _, _, Action
f -> f uioh
4191 method hasaction
n =
4193 | _, _, _, Action
_ -> true
4197 let rec fillsrc prevmode prevuioh
=
4198 let sep () = src#caption
"" 0 in
4199 let colorp name get
set =
4201 (fun () -> color_to_string (get
()))
4204 let c = color_of_string v in
4207 state.text <- Printf.sprintf
"bad color `%s': %s"
4208 v (Printexc.to_string exn
);
4211 let oldmode = state.mode
in
4212 let birdseye = isbirdseye state.mode
in
4214 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4216 src#
bool "presentation mode"
4217 (fun () -> conf.presentation
)
4218 (fun v -> setpresentationmode v);
4220 src#
bool "ignore case in searches"
4221 (fun () -> conf.icase
)
4222 (fun v -> conf.icase
<- v);
4225 (fun () -> conf.preload)
4226 (fun v -> conf.preload <- v);
4228 src#
bool "highlight links"
4229 (fun () -> conf.hlinks
)
4230 (fun v -> conf.hlinks
<- v);
4232 src#
bool "under info"
4233 (fun () -> conf.underinfo
)
4234 (fun v -> conf.underinfo
<- v);
4236 src#
bool "persistent bookmarks"
4237 (fun () -> conf.savebmarks
)
4238 (fun v -> conf.savebmarks
<- v);
4240 src#
bool "proportional display"
4241 (fun () -> conf.proportional
)
4242 (fun v -> reqlayout conf.angle
v);
4244 src#
bool "trim margins"
4245 (fun () -> conf.trimmargins
)
4246 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4248 src#
bool "persistent location"
4249 (fun () -> conf.jumpback
)
4250 (fun v -> conf.jumpback
<- v);
4253 src#
int "inter-page space"
4254 (fun () -> conf.interpagespace
)
4256 conf.interpagespace
<- n;
4257 docolumns conf.columns
;
4259 match state.layout with
4264 state.maxy <- calcheight ();
4265 let y = getpagey pageno in
4270 (fun () -> conf.pagebias
)
4271 (fun v -> conf.pagebias
<- v);
4273 src#
int "scroll step"
4274 (fun () -> conf.scrollstep
)
4275 (fun n -> conf.scrollstep
<- n);
4277 src#
int "horizontal scroll step"
4278 (fun () -> conf.hscrollstep
)
4279 (fun v -> conf.hscrollstep
<- v);
4281 src#
int "auto scroll step"
4283 match state.autoscroll
with
4285 | _ -> conf.autoscrollstep
)
4287 if state.autoscroll
<> None
4288 then state.autoscroll
<- Some
n;
4289 conf.autoscrollstep
<- n);
4292 (fun () -> truncate
(conf.zoom *. 100.))
4293 (fun v -> setzoom ((float v) /. 100.));
4296 (fun () -> conf.angle
)
4297 (fun v -> reqlayout v conf.proportional
);
4299 src#
int "scroll bar width"
4300 (fun () -> state.scrollw
)
4304 reshape conf.winw
conf.winh
;
4307 src#
int "scroll handle height"
4308 (fun () -> conf.scrollh
)
4309 (fun v -> conf.scrollh
<- v;);
4311 src#
int "thumbnail width"
4312 (fun () -> conf.thumbw
)
4314 conf.thumbw
<- min
4096 v;
4317 leavebirdseye beye
false;
4322 let mode = state.mode in
4323 src#
string "columns"
4325 match conf.columns
with
4327 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4328 | Csplit
(count
, _) -> "-" ^ string_of_int count
4331 let n, a, b = multicolumns_of_string v in
4332 setcolumns mode n a b);
4335 src#caption
"Presentation mode" 0;
4336 src#
bool "scrollbar visible"
4337 (fun () -> conf.scrollbarinpm
)
4339 if v != conf.scrollbarinpm
4341 conf.scrollbarinpm
<- v;
4342 if conf.presentation
4344 state.scrollw
<- if v then conf.scrollbw
else 0;
4345 reshape conf.winw
conf.winh
;
4351 src#caption
"Pixmap cache" 0;
4352 src#int_with_suffix
"size (advisory)"
4353 (fun () -> conf.memlimit
)
4354 (fun v -> conf.memlimit
<- v);
4357 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4358 (string_with_suffix_of_int state.memused
)
4359 (Hashtbl.length
state.tilemap
)) 1;
4362 src#caption
"Layout" 0;
4363 src#caption2
"Dimension"
4365 Printf.sprintf
"%dx%d (virtual %dx%d)"
4371 src#caption2
"Position" (fun () ->
4372 Printf.sprintf
"%dx%d" state.x state.y
4375 src#caption2
"Visible" (fun () -> describe_location ()) 1
4379 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4380 "Save these parameters as global defaults at exit"
4381 (fun () -> conf.bedefault
)
4382 (fun v -> conf.bedefault
<- v)
4386 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4387 src#
bool ~offset
:0 ~
btos "Extended parameters"
4388 (fun () -> !showextended)
4389 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4393 (fun () -> conf.checkers
)
4394 (fun v -> conf.checkers
<- v; setcheckers v);
4395 src#
bool "update cursor"
4396 (fun () -> conf.updatecurs
)
4397 (fun v -> conf.updatecurs
<- v);
4399 (fun () -> conf.verbose
)
4400 (fun v -> conf.verbose
<- v);
4401 src#
bool "invert colors"
4402 (fun () -> conf.invert
)
4403 (fun v -> conf.invert
<- v);
4405 (fun () -> conf.maxhfit
)
4406 (fun v -> conf.maxhfit
<- v);
4407 src#
bool "redirect stderr"
4408 (fun () -> conf.redirectstderr)
4409 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4410 src#
string "uri launcher"
4411 (fun () -> conf.urilauncher
)
4412 (fun v -> conf.urilauncher
<- v);
4413 src#
string "path launcher"
4414 (fun () -> conf.pathlauncher
)
4415 (fun v -> conf.pathlauncher
<- v);
4416 src#
string "tile size"
4417 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4420 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4421 conf.tilew
<- max
64 w;
4422 conf.tileh
<- max
64 h;
4425 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4426 v (Printexc.to_string exn
));
4427 src#
int "texture count"
4428 (fun () -> conf.texcount
)
4431 then conf.texcount
<- v
4432 else showtext '
!'
" Failed to set texture count please retry later"
4434 src#
int "slice height"
4435 (fun () -> conf.sliceheight
)
4437 conf.sliceheight
<- v;
4438 wcmd "sliceh %d" conf.sliceheight
;
4440 src#
int "anti-aliasing level"
4441 (fun () -> conf.aalevel
)
4443 conf.aalevel
<- bound v 0 8;
4444 state.anchor <- getanchor ();
4445 opendoc state.path
state.password
state.nameddest
;
4447 src#
string "page scroll scaling factor"
4448 (fun () -> string_of_float
conf.pgscale)
4451 let s = float_of_string
v in
4454 state.text <- Printf.sprintf
4455 "bad page scroll scaling factor `%s': %s"
4456 v (Printexc.to_string exn
)
4459 src#
int "ui font size"
4460 (fun () -> fstate.fontsize
)
4461 (fun v -> setfontsize (bound v 5 100));
4462 src#
int "hint font size"
4463 (fun () -> conf.hfsize
)
4464 (fun v -> conf.hfsize
<- bound v 5 100);
4465 colorp "background color"
4466 (fun () -> conf.bgcolor
)
4467 (fun v -> conf.bgcolor
<- v);
4468 src#
bool "crop hack"
4469 (fun () -> conf.crophack
)
4470 (fun v -> conf.crophack
<- v);
4471 src#
string "trim fuzz"
4472 (fun () -> irect_to_string conf.trimfuzz
)
4475 conf.trimfuzz
<- irect_of_string v;
4477 then settrim true conf.trimfuzz
;
4479 state.text <- Printf.sprintf
"bad irect `%s': %s"
4480 v (Printexc.to_string exn
)
4482 src#
string "throttle"
4484 match conf.maxwait
with
4485 | None
-> "show place holder if page is not ready"
4488 then "wait for page to fully render"
4490 "wait " ^ string_of_float
time
4491 ^
" seconds before showing placeholder"
4495 let f = float_of_string
v in
4497 then conf.maxwait
<- None
4498 else conf.maxwait
<- Some
f
4500 state.text <- Printf.sprintf
"bad time `%s': %s"
4501 v (Printexc.to_string exn
)
4503 src#
string "ghyll scroll"
4505 match conf.ghyllscroll
with
4507 | Some nab
-> ghyllscroll_to_string nab
4512 if String.length
v = 0
4514 else Some
(ghyllscroll_of_string v)
4516 conf.ghyllscroll
<- gs
4518 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4519 v (Printexc.to_string exn
)
4521 src#
string "selection command"
4522 (fun () -> conf.selcmd
)
4523 (fun v -> conf.selcmd
<- v);
4524 src#colorspace
"color space"
4525 (fun () -> colorspace_to_string conf.colorspace
)
4527 conf.colorspace
<- colorspace_of_int v;
4534 (fun () -> conf.usepbo
)
4535 (fun v -> conf.usepbo
<- v);
4536 src#
bool "mouse wheel scrolls pages"
4537 (fun () -> conf.wheelbypage
)
4538 (fun v -> conf.wheelbypage
<- v);
4542 src#caption
"Document" 0;
4543 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4544 src#caption2
"Pages"
4545 (fun () -> string_of_int
state.pagecount
) 1;
4546 src#caption2
"Dimensions"
4547 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4551 src#caption
"Trimmed margins" 0;
4552 src#caption2
"Dimensions"
4553 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4557 src#caption
"OpenGL" 0;
4558 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4559 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4560 src#reset prevmode prevuioh
;
4564 let prevmode = state.mode
4565 and prevuioh
= state.uioh in
4566 fillsrc prevmode prevuioh
;
4567 let source = (src :> lvsource
) in
4568 let modehash = findkeyhash conf "info" in
4569 state.uioh <- coe (object (self)
4570 inherit listview ~
source ~trusted
:true ~
modehash as super
4571 val mutable m_prevmemused
= 0
4572 method infochanged
= function
4574 if m_prevmemused
!= state.memused
4576 m_prevmemused
<- state.memused
;
4577 G.postRedisplay "memusedchanged";
4579 | Pdim
-> G.postRedisplay "pdimchanged"
4580 | Docinfo
-> fillsrc prevmode prevuioh
4582 method key key mask
=
4583 if not
(Wsi.withctrl mask
)
4586 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4587 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4588 | _ -> super#
key key mask
4589 else super#
key key mask
4591 G.postRedisplay "info";
4597 inherit lvsourcebase
4598 method getitemcount
= Array.length
state.help
4600 let s, l, _ = state.help
.(n) in
4603 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4607 m_qsearch
<- qsearch;
4608 match state.help
.(active) with
4609 | _, _, Action
f -> Some
(f uioh)
4619 method hasaction
n =
4620 match state.help
.(n) with
4621 | _, _, Action
_ -> true
4628 let modehash = findkeyhash conf "help" in
4629 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4630 G.postRedisplay "help";
4635 let re = Str.regexp
"[\r\n]" in
4637 inherit lvsourcebase
4638 val mutable m_items
= [||]
4640 method getitemcount
= 1 + Array.length m_items
4645 else m_items
.(n-1), 0
4647 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4652 then Buffer.clear
state.errmsgs
;
4653 m_qsearch
<- qsearch;
4660 method hasaction
n =
4664 state.newerrmsgs
<- false;
4665 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4666 m_items
<- Array.of_list
l
4674 let source = (msgsource :> lvsource
) in
4675 let modehash = findkeyhash conf "listview" in
4676 state.uioh <- coe (object
4677 inherit listview ~
source ~trusted
:false ~
modehash as super
4680 then msgsource#reset
;
4683 G.postRedisplay "msgs";
4686 let quickbookmark ?title
() =
4687 match state.layout with
4693 let sec = Unix.gettimeofday
() in
4694 let tm = Unix.localtime
sec in
4695 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4699 (tm.Unix.tm_year
+ 1900)
4702 | Some
title -> title
4704 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4708 state.fullscreen
<- None
;
4712 let setautoscrollspeed step goingdown
=
4713 let incr = max
1 ((abs step
) / 2) in
4714 let incr = if goingdown
then incr else -incr in
4715 let astep = step
+ incr in
4716 state.autoscroll
<- Some
astep;
4719 let gotounder = function
4720 | Ulinkgoto
(pageno, top) ->
4724 gotopage1 pageno top;
4730 | Uremote
(filename
, pageno) ->
4732 if Sys.file_exists filename
4735 let dir = Filename.dirname
state.path in
4736 let path = Filename.concat
dir filename
in
4737 if Sys.file_exists
path
4741 if String.length
path > 0
4743 let anchor = getanchor () in
4744 let ranchor = state.path, state.password
, anchor in
4745 state.anchor <- (pageno, 0.0, 0.0);
4746 state.ranchors
<- ranchor :: state.ranchors
;
4749 else showtext '
!'
("Could not find " ^ filename
)
4751 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4755 match conf.columns
with
4757 | _ -> conf.zoom > 1.0
4760 let existsinrow pageno (columns
, coverA
, coverB
) p =
4761 let last = ((pageno - coverA
) mod columns
) + columns
in
4762 let rec any = function
4765 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4769 then (if l.pageno = last then false else any rest
)
4777 match state.layout with
4780 match conf.columns
with
4782 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4784 let y = clamp (pgscale conf.winh
) in
4787 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4788 gotoghyll (getpagey pageno)
4789 | Cmulti
((c, _, _) as cl
, _) ->
4790 if conf.presentation
4791 && (existsinrow l.pageno cl
4792 (fun l -> l.pageh
> l.pagey + l.pagevh))
4794 let y = clamp (pgscale conf.winh
) in
4797 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4798 gotoghyll (getpagey pageno)
4800 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4802 let pagey, pageh
= getpageyh l.pageno in
4803 let pagey = pagey + pageh
* l.pagecol
in
4804 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4805 gotoghyll (pagey + pageh
+ ips)
4809 match state.layout with
4812 match conf.columns
with
4814 if conf.presentation
&& l.pagey != 0
4816 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4818 let pageno = max
0 (l.pageno-1) in
4819 gotoghyll (getpagey pageno)
4820 | Cmulti
((c, _, coverB
) as cl
, _) ->
4821 if conf.presentation
&&
4822 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4824 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4827 if l.pageno = state.pagecount
- coverB
4831 let pageno = max
0 (l.pageno-decr) in
4832 gotoghyll (getpagey pageno)
4840 let pageno = max
0 (l.pageno-1) in
4841 let pagey, pageh
= getpageyh pageno in
4844 let pagey, pageh
= getpageyh l.pageno in
4845 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4850 let viewkeyboard key mask
=
4852 let mode = state.mode in
4853 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4856 G.postRedisplay "view:enttext"
4858 let ctrl = Wsi.withctrl mask
in
4860 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4866 | 0xff63 -> (* insert *)
4867 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4869 state.mode <- LinkNav
(Ltgendir
0);
4872 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4874 | 0xff1b | 113 -> (* escape / q *)
4875 begin match state.mstate
with
4877 state.mstate
<- Mnone
;
4878 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4879 G.postRedisplay "kill zoom rect";
4881 begin match state.mode with
4884 G.postRedisplay "esc leave linknav"
4886 match state.ranchors
with
4888 | (path, password
, anchor) :: rest
->
4889 state.ranchors
<- rest
;
4890 state.anchor <- anchor;
4891 opendoc path password
""
4895 | 0xff08 -> (* backspace *)
4896 gotoghyll (getnav ~
-1)
4904 G.postRedisplay "dehighlight";
4906 | 47 | 63 -> (* / ? *)
4907 let ondone isforw
s =
4908 cbput state.hists
.pat
s;
4909 state.searchpattern
<- s;
4912 let s = String.create
1 in
4913 s.[0] <- Char.chr
key;
4914 enttext (s, "", Some
(onhist state.hists
.pat
),
4915 textentry, ondone (key = 47), true)
4917 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4918 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4919 setzoom (conf.zoom +. incr)
4921 | 43 | 0xffab -> (* + *)
4924 try int_of_string
s with exc
->
4925 state.text <- Printf.sprintf
"bad integer `%s': %s"
4926 s (Printexc.to_string exc
);
4932 state.text <- "page bias is now " ^ string_of_int
n;
4935 enttext ("page bias: ", "", None
, intentry, ondone, true)
4937 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4938 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4939 setzoom (max
0.01 (conf.zoom -. decr))
4941 | 45 | 0xffad -> (* - *)
4942 let ondone msg
= state.text <- msg
in
4944 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4945 optentry state.mode, ondone, true
4948 | 48 when ctrl -> (* ctrl-0 *)
4951 | 49 when ctrl -> (* ctrl-1 *)
4953 match conf.columns
with
4954 | Csingle
_ | Cmulti
_ -> 1
4955 | Csplit
(n, _) -> n
4957 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4961 | 0xffc6 -> (* f9 *)
4964 | 57 when ctrl -> (* ctrl-9 *)
4967 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4968 when not
ctrl -> (* 0..9 *)
4971 try int_of_string
s with exc
->
4972 state.text <- Printf.sprintf
"bad integer `%s': %s"
4973 s (Printexc.to_string exc
);
4979 cbput state.hists
.pag
(string_of_int
n);
4980 gotopage1 (n + conf.pagebias
- 1) 0;
4983 let pageentry text key =
4984 match Char.unsafe_chr
key with
4985 | 'g'
-> TEdone
text
4986 | _ -> intentry text key
4988 let text = "x" in text.[0] <- Char.chr
key;
4989 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4992 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4993 reshape conf.winw
conf.winh
;
4996 conf.hlinks
<- not
conf.hlinks
;
4997 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4998 G.postRedisplay "toggle highlightlinks";
5001 state.glinks
<- true;
5002 let mode = state.mode in
5003 state.mode <- Textentry
(
5004 (":", "", None
, linknentry, linkndone gotounder, false),
5006 state.glinks
<- false;
5010 G.postRedisplay "view:linkent(F)"
5013 state.glinks
<- true;
5014 let mode = state.mode in
5015 state.mode <- Textentry
(
5016 (":", "", None
, linknentry, linkndone (fun under ->
5017 match Ne.pipe () with
5019 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
5020 (Printexc.to_string exn
));
5023 try popen conf.selcmd
[r, 0; w, -1]; true
5026 (Printf.sprintf
"failed to execute %s: %s"
5027 conf.selcmd
(Printexc.to_string exn
));
5031 Ne.clo fd
(fun msg
->
5032 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5035 let s = undertext under in
5039 let l = String.length
s in
5040 let n = tempfailureretry (Unix.write
w s 0) l in
5045 "failed to write %d characters to sel pipe, wrote %d"
5050 (Printf.sprintf
"failed to write to sel pipe: %s"
5051 (Printexc.to_string exn
)
5060 state.glinks
<- false;
5064 G.postRedisplay "view:linkent"
5067 begin match state.autoscroll
with
5069 conf.autoscrollstep
<- step
;
5070 state.autoscroll
<- None
5072 if conf.autoscrollstep
= 0
5073 then state.autoscroll
<- Some
1
5074 else state.autoscroll
<- Some
conf.autoscrollstep
5077 | 112 when ctrl -> (* ctrl-p *)
5081 setpresentationmode (not
conf.presentation
);
5082 showtext ' '
("presentation mode " ^
5083 if conf.presentation
then "on" else "off");
5086 begin match state.fullscreen
with
5088 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
5091 state.fullscreen
<- None
;
5095 | 112 | 78 -> (* p|N *)
5096 search state.searchpattern
false
5098 | 110 | 0xffc0 -> (* n|F3 *)
5099 search state.searchpattern
true
5102 begin match state.layout with
5105 gotoy_and_clear_text (getpagey l.pageno)
5111 | 0xff9f | 0xffff -> (* delete *)
5115 showtext ' '
(describe_location ());
5118 begin match state.layout with
5121 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5126 enterbookmarkmode ()
5128 | 104 | 0xffbe -> (* h|F1 *)
5134 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5139 match state.layout with
5141 if String.length
s > 0
5143 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5146 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5150 showtext ' '
"Quick bookmark added";
5153 begin match state.layout with
5155 let rect = getpdimrect
l.pagedimno
in
5159 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5160 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5162 (truncate
(rect.(1) -. rect.(0)),
5163 truncate
(rect.(3) -. rect.(0)))
5165 let w = truncate
((float w)*.conf.zoom)
5166 and h = truncate
((float h)*.conf.zoom) in
5169 state.anchor <- getanchor ();
5170 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5172 G.postRedisplay "z";
5177 | 50 when ctrl -> (* ctrl-2 *)
5178 let maxw = getmaxw
() in
5180 then setzoom (maxw /. float conf.winw
)
5182 | 60 | 62 -> (* < > *)
5183 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5185 | 91 | 93 -> (* [ ] *)
5187 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5189 G.postRedisplay "brightness";
5191 | 99 when state.mode = View
-> (* c *)
5193 match state.prevcolumns
with
5194 | None
-> (1, 0, 0), 1.0
5195 | Some
(columns
, z
) ->
5198 | Csplit
(c, _) -> -c, 0, 0
5199 | Cmulti
((c, a, b), _) -> c, a, b
5200 | Csingle
_ -> 1, 0, 0
5204 setcolumns View
c a b;
5207 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5208 setzoom state.prevzoom
5210 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5211 begin match state.autoscroll
with
5213 begin match state.mode with
5214 | Birdseye beye
-> upbirdseye 1 beye
5217 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5218 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5221 setautoscrollspeed n false
5224 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5225 begin match state.autoscroll
with
5227 begin match state.mode with
5228 | Birdseye beye
-> downbirdseye 1 beye
5231 then gotoy_and_clear_text (clamp (conf.winh
/2))
5232 else gotoy_and_clear_text (clamp conf.scrollstep
)
5235 setautoscrollspeed n true
5238 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5244 else conf.hscrollstep
5246 let dx = if key = 0xff51 then dx else -dx in
5247 state.x <- state.x + dx;
5248 gotoy_and_clear_text state.y
5251 G.postRedisplay "lef/right"
5254 | 0xff55 | 0xff9a -> (* (kp) prior *)
5258 match state.layout with
5260 | l :: _ -> state.y - l.pagey
5262 clamp (pgscale (-conf.winh
))
5266 | 0xff56 | 0xff9b -> (* (kp) next *)
5270 match List.rev
state.layout with
5272 | l :: _ -> getpagey l.pageno
5274 clamp (pgscale conf.winh
)
5278 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5280 | 71 | 0xff57 | 0xff9c -> (* G end *)
5281 gotoghyll (clamp state.maxy)
5283 | 0xff53 when Wsi.withalt mask
-> (* alt-right *)
5284 gotoghyll (getnav 1)
5285 | 0xff51 when Wsi.withalt mask
-> (* alt-left *)
5286 gotoghyll (getnav ~
-1)
5291 | 118 when conf.debug
-> (* v *)
5294 match getopaque l.pageno with
5297 let x0, y0, x1, y1 = pagebbox opaque
in
5298 let a,b = float x0, float y0 in
5299 let c,d = float x1, float y0 in
5300 let e,f = float x1, float y1 in
5301 let h,j
= float x0, float y1 in
5302 let rect = (a,b,c,d,e,f,h,j
) in
5304 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5306 G.postRedisplay "v";
5309 vlog "huh? %s" (Wsi.keyname
key)
5312 let linknavkeyboard key mask
linknav =
5313 let getpage pageno =
5314 let rec loop = function
5316 | l :: _ when l.pageno = pageno -> Some
l
5317 | _ :: rest
-> loop rest
5318 in loop state.layout
5320 let doexact (pageno, n) =
5321 match getopaque pageno, getpage pageno with
5322 | Some opaque
, Some
l ->
5323 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5325 let under = getlink opaque
n in
5326 G.postRedisplay "link gotounder";
5332 | 0xff50 -> (* home *)
5333 Some
(findlink opaque LDfirst
), -1
5335 | 0xff57 -> (* end *)
5336 Some
(findlink opaque LDlast
), 1
5338 | 0xff51 -> (* left *)
5339 Some
(findlink opaque
(LDleft
n)), -1
5341 | 0xff53 -> (* right *)
5342 Some
(findlink opaque
(LDright
n)), 1
5344 | 0xff52 -> (* up *)
5345 Some
(findlink opaque
(LDup
n)), -1
5347 | 0xff54 -> (* down *)
5348 Some
(findlink opaque
(LDdown
n)), 1
5353 begin match findpwl
l.pageno dir with
5357 state.mode <- LinkNav
(Ltgendir
dir);
5358 let y, h = getpageyh pageno in
5361 then y + h - conf.winh
5366 begin match getopaque pageno, getpage pageno with
5367 | Some opaque
, Some
_ ->
5369 let ld = if dir > 0 then LDfirst
else LDlast
in
5372 begin match link with
5374 showlinktype (getlink opaque
m);
5375 state.mode <- LinkNav
(Ltexact
(pageno, m));
5376 G.postRedisplay "linknav jpage";
5383 begin match opt with
5384 | Some Lnotfound
-> pwl l dir;
5385 | Some
(Lfound
m) ->
5389 let _, y0, _, y1 = getlinkrect opaque
m in
5391 then gotopage1 l.pageno y0
5393 let d = fstate.fontsize
+ 1 in
5394 if y1 - l.pagey > l.pagevh - d
5395 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5396 else G.postRedisplay "linknav";
5398 showlinktype (getlink opaque
m);
5399 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5402 | None
-> viewkeyboard key mask
5404 | _ -> viewkeyboard key mask
5409 G.postRedisplay "leave linknav"
5413 | Ltgendir
_ -> viewkeyboard key mask
5414 | Ltexact exact
-> doexact exact
5417 let keyboard key mask
=
5418 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5419 then wcmd "interrupt"
5420 else state.uioh <- state.uioh#
key key mask
5423 let birdseyekeyboard key mask
5424 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5426 match conf.columns
with
5428 | Cmulti
((c, _, _), _) -> c
5429 | Csplit
_ -> failwith
"bird's eye split mode"
5431 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5433 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5434 let y, h = getpageyh pageno in
5435 let top = (conf.winh
- h) / 2 in
5436 gotoy (max
0 (y - top))
5437 | 0xff0d (* enter *)
5438 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5439 | 0xff1b -> leavebirdseye beye
true (* escape *)
5440 | 0xff52 -> upbirdseye incr beye
(* up *)
5441 | 0xff54 -> downbirdseye incr beye
(* down *)
5442 | 0xff51 -> upbirdseye 1 beye
(* left *)
5443 | 0xff53 -> downbirdseye 1 beye
(* right *)
5445 | 0xff55 -> (* prior *)
5446 begin match state.layout with
5450 state.mode <- Birdseye
(
5451 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5453 gotopage1 l.pageno 0;
5456 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5458 | [] -> gotoy (clamp (-conf.winh
))
5460 state.mode <- Birdseye
(
5461 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5463 gotopage1 l.pageno 0
5466 | [] -> gotoy (clamp (-conf.winh
))
5469 | 0xff56 -> (* next *)
5470 begin match List.rev
state.layout with
5472 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5473 begin match layout with
5475 let incr = l.pageh
- l.pagevh in
5480 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5482 G.postRedisplay "birdseye pagedown";
5484 else gotoy (clamp (incr + conf.interpagespace
*2));
5488 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5489 gotopage1 l.pageno 0;
5492 | [] -> gotoy (clamp conf.winh
)
5495 | 0xff50 -> (* home *)
5496 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5499 | 0xff57 -> (* end *)
5500 let pageno = state.pagecount
- 1 in
5501 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5502 if not
(pagevisible state.layout pageno)
5505 match List.rev
state.pdims
with
5507 | (_, _, h, _) :: _ -> h
5509 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5510 else G.postRedisplay "birdseye end";
5511 | _ -> viewkeyboard key mask
5514 let drawpage l linkindexbase
=
5516 match state.mode with
5517 | Textentry
_ -> scalecolor 0.4
5519 | View
-> scalecolor 1.0
5520 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5521 if l.pageno = hooverpageno
5524 if l.pageno = pageno
5530 begin match getopaque l.pageno with
5532 if tileready l l.pagex
l.pagey
5534 let x = l.pagedispx - l.pagex
5535 and y = l.pagedispy - l.pagey in
5537 match conf.columns
with
5538 | Csingle
_ | Cmulti
_ ->
5539 (if conf.hlinks
then 1 else 0)
5541 && not
(isbirdseye state.mode) then 2 else 0)
5545 match state.mode with
5546 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5549 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5556 let scrollindicator () =
5557 let sbw, ph
, sh = state.uioh#
scrollph in
5558 let sbh, pw, sw = state.uioh#scrollpw
in
5560 GlDraw.color (0.64, 0.64, 0.64);
5562 (float (conf.winw
- sbw), 0.)
5563 (float conf.winw
, float conf.winh
)
5566 (0., float (conf.winh
- sbh))
5567 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5569 GlDraw.color (0.0, 0.0, 0.0);
5572 (float (conf.winw
- sbw), ph
)
5573 (float conf.winw
, ph
+. sh)
5576 (pw, float (conf.winh
- sbh))
5577 (pw +. sw, float conf.winh
)
5582 match state.mstate
with
5583 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5586 | Msel
((x0, y0), (x1, y1)) ->
5587 let rec loop = function
5589 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5590 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5591 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5592 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5594 match getopaque l.pageno with
5596 let x0, y0 = pagetranslatepoint l x0 y0 in
5597 let x1, y1 = pagetranslatepoint l x1 y1 in
5598 seltext opaque
(x0, y0, x1, y1);
5606 let showrects rects
=
5608 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5609 GlDraw.polygon_mode `both `fill
;
5610 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5612 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5614 if l.pageno = pageno
5616 let dx = float (l.pagedispx - l.pagex
) in
5617 let dy = float (l.pagedispy - l.pagey) in
5618 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5619 GlDraw.begins `quads
;
5621 GlDraw.vertex2
(x0+.dx, y0+.dy);
5622 GlDraw.vertex2
(x1+.dx, y1+.dy);
5623 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5624 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5635 GlClear.color (scalecolor2 conf.bgcolor
);
5636 GlClear.clear
[`
color];
5637 let rec loop linkindexbase
= function
5639 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5640 loop linkindexbase rest
5643 loop 0 state.layout;
5645 match state.mode with
5646 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5647 begin match getopaque pageno with
5649 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5656 | None
-> state.rects
5663 begin match state.mstate
with
5664 | Mzoomrect
((x0, y0), (x1, y1)) ->
5666 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5667 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5668 GlDraw.rect (float x0, float y0)
5669 (float x1, float y1);
5675 if not
state.wthack
then Wsi.swapb
();
5678 let zoomrect x y x1 y1 =
5681 and y0 = min
y y1 in
5682 gotoy (state.y + y0);
5683 state.anchor <- getanchor ();
5684 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5686 if state.w < conf.winw
- state.scrollw
5687 then (conf.winw
- state.scrollw
- state.w) / 2
5690 state.x <- (state.x + margin) - x0;
5692 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5693 state.mstate
<- Mnone
;
5697 let winw = conf.winw - state.scrollw
- 1 in
5698 let s = float x /. float winw in
5699 let destx = truncate
(float (state.w + winw) *. s) in
5700 state.x <- winw - destx;
5701 gotoy_and_clear_text state.y;
5702 state.mstate
<- Mscrollx
;
5706 let s = float y /. float conf.winh
in
5707 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5708 gotoy_and_clear_text desty;
5709 state.mstate
<- Mscrolly
;
5712 let viewmouse button down
x y mask
=
5714 | n when (n == 4 || n == 5) && not down
->
5715 if Wsi.withctrl mask
5717 match state.mstate
with
5718 | Mzoom
(oldn
, i
) ->
5726 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5728 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5730 let zoom = conf.zoom -. incr in
5732 state.mstate
<- Mzoom
(n, 0);
5734 state.mstate
<- Mzoom
(n, i
+1);
5736 else state.mstate
<- Mzoom
(n, 0)
5738 | _ -> state.mstate
<- Mzoom
(n, 0)
5741 match state.autoscroll
with
5742 | Some step
-> setautoscrollspeed step
(n=4)
5753 then -conf.scrollstep
5754 else conf.scrollstep
5756 let incr = incr * 2 in
5757 let y = clamp incr in
5758 gotoy_and_clear_text y
5761 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5762 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5763 gotoy_and_clear_text state.y
5765 | 1 when Wsi.withctrl mask
->
5768 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5769 state.mstate
<- Mpan
(x, y)
5772 state.mstate
<- Mnone
5777 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5779 state.mstate
<- Mzoomrect
(p, p)
5782 match state.mstate
with
5783 | Mzoomrect
((x0, y0), _) ->
5784 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5785 then zoomrect x0 y0 x y
5787 state.mstate
<- Mnone
;
5788 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5789 G.postRedisplay "kill accidental zoom rect";
5792 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5793 state.mstate
<- Mnone
5796 | 1 when x > conf.winw - state.scrollw
->
5799 let _, position, sh = state.uioh#
scrollph in
5800 if y > truncate
position && y < truncate
(position +. sh)
5801 then state.mstate
<- Mscrolly
5804 state.mstate
<- Mnone
5806 | 1 when y > conf.winh
- state.hscrollh ->
5809 let _, position, sw = state.uioh#scrollpw
in
5810 if x > truncate
position && x < truncate
(position +. sw)
5811 then state.mstate
<- Mscrollx
5814 state.mstate
<- Mnone
5817 let dest = if down
then getunder x y else Unone
in
5818 begin match dest with
5822 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5825 | Unone
when down
->
5826 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5827 state.mstate
<- Mpan
(x, y);
5829 | Unone
| Utext
_ ->
5832 if conf.angle
mod 360 = 0
5834 state.mstate
<- Msel
((x, y), (x, y));
5835 G.postRedisplay "mouse select";
5839 match state.mstate
with
5842 | Mzoom
_ | Mscrollx
| Mscrolly
->
5843 state.mstate
<- Mnone
5845 | Mzoomrect
((x0, y0), _) ->
5849 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5850 state.mstate
<- Mnone
5852 | Msel
((x0, y0), (x1, y1)) ->
5853 let rec loop = function
5857 let a0 = l.pagedispy in
5858 let a1 = a0 + l.pagevh in
5859 let b0 = l.pagedispx in
5860 let b1 = b0 + l.pagevw in
5861 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5862 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5866 match getopaque l.pageno with
5869 match Ne.pipe () with
5873 "can not create sel pipe: %s"
5874 (Printexc.to_string exn
));
5876 let doclose what fd
=
5877 Ne.clo fd
(fun msg
->
5878 dolog "%s close failed: %s" what msg
)
5881 popen conf.selcmd
[r, 0; w, -1];
5884 G.postRedisplay "copysel";
5886 dolog "can not execute %S: %s"
5887 conf.selcmd
(Printexc.to_string exn
);
5895 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5896 state.mstate
<- Mnone
;
5903 let birdseyemouse button down
x y mask
5904 (conf, leftx
, _, hooverpageno
, anchor) =
5907 let rec loop = function
5910 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5911 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5913 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5919 | _ -> viewmouse button down
x y mask
5922 let mouse button down
x y mask
=
5923 state.uioh <- state.uioh#button button down
x y mask
;
5927 state.uioh <- state.uioh#
motion x y
5931 state.uioh <- state.uioh#
pmotion x y;
5937 method key key mask
=
5938 begin match state.mode with
5939 | Textentry
textentry -> textentrykeyboard key mask
textentry
5940 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5941 | View
-> viewkeyboard key mask
5942 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5946 method button button bstate
x y mask
=
5947 begin match state.mode with
5949 | View
-> viewmouse button bstate
x y mask
5950 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5956 begin match state.mode with
5958 | View
| Birdseye
_ | LinkNav
_ ->
5959 match state.mstate
with
5960 | Mzoom
_ | Mnone
-> ()
5965 state.mstate
<- Mpan
(x, y);
5967 then state.x <- state.x + dx;
5969 gotoy_and_clear_text y
5972 state.mstate
<- Msel
(a, (x, y));
5973 G.postRedisplay "motion select";
5976 let y = min
conf.winh
(max
0 y) in
5980 let x = min
conf.winw (max
0 x) in
5983 | Mzoomrect
(p0
, _) ->
5984 state.mstate
<- Mzoomrect
(p0
, (x, y));
5985 G.postRedisplay "motion zoomrect";
5989 method pmotion x y =
5990 begin match state.mode with
5991 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5992 let rec loop = function
5994 if hooverpageno
!= -1
5996 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5997 G.postRedisplay "pmotion birdseye no hoover";
6000 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6001 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6003 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6004 G.postRedisplay "pmotion birdseye hoover";
6014 match state.mstate
with
6015 | Mnone
-> updateunder x y
6016 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6021 method infochanged
_ = ()
6024 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
6025 let p, h = scrollph state.y maxy in
6029 let winw = conf.winw - state.scrollw
- 1 in
6030 let fwinw = float winw in
6032 let sw = fwinw /. float state.w in
6033 let sw = fwinw *. sw in
6034 max
sw (float conf.scrollh
)
6037 let f = state.w+winw in
6038 let r = float (winw-state.x) /. float f in
6039 let p = fwinw *. r in
6043 if position +. sw > fwinw
6044 then fwinw -. position
6047 state.hscrollh, position, sw
6051 match state.mode with
6052 | LinkNav
_ -> "links"
6053 | Textentry
_ -> "textentry"
6054 | Birdseye
_ -> "birdseye"
6057 findkeyhash conf modename
6064 let fontpath = ref "";;
6067 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6070 let l = String.length
s in
6071 let b = Buffer.create
l in
6077 try Sys.getenv
"HOME"
6080 ("Can not determine home directory location: " ^
6081 Printexc.to_string exn
);
6085 let modifier_of_string = function
6086 | "alt" -> Wsi.altmask
6087 | "shift" -> Wsi.shiftmask
6088 | "ctrl" | "control" -> Wsi.ctrlmask
6089 | "meta" -> Wsi.metamask
6094 let r = Str.regexp
"-" in
6096 let elems = Str.full_split
r s in
6099 let m1 = modifier_of_string s in
6101 then (Wsi.namekey
s, m)
6104 | Str.Delim
s when n land 1 = 0 -> g s
6106 | Str.Delim
_ -> (k
, m)
6108 let rec loop n k
m = function
6111 let k, m = f n k m x in
6117 let keys_of_string =
6118 let r = Str.regexp
"[ \t]" in
6120 let elems = Str.split
r s in
6121 List.map
key_of_string elems
6124 let copykeyhashes c =
6125 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6128 let config_of c attrs
=
6132 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6133 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6134 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6135 | "preload" -> { c with preload = bool_of_string
v }
6136 | "page-bias" -> { c with pagebias
= int_of_string
v }
6137 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6138 | "horizontal-scroll-step" ->
6139 { c with hscrollstep
= max
(int_of_string
v) 1 }
6140 | "auto-scroll-step" ->
6141 { c with autoscrollstep
= max
0 (int_of_string
v) }
6142 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6143 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6146 match String.lowercase
v with
6147 | "true" -> Some infinity
6149 | f -> Some
(float_of_string
f)
6151 { c with maxwait
= mw}
6152 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6153 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6154 | "vertical-margin" ->
6155 { c with interpagespace
= max
0 (int_of_string
v) }
6157 let zoom = float_of_string
v /. 100. in
6158 let zoom = max
zoom 0.0 in
6159 { c with zoom = zoom }
6160 | "presentation" -> { c with presentation
= bool_of_string
v }
6161 | "rotation-angle" -> { c with angle
= int_of_string
v }
6162 | "width" -> { c with winw = max
20 (int_of_string
v) }
6163 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6164 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6165 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6166 | "pixmap-cache-size" ->
6167 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6168 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6169 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6170 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6171 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6172 | "background-color" -> { c with bgcolor
= color_of_string v }
6173 | "scrollbar-in-presentation" ->
6174 { c with scrollbarinpm
= bool_of_string
v }
6175 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6176 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6177 | "mupdf-store-size" ->
6178 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6179 | "checkers" -> { c with checkers
= bool_of_string
v }
6180 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6181 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6182 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6183 | "uri-launcher" -> { c with urilauncher
= unent v }
6184 | "path-launcher" -> { c with pathlauncher
= unent v }
6185 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6186 | "invert-colors" -> { c with invert
= bool_of_string
v }
6187 | "brightness" -> { c with colorscale
= float_of_string
v }
6188 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6190 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6192 let (n, _, _) as nab
= multicolumns_of_string v in
6194 then { c with columns
= Csplit
(-n, [||]) }
6195 else { c with columns
= Cmulti
(nab
, [||]) }
6196 | "birds-eye-columns" ->
6197 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6198 | "selection-command" -> { c with selcmd
= unent v }
6199 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6200 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6201 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6202 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6203 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6206 prerr_endline
("Error processing attribute (`" ^
6207 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6210 let rec fold c = function
6213 let c = apply c k v in
6216 fold { c with keyhashes
= copykeyhashes c } attrs
;
6219 let fromstring f pos
n v d =
6222 dolog "Error processing attribute (%S=%S) at %d\n%s"
6223 n v pos
(Printexc.to_string exn
)
6228 let bookmark_of attrs
=
6229 let rec fold title page
rely visy
= function
6230 | ("title", v) :: rest
-> fold v page
rely visy rest
6231 | ("page", v) :: rest
-> fold title v rely visy rest
6232 | ("rely", v) :: rest
-> fold title page
v visy rest
6233 | ("visy", v) :: rest
-> fold title page
rely v rest
6234 | _ :: rest
-> fold title page
rely visy rest
6235 | [] -> title, page
, rely, visy
6237 fold "invalid" "0" "0" "0" attrs
6241 let rec fold path page
rely pan visy
= function
6242 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6243 | ("page", v) :: rest
-> fold path v rely pan visy rest
6244 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6245 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6246 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6247 | _ :: rest
-> fold path page
rely pan visy rest
6248 | [] -> path, page
, rely, pan
, visy
6250 fold "" "0" "0" "0" "0" attrs
6254 let rec fold rs ls
= function
6255 | ("out", v) :: rest
-> fold v ls rest
6256 | ("in", v) :: rest
-> fold rs
v rest
6257 | _ :: rest
-> fold ls rs rest
6263 let setconf dst
src =
6264 dst
.scrollbw
<- src.scrollbw
;
6265 dst
.scrollh
<- src.scrollh
;
6266 dst
.icase
<- src.icase
;
6267 dst
.preload <- src.preload;
6268 dst
.pagebias
<- src.pagebias
;
6269 dst
.verbose
<- src.verbose
;
6270 dst
.scrollstep
<- src.scrollstep
;
6271 dst
.maxhfit
<- src.maxhfit
;
6272 dst
.crophack
<- src.crophack
;
6273 dst
.autoscrollstep
<- src.autoscrollstep
;
6274 dst
.maxwait
<- src.maxwait
;
6275 dst
.hlinks
<- src.hlinks
;
6276 dst
.underinfo
<- src.underinfo
;
6277 dst
.interpagespace
<- src.interpagespace
;
6278 dst
.zoom <- src.zoom;
6279 dst
.presentation
<- src.presentation
;
6280 dst
.angle
<- src.angle
;
6281 dst
.winw <- src.winw;
6282 dst
.winh
<- src.winh
;
6283 dst
.savebmarks
<- src.savebmarks
;
6284 dst
.memlimit
<- src.memlimit
;
6285 dst
.proportional
<- src.proportional
;
6286 dst
.texcount
<- src.texcount
;
6287 dst
.sliceheight
<- src.sliceheight
;
6288 dst
.thumbw
<- src.thumbw
;
6289 dst
.jumpback
<- src.jumpback
;
6290 dst
.bgcolor
<- src.bgcolor
;
6291 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6292 dst
.tilew
<- src.tilew
;
6293 dst
.tileh
<- src.tileh
;
6294 dst
.mustoresize
<- src.mustoresize
;
6295 dst
.checkers
<- src.checkers
;
6296 dst
.aalevel
<- src.aalevel
;
6297 dst
.trimmargins
<- src.trimmargins
;
6298 dst
.trimfuzz
<- src.trimfuzz
;
6299 dst
.urilauncher
<- src.urilauncher
;
6300 dst
.colorspace
<- src.colorspace
;
6301 dst
.invert
<- src.invert
;
6302 dst
.colorscale
<- src.colorscale
;
6303 dst
.redirectstderr <- src.redirectstderr;
6304 dst
.ghyllscroll
<- src.ghyllscroll
;
6305 dst
.columns
<- src.columns
;
6306 dst
.beyecolumns
<- src.beyecolumns
;
6307 dst
.selcmd
<- src.selcmd
;
6308 dst
.updatecurs
<- src.updatecurs
;
6309 dst
.pathlauncher
<- src.pathlauncher
;
6310 dst
.keyhashes
<- copykeyhashes src;
6311 dst
.hfsize
<- src.hfsize
;
6312 dst
.hscrollstep
<- src.hscrollstep
;
6313 dst
.pgscale <- src.pgscale;
6314 dst
.usepbo
<- src.usepbo
;
6315 dst
.wheelbypage
<- src.wheelbypage
;
6319 let h = Hashtbl.create
10 in
6320 let dc = { defconf with angle
= defconf.angle
} in
6321 let rec toplevel v t spos
_ =
6323 | Vdata
| Vcdata
| Vend
-> v
6324 | Vopen
("llppconfig", _, closed
) ->
6327 else { v with f = llppconfig
}
6329 error
"unexpected subelement at top level" s spos
6330 | Vclose
_ -> error
"unexpected close at top level" s spos
6332 and llppconfig
v t spos
_ =
6334 | Vdata
| Vcdata
-> v
6335 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6336 | Vopen
("defaults", attrs
, closed
) ->
6337 let c = config_of dc attrs
in
6341 else { v with f = defaults
}
6343 | Vopen
("ui-font", attrs
, closed
) ->
6344 let rec getsize size
= function
6346 | ("size", v) :: rest
->
6348 fromstring int_of_string spos
"size" v fstate.fontsize
in
6350 | l -> getsize size l
6352 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6355 else { v with f = uifont
(Buffer.create
10) }
6357 | Vopen
("doc", attrs
, closed
) ->
6358 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6359 let path = unent pathent
6360 and pageno = fromstring int_of_string spos
"page" spage
0
6361 and rely = fromstring float_of_string spos
"rely" srely
0.0
6362 and pan
= fromstring int_of_string spos
"pan" span
0
6363 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6364 let c = config_of dc attrs
in
6365 let anchor = (pageno, rely, visy
) in
6367 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6368 else { v with f = doc
path pan
anchor c [] }
6371 error
"unexpected subelement in llppconfig" s spos
6373 | Vclose
"llppconfig" -> { v with f = toplevel }
6374 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6376 and defaults
v t spos
_ =
6378 | Vdata
| Vcdata
-> v
6379 | Vend
-> error
"unexpected end of input in defaults" s spos
6380 | Vopen
("keymap", attrs
, closed
) ->
6382 try List.assoc
"mode" attrs
6383 with Not_found
-> "global" in
6388 let h = findkeyhash dc modename in
6389 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6392 { v with f = pkeymap
ret KeyMap.empty }
6394 | Vopen
(_, _, _) ->
6395 error
"unexpected subelement in defaults" s spos
6397 | Vclose
"defaults" ->
6398 { v with f = llppconfig
}
6400 | Vclose
_ -> error
"unexpected close in defaults" s spos
6402 and uifont
b v t spos
epos =
6405 Buffer.add_substring
b s spos
(epos - spos
);
6407 | Vopen
(_, _, _) ->
6408 error
"unexpected subelement in ui-font" s spos
6409 | Vclose
"ui-font" ->
6410 if String.length
!fontpath = 0
6411 then fontpath := Buffer.contents
b;
6412 { v with f = llppconfig
}
6413 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6414 | Vend
-> error
"unexpected end of input in ui-font" s spos
6416 and doc
path pan
anchor c bookmarks
v t spos
_ =
6418 | Vdata
| Vcdata
-> v
6419 | Vend
-> error
"unexpected end of input in doc" s spos
6420 | Vopen
("bookmarks", _, closed
) ->
6423 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6425 | Vopen
("keymap", attrs
, closed
) ->
6427 try List.assoc
"mode" attrs
6428 with Not_found
-> "global"
6434 let h = findkeyhash c modename in
6435 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6436 doc
path pan
anchor c bookmarks
6438 { v with f = pkeymap
ret KeyMap.empty }
6440 | Vopen
(_, _, _) ->
6441 error
"unexpected subelement in doc" s spos
6444 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6445 { v with f = llppconfig
}
6447 | Vclose
_ -> error
"unexpected close in doc" s spos
6449 and pkeymap
ret keymap
v t spos
_ =
6451 | Vdata
| Vcdata
-> v
6452 | Vend
-> error
"unexpected end of input in keymap" s spos
6453 | Vopen
("map", attrs
, closed
) ->
6454 let r, l = map_of attrs
in
6455 let kss = fromstring keys_of_string spos
"in" r [] in
6456 let lss = fromstring keys_of_string spos
"out" l [] in
6460 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6461 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6464 then { v with f = pkeymap
ret keymap }
6467 { v with f = skip
"map" f }
6470 error
"unexpected subelement in keymap" s spos
6472 | Vclose
"keymap" ->
6473 { v with f = ret keymap }
6475 | Vclose
_ -> error
"unexpected close in keymap" s spos
6477 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6479 | Vdata
| Vcdata
-> v
6480 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6481 | Vopen
("item", attrs
, closed
) ->
6482 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6483 let page = fromstring int_of_string spos
"page" spage
0
6484 and rely = fromstring float_of_string spos
"rely" srely
0.0
6485 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6487 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6490 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6493 { v with f = skip
"item" f }
6496 error
"unexpected subelement in bookmarks" s spos
6498 | Vclose
"bookmarks" ->
6499 { v with f = doc
path pan
anchor c bookmarks }
6501 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6503 and skip tag
f v t spos
_ =
6505 | Vdata
| Vcdata
-> v
6507 error
("unexpected end of input in skipped " ^ tag
) s spos
6508 | Vopen
(tag'
, _, closed
) ->
6512 let f'
() = { v with f = skip tag
f } in
6513 { v with f = skip tag'
f'
}
6517 else error
("unexpected close in skipped " ^ tag
) s spos
6520 parse
{ f = toplevel; accu = () } s;
6526 let len = in_channel_length ic
in
6527 let s = String.create
len in
6528 really_input ic
s 0 len;
6531 | Parse_error
(msg
, s, pos
) ->
6532 let subs = subs s pos
in
6533 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6534 failwith
("parse error: " ^
s)
6537 failwith
("config load error: " ^
Printexc.to_string exn
)
6543 let dir = Filename.concat
home ".config" in
6544 if Sys.is_directory
dir then dir else home
6547 Filename.concat
dir "llpp.conf"
6550 let confpath = ref defconfpath;;
6553 if Sys.file_exists
!confpath
6556 (try Some
(open_in_bin
!confpath)
6559 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6560 Printexc.to_string exn
);
6570 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6571 Printexc.to_string exn
);
6579 f (Hashtbl.create
0, defconf)
6584 let pc, pb
, px, pa
=
6586 Hashtbl.find h (Filename.basename
state.path)
6587 with Not_found
-> dc, [], 0, emptyanchor
6591 state.bookmarks <- pb
;
6593 state.scrollw
<- conf.scrollbw
;
6595 then state.anchor <- pa
;
6596 cbput state.hists
.nav pa
;
6602 let add_attrs bb always
dc c =
6605 then Printf.bprintf bb
"\n %s='%b'" s a
6608 then Printf.bprintf bb
"\n %s='%d'" s a
6611 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6614 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6617 then Printf.bprintf bb
"\n %s='%f'" s a
6621 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6625 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6629 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6633 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6639 | Some
(_N
, _A
, _B
) ->
6640 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6650 else string_of_float
f
6652 Printf.bprintf bb
"\n %s='%s'" s v
6657 | Cmulti
((n, a, b), _) when n > 1 ->
6658 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6659 | Csplit
(n, _) when n > 1 ->
6660 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6666 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6671 then dc.winw, dc.winh
6673 match state.fullscreen
with
6675 | None
-> c.winw, c.winh
6677 oi
"width" w dc.winw;
6678 oi
"height" h dc.winh
;
6679 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6680 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6681 ob "case-insensitive-search" c.icase
dc.icase
;
6682 ob "preload" c.preload dc.preload;
6683 oi
"page-bias" c.pagebias
dc.pagebias
;
6684 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6685 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6686 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6687 ob "crop-hack" c.crophack
dc.crophack
;
6688 oW
"throttle" c.maxwait
dc.maxwait
;
6689 ob "highlight-links" c.hlinks
dc.hlinks
;
6690 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6691 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6692 oz
"zoom" c.zoom dc.zoom;
6693 ob "presentation" c.presentation
dc.presentation
;
6694 oi
"rotation-angle" c.angle
dc.angle
;
6695 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6696 ob "proportional-display" c.proportional
dc.proportional
;
6697 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6698 oi
"tex-count" c.texcount
dc.texcount
;
6699 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6700 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6701 ob "persistent-location" c.jumpback
dc.jumpback
;
6702 oc
"background-color" c.bgcolor
dc.bgcolor
;
6703 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6704 oi
"tile-width" c.tilew
dc.tilew
;
6705 oi
"tile-height" c.tileh
dc.tileh
;
6706 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6707 ob "checkers" c.checkers
dc.checkers
;
6708 oi
"aalevel" c.aalevel
dc.aalevel
;
6709 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6710 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6711 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6712 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6713 oC
"color-space" c.colorspace
dc.colorspace
;
6714 ob "invert-colors" c.invert
dc.invert
;
6715 oF
"brightness" c.colorscale
dc.colorscale
;
6716 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6717 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6718 oco
"columns" c.columns
dc.columns
;
6719 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6720 os
"selection-command" c.selcmd
dc.selcmd
;
6721 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6722 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6723 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6724 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6725 ob "use-pbo" c.usepbo
dc.usepbo
;
6726 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6729 let keymapsbuf always
dc c =
6730 let bb = Buffer.create
16 in
6731 let rec loop = function
6733 | (modename, h) :: rest
->
6734 let dh = findkeyhash dc modename in
6735 if always
|| h <> dh
6737 if Hashtbl.length
h > 0
6739 if Buffer.length
bb > 0
6740 then Buffer.add_char
bb '
\n'
;
6741 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6742 Hashtbl.iter
(fun i
o ->
6743 let isdifferent = always
||
6745 let dO = Hashtbl.find dh i
in
6747 with Not_found
-> true
6752 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6753 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6754 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6755 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6756 Buffer.add_string
bb (Wsi.keyname
k);
6759 let rec loop = function
6761 | km
:: [] -> addkm km
6762 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6766 Buffer.add_string
bb "<map in='";
6770 Buffer.add_string
bb "' out='";
6772 Buffer.add_string
bb "'/>\n"
6775 Buffer.add_string
bb "' out='";
6777 Buffer.add_string
bb "'/>\n"
6779 | KMmulti
(ins, kms
) ->
6780 Buffer.add_char
bb ' '
;
6782 Buffer.add_string
bb "' out='";
6784 Buffer.add_string
bb "'/>\n"
6786 Buffer.add_string
bb "</keymap>";
6796 let uifontsize = fstate.fontsize
in
6797 let bb = Buffer.create
32768 in
6799 let dc = if conf.bedefault
then conf else dc in
6800 Buffer.add_string
bb "<llppconfig>\n";
6802 if String.length
!fontpath > 0
6804 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6810 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6813 Buffer.add_string
bb "<defaults ";
6814 add_attrs bb true dc dc;
6815 let kb = keymapsbuf true dc dc in
6816 if Buffer.length
kb > 0
6818 Buffer.add_string
bb ">\n";
6819 Buffer.add_buffer
bb kb;
6820 Buffer.add_string
bb "\n</defaults>\n";
6822 else Buffer.add_string
bb "/>\n";
6824 let adddoc path pan
anchor c bookmarks =
6825 if bookmarks == [] && c = dc && anchor = emptyanchor
6828 Printf.bprintf
bb "<doc path='%s'"
6829 (enent
path 0 (String.length
path));
6831 if anchor <> emptyanchor
6833 let n, rely, visy
= anchor in
6834 Printf.bprintf
bb " page='%d'" n;
6837 Printf.bprintf
bb " rely='%f'" rely
6839 if abs_float visy
> 1e-6
6841 Printf.bprintf
bb " visy='%f'" visy
6846 then Printf.bprintf
bb " pan='%d'" pan
;
6848 add_attrs bb false dc c;
6849 let kb = keymapsbuf false dc c in
6851 begin match bookmarks with
6853 if Buffer.length
kb > 0
6855 Buffer.add_string
bb ">\n";
6856 Buffer.add_buffer
bb kb;
6857 Buffer.add_string
bb "\n</doc>\n";
6859 else Buffer.add_string
bb "/>\n"
6861 Buffer.add_string
bb ">\n<bookmarks>\n";
6862 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6864 "<item title='%s' page='%d'"
6865 (enent
title 0 (String.length
title))
6870 Printf.bprintf
bb " rely='%f'" rely
6872 if abs_float visy
> 1e-6
6874 Printf.bprintf
bb " visy='%f'" visy
6876 Buffer.add_string
bb "/>\n";
6878 Buffer.add_string
bb "</bookmarks>";
6879 if Buffer.length
kb > 0
6881 Buffer.add_string
bb "\n";
6882 Buffer.add_buffer
bb kb;
6884 Buffer.add_string
bb "\n</doc>\n";
6890 match state.mode with
6891 | Birdseye
(c, pan, _, _, _) ->
6893 match conf.columns
with
6894 | Cmulti
((c, _, _), _) -> Some
c
6898 match c.columns
with
6899 | Cmulti
(c, _) -> Cmulti
(c, [||])
6900 | Csingle
_ -> Csingle
[||]
6901 | Csplit
_ -> failwith
"quit from bird's eye while split"
6903 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6904 | _ -> state.x, conf
6906 let basename = Filename.basename state.path in
6907 adddoc basename pan (getanchor ())
6909 let autoscrollstep =
6910 match state.autoscroll
with
6912 | None
-> conf.autoscrollstep
6914 match state.mode with
6915 | Birdseye
(bc
, _, _, _, _) ->
6918 presentation
= bc
.presentation
;
6919 interpagespace
= bc
.interpagespace
;
6920 maxwait
= bc
.maxwait
;
6921 autoscrollstep = autoscrollstep }
6922 | _ -> { conf with autoscrollstep = autoscrollstep }
6924 (if conf.savebmarks
then state.bookmarks else []);
6926 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6928 then adddoc path x anchor c bookmarks
6930 Buffer.add_string
bb "</llppconfig>\n";
6933 if load1 f && Buffer.length
bb > 0
6936 let tmp = !confpath ^
".tmp" in
6937 let oc = open_out_bin
tmp in
6938 Buffer.output_buffer
oc bb;
6940 Unix.rename
tmp !confpath;
6943 ("error while saving configuration: " ^
Printexc.to_string exn
)
6948 let trimcachepath = ref "" in
6951 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6952 "<password> Set password");
6954 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6955 "<path> Set path to the user interface font");
6957 ("-c", Arg.String
(fun s -> Config.confpath := s),
6958 "<path> Set path to the configuration file");
6960 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6961 "<path> Set path to the trim cache file");
6963 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
6964 "<named destination> Set named destination");
6966 ("-v", Arg.Unit
(fun () ->
6968 "%s\nconfiguration path: %s\n"
6972 exit
0), " Print version and exit");
6975 (fun s -> state.path <- s)
6976 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6978 if String.length
state.path = 0
6979 then (prerr_endline
"file name missing"; exit
1);
6981 if not
(Config.load ())
6982 then prerr_endline
"failed to load configuration";
6984 let globalkeyhash = findkeyhash conf "global" in
6985 let wsfd, winw, winh
= Wsi.init
(object
6987 state.wthack
<- false;
6988 if nogeomcmds state.geomcmds
|| platform == Posx
6991 GlClear.color (scalecolor2 conf.bgcolor
);
6992 GlClear.clear
[`
color];
6994 method display = display ()
6995 method reshape w h = reshape w h
6996 method mouse b d x y m = mouse b d x y m
6997 method motion x y = state.mpos
<- (x, y); motion x y
6998 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7000 let mascm = m land (
7001 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7003 match state.keystate
with
7005 let km = k, mascm in
7008 let modehash = state.uioh#
modehash in
7009 try Hashtbl.find modehash km
7011 try Hashtbl.find globalkeyhash km
7012 with Not_found
-> KMinsrt
(k, m)
7014 | KMinsrt
(k, m) -> keyboard k m
7015 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7016 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7018 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7019 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7020 state.keystate
<- KSnone
7021 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7022 state.keystate
<- KSinto
(keys
, insrt
)
7024 state.keystate
<- KSnone
7026 method enter
x y = state.mpos
<- (x, y); pmotion x y
7027 method leave = state.mpos
<- (-1, -1)
7028 method quit
= raise Quit
7029 end) conf.winw conf.winh
(platform = Posx
) in
7034 List.exists
GlMisc.check_extension
7035 [ "GL_ARB_texture_rectangle"
7036 ; "GL_EXT_texture_recangle"
7037 ; "GL_NV_texture_rectangle" ]
7039 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7042 match Ne.pipe () with
7044 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7048 match Ne.pipe () with
7050 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7060 setcheckers conf.checkers
;
7064 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7065 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7066 !Config.fontpath, !trimcachepath,
7067 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7071 state.text <- "Opening " ^
(mbtoutf8
state.path);
7073 opendoc state.path state.password
state.nameddest
;
7076 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7078 let rec loop deadline
=
7080 match state.errfd
with
7081 | None
-> [state.sr
; state.wsfd]
7082 | Some fd
-> [state.sr
; state.wsfd; fd
]
7086 state.redisplay
<- false;
7093 if deadline
= infinity
7095 else max
0.0 (deadline
-. now)
7100 try tempfailureretry (Unix.select
r [] []) timeout
7101 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7107 if state.ghyll
== noghyll
7109 match state.autoscroll
with
7110 | Some step
when step
!= 0 ->
7111 let y = state.y + step
in
7115 else if y >= state.maxy then 0 else y
7118 if state.mode = View
7119 then state.text <- "";
7122 else deadline
+. 0.01
7127 let rec checkfds = function
7129 | fd
:: rest
when fd
= state.sr
->
7130 let cmd = readcmd state.sr
in
7134 | fd
:: rest
when fd
= state.wsfd ->
7139 let s = String.create
80 in
7140 let n = tempfailureretry (Unix.read fd
s 0) 80 in
7141 if conf.redirectstderr
7143 Buffer.add_substring
state.errmsgs
s 0 n;
7144 state.newerrmsgs
<- true;
7145 state.redisplay
<- true;
7148 prerr_string
(String.sub
s 0 n);
7156 if deadline
= infinity
7160 match state.autoscroll
with
7161 | Some step
when step
!= 0 -> deadline1
7162 | _ -> if state.ghyll
== noghyll then infinity
else deadline1