8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 type params
= (angle
* proportional
* trimparams
17 * texcount
* sliceheight
* memsize
18 * colorspace
* fontpath
* trimcachepath
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
37 and trimcachepath
= string
40 and irect
= (int * int * int * int)
41 and trimparams
= (trimmargins
* irect
)
42 and colorspace
= | Rgb
| Bgr
| Gray
50 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
59 | LDfirstvisible
of (int * int * int)
74 | KMmulti
of key list
* key list
76 and keyhash
= (key
, keymap
) Hashtbl.t
79 | KSinto
of (key list
* key list
)
82 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
83 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
85 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
87 external init
: pipe
-> params
-> unit = "ml_init";;
88 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
89 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
90 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
91 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
92 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
93 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
94 external measurestr
: int -> string -> float = "ml_measure_string";;
95 external getmaxw
: unit -> float = "ml_getmaxw";;
96 external postprocess
:
97 opaque
-> int -> int -> int -> (int * string * int) -> int
99 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
100 external platform
: unit -> platform
= "ml_platform";;
101 external setaalevel
: int -> unit = "ml_setaalevel";;
102 external realloctexts
: int -> bool = "ml_realloctexts";;
103 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
104 external getlink
: opaque
-> int -> under
= "ml_getlink";;
105 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
106 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
107 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
108 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
109 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
110 external freepbo
: string -> unit = "ml_freepbo";;
111 external unmappbo
: string -> unit = "ml_unmappbo";;
112 external pbousable
: unit -> bool = "ml_pbo_usable";;
113 external unproject
: opaque
-> int -> int -> (int * int) option
115 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
117 let platform_to_string = function
118 | Punknown
-> "unknown"
122 | Pfreebsd
-> "FreeBSD"
123 | Pdragonflybsd
-> "DragonflyBSD"
124 | Popenbsd
-> "OpenBSD"
125 | Pnetbsd
-> "NetBSD"
126 | Pcygwin
-> "Cygwin"
129 let platform = platform ();;
131 let now = Unix.gettimeofday
;;
134 if platform = Pcygwin
136 let sh = "/bin/sh" in
137 let args = [|sh; "-c"; cmd
|] in
138 let rec std si so se
= function
140 | (fd
, 0) :: rest
-> std fd so se rest
141 | (fd
, -1) :: rest
->
142 Unix.set_close_on_exec fd
;
145 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
147 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
148 ignore
(Unix.create_process
sh args si so se
)
153 type mpos
= int * int
155 | Msel
of (mpos
* mpos
)
157 | Mscrolly
| Mscrollx
158 | Mzoom
of (int * int)
159 | Mzoomrect
of (mpos
* mpos
)
163 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
164 and onkey
= string -> int -> te
165 and ondone
= string -> unit
166 and histcancel
= unit -> unit
167 and onhist
= ((histcmd
-> string) * histcancel
)
168 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
169 and cancelonempty
= bool
174 | TEswitch
of textentry
185 let bound v minv maxv
=
186 max minv
(min maxv v
);
190 { store
= Array.create n v
197 let cbcap b
= Array.length b
.store
;;
202 b
.wc
<- (b
.wc
+ 1) mod cap;
204 b
.len
<- min
(b
.len
+ 1) cap;
207 let cbempty b
= b
.len
= 0;;
209 let cbgetg b circular dir
=
213 let rc = b
.rc + dir
in
225 else bound rc 0 (b
.len
-1)
231 let cbget b
= cbgetg b
false;;
232 let cbgetc b
= cbgetg b
true;;
234 let drawstring size x y s
=
236 Gl.enable `texture_2d
;
237 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
238 ignore
(drawstr size x y s
);
240 Gl.disable `texture_2d
;
243 let drawstring1 size x y s
=
247 let drawstring2 size x y fmt
=
248 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
267 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
268 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
269 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
270 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
271 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
272 dolog
" column %d" l
.pagecol
;
276 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
278 dolog
" x0,y0=(% f, % f)" x0 y0
;
279 dolog
" x1,y1=(% f, % f)" x1 y1
;
280 dolog
" x2,y2=(% f, % f)" x2 y2
;
281 dolog
" x3,y3=(% f, % f)" x3 y3
;
285 type multicolumns
= multicol
* pagegeom
286 and singlecolumn
= pagegeom
287 and splitcolumns
= columncount
* pagegeom
288 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
289 and multicol
= columncount
* covercount
* covercount
291 and columncount
= int
292 and covercount
= int;;
295 { mutable scrollbw
: int
296 ; mutable scrollh
: int
297 ; mutable icase
: bool
298 ; mutable preload
: bool
299 ; mutable pagebias
: int
300 ; mutable verbose
: bool
301 ; mutable debug
: bool
302 ; mutable scrollstep
: int
303 ; mutable hscrollstep
: int
304 ; mutable maxhfit
: bool
305 ; mutable crophack
: bool
306 ; mutable autoscrollstep
: int
307 ; mutable maxwait
: float option
308 ; mutable hlinks
: bool
309 ; mutable underinfo
: bool
310 ; mutable interpagespace
: interpagespace
311 ; mutable zoom
: float
312 ; mutable presentation
: bool
313 ; mutable angle
: angle
314 ; mutable cwinw
: int
315 ; mutable cwinh
: int
316 ; mutable savebmarks
: bool
317 ; mutable proportional
: proportional
318 ; mutable trimmargins
: trimmargins
319 ; mutable trimfuzz
: irect
320 ; mutable memlimit
: memsize
321 ; mutable texcount
: texcount
322 ; mutable sliceheight
: sliceheight
323 ; mutable thumbw
: width
324 ; mutable jumpback
: bool
325 ; mutable bgcolor
: float * float * float
326 ; mutable bedefault
: bool
327 ; mutable scrollbarinpm
: bool
328 ; mutable tilew
: int
329 ; mutable tileh
: int
330 ; mutable mustoresize
: memsize
331 ; mutable checkers
: bool
332 ; mutable aalevel
: int
333 ; mutable urilauncher
: string
334 ; mutable pathlauncher
: string
335 ; mutable colorspace
: colorspace
336 ; mutable invert
: bool
337 ; mutable colorscale
: float
338 ; mutable redirectstderr
: bool
339 ; mutable ghyllscroll
: (int * int * int) option
340 ; mutable columns
: columns
341 ; mutable beyecolumns
: columncount
option
342 ; mutable selcmd
: string
343 ; mutable updatecurs
: bool
344 ; mutable keyhashes
: (string * keyhash
) list
345 ; mutable hfsize
: int
346 ; mutable pgscale
: float
347 ; mutable usepbo
: bool
348 ; mutable wheelbypage
: bool
349 ; mutable stcmd
: string
352 | Csingle
of singlecolumn
353 | Cmulti
of multicolumns
354 | Csplit
of splitcolumns
357 type anchor
= pageno
* top
* dtop
;;
359 type outline
= string * int * anchor
;;
361 type rect
= float * float * float * float * float * float * float * float;;
363 type tile
= opaque
* pixmapsize
* elapsed
364 and elapsed
= float;;
365 type pagemapkey
= pageno
* gen
;;
366 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
370 let emptyanchor = (0, 0.0, 0.0);;
372 type infochange
= | Memused
| Docinfo
| Pdim
;;
374 class type uioh
= object
375 method display
: unit
376 method key
: int -> int -> uioh
377 method button
: int -> bool -> int -> int -> int -> uioh
378 method motion
: int -> int -> uioh
379 method pmotion
: int -> int -> uioh
380 method infochanged
: infochange
-> unit
381 method scrollpw
: (int * float * float)
382 method scrollph
: (int * float * float)
383 method modehash
: keyhash
387 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
388 | Textentry
of (textentry
* onleave
)
390 | LinkNav
of linktarget
391 and onleave
= leavetextentrystatus
-> unit
392 and leavetextentrystatus
= | Cancel
| Confirm
393 and helpitem
= string * int * action
396 | Action
of (uioh
-> uioh
)
398 | Ltexact
of (pageno
* int)
402 let isbirdseye = function Birdseye _
-> true | _
-> false;;
403 let istextentry = function Textentry _
-> true | _
-> false;;
407 | Loading
of (page
* gen
)
409 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
411 | Outlining
of outline list
414 let emptykeyhash = Hashtbl.create
0;;
415 let nouioh : uioh
= object (self
)
417 method key _ _
= self
418 method button _ _ _ _ _
= self
419 method motion _ _
= self
420 method pmotion _ _
= self
421 method infochanged _
= ()
422 method scrollpw
= (0, nan
, nan
)
423 method scrollph
= (0, nan
, nan
)
424 method modehash
= emptykeyhash
428 { mutable sr
: Unix.file_descr
429 ; mutable sw
: Unix.file_descr
430 ; mutable wsfd
: Unix.file_descr
431 ; mutable errfd
: Unix.file_descr
option
432 ; mutable stderr
: Unix.file_descr
433 ; mutable errmsgs
: Buffer.t
434 ; mutable newerrmsgs
: bool
438 ; mutable scrollw
: int
439 ; mutable hscrollh
: int
440 ; mutable anchor
: anchor
441 ; mutable ranchors
: (string * string * anchor
) list
443 ; mutable layout
: page list
444 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
445 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
446 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
447 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
448 ; mutable pagecount
: int
449 ; mutable currently
: currently
450 ; mutable mstate
: mstate
451 ; mutable searchpattern
: string
452 ; mutable rects
: (pageno
* recttype
* rect
) list
453 ; mutable rects1
: (pageno
* recttype
* rect
) list
454 ; mutable text
: string
455 ; mutable winstate
: Wsi.winstate list
456 ; mutable mode
: mode
457 ; mutable uioh
: uioh
458 ; mutable outlines
: outline array
459 ; mutable bookmarks
: outline list
460 ; mutable path
: string
461 ; mutable password
: string
462 ; mutable nameddest
: string
463 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
464 ; mutable memused
: memsize
466 ; mutable throttle
: (page list
* int * float) option
467 ; mutable autoscroll
: int option
468 ; mutable ghyll
: (int option -> unit)
469 ; mutable help
: helpitem array
470 ; mutable docinfo
: (int * string) list
471 ; mutable texid
: GlTex.texture_id
option
473 ; mutable prevzoom
: float
474 ; mutable progress
: float
475 ; mutable redisplay
: bool
476 ; mutable mpos
: mpos
477 ; mutable keystate
: keystate
478 ; mutable glinks
: bool
479 ; mutable prevcolumns
: (columns
* float) option
480 ; mutable wthack
: bool
483 ; mutable reprf
: (unit -> unit)
486 { pat
: string circbuf
487 ; pag
: string circbuf
488 ; nav
: anchor circbuf
489 ; sel
: string circbuf
511 ; presentation
= false
516 ; proportional
= true
517 ; trimmargins
= false
518 ; trimfuzz
= (0,0,0,0)
519 ; memlimit
= 32 lsl 20
524 ; bgcolor
= (0.5, 0.5, 0.5)
526 ; scrollbarinpm
= true
529 ; mustoresize
= 256 lsl 20
534 | Plinux
| Pfreebsd
| Pdragonflybsd
535 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
536 | Posx
-> "open \"%s\""
537 | Pcygwin
-> "cygstart \"%s\""
538 | Punknown
-> "echo %s")
539 ; pathlauncher
= "lp \"%s\""
542 | Plinux
| Pfreebsd
| Pdragonflybsd
543 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
550 ; redirectstderr
= false
552 ; columns
= Csingle
[||]
558 ; wheelbypage
= false
559 ; stcmd
= "echo SyncTex"
561 let mk n
= (n
, Hashtbl.create
1) in
575 let wtmode = ref false;;
577 let findkeyhash c name
=
578 try List.assoc name c
.keyhashes
579 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
582 let conf = { defconf with angle
= defconf.angle
};;
584 let pgscale h
= truncate
(float h
*. conf.pgscale);;
587 { mutable fontsize
: int
588 ; mutable wwidth
: float
589 ; mutable maxrows
: int
601 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
602 let len = String.length s
in
603 if colonpos >= 0 && colonpos + 3 < len
605 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
608 try String.rindex_from s
colonpos ' '
612 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
615 | "http" | "ftp" | "mailto" ->
617 try String.index_from s
colonpos ' '
618 with Not_found
-> len
620 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
628 if String.length
conf.urilauncher
= 0
629 then print_endline uri
631 let url = geturl uri
in
632 if String.length
url = 0
633 then print_endline uri
635 let re = Str.regexp
"%s" in
636 let command = Str.global_replace
re url conf.urilauncher
in
640 "failed to execute `%s': %s\n" command (exntos exn
);
646 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
647 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
651 let strings = version () :: "" :: Help.keys
in
654 let url = geturl s
in
655 if String.length
url > 0
656 then (s
, 0, Action
(fun u
-> gotouri url; u
))
657 else (s
, 0, Noaction
)
662 let firstgeomcmds = "", [];;
663 let noreprf () = ();;
670 ; stderr
= Unix.stderr
671 ; errmsgs
= Buffer.create
0
678 ; anchor
= emptyanchor
682 ; tilelru
= Queue.create
()
683 ; pagemap
= Hashtbl.create
10
684 ; tilemap
= Hashtbl.create
10
700 ; geomcmds
= firstgeomcmds
702 { nav
= cbnew 10 emptyanchor
731 fstate.fontsize
<- n
;
732 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
733 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
739 Printf.kprintf prerr_endline fmt
741 Printf.kprintf ignore fmt
745 if String.length
conf.pathlauncher
= 0
746 then print_endline
state.path
748 let re = Str.regexp
"%s" in
749 let command = Str.global_replace
re state.path
conf.pathlauncher
in
752 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
758 type 'a t
= | Res
of 'a
| Exn
of exn
;;
761 try Res
(Unix.pipe ())
766 try tempfailureretry
Unix.close fd
767 with exn
-> f
(exntos exn
)
771 try Res
(tempfailureretry
Unix.dup fd
)
776 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
781 let redirectstderr () =
782 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
783 if conf.redirectstderr
785 match Ne.pipe () with
787 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
790 begin match Ne.dup Unix.stderr
with
792 dolog
"failed to dup stderr: %s" (exntos exn
);
793 Ne.clo r
(clofail "pipe/r");
794 Ne.clo w
(clofail "pipe/w");
796 | Ne.Res dupstderr
->
797 begin match Ne.dup2 w
Unix.stderr
with
799 dolog
"failed to dup2 to stderr: %s" (exntos 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" (exntos exn
)
817 Ne.clo fd
(clofail "dup of stderr");
822 prerr_string
(Buffer.contents
state.errmsgs
);
824 Buffer.clear
state.errmsgs
;
830 let postRedisplay who
=
832 then prerr_endline
("redisplay for " ^ who
);
833 state.redisplay
<- true;
837 let getopaque pageno
=
838 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
839 with Not_found
-> None
842 let putopaque pageno opaque
=
843 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
846 let pagetranslatepoint l x y
=
847 let dy = y
- l
.pagedispy
in
848 let y = dy + l
.pagey
in
849 let dx = x
- l
.pagedispx
in
850 let x = dx + l
.pagex
in
854 let onppundermouse g
x y d
=
857 begin match getopaque l
.pageno
with
859 let x0 = l
.pagedispx
in
860 let x1 = x0 + l
.pagevw
in
861 let y0 = l
.pagedispy
in
862 let y1 = y0 + l
.pagevh
in
863 if y >= y0 && y <= y1 && x >= x0 && x <= x1
865 let px, py
= pagetranslatepoint l
x y in
866 match g opaque l
px py
with
879 let g opaque _
px py
=
880 match whatsunder opaque
px py
with
882 | under
-> Some under
884 onppundermouse g x y Unone
889 match unproject opaque
x y with
890 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
893 onppundermouse g x y None
;
897 state.text
<- Printf.sprintf
"%c%s" c s
;
898 G.postRedisplay "showtext";
901 let undertext = function
904 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
905 | Utext s
-> "font: " ^ s
906 | Uunexpected s
-> "unexpected: " ^ s
907 | Ulaunch s
-> "launch: " ^ s
908 | Unamed s
-> "named: " ^ s
909 | Uremote
(filename
, pageno
) ->
910 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
913 let updateunder x y =
914 match getunder x y with
915 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
917 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
918 Wsi.setcursor
Wsi.CURSOR_INFO
919 | Ulinkgoto
(pageno
, _
) ->
921 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
922 Wsi.setcursor
Wsi.CURSOR_INFO
924 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
925 Wsi.setcursor
Wsi.CURSOR_TEXT
927 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
928 Wsi.setcursor
Wsi.CURSOR_INHERIT
930 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
931 Wsi.setcursor
Wsi.CURSOR_INHERIT
933 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
934 Wsi.setcursor
Wsi.CURSOR_INHERIT
935 | Uremote
(filename
, pageno
) ->
936 if conf.underinfo
then showtext 'r'
937 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
938 Wsi.setcursor
Wsi.CURSOR_INFO
941 let showlinktype under
=
947 let s = undertext under
in
952 let b = Buffer.create
(String.length
s + 1) in
953 Buffer.add_string
b s;
958 let colorspace_of_string s =
959 match String.lowercase
s with
963 | _
-> failwith
"invalid colorspace"
966 let int_of_colorspace = function
972 let colorspace_of_int = function
976 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
979 let colorspace_to_string = function
985 let intentry_with_suffix text key
=
987 if key
>= 32 && key
< 127
991 match Char.lowercase
c with
993 let text = addchar text c in
997 let text = addchar text c in
1001 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1005 let multicolumns_to_string (n
, a
, b) =
1007 then Printf.sprintf
"%d" n
1008 else Printf.sprintf
"%d,%d,%d" n a
b;
1011 let multicolumns_of_string s =
1013 (int_of_string
s, 0, 0)
1015 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1017 then failwith
"subtly broken"; (n
, a
, b)
1023 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1024 if n != 4 then failwith
"incomplete read(len)";
1026 lor (Char.code
s.[0] lsl 24)
1027 lor (Char.code
s.[1] lsl 16)
1028 lor (Char.code
s.[2] lsl 8)
1029 lor (Char.code
s.[3] lsl 0)
1031 let s = String.create
len in
1032 let n = tempfailureretry
(Unix.read fd
s 0) len in
1033 if n != len then failwith
"incomplete read(data)";
1037 let btod b = if b then 1 else 0;;
1040 let b = Buffer.create
16 in
1041 Buffer.add_string
b "llll";
1044 let s = Buffer.contents
b in
1045 let n = String.length
s in
1047 (* dolog "wcmd %S" (String.sub s 4 len); *)
1048 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1049 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1050 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1051 s.[3] <- Char.chr
(len land 0xff);
1052 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1053 if n'
!= n then failwith
"write failed";
1058 let d = state.winh
- h
in
1059 max
conf.interpagespace
((d + 1) / 2)
1062 let rowyh (c, coverA
, coverB
) b n =
1063 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1065 let _, _, vy
, (_, _, h
, _) = b.(n) in
1068 let n'
= n - coverA
in
1071 let e = min
state.pagecount
(s + c) in
1072 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1073 let _, _, y, (_, _, h
, _) = b.(m
) in
1074 let miny = min
miny y in
1075 let maxh = max
maxh h
in
1076 find (m
+1) miny maxh
1081 match conf.columns
with
1082 | Cmulti
((_, _, _) as cl
, b) ->
1083 if Array.length
b > 0
1085 let y, h
= rowyh cl
b (Array.length
b - 1) in
1086 y + h
+ (if conf.presentation
then calcips h
else 0)
1089 if Array.length
b > 0
1091 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1092 y + h
+ (if conf.presentation
then calcips h
else 0)
1095 if Array.length
b > 0
1097 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1102 let getpageyh pageno
=
1103 let pageno = bound pageno 0 (state.pagecount
-1) in
1104 match conf.columns
with
1106 if Array.length
b = 0
1109 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1111 if conf.presentation
1117 if Array.length
b = 0
1120 let y, h
= rowyh cl
b pageno in
1122 if conf.presentation
1128 if Array.length
b = 0
1132 let (_, _, y, (_, _, h
, _)) = b.(n) in
1136 let getpagedim pageno =
1139 | (n, _, _, _) as pdim
:: rest
->
1141 then (if n = pageno then pdim
else ppdim
)
1146 f (-1, -1, -1, -1) state.pdims
1149 let getpagey pageno = fst
(getpageyh pageno);;
1151 let nogeomcmds cmds
=
1153 | s, [] -> String.length
s = 0
1158 let ((c, coverA
, coverB
) as cl
), b =
1159 match conf.columns
with
1160 | Csingle
b -> (1, 0, 0), b
1161 | Cmulti
(c, b) -> c, b
1162 | Csplit
(_, b) -> (1, 0, 0), b
1164 if Array.length
b = 0
1167 let rec bsearch nmin nmax
=
1169 then bound nmin
0 (state.pagecount
-1)
1171 let n = (nmax
+ nmin
) / 2 in
1172 let vy, h
= rowyh cl
b n in
1174 if conf.presentation
1176 let ips = calcips h
in
1177 let y0 = vy - ips in
1178 let y1 = vy + h
+ ips in
1182 then 0, vy + h
+ conf.interpagespace
1184 let y0 = vy - conf.interpagespace
in
1185 y0, y0 + h
+ conf.interpagespace
1188 if y >= y0 && y < y1
1195 if n < state.pagecount
- coverB
1196 then ((n-coverA
)/c)*c + coverA
1203 then bsearch (n+1) nmax
1204 else bsearch nmin
(n-1)
1207 let r = bsearch 0 (state.pagecount
-1) in
1211 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1212 let sh = sh - state.hscrollh
in
1213 let rec fold accu
n =
1214 if n = Array.length
b
1217 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1220 || n = state.pagecount
- coverB
1221 || (n - coverA
) mod columns
= columns
- 1)
1227 let pagey = max
0 (y - vy) in
1228 let pagedispy = if pagey > 0 then 0 else vy - y in
1229 let pagedispx, pagex
=
1231 if n = coverA
- 1 || n = state.pagecount
- coverB
1232 then state.x + (state.winw
- state.scrollw
- w
) / 2
1233 else dx + xoff
+ state.x
1240 let vw = state.winw
- state.scrollw
- pagedispx in
1241 let pw = w
- pagex
in
1244 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1245 if pagevw > 0 && pagevh > 0
1249 ; pagedimno
= pdimno
1256 ; pagedispx = pagedispx
1257 ; pagedispy = pagedispy
1269 List.rev
(fold [] (page_of_y y));
1272 let layoutS (columns
, b) y sh =
1273 let sh = sh - state.hscrollh
in
1274 let rec fold accu n =
1275 if n = Array.length
b
1278 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1285 let x = xoff
+ state.x in
1286 let pagey = max
0 (y - vy) in
1287 let pagedispy = if pagey > 0 then 0 else vy - y in
1288 let pagedispx, pagex
=
1302 let pagecolw = pagew
/columns
in
1304 if pagecolw < state.winw
1305 then pagedispx + ((state.winw
- state.scrollw
- pagecolw) / 2)
1309 let vw = state.winw
- pagedispx - state.scrollw
in
1310 let pw = pagew
- pagex
in
1313 let pagevw = min
pagevw pagecolw in
1314 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1315 if pagevw > 0 && pagevh > 0
1318 { pageno = n/columns
1319 ; pagedimno
= pdimno
1326 ; pagedispx = pagedispx
1327 ; pagedispy = pagedispy
1328 ; pagecol
= n mod columns
1339 List.rev
(fold [] 0)
1343 if nogeomcmds state.geomcmds
1345 match conf.columns
with
1346 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1347 | Cmulti
c -> layoutN c y sh
1348 | Csplit
s -> layoutS s y sh
1353 let y = state.y + incr
in
1355 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1360 let tilex = l
.pagex
mod conf.tilew
in
1361 let tiley = l
.pagey mod conf.tileh
in
1363 let col = l
.pagex
/ conf.tilew
in
1364 let row = l
.pagey / conf.tileh
in
1366 let rec rowloop row y0 dispy h
=
1370 let dh = conf.tileh
- y0 in
1371 let dh = min h
dh in
1372 let rec colloop col x0 dispx w
=
1376 let dw = conf.tilew
- x0 in
1377 let dw = min w
dw in
1379 f col row dispx dispy
x0 y0 dw dh;
1380 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1383 colloop col tilex l
.pagedispx l
.pagevw;
1384 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1387 if l
.pagevw > 0 && l
.pagevh > 0
1388 then rowloop row tiley l
.pagedispy l
.pagevh;
1391 let gettileopaque l
col row =
1393 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1395 try Some
(Hashtbl.find state.tilemap
key)
1396 with Not_found
-> None
1399 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1400 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1401 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1404 let drawtiles l color
=
1406 let f col row x y tilex tiley w h
=
1407 match gettileopaque l
col row with
1408 | Some
(opaque
, _, t
) ->
1409 let params = x, y, w
, h
, tilex, tiley in
1413 GlFunc.blend_func `zero `one_minus_src_color
;
1415 drawtile
params opaque
;
1417 then Gl.disable `blend
;
1420 let s = Printf.sprintf
1424 let w = measurestr
fstate.fontsize
s in
1425 GlMisc.push_attrib
[`current
];
1426 GlDraw.color
(0.0, 0.0, 0.0);
1428 (float (x-2), float (y-2))
1429 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1430 GlDraw.color
(1.0, 1.0, 1.0);
1431 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1432 GlMisc.pop_attrib
();
1437 let lw = state.winw
- state.scrollw
- x in
1440 let lh = state.winh
- y in
1443 begin match state.texid
with
1445 Gl.enable `texture_2d
;
1446 GlTex.bind_texture `texture_2d id
;
1449 and x1 = float (x+w)
1450 and y1 = float (y+h
) in
1452 let tw = float w /. 16.0
1453 and th
= float h
/. 16.0 in
1454 let tx0 = float tilex /. 16.0
1455 and ty0
= float tiley /. 16.0 in
1457 and ty1
= ty0
+. th
in
1458 GlDraw.begins `quads
;
1459 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1460 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1461 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1462 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1465 Gl.disable `texture_2d
;
1467 GlDraw.color
(1.0, 1.0, 1.0);
1470 (float (x+w), float (y+h
));
1472 if w > 128 && h
> fstate.fontsize
+ 10
1474 GlDraw.color
(0.0, 0.0, 0.0);
1477 then (col*conf.tilew
, row*conf.tileh
)
1480 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1487 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1489 let tilevisible1 l
x y =
1491 and ax1
= l
.pagex
+ l
.pagevw
1493 and ay1
= l
.pagey + l
.pagevh in
1497 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1498 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1500 let rx0 = max
ax0 bx0
1501 and ry0
= max ay0 by0
1502 and rx1
= min ax1
bx1
1503 and ry1
= min ay1 by1
in
1505 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1506 nonemptyintersection
1509 let tilevisible layout n x y =
1510 let rec findpageinlayout m
= function
1511 | l
:: rest
when l
.pageno = n ->
1512 tilevisible1 l
x y || (
1513 match conf.columns
with
1514 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1517 | _ :: rest
-> findpageinlayout 0 rest
1520 findpageinlayout 0 layout;
1523 let tileready l
x y =
1524 tilevisible1 l
x y &&
1525 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1528 let tilepage n p
layout =
1529 let rec loop = function
1533 let f col row _ _ _ _ _ _ =
1534 if state.currently
= Idle
1536 match gettileopaque l
col row with
1539 let x = col*conf.tilew
1540 and y = row*conf.tileh
in
1542 let w = l
.pagew
- x in
1546 let h = l
.pageh
- y in
1551 then getpbo
w h conf.colorspace
1554 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1557 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1558 conf.tilew
, conf.tileh
1567 if nogeomcmds state.geomcmds
1571 let preloadlayout y =
1572 let y = if y < state.winh
then 0 else y - state.winh
in
1573 let h = state.winh
*3 in
1578 let rec loop pages
=
1579 if state.currently
!= Idle
1584 begin match getopaque l
.pageno with
1586 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1587 state.currently
<- Loading
(l
, state.gen
);
1589 tilepage l
.pageno opaque pages
;
1594 if nogeomcmds state.geomcmds
1600 if conf.preload && state.currently
= Idle
1601 then load (preloadlayout state.y);
1604 let layoutready layout =
1605 let rec fold all ls
=
1606 all
&& match ls
with
1608 let seen = ref false in
1609 let allvisible = ref true in
1610 let foo col row _ _ _ _ _ _ =
1612 allvisible := !allvisible &&
1613 begin match gettileopaque l
col row with
1619 fold (!seen && !allvisible) rest
1622 let alltilesvisible = fold true layout in
1627 state.wthack
<- false;
1628 let y = bound y 0 state.maxy
in
1629 let y, layout, proceed
=
1630 match conf.maxwait
with
1631 | Some time
when state.ghyll
== noghyll ->
1632 begin match state.throttle
with
1634 let layout = layout y state.winh
in
1635 let ready = layoutready layout in
1639 state.throttle
<- Some
(layout, y, now ());
1641 else G.postRedisplay "gotoy showall (None)";
1643 | Some
(_, _, started
) ->
1644 let dt = now () -. started
in
1647 state.throttle
<- None
;
1648 let layout = layout y state.winh
in
1650 G.postRedisplay "maxwait";
1657 let layout = layout y state.winh
in
1658 G.postRedisplay "gotoy ready";
1664 state.layout <- layout;
1665 begin match state.mode
with
1666 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1667 let rec loop = function
1669 state.mode
<- LinkNav
(Ltgendir
0)
1670 | l
:: _ when l
.pageno = pageno ->
1671 begin match getopaque pageno with
1673 state.mode
<- LinkNav
(Ltgendir
0)
1675 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1676 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1677 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1678 then state.mode
<- LinkNav
(Ltgendir
0)
1680 | _ :: rest
-> loop rest
1685 begin match state.mode
with
1686 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1687 if not
(pagevisible layout pageno)
1689 match state.layout with
1692 state.mode
<- Birdseye
(
1693 conf, leftx
, l
.pageno, hooverpageno
, anchor
1696 | LinkNav
(Ltgendir dir
as lt
) ->
1698 let rec loop = function
1701 match getopaque l
.pageno with
1707 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1709 if dir
> 0 then LDfirst
else LDlast
1715 | Lnotfound
-> loop rest
1717 showlinktype (getlink opaque
n);
1718 Ltexact
(l
.pageno, n)
1722 state.mode
<- LinkNav
linknav
1727 state.ghyll
<- noghyll;
1730 let mx, my
= state.mpos
in
1735 let conttiling pageno opaque
=
1736 tilepage pageno opaque
1737 (if conf.preload then preloadlayout state.y else state.layout)
1740 let gotoy_and_clear_text y =
1741 if not
conf.verbose
then state.text <- "";
1747 let coloff = l
.pagecol
* l
.pageh
in
1748 float (l
.pagey + coloff) /. float l
.pageh
1755 if conf.presentation
1756 then float l
.pagedispy /. float (calcips l
.pageh
)
1757 else float l
.pagedispy /. float conf.interpagespace
1759 (l
.pageno, top, dtop)
1763 match state.layout with
1764 | l
:: _ -> getanchor1 l
1766 let n = page_of_y state.y in
1770 let y, h = getpageyh n in
1771 let dy = y - state.y in
1773 if conf.presentation
1775 let ips = calcips h in
1776 float (dy + ips) /. float ips
1778 float dy /. float conf.interpagespace
1783 let getanchory (n, top, dtop) =
1784 let y, h = getpageyh n in
1785 if conf.presentation
1787 let ips = calcips h in
1788 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1790 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1793 let gotoanchor anchor
=
1794 gotoy (getanchory anchor
);
1798 cbput state.hists
.nav
(getanchor ());
1802 let anchor = cbgetc state.hists
.nav dir
in
1807 let scroll f n a
b =
1808 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1810 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1812 then s (float f /. float a
)
1815 then 1.0 -. s ((float (f-b) /. float (n-b)))
1822 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1823 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1825 let ins = float a
*. iv1
1826 and outs
= float (n-b) *. iv1 in
1828 ins +. outs
+. float ones
1830 let rec set (_N
, _A
, _B
) y sy
=
1831 let sum = summa
1.0 _N _A _B
in
1832 let dy = float (y - sy
) in
1836 then state.ghyll
<- noghyll
1839 let s = scroll n _N _A _B
in
1840 let y1 = y1 +. ((s *. dy) /. sum) in
1841 gotoy_and_clear_text (truncate
y1);
1842 state.ghyll
<- gf (n+1) y1;
1846 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1848 gf 0 (float state.y)
1851 match conf.ghyllscroll
with
1853 gotoy_and_clear_text y
1855 if state.ghyll
== noghyll
1856 then set nab
y state.y
1857 else state.ghyll
(Some
y)
1860 let gotopage n top =
1861 let y, h = getpageyh n in
1862 let y = y + (truncate
(top *. float h)) in
1866 let gotopage1 n top =
1867 let y = getpagey n in
1872 let invalidate s f =
1877 match state.geomcmds
with
1878 | ps
, [] when String.length ps
= 0 ->
1880 state.geomcmds
<- s, [];
1883 state.geomcmds
<- ps
, [s, f];
1885 | ps
, (s'
, _) :: rest
when s'
= s ->
1886 state.geomcmds
<- ps
, ((s, f) :: rest
);
1889 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1893 Hashtbl.iter
(fun _ opaque
->
1894 wcmd "freepage %s" opaque
;
1896 Hashtbl.clear
state.pagemap
;
1899 let opendoc path password
=
1901 state.password
<- password
;
1902 state.gen
<- state.gen
+ 1;
1903 state.docinfo
<- [];
1906 setaalevel
conf.aalevel
;
1907 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1908 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1909 invalidate "reqlayout"
1911 wcmd "reqlayout %d %d %s\000"
1912 conf.angle
(btod conf.proportional
) state.nameddest
;
1917 state.anchor <- getanchor ();
1918 state.wthack
<- !wtmode;
1919 opendoc state.path
state.password
;
1923 let c = c *. conf.colorscale
in
1927 let scalecolor2 (r, g, b) =
1928 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
1931 let docolumns = function
1933 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1934 let rec loop pageno pdimno pdim
y ph pdims
=
1935 if pageno = state.pagecount
1938 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1940 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1941 pdimno+1, pdim
, rest
1945 let x = max
0 (((state.winw
- state.scrollw
- w) / 2) - xoff
) in
1947 (if conf.presentation
1948 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1949 else (if pageno = 0 then 0 else conf.interpagespace
)
1952 a.(pageno) <- (pdimno, x, y, pdim
);
1953 loop (pageno+1) pdimno pdim
(y + h) h pdims
1955 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1956 conf.columns
<- Csingle
a;
1958 | Cmulti
((columns
, coverA
, coverB
), _) ->
1959 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1960 let rec loop pageno pdimno pdim
x y rowh pdims
=
1961 let rec fixrow m
= if m
= pageno then () else
1962 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1965 let y = y + (rowh
- h) / 2 in
1966 a.(m
) <- (pdimno, x, y, pdim
);
1970 if pageno = state.pagecount
1971 then fixrow (((pageno - 1) / columns
) * columns
)
1973 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1975 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1976 pdimno+1, pdim
, rest
1981 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1983 let x = (state.winw
- state.scrollw
- w) / 2 in
1985 if conf.presentation
then calcips h else conf.interpagespace
in
1986 x, y + ips + rowh
, h
1989 if (pageno - coverA
) mod columns
= 0
1991 let x = max
0 (state.winw
- state.scrollw
- state.w) / 2 in
1993 if conf.presentation
1995 let ips = calcips h in
1996 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1998 y + (if pageno = 0 then 0 else conf.interpagespace
)
2002 else x, y, max rowh
h
2006 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2009 if pageno = columns
&& conf.presentation
2011 let ips = calcips rowh
in
2012 for i
= 0 to pred columns
2014 let (pdimno, x, y, pdim
) = a.(i
) in
2015 a.(i
) <- (pdimno, x, y+ips, pdim
)
2021 fixrow (pageno - columns
);
2026 a.(pageno) <- (pdimno, x, y, pdim
);
2027 let x = x + w + xoff
*2 + conf.interpagespace
in
2028 loop (pageno+1) pdimno pdim
x y rowh' pdims
2030 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2031 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2034 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2035 let rec loop pageno pdimno pdim
y pdims
=
2036 if pageno = state.pagecount
2039 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2041 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2042 pdimno+1, pdim
, rest
2047 let rec loop1 n x y =
2048 if n = c then y else (
2049 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2050 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2053 let y = loop1 0 0 y in
2054 loop (pageno+1) pdimno pdim
y pdims
2056 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2057 conf.columns
<- Csplit
(c, a);
2061 docolumns conf.columns
;
2062 state.maxy
<- calcheight ();
2064 if state.w <= state.winw
- state.scrollw
2068 if state.reprf
== noreprf
2070 let wthack = state.wthack in
2071 begin match state.mode
with
2072 | Birdseye
(_, _, pageno, _, _) ->
2073 let y, h = getpageyh pageno in
2074 let top = (state.winh
- h) / 2 in
2075 gotoy (max
0 (y - top))
2076 | _ -> gotoanchor state.anchor
2078 state.wthack <- wthack;
2079 state.reprf
<- noreprf;
2084 state.wthack <- false;
2085 GlDraw.viewport
0 0 w h;
2086 let firsttime = state.geomcmds
== firstgeomcmds in
2087 if not
firsttime && nogeomcmds state.geomcmds
2088 then state.anchor <- getanchor ();
2091 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2094 setfontsize fstate.fontsize
;
2095 GlMat.mode `modelview
;
2096 GlMat.load_identity
();
2098 GlMat.mode `projection
;
2099 GlMat.load_identity
();
2100 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2101 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2102 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2107 else float state.x /. float state.w
2109 invalidate "geometry"
2113 then state.x <- truncate
(relx *. float w);
2115 match conf.columns
with
2117 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2118 | Csplit
(c, _) -> w * c
2120 wcmd "geometry %d %d" w h);
2124 let len = String.length
state.text in
2127 match state.mode
with
2130 let h, _, _ = state.uioh#scrollpw
in
2136 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2137 (x+.w, float (state.winh
- hscrollh))
2140 let w = float (state.winw
- state.scrollw
- 1) in
2141 if state.progress
>= 0.0 && state.progress
< 1.0
2143 GlDraw.color
(0.3, 0.3, 0.3);
2144 let w1 = w *. state.progress
in
2146 GlDraw.color
(0.0, 0.0, 0.0);
2150 GlDraw.color
(0.0, 0.0, 0.0);
2154 GlDraw.color
(1.0, 1.0, 1.0);
2155 drawstring fstate.fontsize
2156 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2159 match state.mode
with
2160 | Textentry
((prefix
, text, _, _, _, _), _) ->
2164 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2166 Printf.sprintf
"%s%s_" prefix
text
2175 if not
(istextentry state.mode
)
2177 let s1 = "(press 'e' to review error messasges)" in
2178 if String.length
s > 0 then s ^
" " ^
s1 else s1
2183 if String.length
s > 0
2188 let len = Queue.length
state.tilelru
in
2190 match state.throttle
with
2193 then preloadlayout state.y
2195 | Some
(layout, _, _) ->
2199 if state.memused
<= conf.memlimit
2204 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2205 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2206 let (_, pw, ph
, _) = getpagedim n in
2209 && colorspace
= conf.colorspace
2210 && angle
= conf.angle
2214 let x = col*conf.tilew
2215 and y = row*conf.tileh
in
2216 tilevisible (Lazy.force_val
layout) n x y
2218 then Queue.push lruitem
state.tilelru
2221 wcmd "freetile %s" p
;
2222 state.memused
<- state.memused
- s;
2223 state.uioh#infochanged Memused
;
2224 Hashtbl.remove
state.tilemap k
;
2233 Queue.iter
(fun (k
, p
, s) ->
2234 wcmd "freetile %s" p
;
2235 state.memused
<- state.memused
- s;
2236 state.uioh#infochanged Memused
;
2237 Hashtbl.remove
state.tilemap k
;
2239 Queue.clear
state.tilelru
;
2243 let logcurrently = function
2244 | Idle
-> dolog
"Idle"
2245 | Loading
(l
, gen
) ->
2246 dolog
"Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2247 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2249 "Tiling %d[%d,%d] page=%s cs=%s angle"
2250 l
.pageno col row pageopaque
2251 (colorspace_to_string colorspace
)
2253 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2254 angle gen
conf.angle
state.gen
2256 conf.tilew
conf.tileh
2263 let r = Str.regexp
" " in
2264 fun s -> Str.bounded_split
r s 2;
2267 let onpagerect pageno f =
2269 match conf.columns
with
2270 | Cmulti
(_, b) -> b
2272 | Csplit
(_, b) -> b
2274 if pageno >= 0 && pageno < Array.length
b
2276 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2277 let r = getpdimrect
pdimno in
2278 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2281 let gotopagexy pageno x y =
2282 onpagerect pageno (fun w h ->
2284 let _,w1,_,leftx
= getpagedim pageno in
2285 let wh = state.winh
- state.hscrollh in
2286 let sw = float w1 /. w in
2288 let x = leftx
+ state.x + truncate
x in
2290 if x < 0 || x >= state.winw
- state.scrollw
2294 let py, h = getpageyh pageno in
2295 let y'
= py + truncate
(top *. float h) in
2296 let dy = y'
- state.y in
2298 if x != state.x || not
(dy > 0 && dy < wh)
2300 if conf.presentation
2302 if abs
(py - y'
) > wh
2309 if state.x != sx || state.y != sy
2314 let ww = state.winw
- state.scrollw
in
2319 let x = if -x + ww > w1 then -(w1-ww) else x
2320 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2322 if conf.presentation
2324 if abs
(py - y'
) > wh
2335 state.wthack <- !wtmode && not
(layoutready state.layout);
2342 (* dolog "%S" cmds; *)
2343 let cl = splitatspace cmds
in
2345 try Scanf.sscanf
s fmt
f
2347 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2352 state.uioh#infochanged Pdim
;
2355 | "clearrects" :: [] ->
2356 state.rects
<- state.rects1
;
2357 G.postRedisplay "clearrects";
2359 | "continue" :: args :: [] ->
2360 let n = scan args "%u" (fun n -> n) in
2361 state.pagecount
<- n;
2362 begin match state.currently
with
2364 state.currently
<- Idle
;
2365 state.outlines
<- Array.of_list
(List.rev l
)
2369 let cur, cmds
= state.geomcmds
in
2370 if String.length
cur = 0
2371 then failwith
"umpossible";
2373 begin match List.rev cmds
with
2375 state.geomcmds
<- "", [];
2379 state.geomcmds
<- s, List.rev rest
;
2381 if conf.maxwait
= None
2382 then G.postRedisplay "continue";
2384 | "title" :: args :: [] ->
2387 | "msg" :: args :: [] ->
2390 | "vmsg" :: args :: [] ->
2392 then showtext ' '
args
2394 | "emsg" :: args :: [] ->
2395 Buffer.add_string
state.errmsgs
args;
2396 state.newerrmsgs
<- true;
2397 G.postRedisplay "error message"
2399 | "progress" :: args :: [] ->
2400 let progress, text =
2403 f, String.sub
args pos
(String.length
args - pos
))
2406 state.progress <- progress;
2407 G.postRedisplay "progress"
2409 | "firstmatch" :: args :: [] ->
2410 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2411 scan args "%u %d %f %f %f %f %f %f %f %f"
2412 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2413 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2415 let y = (getpagey pageno) + truncate
y0 in
2418 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2420 | "match" :: args :: [] ->
2421 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2422 scan args "%u %d %f %f %f %f %f %f %f %f"
2423 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2424 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2427 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2429 | "page" :: args :: [] ->
2430 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2431 begin match state.currently
with
2432 | Loading
(l
, gen
) ->
2433 vlog "page %d took %f sec" l
.pageno t
;
2434 Hashtbl.replace
state.pagemap
(l
.pageno, gen
) pageopaque;
2435 begin match state.throttle
with
2437 let preloadedpages =
2439 then preloadlayout state.y
2444 Set.Make
(struct type t
= int let compare = (-) end) in
2446 List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
2447 IntSet.empty
preloadedpages
2450 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2451 if not
(IntSet.mem
pageno set)
2453 wcmd "freepage %s" opaque
;
2459 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2462 state.currently
<- Idle
;
2465 tilepage l
.pageno pageopaque state.layout;
2467 load preloadedpages;
2468 if pagevisible state.layout l
.pageno
2469 && layoutready state.layout
2470 then G.postRedisplay "page";
2473 | Some
(layout, _, _) ->
2474 state.currently
<- Idle
;
2475 tilepage l
.pageno pageopaque layout;
2480 dolog
"Inconsistent loading state";
2481 logcurrently state.currently
;
2485 | "tile" :: args :: [] ->
2486 let (x, y, opaque
, size
, t
) =
2487 scan args "%u %u %s %u %f"
2488 (fun x y p size t
-> (x, y, p
, size
, t
))
2490 begin match state.currently
with
2491 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2492 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
2495 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2497 wcmd "freetile %s" opaque
;
2498 state.currently
<- Idle
;
2502 puttileopaque l
col row gen cs angle opaque size t
;
2503 state.memused
<- state.memused
+ size
;
2504 state.uioh#infochanged Memused
;
2506 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
2507 opaque
, size
) state.tilelru
;
2510 match state.throttle
with
2511 | None
-> state.layout
2512 | Some
(layout, _, _) -> layout
2515 state.currently
<- Idle
;
2517 && conf.colorspace
= cs
2518 && conf.angle
= angle
2519 && tilevisible layout l
.pageno x y
2520 then conttiling l
.pageno pageopaque;
2522 begin match state.throttle
with
2525 then state.wthack <- not
(layoutready state.layout);
2526 preload state.layout;
2528 && conf.colorspace
= cs
2529 && conf.angle
= angle
2530 && tilevisible state.layout l
.pageno x y
2531 then G.postRedisplay "tile nothrottle";
2533 | Some
(layout, y, _) ->
2534 let ready = layoutready layout in
2537 state.wthack <- false;
2539 state.layout <- layout;
2540 state.throttle
<- None
;
2541 G.postRedisplay "throttle";
2548 dolog
"Inconsistent tiling state";
2549 logcurrently state.currently
;
2553 | "pdim" :: args :: [] ->
2555 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2557 state.uioh#infochanged Pdim
;
2558 state.pdims
<- pdim :: state.pdims
2560 | "o" :: args :: [] ->
2561 let (l
, n, t
, h, pos
) =
2562 scan args "%u %u %d %u %n"
2563 (fun l
n t
h pos
-> l
, n, t
, h, pos
)
2565 let s = String.sub
args pos
(String.length
args - pos
) in
2566 let outline = (s, l
, (n, float t
/. float h, 0.0)) in
2567 begin match state.currently
with
2568 | Outlining outlines
->
2569 state.currently
<- Outlining
(outline :: outlines
)
2571 state.currently
<- Outlining
[outline]
2573 dolog
"invalid outlining state";
2574 logcurrently currently
2577 | "a" :: args :: [] ->
2579 scan args "%u %d %d" (fun n l t
-> n, l
, t
)
2581 state.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
2583 | "info" :: args :: [] ->
2584 state.docinfo
<- (1, args) :: state.docinfo
2586 | "infoend" :: [] ->
2587 state.uioh#infochanged Docinfo
;
2588 state.docinfo
<- List.rev
state.docinfo
2591 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2596 let action = function
2597 | HCprev
-> cbget cb ~
-1
2598 | HCnext
-> cbget cb
1
2599 | HCfirst
-> cbget cb ~
-(cb
.rc)
2600 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2601 and cancel
() = cb
.rc <- rc
2605 let search pattern forward
=
2606 if String.length pattern
> 0
2609 match state.layout with
2612 l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
2614 wcmd "search %d %d %d %d,%s\000"
2615 (btod conf.icase
) pn py (btod forward
) pattern
;
2618 let intentry text key =
2620 if key >= 32 && key < 127
2626 let text = addchar text c in
2630 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2634 let linknentry text key =
2636 if key >= 32 && key < 127
2642 let text = addchar text c in
2646 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2651 if String.length
s > 0
2654 let l = String.length
s in
2655 let rec loop pos
n = if pos
= l then n else
2656 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2657 loop (pos
+1) (n*26 + m)
2660 let rec loop n = function
2663 match getopaque l.pageno with
2664 | None
-> loop n rest
2666 let m = getlinkcount opaque
in
2669 let under = getlink opaque
n in
2672 else loop (n-m) rest
2674 loop n state.layout;
2678 let textentry text key =
2679 if key land 0xff00 = 0xff00
2681 else TEcont
(text ^ toutf8
key)
2684 let reqlayout angle proportional
=
2685 match state.throttle
with
2687 if nogeomcmds state.geomcmds
2688 then state.anchor <- getanchor ();
2689 conf.angle
<- angle
mod 360;
2692 match state.mode
with
2693 | LinkNav
_ -> state.mode
<- View
2696 conf.proportional
<- proportional
;
2697 invalidate "reqlayout"
2698 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2702 let settrim trimmargins trimfuzz
=
2703 if nogeomcmds state.geomcmds
2704 then state.anchor <- getanchor ();
2705 conf.trimmargins
<- trimmargins
;
2706 conf.trimfuzz
<- trimfuzz
;
2707 let x0, y0, x1, y1 = trimfuzz
in
2708 invalidate "settrim"
2710 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2715 match state.throttle
with
2717 let zoom = max
0.01 zoom in
2718 if zoom <> conf.zoom
2720 state.prevzoom
<- conf.zoom;
2722 reshape state.winw
state.winh
;
2723 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2726 | Some
(layout, y, started
) ->
2728 match conf.maxwait
with
2732 let dt = now () -. started
in
2740 let setcolumns mode columns coverA coverB
=
2741 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2745 then showtext '
!'
"split mode doesn't work in bird's eye"
2747 conf.columns
<- Csplit
(-columns
, [||]);
2755 conf.columns
<- Csingle
[||];
2760 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2764 reshape state.winw
state.winh
;
2767 let enterbirdseye () =
2768 let zoom = float conf.thumbw
/. float state.winw
in
2769 let birdseyepageno =
2770 let cy = state.winh
/ 2 in
2774 let rec fold best
= function
2777 let d = cy - (l.pagedispy + l.pagevh/2)
2778 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2779 if abs
d < abs dbest
2786 state.mode
<- Birdseye
(
2787 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2790 conf.presentation
<- false;
2791 conf.interpagespace
<- 10;
2792 conf.hlinks
<- false;
2794 state.mstate
<- Mnone
;
2795 conf.maxwait
<- None
;
2797 match conf.beyecolumns
with
2800 Cmulti
((c, 0, 0), [||])
2801 | None
-> Csingle
[||]
2803 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2806 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2811 reshape state.winw
state.winh
;
2814 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2816 conf.zoom <- c.zoom;
2817 conf.presentation
<- c.presentation
;
2818 conf.interpagespace
<- c.interpagespace
;
2819 conf.maxwait
<- c.maxwait
;
2820 conf.hlinks
<- c.hlinks
;
2821 conf.beyecolumns
<- (
2822 match conf.columns
with
2823 | Cmulti
((c, _, _), _) -> Some
c
2825 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2828 match c.columns
with
2829 | Cmulti
(c, _) -> Cmulti
(c, [||])
2830 | Csingle
_ -> Csingle
[||]
2831 | Csplit
(c, _) -> Csplit
(c, [||])
2836 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2839 reshape state.winw
state.winh
;
2840 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2843 let togglebirdseye () =
2844 match state.mode
with
2845 | Birdseye vals
-> leavebirdseye vals
true
2846 | View
-> enterbirdseye ()
2850 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2851 let pageno = max
0 (pageno - incr
) in
2852 let rec loop = function
2853 | [] -> gotopage1 pageno 0
2854 | l :: _ when l.pageno = pageno ->
2855 if l.pagedispy >= 0 && l.pagey = 0
2856 then G.postRedisplay "upbirdseye"
2857 else gotopage1 pageno 0
2858 | _ :: rest
-> loop rest
2861 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2864 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2865 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2866 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2867 let rec loop = function
2869 let y, h = getpageyh pageno in
2870 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2872 | l :: _ when l.pageno = pageno ->
2873 if l.pagevh != l.pageh
2874 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2875 else G.postRedisplay "downbirdseye"
2876 | _ :: rest
-> loop rest
2881 let optentry mode
_ key =
2882 let btos b = if b then "on" else "off" in
2883 if key >= 32 && key < 127
2885 let c = Char.chr
key in
2889 try conf.scrollstep
<- int_of_string
s with exc
->
2890 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2892 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2897 conf.autoscrollstep
<- int_of_string
s;
2898 if state.autoscroll
<> None
2899 then state.autoscroll
<- Some
conf.autoscrollstep
2901 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2903 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2908 let n, a, b = multicolumns_of_string s in
2909 setcolumns mode
n a b;
2911 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
2913 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2918 let zoom = float (int_of_string
s) /. 100.0 in
2921 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2923 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2928 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2930 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2931 begin match mode
with
2933 leavebirdseye beye
false;
2938 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2940 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2945 Some
(int_of_string
s)
2947 state.text <- Printf.sprintf
"bad integer `%s': %s"
2951 | Some angle
-> reqlayout angle
conf.proportional
2954 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2957 conf.icase
<- not
conf.icase
;
2958 TEdone
("case insensitive search " ^
(btos conf.icase
))
2961 conf.preload <- not
conf.preload;
2963 TEdone
("preload " ^
(btos conf.preload))
2966 conf.verbose
<- not
conf.verbose
;
2967 TEdone
("verbose " ^
(btos conf.verbose
))
2970 conf.debug
<- not
conf.debug
;
2971 TEdone
("debug " ^
(btos conf.debug
))
2974 conf.maxhfit
<- not
conf.maxhfit
;
2975 state.maxy
<- calcheight ();
2976 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2979 conf.crophack
<- not
conf.crophack
;
2980 TEdone
("crophack " ^
btos conf.crophack
)
2984 match conf.maxwait
with
2986 conf.maxwait
<- Some infinity
;
2987 "always wait for page to complete"
2989 conf.maxwait
<- None
;
2990 "show placeholder if page is not ready"
2995 conf.underinfo
<- not
conf.underinfo
;
2996 TEdone
("underinfo " ^
btos conf.underinfo
)
2999 conf.savebmarks
<- not
conf.savebmarks
;
3000 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3006 match state.layout with
3011 conf.interpagespace
<- int_of_string
s;
3012 docolumns conf.columns
;
3013 state.maxy
<- calcheight ();
3014 let y = getpagey pageno in
3017 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3019 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3022 reqlayout conf.angle
(not
conf.proportional
);
3023 TEdone
("proportional display " ^
btos conf.proportional
)
3026 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3027 TEdone
("trim margins " ^
btos conf.trimmargins
)
3030 conf.invert
<- not
conf.invert
;
3031 TEdone
("invert colors " ^
btos conf.invert
)
3035 cbput state.hists
.sel
s;
3038 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3039 textentry, ondone, true)
3042 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3048 class type lvsource
= object
3049 method getitemcount
: int
3050 method getitem
: int -> (string * int)
3051 method hasaction
: int -> bool
3060 method getactive
: int
3061 method getfirst
: int
3062 method getqsearch
: string
3063 method setqsearch
: string -> unit
3067 class virtual lvsourcebase
= object
3068 val mutable m_active
= 0
3069 val mutable m_first
= 0
3070 val mutable m_qsearch
= ""
3071 val mutable m_pan
= 0
3072 method getactive
= m_active
3073 method getfirst
= m_first
3074 method getqsearch
= m_qsearch
3075 method getpan
= m_pan
3076 method setqsearch
s = m_qsearch
<- s
3079 let withoutlastutf8 s =
3080 let len = String.length
s in
3088 let b = Char.code
s.[pos
] in
3089 if b land 0b11000000 = 0b11000000
3094 if Char.code
s.[len-1] land 0x80 = 0
3098 String.sub
s 0 first;
3101 let textentrykeyboard
3102 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3104 if key >= 0xffb0 && key <= 0xffb9
3105 then key - 0xffb0 + 48 else key
3108 state.mode
<- Textentry
(te
, onleave
);
3111 G.postRedisplay "textentrykeyboard enttext";
3113 let histaction cmd
=
3116 | Some
(action, _) ->
3117 state.mode
<- Textentry
(
3118 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3120 G.postRedisplay "textentry histaction"
3123 | 0xff08 -> (* backspace *)
3124 let s = withoutlastutf8 text in
3125 let len = String.length
s in
3126 if cancelonempty
&& len = 0
3129 G.postRedisplay "textentrykeyboard after cancel";
3132 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3135 | 0xff0d | 0xff8d -> (* (kp) enter *)
3138 G.postRedisplay "textentrykeyboard after confirm"
3140 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3141 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3142 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3143 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3145 | 0xff1b -> (* escape*)
3146 if String.length
text = 0
3148 begin match opthist
with
3150 | Some
(_, onhistcancel
) -> onhistcancel
()
3154 G.postRedisplay "textentrykeyboard after cancel2"
3157 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3160 | 0xff9f | 0xffff -> () (* delete *)
3163 && key land 0xff00 != 0xff00 (* keyboard *)
3164 && key land 0xfe00 != 0xfe00 (* xkb *)
3165 && key land 0xfd00 != 0xfd00 (* 3270 *)
3167 begin match onkey
text key with
3171 G.postRedisplay "textentrykeyboard after confirm2";
3174 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3178 G.postRedisplay "textentrykeyboard after cancel3"
3181 state.mode
<- Textentry
(te
, onleave
);
3182 G.postRedisplay "textentrykeyboard switch";
3186 vlog "unhandled key %s" (Wsi.keyname
key)
3189 let firstof first active
=
3190 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3191 then max
0 (active
- (fstate.maxrows
/2))
3195 let calcfirst first active
=
3198 let rows = active
- first in
3199 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3203 let scrollph y maxy
=
3204 let sh = (float (maxy
+ state.winh
) /. float state.winh
) in
3205 let sh = float state.winh
/. sh in
3206 let sh = max
sh (float conf.scrollh
) in
3211 else float y /. float maxy
3213 let position = (float state.winh
-. sh) *. percent in
3216 if position +. sh > float state.winh
3217 then float state.winh
-. sh
3223 let coe s = (s :> uioh
);;
3225 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3227 val m_pan
= source#getpan
3228 val m_first
= source#getfirst
3229 val m_active
= source#getactive
3230 val m_qsearch
= source#getqsearch
3231 val m_prev_uioh
= state.uioh
3233 method private elemunder
y =
3234 let n = y / (fstate.fontsize
+1) in
3235 if m_first
+ n < source#getitemcount
3237 if source#hasaction
(m_first
+ n)
3238 then Some
(m_first
+ n)
3245 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3246 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3247 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3248 GlDraw.color
(1., 1., 1.);
3249 Gl.enable `texture_2d
;
3250 let fs = fstate.fontsize
in
3252 let ww = fstate.wwidth
in
3253 let tabw = 30.0*.ww in
3254 let itemcount = source#getitemcount
in
3256 if (row - m_first
) > fstate.maxrows
3259 if row >= 0 && row < itemcount
3261 let (s, level
) = source#getitem
row in
3262 let y = (row - m_first
) * nfs in
3263 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3266 Gl.disable `texture_2d
;
3267 GlDraw.polygon_mode `both `line
;
3268 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3269 GlDraw.rect (1., float (y + 1))
3270 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3271 GlDraw.polygon_mode `both `fill
;
3272 GlDraw.color
(1., 1., 1.);
3273 Gl.enable `texture_2d
;
3276 let drawtabularstring s =
3277 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3280 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3283 let len = String.length
s - tabpos - 1 in
3284 let s1 = String.sub
s 0 tabpos
3285 and s2
= String.sub
s (tabpos + 1) len in
3286 let nx = drawstr x s1 in
3288 let x = x +. (max
tabw sw) in
3295 let _ = drawtabularstring s in
3302 Gl.disable `texture_2d
;
3304 method updownlevel incr
=
3305 let len = source#getitemcount
in
3307 if m_active
>= 0 && m_active
< len
3308 then snd
(source#getitem m_active
)
3312 if i
= len then i
-1 else if i
= -1 then 0 else
3313 let _, l = source#getitem i
in
3314 if l != curlevel then i
else flow (i
+incr
)
3316 let active = flow m_active
in
3317 let first = calcfirst m_first
active in
3318 G.postRedisplay "outline updownlevel";
3319 {< m_active
= active; m_first
= first >}
3321 method private key1
key mask
=
3322 let set1 active first qsearch
=
3323 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3325 let search active pattern incr
=
3328 if n >= 0 && n < source#getitemcount
3330 let s, _ = source#getitem
n in
3332 (try ignore
(Str.search_forward
re s 0); true
3333 with Not_found
-> false)
3335 else loop (n + incr
)
3342 let re = Str.regexp_case_fold pattern
in
3348 let itemcount = source#getitemcount
in
3349 let find start incr
=
3351 if i
= -1 || i
= itemcount
3354 if source#hasaction i
3356 else find (i
+ incr
)
3361 let set active first =
3362 let first = bound first 0 (itemcount - fstate.maxrows
) in
3364 coe {< m_active
= active; m_first
= first >}
3367 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3369 let incr1 = if incr
> 0 then 1 else -1 in
3370 if isvisible m_first m_active
3373 let next = m_active
+ incr
in
3375 if next < 0 || next >= itemcount
3377 else find next incr1
3379 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3385 let first = m_first
+ incr
in
3386 let first = bound first 0 (itemcount - 1) in
3388 let next = m_active
+ incr
in
3389 let next = bound next 0 (itemcount - 1) in
3392 let active = if next = -1 then m_active
else next in
3395 let first = min
next m_first
in
3397 if abs
(next - first) > fstate.maxrows
3403 let first = m_first
+ incr
in
3404 let first = bound first 0 (itemcount - 1) in
3406 let next = m_active
+ incr
in
3407 let next = bound next 0 (itemcount - 1) in
3408 let next = find next incr1 in
3410 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3412 let active = if m_active
= -1 then next else m_active
in
3417 if isvisible first active
3423 G.postRedisplay "listview navigate";
3427 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3428 let incr = if key = 0x72 then -1 else 1 in
3430 match search (m_active
+ incr) m_qsearch
incr with
3432 state.text <- m_qsearch ^
" [not found]";
3435 state.text <- m_qsearch
;
3436 active, firstof m_first
active
3438 G.postRedisplay "listview ctrl-r/s";
3439 set1 active first m_qsearch
;
3441 | 0xff08 -> (* backspace *)
3442 if String.length m_qsearch
= 0
3445 let qsearch = withoutlastutf8 m_qsearch
in
3446 let len = String.length
qsearch in
3450 G.postRedisplay "listview empty qsearch";
3451 set1 m_active m_first
"";
3455 match search m_active
qsearch ~
-1 with
3457 state.text <- qsearch ^
" [not found]";
3460 state.text <- qsearch;
3461 active, firstof m_first
active
3463 G.postRedisplay "listview backspace qsearch";
3464 set1 active first qsearch
3467 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3468 let pattern = m_qsearch ^ toutf8
key in
3470 match search m_active
pattern 1 with
3472 state.text <- pattern ^
" [not found]";
3475 state.text <- pattern;
3476 active, firstof m_first
active
3478 G.postRedisplay "listview qsearch add";
3479 set1 active first pattern;
3481 | 0xff1b -> (* escape *)
3483 if String.length m_qsearch
= 0
3485 G.postRedisplay "list view escape";
3488 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3490 | None
-> m_prev_uioh
3495 G.postRedisplay "list view kill qsearch";
3496 source#setqsearch
"";
3497 coe {< m_qsearch
= "" >}
3500 | 0xff0d | 0xff8d -> (* (kp) enter *)
3502 let self = {< m_qsearch
= "" >} in
3503 source#setqsearch
"";
3505 G.postRedisplay "listview enter";
3506 if m_active
>= 0 && m_active
< source#getitemcount
3508 source#exit
(coe self) false m_active m_first m_pan
"";
3511 source#exit
(coe self) true m_active m_first m_pan
"";
3514 begin match opt with
3515 | None
-> m_prev_uioh
3519 | 0xff9f | 0xffff -> (* (kp) delete *)
3522 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3523 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3524 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3525 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3527 | 0xff53 | 0xff98 -> (* (kp) right *)
3529 G.postRedisplay "listview right";
3530 coe {< m_pan
= m_pan
- 1 >}
3532 | 0xff51 | 0xff96 -> (* (kp) left *)
3534 G.postRedisplay "listview left";
3535 coe {< m_pan
= m_pan
+ 1 >}
3537 | 0xff50 | 0xff95 -> (* (kp) home *)
3538 let active = find 0 1 in
3539 G.postRedisplay "listview home";
3542 | 0xff57 | 0xff9c -> (* (kp) end *)
3543 let first = max
0 (itemcount - fstate.maxrows
) in
3544 let active = find (itemcount - 1) ~
-1 in
3545 G.postRedisplay "listview end";
3548 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3552 dolog
"listview unknown key %#x" key; coe self
3554 method key key mask
=
3555 match state.mode
with
3556 | Textentry te
-> textentrykeyboard key mask te
; coe self
3557 | _ -> self#key1
key mask
3559 method button button down
x y _ =
3562 | 1 when x > state.winw
- conf.scrollbw
->
3563 G.postRedisplay "listview scroll";
3566 let _, position, sh = self#
scrollph in
3567 if y > truncate
position && y < truncate
(position +. sh)
3569 state.mstate
<- Mscrolly
;
3573 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3574 let first = truncate
(s *. float source#getitemcount
) in
3575 let first = min source#getitemcount
first in
3576 Some
(coe {< m_first
= first; m_active
= first >})
3578 state.mstate
<- Mnone
;
3581 | 1 when not down
->
3582 begin match self#elemunder
y with
3584 G.postRedisplay "listview click";
3586 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3590 | n when (n == 4 || n == 5) && not down
->
3591 let len = source#getitemcount
in
3593 if n = 5 && m_first
+ fstate.maxrows
>= len
3597 let first = m_first
+ (if n == 4 then -1 else 1) in
3598 bound first 0 (len - 1)
3600 G.postRedisplay "listview wheel";
3601 Some
(coe {< m_first
= first >})
3602 | n when (n = 6 || n = 7) && not down
->
3603 let inc = m_first
+ (if n = 7 then -1 else 1) in
3604 G.postRedisplay "listview hwheel";
3605 Some
(coe {< m_pan
= m_pan
+ inc >})
3610 | None
-> m_prev_uioh
3614 match state.mstate
with
3616 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3617 let first = truncate
(s *. float source#getitemcount
) in
3618 let first = min source#getitemcount
first in
3619 G.postRedisplay "listview motion";
3620 coe {< m_first
= first; m_active
= first >}
3623 method pmotion
x y =
3624 if x < state.winw
- conf.scrollbw
3627 match self#elemunder
y with
3628 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3629 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3633 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3638 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3642 method infochanged
_ = ()
3644 method scrollpw
= (0, 0.0, 0.0)
3646 let nfs = fstate.fontsize
+ 1 in
3647 let y = m_first
* nfs in
3648 let itemcount = source#getitemcount
in
3649 let maxi = max
0 (itemcount - fstate.maxrows
) in
3650 let maxy = maxi * nfs in
3651 let p, h = scrollph y maxy in
3654 method modehash
= modehash
3657 class outlinelistview ~source
=
3660 ~source
:(source
:> lvsource
)
3662 ~modehash
:(findkeyhash conf "outline")
3665 method key key mask
=
3666 let calcfirst first active =
3669 let rows = active - first in
3671 if String.length
state.text = 0
3673 else fstate.maxrows - 2
3675 if rows > maxrows then active - maxrows else first
3679 let active = m_active
+ incr in
3680 let active = bound active 0 (source#getitemcount
- 1) in
3681 let first = calcfirst m_first
active in
3682 G.postRedisplay "outline navigate";
3683 coe {< m_active
= active; m_first
= first >}
3685 let ctrl = Wsi.withctrl mask
in
3687 | 110 when ctrl -> (* ctrl-n *)
3688 source#narrow m_qsearch
;
3689 G.postRedisplay "outline ctrl-n";
3690 coe {< m_first
= 0; m_active
= 0 >}
3692 | 117 when ctrl -> (* ctrl-u *)
3694 G.postRedisplay "outline ctrl-u";
3696 coe {< m_first
= 0; m_active
= 0 >}
3698 | 108 when ctrl -> (* ctrl-l *)
3699 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3700 G.postRedisplay "outline ctrl-l";
3701 coe {< m_first
= first >}
3703 | 0xff9f | 0xffff -> (* (kp) delete *)
3704 source#remove m_active
;
3705 G.postRedisplay "outline delete";
3706 let active = max
0 (m_active
-1) in
3707 coe {< m_first
= firstof m_first
active;
3708 m_active
= active >}
3710 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3711 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3712 | 0xff55 | 0xff9a -> (* (kp) prior *)
3713 navigate ~
-(fstate.maxrows)
3714 | 0xff56 | 0xff9b -> (* (kp) next *)
3715 navigate fstate.maxrows
3717 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3721 G.postRedisplay "outline ctrl right";
3722 {< m_pan
= m_pan
+ 1 >}
3724 else self#updownlevel
1
3728 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3732 G.postRedisplay "outline ctrl left";
3733 {< m_pan
= m_pan
- 1 >}
3735 else self#updownlevel ~
-1
3739 | 0xff50 | 0xff95 -> (* (kp) home *)
3740 G.postRedisplay "outline home";
3741 coe {< m_first
= 0; m_active
= 0 >}
3743 | 0xff57 | 0xff9c -> (* (kp) end *)
3744 let active = source#getitemcount
- 1 in
3745 let first = max
0 (active - fstate.maxrows) in
3746 G.postRedisplay "outline end";
3747 coe {< m_active
= active; m_first
= first >}
3749 | _ -> super#
key key mask
3752 let outlinesource usebookmarks
=
3755 inherit lvsourcebase
3756 val mutable m_items
= empty
3757 val mutable m_orig_items
= empty
3758 val mutable m_prev_items
= empty
3759 val mutable m_narrow_pattern
= ""
3760 val mutable m_hadremovals
= false
3762 method getitemcount
=
3763 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3766 if n == Array.length m_items
&& m_hadremovals
3768 ("[Confirm removal]", 0)
3770 let s, n, _ = m_items
.(n) in
3773 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3774 ignore
(uioh
, first, qsearch);
3775 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3777 if String.length m_narrow_pattern
= 0
3783 if not
confrimremoval
3785 let _, _, anchor = m_items
.(active) in
3786 gotoghyll (getanchory anchor);
3790 state.bookmarks
<- Array.to_list m_items
;
3791 m_orig_items
<- m_items
;
3794 else m_items
<- items;
3798 method hasaction
_ = true
3801 if Array.length m_items
!= Array.length m_orig_items
3802 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3805 method narrow
pattern =
3806 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3810 let rec loop accu n =
3813 m_narrow_pattern
<- pattern;
3814 m_items
<- Array.of_list
accu
3817 let (s, _, _) as o = m_items
.(n) in
3819 if (try ignore
(Str.search_forward
re s 0); true
3820 with Not_found
-> false)
3826 loop [] (Array.length m_items
- 1)
3831 then Array.of_list
state.bookmarks
3834 m_items
<- m_orig_items
3839 if m >= 0 && m < Array.length m_items
3841 m_hadremovals
<- true;
3842 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3843 let n = if n >= m then n+1 else n in
3848 method reset
anchor items =
3849 m_hadremovals
<- false;
3850 if m_orig_items
== empty || m_prev_items
!= items
3852 m_orig_items
<- items;
3853 if String.length m_narrow_pattern
= 0
3854 then m_items
<- items;
3856 m_prev_items
<- items;
3857 let rely = getanchory anchor in
3859 let rec loop n best bestd
=
3860 if n = Array.length m_items
3863 let (_, _, anchor) = m_items
.(n) in
3864 let orely = getanchory anchor in
3865 let d = abs
(orely - rely) in
3868 else loop (n+1) best bestd
3873 m_first
<- firstof m_first
active
3877 let enterselector usebookmarks
=
3878 let source = outlinesource usebookmarks
in
3882 then Array.of_list
state.bookmarks
3885 if Array.length
outlines = 0
3887 showtext ' ' errmsg
;
3890 state.text <- source#greetmsg
;
3891 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3892 let anchor = getanchor () in
3893 source#reset
anchor outlines;
3894 state.uioh
<- coe (new outlinelistview ~
source);
3895 G.postRedisplay "enter selector";
3899 let enteroutlinemode =
3900 let f = enterselector false in
3901 fun ()-> f "Document has no outline";
3904 let enterbookmarkmode =
3905 let f = enterselector true in
3906 fun () -> f "Document has no bookmarks (yet)";
3909 let color_of_string s =
3910 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
3911 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
3915 let color_to_string (r, g, b) =
3916 let r = truncate
(r *. 256.0)
3917 and g = truncate
(g *. 256.0)
3918 and b = truncate
(b *. 256.0) in
3919 Printf.sprintf
"%d/%d/%d" r g b
3922 let irect_of_string s =
3923 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3926 let irect_to_string (x0,y0,x1,y1) =
3927 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3930 let makecheckers () =
3931 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3933 converted by Issac Trotts. July 25, 2002 *)
3934 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3935 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3936 let id = GlTex.gen_texture
() in
3937 GlTex.bind_texture `texture_2d
id;
3938 GlPix.store
(`unpack_alignment
1);
3939 GlTex.image2d
image;
3940 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3941 [ `mag_filter `nearest
; `min_filter `nearest
];
3945 let setcheckers enabled
=
3946 match state.texid
with
3948 if enabled
then state.texid
<- Some
(makecheckers ())
3953 GlTex.delete_texture texid
;
3954 state.texid
<- None
;
3958 let int_of_string_with_suffix s =
3959 let l = String.length
s in
3963 let suffix = Char.lowercase
s.[l-1] in
3965 | 'k'
-> String.sub
s 0 (l-1), 10
3966 | '
m'
-> String.sub
s 0 (l-1), 20
3967 | '
g'
-> String.sub
s 0 (l-1), 30
3971 let n = int_of_string
s1 in
3972 let m = n lsl shift
in
3974 then raise
(Failure
"value too large")
3978 let string_with_suffix_of_int n =
3983 if n land ((1 lsl 30) - 1) = 0
3986 if n land ((1 lsl 20) - 1) = 0
3989 if n land ((1 lsl 10) - 1) = 0
3996 let h = n mod 1000 in
3999 then string_of_int
h ^
s
4001 let s = Printf.sprintf
"_%03d%s" h s in
4008 let defghyllscroll = (40, 8, 32);;
4009 let ghyllscroll_of_string s =
4010 let (n, a, b) as nab
=
4013 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4015 if n <= a || n <= b || a >= b
4016 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4020 let ghyllscroll_to_string ((n, a, b) as nab
) =
4021 if nab
= defghyllscroll
4023 else Printf.sprintf
"%d,%d,%d" n a b;
4026 let describe_location () =
4028 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
4030 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
4031 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4035 else (100. *. (float state.y /. float maxy))
4039 Printf.sprintf
"page %d of %d [%.2f%%]"
4040 (fn+1) state.pagecount
percent
4043 "pages %d-%d of %d [%.2f%%]"
4044 (fn+1) (ln
+1) state.pagecount
percent
4047 let setpresentationmode v
=
4048 let n = page_of_y state.y in
4049 state.anchor <- (n, 0.0, 1.0);
4050 conf.presentation
<- v
;
4051 if conf.presentation
4053 if not
conf.scrollbarinpm
4054 then state.scrollw
<- 0;
4056 else state.scrollw
<- conf.scrollbw
;
4061 let btos b = if b then "\xe2\x88\x9a" else "" in
4062 let showextended = ref false in
4063 let leave mode
= function
4064 | Confirm
-> state.mode
<- mode
4065 | Cancel
-> state.mode
<- mode
in
4068 val mutable m_first_time
= true
4069 val mutable m_l
= []
4070 val mutable m_a
= [||]
4071 val mutable m_prev_uioh
= nouioh
4072 val mutable m_prev_mode
= View
4074 inherit lvsourcebase
4076 method reset prev_mode prev_uioh
=
4077 m_a
<- Array.of_list
(List.rev m_l
);
4079 m_prev_mode
<- prev_mode
;
4080 m_prev_uioh
<- prev_uioh
;
4084 if n >= Array.length m_a
4088 | _, _, _, Action
_ -> m_active
<- n
4092 m_first_time
<- false;
4095 method int name get
set =
4097 (name
, `
int get
, 1, Action
(
4100 try set (int_of_string
s)
4102 state.text <- Printf.sprintf
"bad integer `%s': %s"
4106 let te = name ^
": ", "", None
, intentry, ondone, true in
4107 state.mode
<- Textentry
(te, leave m_prev_mode
);
4111 method int_with_suffix name get
set =
4113 (name
, `intws get
, 1, Action
(
4116 try set (int_of_string_with_suffix s)
4118 state.text <- Printf.sprintf
"bad integer `%s': %s"
4123 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4125 state.mode
<- Textentry
(te, leave m_prev_mode
);
4129 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4131 (name
, `
bool (btos, get
), offset
, Action
(
4138 method color name get
set =
4140 (name
, `color get
, 1, Action
(
4142 let invalid = (nan
, nan
, nan
) in
4145 try color_of_string s
4147 state.text <- Printf.sprintf
"bad color `%s': %s"
4154 let te = name ^
": ", "", None
, textentry, ondone, true in
4155 state.text <- color_to_string (get
());
4156 state.mode
<- Textentry
(te, leave m_prev_mode
);
4160 method string name get
set =
4162 (name
, `
string get
, 1, Action
(
4164 let ondone s = set s in
4165 let te = name ^
": ", "", None
, textentry, ondone, true in
4166 state.mode
<- Textentry
(te, leave m_prev_mode
);
4170 method colorspace name get
set =
4172 (name
, `
string get
, 1, Action
(
4175 let vals = [| "rgb"; "bgr"; "gray" |] in
4177 inherit lvsourcebase
4180 m_active
<- int_of_colorspace conf.colorspace
;
4183 method getitemcount
= Array.length
vals
4184 method getitem
n = (vals.(n), 0)
4185 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4186 ignore
(uioh
, first, pan
, qsearch);
4187 if not cancel
then set active;
4189 method hasaction
_ = true
4193 let modehash = findkeyhash conf "info" in
4194 coe (new listview ~
source ~trusted
:true ~
modehash)
4197 method caption
s offset
=
4198 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4200 method caption2
s f offset
=
4201 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4203 method getitemcount
= Array.length m_a
4206 let tostr = function
4207 | `
int f -> string_of_int
(f ())
4208 | `intws
f -> string_with_suffix_of_int (f ())
4210 | `color
f -> color_to_string (f ())
4211 | `
bool (btos, f) -> btos (f ())
4214 let name, t
, offset
, _ = m_a
.(n) in
4215 ((let s = tostr t
in
4216 if String.length
s > 0
4217 then Printf.sprintf
"%s\t%s" name s
4221 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4225 m_qsearch
<- qsearch;
4227 match m_a
.(active) with
4228 | _, _, _, Action
f -> f uioh
4240 method hasaction
n =
4242 | _, _, _, Action
_ -> true
4246 let rec fillsrc prevmode prevuioh
=
4247 let sep () = src#caption
"" 0 in
4248 let colorp name get
set =
4250 (fun () -> color_to_string (get
()))
4253 let c = color_of_string v in
4256 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4259 let oldmode = state.mode
in
4260 let birdseye = isbirdseye state.mode
in
4262 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4264 src#
bool "presentation mode"
4265 (fun () -> conf.presentation
)
4266 (fun v -> setpresentationmode v);
4268 src#
bool "ignore case in searches"
4269 (fun () -> conf.icase
)
4270 (fun v -> conf.icase
<- v);
4273 (fun () -> conf.preload)
4274 (fun v -> conf.preload <- v);
4276 src#
bool "highlight links"
4277 (fun () -> conf.hlinks
)
4278 (fun v -> conf.hlinks
<- v);
4280 src#
bool "under info"
4281 (fun () -> conf.underinfo
)
4282 (fun v -> conf.underinfo
<- v);
4284 src#
bool "persistent bookmarks"
4285 (fun () -> conf.savebmarks
)
4286 (fun v -> conf.savebmarks
<- v);
4288 src#
bool "proportional display"
4289 (fun () -> conf.proportional
)
4290 (fun v -> reqlayout conf.angle
v);
4292 src#
bool "trim margins"
4293 (fun () -> conf.trimmargins
)
4294 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4296 src#
bool "persistent location"
4297 (fun () -> conf.jumpback
)
4298 (fun v -> conf.jumpback
<- v);
4301 src#
int "inter-page space"
4302 (fun () -> conf.interpagespace
)
4304 conf.interpagespace
<- n;
4305 docolumns conf.columns
;
4307 match state.layout with
4312 state.maxy <- calcheight ();
4313 let y = getpagey pageno in
4318 (fun () -> conf.pagebias
)
4319 (fun v -> conf.pagebias
<- v);
4321 src#
int "scroll step"
4322 (fun () -> conf.scrollstep
)
4323 (fun n -> conf.scrollstep
<- n);
4325 src#
int "horizontal scroll step"
4326 (fun () -> conf.hscrollstep
)
4327 (fun v -> conf.hscrollstep
<- v);
4329 src#
int "auto scroll step"
4331 match state.autoscroll
with
4333 | _ -> conf.autoscrollstep
)
4335 if state.autoscroll
<> None
4336 then state.autoscroll
<- Some
n;
4337 conf.autoscrollstep
<- n);
4340 (fun () -> truncate
(conf.zoom *. 100.))
4341 (fun v -> setzoom ((float v) /. 100.));
4344 (fun () -> conf.angle
)
4345 (fun v -> reqlayout v conf.proportional
);
4347 src#
int "scroll bar width"
4348 (fun () -> state.scrollw
)
4352 reshape state.winw
state.winh
;
4355 src#
int "scroll handle height"
4356 (fun () -> conf.scrollh
)
4357 (fun v -> conf.scrollh
<- v;);
4359 src#
int "thumbnail width"
4360 (fun () -> conf.thumbw
)
4362 conf.thumbw
<- min
4096 v;
4365 leavebirdseye beye
false;
4370 let mode = state.mode in
4371 src#
string "columns"
4373 match conf.columns
with
4375 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4376 | Csplit
(count
, _) -> "-" ^ string_of_int count
4379 let n, a, b = multicolumns_of_string v in
4380 setcolumns mode n a b);
4383 src#caption
"Presentation mode" 0;
4384 src#
bool "scrollbar visible"
4385 (fun () -> conf.scrollbarinpm
)
4387 if v != conf.scrollbarinpm
4389 conf.scrollbarinpm
<- v;
4390 if conf.presentation
4392 state.scrollw
<- if v then conf.scrollbw
else 0;
4393 reshape state.winw
state.winh
;
4399 src#caption
"Pixmap cache" 0;
4400 src#int_with_suffix
"size (advisory)"
4401 (fun () -> conf.memlimit
)
4402 (fun v -> conf.memlimit
<- v);
4405 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4406 (string_with_suffix_of_int state.memused
)
4407 (Hashtbl.length
state.tilemap
)) 1;
4410 src#caption
"Layout" 0;
4411 src#caption2
"Dimension"
4413 Printf.sprintf
"%dx%d (virtual %dx%d)"
4414 state.winw
state.winh
4419 src#caption2
"Position" (fun () ->
4420 Printf.sprintf
"%dx%d" state.x state.y
4423 src#caption2
"Visible" (fun () -> describe_location ()) 1
4427 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4428 "Save these parameters as global defaults at exit"
4429 (fun () -> conf.bedefault
)
4430 (fun v -> conf.bedefault
<- v)
4434 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4435 src#
bool ~offset
:0 ~
btos "Extended parameters"
4436 (fun () -> !showextended)
4437 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4441 (fun () -> conf.checkers
)
4442 (fun v -> conf.checkers
<- v; setcheckers v);
4443 src#
bool "update cursor"
4444 (fun () -> conf.updatecurs
)
4445 (fun v -> conf.updatecurs
<- v);
4447 (fun () -> conf.verbose
)
4448 (fun v -> conf.verbose
<- v);
4449 src#
bool "invert colors"
4450 (fun () -> conf.invert
)
4451 (fun v -> conf.invert
<- v);
4453 (fun () -> conf.maxhfit
)
4454 (fun v -> conf.maxhfit
<- v);
4455 src#
bool "redirect stderr"
4456 (fun () -> conf.redirectstderr)
4457 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4458 src#
string "uri launcher"
4459 (fun () -> conf.urilauncher
)
4460 (fun v -> conf.urilauncher
<- v);
4461 src#
string "path launcher"
4462 (fun () -> conf.pathlauncher
)
4463 (fun v -> conf.pathlauncher
<- v);
4464 src#
string "tile size"
4465 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4468 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4469 conf.tilew
<- max
64 w;
4470 conf.tileh
<- max
64 h;
4473 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4476 src#
int "texture count"
4477 (fun () -> conf.texcount
)
4480 then conf.texcount
<- v
4481 else showtext '
!'
" Failed to set texture count please retry later"
4483 src#
int "slice height"
4484 (fun () -> conf.sliceheight
)
4486 conf.sliceheight
<- v;
4487 wcmd "sliceh %d" conf.sliceheight
;
4489 src#
int "anti-aliasing level"
4490 (fun () -> conf.aalevel
)
4492 conf.aalevel
<- bound v 0 8;
4493 state.anchor <- getanchor ();
4494 opendoc state.path
state.password
;
4496 src#
string "page scroll scaling factor"
4497 (fun () -> string_of_float
conf.pgscale)
4500 let s = float_of_string
v in
4503 state.text <- Printf.sprintf
4504 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4507 src#
int "ui font size"
4508 (fun () -> fstate.fontsize
)
4509 (fun v -> setfontsize (bound v 5 100));
4510 src#
int "hint font size"
4511 (fun () -> conf.hfsize
)
4512 (fun v -> conf.hfsize
<- bound v 5 100);
4513 colorp "background color"
4514 (fun () -> conf.bgcolor
)
4515 (fun v -> conf.bgcolor
<- v);
4516 src#
bool "crop hack"
4517 (fun () -> conf.crophack
)
4518 (fun v -> conf.crophack
<- v);
4519 src#
string "trim fuzz"
4520 (fun () -> irect_to_string conf.trimfuzz
)
4523 conf.trimfuzz
<- irect_of_string v;
4525 then settrim true conf.trimfuzz
;
4527 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4529 src#
string "throttle"
4531 match conf.maxwait
with
4532 | None
-> "show place holder if page is not ready"
4535 then "wait for page to fully render"
4537 "wait " ^ string_of_float
time
4538 ^
" seconds before showing placeholder"
4542 let f = float_of_string
v in
4544 then conf.maxwait
<- None
4545 else conf.maxwait
<- Some
f
4547 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4549 src#
string "ghyll scroll"
4551 match conf.ghyllscroll
with
4553 | Some nab
-> ghyllscroll_to_string nab
4558 if String.length
v = 0
4560 else Some
(ghyllscroll_of_string v)
4562 conf.ghyllscroll
<- gs
4564 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4566 src#
string "selection command"
4567 (fun () -> conf.selcmd
)
4568 (fun v -> conf.selcmd
<- v);
4569 src#
string "synctex command"
4570 (fun () -> conf.stcmd
)
4571 (fun v -> conf.stcmd
<- v);
4572 src#colorspace
"color space"
4573 (fun () -> colorspace_to_string conf.colorspace
)
4575 conf.colorspace
<- colorspace_of_int v;
4582 (fun () -> conf.usepbo
)
4583 (fun v -> conf.usepbo
<- v);
4584 src#
bool "mouse wheel scrolls pages"
4585 (fun () -> conf.wheelbypage
)
4586 (fun v -> conf.wheelbypage
<- v);
4590 src#caption
"Document" 0;
4591 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4592 src#caption2
"Pages"
4593 (fun () -> string_of_int
state.pagecount
) 1;
4594 src#caption2
"Dimensions"
4595 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4599 src#caption
"Trimmed margins" 0;
4600 src#caption2
"Dimensions"
4601 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4605 src#caption
"OpenGL" 0;
4606 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4607 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4608 src#reset prevmode prevuioh
;
4612 let prevmode = state.mode
4613 and prevuioh
= state.uioh in
4614 fillsrc prevmode prevuioh
;
4615 let source = (src :> lvsource
) in
4616 let modehash = findkeyhash conf "info" in
4617 state.uioh <- coe (object (self)
4618 inherit listview ~
source ~trusted
:true ~
modehash as super
4619 val mutable m_prevmemused
= 0
4620 method infochanged
= function
4622 if m_prevmemused
!= state.memused
4624 m_prevmemused
<- state.memused
;
4625 G.postRedisplay "memusedchanged";
4627 | Pdim
-> G.postRedisplay "pdimchanged"
4628 | Docinfo
-> fillsrc prevmode prevuioh
4630 method key key mask
=
4631 if not
(Wsi.withctrl mask
)
4634 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4635 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4636 | _ -> super#
key key mask
4637 else super#
key key mask
4639 G.postRedisplay "info";
4645 inherit lvsourcebase
4646 method getitemcount
= Array.length
state.help
4648 let s, l, _ = state.help
.(n) in
4651 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4655 m_qsearch
<- qsearch;
4656 match state.help
.(active) with
4657 | _, _, Action
f -> Some
(f uioh)
4667 method hasaction
n =
4668 match state.help
.(n) with
4669 | _, _, Action
_ -> true
4676 let modehash = findkeyhash conf "help" in
4677 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4678 G.postRedisplay "help";
4683 let re = Str.regexp
"[\r\n]" in
4685 inherit lvsourcebase
4686 val mutable m_items
= [||]
4688 method getitemcount
= 1 + Array.length m_items
4693 else m_items
.(n-1), 0
4695 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4700 then Buffer.clear
state.errmsgs
;
4701 m_qsearch
<- qsearch;
4708 method hasaction
n =
4712 state.newerrmsgs
<- false;
4713 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4714 m_items
<- Array.of_list
l
4722 let source = (msgsource :> lvsource
) in
4723 let modehash = findkeyhash conf "listview" in
4724 state.uioh <- coe (object
4725 inherit listview ~
source ~trusted
:false ~
modehash as super
4728 then msgsource#reset
;
4731 G.postRedisplay "msgs";
4734 let quickbookmark ?title
() =
4735 match state.layout with
4741 let sec = Unix.gettimeofday
() in
4742 let tm = Unix.localtime
sec in
4743 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4747 (tm.Unix.tm_year
+ 1900)
4750 | Some
title -> title
4752 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4759 let setautoscrollspeed step goingdown
=
4760 let incr = max
1 ((abs step
) / 2) in
4761 let incr = if goingdown
then incr else -incr in
4762 let astep = step
+ incr in
4763 state.autoscroll
<- Some
astep;
4766 let gotounder = function
4767 | Ulinkgoto
(pageno, top) ->
4771 gotopage1 pageno top;
4777 | Uremote
(filename
, pageno) ->
4779 if Sys.file_exists filename
4782 let dir = Filename.dirname
state.path in
4783 let path = Filename.concat
dir filename
in
4784 if Sys.file_exists
path
4788 if String.length
path > 0
4790 let anchor = getanchor () in
4791 let ranchor = state.path, state.password
, anchor in
4792 state.anchor <- (pageno, 0.0, 0.0);
4793 state.ranchors
<- ranchor :: state.ranchors
;
4796 else showtext '
!'
("Could not find " ^ filename
)
4798 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4802 match conf.columns
with
4804 | _ -> conf.zoom > 1.0
4807 let existsinrow pageno (columns
, coverA
, coverB
) p =
4808 let last = ((pageno - coverA
) mod columns
) + columns
in
4809 let rec any = function
4812 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4816 then (if l.pageno = last then false else any rest
)
4824 match state.layout with
4826 let pageno = page_of_y state.y in
4827 gotoghyll (getpagey (pageno+1))
4829 match conf.columns
with
4831 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4833 let y = clamp (pgscale state.winh
) in
4836 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4837 gotoghyll (getpagey pageno)
4838 | Cmulti
((c, _, _) as cl, _) ->
4839 if conf.presentation
4840 && (existsinrow l.pageno cl
4841 (fun l -> l.pageh
> l.pagey + l.pagevh))
4843 let y = clamp (pgscale state.winh
) in
4846 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4847 gotoghyll (getpagey pageno)
4849 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4851 let pagey, pageh
= getpageyh l.pageno in
4852 let pagey = pagey + pageh
* l.pagecol
in
4853 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4854 gotoghyll (pagey + pageh
+ ips)
4858 match state.layout with
4860 let pageno = page_of_y state.y in
4861 gotoghyll (getpagey (pageno-1))
4863 match conf.columns
with
4865 if conf.presentation
&& l.pagey != 0
4867 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4869 let pageno = max
0 (l.pageno-1) in
4870 gotoghyll (getpagey pageno)
4871 | Cmulti
((c, _, coverB
) as cl, _) ->
4872 if conf.presentation
&&
4873 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4875 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4878 if l.pageno = state.pagecount
- coverB
4882 let pageno = max
0 (l.pageno-decr) in
4883 gotoghyll (getpagey pageno)
4891 let pageno = max
0 (l.pageno-1) in
4892 let pagey, pageh
= getpageyh pageno in
4895 let pagey, pageh
= getpageyh l.pageno in
4896 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4901 let viewkeyboard key mask
=
4903 let mode = state.mode in
4904 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4907 G.postRedisplay "view:enttext"
4909 let ctrl = Wsi.withctrl mask
in
4911 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4917 | 0xff63 -> (* insert *)
4918 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4920 state.mode <- LinkNav
(Ltgendir
0);
4923 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4925 | 0xff1b | 113 -> (* escape / q *)
4926 begin match state.mstate
with
4928 state.mstate
<- Mnone
;
4929 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4930 G.postRedisplay "kill zoom rect";
4932 begin match state.mode with
4935 G.postRedisplay "esc leave linknav"
4937 match state.ranchors
with
4939 | (path, password
, anchor) :: rest
->
4940 state.ranchors
<- rest
;
4941 state.anchor <- anchor;
4942 opendoc path password
4946 | 0xff08 -> (* backspace *)
4947 gotoghyll (getnav ~
-1)
4955 G.postRedisplay "dehighlight";
4957 | 47 | 63 -> (* / ? *)
4958 let ondone isforw
s =
4959 cbput state.hists
.pat
s;
4960 state.searchpattern
<- s;
4963 let s = String.create
1 in
4964 s.[0] <- Char.chr
key;
4965 enttext (s, "", Some
(onhist state.hists
.pat
),
4966 textentry, ondone (key = 47), true)
4968 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4969 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4970 setzoom (conf.zoom +. incr)
4972 | 43 | 0xffab -> (* + *)
4975 try int_of_string
s with exc
->
4976 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4982 state.text <- "page bias is now " ^ string_of_int
n;
4985 enttext ("page bias: ", "", None
, intentry, ondone, true)
4987 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4988 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4989 setzoom (max
0.01 (conf.zoom -. decr))
4991 | 45 | 0xffad -> (* - *)
4992 let ondone msg
= state.text <- msg
in
4994 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4995 optentry state.mode, ondone, true
4998 | 48 when ctrl -> (* ctrl-0 *)
5001 | 49 when ctrl -> (* ctrl-1 *)
5003 match conf.columns
with
5004 | Csingle
_ | Cmulti
_ -> 1
5005 | Csplit
(n, _) -> n
5007 let zoom = zoomforh
state.winw
state.winh
state.scrollw
cols in
5011 | 0xffc6 -> (* f9 *)
5014 | 57 when ctrl -> (* ctrl-9 *)
5017 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5018 when not
ctrl -> (* 0..9 *)
5021 try int_of_string
s with exc
->
5022 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5028 cbput state.hists
.pag
(string_of_int
n);
5029 gotopage1 (n + conf.pagebias
- 1) 0;
5032 let pageentry text key =
5033 match Char.unsafe_chr
key with
5034 | '
g'
-> TEdone
text
5035 | _ -> intentry text key
5037 let text = "x" in text.[0] <- Char.chr
key;
5038 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5041 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5042 reshape state.winw
state.winh
;
5045 conf.hlinks
<- not
conf.hlinks
;
5046 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5047 G.postRedisplay "toggle highlightlinks";
5050 state.glinks
<- true;
5051 let mode = state.mode in
5052 state.mode <- Textentry
(
5053 (":", "", None
, linknentry, linkndone gotounder, false),
5055 state.glinks
<- false;
5059 G.postRedisplay "view:linkent(F)"
5062 state.glinks
<- true;
5063 let mode = state.mode in
5064 state.mode <- Textentry
(
5065 (":", "", None
, linknentry, linkndone (fun under ->
5066 match Ne.pipe () with
5068 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
5071 try popen conf.selcmd
[r, 0; w, -1]; true
5074 (Printf.sprintf
"failed to execute %s: %s"
5075 conf.selcmd
(exntos exn
));
5079 Ne.clo fd
(fun msg
->
5080 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5083 let s = undertext under in
5087 let l = String.length
s in
5088 let n = tempfailureretry
(Unix.write
w s 0) l in
5093 "failed to write %d characters to sel pipe, wrote %d"
5098 (Printf.sprintf
"failed to write to sel pipe: %s"
5108 state.glinks
<- false;
5112 G.postRedisplay "view:linkent"
5115 begin match state.autoscroll
with
5117 conf.autoscrollstep
<- step
;
5118 state.autoscroll
<- None
5120 if conf.autoscrollstep
= 0
5121 then state.autoscroll
<- Some
1
5122 else state.autoscroll
<- Some
conf.autoscrollstep
5125 | 112 when ctrl -> (* ctrl-p *)
5129 setpresentationmode (not
conf.presentation
);
5130 showtext ' '
("presentation mode " ^
5131 if conf.presentation
then "on" else "off");
5134 if List.mem
Wsi.Fullscreen
state.winstate
5135 then doreshape conf.cwinw
conf.cwinh
5136 else Wsi.fullscreen
()
5138 | 112 | 78 -> (* p|N *)
5139 search state.searchpattern
false
5141 | 110 | 0xffc0 -> (* n|F3 *)
5142 search state.searchpattern
true
5145 begin match state.layout with
5148 gotoghyll (getpagey l.pageno)
5154 | 0xff9f | 0xffff -> (* delete *)
5158 showtext ' '
(describe_location ());
5161 begin match state.layout with
5164 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5169 enterbookmarkmode ()
5171 | 104 | 0xffbe -> (* h|F1 *)
5177 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5182 match state.layout with
5184 if String.length
s > 0
5186 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5189 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5193 showtext ' '
"Quick bookmark added";
5196 begin match state.layout with
5198 let rect = getpdimrect
l.pagedimno
in
5202 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5203 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5205 (truncate
(rect.(1) -. rect.(0)),
5206 truncate
(rect.(3) -. rect.(0)))
5208 let w = truncate
((float w)*.conf.zoom)
5209 and h = truncate
((float h)*.conf.zoom) in
5212 state.anchor <- getanchor ();
5213 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5215 G.postRedisplay "z";
5220 | 50 when ctrl -> (* ctrl-2 *)
5221 let maxw = getmaxw
() in
5223 then setzoom (maxw /. float state.winw
)
5225 | 60 | 62 -> (* < > *)
5226 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5228 | 91 | 93 -> (* [ ] *)
5230 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5232 G.postRedisplay "brightness";
5234 | 99 when state.mode = View
-> (* c *)
5236 match state.prevcolumns
with
5237 | None
-> (1, 0, 0), 1.0
5238 | Some
(columns
, z
) ->
5241 | Csplit
(c, _) -> -c, 0, 0
5242 | Cmulti
((c, a, b), _) -> c, a, b
5243 | Csingle
_ -> 1, 0, 0
5247 setcolumns View
c a b;
5250 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5251 setzoom state.prevzoom
5253 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5254 begin match state.autoscroll
with
5256 begin match state.mode with
5257 | Birdseye beye
-> upbirdseye 1 beye
5260 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5261 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5264 setautoscrollspeed n false
5267 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5268 begin match state.autoscroll
with
5270 begin match state.mode with
5271 | Birdseye beye
-> downbirdseye 1 beye
5274 then gotoy_and_clear_text (clamp (state.winh
/2))
5275 else gotoy_and_clear_text (clamp conf.scrollstep
)
5278 setautoscrollspeed n true
5281 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5282 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5288 else conf.hscrollstep
5290 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5291 state.x <- state.x + dx;
5292 gotoy_and_clear_text state.y
5295 G.postRedisplay "lef/right"
5298 | 0xff55 | 0xff9a -> (* (kp) prior *)
5302 match state.layout with
5304 | l :: _ -> state.y - l.pagey
5306 clamp (pgscale (-state.winh
))
5310 | 0xff56 | 0xff9b -> (* (kp) next *)
5314 match List.rev
state.layout with
5316 | l :: _ -> getpagey l.pageno
5318 clamp (pgscale state.winh
)
5322 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5324 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5325 gotoghyll (clamp state.maxy)
5328 when Wsi.withalt mask
-> (* alt-(kp) right *)
5329 gotoghyll (getnav 1)
5331 when Wsi.withalt mask
-> (* alt-(kp) left *)
5332 gotoghyll (getnav ~
-1)
5337 | 118 when conf.debug
-> (* v *)
5340 match getopaque l.pageno with
5343 let x0, y0, x1, y1 = pagebbox opaque
in
5344 let a,b = float x0, float y0 in
5345 let c,d = float x1, float y0 in
5346 let e,f = float x1, float y1 in
5347 let h,j
= float x0, float y1 in
5348 let rect = (a,b,c,d,e,f,h,j
) in
5350 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5352 G.postRedisplay "v";
5355 vlog "huh? %s" (Wsi.keyname
key)
5358 let linknavkeyboard key mask
linknav =
5359 let getpage pageno =
5360 let rec loop = function
5362 | l :: _ when l.pageno = pageno -> Some
l
5363 | _ :: rest
-> loop rest
5364 in loop state.layout
5366 let doexact (pageno, n) =
5367 match getopaque pageno, getpage pageno with
5368 | Some opaque
, Some
l ->
5369 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5371 let under = getlink opaque
n in
5372 G.postRedisplay "link gotounder";
5378 | 0xff50 -> (* home *)
5379 Some
(findlink opaque LDfirst
), -1
5381 | 0xff57 -> (* end *)
5382 Some
(findlink opaque LDlast
), 1
5384 | 0xff51 -> (* left *)
5385 Some
(findlink opaque
(LDleft
n)), -1
5387 | 0xff53 -> (* right *)
5388 Some
(findlink opaque
(LDright
n)), 1
5390 | 0xff52 -> (* up *)
5391 Some
(findlink opaque
(LDup
n)), -1
5393 | 0xff54 -> (* down *)
5394 Some
(findlink opaque
(LDdown
n)), 1
5399 begin match findpwl
l.pageno dir with
5403 state.mode <- LinkNav
(Ltgendir
dir);
5404 let y, h = getpageyh pageno in
5407 then y + h - state.winh
5412 begin match getopaque pageno, getpage pageno with
5413 | Some opaque
, Some
_ ->
5415 let ld = if dir > 0 then LDfirst
else LDlast
in
5418 begin match link with
5420 showlinktype (getlink opaque
m);
5421 state.mode <- LinkNav
(Ltexact
(pageno, m));
5422 G.postRedisplay "linknav jpage";
5429 begin match opt with
5430 | Some Lnotfound
-> pwl l dir;
5431 | Some
(Lfound
m) ->
5435 let _, y0, _, y1 = getlinkrect opaque
m in
5437 then gotopage1 l.pageno y0
5439 let d = fstate.fontsize
+ 1 in
5440 if y1 - l.pagey > l.pagevh - d
5441 then gotopage1 l.pageno (y1 - state.winh
- state.hscrollh + d)
5442 else G.postRedisplay "linknav";
5444 showlinktype (getlink opaque
m);
5445 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5448 | None
-> viewkeyboard key mask
5450 | _ -> viewkeyboard key mask
5455 G.postRedisplay "leave linknav"
5459 | Ltgendir
_ -> viewkeyboard key mask
5460 | Ltexact exact
-> doexact exact
5463 let keyboard key mask
=
5464 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5465 then wcmd "interrupt"
5466 else state.uioh <- state.uioh#
key key mask
5469 let birdseyekeyboard key mask
5470 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5472 match conf.columns
with
5474 | Cmulti
((c, _, _), _) -> c
5475 | Csplit
_ -> failwith
"bird's eye split mode"
5477 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5479 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5480 let y, h = getpageyh pageno in
5481 let top = (state.winh
- h) / 2 in
5482 gotoy (max
0 (y - top))
5483 | 0xff0d (* enter *)
5484 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5485 | 0xff1b -> leavebirdseye beye
true (* escape *)
5486 | 0xff52 -> upbirdseye incr beye
(* up *)
5487 | 0xff54 -> downbirdseye incr beye
(* down *)
5488 | 0xff51 -> upbirdseye 1 beye
(* left *)
5489 | 0xff53 -> downbirdseye 1 beye
(* right *)
5491 | 0xff55 -> (* prior *)
5492 begin match state.layout with
5496 state.mode <- Birdseye
(
5497 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5499 gotopage1 l.pageno 0;
5502 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5504 | [] -> gotoy (clamp (-state.winh
))
5506 state.mode <- Birdseye
(
5507 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5509 gotopage1 l.pageno 0
5512 | [] -> gotoy (clamp (-state.winh
))
5515 | 0xff56 -> (* next *)
5516 begin match List.rev
state.layout with
5518 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5519 begin match layout with
5521 let incr = l.pageh
- l.pagevh in
5526 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5528 G.postRedisplay "birdseye pagedown";
5530 else gotoy (clamp (incr + conf.interpagespace
*2));
5534 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5535 gotopage1 l.pageno 0;
5538 | [] -> gotoy (clamp state.winh
)
5541 | 0xff50 -> (* home *)
5542 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5545 | 0xff57 -> (* end *)
5546 let pageno = state.pagecount
- 1 in
5547 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5548 if not
(pagevisible state.layout pageno)
5551 match List.rev
state.pdims
with
5553 | (_, _, h, _) :: _ -> h
5555 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5556 else G.postRedisplay "birdseye end";
5557 | _ -> viewkeyboard key mask
5560 let drawpage l linkindexbase
=
5562 match state.mode with
5563 | Textentry
_ -> scalecolor 0.4
5565 | View
-> scalecolor 1.0
5566 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5567 if l.pageno = hooverpageno
5570 if l.pageno = pageno
5576 begin match getopaque l.pageno with
5578 if tileready l l.pagex
l.pagey
5580 let x = l.pagedispx - l.pagex
5581 and y = l.pagedispy - l.pagey in
5583 match conf.columns
with
5584 | Csingle
_ | Cmulti
_ ->
5585 (if conf.hlinks
then 1 else 0)
5587 && not
(isbirdseye state.mode) then 2 else 0)
5591 match state.mode with
5592 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5595 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5602 let scrollindicator () =
5603 let sbw, ph
, sh = state.uioh#
scrollph in
5604 let sbh, pw, sw = state.uioh#scrollpw
in
5606 GlDraw.color (0.64, 0.64, 0.64);
5608 (float (state.winw
- sbw), 0.)
5609 (float state.winw
, float state.winh
)
5612 (0., float (state.winh
- sbh))
5613 (float (state.winw
- state.scrollw
- 1), float state.winh
)
5615 GlDraw.color (0.0, 0.0, 0.0);
5618 (float (state.winw
- sbw), ph
)
5619 (float state.winw
, ph
+. sh)
5622 (pw, float (state.winh
- sbh))
5623 (pw +. sw, float state.winh
)
5628 match state.mstate
with
5629 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5632 | Msel
((x0, y0), (x1, y1)) ->
5633 let rec loop = function
5635 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5636 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5637 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5638 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5640 match getopaque l.pageno with
5642 let x0, y0 = pagetranslatepoint l x0 y0 in
5643 let x1, y1 = pagetranslatepoint l x1 y1 in
5644 seltext opaque
(x0, y0, x1, y1);
5652 let showrects rects
=
5654 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5655 GlDraw.polygon_mode `both `fill
;
5656 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5658 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5660 if l.pageno = pageno
5662 let dx = float (l.pagedispx - l.pagex
) in
5663 let dy = float (l.pagedispy - l.pagey) in
5664 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5665 GlDraw.begins `quads
;
5667 GlDraw.vertex2
(x0+.dx, y0+.dy);
5668 GlDraw.vertex2
(x1+.dx, y1+.dy);
5669 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5670 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5681 GlClear.color (scalecolor2 conf.bgcolor
);
5682 GlClear.clear
[`
color];
5683 let rec loop linkindexbase
= function
5685 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5686 loop linkindexbase rest
5689 loop 0 state.layout;
5691 match state.mode with
5692 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5693 begin match getopaque pageno with
5695 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5702 | None
-> state.rects
5709 begin match state.mstate
with
5710 | Mzoomrect
((x0, y0), (x1, y1)) ->
5712 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5713 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5714 GlDraw.rect (float x0, float y0)
5715 (float x1, float y1);
5724 let zoomrect x y x1 y1 =
5727 and y0 = min
y y1 in
5728 gotoy (state.y + y0);
5729 state.anchor <- getanchor ();
5730 let zoom = (float state.winw
*. conf.zoom) /. float (x1 - x0) in
5732 if state.w < state.winw
- state.scrollw
5733 then (state.winw
- state.scrollw
- state.w) / 2
5736 state.x <- (state.x + margin) - x0;
5738 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5739 state.mstate
<- Mnone
;
5743 let winw = state.winw - state.scrollw
- 1 in
5744 let s = float x /. float winw in
5745 let destx = truncate
(float (state.w + winw) *. s) in
5746 state.x <- winw - destx;
5747 gotoy_and_clear_text state.y;
5748 state.mstate
<- Mscrollx
;
5752 let s = float y /. float state.winh
in
5753 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5754 gotoy_and_clear_text desty;
5755 state.mstate
<- Mscrolly
;
5758 let viewmouse button down
x y mask
=
5760 | n when (n == 4 || n == 5) && not down
->
5761 if Wsi.withctrl mask
5763 match state.mstate
with
5764 | Mzoom
(oldn
, i
) ->
5772 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5774 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5776 let zoom = conf.zoom -. incr in
5778 state.mstate
<- Mzoom
(n, 0);
5780 state.mstate
<- Mzoom
(n, i
+1);
5782 else state.mstate
<- Mzoom
(n, 0)
5784 | _ -> state.mstate
<- Mzoom
(n, 0)
5787 match state.autoscroll
with
5788 | Some step
-> setautoscrollspeed step
(n=4)
5799 then -conf.scrollstep
5800 else conf.scrollstep
5802 let incr = incr * 2 in
5803 let y = clamp incr in
5804 gotoy_and_clear_text y
5807 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5808 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5809 gotoy_and_clear_text state.y
5811 | 1 when Wsi.withshift mask
->
5812 state.mstate
<- Mnone
;
5814 match unproject x y with
5815 | Some
(pageno, ux
, uy
) ->
5816 let cmd = Printf.sprintf
5818 conf.stcmd
state.path pageno ux uy
5824 | 1 when Wsi.withctrl mask
->
5827 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5828 state.mstate
<- Mpan
(x, y)
5831 state.mstate
<- Mnone
5836 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5838 state.mstate
<- Mzoomrect
(p, p)
5841 match state.mstate
with
5842 | Mzoomrect
((x0, y0), _) ->
5843 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5844 then zoomrect x0 y0 x y
5846 state.mstate
<- Mnone
;
5847 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5848 G.postRedisplay "kill accidental zoom rect";
5851 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5852 state.mstate
<- Mnone
5855 | 1 when x > state.winw - state.scrollw
->
5858 let _, position, sh = state.uioh#
scrollph in
5859 if y > truncate
position && y < truncate
(position +. sh)
5860 then state.mstate
<- Mscrolly
5863 state.mstate
<- Mnone
5865 | 1 when y > state.winh
- state.hscrollh ->
5868 let _, position, sw = state.uioh#scrollpw
in
5869 if x > truncate
position && x < truncate
(position +. sw)
5870 then state.mstate
<- Mscrollx
5873 state.mstate
<- Mnone
5876 let dest = if down
then getunder x y else Unone
in
5877 begin match dest with
5881 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5884 | Unone
when down
->
5885 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5886 state.mstate
<- Mpan
(x, y);
5888 | Unone
| Utext
_ ->
5891 if conf.angle
mod 360 = 0
5893 state.mstate
<- Msel
((x, y), (x, y));
5894 G.postRedisplay "mouse select";
5898 match state.mstate
with
5901 | Mzoom
_ | Mscrollx
| Mscrolly
->
5902 state.mstate
<- Mnone
5904 | Mzoomrect
((x0, y0), _) ->
5908 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5909 state.mstate
<- Mnone
5911 | Msel
((x0, y0), (x1, y1)) ->
5912 let rec loop = function
5916 let a0 = l.pagedispy in
5917 let a1 = a0 + l.pagevh in
5918 let b0 = l.pagedispx in
5919 let b1 = b0 + l.pagevw in
5920 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5921 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5925 match getopaque l.pageno with
5928 match Ne.pipe () with
5932 "can not create sel pipe: %s"
5935 let doclose what fd
=
5936 Ne.clo fd
(fun msg
->
5937 dolog
"%s close failed: %s" what msg
)
5940 popen conf.selcmd
[r, 0; w, -1];
5943 G.postRedisplay "copysel";
5945 dolog
"can not execute %S: %s"
5946 conf.selcmd
(exntos exn
);
5954 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5955 state.mstate
<- Mnone
;
5962 let birdseyemouse button down
x y mask
5963 (conf, leftx
, _, hooverpageno
, anchor) =
5966 let rec loop = function
5969 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5970 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5972 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5978 | _ -> viewmouse button down
x y mask
5981 let mouse button down
x y mask
=
5982 state.uioh <- state.uioh#button button down
x y mask
;
5986 state.uioh <- state.uioh#
motion x y
5990 state.uioh <- state.uioh#
pmotion x y;
5996 method key key mask
=
5997 begin match state.mode with
5998 | Textentry
textentry -> textentrykeyboard key mask
textentry
5999 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6000 | View
-> viewkeyboard key mask
6001 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6005 method button button bstate
x y mask
=
6006 begin match state.mode with
6008 | View
-> viewmouse button bstate
x y mask
6009 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6015 begin match state.mode with
6017 | View
| Birdseye
_ | LinkNav
_ ->
6018 match state.mstate
with
6019 | Mzoom
_ | Mnone
-> ()
6024 state.mstate
<- Mpan
(x, y);
6026 then state.x <- state.x + dx;
6028 gotoy_and_clear_text y
6031 state.mstate
<- Msel
(a, (x, y));
6032 G.postRedisplay "motion select";
6035 let y = min
state.winh
(max
0 y) in
6039 let x = min
state.winw (max
0 x) in
6042 | Mzoomrect
(p0
, _) ->
6043 state.mstate
<- Mzoomrect
(p0
, (x, y));
6044 G.postRedisplay "motion zoomrect";
6048 method pmotion x y =
6049 begin match state.mode with
6050 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6051 let rec loop = function
6053 if hooverpageno
!= -1
6055 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6056 G.postRedisplay "pmotion birdseye no hoover";
6059 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6060 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6062 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6063 G.postRedisplay "pmotion birdseye hoover";
6073 match state.mstate
with
6074 | Mnone
-> updateunder x y
6075 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6080 method infochanged
_ = ()
6083 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6084 let p, h = scrollph state.y maxy in
6088 let winw = state.winw - state.scrollw
- 1 in
6089 let fwinw = float winw in
6091 let sw = fwinw /. float state.w in
6092 let sw = fwinw *. sw in
6093 max
sw (float conf.scrollh
)
6096 let f = state.w+winw in
6097 let r = float (winw-state.x) /. float f in
6098 let p = fwinw *. r in
6102 if position +. sw > fwinw
6103 then fwinw -. position
6106 state.hscrollh, position, sw
6110 match state.mode with
6111 | LinkNav
_ -> "links"
6112 | Textentry
_ -> "textentry"
6113 | Birdseye
_ -> "birdseye"
6116 findkeyhash conf modename
6123 let fontpath = ref "";;
6126 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6129 let l = String.length
s in
6130 let b = Buffer.create
l in
6136 try Sys.getenv
"HOME"
6139 ("Can not determine home directory location: " ^ exntos exn
);
6143 let modifier_of_string = function
6144 | "alt" -> Wsi.altmask
6145 | "shift" -> Wsi.shiftmask
6146 | "ctrl" | "control" -> Wsi.ctrlmask
6147 | "meta" -> Wsi.metamask
6152 let r = Str.regexp
"-" in
6154 let elems = Str.full_split
r s in
6157 let m1 = modifier_of_string s in
6159 then (Wsi.namekey
s, m)
6162 | Str.Delim
s when n land 1 = 0 -> g s
6164 | Str.Delim
_ -> (k
, m)
6166 let rec loop n k
m = function
6169 let k, m = f n k m x in
6175 let keys_of_string =
6176 let r = Str.regexp
"[ \t]" in
6178 let elems = Str.split
r s in
6179 List.map
key_of_string elems
6182 let copykeyhashes c =
6183 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6186 let config_of c attrs
=
6190 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6191 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6192 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6193 | "preload" -> { c with preload = bool_of_string
v }
6194 | "page-bias" -> { c with pagebias
= int_of_string
v }
6195 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6196 | "horizontal-scroll-step" ->
6197 { c with hscrollstep
= max
(int_of_string
v) 1 }
6198 | "auto-scroll-step" ->
6199 { c with autoscrollstep
= max
0 (int_of_string
v) }
6200 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6201 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6204 match String.lowercase
v with
6205 | "true" -> Some infinity
6207 | f -> Some
(float_of_string
f)
6209 { c with maxwait
= mw}
6210 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6211 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6212 | "vertical-margin" ->
6213 { c with interpagespace
= max
0 (int_of_string
v) }
6215 let zoom = float_of_string
v /. 100. in
6216 let zoom = max
zoom 0.0 in
6217 { c with zoom = zoom }
6218 | "presentation" -> { c with presentation
= bool_of_string
v }
6219 | "rotation-angle" -> { c with angle
= int_of_string
v }
6220 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6221 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6222 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6223 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6224 | "pixmap-cache-size" ->
6225 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6226 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6227 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6228 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6229 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6230 | "background-color" -> { c with bgcolor
= color_of_string v }
6231 | "scrollbar-in-presentation" ->
6232 { c with scrollbarinpm
= bool_of_string
v }
6233 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6234 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6235 | "mupdf-store-size" ->
6236 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6237 | "checkers" -> { c with checkers
= bool_of_string
v }
6238 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6239 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6240 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6241 | "uri-launcher" -> { c with urilauncher
= unent v }
6242 | "path-launcher" -> { c with pathlauncher
= unent v }
6243 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6244 | "invert-colors" -> { c with invert
= bool_of_string
v }
6245 | "brightness" -> { c with colorscale
= float_of_string
v }
6246 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6248 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6250 let (n, _, _) as nab
= multicolumns_of_string v in
6252 then { c with columns
= Csplit
(-n, [||]) }
6253 else { c with columns
= Cmulti
(nab
, [||]) }
6254 | "birds-eye-columns" ->
6255 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6256 | "selection-command" -> { c with selcmd
= unent v }
6257 | "synctex-command" -> { c with stcmd
= unent v }
6258 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6259 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6260 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6261 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6262 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6265 prerr_endline
("Error processing attribute (`" ^
6266 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6269 let rec fold c = function
6272 let c = apply c k v in
6275 fold { c with keyhashes
= copykeyhashes c } attrs
;
6278 let fromstring f pos
n v d =
6281 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6282 n v pos
(exntos exn
)
6287 let bookmark_of attrs
=
6288 let rec fold title page
rely visy
= function
6289 | ("title", v) :: rest
-> fold v page
rely visy rest
6290 | ("page", v) :: rest
-> fold title v rely visy rest
6291 | ("rely", v) :: rest
-> fold title page
v visy rest
6292 | ("visy", v) :: rest
-> fold title page
rely v rest
6293 | _ :: rest
-> fold title page
rely visy rest
6294 | [] -> title, page
, rely, visy
6296 fold "invalid" "0" "0" "0" attrs
6300 let rec fold path page
rely pan visy
= function
6301 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6302 | ("page", v) :: rest
-> fold path v rely pan visy rest
6303 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6304 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6305 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6306 | _ :: rest
-> fold path page
rely pan visy rest
6307 | [] -> path, page
, rely, pan
, visy
6309 fold "" "0" "0" "0" "0" attrs
6313 let rec fold rs ls
= function
6314 | ("out", v) :: rest
-> fold v ls rest
6315 | ("in", v) :: rest
-> fold rs
v rest
6316 | _ :: rest
-> fold ls rs rest
6322 let setconf dst
src =
6323 dst
.scrollbw
<- src.scrollbw
;
6324 dst
.scrollh
<- src.scrollh
;
6325 dst
.icase
<- src.icase
;
6326 dst
.preload <- src.preload;
6327 dst
.pagebias
<- src.pagebias
;
6328 dst
.verbose
<- src.verbose
;
6329 dst
.scrollstep
<- src.scrollstep
;
6330 dst
.maxhfit
<- src.maxhfit
;
6331 dst
.crophack
<- src.crophack
;
6332 dst
.autoscrollstep
<- src.autoscrollstep
;
6333 dst
.maxwait
<- src.maxwait
;
6334 dst
.hlinks
<- src.hlinks
;
6335 dst
.underinfo
<- src.underinfo
;
6336 dst
.interpagespace
<- src.interpagespace
;
6337 dst
.zoom <- src.zoom;
6338 dst
.presentation
<- src.presentation
;
6339 dst
.angle
<- src.angle
;
6340 dst
.cwinw
<- src.cwinw
;
6341 dst
.cwinh
<- src.cwinh
;
6342 dst
.savebmarks
<- src.savebmarks
;
6343 dst
.memlimit
<- src.memlimit
;
6344 dst
.proportional
<- src.proportional
;
6345 dst
.texcount
<- src.texcount
;
6346 dst
.sliceheight
<- src.sliceheight
;
6347 dst
.thumbw
<- src.thumbw
;
6348 dst
.jumpback
<- src.jumpback
;
6349 dst
.bgcolor
<- src.bgcolor
;
6350 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6351 dst
.tilew
<- src.tilew
;
6352 dst
.tileh
<- src.tileh
;
6353 dst
.mustoresize
<- src.mustoresize
;
6354 dst
.checkers
<- src.checkers
;
6355 dst
.aalevel
<- src.aalevel
;
6356 dst
.trimmargins
<- src.trimmargins
;
6357 dst
.trimfuzz
<- src.trimfuzz
;
6358 dst
.urilauncher
<- src.urilauncher
;
6359 dst
.colorspace
<- src.colorspace
;
6360 dst
.invert
<- src.invert
;
6361 dst
.colorscale
<- src.colorscale
;
6362 dst
.redirectstderr <- src.redirectstderr;
6363 dst
.ghyllscroll
<- src.ghyllscroll
;
6364 dst
.columns
<- src.columns
;
6365 dst
.beyecolumns
<- src.beyecolumns
;
6366 dst
.selcmd
<- src.selcmd
;
6367 dst
.updatecurs
<- src.updatecurs
;
6368 dst
.pathlauncher
<- src.pathlauncher
;
6369 dst
.keyhashes
<- copykeyhashes src;
6370 dst
.hfsize
<- src.hfsize
;
6371 dst
.hscrollstep
<- src.hscrollstep
;
6372 dst
.pgscale <- src.pgscale;
6373 dst
.usepbo
<- src.usepbo
;
6374 dst
.wheelbypage
<- src.wheelbypage
;
6375 dst
.stcmd
<- src.stcmd
;
6379 let h = Hashtbl.create
10 in
6380 let dc = { defconf with angle
= defconf.angle
} in
6381 let rec toplevel v t spos
_ =
6383 | Vdata
| Vcdata
| Vend
-> v
6384 | Vopen
("llppconfig", _, closed
) ->
6387 else { v with f = llppconfig
}
6389 error
"unexpected subelement at top level" s spos
6390 | Vclose
_ -> error
"unexpected close at top level" s spos
6392 and llppconfig
v t spos
_ =
6394 | Vdata
| Vcdata
-> v
6395 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6396 | Vopen
("defaults", attrs
, closed
) ->
6397 let c = config_of dc attrs
in
6401 else { v with f = defaults
}
6403 | Vopen
("ui-font", attrs
, closed
) ->
6404 let rec getsize size
= function
6406 | ("size", v) :: rest
->
6408 fromstring int_of_string spos
"size" v fstate.fontsize
in
6410 | l -> getsize size l
6412 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6415 else { v with f = uifont
(Buffer.create
10) }
6417 | Vopen
("doc", attrs
, closed
) ->
6418 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6419 let path = unent pathent
6420 and pageno = fromstring int_of_string spos
"page" spage
0
6421 and rely = fromstring float_of_string spos
"rely" srely
0.0
6422 and pan
= fromstring int_of_string spos
"pan" span
0
6423 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6424 let c = config_of dc attrs
in
6425 let anchor = (pageno, rely, visy
) in
6427 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6428 else { v with f = doc
path pan
anchor c [] }
6431 error
"unexpected subelement in llppconfig" s spos
6433 | Vclose
"llppconfig" -> { v with f = toplevel }
6434 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6436 and defaults
v t spos
_ =
6438 | Vdata
| Vcdata
-> v
6439 | Vend
-> error
"unexpected end of input in defaults" s spos
6440 | Vopen
("keymap", attrs
, closed
) ->
6442 try List.assoc
"mode" attrs
6443 with Not_found
-> "global" in
6448 let h = findkeyhash dc modename in
6449 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6452 { v with f = pkeymap
ret KeyMap.empty }
6454 | Vopen
(_, _, _) ->
6455 error
"unexpected subelement in defaults" s spos
6457 | Vclose
"defaults" ->
6458 { v with f = llppconfig
}
6460 | Vclose
_ -> error
"unexpected close in defaults" s spos
6462 and uifont
b v t spos
epos =
6465 Buffer.add_substring
b s spos
(epos - spos
);
6467 | Vopen
(_, _, _) ->
6468 error
"unexpected subelement in ui-font" s spos
6469 | Vclose
"ui-font" ->
6470 if String.length
!fontpath = 0
6471 then fontpath := Buffer.contents
b;
6472 { v with f = llppconfig
}
6473 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6474 | Vend
-> error
"unexpected end of input in ui-font" s spos
6476 and doc
path pan
anchor c bookmarks
v t spos
_ =
6478 | Vdata
| Vcdata
-> v
6479 | Vend
-> error
"unexpected end of input in doc" s spos
6480 | Vopen
("bookmarks", _, closed
) ->
6483 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6485 | Vopen
("keymap", attrs
, closed
) ->
6487 try List.assoc
"mode" attrs
6488 with Not_found
-> "global"
6494 let h = findkeyhash c modename in
6495 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6496 doc
path pan
anchor c bookmarks
6498 { v with f = pkeymap
ret KeyMap.empty }
6500 | Vopen
(_, _, _) ->
6501 error
"unexpected subelement in doc" s spos
6504 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6505 { v with f = llppconfig
}
6507 | Vclose
_ -> error
"unexpected close in doc" s spos
6509 and pkeymap
ret keymap
v t spos
_ =
6511 | Vdata
| Vcdata
-> v
6512 | Vend
-> error
"unexpected end of input in keymap" s spos
6513 | Vopen
("map", attrs
, closed
) ->
6514 let r, l = map_of attrs
in
6515 let kss = fromstring keys_of_string spos
"in" r [] in
6516 let lss = fromstring keys_of_string spos
"out" l [] in
6520 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6521 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6524 then { v with f = pkeymap
ret keymap }
6527 { v with f = skip
"map" f }
6530 error
"unexpected subelement in keymap" s spos
6532 | Vclose
"keymap" ->
6533 { v with f = ret keymap }
6535 | Vclose
_ -> error
"unexpected close in keymap" s spos
6537 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6539 | Vdata
| Vcdata
-> v
6540 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6541 | Vopen
("item", attrs
, closed
) ->
6542 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6543 let page = fromstring int_of_string spos
"page" spage
0
6544 and rely = fromstring float_of_string spos
"rely" srely
0.0
6545 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6547 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6550 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6553 { v with f = skip
"item" f }
6556 error
"unexpected subelement in bookmarks" s spos
6558 | Vclose
"bookmarks" ->
6559 { v with f = doc
path pan
anchor c bookmarks }
6561 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6563 and skip tag
f v t spos
_ =
6565 | Vdata
| Vcdata
-> v
6567 error
("unexpected end of input in skipped " ^ tag
) s spos
6568 | Vopen
(tag'
, _, closed
) ->
6572 let f'
() = { v with f = skip tag
f } in
6573 { v with f = skip tag'
f'
}
6577 else error
("unexpected close in skipped " ^ tag
) s spos
6580 parse
{ f = toplevel; accu = () } s;
6586 let len = in_channel_length ic
in
6587 let s = String.create
len in
6588 really_input ic
s 0 len;
6591 | Parse_error
(msg
, s, pos
) ->
6592 let subs = subs s pos
in
6593 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6594 failwith
("parse error: " ^
s)
6597 failwith
("config load error: " ^ exntos exn
)
6603 let dir = Filename.concat
home ".config" in
6604 if Sys.is_directory
dir then dir else home
6607 Filename.concat
dir "llpp.conf"
6610 let confpath = ref defconfpath;;
6613 if Sys.file_exists
!confpath
6616 (try Some
(open_in_bin
!confpath)
6619 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6630 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6639 f (Hashtbl.create
0, defconf)
6644 let pc, pb
, px, pa
=
6646 Hashtbl.find h (Filename.basename
state.path)
6647 with Not_found
-> dc, [], 0, emptyanchor
6651 state.bookmarks <- pb
;
6653 state.scrollw
<- conf.scrollbw
;
6655 then state.anchor <- pa
;
6656 cbput state.hists
.nav pa
;
6662 let add_attrs bb always
dc c =
6665 then Printf.bprintf bb
"\n %s='%b'" s a
6668 then Printf.bprintf bb
"\n %s='%d'" s a
6671 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6674 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6677 then Printf.bprintf bb
"\n %s='%f'" s a
6681 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6685 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6689 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6693 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6699 | Some
(_N
, _A
, _B
) ->
6700 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6710 else string_of_float
f
6712 Printf.bprintf bb
"\n %s='%s'" s v
6717 | Cmulti
((n, a, b), _) when n > 1 ->
6718 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6719 | Csplit
(n, _) when n > 1 ->
6720 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6726 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6729 oi
"width" c.cwinw
dc.cwinw
;
6730 oi
"height" c.cwinh
dc.cwinh
;
6731 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6732 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6733 ob "case-insensitive-search" c.icase
dc.icase
;
6734 ob "preload" c.preload dc.preload;
6735 oi
"page-bias" c.pagebias
dc.pagebias
;
6736 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6737 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6738 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6739 ob "crop-hack" c.crophack
dc.crophack
;
6740 oW
"throttle" c.maxwait
dc.maxwait
;
6741 ob "highlight-links" c.hlinks
dc.hlinks
;
6742 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6743 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6744 oz
"zoom" c.zoom dc.zoom;
6745 ob "presentation" c.presentation
dc.presentation
;
6746 oi
"rotation-angle" c.angle
dc.angle
;
6747 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6748 ob "proportional-display" c.proportional
dc.proportional
;
6749 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6750 oi
"tex-count" c.texcount
dc.texcount
;
6751 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6752 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6753 ob "persistent-location" c.jumpback
dc.jumpback
;
6754 oc
"background-color" c.bgcolor
dc.bgcolor
;
6755 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6756 oi
"tile-width" c.tilew
dc.tilew
;
6757 oi
"tile-height" c.tileh
dc.tileh
;
6758 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6759 ob "checkers" c.checkers
dc.checkers
;
6760 oi
"aalevel" c.aalevel
dc.aalevel
;
6761 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6762 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6763 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6764 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6765 oC
"color-space" c.colorspace
dc.colorspace
;
6766 ob "invert-colors" c.invert
dc.invert
;
6767 oF
"brightness" c.colorscale
dc.colorscale
;
6768 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6769 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6770 oco
"columns" c.columns
dc.columns
;
6771 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6772 os
"selection-command" c.selcmd
dc.selcmd
;
6773 os
"synctex-command" c.stcmd
dc.stcmd
;
6774 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6775 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6776 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6777 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6778 ob "use-pbo" c.usepbo
dc.usepbo
;
6779 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6782 let keymapsbuf always
dc c =
6783 let bb = Buffer.create
16 in
6784 let rec loop = function
6786 | (modename, h) :: rest
->
6787 let dh = findkeyhash dc modename in
6788 if always
|| h <> dh
6790 if Hashtbl.length
h > 0
6792 if Buffer.length
bb > 0
6793 then Buffer.add_char
bb '
\n'
;
6794 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6795 Hashtbl.iter
(fun i
o ->
6796 let isdifferent = always
||
6798 let dO = Hashtbl.find dh i
in
6800 with Not_found
-> true
6805 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6806 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6807 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6808 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6809 Buffer.add_string
bb (Wsi.keyname
k);
6812 let rec loop = function
6814 | km
:: [] -> addkm km
6815 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6819 Buffer.add_string
bb "<map in='";
6823 Buffer.add_string
bb "' out='";
6825 Buffer.add_string
bb "'/>\n"
6828 Buffer.add_string
bb "' out='";
6830 Buffer.add_string
bb "'/>\n"
6832 | KMmulti
(ins, kms
) ->
6833 Buffer.add_char
bb ' '
;
6835 Buffer.add_string
bb "' out='";
6837 Buffer.add_string
bb "'/>\n"
6839 Buffer.add_string
bb "</keymap>";
6849 let uifontsize = fstate.fontsize
in
6850 let bb = Buffer.create
32768 in
6855 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
)
6856 | Wsi.MaxVert
-> (w, conf.cwinh
)
6857 | Wsi.MaxHorz
-> (conf.cwinw
, h)
6859 (state.winw, state.winh
) state.winstate
6864 let dc = if conf.bedefault
then conf else dc in
6865 Buffer.add_string
bb "<llppconfig>\n";
6867 if String.length
!fontpath > 0
6869 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6875 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6878 Buffer.add_string
bb "<defaults ";
6879 add_attrs bb true dc dc;
6880 let kb = keymapsbuf true dc dc in
6881 if Buffer.length
kb > 0
6883 Buffer.add_string
bb ">\n";
6884 Buffer.add_buffer
bb kb;
6885 Buffer.add_string
bb "\n</defaults>\n";
6887 else Buffer.add_string
bb "/>\n";
6889 let adddoc path pan
anchor c bookmarks =
6890 if bookmarks == [] && c = dc && anchor = emptyanchor
6893 Printf.bprintf
bb "<doc path='%s'"
6894 (enent
path 0 (String.length
path));
6896 if anchor <> emptyanchor
6898 let n, rely, visy
= anchor in
6899 Printf.bprintf
bb " page='%d'" n;
6902 Printf.bprintf
bb " rely='%f'" rely
6904 if abs_float visy
> 1e-6
6906 Printf.bprintf
bb " visy='%f'" visy
6911 then Printf.bprintf
bb " pan='%d'" pan
;
6913 add_attrs bb false dc c;
6914 let kb = keymapsbuf false dc c in
6916 begin match bookmarks with
6918 if Buffer.length
kb > 0
6920 Buffer.add_string
bb ">\n";
6921 Buffer.add_buffer
bb kb;
6922 Buffer.add_string
bb "\n</doc>\n";
6924 else Buffer.add_string
bb "/>\n"
6926 Buffer.add_string
bb ">\n<bookmarks>\n";
6927 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6929 "<item title='%s' page='%d'"
6930 (enent
title 0 (String.length
title))
6935 Printf.bprintf
bb " rely='%f'" rely
6937 if abs_float visy
> 1e-6
6939 Printf.bprintf
bb " visy='%f'" visy
6941 Buffer.add_string
bb "/>\n";
6943 Buffer.add_string
bb "</bookmarks>";
6944 if Buffer.length
kb > 0
6946 Buffer.add_string
bb "\n";
6947 Buffer.add_buffer
bb kb;
6949 Buffer.add_string
bb "\n</doc>\n";
6955 match state.mode with
6956 | Birdseye
(c, pan, _, _, _) ->
6958 match conf.columns
with
6959 | Cmulti
((c, _, _), _) -> Some
c
6963 match c.columns
with
6964 | Cmulti
(c, _) -> Cmulti
(c, [||])
6965 | Csingle
_ -> Csingle
[||]
6966 | Csplit
_ -> failwith
"quit from bird's eye while split"
6968 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6969 | _ -> state.x, conf
6971 let basename = Filename.basename state.path in
6972 adddoc basename pan (getanchor ())
6974 let autoscrollstep =
6975 match state.autoscroll
with
6977 | None
-> conf.autoscrollstep
6979 match state.mode with
6980 | Birdseye
(bc
, _, _, _, _) ->
6983 presentation
= bc
.presentation
;
6984 interpagespace
= bc
.interpagespace
;
6985 maxwait
= bc
.maxwait
;
6986 autoscrollstep = autoscrollstep }
6987 | _ -> { conf with autoscrollstep = autoscrollstep }
6989 (if conf.savebmarks
then state.bookmarks else []);
6991 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6993 then adddoc path x anchor c bookmarks
6995 Buffer.add_string
bb "</llppconfig>\n";
6998 if load1 f && Buffer.length
bb > 0
7001 let tmp = !confpath ^
".tmp" in
7002 let oc = open_out_bin
tmp in
7003 Buffer.output_buffer
oc bb;
7005 Unix.rename
tmp !confpath;
7008 ("error while saving configuration: " ^ exntos exn
)
7012 let adderrmsg src msg
=
7013 Buffer.add_string
state.errmsgs msg
;
7014 state.newerrmsgs
<- true;
7018 let adderrfmt src fmt
=
7019 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7023 let cl = splitatspace cmds
in
7025 try Scanf.sscanf
s fmt
f
7027 adderrfmt "remote exec"
7028 "error processing '%S': %s\n" cmds
(exntos exn
)
7031 | "reload" :: [] -> reload ()
7032 | "goto" :: args :: [] ->
7033 scan args "%u %f %f"
7035 let cmd, _ = state.geomcmds
in
7036 if String.length
cmd = 0
7037 then gotopagexy pageno x y
7040 gotopagexy pageno x y;
7043 state.reprf
<- f state.reprf
7045 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7046 | "rect" :: args :: [] ->
7047 scan args "%u %u %f %f %f %f"
7048 (fun pageno color x0 y0 x1 y1 ->
7049 onpagerect pageno (fun w h ->
7050 let _,w1,h1
,_ = getpagedim pageno in
7051 let sw = float w1 /. w
7052 and sh = float h1
/. h in
7056 and y1s
= y1 *. sh in
7057 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7059 state.rects <- (pageno, color, rect) :: state.rects;
7060 G.postRedisplay "rect";
7063 | "activatewin" :: [] -> Wsi.activatewin
()
7064 | "quit" :: [] -> raise Quit
7066 adderrfmt "remote command"
7067 "error processing remote command: %S\n" cmds
;
7071 let scratch = String.create
80 in
7072 let buf = Buffer.create
80 in
7075 try Some
(Unix.read fd
scratch 0 80)
7077 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7078 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7081 match tempfr () with
7087 if Buffer.length
buf > 0
7089 let s = Buffer.contents
buf in
7099 let pos = String.index_from
scratch ppos '
\n'
in
7100 if pos >= n then -1 else pos
7101 with Not_found
-> -1
7105 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7106 let s = Buffer.contents
buf in
7112 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7118 let remoteopen path =
7119 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7121 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7126 let trimcachepath = ref "" in
7127 let rcmdpath = ref "" in
7130 [("-p", Arg.String
(fun s -> state.password
<- s) ,
7131 "<password> Set password");
7133 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7134 "<path> Set path to the user interface font");
7136 ("-c", Arg.String
(fun s -> Config.confpath := s),
7137 "<path> Set path to the configuration file");
7139 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7140 "<path> Set path to the trim cache file");
7142 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7143 "<named-destination> Set named destination");
7145 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7147 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7148 "<path> Set path to the remote commands source");
7150 ("-v", Arg.Unit
(fun () ->
7152 "%s\nconfiguration path: %s\n"
7156 exit
0), " Print version and exit");
7159 (fun s -> state.path <- s)
7160 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7162 if String.length
state.path = 0
7163 then (prerr_endline
"file name missing"; exit
1);
7165 if not
(Config.load ())
7166 then prerr_endline
"failed to load configuration";
7168 let globalkeyhash = findkeyhash conf "global" in
7169 let wsfd, winw, winh
= Wsi.init
(object
7171 state.wthack <- false;
7172 if nogeomcmds state.geomcmds
|| platform == Posx
7175 GlClear.color (scalecolor2 conf.bgcolor
);
7176 GlClear.clear
[`
color];
7178 method display = display ()
7179 method reshape w h = reshape w h
7180 method mouse b d x y m = mouse b d x y m
7181 method motion x y = state.mpos
<- (x, y); motion x y
7182 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7184 let mascm = m land (
7185 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7187 match state.keystate
with
7189 let km = k, mascm in
7192 let modehash = state.uioh#
modehash in
7193 try Hashtbl.find modehash km
7195 try Hashtbl.find globalkeyhash km
7196 with Not_found
-> KMinsrt
(k, m)
7198 | KMinsrt
(k, m) -> keyboard k m
7199 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7200 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7202 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7203 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7204 state.keystate
<- KSnone
7205 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7206 state.keystate
<- KSinto
(keys
, insrt
)
7208 state.keystate
<- KSnone
7210 method enter
x y = state.mpos
<- (x, y); pmotion x y
7211 method leave = state.mpos
<- (-1, -1)
7212 method winstate wsl
= state.winstate
<- wsl
7213 method quit
= raise Quit
7214 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7219 List.exists
GlMisc.check_extension
7220 [ "GL_ARB_texture_rectangle"
7221 ; "GL_EXT_texture_recangle"
7222 ; "GL_NV_texture_rectangle" ]
7224 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7227 match Ne.pipe () with
7229 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7233 match Ne.pipe () with
7235 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7245 setcheckers conf.checkers
;
7249 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7250 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7251 !Config.fontpath, !trimcachepath,
7252 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7256 state.text <- "Opening " ^
(mbtoutf8
state.path);
7258 opendoc state.path state.password
;
7261 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7264 if String.length
!rcmdpath > 0
7265 then remoteopen !rcmdpath
7270 let rec loop deadline
=
7272 match state.errfd
with
7273 | None
-> [state.sr
; state.wsfd]
7274 | Some fd
-> [state.sr
; state.wsfd; fd
]
7279 | Some fd
-> fd
:: r
7281 if state.redisplay
&& not
state.wthack
7283 state.redisplay
<- false;
7290 if deadline
= infinity
7292 else max
0.0 (deadline
-. now)
7297 try Unix.select
r [] [] timeout
7298 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7304 if state.ghyll
== noghyll
7306 match state.autoscroll
with
7307 | Some step
when step
!= 0 ->
7308 let y = state.y + step
in
7312 else if y >= state.maxy then 0 else y
7315 if state.mode = View
7316 then state.text <- "";
7319 else deadline
+. 0.01
7324 let rec checkfds = function
7326 | fd
:: rest
when fd
= state.sr
->
7327 let cmd = readcmd state.sr
in
7331 | fd
:: rest
when fd
= state.wsfd ->
7335 | fd
:: rest
when Some fd
= !optrfd ->
7336 begin match remote fd
with
7337 | None
-> optrfd := remoteopen !rcmdpath;
7338 | opt -> optrfd := opt
7343 let s = String.create
80 in
7344 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7345 if conf.redirectstderr
7347 Buffer.add_substring
state.errmsgs
s 0 n;
7348 state.newerrmsgs
<- true;
7349 state.redisplay
<- true;
7352 prerr_string
(String.sub
s 0 n);
7360 if deadline
= infinity
7364 match state.autoscroll
with
7365 | Some step
when step
!= 0 -> deadline1
7366 | _ -> if state.ghyll
== noghyll then infinity
else deadline1