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
95 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
96 external platform
: unit -> platform
= "ml_platform";;
97 external setaalevel
: int -> unit = "ml_setaalevel";;
98 external realloctexts
: int -> bool = "ml_realloctexts";;
99 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
100 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
101 external getlink
: opaque
-> int -> under
= "ml_getlink";;
102 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
103 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
104 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
105 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
106 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
107 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
108 external freepbo
: string -> unit = "ml_freepbo";;
109 external unmappbo
: string -> unit = "ml_unmappbo";;
110 external pbousable
: unit -> bool = "ml_pbo_usable";;
111 external unproject
: opaque
-> int -> int -> (int * int) option
114 let platform_to_string = function
115 | Punknown
-> "unknown"
119 | Pfreebsd
-> "FreeBSD"
120 | Pdragonflybsd
-> "DragonflyBSD"
121 | Popenbsd
-> "OpenBSD"
122 | Pnetbsd
-> "NetBSD"
123 | Pcygwin
-> "Cygwin"
126 let platform = platform ();;
129 if platform = Pcygwin
131 let sh = "/bin/sh" in
132 let args = [|sh; "-c"; cmd
|] in
133 let rec std si so se
= function
135 | (fd
, 0) :: rest
-> std fd so se rest
136 | (fd
, -1) :: rest
->
137 Unix.set_close_on_exec fd
;
140 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
142 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
143 ignore
(Unix.create_process
sh args si so se
)
152 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
155 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
157 type mpos
= int * int
159 | Msel
of (mpos
* mpos
)
161 | Mscrolly
| Mscrollx
162 | Mzoom
of (int * int)
163 | Mzoomrect
of (mpos
* mpos
)
167 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
168 and onkey
= string -> int -> te
169 and ondone
= string -> unit
170 and histcancel
= unit -> unit
171 and onhist
= ((histcmd
-> string) * histcancel
)
172 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
173 and cancelonempty
= bool
178 | TEswitch
of textentry
189 let bound v minv maxv
=
190 max minv
(min maxv v
);
194 { store
= Array.create n v
201 let cbcap b
= Array.length b
.store
;;
206 b
.wc
<- (b
.wc
+ 1) mod cap;
208 b
.len
<- min
(b
.len
+ 1) cap;
211 let cbempty b
= b
.len
= 0;;
213 let cbgetg b circular dir
=
217 let rc = b
.rc + dir
in
229 else bound rc 0 (b
.len
-1)
235 let cbget b
= cbgetg b
false;;
236 let cbgetc b
= cbgetg b
true;;
238 let drawstring size x y s
=
240 Gl.enable `texture_2d
;
241 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
242 ignore
(drawstr size x y s
);
244 Gl.disable `texture_2d
;
247 let drawstring1 size x y s
=
251 let drawstring2 size x y fmt
=
252 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
271 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
272 dolog " WxH %dx%d" l
.pagew l
.pageh
;
273 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
274 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
275 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
276 dolog " column %d" l
.pagecol
;
280 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
282 dolog " x0,y0=(% f, % f)" x0 y0
;
283 dolog " x1,y1=(% f, % f)" x1 y1
;
284 dolog " x2,y2=(% f, % f)" x2 y2
;
285 dolog " x3,y3=(% f, % f)" x3 y3
;
289 type multicolumns
= multicol
* pagegeom
290 and singlecolumn
= pagegeom
291 and splitcolumns
= columncount
* pagegeom
292 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
293 and multicol
= columncount
* covercount
* covercount
295 and columncount
= int
296 and covercount
= int;;
299 { mutable scrollbw
: int
300 ; mutable scrollh
: int
301 ; mutable icase
: bool
302 ; mutable preload
: bool
303 ; mutable pagebias
: int
304 ; mutable verbose
: bool
305 ; mutable debug
: bool
306 ; mutable scrollstep
: int
307 ; mutable hscrollstep
: int
308 ; mutable maxhfit
: bool
309 ; mutable crophack
: bool
310 ; mutable autoscrollstep
: int
311 ; mutable maxwait
: float option
312 ; mutable hlinks
: bool
313 ; mutable underinfo
: bool
314 ; mutable interpagespace
: interpagespace
315 ; mutable zoom
: float
316 ; mutable presentation
: bool
317 ; mutable angle
: angle
320 ; mutable savebmarks
: bool
321 ; mutable proportional
: proportional
322 ; mutable trimmargins
: trimmargins
323 ; mutable trimfuzz
: irect
324 ; mutable memlimit
: memsize
325 ; mutable texcount
: texcount
326 ; mutable sliceheight
: sliceheight
327 ; mutable thumbw
: width
328 ; mutable jumpback
: bool
329 ; mutable bgcolor
: float * float * float
330 ; mutable bedefault
: bool
331 ; mutable scrollbarinpm
: bool
332 ; mutable tilew
: int
333 ; mutable tileh
: int
334 ; mutable mustoresize
: memsize
335 ; mutable checkers
: bool
336 ; mutable aalevel
: int
337 ; mutable urilauncher
: string
338 ; mutable pathlauncher
: string
339 ; mutable colorspace
: colorspace
340 ; mutable invert
: bool
341 ; mutable colorscale
: float
342 ; mutable redirectstderr
: bool
343 ; mutable ghyllscroll
: (int * int * int) option
344 ; mutable columns
: columns
345 ; mutable beyecolumns
: columncount
option
346 ; mutable selcmd
: string
347 ; mutable updatecurs
: bool
348 ; mutable keyhashes
: (string * keyhash
) list
349 ; mutable hfsize
: int
350 ; mutable pgscale
: float
351 ; mutable usepbo
: bool
352 ; mutable wheelbypage
: bool
353 ; mutable stcmd
: string
356 | Csingle
of singlecolumn
357 | Cmulti
of multicolumns
358 | Csplit
of splitcolumns
361 type anchor
= pageno
* top
* dtop
;;
363 type outline
= string * int * anchor
;;
365 type rect
= float * float * float * float * float * float * float * float;;
367 type tile
= opaque
* pixmapsize
* elapsed
368 and elapsed
= float;;
369 type pagemapkey
= pageno
* gen
;;
370 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
374 let emptyanchor = (0, 0.0, 0.0);;
376 type infochange
= | Memused
| Docinfo
| Pdim
;;
378 class type uioh
= object
379 method display
: unit
380 method key
: int -> int -> uioh
381 method button
: int -> bool -> int -> int -> int -> uioh
382 method motion
: int -> int -> uioh
383 method pmotion
: int -> int -> uioh
384 method infochanged
: infochange
-> unit
385 method scrollpw
: (int * float * float)
386 method scrollph
: (int * float * float)
387 method modehash
: keyhash
391 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
392 | Textentry
of (textentry
* onleave
)
394 | LinkNav
of linktarget
395 and onleave
= leavetextentrystatus
-> unit
396 and leavetextentrystatus
= | Cancel
| Confirm
397 and helpitem
= string * int * action
400 | Action
of (uioh
-> uioh
)
402 | Ltexact
of (pageno
* int)
406 let isbirdseye = function Birdseye _
-> true | _
-> false;;
407 let istextentry = function Textentry _
-> true | _
-> false;;
411 | Loading
of (page
* gen
)
413 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
415 | Outlining
of outline list
418 let emptykeyhash = Hashtbl.create
0;;
419 let nouioh : uioh
= object (self
)
421 method key _ _
= self
422 method button _ _ _ _ _
= self
423 method motion _ _
= self
424 method pmotion _ _
= self
425 method infochanged _
= ()
426 method scrollpw
= (0, nan
, nan
)
427 method scrollph
= (0, nan
, nan
)
428 method modehash
= emptykeyhash
432 { mutable sr
: Unix.file_descr
433 ; mutable sw
: Unix.file_descr
434 ; mutable wsfd
: Unix.file_descr
435 ; mutable errfd
: Unix.file_descr
option
436 ; mutable stderr
: Unix.file_descr
437 ; mutable errmsgs
: Buffer.t
438 ; mutable newerrmsgs
: bool
442 ; mutable scrollw
: int
443 ; mutable hscrollh
: int
444 ; mutable anchor
: anchor
445 ; mutable ranchors
: (string * string * anchor
) list
447 ; mutable layout
: page list
448 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
449 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
450 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
451 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
452 ; mutable pagecount
: int
453 ; mutable currently
: currently
454 ; mutable mstate
: mstate
455 ; mutable searchpattern
: string
456 ; mutable rects
: (pageno
* recttype
* rect
) list
457 ; mutable rects1
: (pageno
* recttype
* rect
) list
458 ; mutable text
: string
459 ; mutable fullscreen
: (width
* height
) option
460 ; mutable mode
: mode
461 ; mutable uioh
: uioh
462 ; mutable outlines
: outline array
463 ; mutable bookmarks
: outline list
464 ; mutable path
: string
465 ; mutable password
: string
466 ; mutable nameddest
: string
467 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
468 ; mutable memused
: memsize
470 ; mutable throttle
: (page list
* int * float) option
471 ; mutable autoscroll
: int option
472 ; mutable ghyll
: (int option -> unit)
473 ; mutable help
: helpitem array
474 ; mutable docinfo
: (int * string) list
475 ; mutable texid
: GlTex.texture_id
option
477 ; mutable prevzoom
: float
478 ; mutable progress
: float
479 ; mutable redisplay
: bool
480 ; mutable mpos
: mpos
481 ; mutable keystate
: keystate
482 ; mutable glinks
: bool
483 ; mutable prevcolumns
: (columns
* float) option
484 ; mutable wthack
: bool
487 { pat
: string circbuf
488 ; pag
: string circbuf
489 ; nav
: anchor circbuf
490 ; sel
: string circbuf
512 ; presentation
= false
517 ; proportional
= true
518 ; trimmargins
= false
519 ; trimfuzz
= (0,0,0,0)
520 ; memlimit
= 32 lsl 20
525 ; bgcolor
= (0.5, 0.5, 0.5)
527 ; scrollbarinpm
= true
530 ; mustoresize
= 256 lsl 20
535 | Plinux
| Pfreebsd
| Pdragonflybsd
536 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
537 | Posx
-> "open \"%s\""
538 | Pcygwin
-> "cygstart \"%s\""
539 | Punknown
-> "echo %s")
540 ; pathlauncher
= "lp \"%s\""
543 | Plinux
| Pfreebsd
| Pdragonflybsd
544 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
551 ; redirectstderr
= false
553 ; columns
= Csingle
[||]
559 ; wheelbypage
= false
560 ; stcmd
= "echo SyncTex"
562 let mk n
= (n
, Hashtbl.create
1) in
576 let wtmode = ref false;;
578 let findkeyhash c name
=
579 try List.assoc name c
.keyhashes
580 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
583 let conf = { defconf with angle
= defconf.angle
};;
585 let pgscale h
= truncate
(float h
*. conf.pgscale);;
588 { mutable fontsize
: int
589 ; mutable wwidth
: float
590 ; mutable maxrows
: int
602 fstate.fontsize
<- n
;
603 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
604 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
608 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
609 let len = String.length s
in
610 if colonpos >= 0 && colonpos + 3 < len
612 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
615 try String.rindex_from s
colonpos ' '
619 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
622 | "http" | "ftp" | "mailto" ->
624 try String.index_from s
colonpos ' '
625 with Not_found
-> len
627 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
635 if String.length
conf.urilauncher
= 0
636 then print_endline uri
638 let url = geturl uri
in
639 if String.length
url = 0
640 then print_endline uri
642 let re = Str.regexp
"%s" in
643 let command = Str.global_replace
re url conf.urilauncher
in
647 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
653 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
654 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
658 let strings = version () :: "" :: Help.keys
in
661 let url = geturl s
in
662 if String.length
url > 0
663 then (s
, 0, Action
(fun u
-> gotouri url; u
))
664 else (s
, 0, Noaction
)
669 let firstgeomcmds = "", [];;
676 ; stderr
= Unix.stderr
677 ; errmsgs
= Buffer.create
0
684 ; anchor
= emptyanchor
688 ; tilelru
= Queue.create
()
689 ; pagemap
= Hashtbl.create
10
690 ; tilemap
= Hashtbl.create
10
706 ; geomcmds
= firstgeomcmds
708 { nav
= cbnew 10 emptyanchor
736 Printf.kprintf prerr_endline fmt
738 Printf.kprintf ignore fmt
742 if String.length
conf.pathlauncher
= 0
743 then print_endline
state.path
745 let re = Str.regexp
"%s" in
746 let command = Str.global_replace
re state.path
conf.pathlauncher
in
750 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
756 type 'a t
= | Res
of 'a
| Exn
of exn
;;
759 try Res
(Unix.pipe ())
764 try tempfailureretry Unix.close fd
765 with exn
-> f
(Printexc.to_string exn
)
769 try Res
(tempfailureretry Unix.dup fd
)
774 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
779 let redirectstderr () =
780 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
781 if conf.redirectstderr
783 match Ne.pipe () with
785 dolog "failed to create stderr redirection pipes: %s"
786 (Printexc.to_string exn
)
789 begin match Ne.dup Unix.stderr
with
791 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
792 Ne.clo r
(clofail "pipe/r");
793 Ne.clo w
(clofail "pipe/w");
795 | Ne.Res dupstderr
->
796 begin match Ne.dup2 w
Unix.stderr
with
798 dolog "failed to dup2 to stderr: %s"
799 (Printexc.to_string exn
);
800 Ne.clo dupstderr
(clofail "stderr duplicate");
801 Ne.clo r
(clofail "redir pipe/r");
802 Ne.clo w
(clofail "redir pipe/w");
805 state.stderr
<- dupstderr
;
806 state.errfd
<- Some r
;
810 state.newerrmsgs
<- false;
811 begin match state.errfd
with
813 begin match Ne.dup2 state.stderr
Unix.stderr
with
815 dolog "failed to dup2 original stderr: %s"
816 (Printexc.to_string exn
)
818 Ne.clo fd
(clofail "dup of stderr");
823 prerr_string
(Buffer.contents
state.errmsgs
);
825 Buffer.clear
state.errmsgs
;
831 let postRedisplay who
=
833 then prerr_endline
("redisplay for " ^ who
);
834 state.redisplay
<- true;
838 let getopaque pageno
=
839 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
840 with Not_found
-> None
843 let putopaque pageno opaque
=
844 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
847 let pagetranslatepoint l x y
=
848 let dy = y
- l
.pagedispy
in
849 let y = dy + l
.pagey
in
850 let dx = x
- l
.pagedispx
in
851 let x = dx + l
.pagex
in
855 let onppundermouse g
x y d
=
858 begin match getopaque l
.pageno
with
860 let x0 = l
.pagedispx
in
861 let x1 = x0 + l
.pagevw
in
862 let y0 = l
.pagedispy
in
863 let y1 = y0 + l
.pagevh
in
864 if y >= y0 && y <= y1 && x >= x0 && x <= x1
866 let px, py
= pagetranslatepoint l
x y in
867 match g opaque l
px py
with
880 let g opaque _
px py
=
881 match whatsunder opaque
px py
with
883 | under
-> Some under
885 onppundermouse g x y Unone
890 match unproject opaque
x y with
891 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
894 onppundermouse g x y None
;
898 state.text
<- Printf.sprintf
"%c%s" c s
;
899 G.postRedisplay "showtext";
902 let undertext = function
905 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
906 | Utext s
-> "font: " ^ s
907 | Uunexpected s
-> "unexpected: " ^ s
908 | Ulaunch s
-> "launch: " ^ s
909 | Unamed s
-> "named: " ^ s
910 | Uremote
(filename
, pageno
) ->
911 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
914 let updateunder x y =
915 match getunder x y with
916 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
918 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
919 Wsi.setcursor
Wsi.CURSOR_INFO
920 | Ulinkgoto
(pageno
, _
) ->
922 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
923 Wsi.setcursor
Wsi.CURSOR_INFO
925 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
926 Wsi.setcursor
Wsi.CURSOR_TEXT
928 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
929 Wsi.setcursor
Wsi.CURSOR_INHERIT
931 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
932 Wsi.setcursor
Wsi.CURSOR_INHERIT
934 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
935 Wsi.setcursor
Wsi.CURSOR_INHERIT
936 | Uremote
(filename
, pageno
) ->
937 if conf.underinfo
then showtext 'r'
938 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
939 Wsi.setcursor
Wsi.CURSOR_INFO
942 let showlinktype under
=
948 let s = undertext under
in
953 let b = Buffer.create
(String.length
s + 1) in
954 Buffer.add_string
b s;
959 let colorspace_of_string s =
960 match String.lowercase
s with
964 | _
-> failwith
"invalid colorspace"
967 let int_of_colorspace = function
973 let colorspace_of_int = function
977 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
980 let colorspace_to_string = function
986 let intentry_with_suffix text key
=
988 if key
>= 32 && key
< 127
992 match Char.lowercase
c with
994 let text = addchar text c in
998 let text = addchar text c in
1002 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1006 let multicolumns_to_string (n
, a
, b) =
1008 then Printf.sprintf
"%d" n
1009 else Printf.sprintf
"%d,%d,%d" n a
b;
1012 let multicolumns_of_string s =
1014 (int_of_string
s, 0, 0)
1016 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1018 then failwith
"subtly broken"; (n
, a
, b)
1024 let n = tempfailureretry (Unix.read fd
s 0) 4 in
1025 if n != 4 then failwith
"incomplete read(len)";
1027 lor (Char.code
s.[0] lsl 24)
1028 lor (Char.code
s.[1] lsl 16)
1029 lor (Char.code
s.[2] lsl 8)
1030 lor (Char.code
s.[3] lsl 0)
1032 let s = String.create
len in
1033 let n = tempfailureretry (Unix.read fd
s 0) len in
1034 if n != len then failwith
"incomplete read(data)";
1038 let btod b = if b then 1 else 0;;
1041 let b = Buffer.create
16 in
1042 Buffer.add_string
b "llll";
1045 let s = Buffer.contents
b in
1046 let n = String.length
s in
1048 (* dolog "wcmd %S" (String.sub s 4 len); *)
1049 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1050 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1051 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1052 s.[3] <- Char.chr
(len land 0xff);
1053 let n'
= tempfailureretry (Unix.write
state.sw
s 0) n in
1054 if n'
!= n then failwith
"write failed";
1059 let d = conf.winh
- h
in
1060 max
conf.interpagespace
((d + 1) / 2)
1063 let rowyh (c, coverA
, coverB
) b n =
1064 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1066 let _, _, vy
, (_, _, h
, _) = b.(n) in
1069 let n'
= n - coverA
in
1072 let e = min
state.pagecount
(s + c) in
1073 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1074 let _, _, y, (_, _, h
, _) = b.(m
) in
1075 let miny = min
miny y in
1076 let maxh = max
maxh h
in
1077 find (m
+1) miny maxh
1082 match conf.columns
with
1083 | Cmulti
((_, _, _) as cl
, b) ->
1084 if Array.length
b > 0
1086 let y, h
= rowyh cl
b (Array.length
b - 1) in
1087 y + h
+ (if conf.presentation
then calcips h
else 0)
1090 if Array.length
b > 0
1092 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1093 y + h
+ (if conf.presentation
then calcips h
else 0)
1096 if Array.length
b > 0
1098 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1103 let getpageyh pageno
=
1104 let pageno = bound pageno 0 (state.pagecount
-1) in
1105 match conf.columns
with
1107 if Array.length
b = 0
1110 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1112 if conf.presentation
1118 if Array.length
b = 0
1121 let y, h
= rowyh cl
b pageno in
1123 if conf.presentation
1129 if Array.length
b = 0
1133 let (_, _, y, (_, _, h
, _)) = b.(n) in
1137 let getpagedim pageno =
1140 | (n, _, _, _) as pdim
:: rest
->
1142 then (if n = pageno then pdim
else ppdim
)
1147 f (-1, -1, -1, -1) state.pdims
1150 let getpagey pageno = fst
(getpageyh pageno);;
1152 let nogeomcmds cmds
=
1154 | s, [] -> String.length
s = 0
1159 let ((c, coverA
, coverB
) as cl
), b =
1160 match conf.columns
with
1161 | Csingle
b -> (1, 0, 0), b
1162 | Cmulti
(c, b) -> c, b
1163 | Csplit
(_, b) -> (1, 0, 0), b
1165 let rec bsearch nmin nmax
=
1167 then bound nmin
0 (state.pagecount
-1)
1169 let n = (nmax
+ nmin
) / 2 in
1170 let vy, h
= rowyh cl
b n in
1172 if conf.presentation
1174 let ips = calcips h
in
1175 let y0 = vy - ips in
1176 let y1 = vy + h
+ ips in
1180 then 0, vy + h
+ conf.interpagespace
1182 let y0 = vy - conf.interpagespace
in
1183 y0, y0 + h
+ conf.interpagespace
1186 if y >= y0 && y < y1
1193 if n < state.pagecount
- coverB
1194 then ((n-coverA
)/c)*c + coverA
1201 then bsearch (n+1) nmax
1202 else bsearch nmin
(n-1)
1205 let r = bsearch 0 (state.pagecount
-1) in
1209 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1210 let sh = sh - state.hscrollh
in
1211 let rec fold accu
n =
1212 if n = Array.length
b
1215 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1218 || n = state.pagecount
- coverB
1219 || (n - coverA
) mod columns
= columns
- 1)
1225 let pagey = max
0 (y - vy) in
1226 let pagedispy = if pagey > 0 then 0 else vy - y in
1227 let pagedispx, pagex
=
1229 if n = coverA
- 1 || n = state.pagecount
- coverB
1230 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1231 else dx + xoff
+ state.x
1238 let vw = conf.winw
- state.scrollw
- pagedispx in
1239 let pw = w
- pagex
in
1242 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1243 if pagevw > 0 && pagevh > 0
1247 ; pagedimno
= pdimno
1254 ; pagedispx = pagedispx
1255 ; pagedispy = pagedispy
1267 List.rev
(fold [] (page_of_y y));
1270 let layoutS (columns
, b) y sh =
1271 let sh = sh - state.hscrollh
in
1272 let rec fold accu n =
1273 if n = Array.length
b
1276 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1283 let x = xoff
+ state.x in
1284 let pagey = max
0 (y - vy) in
1285 let pagedispy = if pagey > 0 then 0 else vy - y in
1286 let pagedispx, pagex
=
1300 let pagecolw = pagew
/columns
in
1302 if pagecolw < conf.winw
1303 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1307 let vw = conf.winw
- pagedispx - state.scrollw
in
1308 let pw = pagew
- pagex
in
1311 let pagevw = min
pagevw pagecolw in
1312 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1313 if pagevw > 0 && pagevh > 0
1316 { pageno = n/columns
1317 ; pagedimno
= pdimno
1324 ; pagedispx = pagedispx
1325 ; pagedispy = pagedispy
1326 ; pagecol
= n mod columns
1337 List.rev
(fold [] 0)
1341 if nogeomcmds state.geomcmds
1343 match conf.columns
with
1344 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1345 | Cmulti
c -> layoutN c y sh
1346 | Csplit
s -> layoutS s y sh
1351 let y = state.y + incr
in
1353 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1358 let tilex = l
.pagex
mod conf.tilew
in
1359 let tiley = l
.pagey mod conf.tileh
in
1361 let col = l
.pagex
/ conf.tilew
in
1362 let row = l
.pagey / conf.tileh
in
1364 let rec rowloop row y0 dispy h
=
1368 let dh = conf.tileh
- y0 in
1369 let dh = min h
dh in
1370 let rec colloop col x0 dispx w
=
1374 let dw = conf.tilew
- x0 in
1375 let dw = min w
dw in
1377 f col row dispx dispy
x0 y0 dw dh;
1378 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1381 colloop col tilex l
.pagedispx l
.pagevw;
1382 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1385 if l
.pagevw > 0 && l
.pagevh > 0
1386 then rowloop row tiley l
.pagedispy l
.pagevh;
1389 let gettileopaque l
col row =
1391 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1393 try Some
(Hashtbl.find state.tilemap
key)
1394 with Not_found
-> None
1397 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1398 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1399 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1402 let drawtiles l color
=
1404 let f col row x y tilex tiley w h
=
1405 match gettileopaque l
col row with
1406 | Some
(opaque
, _, t
) ->
1407 let params = x, y, w
, h
, tilex, tiley in
1411 GlFunc.blend_func `zero `one_minus_src_color
;
1413 drawtile
params opaque
;
1415 then Gl.disable `blend
;
1418 let s = Printf.sprintf
1422 let w = measurestr
fstate.fontsize
s in
1423 GlMisc.push_attrib
[`current
];
1424 GlDraw.color
(0.0, 0.0, 0.0);
1426 (float (x-2), float (y-2))
1427 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1428 GlDraw.color
(1.0, 1.0, 1.0);
1429 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1430 GlMisc.pop_attrib
();
1435 let lw = conf.winw
- state.scrollw
- x in
1438 let lh = conf.winh
- y in
1441 begin match state.texid
with
1443 Gl.enable `texture_2d
;
1444 GlTex.bind_texture `texture_2d id
;
1447 and x1 = float (x+w)
1448 and y1 = float (y+h
) in
1450 let tw = float w /. 16.0
1451 and th
= float h
/. 16.0 in
1452 let tx0 = float tilex /. 16.0
1453 and ty0
= float tiley /. 16.0 in
1455 and ty1
= ty0
+. th
in
1456 GlDraw.begins `quads
;
1457 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1458 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1459 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1460 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1463 Gl.disable `texture_2d
;
1465 GlDraw.color
(1.0, 1.0, 1.0);
1468 (float (x+w), float (y+h
));
1470 if w > 128 && h
> fstate.fontsize
+ 10
1472 GlDraw.color
(0.0, 0.0, 0.0);
1475 then (col*conf.tilew
, row*conf.tileh
)
1478 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1485 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1487 let tilevisible1 l
x y =
1489 and ax1
= l
.pagex
+ l
.pagevw
1491 and ay1
= l
.pagey + l
.pagevh in
1495 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1496 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1498 let rx0 = max
ax0 bx0
1499 and ry0
= max ay0 by0
1500 and rx1
= min ax1
bx1
1501 and ry1
= min ay1 by1
in
1503 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1504 nonemptyintersection
1507 let tilevisible layout n x y =
1508 let rec findpageinlayout m
= function
1509 | l
:: rest
when l
.pageno = n ->
1510 tilevisible1 l
x y || (
1511 match conf.columns
with
1512 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1515 | _ :: rest
-> findpageinlayout 0 rest
1518 findpageinlayout 0 layout;
1521 let tileready l
x y =
1522 tilevisible1 l
x y &&
1523 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1526 let tilepage n p
layout =
1527 let rec loop = function
1531 let f col row _ _ _ _ _ _ =
1532 if state.currently
= Idle
1534 match gettileopaque l
col row with
1537 let x = col*conf.tilew
1538 and y = row*conf.tileh
in
1540 let w = l
.pagew
- x in
1544 let h = l
.pageh
- y in
1549 then getpbo
w h conf.colorspace
1552 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1555 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1556 conf.tilew
, conf.tileh
1565 if nogeomcmds state.geomcmds
1569 let preloadlayout y =
1570 let y = if y < conf.winh
then 0 else y - conf.winh
in
1571 let h = conf.winh
*3 in
1576 let rec loop pages
=
1577 if state.currently
!= Idle
1582 begin match getopaque l
.pageno with
1584 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1585 state.currently
<- Loading
(l
, state.gen
);
1587 tilepage l
.pageno opaque pages
;
1592 if nogeomcmds state.geomcmds
1598 if conf.preload && state.currently
= Idle
1599 then load (preloadlayout state.y);
1602 let layoutready layout =
1603 let rec fold all ls
=
1604 all
&& match ls
with
1606 let seen = ref false in
1607 let allvisible = ref true in
1608 let foo col row _ _ _ _ _ _ =
1610 allvisible := !allvisible &&
1611 begin match gettileopaque l
col row with
1617 fold (!seen && !allvisible) rest
1620 let alltilesvisible = fold true layout in
1625 state.wthack
<- false;
1626 let y = bound y 0 state.maxy
in
1627 let y, layout, proceed
=
1628 match conf.maxwait
with
1629 | Some time
when state.ghyll
== noghyll ->
1630 begin match state.throttle
with
1632 let layout = layout y conf.winh
in
1633 let ready = layoutready layout in
1637 state.throttle
<- Some
(layout, y, now ());
1639 else G.postRedisplay "gotoy showall (None)";
1641 | Some
(_, _, started
) ->
1642 let dt = now () -. started
in
1645 state.throttle
<- None
;
1646 let layout = layout y conf.winh
in
1648 G.postRedisplay "maxwait";
1655 let layout = layout y conf.winh
in
1656 G.postRedisplay "gotoy ready";
1662 state.layout <- layout;
1663 begin match state.mode
with
1664 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1665 let rec loop = function
1667 state.mode
<- LinkNav
(Ltgendir
0)
1668 | l
:: _ when l
.pageno = pageno ->
1669 begin match getopaque pageno with
1671 state.mode
<- LinkNav
(Ltgendir
0)
1673 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1674 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1675 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1676 then state.mode
<- LinkNav
(Ltgendir
0)
1678 | _ :: rest
-> loop rest
1683 begin match state.mode
with
1684 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1685 if not
(pagevisible layout pageno)
1687 match state.layout with
1690 state.mode
<- Birdseye
(
1691 conf, leftx
, l
.pageno, hooverpageno
, anchor
1694 | LinkNav
(Ltgendir dir
as lt
) ->
1696 let rec loop = function
1699 match getopaque l
.pageno with
1705 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1707 if dir
> 0 then LDfirst
else LDlast
1713 | Lnotfound
-> loop rest
1715 showlinktype (getlink opaque
n);
1716 Ltexact
(l
.pageno, n)
1720 state.mode
<- LinkNav
linknav
1725 state.ghyll
<- noghyll;
1728 let mx, my
= state.mpos
in
1733 let conttiling pageno opaque
=
1734 tilepage pageno opaque
1735 (if conf.preload then preloadlayout state.y else state.layout)
1738 let gotoy_and_clear_text y =
1739 if not
conf.verbose
then state.text <- "";
1745 let coloff = l
.pagecol
* l
.pageh
in
1746 float (l
.pagey + coloff) /. float l
.pageh
1753 if conf.presentation
1754 then float l
.pagedispy /. float (calcips l
.pageh
)
1755 else float l
.pagedispy /. float conf.interpagespace
1757 (l
.pageno, top, dtop)
1761 match state.layout with
1762 | l
:: _ -> getanchor1 l
1764 let n = page_of_y state.y in
1765 let y, h = getpageyh n in
1766 let dy = y - state.y in
1768 if conf.presentation
1770 let ips = calcips h in
1771 float (dy + ips) /. float ips
1773 float dy /. float conf.interpagespace
1778 let getanchory (n, top, dtop) =
1779 let y, h = getpageyh n in
1780 if conf.presentation
1782 let ips = calcips h in
1783 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1785 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1788 let gotoanchor anchor
=
1789 gotoy (getanchory anchor
);
1793 cbput state.hists
.nav
(getanchor ());
1797 let anchor = cbgetc state.hists
.nav dir
in
1802 let scroll f n a
b =
1803 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1805 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1807 then s (float f /. float a
)
1810 then 1.0 -. s ((float (f-b) /. float (n-b)))
1817 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1818 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1820 let ins = float a
*. iv1
1821 and outs
= float (n-b) *. iv1 in
1823 ins +. outs
+. float ones
1825 let rec set (_N
, _A
, _B
) y sy
=
1826 let sum = summa
1.0 _N _A _B
in
1827 let dy = float (y - sy
) in
1831 then state.ghyll
<- noghyll
1834 let s = scroll n _N _A _B
in
1835 let y1 = y1 +. ((s *. dy) /. sum) in
1836 gotoy_and_clear_text (truncate
y1);
1837 state.ghyll
<- gf (n+1) y1;
1841 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1843 gf 0 (float state.y)
1846 match conf.ghyllscroll
with
1848 gotoy_and_clear_text y
1850 if state.ghyll
== noghyll
1851 then set nab
y state.y
1852 else state.ghyll
(Some
y)
1855 let gotopage n top =
1856 let y, h = getpageyh n in
1857 let y = y + (truncate
(top *. float h)) in
1861 let gotopage1 n top =
1862 let y = getpagey n in
1867 let invalidate s f =
1872 match state.geomcmds
with
1873 | ps
, [] when String.length ps
= 0 ->
1875 state.geomcmds
<- s, [];
1878 state.geomcmds
<- ps
, [s, f];
1880 | ps
, (s'
, _) :: rest
when s'
= s ->
1881 state.geomcmds
<- ps
, ((s, f) :: rest
);
1884 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1888 Hashtbl.iter
(fun _ opaque
->
1889 wcmd "freepage %s" opaque
;
1891 Hashtbl.clear
state.pagemap
;
1894 let opendoc path password
=
1896 state.password
<- password
;
1897 state.gen
<- state.gen
+ 1;
1898 state.docinfo
<- [];
1901 setaalevel
conf.aalevel
;
1902 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1903 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1904 invalidate "reqlayout"
1906 wcmd "reqlayout %d %d %s\000"
1907 conf.angle
(btod conf.proportional
) state.nameddest
;
1912 state.anchor <- getanchor ();
1913 state.wthack
<- !wtmode;
1914 opendoc state.path
state.password
;
1918 let c = c *. conf.colorscale
in
1922 let scalecolor2 (r, g, b) =
1923 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
1926 let docolumns = function
1928 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1929 let rec loop pageno pdimno pdim
y ph pdims
=
1930 if pageno = state.pagecount
1933 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1935 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1936 pdimno+1, pdim
, rest
1940 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1942 (if conf.presentation
1943 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1944 else (if pageno = 0 then 0 else conf.interpagespace
)
1947 a.(pageno) <- (pdimno, x, y, pdim
);
1948 loop (pageno+1) pdimno pdim
(y + h) h pdims
1950 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1951 conf.columns
<- Csingle
a;
1953 | Cmulti
((columns
, coverA
, coverB
), _) ->
1954 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1955 let rec loop pageno pdimno pdim
x y rowh pdims
=
1956 let rec fixrow m
= if m
= pageno then () else
1957 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1960 let y = y + (rowh
- h) / 2 in
1961 a.(m
) <- (pdimno, x, y, pdim
);
1965 if pageno = state.pagecount
1966 then fixrow (((pageno - 1) / columns
) * columns
)
1968 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1970 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1971 pdimno+1, pdim
, rest
1976 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1978 let x = (conf.winw
- state.scrollw
- w) / 2 in
1980 if conf.presentation
then calcips h else conf.interpagespace
in
1981 x, y + ips + rowh
, h
1984 if (pageno - coverA
) mod columns
= 0
1986 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1988 if conf.presentation
1990 let ips = calcips h in
1991 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1993 y + (if pageno = 0 then 0 else conf.interpagespace
)
1997 else x, y, max rowh
h
2001 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2004 if pageno = columns
&& conf.presentation
2006 let ips = calcips rowh
in
2007 for i
= 0 to pred columns
2009 let (pdimno, x, y, pdim
) = a.(i
) in
2010 a.(i
) <- (pdimno, x, y+ips, pdim
)
2016 fixrow (pageno - columns
);
2021 a.(pageno) <- (pdimno, x, y, pdim
);
2022 let x = x + w + xoff
*2 + conf.interpagespace
in
2023 loop (pageno+1) pdimno pdim
x y rowh' pdims
2025 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2026 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2029 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2030 let rec loop pageno pdimno pdim
y pdims
=
2031 if pageno = state.pagecount
2034 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2036 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2037 pdimno+1, pdim
, rest
2042 let rec loop1 n x y =
2043 if n = c then y else (
2044 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2045 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2048 let y = loop1 0 0 y in
2049 loop (pageno+1) pdimno pdim
y pdims
2051 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2052 conf.columns
<- Csplit
(c, a);
2056 docolumns conf.columns
;
2057 state.maxy
<- calcheight ();
2059 if state.w <= conf.winw
- state.scrollw
2063 let wthack = state.wthack in
2064 begin match state.mode
with
2065 | Birdseye
(_, _, pageno, _, _) ->
2066 let y, h = getpageyh pageno in
2067 let top = (conf.winh
- h) / 2 in
2068 gotoy (max
0 (y - top))
2069 | _ -> gotoanchor state.anchor
2071 state.wthack <- wthack;
2075 state.wthack <- false;
2076 GlDraw.viewport
0 0 w h;
2077 let firsttime = state.geomcmds
== firstgeomcmds in
2078 if not
firsttime && nogeomcmds state.geomcmds
2079 then state.anchor <- getanchor ();
2082 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2085 setfontsize fstate.fontsize
;
2086 GlMat.mode `modelview
;
2087 GlMat.load_identity
();
2089 GlMat.mode `projection
;
2090 GlMat.load_identity
();
2091 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2092 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2093 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2098 else float state.x /. float state.w
2100 invalidate "geometry"
2104 then state.x <- truncate
(relx *. float w);
2106 match conf.columns
with
2108 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2109 | Csplit
(c, _) -> w * c
2111 wcmd "geometry %d %d" w h);
2115 let len = String.length
state.text in
2118 match state.mode
with
2121 let h, _, _ = state.uioh#scrollpw
in
2127 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2128 (x+.w, float (conf.winh
- hscrollh))
2131 let w = float (conf.winw
- state.scrollw
- 1) in
2132 if state.progress
>= 0.0 && state.progress
< 1.0
2134 GlDraw.color
(0.3, 0.3, 0.3);
2135 let w1 = w *. state.progress
in
2137 GlDraw.color
(0.0, 0.0, 0.0);
2141 GlDraw.color
(0.0, 0.0, 0.0);
2145 GlDraw.color
(1.0, 1.0, 1.0);
2146 drawstring fstate.fontsize
2147 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2150 match state.mode
with
2151 | Textentry
((prefix
, text, _, _, _, _), _) ->
2155 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2157 Printf.sprintf
"%s%s_" prefix
text
2166 if not
(istextentry state.mode
)
2168 let s1 = "(press 'e' to review error messasges)" in
2169 if String.length
s > 0 then s ^
" " ^
s1 else s1
2174 if String.length
s > 0
2179 let len = Queue.length
state.tilelru
in
2181 match state.throttle
with
2184 then preloadlayout state.y
2186 | Some
(layout, _, _) ->
2190 if state.memused
<= conf.memlimit
2195 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2196 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2197 let (_, pw, ph
, _) = getpagedim n in
2200 && colorspace
= conf.colorspace
2201 && angle
= conf.angle
2205 let x = col*conf.tilew
2206 and y = row*conf.tileh
in
2207 tilevisible (Lazy.force_val
layout) n x y
2209 then Queue.push lruitem
state.tilelru
2212 wcmd "freetile %s" p
;
2213 state.memused
<- state.memused
- s;
2214 state.uioh#infochanged Memused
;
2215 Hashtbl.remove
state.tilemap k
;
2224 Queue.iter
(fun (k
, p
, s) ->
2225 wcmd "freetile %s" p
;
2226 state.memused
<- state.memused
- s;
2227 state.uioh#infochanged Memused
;
2228 Hashtbl.remove
state.tilemap k
;
2230 Queue.clear
state.tilelru
;
2234 let logcurrently = function
2235 | Idle
-> dolog "Idle"
2236 | Loading
(l
, gen
) ->
2237 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2238 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2240 "Tiling %d[%d,%d] page=%s cs=%s angle"
2241 l
.pageno col row pageopaque
2242 (colorspace_to_string colorspace
)
2244 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2245 angle gen
conf.angle
state.gen
2247 conf.tilew
conf.tileh
2254 (* dolog "%S" cmds; *)
2257 try String.index cmds ' '
2258 with Not_found
-> -1
2263 let l = String.length cmds
in
2264 let op = String.sub cmds
0 spacepos in
2266 if l - spacepos < 2 then ""
2267 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2271 try Scanf.sscanf
s fmt
f
2273 dolog "error processing '%S' %S: %s"
2274 op cmds
(Printexc.to_string exn
);
2279 state.uioh#infochanged Pdim
;
2283 state.rects
<- state.rects1
;
2284 G.postRedisplay "clearrects";
2287 let n = scan args "%u" (fun n -> n) in
2288 state.pagecount
<- n;
2289 begin match state.currently
with
2291 state.currently
<- Idle
;
2292 state.outlines
<- Array.of_list
(List.rev
l)
2296 let cur, cmds
= state.geomcmds
in
2297 if String.length
cur = 0
2298 then failwith
"umpossible";
2300 begin match List.rev cmds
with
2302 state.geomcmds
<- "", [];
2306 state.geomcmds
<- s, List.rev rest
;
2308 if conf.maxwait
= None
2309 then G.postRedisplay "continue";
2319 then showtext ' '
args
2322 Buffer.add_string
state.errmsgs
args;
2323 state.newerrmsgs
<- true;
2324 G.postRedisplay "error message"
2327 let progress, text =
2330 f, String.sub
args pos
(String.length
args - pos
))
2333 state.progress <- progress;
2334 G.postRedisplay "progress"
2337 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2338 scan args "%u %d %f %f %f %f %f %f %f %f"
2339 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2340 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2342 let y = (getpagey pageno) + truncate
y0 in
2345 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2348 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2349 scan args "%u %d %f %f %f %f %f %f %f %f"
2350 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2351 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2354 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2357 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2358 begin match state.currently
with
2359 | Loading
(l, gen
) ->
2360 vlog "page %d took %f sec" l.pageno t
;
2361 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2362 begin match state.throttle
with
2364 let preloadedpages =
2366 then preloadlayout state.y
2371 Set.Make
(struct type t
= int let compare = (-) end) in
2373 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2374 IntSet.empty
preloadedpages
2377 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2378 if not
(IntSet.mem
pageno set)
2380 wcmd "freepage %s" opaque
;
2386 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2389 state.currently
<- Idle
;
2392 tilepage l.pageno pageopaque state.layout;
2394 load preloadedpages;
2395 if pagevisible state.layout l.pageno
2396 && layoutready state.layout
2397 then G.postRedisplay "page";
2400 | Some
(layout, _, _) ->
2401 state.currently
<- Idle
;
2402 tilepage l.pageno pageopaque layout;
2407 dolog "Inconsistent loading state";
2408 logcurrently state.currently
;
2413 let (x, y, opaque
, size
, t
) =
2414 scan args "%u %u %s %u %f"
2415 (fun x y p size t
-> (x, y, p
, size
, t
))
2417 begin match state.currently
with
2418 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2419 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2422 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2424 wcmd "freetile %s" opaque
;
2425 state.currently
<- Idle
;
2429 puttileopaque l col row gen cs angle opaque size t
;
2430 state.memused
<- state.memused
+ size
;
2431 state.uioh#infochanged Memused
;
2433 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2434 opaque
, size
) state.tilelru
;
2437 match state.throttle
with
2438 | None
-> state.layout
2439 | Some
(layout, _, _) -> layout
2442 state.currently
<- Idle
;
2444 && conf.colorspace
= cs
2445 && conf.angle
= angle
2446 && tilevisible layout l.pageno x y
2447 then conttiling l.pageno pageopaque;
2449 begin match state.throttle
with
2452 then state.wthack <- not
(layoutready state.layout);
2453 preload state.layout;
2455 && conf.colorspace
= cs
2456 && conf.angle
= angle
2457 && tilevisible state.layout l.pageno x y
2458 then G.postRedisplay "tile nothrottle";
2460 | Some
(layout, y, _) ->
2461 let ready = layoutready layout in
2464 state.wthack <- false;
2466 state.layout <- layout;
2467 state.throttle
<- None
;
2468 G.postRedisplay "throttle";
2475 dolog "Inconsistent tiling state";
2476 logcurrently state.currently
;
2482 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2484 state.uioh#infochanged Pdim
;
2485 state.pdims
<- pdim :: state.pdims
2488 let (l, n, t
, h, pos
) =
2489 scan args "%u %u %d %u %n"
2490 (fun l n t
h pos
-> l, n, t
, h, pos
)
2492 let s = String.sub
args pos
(String.length
args - pos
) in
2493 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2494 begin match state.currently
with
2495 | Outlining outlines
->
2496 state.currently
<- Outlining
(outline :: outlines
)
2498 state.currently
<- Outlining
[outline]
2500 dolog "invalid outlining state";
2501 logcurrently currently
2506 scan args "%u %u %d" (fun n t
h -> n, t
, h)
2509 if conf.presentation
2511 else float t
/. float h, 0.0
2513 state.anchor <- (n, top, dtop)
2516 state.docinfo
<- (1, args) :: state.docinfo
2519 state.uioh#infochanged Docinfo
;
2520 state.docinfo
<- List.rev
state.docinfo
2523 dolog "unknown cmd `%S'" cmds
2528 let action = function
2529 | HCprev
-> cbget cb ~
-1
2530 | HCnext
-> cbget cb
1
2531 | HCfirst
-> cbget cb ~
-(cb
.rc)
2532 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2533 and cancel
() = cb
.rc <- rc
2537 let search pattern forward
=
2538 if String.length pattern
> 0
2541 match state.layout with
2544 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2546 wcmd "search %d %d %d %d,%s\000"
2547 (btod conf.icase
) pn py
(btod forward
) pattern
;
2550 let intentry text key =
2552 if key >= 32 && key < 127
2558 let text = addchar text c in
2562 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2566 let linknentry text key =
2568 if key >= 32 && key < 127
2574 let text = addchar text c in
2578 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2583 if String.length
s > 0
2586 let l = String.length
s in
2587 let rec loop pos
n = if pos
= l then n else
2588 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2589 loop (pos
+1) (n*26 + m)
2592 let rec loop n = function
2595 match getopaque l.pageno with
2596 | None
-> loop n rest
2598 let m = getlinkcount opaque
in
2601 let under = getlink opaque
n in
2604 else loop (n-m) rest
2606 loop n state.layout;
2610 let textentry text key =
2611 if key land 0xff00 = 0xff00
2613 else TEcont
(text ^
Wsi.toutf8
key)
2616 let reqlayout angle proportional
=
2617 match state.throttle
with
2619 if nogeomcmds state.geomcmds
2620 then state.anchor <- getanchor ();
2621 conf.angle
<- angle
mod 360;
2624 match state.mode
with
2625 | LinkNav
_ -> state.mode
<- View
2628 conf.proportional
<- proportional
;
2629 invalidate "reqlayout"
2630 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2634 let settrim trimmargins trimfuzz
=
2635 if nogeomcmds state.geomcmds
2636 then state.anchor <- getanchor ();
2637 conf.trimmargins
<- trimmargins
;
2638 conf.trimfuzz
<- trimfuzz
;
2639 let x0, y0, x1, y1 = trimfuzz
in
2640 invalidate "settrim"
2642 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2647 match state.throttle
with
2649 let zoom = max
0.01 zoom in
2650 if zoom <> conf.zoom
2652 state.prevzoom
<- conf.zoom;
2654 reshape conf.winw
conf.winh
;
2655 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2658 | Some
(layout, y, started
) ->
2660 match conf.maxwait
with
2664 let dt = now () -. started
in
2672 let setcolumns mode columns coverA coverB
=
2673 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2677 then showtext '
!'
"split mode doesn't work in bird's eye"
2679 conf.columns
<- Csplit
(-columns
, [||]);
2687 conf.columns
<- Csingle
[||];
2692 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2696 reshape conf.winw
conf.winh
;
2699 let enterbirdseye () =
2700 let zoom = float conf.thumbw
/. float conf.winw
in
2701 let birdseyepageno =
2702 let cy = conf.winh
/ 2 in
2706 let rec fold best
= function
2709 let d = cy - (l.pagedispy + l.pagevh/2)
2710 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2711 if abs
d < abs dbest
2718 state.mode
<- Birdseye
(
2719 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2722 conf.presentation
<- false;
2723 conf.interpagespace
<- 10;
2724 conf.hlinks
<- false;
2726 state.mstate
<- Mnone
;
2727 conf.maxwait
<- None
;
2729 match conf.beyecolumns
with
2732 Cmulti
((c, 0, 0), [||])
2733 | None
-> Csingle
[||]
2735 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2738 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2743 reshape conf.winw
conf.winh
;
2746 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2748 conf.zoom <- c.zoom;
2749 conf.presentation
<- c.presentation
;
2750 conf.interpagespace
<- c.interpagespace
;
2751 conf.maxwait
<- c.maxwait
;
2752 conf.hlinks
<- c.hlinks
;
2753 conf.beyecolumns
<- (
2754 match conf.columns
with
2755 | Cmulti
((c, _, _), _) -> Some
c
2757 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2760 match c.columns
with
2761 | Cmulti
(c, _) -> Cmulti
(c, [||])
2762 | Csingle
_ -> Csingle
[||]
2763 | Csplit
(c, _) -> Csplit
(c, [||])
2768 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2771 reshape conf.winw
conf.winh
;
2772 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2775 let togglebirdseye () =
2776 match state.mode
with
2777 | Birdseye vals
-> leavebirdseye vals
true
2778 | View
-> enterbirdseye ()
2782 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2783 let pageno = max
0 (pageno - incr
) in
2784 let rec loop = function
2785 | [] -> gotopage1 pageno 0
2786 | l :: _ when l.pageno = pageno ->
2787 if l.pagedispy >= 0 && l.pagey = 0
2788 then G.postRedisplay "upbirdseye"
2789 else gotopage1 pageno 0
2790 | _ :: rest
-> loop rest
2793 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2796 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2797 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2798 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2799 let rec loop = function
2801 let y, h = getpageyh pageno in
2802 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2804 | l :: _ when l.pageno = pageno ->
2805 if l.pagevh != l.pageh
2806 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2807 else G.postRedisplay "downbirdseye"
2808 | _ :: rest
-> loop rest
2813 let optentry mode
_ key =
2814 let btos b = if b then "on" else "off" in
2815 if key >= 32 && key < 127
2817 let c = Char.chr
key in
2821 try conf.scrollstep
<- int_of_string
s with exc
->
2822 state.text <- Printf.sprintf
"bad integer `%s': %s"
2823 s (Printexc.to_string exc
)
2825 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2830 conf.autoscrollstep
<- int_of_string
s;
2831 if state.autoscroll
<> None
2832 then state.autoscroll
<- Some
conf.autoscrollstep
2834 state.text <- Printf.sprintf
"bad integer `%s': %s"
2835 s (Printexc.to_string exc
)
2837 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2842 let n, a, b = multicolumns_of_string s in
2843 setcolumns mode
n a b;
2845 state.text <- Printf.sprintf
"bad columns `%s': %s"
2846 s (Printexc.to_string exc
)
2848 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2853 let zoom = float (int_of_string
s) /. 100.0 in
2856 state.text <- Printf.sprintf
"bad integer `%s': %s"
2857 s (Printexc.to_string exc
)
2859 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2864 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2866 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2867 begin match mode
with
2869 leavebirdseye beye
false;
2874 state.text <- Printf.sprintf
"bad integer `%s': %s"
2875 s (Printexc.to_string exc
)
2877 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2882 Some
(int_of_string
s)
2884 state.text <- Printf.sprintf
"bad integer `%s': %s"
2885 s (Printexc.to_string exc
);
2888 | Some angle
-> reqlayout angle
conf.proportional
2891 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2894 conf.icase
<- not
conf.icase
;
2895 TEdone
("case insensitive search " ^
(btos conf.icase
))
2898 conf.preload <- not
conf.preload;
2900 TEdone
("preload " ^
(btos conf.preload))
2903 conf.verbose
<- not
conf.verbose
;
2904 TEdone
("verbose " ^
(btos conf.verbose
))
2907 conf.debug
<- not
conf.debug
;
2908 TEdone
("debug " ^
(btos conf.debug
))
2911 conf.maxhfit
<- not
conf.maxhfit
;
2912 state.maxy
<- calcheight ();
2913 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2916 conf.crophack
<- not
conf.crophack
;
2917 TEdone
("crophack " ^
btos conf.crophack
)
2921 match conf.maxwait
with
2923 conf.maxwait
<- Some infinity
;
2924 "always wait for page to complete"
2926 conf.maxwait
<- None
;
2927 "show placeholder if page is not ready"
2932 conf.underinfo
<- not
conf.underinfo
;
2933 TEdone
("underinfo " ^
btos conf.underinfo
)
2936 conf.savebmarks
<- not
conf.savebmarks
;
2937 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2943 match state.layout with
2948 conf.interpagespace
<- int_of_string
s;
2949 docolumns conf.columns
;
2950 state.maxy
<- calcheight ();
2951 let y = getpagey pageno in
2954 state.text <- Printf.sprintf
"bad integer `%s': %s"
2955 s (Printexc.to_string exc
)
2957 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2960 reqlayout conf.angle
(not
conf.proportional
);
2961 TEdone
("proportional display " ^
btos conf.proportional
)
2964 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2965 TEdone
("trim margins " ^
btos conf.trimmargins
)
2968 conf.invert
<- not
conf.invert
;
2969 TEdone
("invert colors " ^
btos conf.invert
)
2973 cbput state.hists
.sel
s;
2976 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2977 textentry, ondone, true)
2980 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2986 class type lvsource
= object
2987 method getitemcount
: int
2988 method getitem
: int -> (string * int)
2989 method hasaction
: int -> bool
2998 method getactive
: int
2999 method getfirst
: int
3000 method getqsearch
: string
3001 method setqsearch
: string -> unit
3005 class virtual lvsourcebase
= object
3006 val mutable m_active
= 0
3007 val mutable m_first
= 0
3008 val mutable m_qsearch
= ""
3009 val mutable m_pan
= 0
3010 method getactive
= m_active
3011 method getfirst
= m_first
3012 method getqsearch
= m_qsearch
3013 method getpan
= m_pan
3014 method setqsearch
s = m_qsearch
<- s
3017 let withoutlastutf8 s =
3018 let len = String.length
s in
3026 let b = Char.code
s.[pos
] in
3027 if b land 0b11000000 = 0b11000000
3032 if Char.code
s.[len-1] land 0x80 = 0
3036 String.sub
s 0 first;
3039 let textentrykeyboard
3040 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3042 if key >= 0xffb0 && key <= 0xffb9
3043 then key - 0xffb0 + 48 else key
3046 state.mode
<- Textentry
(te
, onleave
);
3049 G.postRedisplay "textentrykeyboard enttext";
3051 let histaction cmd
=
3054 | Some
(action, _) ->
3055 state.mode
<- Textentry
(
3056 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3058 G.postRedisplay "textentry histaction"
3061 | 0xff08 -> (* backspace *)
3062 let s = withoutlastutf8 text in
3063 let len = String.length
s in
3064 if cancelonempty
&& len = 0
3067 G.postRedisplay "textentrykeyboard after cancel";
3070 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3073 | 0xff0d | 0xff8d -> (* (kp) enter *)
3076 G.postRedisplay "textentrykeyboard after confirm"
3078 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3079 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3080 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3081 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3083 | 0xff1b -> (* escape*)
3084 if String.length
text = 0
3086 begin match opthist
with
3088 | Some
(_, onhistcancel
) -> onhistcancel
()
3092 G.postRedisplay "textentrykeyboard after cancel2"
3095 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3098 | 0xff9f | 0xffff -> () (* delete *)
3101 && key land 0xff00 != 0xff00 (* keyboard *)
3102 && key land 0xfe00 != 0xfe00 (* xkb *)
3103 && key land 0xfd00 != 0xfd00 (* 3270 *)
3105 begin match onkey
text key with
3109 G.postRedisplay "textentrykeyboard after confirm2";
3112 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3116 G.postRedisplay "textentrykeyboard after cancel3"
3119 state.mode
<- Textentry
(te
, onleave
);
3120 G.postRedisplay "textentrykeyboard switch";
3124 vlog "unhandled key %s" (Wsi.keyname
key)
3127 let firstof first active
=
3128 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3129 then max
0 (active
- (fstate.maxrows
/2))
3133 let calcfirst first active
=
3136 let rows = active
- first in
3137 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3141 let scrollph y maxy
=
3142 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3143 let sh = float conf.winh
/. sh in
3144 let sh = max
sh (float conf.scrollh
) in
3149 else float y /. float maxy
3151 let position = (float conf.winh
-. sh) *. percent in
3154 if position +. sh > float conf.winh
3155 then float conf.winh
-. sh
3161 let coe s = (s :> uioh
);;
3163 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3165 val m_pan
= source#getpan
3166 val m_first
= source#getfirst
3167 val m_active
= source#getactive
3168 val m_qsearch
= source#getqsearch
3169 val m_prev_uioh
= state.uioh
3171 method private elemunder
y =
3172 let n = y / (fstate.fontsize
+1) in
3173 if m_first
+ n < source#getitemcount
3175 if source#hasaction
(m_first
+ n)
3176 then Some
(m_first
+ n)
3183 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3184 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3185 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3186 GlDraw.color
(1., 1., 1.);
3187 Gl.enable `texture_2d
;
3188 let fs = fstate.fontsize
in
3190 let ww = fstate.wwidth
in
3191 let tabw = 30.0*.ww in
3192 let itemcount = source#getitemcount
in
3194 if (row - m_first
) > fstate.maxrows
3197 if row >= 0 && row < itemcount
3199 let (s, level
) = source#getitem
row in
3200 let y = (row - m_first
) * nfs in
3201 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3204 Gl.disable `texture_2d
;
3205 GlDraw.polygon_mode `both `line
;
3206 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3207 GlDraw.rect (1., float (y + 1))
3208 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3209 GlDraw.polygon_mode `both `fill
;
3210 GlDraw.color
(1., 1., 1.);
3211 Gl.enable `texture_2d
;
3214 let drawtabularstring s =
3215 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3218 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3221 let len = String.length
s - tabpos - 1 in
3222 let s1 = String.sub
s 0 tabpos
3223 and s2
= String.sub
s (tabpos + 1) len in
3224 let nx = drawstr x s1 in
3226 let x = x +. (max
tabw sw) in
3233 let _ = drawtabularstring s in
3240 Gl.disable `texture_2d
;
3242 method updownlevel incr
=
3243 let len = source#getitemcount
in
3245 if m_active
>= 0 && m_active
< len
3246 then snd
(source#getitem m_active
)
3250 if i
= len then i
-1 else if i
= -1 then 0 else
3251 let _, l = source#getitem i
in
3252 if l != curlevel then i
else flow (i
+incr
)
3254 let active = flow m_active
in
3255 let first = calcfirst m_first
active in
3256 G.postRedisplay "outline updownlevel";
3257 {< m_active
= active; m_first
= first >}
3259 method private key1
key mask
=
3260 let set1 active first qsearch
=
3261 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3263 let search active pattern incr
=
3266 if n >= 0 && n < source#getitemcount
3268 let s, _ = source#getitem
n in
3270 (try ignore
(Str.search_forward
re s 0); true
3271 with Not_found
-> false)
3273 else loop (n + incr
)
3280 let re = Str.regexp_case_fold pattern
in
3286 let itemcount = source#getitemcount
in
3287 let find start incr
=
3289 if i
= -1 || i
= itemcount
3292 if source#hasaction i
3294 else find (i
+ incr
)
3299 let set active first =
3300 let first = bound first 0 (itemcount - fstate.maxrows
) in
3302 coe {< m_active
= active; m_first
= first >}
3305 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3307 let incr1 = if incr
> 0 then 1 else -1 in
3308 if isvisible m_first m_active
3311 let next = m_active
+ incr
in
3313 if next < 0 || next >= itemcount
3315 else find next incr1
3317 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3323 let first = m_first
+ incr
in
3324 let first = bound first 0 (itemcount - 1) in
3326 let next = m_active
+ incr
in
3327 let next = bound next 0 (itemcount - 1) in
3330 let active = if next = -1 then m_active
else next in
3333 let first = min
next m_first
in
3335 if abs
(next - first) > fstate.maxrows
3341 let first = m_first
+ incr
in
3342 let first = bound first 0 (itemcount - 1) in
3344 let next = m_active
+ incr
in
3345 let next = bound next 0 (itemcount - 1) in
3346 let next = find next incr1 in
3348 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3350 let active = if m_active
= -1 then next else m_active
in
3355 if isvisible first active
3361 G.postRedisplay "listview navigate";
3365 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3366 let incr = if key = 0x72 then -1 else 1 in
3368 match search (m_active
+ incr) m_qsearch
incr with
3370 state.text <- m_qsearch ^
" [not found]";
3373 state.text <- m_qsearch
;
3374 active, firstof m_first
active
3376 G.postRedisplay "listview ctrl-r/s";
3377 set1 active first m_qsearch
;
3379 | 0xff08 -> (* backspace *)
3380 if String.length m_qsearch
= 0
3383 let qsearch = withoutlastutf8 m_qsearch
in
3384 let len = String.length
qsearch in
3388 G.postRedisplay "listview empty qsearch";
3389 set1 m_active m_first
"";
3393 match search m_active
qsearch ~
-1 with
3395 state.text <- qsearch ^
" [not found]";
3398 state.text <- qsearch;
3399 active, firstof m_first
active
3401 G.postRedisplay "listview backspace qsearch";
3402 set1 active first qsearch
3405 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3406 let pattern = m_qsearch ^
Wsi.toutf8
key in
3408 match search m_active
pattern 1 with
3410 state.text <- pattern ^
" [not found]";
3413 state.text <- pattern;
3414 active, firstof m_first
active
3416 G.postRedisplay "listview qsearch add";
3417 set1 active first pattern;
3419 | 0xff1b -> (* escape *)
3421 if String.length m_qsearch
= 0
3423 G.postRedisplay "list view escape";
3426 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3428 | None
-> m_prev_uioh
3433 G.postRedisplay "list view kill qsearch";
3434 source#setqsearch
"";
3435 coe {< m_qsearch
= "" >}
3438 | 0xff0d | 0xff8d -> (* (kp) enter *)
3440 let self = {< m_qsearch
= "" >} in
3441 source#setqsearch
"";
3443 G.postRedisplay "listview enter";
3444 if m_active
>= 0 && m_active
< source#getitemcount
3446 source#exit
(coe self) false m_active m_first m_pan
"";
3449 source#exit
(coe self) true m_active m_first m_pan
"";
3452 begin match opt with
3453 | None
-> m_prev_uioh
3457 | 0xff9f | 0xffff -> (* (kp) delete *)
3460 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3461 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3462 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3463 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3465 | 0xff53 | 0xff98 -> (* (kp) right *)
3467 G.postRedisplay "listview right";
3468 coe {< m_pan
= m_pan
- 1 >}
3470 | 0xff51 | 0xff96 -> (* (kp) left *)
3472 G.postRedisplay "listview left";
3473 coe {< m_pan
= m_pan
+ 1 >}
3475 | 0xff50 | 0xff95 -> (* (kp) home *)
3476 let active = find 0 1 in
3477 G.postRedisplay "listview home";
3480 | 0xff57 | 0xff9c -> (* (kp) end *)
3481 let first = max
0 (itemcount - fstate.maxrows
) in
3482 let active = find (itemcount - 1) ~
-1 in
3483 G.postRedisplay "listview end";
3486 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3490 dolog "listview unknown key %#x" key; coe self
3492 method key key mask
=
3493 match state.mode
with
3494 | Textentry te
-> textentrykeyboard key mask te
; coe self
3495 | _ -> self#key1
key mask
3497 method button button down
x y _ =
3500 | 1 when x > conf.winw
- conf.scrollbw
->
3501 G.postRedisplay "listview scroll";
3504 let _, position, sh = self#
scrollph in
3505 if y > truncate
position && y < truncate
(position +. sh)
3507 state.mstate
<- Mscrolly
;
3511 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3512 let first = truncate
(s *. float source#getitemcount
) in
3513 let first = min source#getitemcount
first in
3514 Some
(coe {< m_first
= first; m_active
= first >})
3516 state.mstate
<- Mnone
;
3519 | 1 when not down
->
3520 begin match self#elemunder
y with
3522 G.postRedisplay "listview click";
3524 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3528 | n when (n == 4 || n == 5) && not down
->
3529 let len = source#getitemcount
in
3531 if n = 5 && m_first
+ fstate.maxrows
>= len
3535 let first = m_first
+ (if n == 4 then -1 else 1) in
3536 bound first 0 (len - 1)
3538 G.postRedisplay "listview wheel";
3539 Some
(coe {< m_first
= first >})
3540 | n when (n = 6 || n = 7) && not down
->
3541 let inc = m_first
+ (if n = 7 then -1 else 1) in
3542 G.postRedisplay "listview hwheel";
3543 Some
(coe {< m_pan
= m_pan
+ inc >})
3548 | None
-> m_prev_uioh
3552 match state.mstate
with
3554 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3555 let first = truncate
(s *. float source#getitemcount
) in
3556 let first = min source#getitemcount
first in
3557 G.postRedisplay "listview motion";
3558 coe {< m_first
= first; m_active
= first >}
3561 method pmotion
x y =
3562 if x < conf.winw
- conf.scrollbw
3565 match self#elemunder
y with
3566 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3567 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3571 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3576 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3580 method infochanged
_ = ()
3582 method scrollpw
= (0, 0.0, 0.0)
3584 let nfs = fstate.fontsize
+ 1 in
3585 let y = m_first
* nfs in
3586 let itemcount = source#getitemcount
in
3587 let maxi = max
0 (itemcount - fstate.maxrows
) in
3588 let maxy = maxi * nfs in
3589 let p, h = scrollph y maxy in
3592 method modehash
= modehash
3595 class outlinelistview ~source
=
3598 ~source
:(source
:> lvsource
)
3600 ~modehash
:(findkeyhash conf "outline")
3603 method key key mask
=
3604 let calcfirst first active =
3607 let rows = active - first in
3609 if String.length
state.text = 0
3611 else fstate.maxrows - 2
3613 if rows > maxrows then active - maxrows else first
3617 let active = m_active
+ incr in
3618 let active = bound active 0 (source#getitemcount
- 1) in
3619 let first = calcfirst m_first
active in
3620 G.postRedisplay "outline navigate";
3621 coe {< m_active
= active; m_first
= first >}
3623 let ctrl = Wsi.withctrl mask
in
3625 | 110 when ctrl -> (* ctrl-n *)
3626 source#narrow m_qsearch
;
3627 G.postRedisplay "outline ctrl-n";
3628 coe {< m_first
= 0; m_active
= 0 >}
3630 | 117 when ctrl -> (* ctrl-u *)
3632 G.postRedisplay "outline ctrl-u";
3634 coe {< m_first
= 0; m_active
= 0 >}
3636 | 108 when ctrl -> (* ctrl-l *)
3637 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3638 G.postRedisplay "outline ctrl-l";
3639 coe {< m_first
= first >}
3641 | 0xff9f | 0xffff -> (* (kp) delete *)
3642 source#remove m_active
;
3643 G.postRedisplay "outline delete";
3644 let active = max
0 (m_active
-1) in
3645 coe {< m_first
= firstof m_first
active;
3646 m_active
= active >}
3648 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3649 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3650 | 0xff55 | 0xff9a -> (* (kp) prior *)
3651 navigate ~
-(fstate.maxrows)
3652 | 0xff56 | 0xff9b -> (* (kp) next *)
3653 navigate fstate.maxrows
3655 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3659 G.postRedisplay "outline ctrl right";
3660 {< m_pan
= m_pan
+ 1 >}
3662 else self#updownlevel
1
3666 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3670 G.postRedisplay "outline ctrl left";
3671 {< m_pan
= m_pan
- 1 >}
3673 else self#updownlevel ~
-1
3677 | 0xff50 | 0xff95 -> (* (kp) home *)
3678 G.postRedisplay "outline home";
3679 coe {< m_first
= 0; m_active
= 0 >}
3681 | 0xff57 | 0xff9c -> (* (kp) end *)
3682 let active = source#getitemcount
- 1 in
3683 let first = max
0 (active - fstate.maxrows) in
3684 G.postRedisplay "outline end";
3685 coe {< m_active
= active; m_first
= first >}
3687 | _ -> super#
key key mask
3690 let outlinesource usebookmarks
=
3693 inherit lvsourcebase
3694 val mutable m_items
= empty
3695 val mutable m_orig_items
= empty
3696 val mutable m_prev_items
= empty
3697 val mutable m_narrow_pattern
= ""
3698 val mutable m_hadremovals
= false
3700 method getitemcount
=
3701 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3704 if n == Array.length m_items
&& m_hadremovals
3706 ("[Confirm removal]", 0)
3708 let s, n, _ = m_items
.(n) in
3711 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3712 ignore
(uioh
, first, qsearch);
3713 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3715 if String.length m_narrow_pattern
= 0
3721 if not
confrimremoval
3723 let _, _, anchor = m_items
.(active) in
3724 gotoghyll (getanchory anchor);
3728 state.bookmarks
<- Array.to_list m_items
;
3729 m_orig_items
<- m_items
;
3732 else m_items
<- items;
3736 method hasaction
_ = true
3739 if Array.length m_items
!= Array.length m_orig_items
3740 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3743 method narrow
pattern =
3744 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3748 let rec loop accu n =
3751 m_narrow_pattern
<- pattern;
3752 m_items
<- Array.of_list
accu
3755 let (s, _, _) as o = m_items
.(n) in
3757 if (try ignore
(Str.search_forward
re s 0); true
3758 with Not_found
-> false)
3764 loop [] (Array.length m_items
- 1)
3769 then Array.of_list
state.bookmarks
3772 m_items
<- m_orig_items
3777 if m >= 0 && m < Array.length m_items
3779 m_hadremovals
<- true;
3780 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3781 let n = if n >= m then n+1 else n in
3786 method reset
anchor items =
3787 m_hadremovals
<- false;
3788 if m_orig_items
== empty || m_prev_items
!= items
3790 m_orig_items
<- items;
3791 if String.length m_narrow_pattern
= 0
3792 then m_items
<- items;
3794 m_prev_items
<- items;
3795 let rely = getanchory anchor in
3797 let rec loop n best bestd
=
3798 if n = Array.length m_items
3801 let (_, _, anchor) = m_items
.(n) in
3802 let orely = getanchory anchor in
3803 let d = abs
(orely - rely) in
3806 else loop (n+1) best bestd
3811 m_first
<- firstof m_first
active
3815 let enterselector usebookmarks
=
3816 let source = outlinesource usebookmarks
in
3820 then Array.of_list
state.bookmarks
3823 if Array.length
outlines = 0
3825 showtext ' ' errmsg
;
3828 state.text <- source#greetmsg
;
3829 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3830 let anchor = getanchor () in
3831 source#reset
anchor outlines;
3832 state.uioh
<- coe (new outlinelistview ~
source);
3833 G.postRedisplay "enter selector";
3837 let enteroutlinemode =
3838 let f = enterselector false in
3839 fun ()-> f "Document has no outline";
3842 let enterbookmarkmode =
3843 let f = enterselector true in
3844 fun () -> f "Document has no bookmarks (yet)";
3847 let color_of_string s =
3848 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
3849 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
3853 let color_to_string (r, g, b) =
3854 let r = truncate
(r *. 256.0)
3855 and g = truncate
(g *. 256.0)
3856 and b = truncate
(b *. 256.0) in
3857 Printf.sprintf
"%d/%d/%d" r g b
3860 let irect_of_string s =
3861 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3864 let irect_to_string (x0,y0,x1,y1) =
3865 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3868 let makecheckers () =
3869 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3871 converted by Issac Trotts. July 25, 2002 *)
3872 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3873 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3874 let id = GlTex.gen_texture
() in
3875 GlTex.bind_texture `texture_2d
id;
3876 GlPix.store
(`unpack_alignment
1);
3877 GlTex.image2d
image;
3878 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3879 [ `mag_filter `nearest
; `min_filter `nearest
];
3883 let setcheckers enabled
=
3884 match state.texid
with
3886 if enabled
then state.texid
<- Some
(makecheckers ())
3891 GlTex.delete_texture texid
;
3892 state.texid
<- None
;
3896 let int_of_string_with_suffix s =
3897 let l = String.length
s in
3901 let suffix = Char.lowercase
s.[l-1] in
3903 | 'k'
-> String.sub
s 0 (l-1), 10
3904 | '
m'
-> String.sub
s 0 (l-1), 20
3905 | '
g'
-> String.sub
s 0 (l-1), 30
3909 let n = int_of_string
s1 in
3910 let m = n lsl shift
in
3912 then raise
(Failure
"value too large")
3916 let string_with_suffix_of_int n =
3921 if n land ((1 lsl 30) - 1) = 0
3924 if n land ((1 lsl 20) - 1) = 0
3927 if n land ((1 lsl 10) - 1) = 0
3934 let h = n mod 1000 in
3937 then string_of_int
h ^
s
3939 let s = Printf.sprintf
"_%03d%s" h s in
3946 let defghyllscroll = (40, 8, 32);;
3947 let ghyllscroll_of_string s =
3948 let (n, a, b) as nab
=
3951 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3953 if n <= a || n <= b || a >= b
3954 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3958 let ghyllscroll_to_string ((n, a, b) as nab
) =
3959 if nab
= defghyllscroll
3961 else Printf.sprintf
"%d,%d,%d" n a b;
3964 let describe_location () =
3966 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3968 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3969 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3973 else (100. *. (float state.y /. float maxy))
3977 Printf.sprintf
"page %d of %d [%.2f%%]"
3978 (fn+1) state.pagecount
percent
3981 "pages %d-%d of %d [%.2f%%]"
3982 (fn+1) (ln
+1) state.pagecount
percent
3985 let setpresentationmode v
=
3986 let (n, _, _) = getanchor () in
3987 let _, h = getpageyh n in
3988 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
3989 state.anchor <- (n, 0.0, float ips);
3990 conf.presentation
<- v
;
3991 if conf.presentation
3993 if not
conf.scrollbarinpm
3994 then state.scrollw
<- 0;
3996 else state.scrollw
<- conf.scrollbw
;
4001 let btos b = if b then "\xe2\x88\x9a" else "" in
4002 let showextended = ref false in
4003 let leave mode
= function
4004 | Confirm
-> state.mode
<- mode
4005 | Cancel
-> state.mode
<- mode
in
4008 val mutable m_first_time
= true
4009 val mutable m_l
= []
4010 val mutable m_a
= [||]
4011 val mutable m_prev_uioh
= nouioh
4012 val mutable m_prev_mode
= View
4014 inherit lvsourcebase
4016 method reset prev_mode prev_uioh
=
4017 m_a
<- Array.of_list
(List.rev m_l
);
4019 m_prev_mode
<- prev_mode
;
4020 m_prev_uioh
<- prev_uioh
;
4024 if n >= Array.length m_a
4028 | _, _, _, Action
_ -> m_active
<- n
4032 m_first_time
<- false;
4035 method int name get
set =
4037 (name
, `
int get
, 1, Action
(
4040 try set (int_of_string
s)
4042 state.text <- Printf.sprintf
"bad integer `%s': %s"
4043 s (Printexc.to_string exn
)
4046 let te = name ^
": ", "", None
, intentry, ondone, true in
4047 state.mode
<- Textentry
(te, leave m_prev_mode
);
4051 method int_with_suffix name get
set =
4053 (name
, `intws get
, 1, Action
(
4056 try set (int_of_string_with_suffix s)
4058 state.text <- Printf.sprintf
"bad integer `%s': %s"
4059 s (Printexc.to_string exn
)
4063 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4065 state.mode
<- Textentry
(te, leave m_prev_mode
);
4069 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4071 (name
, `
bool (btos, get
), offset
, Action
(
4078 method color name get
set =
4080 (name
, `color get
, 1, Action
(
4082 let invalid = (nan
, nan
, nan
) in
4085 try color_of_string s
4087 state.text <- Printf.sprintf
"bad color `%s': %s"
4088 s (Printexc.to_string exn
);
4094 let te = name ^
": ", "", None
, textentry, ondone, true in
4095 state.text <- color_to_string (get
());
4096 state.mode
<- Textentry
(te, leave m_prev_mode
);
4100 method string name get
set =
4102 (name
, `
string get
, 1, Action
(
4104 let ondone s = set s in
4105 let te = name ^
": ", "", None
, textentry, ondone, true in
4106 state.mode
<- Textentry
(te, leave m_prev_mode
);
4110 method colorspace name get
set =
4112 (name
, `
string get
, 1, Action
(
4115 let vals = [| "rgb"; "bgr"; "gray" |] in
4117 inherit lvsourcebase
4120 m_active
<- int_of_colorspace conf.colorspace
;
4123 method getitemcount
= Array.length
vals
4124 method getitem
n = (vals.(n), 0)
4125 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4126 ignore
(uioh
, first, pan
, qsearch);
4127 if not cancel
then set active;
4129 method hasaction
_ = true
4133 let modehash = findkeyhash conf "info" in
4134 coe (new listview ~
source ~trusted
:true ~
modehash)
4137 method caption
s offset
=
4138 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4140 method caption2
s f offset
=
4141 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4143 method getitemcount
= Array.length m_a
4146 let tostr = function
4147 | `
int f -> string_of_int
(f ())
4148 | `intws
f -> string_with_suffix_of_int (f ())
4150 | `color
f -> color_to_string (f ())
4151 | `
bool (btos, f) -> btos (f ())
4154 let name, t
, offset
, _ = m_a
.(n) in
4155 ((let s = tostr t
in
4156 if String.length
s > 0
4157 then Printf.sprintf
"%s\t%s" name s
4161 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4165 m_qsearch
<- qsearch;
4167 match m_a
.(active) with
4168 | _, _, _, Action
f -> f uioh
4180 method hasaction
n =
4182 | _, _, _, Action
_ -> true
4186 let rec fillsrc prevmode prevuioh
=
4187 let sep () = src#caption
"" 0 in
4188 let colorp name get
set =
4190 (fun () -> color_to_string (get
()))
4193 let c = color_of_string v in
4196 state.text <- Printf.sprintf
"bad color `%s': %s"
4197 v (Printexc.to_string exn
);
4200 let oldmode = state.mode
in
4201 let birdseye = isbirdseye state.mode
in
4203 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4205 src#
bool "presentation mode"
4206 (fun () -> conf.presentation
)
4207 (fun v -> setpresentationmode v);
4209 src#
bool "ignore case in searches"
4210 (fun () -> conf.icase
)
4211 (fun v -> conf.icase
<- v);
4214 (fun () -> conf.preload)
4215 (fun v -> conf.preload <- v);
4217 src#
bool "highlight links"
4218 (fun () -> conf.hlinks
)
4219 (fun v -> conf.hlinks
<- v);
4221 src#
bool "under info"
4222 (fun () -> conf.underinfo
)
4223 (fun v -> conf.underinfo
<- v);
4225 src#
bool "persistent bookmarks"
4226 (fun () -> conf.savebmarks
)
4227 (fun v -> conf.savebmarks
<- v);
4229 src#
bool "proportional display"
4230 (fun () -> conf.proportional
)
4231 (fun v -> reqlayout conf.angle
v);
4233 src#
bool "trim margins"
4234 (fun () -> conf.trimmargins
)
4235 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4237 src#
bool "persistent location"
4238 (fun () -> conf.jumpback
)
4239 (fun v -> conf.jumpback
<- v);
4242 src#
int "inter-page space"
4243 (fun () -> conf.interpagespace
)
4245 conf.interpagespace
<- n;
4246 docolumns conf.columns
;
4248 match state.layout with
4253 state.maxy <- calcheight ();
4254 let y = getpagey pageno in
4259 (fun () -> conf.pagebias
)
4260 (fun v -> conf.pagebias
<- v);
4262 src#
int "scroll step"
4263 (fun () -> conf.scrollstep
)
4264 (fun n -> conf.scrollstep
<- n);
4266 src#
int "horizontal scroll step"
4267 (fun () -> conf.hscrollstep
)
4268 (fun v -> conf.hscrollstep
<- v);
4270 src#
int "auto scroll step"
4272 match state.autoscroll
with
4274 | _ -> conf.autoscrollstep
)
4276 if state.autoscroll
<> None
4277 then state.autoscroll
<- Some
n;
4278 conf.autoscrollstep
<- n);
4281 (fun () -> truncate
(conf.zoom *. 100.))
4282 (fun v -> setzoom ((float v) /. 100.));
4285 (fun () -> conf.angle
)
4286 (fun v -> reqlayout v conf.proportional
);
4288 src#
int "scroll bar width"
4289 (fun () -> state.scrollw
)
4293 reshape conf.winw
conf.winh
;
4296 src#
int "scroll handle height"
4297 (fun () -> conf.scrollh
)
4298 (fun v -> conf.scrollh
<- v;);
4300 src#
int "thumbnail width"
4301 (fun () -> conf.thumbw
)
4303 conf.thumbw
<- min
4096 v;
4306 leavebirdseye beye
false;
4311 let mode = state.mode in
4312 src#
string "columns"
4314 match conf.columns
with
4316 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4317 | Csplit
(count
, _) -> "-" ^ string_of_int count
4320 let n, a, b = multicolumns_of_string v in
4321 setcolumns mode n a b);
4324 src#caption
"Presentation mode" 0;
4325 src#
bool "scrollbar visible"
4326 (fun () -> conf.scrollbarinpm
)
4328 if v != conf.scrollbarinpm
4330 conf.scrollbarinpm
<- v;
4331 if conf.presentation
4333 state.scrollw
<- if v then conf.scrollbw
else 0;
4334 reshape conf.winw
conf.winh
;
4340 src#caption
"Pixmap cache" 0;
4341 src#int_with_suffix
"size (advisory)"
4342 (fun () -> conf.memlimit
)
4343 (fun v -> conf.memlimit
<- v);
4346 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4347 (string_with_suffix_of_int state.memused
)
4348 (Hashtbl.length
state.tilemap
)) 1;
4351 src#caption
"Layout" 0;
4352 src#caption2
"Dimension"
4354 Printf.sprintf
"%dx%d (virtual %dx%d)"
4360 src#caption2
"Position" (fun () ->
4361 Printf.sprintf
"%dx%d" state.x state.y
4364 src#caption2
"Visible" (fun () -> describe_location ()) 1
4368 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4369 "Save these parameters as global defaults at exit"
4370 (fun () -> conf.bedefault
)
4371 (fun v -> conf.bedefault
<- v)
4375 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4376 src#
bool ~offset
:0 ~
btos "Extended parameters"
4377 (fun () -> !showextended)
4378 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4382 (fun () -> conf.checkers
)
4383 (fun v -> conf.checkers
<- v; setcheckers v);
4384 src#
bool "update cursor"
4385 (fun () -> conf.updatecurs
)
4386 (fun v -> conf.updatecurs
<- v);
4388 (fun () -> conf.verbose
)
4389 (fun v -> conf.verbose
<- v);
4390 src#
bool "invert colors"
4391 (fun () -> conf.invert
)
4392 (fun v -> conf.invert
<- v);
4394 (fun () -> conf.maxhfit
)
4395 (fun v -> conf.maxhfit
<- v);
4396 src#
bool "redirect stderr"
4397 (fun () -> conf.redirectstderr)
4398 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4399 src#
string "uri launcher"
4400 (fun () -> conf.urilauncher
)
4401 (fun v -> conf.urilauncher
<- v);
4402 src#
string "path launcher"
4403 (fun () -> conf.pathlauncher
)
4404 (fun v -> conf.pathlauncher
<- v);
4405 src#
string "tile size"
4406 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4409 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4410 conf.tilew
<- max
64 w;
4411 conf.tileh
<- max
64 h;
4414 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4415 v (Printexc.to_string exn
));
4416 src#
int "texture count"
4417 (fun () -> conf.texcount
)
4420 then conf.texcount
<- v
4421 else showtext '
!'
" Failed to set texture count please retry later"
4423 src#
int "slice height"
4424 (fun () -> conf.sliceheight
)
4426 conf.sliceheight
<- v;
4427 wcmd "sliceh %d" conf.sliceheight
;
4429 src#
int "anti-aliasing level"
4430 (fun () -> conf.aalevel
)
4432 conf.aalevel
<- bound v 0 8;
4433 state.anchor <- getanchor ();
4434 opendoc state.path
state.password
;
4436 src#
string "page scroll scaling factor"
4437 (fun () -> string_of_float
conf.pgscale)
4440 let s = float_of_string
v in
4443 state.text <- Printf.sprintf
4444 "bad page scroll scaling factor `%s': %s"
4445 v (Printexc.to_string exn
)
4448 src#
int "ui font size"
4449 (fun () -> fstate.fontsize
)
4450 (fun v -> setfontsize (bound v 5 100));
4451 src#
int "hint font size"
4452 (fun () -> conf.hfsize
)
4453 (fun v -> conf.hfsize
<- bound v 5 100);
4454 colorp "background color"
4455 (fun () -> conf.bgcolor
)
4456 (fun v -> conf.bgcolor
<- v);
4457 src#
bool "crop hack"
4458 (fun () -> conf.crophack
)
4459 (fun v -> conf.crophack
<- v);
4460 src#
string "trim fuzz"
4461 (fun () -> irect_to_string conf.trimfuzz
)
4464 conf.trimfuzz
<- irect_of_string v;
4466 then settrim true conf.trimfuzz
;
4468 state.text <- Printf.sprintf
"bad irect `%s': %s"
4469 v (Printexc.to_string exn
)
4471 src#
string "throttle"
4473 match conf.maxwait
with
4474 | None
-> "show place holder if page is not ready"
4477 then "wait for page to fully render"
4479 "wait " ^ string_of_float
time
4480 ^
" seconds before showing placeholder"
4484 let f = float_of_string
v in
4486 then conf.maxwait
<- None
4487 else conf.maxwait
<- Some
f
4489 state.text <- Printf.sprintf
"bad time `%s': %s"
4490 v (Printexc.to_string exn
)
4492 src#
string "ghyll scroll"
4494 match conf.ghyllscroll
with
4496 | Some nab
-> ghyllscroll_to_string nab
4501 if String.length
v = 0
4503 else Some
(ghyllscroll_of_string v)
4505 conf.ghyllscroll
<- gs
4507 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4508 v (Printexc.to_string exn
)
4510 src#
string "selection command"
4511 (fun () -> conf.selcmd
)
4512 (fun v -> conf.selcmd
<- v);
4513 src#
string "synctex command"
4514 (fun () -> conf.stcmd
)
4515 (fun v -> conf.stcmd
<- v);
4516 src#colorspace
"color space"
4517 (fun () -> colorspace_to_string conf.colorspace
)
4519 conf.colorspace
<- colorspace_of_int v;
4526 (fun () -> conf.usepbo
)
4527 (fun v -> conf.usepbo
<- v);
4528 src#
bool "mouse wheel scrolls pages"
4529 (fun () -> conf.wheelbypage
)
4530 (fun v -> conf.wheelbypage
<- v);
4534 src#caption
"Document" 0;
4535 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4536 src#caption2
"Pages"
4537 (fun () -> string_of_int
state.pagecount
) 1;
4538 src#caption2
"Dimensions"
4539 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4543 src#caption
"Trimmed margins" 0;
4544 src#caption2
"Dimensions"
4545 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4549 src#caption
"OpenGL" 0;
4550 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4551 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4552 src#reset prevmode prevuioh
;
4556 let prevmode = state.mode
4557 and prevuioh
= state.uioh in
4558 fillsrc prevmode prevuioh
;
4559 let source = (src :> lvsource
) in
4560 let modehash = findkeyhash conf "info" in
4561 state.uioh <- coe (object (self)
4562 inherit listview ~
source ~trusted
:true ~
modehash as super
4563 val mutable m_prevmemused
= 0
4564 method infochanged
= function
4566 if m_prevmemused
!= state.memused
4568 m_prevmemused
<- state.memused
;
4569 G.postRedisplay "memusedchanged";
4571 | Pdim
-> G.postRedisplay "pdimchanged"
4572 | Docinfo
-> fillsrc prevmode prevuioh
4574 method key key mask
=
4575 if not
(Wsi.withctrl mask
)
4578 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4579 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4580 | _ -> super#
key key mask
4581 else super#
key key mask
4583 G.postRedisplay "info";
4589 inherit lvsourcebase
4590 method getitemcount
= Array.length
state.help
4592 let s, l, _ = state.help
.(n) in
4595 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4599 m_qsearch
<- qsearch;
4600 match state.help
.(active) with
4601 | _, _, Action
f -> Some
(f uioh)
4611 method hasaction
n =
4612 match state.help
.(n) with
4613 | _, _, Action
_ -> true
4620 let modehash = findkeyhash conf "help" in
4621 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4622 G.postRedisplay "help";
4627 let re = Str.regexp
"[\r\n]" in
4629 inherit lvsourcebase
4630 val mutable m_items
= [||]
4632 method getitemcount
= 1 + Array.length m_items
4637 else m_items
.(n-1), 0
4639 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4644 then Buffer.clear
state.errmsgs
;
4645 m_qsearch
<- qsearch;
4652 method hasaction
n =
4656 state.newerrmsgs
<- false;
4657 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4658 m_items
<- Array.of_list
l
4666 let source = (msgsource :> lvsource
) in
4667 let modehash = findkeyhash conf "listview" in
4668 state.uioh <- coe (object
4669 inherit listview ~
source ~trusted
:false ~
modehash as super
4672 then msgsource#reset
;
4675 G.postRedisplay "msgs";
4678 let quickbookmark ?title
() =
4679 match state.layout with
4685 let sec = Unix.gettimeofday
() in
4686 let tm = Unix.localtime
sec in
4687 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4691 (tm.Unix.tm_year
+ 1900)
4694 | Some
title -> title
4696 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4700 state.fullscreen
<- None
;
4704 let setautoscrollspeed step goingdown
=
4705 let incr = max
1 ((abs step
) / 2) in
4706 let incr = if goingdown
then incr else -incr in
4707 let astep = step
+ incr in
4708 state.autoscroll
<- Some
astep;
4711 let gotounder = function
4712 | Ulinkgoto
(pageno, top) ->
4716 gotopage1 pageno top;
4722 | Uremote
(filename
, pageno) ->
4724 if Sys.file_exists filename
4727 let dir = Filename.dirname
state.path in
4728 let path = Filename.concat
dir filename
in
4729 if Sys.file_exists
path
4733 if String.length
path > 0
4735 let anchor = getanchor () in
4736 let ranchor = state.path, state.password
, anchor in
4737 state.anchor <- (pageno, 0.0, 0.0);
4738 state.ranchors
<- ranchor :: state.ranchors
;
4741 else showtext '
!'
("Could not find " ^ filename
)
4743 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4747 match conf.columns
with
4749 | _ -> conf.zoom > 1.0
4752 let existsinrow pageno (columns
, coverA
, coverB
) p =
4753 let last = ((pageno - coverA
) mod columns
) + columns
in
4754 let rec any = function
4757 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4761 then (if l.pageno = last then false else any rest
)
4769 match state.layout with
4772 match conf.columns
with
4774 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4776 let y = clamp (pgscale conf.winh
) in
4779 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4780 gotoghyll (getpagey pageno)
4781 | Cmulti
((c, _, _) as cl
, _) ->
4782 if conf.presentation
4783 && (existsinrow l.pageno cl
4784 (fun l -> l.pageh
> l.pagey + l.pagevh))
4786 let y = clamp (pgscale conf.winh
) in
4789 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4790 gotoghyll (getpagey pageno)
4792 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4794 let pagey, pageh
= getpageyh l.pageno in
4795 let pagey = pagey + pageh
* l.pagecol
in
4796 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4797 gotoghyll (pagey + pageh
+ ips)
4801 match state.layout with
4804 match conf.columns
with
4806 if conf.presentation
&& l.pagey != 0
4808 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4810 let pageno = max
0 (l.pageno-1) in
4811 gotoghyll (getpagey pageno)
4812 | Cmulti
((c, _, coverB
) as cl
, _) ->
4813 if conf.presentation
&&
4814 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4816 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4819 if l.pageno = state.pagecount
- coverB
4823 let pageno = max
0 (l.pageno-decr) in
4824 gotoghyll (getpagey pageno)
4832 let pageno = max
0 (l.pageno-1) in
4833 let pagey, pageh
= getpageyh pageno in
4836 let pagey, pageh
= getpageyh l.pageno in
4837 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4842 let viewkeyboard key mask
=
4844 let mode = state.mode in
4845 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4848 G.postRedisplay "view:enttext"
4850 let ctrl = Wsi.withctrl mask
in
4852 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4858 | 0xff63 -> (* insert *)
4859 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4861 state.mode <- LinkNav
(Ltgendir
0);
4864 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4866 | 0xff1b | 113 -> (* escape / q *)
4867 begin match state.mstate
with
4869 state.mstate
<- Mnone
;
4870 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4871 G.postRedisplay "kill zoom rect";
4873 begin match state.mode with
4876 G.postRedisplay "esc leave linknav"
4878 match state.ranchors
with
4880 | (path, password
, anchor) :: rest
->
4881 state.ranchors
<- rest
;
4882 state.anchor <- anchor;
4883 opendoc path password
4887 | 0xff08 -> (* backspace *)
4888 gotoghyll (getnav ~
-1)
4896 G.postRedisplay "dehighlight";
4898 | 47 | 63 -> (* / ? *)
4899 let ondone isforw
s =
4900 cbput state.hists
.pat
s;
4901 state.searchpattern
<- s;
4904 let s = String.create
1 in
4905 s.[0] <- Char.chr
key;
4906 enttext (s, "", Some
(onhist state.hists
.pat
),
4907 textentry, ondone (key = 47), true)
4909 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4910 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4911 setzoom (conf.zoom +. incr)
4913 | 43 | 0xffab -> (* + *)
4916 try int_of_string
s with exc
->
4917 state.text <- Printf.sprintf
"bad integer `%s': %s"
4918 s (Printexc.to_string exc
);
4924 state.text <- "page bias is now " ^ string_of_int
n;
4927 enttext ("page bias: ", "", None
, intentry, ondone, true)
4929 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4930 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4931 setzoom (max
0.01 (conf.zoom -. decr))
4933 | 45 | 0xffad -> (* - *)
4934 let ondone msg
= state.text <- msg
in
4936 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4937 optentry state.mode, ondone, true
4940 | 48 when ctrl -> (* ctrl-0 *)
4943 | 49 when ctrl -> (* ctrl-1 *)
4945 match conf.columns
with
4946 | Csingle
_ | Cmulti
_ -> 1
4947 | Csplit
(n, _) -> n
4949 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4953 | 0xffc6 -> (* f9 *)
4956 | 57 when ctrl -> (* ctrl-9 *)
4959 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4960 when not
ctrl -> (* 0..9 *)
4963 try int_of_string
s with exc
->
4964 state.text <- Printf.sprintf
"bad integer `%s': %s"
4965 s (Printexc.to_string exc
);
4971 cbput state.hists
.pag
(string_of_int
n);
4972 gotopage1 (n + conf.pagebias
- 1) 0;
4975 let pageentry text key =
4976 match Char.unsafe_chr
key with
4977 | '
g'
-> TEdone
text
4978 | _ -> intentry text key
4980 let text = "x" in text.[0] <- Char.chr
key;
4981 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4984 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4985 reshape conf.winw
conf.winh
;
4988 conf.hlinks
<- not
conf.hlinks
;
4989 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4990 G.postRedisplay "toggle highlightlinks";
4993 state.glinks
<- true;
4994 let mode = state.mode in
4995 state.mode <- Textentry
(
4996 (":", "", None
, linknentry, linkndone gotounder, false),
4998 state.glinks
<- false;
5002 G.postRedisplay "view:linkent(F)"
5005 state.glinks
<- true;
5006 let mode = state.mode in
5007 state.mode <- Textentry
(
5008 (":", "", None
, linknentry, linkndone (fun under ->
5009 match Ne.pipe () with
5011 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
5012 (Printexc.to_string exn
));
5015 try popen conf.selcmd
[r, 0; w, -1]; true
5018 (Printf.sprintf
"failed to execute %s: %s"
5019 conf.selcmd
(Printexc.to_string exn
));
5023 Ne.clo fd
(fun msg
->
5024 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5027 let s = undertext under in
5031 let l = String.length
s in
5032 let n = tempfailureretry (Unix.write
w s 0) l in
5037 "failed to write %d characters to sel pipe, wrote %d"
5042 (Printf.sprintf
"failed to write to sel pipe: %s"
5043 (Printexc.to_string exn
)
5052 state.glinks
<- false;
5056 G.postRedisplay "view:linkent"
5059 begin match state.autoscroll
with
5061 conf.autoscrollstep
<- step
;
5062 state.autoscroll
<- None
5064 if conf.autoscrollstep
= 0
5065 then state.autoscroll
<- Some
1
5066 else state.autoscroll
<- Some
conf.autoscrollstep
5069 | 112 when ctrl -> (* ctrl-p *)
5073 setpresentationmode (not
conf.presentation
);
5074 showtext ' '
("presentation mode " ^
5075 if conf.presentation
then "on" else "off");
5078 begin match state.fullscreen
with
5080 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
5083 state.fullscreen
<- None
;
5087 | 112 | 78 -> (* p|N *)
5088 search state.searchpattern
false
5090 | 110 | 0xffc0 -> (* n|F3 *)
5091 search state.searchpattern
true
5094 begin match state.layout with
5097 gotoghyll (getpagey l.pageno)
5103 | 0xff9f | 0xffff -> (* delete *)
5107 showtext ' '
(describe_location ());
5110 begin match state.layout with
5113 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5118 enterbookmarkmode ()
5120 | 104 | 0xffbe -> (* h|F1 *)
5126 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5131 match state.layout with
5133 if String.length
s > 0
5135 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5138 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5142 showtext ' '
"Quick bookmark added";
5145 begin match state.layout with
5147 let rect = getpdimrect
l.pagedimno
in
5151 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5152 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5154 (truncate
(rect.(1) -. rect.(0)),
5155 truncate
(rect.(3) -. rect.(0)))
5157 let w = truncate
((float w)*.conf.zoom)
5158 and h = truncate
((float h)*.conf.zoom) in
5161 state.anchor <- getanchor ();
5162 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5164 G.postRedisplay "z";
5169 | 50 when ctrl -> (* ctrl-2 *)
5170 let maxw = getmaxw
() in
5172 then setzoom (maxw /. float conf.winw
)
5174 | 60 | 62 -> (* < > *)
5175 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5177 | 91 | 93 -> (* [ ] *)
5179 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5181 G.postRedisplay "brightness";
5183 | 99 when state.mode = View
-> (* c *)
5185 match state.prevcolumns
with
5186 | None
-> (1, 0, 0), 1.0
5187 | Some
(columns
, z
) ->
5190 | Csplit
(c, _) -> -c, 0, 0
5191 | Cmulti
((c, a, b), _) -> c, a, b
5192 | Csingle
_ -> 1, 0, 0
5196 setcolumns View
c a b;
5199 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5200 setzoom state.prevzoom
5202 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5203 begin match state.autoscroll
with
5205 begin match state.mode with
5206 | Birdseye beye
-> upbirdseye 1 beye
5209 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5210 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5213 setautoscrollspeed n false
5216 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5217 begin match state.autoscroll
with
5219 begin match state.mode with
5220 | Birdseye beye
-> downbirdseye 1 beye
5223 then gotoy_and_clear_text (clamp (conf.winh
/2))
5224 else gotoy_and_clear_text (clamp conf.scrollstep
)
5227 setautoscrollspeed n true
5230 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5231 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5237 else conf.hscrollstep
5239 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5240 state.x <- state.x + dx;
5241 gotoy_and_clear_text state.y
5244 G.postRedisplay "lef/right"
5247 | 0xff55 | 0xff9a -> (* (kp) prior *)
5251 match state.layout with
5253 | l :: _ -> state.y - l.pagey
5255 clamp (pgscale (-conf.winh
))
5259 | 0xff56 | 0xff9b -> (* (kp) next *)
5263 match List.rev
state.layout with
5265 | l :: _ -> getpagey l.pageno
5267 clamp (pgscale conf.winh
)
5271 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5273 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5274 gotoghyll (clamp state.maxy)
5277 when Wsi.withalt mask
-> (* alt-(kp) right *)
5278 gotoghyll (getnav 1)
5280 when Wsi.withalt mask
-> (* alt-(kp) left *)
5281 gotoghyll (getnav ~
-1)
5286 | 118 when conf.debug
-> (* v *)
5289 match getopaque l.pageno with
5292 let x0, y0, x1, y1 = pagebbox opaque
in
5293 let a,b = float x0, float y0 in
5294 let c,d = float x1, float y0 in
5295 let e,f = float x1, float y1 in
5296 let h,j
= float x0, float y1 in
5297 let rect = (a,b,c,d,e,f,h,j
) in
5299 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5301 G.postRedisplay "v";
5304 vlog "huh? %s" (Wsi.keyname
key)
5307 let linknavkeyboard key mask
linknav =
5308 let getpage pageno =
5309 let rec loop = function
5311 | l :: _ when l.pageno = pageno -> Some
l
5312 | _ :: rest
-> loop rest
5313 in loop state.layout
5315 let doexact (pageno, n) =
5316 match getopaque pageno, getpage pageno with
5317 | Some opaque
, Some
l ->
5318 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5320 let under = getlink opaque
n in
5321 G.postRedisplay "link gotounder";
5327 | 0xff50 -> (* home *)
5328 Some
(findlink opaque LDfirst
), -1
5330 | 0xff57 -> (* end *)
5331 Some
(findlink opaque LDlast
), 1
5333 | 0xff51 -> (* left *)
5334 Some
(findlink opaque
(LDleft
n)), -1
5336 | 0xff53 -> (* right *)
5337 Some
(findlink opaque
(LDright
n)), 1
5339 | 0xff52 -> (* up *)
5340 Some
(findlink opaque
(LDup
n)), -1
5342 | 0xff54 -> (* down *)
5343 Some
(findlink opaque
(LDdown
n)), 1
5348 begin match findpwl
l.pageno dir with
5352 state.mode <- LinkNav
(Ltgendir
dir);
5353 let y, h = getpageyh pageno in
5356 then y + h - conf.winh
5361 begin match getopaque pageno, getpage pageno with
5362 | Some opaque
, Some
_ ->
5364 let ld = if dir > 0 then LDfirst
else LDlast
in
5367 begin match link with
5369 showlinktype (getlink opaque
m);
5370 state.mode <- LinkNav
(Ltexact
(pageno, m));
5371 G.postRedisplay "linknav jpage";
5378 begin match opt with
5379 | Some Lnotfound
-> pwl l dir;
5380 | Some
(Lfound
m) ->
5384 let _, y0, _, y1 = getlinkrect opaque
m in
5386 then gotopage1 l.pageno y0
5388 let d = fstate.fontsize
+ 1 in
5389 if y1 - l.pagey > l.pagevh - d
5390 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5391 else G.postRedisplay "linknav";
5393 showlinktype (getlink opaque
m);
5394 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5397 | None
-> viewkeyboard key mask
5399 | _ -> viewkeyboard key mask
5404 G.postRedisplay "leave linknav"
5408 | Ltgendir
_ -> viewkeyboard key mask
5409 | Ltexact exact
-> doexact exact
5412 let keyboard key mask
=
5413 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5414 then wcmd "interrupt"
5415 else state.uioh <- state.uioh#
key key mask
5418 let birdseyekeyboard key mask
5419 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5421 match conf.columns
with
5423 | Cmulti
((c, _, _), _) -> c
5424 | Csplit
_ -> failwith
"bird's eye split mode"
5426 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5428 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5429 let y, h = getpageyh pageno in
5430 let top = (conf.winh
- h) / 2 in
5431 gotoy (max
0 (y - top))
5432 | 0xff0d (* enter *)
5433 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5434 | 0xff1b -> leavebirdseye beye
true (* escape *)
5435 | 0xff52 -> upbirdseye incr beye
(* up *)
5436 | 0xff54 -> downbirdseye incr beye
(* down *)
5437 | 0xff51 -> upbirdseye 1 beye
(* left *)
5438 | 0xff53 -> downbirdseye 1 beye
(* right *)
5440 | 0xff55 -> (* prior *)
5441 begin match state.layout with
5445 state.mode <- Birdseye
(
5446 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5448 gotopage1 l.pageno 0;
5451 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5453 | [] -> gotoy (clamp (-conf.winh
))
5455 state.mode <- Birdseye
(
5456 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5458 gotopage1 l.pageno 0
5461 | [] -> gotoy (clamp (-conf.winh
))
5464 | 0xff56 -> (* next *)
5465 begin match List.rev
state.layout with
5467 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5468 begin match layout with
5470 let incr = l.pageh
- l.pagevh in
5475 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5477 G.postRedisplay "birdseye pagedown";
5479 else gotoy (clamp (incr + conf.interpagespace
*2));
5483 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5484 gotopage1 l.pageno 0;
5487 | [] -> gotoy (clamp conf.winh
)
5490 | 0xff50 -> (* home *)
5491 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5494 | 0xff57 -> (* end *)
5495 let pageno = state.pagecount
- 1 in
5496 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5497 if not
(pagevisible state.layout pageno)
5500 match List.rev
state.pdims
with
5502 | (_, _, h, _) :: _ -> h
5504 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5505 else G.postRedisplay "birdseye end";
5506 | _ -> viewkeyboard key mask
5509 let drawpage l linkindexbase
=
5511 match state.mode with
5512 | Textentry
_ -> scalecolor 0.4
5514 | View
-> scalecolor 1.0
5515 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5516 if l.pageno = hooverpageno
5519 if l.pageno = pageno
5525 begin match getopaque l.pageno with
5527 if tileready l l.pagex
l.pagey
5529 let x = l.pagedispx - l.pagex
5530 and y = l.pagedispy - l.pagey in
5532 match conf.columns
with
5533 | Csingle
_ | Cmulti
_ ->
5534 (if conf.hlinks
then 1 else 0)
5536 && not
(isbirdseye state.mode) then 2 else 0)
5540 match state.mode with
5541 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5544 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5551 let scrollindicator () =
5552 let sbw, ph
, sh = state.uioh#
scrollph in
5553 let sbh, pw, sw = state.uioh#scrollpw
in
5555 GlDraw.color (0.64, 0.64, 0.64);
5557 (float (conf.winw
- sbw), 0.)
5558 (float conf.winw
, float conf.winh
)
5561 (0., float (conf.winh
- sbh))
5562 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5564 GlDraw.color (0.0, 0.0, 0.0);
5567 (float (conf.winw
- sbw), ph
)
5568 (float conf.winw
, ph
+. sh)
5571 (pw, float (conf.winh
- sbh))
5572 (pw +. sw, float conf.winh
)
5577 match state.mstate
with
5578 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5581 | Msel
((x0, y0), (x1, y1)) ->
5582 let rec loop = function
5584 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5585 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5586 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5587 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5589 match getopaque l.pageno with
5591 let x0, y0 = pagetranslatepoint l x0 y0 in
5592 let x1, y1 = pagetranslatepoint l x1 y1 in
5593 seltext opaque
(x0, y0, x1, y1);
5601 let showrects rects
=
5603 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5604 GlDraw.polygon_mode `both `fill
;
5605 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5607 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5609 if l.pageno = pageno
5611 let dx = float (l.pagedispx - l.pagex
) in
5612 let dy = float (l.pagedispy - l.pagey) in
5613 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5614 GlDraw.begins `quads
;
5616 GlDraw.vertex2
(x0+.dx, y0+.dy);
5617 GlDraw.vertex2
(x1+.dx, y1+.dy);
5618 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5619 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5630 GlClear.color (scalecolor2 conf.bgcolor
);
5631 GlClear.clear
[`
color];
5632 let rec loop linkindexbase
= function
5634 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5635 loop linkindexbase rest
5638 loop 0 state.layout;
5640 match state.mode with
5641 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5642 begin match getopaque pageno with
5644 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5651 | None
-> state.rects
5658 begin match state.mstate
with
5659 | Mzoomrect
((x0, y0), (x1, y1)) ->
5661 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5662 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5663 GlDraw.rect (float x0, float y0)
5664 (float x1, float y1);
5673 let zoomrect x y x1 y1 =
5676 and y0 = min
y y1 in
5677 gotoy (state.y + y0);
5678 state.anchor <- getanchor ();
5679 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5681 if state.w < conf.winw
- state.scrollw
5682 then (conf.winw
- state.scrollw
- state.w) / 2
5685 state.x <- (state.x + margin) - x0;
5687 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5688 state.mstate
<- Mnone
;
5692 let winw = conf.winw - state.scrollw
- 1 in
5693 let s = float x /. float winw in
5694 let destx = truncate
(float (state.w + winw) *. s) in
5695 state.x <- winw - destx;
5696 gotoy_and_clear_text state.y;
5697 state.mstate
<- Mscrollx
;
5701 let s = float y /. float conf.winh
in
5702 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5703 gotoy_and_clear_text desty;
5704 state.mstate
<- Mscrolly
;
5707 let viewmouse button down
x y mask
=
5709 | n when (n == 4 || n == 5) && not down
->
5710 if Wsi.withctrl mask
5712 match state.mstate
with
5713 | Mzoom
(oldn
, i
) ->
5721 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5723 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5725 let zoom = conf.zoom -. incr in
5727 state.mstate
<- Mzoom
(n, 0);
5729 state.mstate
<- Mzoom
(n, i
+1);
5731 else state.mstate
<- Mzoom
(n, 0)
5733 | _ -> state.mstate
<- Mzoom
(n, 0)
5736 match state.autoscroll
with
5737 | Some step
-> setautoscrollspeed step
(n=4)
5748 then -conf.scrollstep
5749 else conf.scrollstep
5751 let incr = incr * 2 in
5752 let y = clamp incr in
5753 gotoy_and_clear_text y
5756 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5757 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5758 gotoy_and_clear_text state.y
5760 | 1 when Wsi.withshift mask
->
5761 state.mstate
<- Mnone
;
5763 match unproject x y with
5764 | Some
(pageno, ux
, uy
) ->
5765 let cmd = Printf.sprintf
5767 conf.stcmd
state.path pageno ux uy
5773 | 1 when Wsi.withctrl mask
->
5776 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5777 state.mstate
<- Mpan
(x, y)
5780 state.mstate
<- Mnone
5785 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5787 state.mstate
<- Mzoomrect
(p, p)
5790 match state.mstate
with
5791 | Mzoomrect
((x0, y0), _) ->
5792 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5793 then zoomrect x0 y0 x y
5795 state.mstate
<- Mnone
;
5796 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5797 G.postRedisplay "kill accidental zoom rect";
5800 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5801 state.mstate
<- Mnone
5804 | 1 when x > conf.winw - state.scrollw
->
5807 let _, position, sh = state.uioh#
scrollph in
5808 if y > truncate
position && y < truncate
(position +. sh)
5809 then state.mstate
<- Mscrolly
5812 state.mstate
<- Mnone
5814 | 1 when y > conf.winh
- state.hscrollh ->
5817 let _, position, sw = state.uioh#scrollpw
in
5818 if x > truncate
position && x < truncate
(position +. sw)
5819 then state.mstate
<- Mscrollx
5822 state.mstate
<- Mnone
5825 let dest = if down
then getunder x y else Unone
in
5826 begin match dest with
5830 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5833 | Unone
when down
->
5834 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5835 state.mstate
<- Mpan
(x, y);
5837 | Unone
| Utext
_ ->
5840 if conf.angle
mod 360 = 0
5842 state.mstate
<- Msel
((x, y), (x, y));
5843 G.postRedisplay "mouse select";
5847 match state.mstate
with
5850 | Mzoom
_ | Mscrollx
| Mscrolly
->
5851 state.mstate
<- Mnone
5853 | Mzoomrect
((x0, y0), _) ->
5857 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5858 state.mstate
<- Mnone
5860 | Msel
((x0, y0), (x1, y1)) ->
5861 let rec loop = function
5865 let a0 = l.pagedispy in
5866 let a1 = a0 + l.pagevh in
5867 let b0 = l.pagedispx in
5868 let b1 = b0 + l.pagevw in
5869 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5870 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5874 match getopaque l.pageno with
5877 match Ne.pipe () with
5881 "can not create sel pipe: %s"
5882 (Printexc.to_string exn
));
5884 let doclose what fd
=
5885 Ne.clo fd
(fun msg
->
5886 dolog "%s close failed: %s" what msg
)
5889 popen conf.selcmd
[r, 0; w, -1];
5892 G.postRedisplay "copysel";
5894 dolog "can not execute %S: %s"
5895 conf.selcmd
(Printexc.to_string exn
);
5903 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5904 state.mstate
<- Mnone
;
5911 let birdseyemouse button down
x y mask
5912 (conf, leftx
, _, hooverpageno
, anchor) =
5915 let rec loop = function
5918 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5919 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5921 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5927 | _ -> viewmouse button down
x y mask
5930 let mouse button down
x y mask
=
5931 state.uioh <- state.uioh#button button down
x y mask
;
5935 state.uioh <- state.uioh#
motion x y
5939 state.uioh <- state.uioh#
pmotion x y;
5945 method key key mask
=
5946 begin match state.mode with
5947 | Textentry
textentry -> textentrykeyboard key mask
textentry
5948 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5949 | View
-> viewkeyboard key mask
5950 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5954 method button button bstate
x y mask
=
5955 begin match state.mode with
5957 | View
-> viewmouse button bstate
x y mask
5958 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5964 begin match state.mode with
5966 | View
| Birdseye
_ | LinkNav
_ ->
5967 match state.mstate
with
5968 | Mzoom
_ | Mnone
-> ()
5973 state.mstate
<- Mpan
(x, y);
5975 then state.x <- state.x + dx;
5977 gotoy_and_clear_text y
5980 state.mstate
<- Msel
(a, (x, y));
5981 G.postRedisplay "motion select";
5984 let y = min
conf.winh
(max
0 y) in
5988 let x = min
conf.winw (max
0 x) in
5991 | Mzoomrect
(p0
, _) ->
5992 state.mstate
<- Mzoomrect
(p0
, (x, y));
5993 G.postRedisplay "motion zoomrect";
5997 method pmotion x y =
5998 begin match state.mode with
5999 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6000 let rec loop = function
6002 if hooverpageno
!= -1
6004 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6005 G.postRedisplay "pmotion birdseye no hoover";
6008 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6009 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6011 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6012 G.postRedisplay "pmotion birdseye hoover";
6022 match state.mstate
with
6023 | Mnone
-> updateunder x y
6024 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6029 method infochanged
_ = ()
6032 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
6033 let p, h = scrollph state.y maxy in
6037 let winw = conf.winw - state.scrollw
- 1 in
6038 let fwinw = float winw in
6040 let sw = fwinw /. float state.w in
6041 let sw = fwinw *. sw in
6042 max
sw (float conf.scrollh
)
6045 let f = state.w+winw in
6046 let r = float (winw-state.x) /. float f in
6047 let p = fwinw *. r in
6051 if position +. sw > fwinw
6052 then fwinw -. position
6055 state.hscrollh, position, sw
6059 match state.mode with
6060 | LinkNav
_ -> "links"
6061 | Textentry
_ -> "textentry"
6062 | Birdseye
_ -> "birdseye"
6065 findkeyhash conf modename
6072 let fontpath = ref "";;
6075 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6078 let l = String.length
s in
6079 let b = Buffer.create
l in
6085 try Sys.getenv
"HOME"
6088 ("Can not determine home directory location: " ^
6089 Printexc.to_string exn
);
6093 let modifier_of_string = function
6094 | "alt" -> Wsi.altmask
6095 | "shift" -> Wsi.shiftmask
6096 | "ctrl" | "control" -> Wsi.ctrlmask
6097 | "meta" -> Wsi.metamask
6102 let r = Str.regexp
"-" in
6104 let elems = Str.full_split
r s in
6107 let m1 = modifier_of_string s in
6109 then (Wsi.namekey
s, m)
6112 | Str.Delim
s when n land 1 = 0 -> g s
6114 | Str.Delim
_ -> (k
, m)
6116 let rec loop n k
m = function
6119 let k, m = f n k m x in
6125 let keys_of_string =
6126 let r = Str.regexp
"[ \t]" in
6128 let elems = Str.split
r s in
6129 List.map
key_of_string elems
6132 let copykeyhashes c =
6133 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6136 let config_of c attrs
=
6140 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6141 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6142 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6143 | "preload" -> { c with preload = bool_of_string
v }
6144 | "page-bias" -> { c with pagebias
= int_of_string
v }
6145 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6146 | "horizontal-scroll-step" ->
6147 { c with hscrollstep
= max
(int_of_string
v) 1 }
6148 | "auto-scroll-step" ->
6149 { c with autoscrollstep
= max
0 (int_of_string
v) }
6150 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6151 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6154 match String.lowercase
v with
6155 | "true" -> Some infinity
6157 | f -> Some
(float_of_string
f)
6159 { c with maxwait
= mw}
6160 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6161 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6162 | "vertical-margin" ->
6163 { c with interpagespace
= max
0 (int_of_string
v) }
6165 let zoom = float_of_string
v /. 100. in
6166 let zoom = max
zoom 0.0 in
6167 { c with zoom = zoom }
6168 | "presentation" -> { c with presentation
= bool_of_string
v }
6169 | "rotation-angle" -> { c with angle
= int_of_string
v }
6170 | "width" -> { c with winw = max
20 (int_of_string
v) }
6171 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6172 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6173 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6174 | "pixmap-cache-size" ->
6175 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6176 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6177 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6178 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6179 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6180 | "background-color" -> { c with bgcolor
= color_of_string v }
6181 | "scrollbar-in-presentation" ->
6182 { c with scrollbarinpm
= bool_of_string
v }
6183 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6184 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6185 | "mupdf-store-size" ->
6186 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6187 | "checkers" -> { c with checkers
= bool_of_string
v }
6188 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6189 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6190 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6191 | "uri-launcher" -> { c with urilauncher
= unent v }
6192 | "path-launcher" -> { c with pathlauncher
= unent v }
6193 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6194 | "invert-colors" -> { c with invert
= bool_of_string
v }
6195 | "brightness" -> { c with colorscale
= float_of_string
v }
6196 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6198 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6200 let (n, _, _) as nab
= multicolumns_of_string v in
6202 then { c with columns
= Csplit
(-n, [||]) }
6203 else { c with columns
= Cmulti
(nab
, [||]) }
6204 | "birds-eye-columns" ->
6205 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6206 | "selection-command" -> { c with selcmd
= unent v }
6207 | "synctex-command" -> { c with stcmd
= unent v }
6208 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6209 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6210 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6211 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6212 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6215 prerr_endline
("Error processing attribute (`" ^
6216 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6219 let rec fold c = function
6222 let c = apply c k v in
6225 fold { c with keyhashes
= copykeyhashes c } attrs
;
6228 let fromstring f pos
n v d =
6231 dolog "Error processing attribute (%S=%S) at %d\n%s"
6232 n v pos
(Printexc.to_string exn
)
6237 let bookmark_of attrs
=
6238 let rec fold title page
rely visy
= function
6239 | ("title", v) :: rest
-> fold v page
rely visy rest
6240 | ("page", v) :: rest
-> fold title v rely visy rest
6241 | ("rely", v) :: rest
-> fold title page
v visy rest
6242 | ("visy", v) :: rest
-> fold title page
rely v rest
6243 | _ :: rest
-> fold title page
rely visy rest
6244 | [] -> title, page
, rely, visy
6246 fold "invalid" "0" "0" "0" attrs
6250 let rec fold path page
rely pan visy
= function
6251 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6252 | ("page", v) :: rest
-> fold path v rely pan visy rest
6253 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6254 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6255 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6256 | _ :: rest
-> fold path page
rely pan visy rest
6257 | [] -> path, page
, rely, pan
, visy
6259 fold "" "0" "0" "0" "0" attrs
6263 let rec fold rs ls
= function
6264 | ("out", v) :: rest
-> fold v ls rest
6265 | ("in", v) :: rest
-> fold rs
v rest
6266 | _ :: rest
-> fold ls rs rest
6272 let setconf dst
src =
6273 dst
.scrollbw
<- src.scrollbw
;
6274 dst
.scrollh
<- src.scrollh
;
6275 dst
.icase
<- src.icase
;
6276 dst
.preload <- src.preload;
6277 dst
.pagebias
<- src.pagebias
;
6278 dst
.verbose
<- src.verbose
;
6279 dst
.scrollstep
<- src.scrollstep
;
6280 dst
.maxhfit
<- src.maxhfit
;
6281 dst
.crophack
<- src.crophack
;
6282 dst
.autoscrollstep
<- src.autoscrollstep
;
6283 dst
.maxwait
<- src.maxwait
;
6284 dst
.hlinks
<- src.hlinks
;
6285 dst
.underinfo
<- src.underinfo
;
6286 dst
.interpagespace
<- src.interpagespace
;
6287 dst
.zoom <- src.zoom;
6288 dst
.presentation
<- src.presentation
;
6289 dst
.angle
<- src.angle
;
6290 dst
.winw <- src.winw;
6291 dst
.winh
<- src.winh
;
6292 dst
.savebmarks
<- src.savebmarks
;
6293 dst
.memlimit
<- src.memlimit
;
6294 dst
.proportional
<- src.proportional
;
6295 dst
.texcount
<- src.texcount
;
6296 dst
.sliceheight
<- src.sliceheight
;
6297 dst
.thumbw
<- src.thumbw
;
6298 dst
.jumpback
<- src.jumpback
;
6299 dst
.bgcolor
<- src.bgcolor
;
6300 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6301 dst
.tilew
<- src.tilew
;
6302 dst
.tileh
<- src.tileh
;
6303 dst
.mustoresize
<- src.mustoresize
;
6304 dst
.checkers
<- src.checkers
;
6305 dst
.aalevel
<- src.aalevel
;
6306 dst
.trimmargins
<- src.trimmargins
;
6307 dst
.trimfuzz
<- src.trimfuzz
;
6308 dst
.urilauncher
<- src.urilauncher
;
6309 dst
.colorspace
<- src.colorspace
;
6310 dst
.invert
<- src.invert
;
6311 dst
.colorscale
<- src.colorscale
;
6312 dst
.redirectstderr <- src.redirectstderr;
6313 dst
.ghyllscroll
<- src.ghyllscroll
;
6314 dst
.columns
<- src.columns
;
6315 dst
.beyecolumns
<- src.beyecolumns
;
6316 dst
.selcmd
<- src.selcmd
;
6317 dst
.updatecurs
<- src.updatecurs
;
6318 dst
.pathlauncher
<- src.pathlauncher
;
6319 dst
.keyhashes
<- copykeyhashes src;
6320 dst
.hfsize
<- src.hfsize
;
6321 dst
.hscrollstep
<- src.hscrollstep
;
6322 dst
.pgscale <- src.pgscale;
6323 dst
.usepbo
<- src.usepbo
;
6324 dst
.wheelbypage
<- src.wheelbypage
;
6325 dst
.stcmd
<- src.stcmd
;
6329 let h = Hashtbl.create
10 in
6330 let dc = { defconf with angle
= defconf.angle
} in
6331 let rec toplevel v t spos
_ =
6333 | Vdata
| Vcdata
| Vend
-> v
6334 | Vopen
("llppconfig", _, closed
) ->
6337 else { v with f = llppconfig
}
6339 error
"unexpected subelement at top level" s spos
6340 | Vclose
_ -> error
"unexpected close at top level" s spos
6342 and llppconfig
v t spos
_ =
6344 | Vdata
| Vcdata
-> v
6345 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6346 | Vopen
("defaults", attrs
, closed
) ->
6347 let c = config_of dc attrs
in
6351 else { v with f = defaults
}
6353 | Vopen
("ui-font", attrs
, closed
) ->
6354 let rec getsize size
= function
6356 | ("size", v) :: rest
->
6358 fromstring int_of_string spos
"size" v fstate.fontsize
in
6360 | l -> getsize size l
6362 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6365 else { v with f = uifont
(Buffer.create
10) }
6367 | Vopen
("doc", attrs
, closed
) ->
6368 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6369 let path = unent pathent
6370 and pageno = fromstring int_of_string spos
"page" spage
0
6371 and rely = fromstring float_of_string spos
"rely" srely
0.0
6372 and pan
= fromstring int_of_string spos
"pan" span
0
6373 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6374 let c = config_of dc attrs
in
6375 let anchor = (pageno, rely, visy
) in
6377 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6378 else { v with f = doc
path pan
anchor c [] }
6381 error
"unexpected subelement in llppconfig" s spos
6383 | Vclose
"llppconfig" -> { v with f = toplevel }
6384 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6386 and defaults
v t spos
_ =
6388 | Vdata
| Vcdata
-> v
6389 | Vend
-> error
"unexpected end of input in defaults" s spos
6390 | Vopen
("keymap", attrs
, closed
) ->
6392 try List.assoc
"mode" attrs
6393 with Not_found
-> "global" in
6398 let h = findkeyhash dc modename in
6399 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6402 { v with f = pkeymap
ret KeyMap.empty }
6404 | Vopen
(_, _, _) ->
6405 error
"unexpected subelement in defaults" s spos
6407 | Vclose
"defaults" ->
6408 { v with f = llppconfig
}
6410 | Vclose
_ -> error
"unexpected close in defaults" s spos
6412 and uifont
b v t spos
epos =
6415 Buffer.add_substring
b s spos
(epos - spos
);
6417 | Vopen
(_, _, _) ->
6418 error
"unexpected subelement in ui-font" s spos
6419 | Vclose
"ui-font" ->
6420 if String.length
!fontpath = 0
6421 then fontpath := Buffer.contents
b;
6422 { v with f = llppconfig
}
6423 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6424 | Vend
-> error
"unexpected end of input in ui-font" s spos
6426 and doc
path pan
anchor c bookmarks
v t spos
_ =
6428 | Vdata
| Vcdata
-> v
6429 | Vend
-> error
"unexpected end of input in doc" s spos
6430 | Vopen
("bookmarks", _, closed
) ->
6433 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6435 | Vopen
("keymap", attrs
, closed
) ->
6437 try List.assoc
"mode" attrs
6438 with Not_found
-> "global"
6444 let h = findkeyhash c modename in
6445 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6446 doc
path pan
anchor c bookmarks
6448 { v with f = pkeymap
ret KeyMap.empty }
6450 | Vopen
(_, _, _) ->
6451 error
"unexpected subelement in doc" s spos
6454 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6455 { v with f = llppconfig
}
6457 | Vclose
_ -> error
"unexpected close in doc" s spos
6459 and pkeymap
ret keymap
v t spos
_ =
6461 | Vdata
| Vcdata
-> v
6462 | Vend
-> error
"unexpected end of input in keymap" s spos
6463 | Vopen
("map", attrs
, closed
) ->
6464 let r, l = map_of attrs
in
6465 let kss = fromstring keys_of_string spos
"in" r [] in
6466 let lss = fromstring keys_of_string spos
"out" l [] in
6470 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6471 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6474 then { v with f = pkeymap
ret keymap }
6477 { v with f = skip
"map" f }
6480 error
"unexpected subelement in keymap" s spos
6482 | Vclose
"keymap" ->
6483 { v with f = ret keymap }
6485 | Vclose
_ -> error
"unexpected close in keymap" s spos
6487 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6489 | Vdata
| Vcdata
-> v
6490 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6491 | Vopen
("item", attrs
, closed
) ->
6492 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6493 let page = fromstring int_of_string spos
"page" spage
0
6494 and rely = fromstring float_of_string spos
"rely" srely
0.0
6495 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6497 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6500 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6503 { v with f = skip
"item" f }
6506 error
"unexpected subelement in bookmarks" s spos
6508 | Vclose
"bookmarks" ->
6509 { v with f = doc
path pan
anchor c bookmarks }
6511 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6513 and skip tag
f v t spos
_ =
6515 | Vdata
| Vcdata
-> v
6517 error
("unexpected end of input in skipped " ^ tag
) s spos
6518 | Vopen
(tag'
, _, closed
) ->
6522 let f'
() = { v with f = skip tag
f } in
6523 { v with f = skip tag'
f'
}
6527 else error
("unexpected close in skipped " ^ tag
) s spos
6530 parse
{ f = toplevel; accu = () } s;
6536 let len = in_channel_length ic
in
6537 let s = String.create
len in
6538 really_input ic
s 0 len;
6541 | Parse_error
(msg
, s, pos
) ->
6542 let subs = subs s pos
in
6543 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6544 failwith
("parse error: " ^
s)
6547 failwith
("config load error: " ^
Printexc.to_string exn
)
6553 let dir = Filename.concat
home ".config" in
6554 if Sys.is_directory
dir then dir else home
6557 Filename.concat
dir "llpp.conf"
6560 let confpath = ref defconfpath;;
6563 if Sys.file_exists
!confpath
6566 (try Some
(open_in_bin
!confpath)
6569 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6570 Printexc.to_string exn
);
6580 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6581 Printexc.to_string exn
);
6589 f (Hashtbl.create
0, defconf)
6594 let pc, pb
, px, pa
=
6596 Hashtbl.find h (Filename.basename
state.path)
6597 with Not_found
-> dc, [], 0, emptyanchor
6601 state.bookmarks <- pb
;
6603 state.scrollw
<- conf.scrollbw
;
6605 then state.anchor <- pa
;
6606 cbput state.hists
.nav pa
;
6612 let add_attrs bb always
dc c =
6615 then Printf.bprintf bb
"\n %s='%b'" s a
6618 then Printf.bprintf bb
"\n %s='%d'" s a
6621 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6624 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6627 then Printf.bprintf bb
"\n %s='%f'" s a
6631 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6635 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6639 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6643 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6649 | Some
(_N
, _A
, _B
) ->
6650 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6660 else string_of_float
f
6662 Printf.bprintf bb
"\n %s='%s'" s v
6667 | Cmulti
((n, a, b), _) when n > 1 ->
6668 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6669 | Csplit
(n, _) when n > 1 ->
6670 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6676 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6681 then dc.winw, dc.winh
6683 match state.fullscreen
with
6685 | None
-> c.winw, c.winh
6687 oi
"width" w dc.winw;
6688 oi
"height" h dc.winh
;
6689 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6690 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6691 ob "case-insensitive-search" c.icase
dc.icase
;
6692 ob "preload" c.preload dc.preload;
6693 oi
"page-bias" c.pagebias
dc.pagebias
;
6694 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6695 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6696 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6697 ob "crop-hack" c.crophack
dc.crophack
;
6698 oW
"throttle" c.maxwait
dc.maxwait
;
6699 ob "highlight-links" c.hlinks
dc.hlinks
;
6700 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6701 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6702 oz
"zoom" c.zoom dc.zoom;
6703 ob "presentation" c.presentation
dc.presentation
;
6704 oi
"rotation-angle" c.angle
dc.angle
;
6705 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6706 ob "proportional-display" c.proportional
dc.proportional
;
6707 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6708 oi
"tex-count" c.texcount
dc.texcount
;
6709 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6710 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6711 ob "persistent-location" c.jumpback
dc.jumpback
;
6712 oc
"background-color" c.bgcolor
dc.bgcolor
;
6713 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6714 oi
"tile-width" c.tilew
dc.tilew
;
6715 oi
"tile-height" c.tileh
dc.tileh
;
6716 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6717 ob "checkers" c.checkers
dc.checkers
;
6718 oi
"aalevel" c.aalevel
dc.aalevel
;
6719 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6720 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6721 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6722 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6723 oC
"color-space" c.colorspace
dc.colorspace
;
6724 ob "invert-colors" c.invert
dc.invert
;
6725 oF
"brightness" c.colorscale
dc.colorscale
;
6726 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6727 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6728 oco
"columns" c.columns
dc.columns
;
6729 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6730 os
"selection-command" c.selcmd
dc.selcmd
;
6731 os
"synctex-command" c.stcmd
dc.stcmd
;
6732 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6733 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6734 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6735 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6736 ob "use-pbo" c.usepbo
dc.usepbo
;
6737 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6740 let keymapsbuf always
dc c =
6741 let bb = Buffer.create
16 in
6742 let rec loop = function
6744 | (modename, h) :: rest
->
6745 let dh = findkeyhash dc modename in
6746 if always
|| h <> dh
6748 if Hashtbl.length
h > 0
6750 if Buffer.length
bb > 0
6751 then Buffer.add_char
bb '
\n'
;
6752 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6753 Hashtbl.iter
(fun i
o ->
6754 let isdifferent = always
||
6756 let dO = Hashtbl.find dh i
in
6758 with Not_found
-> true
6763 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6764 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6765 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6766 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6767 Buffer.add_string
bb (Wsi.keyname
k);
6770 let rec loop = function
6772 | km
:: [] -> addkm km
6773 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6777 Buffer.add_string
bb "<map in='";
6781 Buffer.add_string
bb "' out='";
6783 Buffer.add_string
bb "'/>\n"
6786 Buffer.add_string
bb "' out='";
6788 Buffer.add_string
bb "'/>\n"
6790 | KMmulti
(ins, kms
) ->
6791 Buffer.add_char
bb ' '
;
6793 Buffer.add_string
bb "' out='";
6795 Buffer.add_string
bb "'/>\n"
6797 Buffer.add_string
bb "</keymap>";
6807 let uifontsize = fstate.fontsize
in
6808 let bb = Buffer.create
32768 in
6810 let dc = if conf.bedefault
then conf else dc in
6811 Buffer.add_string
bb "<llppconfig>\n";
6813 if String.length
!fontpath > 0
6815 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6821 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6824 Buffer.add_string
bb "<defaults ";
6825 add_attrs bb true dc dc;
6826 let kb = keymapsbuf true dc dc in
6827 if Buffer.length
kb > 0
6829 Buffer.add_string
bb ">\n";
6830 Buffer.add_buffer
bb kb;
6831 Buffer.add_string
bb "\n</defaults>\n";
6833 else Buffer.add_string
bb "/>\n";
6835 let adddoc path pan
anchor c bookmarks =
6836 if bookmarks == [] && c = dc && anchor = emptyanchor
6839 Printf.bprintf
bb "<doc path='%s'"
6840 (enent
path 0 (String.length
path));
6842 if anchor <> emptyanchor
6844 let n, rely, visy
= anchor in
6845 Printf.bprintf
bb " page='%d'" n;
6848 Printf.bprintf
bb " rely='%f'" rely
6850 if abs_float visy
> 1e-6
6852 Printf.bprintf
bb " visy='%f'" visy
6857 then Printf.bprintf
bb " pan='%d'" pan
;
6859 add_attrs bb false dc c;
6860 let kb = keymapsbuf false dc c in
6862 begin match bookmarks with
6864 if Buffer.length
kb > 0
6866 Buffer.add_string
bb ">\n";
6867 Buffer.add_buffer
bb kb;
6868 Buffer.add_string
bb "\n</doc>\n";
6870 else Buffer.add_string
bb "/>\n"
6872 Buffer.add_string
bb ">\n<bookmarks>\n";
6873 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6875 "<item title='%s' page='%d'"
6876 (enent
title 0 (String.length
title))
6881 Printf.bprintf
bb " rely='%f'" rely
6883 if abs_float visy
> 1e-6
6885 Printf.bprintf
bb " visy='%f'" visy
6887 Buffer.add_string
bb "/>\n";
6889 Buffer.add_string
bb "</bookmarks>";
6890 if Buffer.length
kb > 0
6892 Buffer.add_string
bb "\n";
6893 Buffer.add_buffer
bb kb;
6895 Buffer.add_string
bb "\n</doc>\n";
6901 match state.mode with
6902 | Birdseye
(c, pan, _, _, _) ->
6904 match conf.columns
with
6905 | Cmulti
((c, _, _), _) -> Some
c
6909 match c.columns
with
6910 | Cmulti
(c, _) -> Cmulti
(c, [||])
6911 | Csingle
_ -> Csingle
[||]
6912 | Csplit
_ -> failwith
"quit from bird's eye while split"
6914 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6915 | _ -> state.x, conf
6917 let basename = Filename.basename state.path in
6918 adddoc basename pan (getanchor ())
6920 let autoscrollstep =
6921 match state.autoscroll
with
6923 | None
-> conf.autoscrollstep
6925 match state.mode with
6926 | Birdseye
(bc
, _, _, _, _) ->
6929 presentation
= bc
.presentation
;
6930 interpagespace
= bc
.interpagespace
;
6931 maxwait
= bc
.maxwait
;
6932 autoscrollstep = autoscrollstep }
6933 | _ -> { conf with autoscrollstep = autoscrollstep }
6935 (if conf.savebmarks
then state.bookmarks else []);
6937 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6939 then adddoc path x anchor c bookmarks
6941 Buffer.add_string
bb "</llppconfig>\n";
6944 if load1 f && Buffer.length
bb > 0
6947 let tmp = !confpath ^
".tmp" in
6948 let oc = open_out_bin
tmp in
6949 Buffer.output_buffer
oc bb;
6951 Unix.rename
tmp !confpath;
6954 ("error while saving configuration: " ^
Printexc.to_string exn
)
6958 let adderrmsg src msg
=
6959 Buffer.add_string
state.errmsgs msg
;
6960 state.newerrmsgs
<- true;
6964 let adderrfmt src fmt
=
6965 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
6968 let onpagerect pageno f =
6970 match conf.columns
with
6971 | Cmulti
(_, b) -> b
6973 | Csplit
(_, b) -> b
6975 if pageno >= 0 && pageno < Array.length
b
6977 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
6978 let r = getpdimrect
pdimno in
6979 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
6985 try String.index cmds ' '
6986 with Not_found
-> -1
6991 let l = String.length cmds
in
6992 let op = String.sub cmds
0 spacepos in
6994 if l - spacepos < 2 then ""
6995 else String.sub cmds
(spacepos+1) (l-spacepos-1)
6999 try Scanf.sscanf
s fmt
f
7001 adderrfmt "remote exec"
7002 "error processing '%S' %S: %s\n" op cmds
(Printexc.to_string exn
)
7005 | "reload" -> reload ()
7007 scan args "%u %f %f"
7009 onpagerect pageno (fun _ h ->
7011 gotopage pageno top;
7014 | "goto1" -> scan args "%u %f" gotopage
7016 scan args "%u %u %f %f %f %f"
7017 (fun pageno color x0 y0 x1 y1 ->
7018 onpagerect pageno (fun w h ->
7019 let _,w1,h1
,_ = getpagedim pageno in
7020 let sw = float w1 /. w
7021 and sh = float h1
/. h in
7025 and y1s
= y1 *. sh in
7026 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7028 state.rects <- (pageno, color, rect) :: state.rects;
7029 G.postRedisplay "rect";
7032 | "quit" -> raise Quit
7034 adderrfmt "remote command"
7035 "error processing remote command: %S\n" cmds
;
7039 let scratch = String.create
80 in
7040 let buf = Buffer.create
80 in
7044 try Some
(Unix.read fd
scratch 0 80)
7046 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7047 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7050 match tempfr () with
7056 if Buffer.length
buf > 0
7058 let s = Buffer.contents
buf in
7067 let pos = String.index
scratch '
\n'
in
7068 if pos >= n then -1 else pos
7069 with Not_found
-> -1
7073 Buffer.add_substring
buf scratch 0 nlpos;
7074 let s = Buffer.contents
buf in
7076 if n - nlpos - 1 > 0
7077 then Buffer.add_substring
buf scratch (nlpos+1) (n-nlpos-1);
7082 Buffer.add_substring
buf scratch 0 n;
7089 let remoteopen path =
7090 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7092 adderrfmt "remoteopen" "error opening %S: %s" path (Printexc.to_string exn
);
7097 let trimcachepath = ref "" in
7098 let rcmdpath = ref "" in
7101 [("-p", Arg.String
(fun s -> state.password
<- s) ,
7102 "<password> Set password");
7104 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7105 "<path> Set path to the user interface font");
7107 ("-c", Arg.String
(fun s -> Config.confpath := s),
7108 "<path> Set path to the configuration file");
7110 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7111 "<path> Set path to the trim cache file");
7113 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7114 "<named-destination> Set named destination");
7116 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7118 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7119 "<path> Set path to the remote commands source");
7121 ("-v", Arg.Unit
(fun () ->
7123 "%s\nconfiguration path: %s\n"
7127 exit
0), " Print version and exit");
7130 (fun s -> state.path <- s)
7131 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7133 if String.length
state.path = 0
7134 then (prerr_endline
"file name missing"; exit
1);
7136 if not
(Config.load ())
7137 then prerr_endline
"failed to load configuration";
7139 let globalkeyhash = findkeyhash conf "global" in
7140 let wsfd, winw, winh
= Wsi.init
(object
7142 state.wthack <- false;
7143 if nogeomcmds state.geomcmds
|| platform == Posx
7146 GlClear.color (scalecolor2 conf.bgcolor
);
7147 GlClear.clear
[`
color];
7149 method display = display ()
7150 method reshape w h = reshape w h
7151 method mouse b d x y m = mouse b d x y m
7152 method motion x y = state.mpos
<- (x, y); motion x y
7153 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7155 let mascm = m land (
7156 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7158 match state.keystate
with
7160 let km = k, mascm in
7163 let modehash = state.uioh#
modehash in
7164 try Hashtbl.find modehash km
7166 try Hashtbl.find globalkeyhash km
7167 with Not_found
-> KMinsrt
(k, m)
7169 | KMinsrt
(k, m) -> keyboard k m
7170 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7171 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7173 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7174 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7175 state.keystate
<- KSnone
7176 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7177 state.keystate
<- KSinto
(keys
, insrt
)
7179 state.keystate
<- KSnone
7181 method enter
x y = state.mpos
<- (x, y); pmotion x y
7182 method leave = state.mpos
<- (-1, -1)
7183 method quit
= raise Quit
7184 end) conf.winw conf.winh
(platform = Posx
) in
7189 List.exists
GlMisc.check_extension
7190 [ "GL_ARB_texture_rectangle"
7191 ; "GL_EXT_texture_recangle"
7192 ; "GL_NV_texture_rectangle" ]
7194 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7197 match Ne.pipe () with
7199 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7203 match Ne.pipe () with
7205 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7215 setcheckers conf.checkers
;
7219 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7220 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7221 !Config.fontpath, !trimcachepath,
7222 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7226 state.text <- "Opening " ^
(mbtoutf8
state.path);
7228 opendoc state.path state.password
;
7231 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7234 if String.length
!rcmdpath > 0
7235 then remoteopen !rcmdpath
7240 let rec loop deadline
=
7242 match state.errfd
with
7243 | None
-> [state.sr
; state.wsfd]
7244 | Some fd
-> [state.sr
; state.wsfd; fd
]
7249 | Some fd
-> fd
:: r
7251 if state.redisplay
&& not
state.wthack
7253 state.redisplay
<- false;
7260 if deadline
= infinity
7262 else max
0.0 (deadline
-. now)
7267 try Unix.select
r [] [] timeout
7268 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7274 if state.ghyll
== noghyll
7276 match state.autoscroll
with
7277 | Some step
when step
!= 0 ->
7278 let y = state.y + step
in
7282 else if y >= state.maxy then 0 else y
7285 if state.mode = View
7286 then state.text <- "";
7289 else deadline
+. 0.01
7294 let rec checkfds = function
7296 | fd
:: rest
when fd
= state.sr
->
7297 let cmd = readcmd state.sr
in
7301 | fd
:: rest
when fd
= state.wsfd ->
7305 | fd
:: rest
when Some fd
= !optrfd ->
7306 begin match remote fd
with
7307 | None
-> optrfd := remoteopen !rcmdpath;
7308 | opt -> optrfd := opt
7313 let s = String.create
80 in
7314 let n = tempfailureretry (Unix.read fd
s 0) 80 in
7315 if conf.redirectstderr
7317 Buffer.add_substring
state.errmsgs
s 0 n;
7318 state.newerrmsgs
<- true;
7319 state.redisplay
<- true;
7322 prerr_string
(String.sub
s 0 n);
7330 if deadline
= infinity
7334 match state.autoscroll
with
7335 | Some step
when step
!= 0 -> deadline1
7336 | _ -> if state.ghyll
== noghyll then infinity
else deadline1