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 postprocess
:
96 opaque
-> int -> int -> int -> (int * string * int) -> int
98 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
99 external platform
: unit -> platform
= "ml_platform";;
100 external setaalevel
: int -> unit = "ml_setaalevel";;
101 external realloctexts
: int -> bool = "ml_realloctexts";;
102 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
103 external getlink
: opaque
-> int -> under
= "ml_getlink";;
104 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
105 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
106 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
107 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
108 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
109 external freepbo
: string -> unit = "ml_freepbo";;
110 external unmappbo
: string -> unit = "ml_unmappbo";;
111 external pbousable
: unit -> bool = "ml_pbo_usable";;
112 external unproject
: opaque
-> int -> int -> (int * int) option
114 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
116 let platform_to_string = function
117 | Punknown
-> "unknown"
121 | Pfreebsd
-> "FreeBSD"
122 | Pdragonflybsd
-> "DragonflyBSD"
123 | Popenbsd
-> "OpenBSD"
124 | Pnetbsd
-> "NetBSD"
125 | Pcygwin
-> "Cygwin"
128 let platform = platform ();;
130 let now = Unix.gettimeofday
;;
133 if platform = Pcygwin
135 let sh = "/bin/sh" in
136 let args = [|sh; "-c"; cmd
|] in
137 let rec std si so se
= function
139 | (fd
, 0) :: rest
-> std fd so se rest
140 | (fd
, -1) :: rest
->
141 Unix.set_close_on_exec fd
;
144 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
146 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
147 ignore
(Unix.create_process
sh args si so se
)
152 type mpos
= int * int
154 | Msel
of (mpos
* mpos
)
156 | Mscrolly
| Mscrollx
157 | Mzoom
of (int * int)
158 | Mzoomrect
of (mpos
* mpos
)
162 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
163 and onkey
= string -> int -> te
164 and ondone
= string -> unit
165 and histcancel
= unit -> unit
166 and onhist
= ((histcmd
-> string) * histcancel
)
167 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
168 and cancelonempty
= bool
173 | TEswitch
of textentry
184 let bound v minv maxv
=
185 max minv
(min maxv v
);
189 { store
= Array.create n v
196 let cbcap b
= Array.length b
.store
;;
201 b
.wc
<- (b
.wc
+ 1) mod cap;
203 b
.len
<- min
(b
.len
+ 1) cap;
206 let cbempty b
= b
.len
= 0;;
208 let cbgetg b circular dir
=
212 let rc = b
.rc + dir
in
224 else bound rc 0 (b
.len
-1)
230 let cbget b
= cbgetg b
false;;
231 let cbgetc b
= cbgetg b
true;;
233 let drawstring size x y s
=
235 Gl.enable `texture_2d
;
236 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
237 ignore
(drawstr size x y s
);
239 Gl.disable `texture_2d
;
242 let drawstring1 size x y s
=
246 let drawstring2 size x y fmt
=
247 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
266 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
267 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
268 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
269 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
270 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
271 dolog
" column %d" l
.pagecol
;
275 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
277 dolog
" x0,y0=(% f, % f)" x0 y0
;
278 dolog
" x1,y1=(% f, % f)" x1 y1
;
279 dolog
" x2,y2=(% f, % f)" x2 y2
;
280 dolog
" x3,y3=(% f, % f)" x3 y3
;
284 type multicolumns
= multicol
* pagegeom
285 and singlecolumn
= pagegeom
286 and splitcolumns
= columncount
* pagegeom
287 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
288 and multicol
= columncount
* covercount
* covercount
290 and columncount
= int
291 and covercount
= int;;
294 { mutable scrollbw
: int
295 ; mutable scrollh
: int
296 ; mutable icase
: bool
297 ; mutable preload
: bool
298 ; mutable pagebias
: int
299 ; mutable verbose
: bool
300 ; mutable debug
: bool
301 ; mutable scrollstep
: int
302 ; mutable hscrollstep
: int
303 ; mutable maxhfit
: bool
304 ; mutable crophack
: bool
305 ; mutable autoscrollstep
: int
306 ; mutable maxwait
: float option
307 ; mutable hlinks
: bool
308 ; mutable underinfo
: bool
309 ; mutable interpagespace
: interpagespace
310 ; mutable zoom
: float
311 ; mutable presentation
: bool
312 ; mutable angle
: angle
313 ; mutable cwinw
: int
314 ; mutable cwinh
: int
315 ; mutable savebmarks
: bool
316 ; mutable proportional
: proportional
317 ; mutable trimmargins
: trimmargins
318 ; mutable trimfuzz
: irect
319 ; mutable memlimit
: memsize
320 ; mutable texcount
: texcount
321 ; mutable sliceheight
: sliceheight
322 ; mutable thumbw
: width
323 ; mutable jumpback
: bool
324 ; mutable bgcolor
: float * float * float
325 ; mutable bedefault
: bool
326 ; mutable scrollbarinpm
: bool
327 ; mutable tilew
: int
328 ; mutable tileh
: int
329 ; mutable mustoresize
: memsize
330 ; mutable checkers
: bool
331 ; mutable aalevel
: int
332 ; mutable urilauncher
: string
333 ; mutable pathlauncher
: string
334 ; mutable colorspace
: colorspace
335 ; mutable invert
: bool
336 ; mutable colorscale
: float
337 ; mutable redirectstderr
: bool
338 ; mutable ghyllscroll
: (int * int * int) option
339 ; mutable columns
: columns
340 ; mutable beyecolumns
: columncount
option
341 ; mutable selcmd
: string
342 ; mutable updatecurs
: bool
343 ; mutable keyhashes
: (string * keyhash
) list
344 ; mutable hfsize
: int
345 ; mutable pgscale
: float
346 ; mutable usepbo
: bool
347 ; mutable wheelbypage
: bool
348 ; mutable stcmd
: string
351 | Csingle
of singlecolumn
352 | Cmulti
of multicolumns
353 | Csplit
of splitcolumns
356 type anchor
= pageno
* top
* dtop
;;
358 type outline
= string * int * anchor
;;
360 type rect
= float * float * float * float * float * float * float * float;;
362 type tile
= opaque
* pixmapsize
* elapsed
363 and elapsed
= float;;
364 type pagemapkey
= pageno
* gen
;;
365 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
369 let emptyanchor = (0, 0.0, 0.0);;
371 type infochange
= | Memused
| Docinfo
| Pdim
;;
373 class type uioh
= object
374 method display
: unit
375 method key
: int -> int -> uioh
376 method button
: int -> bool -> int -> int -> int -> uioh
377 method motion
: int -> int -> uioh
378 method pmotion
: int -> int -> uioh
379 method infochanged
: infochange
-> unit
380 method scrollpw
: (int * float * float)
381 method scrollph
: (int * float * float)
382 method modehash
: keyhash
386 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
387 | Textentry
of (textentry
* onleave
)
389 | LinkNav
of linktarget
390 and onleave
= leavetextentrystatus
-> unit
391 and leavetextentrystatus
= | Cancel
| Confirm
392 and helpitem
= string * int * action
395 | Action
of (uioh
-> uioh
)
397 | Ltexact
of (pageno
* int)
401 let isbirdseye = function Birdseye _
-> true | _
-> false;;
402 let istextentry = function Textentry _
-> true | _
-> false;;
406 | Loading
of (page
* gen
)
408 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
410 | Outlining
of outline list
413 let emptykeyhash = Hashtbl.create
0;;
414 let nouioh : uioh
= object (self
)
416 method key _ _
= self
417 method button _ _ _ _ _
= self
418 method motion _ _
= self
419 method pmotion _ _
= self
420 method infochanged _
= ()
421 method scrollpw
= (0, nan
, nan
)
422 method scrollph
= (0, nan
, nan
)
423 method modehash
= emptykeyhash
427 { mutable sr
: Unix.file_descr
428 ; mutable sw
: Unix.file_descr
429 ; mutable wsfd
: Unix.file_descr
430 ; mutable errfd
: Unix.file_descr
option
431 ; mutable stderr
: Unix.file_descr
432 ; mutable errmsgs
: Buffer.t
433 ; mutable newerrmsgs
: bool
437 ; mutable scrollw
: int
438 ; mutable hscrollh
: int
439 ; mutable anchor
: anchor
440 ; mutable ranchors
: (string * string * anchor
) list
442 ; mutable layout
: page list
443 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
444 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
445 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
446 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
447 ; mutable pagecount
: int
448 ; mutable currently
: currently
449 ; mutable mstate
: mstate
450 ; mutable searchpattern
: string
451 ; mutable rects
: (pageno
* recttype
* rect
) list
452 ; mutable rects1
: (pageno
* recttype
* rect
) list
453 ; mutable text
: string
454 ; mutable winstate
: Wsi.winstate list
455 ; mutable mode
: mode
456 ; mutable uioh
: uioh
457 ; mutable outlines
: outline array
458 ; mutable bookmarks
: outline list
459 ; mutable path
: string
460 ; mutable password
: string
461 ; mutable nameddest
: string
462 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
463 ; mutable memused
: memsize
465 ; mutable throttle
: (page list
* int * float) option
466 ; mutable autoscroll
: int option
467 ; mutable ghyll
: (int option -> unit)
468 ; mutable help
: helpitem array
469 ; mutable docinfo
: (int * string) list
470 ; mutable texid
: GlTex.texture_id
option
472 ; mutable prevzoom
: float
473 ; mutable progress
: float
474 ; mutable redisplay
: bool
475 ; mutable mpos
: mpos
476 ; mutable keystate
: keystate
477 ; mutable glinks
: bool
478 ; mutable prevcolumns
: (columns
* float) option
481 ; mutable reprf
: (unit -> unit)
484 { pat
: string circbuf
485 ; pag
: string circbuf
486 ; nav
: anchor circbuf
487 ; sel
: string circbuf
509 ; presentation
= false
514 ; proportional
= true
515 ; trimmargins
= false
516 ; trimfuzz
= (0,0,0,0)
517 ; memlimit
= 32 lsl 20
522 ; bgcolor
= (0.5, 0.5, 0.5)
524 ; scrollbarinpm
= true
527 ; mustoresize
= 256 lsl 20
532 | Plinux
| Pfreebsd
| Pdragonflybsd
533 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
534 | Posx
-> "open \"%s\""
535 | Pcygwin
-> "cygstart \"%s\""
536 | Punknown
-> "echo %s")
537 ; pathlauncher
= "lp \"%s\""
540 | Plinux
| Pfreebsd
| Pdragonflybsd
541 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
548 ; redirectstderr
= false
550 ; columns
= Csingle
[||]
556 ; wheelbypage
= false
557 ; stcmd
= "echo SyncTex"
559 let mk n
= (n
, Hashtbl.create
1) in
573 let wtmode = ref false;;
575 let findkeyhash c name
=
576 try List.assoc name c
.keyhashes
577 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
580 let conf = { defconf with angle
= defconf.angle
};;
582 let pgscale h
= truncate
(float h
*. conf.pgscale);;
585 { mutable fontsize
: int
586 ; mutable wwidth
: float
587 ; mutable maxrows
: int
599 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
600 let len = String.length s
in
601 if colonpos >= 0 && colonpos + 3 < len
603 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
606 try String.rindex_from s
colonpos ' '
610 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
613 | "http" | "ftp" | "mailto" ->
615 try String.index_from s
colonpos ' '
616 with Not_found
-> len
618 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
626 if String.length
conf.urilauncher
= 0
627 then print_endline uri
629 let url = geturl uri
in
630 if String.length
url = 0
631 then print_endline uri
633 let re = Str.regexp
"%s" in
634 let command = Str.global_replace
re url conf.urilauncher
in
638 "failed to execute `%s': %s\n" command (exntos exn
);
644 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
645 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
649 let strings = version () :: "" :: Help.keys
in
652 let url = geturl s
in
653 if String.length
url > 0
654 then (s
, 0, Action
(fun u
-> gotouri url; u
))
655 else (s
, 0, Noaction
)
660 let firstgeomcmds = "", [];;
661 let noreprf () = ();;
668 ; stderr
= Unix.stderr
669 ; errmsgs
= Buffer.create
0
676 ; anchor
= emptyanchor
680 ; tilelru
= Queue.create
()
681 ; pagemap
= Hashtbl.create
10
682 ; tilemap
= Hashtbl.create
10
698 ; geomcmds
= firstgeomcmds
700 { nav
= cbnew 10 emptyanchor
728 fstate.fontsize
<- n
;
729 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
730 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
736 Printf.kprintf prerr_endline fmt
738 Printf.kprintf ignore fmt
742 if String.length
conf.pathlauncher
= 0
743 then print_endline
state.path
745 let re = Str.regexp
"%s" in
746 let command = Str.global_replace
re state.path
conf.pathlauncher
in
749 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
755 type 'a t
= | Res
of 'a
| Exn
of exn
;;
758 try Res
(Unix.pipe ())
763 try tempfailureretry
Unix.close fd
764 with exn
-> f
(exntos exn
)
768 try Res
(tempfailureretry
Unix.dup fd
)
773 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
778 let redirectstderr () =
779 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
780 if conf.redirectstderr
782 match Ne.pipe () with
784 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
787 begin match Ne.dup Unix.stderr
with
789 dolog
"failed to dup stderr: %s" (exntos exn
);
790 Ne.clo r
(clofail "pipe/r");
791 Ne.clo w
(clofail "pipe/w");
793 | Ne.Res dupstderr
->
794 begin match Ne.dup2 w
Unix.stderr
with
796 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
797 Ne.clo dupstderr
(clofail "stderr duplicate");
798 Ne.clo r
(clofail "redir pipe/r");
799 Ne.clo w
(clofail "redir pipe/w");
802 state.stderr
<- dupstderr
;
803 state.errfd
<- Some r
;
807 state.newerrmsgs
<- false;
808 begin match state.errfd
with
810 begin match Ne.dup2 state.stderr
Unix.stderr
with
812 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
814 Ne.clo fd
(clofail "dup of stderr");
819 prerr_string
(Buffer.contents
state.errmsgs
);
821 Buffer.clear
state.errmsgs
;
827 let postRedisplay who
=
829 then prerr_endline
("redisplay for " ^ who
);
830 state.redisplay
<- true;
834 let getopaque pageno
=
835 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
836 with Not_found
-> None
839 let putopaque pageno opaque
=
840 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
843 let pagetranslatepoint l x y
=
844 let dy = y
- l
.pagedispy
in
845 let y = dy + l
.pagey
in
846 let dx = x
- l
.pagedispx
in
847 let x = dx + l
.pagex
in
851 let onppundermouse g
x y d
=
854 begin match getopaque l
.pageno
with
856 let x0 = l
.pagedispx
in
857 let x1 = x0 + l
.pagevw
in
858 let y0 = l
.pagedispy
in
859 let y1 = y0 + l
.pagevh
in
860 if y >= y0 && y <= y1 && x >= x0 && x <= x1
862 let px, py
= pagetranslatepoint l
x y in
863 match g opaque l
px py
with
876 let g opaque _
px py
=
877 match whatsunder opaque
px py
with
879 | under
-> Some under
881 onppundermouse g x y Unone
886 match unproject opaque
x y with
887 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
890 onppundermouse g x y None
;
894 state.text
<- Printf.sprintf
"%c%s" c s
;
895 G.postRedisplay "showtext";
898 let undertext = function
901 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
902 | Utext s
-> "font: " ^ s
903 | Uunexpected s
-> "unexpected: " ^ s
904 | Ulaunch s
-> "launch: " ^ s
905 | Unamed s
-> "named: " ^ s
906 | Uremote
(filename
, pageno
) ->
907 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
910 let updateunder x y =
911 match getunder x y with
912 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
914 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
915 Wsi.setcursor
Wsi.CURSOR_INFO
916 | Ulinkgoto
(pageno
, _
) ->
918 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
919 Wsi.setcursor
Wsi.CURSOR_INFO
921 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
922 Wsi.setcursor
Wsi.CURSOR_TEXT
924 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
925 Wsi.setcursor
Wsi.CURSOR_INHERIT
927 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
928 Wsi.setcursor
Wsi.CURSOR_INHERIT
930 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
931 Wsi.setcursor
Wsi.CURSOR_INHERIT
932 | Uremote
(filename
, pageno
) ->
933 if conf.underinfo
then showtext 'r'
934 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
935 Wsi.setcursor
Wsi.CURSOR_INFO
938 let showlinktype under
=
944 let s = undertext under
in
949 let b = Buffer.create
(String.length
s + 1) in
950 Buffer.add_string
b s;
955 let colorspace_of_string s =
956 match String.lowercase
s with
960 | _
-> failwith
"invalid colorspace"
963 let int_of_colorspace = function
969 let colorspace_of_int = function
973 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
976 let colorspace_to_string = function
982 let intentry_with_suffix text key
=
984 if key
>= 32 && key
< 127
988 match Char.lowercase
c with
990 let text = addchar text c in
994 let text = addchar text c in
998 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1002 let multicolumns_to_string (n
, a
, b) =
1004 then Printf.sprintf
"%d" n
1005 else Printf.sprintf
"%d,%d,%d" n a
b;
1008 let multicolumns_of_string s =
1010 (int_of_string
s, 0, 0)
1012 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1014 then failwith
"subtly broken"; (n
, a
, b)
1020 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1021 if n != 4 then failwith
"incomplete read(len)";
1023 lor (Char.code
s.[0] lsl 24)
1024 lor (Char.code
s.[1] lsl 16)
1025 lor (Char.code
s.[2] lsl 8)
1026 lor (Char.code
s.[3] lsl 0)
1028 let s = String.create
len in
1029 let n = tempfailureretry
(Unix.read fd
s 0) len in
1030 if n != len then failwith
"incomplete read(data)";
1034 let btod b = if b then 1 else 0;;
1037 let b = Buffer.create
16 in
1038 Buffer.add_string
b "llll";
1041 let s = Buffer.contents
b in
1042 let n = String.length
s in
1044 (* dolog "wcmd %S" (String.sub s 4 len); *)
1045 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1046 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1047 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1048 s.[3] <- Char.chr
(len land 0xff);
1049 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1050 if n'
!= n then failwith
"write failed";
1055 let d = state.winh
- h
in
1056 max
conf.interpagespace
((d + 1) / 2)
1059 let rowyh (c, coverA
, coverB
) b n =
1060 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1062 let _, _, vy
, (_, _, h
, _) = b.(n) in
1065 let n'
= n - coverA
in
1068 let e = min
state.pagecount
(s + c) in
1069 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1070 let _, _, y, (_, _, h
, _) = b.(m
) in
1071 let miny = min
miny y in
1072 let maxh = max
maxh h
in
1073 find (m
+1) miny maxh
1078 match conf.columns
with
1079 | Cmulti
((_, _, _) as cl
, b) ->
1080 if Array.length
b > 0
1082 let y, h
= rowyh cl
b (Array.length
b - 1) in
1083 y + h
+ (if conf.presentation
then calcips h
else 0)
1086 if Array.length
b > 0
1088 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1089 y + h
+ (if conf.presentation
then calcips h
else 0)
1092 if Array.length
b > 0
1094 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1099 let getpageyh pageno
=
1100 let pageno = bound pageno 0 (state.pagecount
-1) in
1101 match conf.columns
with
1103 if Array.length
b = 0
1106 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1108 if conf.presentation
1114 if Array.length
b = 0
1117 let y, h
= rowyh cl
b pageno in
1119 if conf.presentation
1125 if Array.length
b = 0
1129 let (_, _, y, (_, _, h
, _)) = b.(n) in
1133 let getpagedim pageno =
1136 | (n, _, _, _) as pdim
:: rest
->
1138 then (if n = pageno then pdim
else ppdim
)
1143 f (-1, -1, -1, -1) state.pdims
1146 let getpagey pageno = fst
(getpageyh pageno);;
1148 let nogeomcmds cmds
=
1150 | s, [] -> String.length
s = 0
1155 let ((c, coverA
, coverB
) as cl
), b =
1156 match conf.columns
with
1157 | Csingle
b -> (1, 0, 0), b
1158 | Cmulti
(c, b) -> c, b
1159 | Csplit
(_, b) -> (1, 0, 0), b
1161 if Array.length
b = 0
1164 let rec bsearch nmin nmax
=
1166 then bound nmin
0 (state.pagecount
-1)
1168 let n = (nmax
+ nmin
) / 2 in
1169 let vy, h
= rowyh cl
b n in
1171 if conf.presentation
1173 let ips = calcips h
in
1174 let y0 = vy - ips in
1175 let y1 = vy + h
+ ips in
1179 then 0, vy + h
+ conf.interpagespace
1181 let y0 = vy - conf.interpagespace
in
1182 y0, y0 + h
+ conf.interpagespace
1185 if y >= y0 && y < y1
1192 if n < state.pagecount
- coverB
1193 then ((n-coverA
)/c)*c + coverA
1200 then bsearch (n+1) nmax
1201 else bsearch nmin
(n-1)
1204 let r = bsearch 0 (state.pagecount
-1) in
1208 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1209 let sh = sh - state.hscrollh
in
1210 let rec fold accu
n =
1211 if n = Array.length
b
1214 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1217 || n = state.pagecount
- coverB
1218 || (n - coverA
) mod columns
= columns
- 1)
1224 let pagey = max
0 (y - vy) in
1225 let pagedispy = if pagey > 0 then 0 else vy - y in
1226 let pagedispx, pagex
=
1228 if n = coverA
- 1 || n = state.pagecount
- coverB
1229 then state.x + (state.winw
- state.scrollw
- w
) / 2
1230 else dx + xoff
+ state.x
1237 let vw = state.winw
- state.scrollw
- pagedispx in
1238 let pw = w
- pagex
in
1241 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1242 if pagevw > 0 && pagevh > 0
1246 ; pagedimno
= pdimno
1253 ; pagedispx = pagedispx
1254 ; pagedispy = pagedispy
1266 List.rev
(fold [] (page_of_y y));
1269 let layoutS (columns
, b) y sh =
1270 let sh = sh - state.hscrollh
in
1271 let rec fold accu n =
1272 if n = Array.length
b
1275 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1282 let x = xoff
+ state.x in
1283 let pagey = max
0 (y - vy) in
1284 let pagedispy = if pagey > 0 then 0 else vy - y in
1285 let pagedispx, pagex
=
1299 let pagecolw = pagew
/columns
in
1301 if pagecolw < state.winw
1302 then pagedispx + ((state.winw
- state.scrollw
- pagecolw) / 2)
1306 let vw = state.winw
- pagedispx - state.scrollw
in
1307 let pw = pagew
- pagex
in
1310 let pagevw = min
pagevw pagecolw in
1311 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1312 if pagevw > 0 && pagevh > 0
1315 { pageno = n/columns
1316 ; pagedimno
= pdimno
1323 ; pagedispx = pagedispx
1324 ; pagedispy = pagedispy
1325 ; pagecol
= n mod columns
1336 List.rev
(fold [] 0)
1340 if nogeomcmds state.geomcmds
1342 match conf.columns
with
1343 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1344 | Cmulti
c -> layoutN c y sh
1345 | Csplit
s -> layoutS s y sh
1350 let y = state.y + incr
in
1352 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1357 let tilex = l
.pagex
mod conf.tilew
in
1358 let tiley = l
.pagey mod conf.tileh
in
1360 let col = l
.pagex
/ conf.tilew
in
1361 let row = l
.pagey / conf.tileh
in
1363 let rec rowloop row y0 dispy h
=
1367 let dh = conf.tileh
- y0 in
1368 let dh = min h
dh in
1369 let rec colloop col x0 dispx w
=
1373 let dw = conf.tilew
- x0 in
1374 let dw = min w
dw in
1376 f col row dispx dispy
x0 y0 dw dh;
1377 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1380 colloop col tilex l
.pagedispx l
.pagevw;
1381 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1384 if l
.pagevw > 0 && l
.pagevh > 0
1385 then rowloop row tiley l
.pagedispy l
.pagevh;
1388 let gettileopaque l
col row =
1390 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1392 try Some
(Hashtbl.find state.tilemap
key)
1393 with Not_found
-> None
1396 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1397 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1398 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1401 let drawtiles l color
=
1403 let f col row x y tilex tiley w h
=
1404 match gettileopaque l
col row with
1405 | Some
(opaque
, _, t
) ->
1406 let params = x, y, w
, h
, tilex, tiley in
1410 GlFunc.blend_func `zero `one_minus_src_color
;
1412 drawtile
params opaque
;
1414 then Gl.disable `blend
;
1417 let s = Printf.sprintf
1421 let w = measurestr
fstate.fontsize
s in
1422 GlMisc.push_attrib
[`current
];
1423 GlDraw.color
(0.0, 0.0, 0.0);
1425 (float (x-2), float (y-2))
1426 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1427 GlDraw.color
(1.0, 1.0, 1.0);
1428 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1429 GlMisc.pop_attrib
();
1434 let lw = state.winw
- state.scrollw
- x in
1437 let lh = state.winh
- y in
1440 begin match state.texid
with
1442 Gl.enable `texture_2d
;
1443 GlTex.bind_texture `texture_2d id
;
1446 and x1 = float (x+w)
1447 and y1 = float (y+h
) in
1449 let tw = float w /. 16.0
1450 and th
= float h
/. 16.0 in
1451 let tx0 = float tilex /. 16.0
1452 and ty0
= float tiley /. 16.0 in
1454 and ty1
= ty0
+. th
in
1455 GlDraw.begins `quads
;
1456 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1457 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1458 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1459 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1462 Gl.disable `texture_2d
;
1464 GlDraw.color
(1.0, 1.0, 1.0);
1467 (float (x+w), float (y+h
));
1469 if w > 128 && h
> fstate.fontsize
+ 10
1471 GlDraw.color
(0.0, 0.0, 0.0);
1474 then (col*conf.tilew
, row*conf.tileh
)
1477 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1484 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1486 let tilevisible1 l
x y =
1488 and ax1
= l
.pagex
+ l
.pagevw
1490 and ay1
= l
.pagey + l
.pagevh in
1494 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1495 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1497 let rx0 = max
ax0 bx0
1498 and ry0
= max ay0 by0
1499 and rx1
= min ax1
bx1
1500 and ry1
= min ay1 by1
in
1502 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1503 nonemptyintersection
1506 let tilevisible layout n x y =
1507 let rec findpageinlayout m
= function
1508 | l
:: rest
when l
.pageno = n ->
1509 tilevisible1 l
x y || (
1510 match conf.columns
with
1511 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1514 | _ :: rest
-> findpageinlayout 0 rest
1517 findpageinlayout 0 layout;
1520 let tileready l
x y =
1521 tilevisible1 l
x y &&
1522 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1525 let tilepage n p
layout =
1526 let rec loop = function
1530 let f col row _ _ _ _ _ _ =
1531 if state.currently
= Idle
1533 match gettileopaque l
col row with
1536 let x = col*conf.tilew
1537 and y = row*conf.tileh
in
1539 let w = l
.pagew
- x in
1543 let h = l
.pageh
- y in
1548 then getpbo
w h conf.colorspace
1551 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1554 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1555 conf.tilew
, conf.tileh
1564 if nogeomcmds state.geomcmds
1568 let preloadlayout y =
1569 let y = if y < state.winh
then 0 else y - state.winh
in
1570 let h = state.winh
*3 in
1575 let rec loop pages
=
1576 if state.currently
!= Idle
1581 begin match getopaque l
.pageno with
1583 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1584 state.currently
<- Loading
(l
, state.gen
);
1586 tilepage l
.pageno opaque pages
;
1591 if nogeomcmds state.geomcmds
1597 if conf.preload && state.currently
= Idle
1598 then load (preloadlayout state.y);
1601 let layoutready layout =
1602 let rec fold all ls
=
1603 all
&& match ls
with
1605 let seen = ref false in
1606 let allvisible = ref true in
1607 let foo col row _ _ _ _ _ _ =
1609 allvisible := !allvisible &&
1610 begin match gettileopaque l
col row with
1616 fold (!seen && !allvisible) rest
1619 let alltilesvisible = fold true layout in
1624 let y = bound y 0 state.maxy
in
1625 let y, layout, proceed
=
1626 match conf.maxwait
with
1627 | Some time
when state.ghyll
== noghyll ->
1628 begin match state.throttle
with
1630 let layout = layout y state.winh
in
1631 let ready = layoutready layout in
1635 state.throttle
<- Some
(layout, y, now ());
1637 else G.postRedisplay "gotoy showall (None)";
1639 | Some
(_, _, started
) ->
1640 let dt = now () -. started
in
1643 state.throttle
<- None
;
1644 let layout = layout y state.winh
in
1646 G.postRedisplay "maxwait";
1653 let layout = layout y state.winh
in
1654 if not
!wtmode || layoutready layout
1655 then G.postRedisplay "gotoy ready";
1661 state.layout <- layout;
1662 begin match state.mode
with
1663 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1664 let rec loop = function
1666 state.mode
<- LinkNav
(Ltgendir
0)
1667 | l
:: _ when l
.pageno = pageno ->
1668 begin match getopaque pageno with
1670 state.mode
<- LinkNav
(Ltgendir
0)
1672 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1673 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1674 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1675 then state.mode
<- LinkNav
(Ltgendir
0)
1677 | _ :: rest
-> loop rest
1682 begin match state.mode
with
1683 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1684 if not
(pagevisible layout pageno)
1686 match state.layout with
1689 state.mode
<- Birdseye
(
1690 conf, leftx
, l
.pageno, hooverpageno
, anchor
1693 | LinkNav
(Ltgendir dir
as lt
) ->
1695 let rec loop = function
1698 match getopaque l
.pageno with
1704 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1706 if dir
> 0 then LDfirst
else LDlast
1712 | Lnotfound
-> loop rest
1714 showlinktype (getlink opaque
n);
1715 Ltexact
(l
.pageno, n)
1719 state.mode
<- LinkNav
linknav
1724 state.ghyll
<- noghyll;
1727 let mx, my
= state.mpos
in
1732 let conttiling pageno opaque
=
1733 tilepage pageno opaque
1734 (if conf.preload then preloadlayout state.y else state.layout)
1737 let gotoy_and_clear_text y =
1738 if not
conf.verbose
then state.text <- "";
1744 let coloff = l
.pagecol
* l
.pageh
in
1745 float (l
.pagey + coloff) /. float l
.pageh
1752 if conf.presentation
1753 then float l
.pagedispy /. float (calcips l
.pageh
)
1754 else float l
.pagedispy /. float conf.interpagespace
1756 (l
.pageno, top, dtop)
1760 match state.layout with
1761 | l
:: _ -> getanchor1 l
1763 let n = page_of_y state.y in
1767 let y, h = getpageyh n in
1768 let dy = y - state.y in
1770 if conf.presentation
1772 let ips = calcips h in
1773 float (dy + ips) /. float ips
1775 float dy /. float conf.interpagespace
1780 let getanchory (n, top, dtop) =
1781 let y, h = getpageyh n in
1782 if conf.presentation
1784 let ips = calcips h in
1785 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1787 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1790 let gotoanchor anchor
=
1791 gotoy (getanchory anchor
);
1795 cbput state.hists
.nav
(getanchor ());
1799 let anchor = cbgetc state.hists
.nav dir
in
1804 let scroll f n a
b =
1805 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1807 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1809 then s (float f /. float a
)
1812 then 1.0 -. s ((float (f-b) /. float (n-b)))
1819 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1820 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1822 let ins = float a
*. iv1
1823 and outs
= float (n-b) *. iv1 in
1825 ins +. outs
+. float ones
1827 let rec set (_N
, _A
, _B
) y sy
=
1828 let sum = summa
1.0 _N _A _B
in
1829 let dy = float (y - sy
) in
1833 then state.ghyll
<- noghyll
1836 let s = scroll n _N _A _B
in
1837 let y1 = y1 +. ((s *. dy) /. sum) in
1838 gotoy_and_clear_text (truncate
y1);
1839 state.ghyll
<- gf (n+1) y1;
1843 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1845 gf 0 (float state.y)
1848 match conf.ghyllscroll
with
1850 gotoy_and_clear_text y
1852 if state.ghyll
== noghyll
1853 then set nab
y state.y
1854 else state.ghyll
(Some
y)
1857 let gotopage n top =
1858 let y, h = getpageyh n in
1859 let y = y + (truncate
(top *. float h)) in
1863 let gotopage1 n top =
1864 let y = getpagey n in
1869 let invalidate s f =
1874 match state.geomcmds
with
1875 | ps
, [] when String.length ps
= 0 ->
1877 state.geomcmds
<- s, [];
1880 state.geomcmds
<- ps
, [s, f];
1882 | ps
, (s'
, _) :: rest
when s'
= s ->
1883 state.geomcmds
<- ps
, ((s, f) :: rest
);
1886 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1890 Hashtbl.iter
(fun _ opaque
->
1891 wcmd "freepage %s" opaque
;
1893 Hashtbl.clear
state.pagemap
;
1897 if not
(Queue.is_empty
state.tilelru
)
1899 Queue.iter
(fun (k
, p
, s) ->
1900 wcmd "freetile %s" p
;
1901 state.memused
<- state.memused
- s;
1902 Hashtbl.remove
state.tilemap k
;
1904 state.uioh#infochanged Memused
;
1905 Queue.clear
state.tilelru
;
1910 let opendoc path password
=
1912 state.password
<- password
;
1913 state.gen
<- state.gen
+ 1;
1914 state.docinfo
<- [];
1917 setaalevel
conf.aalevel
;
1918 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1919 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
1920 invalidate "reqlayout"
1922 wcmd "reqlayout %d %d %s\000"
1923 conf.angle
(btod conf.proportional
) state.nameddest
;
1928 state.anchor <- getanchor ();
1929 opendoc state.path
state.password
;
1933 let c = c *. conf.colorscale
in
1937 let scalecolor2 (r, g, b) =
1938 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
1941 let docolumns = function
1943 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1944 let rec loop pageno pdimno pdim
y ph pdims
=
1945 if pageno = state.pagecount
1948 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1950 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1951 pdimno+1, pdim
, rest
1955 let x = max
0 (((state.winw
- state.scrollw
- w) / 2) - xoff
) in
1957 (if conf.presentation
1958 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1959 else (if pageno = 0 then 0 else conf.interpagespace
)
1962 a.(pageno) <- (pdimno, x, y, pdim
);
1963 loop (pageno+1) pdimno pdim
(y + h) h pdims
1965 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1966 conf.columns
<- Csingle
a;
1968 | Cmulti
((columns
, coverA
, coverB
), _) ->
1969 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1970 let rec loop pageno pdimno pdim
x y rowh pdims
=
1971 let rec fixrow m
= if m
= pageno then () else
1972 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1975 let y = y + (rowh
- h) / 2 in
1976 a.(m
) <- (pdimno, x, y, pdim
);
1980 if pageno = state.pagecount
1981 then fixrow (((pageno - 1) / columns
) * columns
)
1983 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1985 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1986 pdimno+1, pdim
, rest
1991 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1993 let x = (state.winw
- state.scrollw
- w) / 2 in
1995 if conf.presentation
then calcips h else conf.interpagespace
in
1996 x, y + ips + rowh
, h
1999 if (pageno - coverA
) mod columns
= 0
2001 let x = max
0 (state.winw
- state.scrollw
- state.w) / 2 in
2003 if conf.presentation
2005 let ips = calcips h in
2006 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2008 y + (if pageno = 0 then 0 else conf.interpagespace
)
2012 else x, y, max rowh
h
2016 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2019 if pageno = columns
&& conf.presentation
2021 let ips = calcips rowh
in
2022 for i
= 0 to pred columns
2024 let (pdimno, x, y, pdim
) = a.(i
) in
2025 a.(i
) <- (pdimno, x, y+ips, pdim
)
2031 fixrow (pageno - columns
);
2036 a.(pageno) <- (pdimno, x, y, pdim
);
2037 let x = x + w + xoff
*2 + conf.interpagespace
in
2038 loop (pageno+1) pdimno pdim
x y rowh' pdims
2040 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2041 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2044 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2045 let rec loop pageno pdimno pdim
y pdims
=
2046 if pageno = state.pagecount
2049 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2051 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2052 pdimno+1, pdim
, rest
2057 let rec loop1 n x y =
2058 if n = c then y else (
2059 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2060 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2063 let y = loop1 0 0 y in
2064 loop (pageno+1) pdimno pdim
y pdims
2066 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2067 conf.columns
<- Csplit
(c, a);
2071 docolumns conf.columns
;
2072 state.maxy
<- calcheight ();
2074 if state.x = 0 && state.w <= state.winw
- state.scrollw
2078 if state.reprf
== noreprf
2080 match state.mode
with
2081 | Birdseye
(_, _, pageno, _, _) ->
2082 let y, h = getpageyh pageno in
2083 let top = (state.winh
- h) / 2 in
2084 gotoy (max
0 (y - top))
2085 | _ -> gotoanchor state.anchor
2089 state.reprf
<- noreprf;
2094 GlDraw.viewport
0 0 w h;
2095 let firsttime = state.geomcmds
== firstgeomcmds in
2096 if not
firsttime && nogeomcmds state.geomcmds
2097 then state.anchor <- getanchor ();
2100 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2103 setfontsize fstate.fontsize
;
2104 GlMat.mode `modelview
;
2105 GlMat.load_identity
();
2107 GlMat.mode `projection
;
2108 GlMat.load_identity
();
2109 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2110 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2111 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2116 else float state.x /. float state.w
2118 invalidate "geometry"
2122 then state.x <- truncate
(relx *. float w);
2124 match conf.columns
with
2126 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2127 | Csplit
(c, _) -> w * c
2129 wcmd "geometry %d %d" w h);
2133 let len = String.length
state.text in
2136 match state.mode
with
2139 let h, _, _ = state.uioh#scrollpw
in
2145 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2146 (x+.w, float (state.winh
- hscrollh))
2149 let w = float (state.winw
- state.scrollw
- 1) in
2150 if state.progress
>= 0.0 && state.progress
< 1.0
2152 GlDraw.color
(0.3, 0.3, 0.3);
2153 let w1 = w *. state.progress
in
2155 GlDraw.color
(0.0, 0.0, 0.0);
2159 GlDraw.color
(0.0, 0.0, 0.0);
2163 GlDraw.color
(1.0, 1.0, 1.0);
2164 drawstring fstate.fontsize
2165 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2168 match state.mode
with
2169 | Textentry
((prefix
, text, _, _, _, _), _) ->
2173 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2175 Printf.sprintf
"%s%s_" prefix
text
2184 if not
(istextentry state.mode
)
2186 let s1 = "(press 'e' to review error messasges)" in
2187 if String.length
s > 0 then s ^
" " ^
s1 else s1
2192 if String.length
s > 0
2197 let len = Queue.length
state.tilelru
in
2199 match state.throttle
with
2202 then preloadlayout state.y
2204 | Some
(layout, _, _) ->
2208 if state.memused
<= conf.memlimit
2213 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2214 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2215 let (_, pw, ph
, _) = getpagedim n in
2218 && colorspace
= conf.colorspace
2219 && angle
= conf.angle
2223 let x = col*conf.tilew
2224 and y = row*conf.tileh
in
2225 tilevisible (Lazy.force_val
layout) n x y
2227 then Queue.push lruitem
state.tilelru
2230 wcmd "freetile %s" p
;
2231 state.memused
<- state.memused
- s;
2232 state.uioh#infochanged Memused
;
2233 Hashtbl.remove
state.tilemap k
;
2241 let logcurrently = function
2242 | Idle
-> dolog
"Idle"
2243 | Loading
(l
, gen
) ->
2244 dolog
"Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2245 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2247 "Tiling %d[%d,%d] page=%s cs=%s angle"
2248 l
.pageno col row pageopaque
2249 (colorspace_to_string colorspace
)
2251 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2252 angle gen
conf.angle
state.gen
2254 conf.tilew
conf.tileh
2261 let r = Str.regexp
" " in
2262 fun s -> Str.bounded_split
r s 2;
2265 let onpagerect pageno f =
2267 match conf.columns
with
2268 | Cmulti
(_, b) -> b
2270 | Csplit
(_, b) -> b
2272 if pageno >= 0 && pageno < Array.length
b
2274 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2275 let r = getpdimrect
pdimno in
2276 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2279 let gotopagexy pageno x y =
2280 onpagerect pageno (fun w h ->
2282 let _,w1,_,leftx
= getpagedim pageno in
2283 let wh = state.winh
- state.hscrollh in
2284 let sw = float w1 /. w in
2286 let x = leftx
+ state.x + truncate
x in
2288 if x < 0 || x >= state.winw
- state.scrollw
2292 let py, h = getpageyh pageno in
2293 let y'
= py + truncate
(top *. float h) in
2294 let dy = y'
- state.y in
2296 if x != state.x || not
(dy > 0 && dy < wh)
2298 if conf.presentation
2300 if abs
(py - y'
) > wh
2307 if state.x != sx || state.y != sy
2312 let ww = state.winw
- state.scrollw
in
2317 let x = if -x + ww > w1 then -(w1-ww) else x
2318 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2320 if conf.presentation
2322 if abs
(py - y'
) > wh
2333 if x = 0 && state.w <= state.winw
- state.scrollw
2337 gotoy_and_clear_text y;
2339 else gotoy_and_clear_text state.y;
2344 (* dolog "%S" cmds; *)
2345 let cl = splitatspace cmds
in
2347 try Scanf.sscanf
s fmt
f
2349 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2354 state.uioh#infochanged Pdim
;
2357 | "clearrects" :: [] ->
2358 state.rects
<- state.rects1
;
2359 G.postRedisplay "clearrects";
2361 | "continue" :: args :: [] ->
2362 let n = scan args "%u" (fun n -> n) in
2363 state.pagecount
<- n;
2364 begin match state.currently
with
2366 state.currently
<- Idle
;
2367 state.outlines
<- Array.of_list
(List.rev l
)
2371 let cur, cmds
= state.geomcmds
in
2372 if String.length
cur = 0
2373 then failwith
"umpossible";
2375 begin match List.rev cmds
with
2377 state.geomcmds
<- "", [];
2381 state.geomcmds
<- s, List.rev rest
;
2383 if conf.maxwait
= None
&& not
!wtmode
2384 then G.postRedisplay "continue";
2386 | "title" :: args :: [] ->
2389 | "msg" :: args :: [] ->
2392 | "vmsg" :: args :: [] ->
2394 then showtext ' '
args
2396 | "emsg" :: args :: [] ->
2397 Buffer.add_string
state.errmsgs
args;
2398 state.newerrmsgs
<- true;
2399 G.postRedisplay "error message"
2401 | "progress" :: args :: [] ->
2402 let progress, text =
2405 f, String.sub
args pos
(String.length
args - pos
))
2408 state.progress <- progress;
2409 G.postRedisplay "progress"
2411 | "firstmatch" :: args :: [] ->
2412 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2413 scan args "%u %d %f %f %f %f %f %f %f %f"
2414 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2415 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2417 let y = (getpagey pageno) + truncate
y0 in
2420 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2422 | "match" :: args :: [] ->
2423 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2424 scan args "%u %d %f %f %f %f %f %f %f %f"
2425 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2426 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2429 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2431 | "page" :: args :: [] ->
2432 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2433 begin match state.currently
with
2434 | Loading
(l
, gen
) ->
2435 vlog "page %d took %f sec" l
.pageno t
;
2436 Hashtbl.replace
state.pagemap
(l
.pageno, gen
) pageopaque;
2437 begin match state.throttle
with
2439 let preloadedpages =
2441 then preloadlayout state.y
2446 Set.Make
(struct type t
= int let compare = (-) end) in
2448 List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
2449 IntSet.empty
preloadedpages
2452 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2453 if not
(IntSet.mem
pageno set)
2455 wcmd "freepage %s" opaque
;
2461 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2464 state.currently
<- Idle
;
2467 tilepage l
.pageno pageopaque state.layout;
2469 load preloadedpages;
2470 if pagevisible state.layout l
.pageno
2471 && layoutready state.layout
2472 then G.postRedisplay "page";
2475 | Some
(layout, _, _) ->
2476 state.currently
<- Idle
;
2477 tilepage l
.pageno pageopaque layout;
2482 dolog
"Inconsistent loading state";
2483 logcurrently state.currently
;
2487 | "tile" :: args :: [] ->
2488 let (x, y, opaque
, size
, t
) =
2489 scan args "%u %u %s %u %f"
2490 (fun x y p size t
-> (x, y, p
, size
, t
))
2492 begin match state.currently
with
2493 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2494 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
2497 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2499 wcmd "freetile %s" opaque
;
2500 state.currently
<- Idle
;
2504 puttileopaque l
col row gen cs angle opaque size t
;
2505 state.memused
<- state.memused
+ size
;
2506 state.uioh#infochanged Memused
;
2508 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
2509 opaque
, size
) state.tilelru
;
2512 match state.throttle
with
2513 | None
-> state.layout
2514 | Some
(layout, _, _) -> layout
2517 state.currently
<- Idle
;
2519 && conf.colorspace
= cs
2520 && conf.angle
= angle
2521 && tilevisible layout l
.pageno x y
2522 then conttiling l
.pageno pageopaque;
2524 begin match state.throttle
with
2526 preload state.layout;
2528 && conf.colorspace
= cs
2529 && conf.angle
= angle
2530 && tilevisible state.layout l
.pageno x y
2531 && (not
!wtmode || layoutready state.layout)
2532 then G.postRedisplay "tile nothrottle";
2534 | Some
(layout, y, _) ->
2535 let ready = layoutready layout in
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 () =
4027 let fn = page_of_y state.y in
4028 let ln = page_of_y (state.y + state.winh
- state.hscrollh) in
4029 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4033 else (100. *. (float state.y /. float maxy))
4037 Printf.sprintf
"page %d of %d [%.2f%%]"
4038 (fn+1) state.pagecount
percent
4041 "pages %d-%d of %d [%.2f%%]"
4042 (fn+1) (ln+1) state.pagecount
percent
4045 let setpresentationmode v
=
4046 let n = page_of_y state.y in
4047 state.anchor <- (n, 0.0, 1.0);
4048 conf.presentation
<- v
;
4049 if conf.presentation
4051 if not
conf.scrollbarinpm
4052 then state.scrollw
<- 0;
4054 else state.scrollw
<- conf.scrollbw
;
4059 let btos b = if b then "\xe2\x88\x9a" else "" in
4060 let showextended = ref false in
4061 let leave mode
= function
4062 | Confirm
-> state.mode
<- mode
4063 | Cancel
-> state.mode
<- mode
in
4066 val mutable m_first_time
= true
4067 val mutable m_l
= []
4068 val mutable m_a
= [||]
4069 val mutable m_prev_uioh
= nouioh
4070 val mutable m_prev_mode
= View
4072 inherit lvsourcebase
4074 method reset prev_mode prev_uioh
=
4075 m_a
<- Array.of_list
(List.rev m_l
);
4077 m_prev_mode
<- prev_mode
;
4078 m_prev_uioh
<- prev_uioh
;
4082 if n >= Array.length m_a
4086 | _, _, _, Action
_ -> m_active
<- n
4090 m_first_time
<- false;
4093 method int name get
set =
4095 (name
, `
int get
, 1, Action
(
4098 try set (int_of_string
s)
4100 state.text <- Printf.sprintf
"bad integer `%s': %s"
4104 let te = name ^
": ", "", None
, intentry, ondone, true in
4105 state.mode
<- Textentry
(te, leave m_prev_mode
);
4109 method int_with_suffix name get
set =
4111 (name
, `intws get
, 1, Action
(
4114 try set (int_of_string_with_suffix s)
4116 state.text <- Printf.sprintf
"bad integer `%s': %s"
4121 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4123 state.mode
<- Textentry
(te, leave m_prev_mode
);
4127 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4129 (name
, `
bool (btos, get
), offset
, Action
(
4136 method color name get
set =
4138 (name
, `color get
, 1, Action
(
4140 let invalid = (nan
, nan
, nan
) in
4143 try color_of_string s
4145 state.text <- Printf.sprintf
"bad color `%s': %s"
4152 let te = name ^
": ", "", None
, textentry, ondone, true in
4153 state.text <- color_to_string (get
());
4154 state.mode
<- Textentry
(te, leave m_prev_mode
);
4158 method string name get
set =
4160 (name
, `
string get
, 1, Action
(
4162 let ondone s = set s in
4163 let te = name ^
": ", "", None
, textentry, ondone, true in
4164 state.mode
<- Textentry
(te, leave m_prev_mode
);
4168 method colorspace name get
set =
4170 (name
, `
string get
, 1, Action
(
4173 let vals = [| "rgb"; "bgr"; "gray" |] in
4175 inherit lvsourcebase
4178 m_active
<- int_of_colorspace conf.colorspace
;
4181 method getitemcount
= Array.length
vals
4182 method getitem
n = (vals.(n), 0)
4183 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4184 ignore
(uioh
, first, pan
, qsearch);
4185 if not cancel
then set active;
4187 method hasaction
_ = true
4191 let modehash = findkeyhash conf "info" in
4192 coe (new listview ~
source ~trusted
:true ~
modehash)
4195 method caption
s offset
=
4196 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4198 method caption2
s f offset
=
4199 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4201 method getitemcount
= Array.length m_a
4204 let tostr = function
4205 | `
int f -> string_of_int
(f ())
4206 | `intws
f -> string_with_suffix_of_int (f ())
4208 | `color
f -> color_to_string (f ())
4209 | `
bool (btos, f) -> btos (f ())
4212 let name, t
, offset
, _ = m_a
.(n) in
4213 ((let s = tostr t
in
4214 if String.length
s > 0
4215 then Printf.sprintf
"%s\t%s" name s
4219 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4223 m_qsearch
<- qsearch;
4225 match m_a
.(active) with
4226 | _, _, _, Action
f -> f uioh
4238 method hasaction
n =
4240 | _, _, _, Action
_ -> true
4244 let rec fillsrc prevmode prevuioh
=
4245 let sep () = src#caption
"" 0 in
4246 let colorp name get
set =
4248 (fun () -> color_to_string (get
()))
4251 let c = color_of_string v in
4254 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4257 let oldmode = state.mode
in
4258 let birdseye = isbirdseye state.mode
in
4260 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4262 src#
bool "presentation mode"
4263 (fun () -> conf.presentation
)
4264 (fun v -> setpresentationmode v);
4266 src#
bool "ignore case in searches"
4267 (fun () -> conf.icase
)
4268 (fun v -> conf.icase
<- v);
4271 (fun () -> conf.preload)
4272 (fun v -> conf.preload <- v);
4274 src#
bool "highlight links"
4275 (fun () -> conf.hlinks
)
4276 (fun v -> conf.hlinks
<- v);
4278 src#
bool "under info"
4279 (fun () -> conf.underinfo
)
4280 (fun v -> conf.underinfo
<- v);
4282 src#
bool "persistent bookmarks"
4283 (fun () -> conf.savebmarks
)
4284 (fun v -> conf.savebmarks
<- v);
4286 src#
bool "proportional display"
4287 (fun () -> conf.proportional
)
4288 (fun v -> reqlayout conf.angle
v);
4290 src#
bool "trim margins"
4291 (fun () -> conf.trimmargins
)
4292 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4294 src#
bool "persistent location"
4295 (fun () -> conf.jumpback
)
4296 (fun v -> conf.jumpback
<- v);
4299 src#
int "inter-page space"
4300 (fun () -> conf.interpagespace
)
4302 conf.interpagespace
<- n;
4303 docolumns conf.columns
;
4305 match state.layout with
4310 state.maxy <- calcheight ();
4311 let y = getpagey pageno in
4316 (fun () -> conf.pagebias
)
4317 (fun v -> conf.pagebias
<- v);
4319 src#
int "scroll step"
4320 (fun () -> conf.scrollstep
)
4321 (fun n -> conf.scrollstep
<- n);
4323 src#
int "horizontal scroll step"
4324 (fun () -> conf.hscrollstep
)
4325 (fun v -> conf.hscrollstep
<- v);
4327 src#
int "auto scroll step"
4329 match state.autoscroll
with
4331 | _ -> conf.autoscrollstep
)
4333 if state.autoscroll
<> None
4334 then state.autoscroll
<- Some
n;
4335 conf.autoscrollstep
<- n);
4338 (fun () -> truncate
(conf.zoom *. 100.))
4339 (fun v -> setzoom ((float v) /. 100.));
4342 (fun () -> conf.angle
)
4343 (fun v -> reqlayout v conf.proportional
);
4345 src#
int "scroll bar width"
4346 (fun () -> state.scrollw
)
4350 reshape state.winw
state.winh
;
4353 src#
int "scroll handle height"
4354 (fun () -> conf.scrollh
)
4355 (fun v -> conf.scrollh
<- v;);
4357 src#
int "thumbnail width"
4358 (fun () -> conf.thumbw
)
4360 conf.thumbw
<- min
4096 v;
4363 leavebirdseye beye
false;
4368 let mode = state.mode in
4369 src#
string "columns"
4371 match conf.columns
with
4373 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4374 | Csplit
(count
, _) -> "-" ^ string_of_int count
4377 let n, a, b = multicolumns_of_string v in
4378 setcolumns mode n a b);
4381 src#caption
"Presentation mode" 0;
4382 src#
bool "scrollbar visible"
4383 (fun () -> conf.scrollbarinpm
)
4385 if v != conf.scrollbarinpm
4387 conf.scrollbarinpm
<- v;
4388 if conf.presentation
4390 state.scrollw
<- if v then conf.scrollbw
else 0;
4391 reshape state.winw
state.winh
;
4397 src#caption
"Pixmap cache" 0;
4398 src#int_with_suffix
"size (advisory)"
4399 (fun () -> conf.memlimit
)
4400 (fun v -> conf.memlimit
<- v);
4403 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4404 (string_with_suffix_of_int state.memused
)
4405 (Hashtbl.length
state.tilemap
)) 1;
4408 src#caption
"Layout" 0;
4409 src#caption2
"Dimension"
4411 Printf.sprintf
"%dx%d (virtual %dx%d)"
4412 state.winw
state.winh
4417 src#caption2
"Position" (fun () ->
4418 Printf.sprintf
"%dx%d" state.x state.y
4421 src#caption2
"Position" (fun () -> describe_location ()) 1
4425 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4426 "Save these parameters as global defaults at exit"
4427 (fun () -> conf.bedefault
)
4428 (fun v -> conf.bedefault
<- v)
4432 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4433 src#
bool ~offset
:0 ~
btos "Extended parameters"
4434 (fun () -> !showextended)
4435 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4439 (fun () -> conf.checkers
)
4440 (fun v -> conf.checkers
<- v; setcheckers v);
4441 src#
bool "update cursor"
4442 (fun () -> conf.updatecurs
)
4443 (fun v -> conf.updatecurs
<- v);
4445 (fun () -> conf.verbose
)
4446 (fun v -> conf.verbose
<- v);
4447 src#
bool "invert colors"
4448 (fun () -> conf.invert
)
4449 (fun v -> conf.invert
<- v);
4451 (fun () -> conf.maxhfit
)
4452 (fun v -> conf.maxhfit
<- v);
4453 src#
bool "redirect stderr"
4454 (fun () -> conf.redirectstderr)
4455 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4456 src#
string "uri launcher"
4457 (fun () -> conf.urilauncher
)
4458 (fun v -> conf.urilauncher
<- v);
4459 src#
string "path launcher"
4460 (fun () -> conf.pathlauncher
)
4461 (fun v -> conf.pathlauncher
<- v);
4462 src#
string "tile size"
4463 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4466 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4467 conf.tilew
<- max
64 w;
4468 conf.tileh
<- max
64 h;
4471 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4474 src#
int "texture count"
4475 (fun () -> conf.texcount
)
4478 then conf.texcount
<- v
4479 else showtext '
!'
" Failed to set texture count please retry later"
4481 src#
int "slice height"
4482 (fun () -> conf.sliceheight
)
4484 conf.sliceheight
<- v;
4485 wcmd "sliceh %d" conf.sliceheight
;
4487 src#
int "anti-aliasing level"
4488 (fun () -> conf.aalevel
)
4490 conf.aalevel
<- bound v 0 8;
4491 state.anchor <- getanchor ();
4492 opendoc state.path
state.password
;
4494 src#
string "page scroll scaling factor"
4495 (fun () -> string_of_float
conf.pgscale)
4498 let s = float_of_string
v in
4501 state.text <- Printf.sprintf
4502 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4505 src#
int "ui font size"
4506 (fun () -> fstate.fontsize
)
4507 (fun v -> setfontsize (bound v 5 100));
4508 src#
int "hint font size"
4509 (fun () -> conf.hfsize
)
4510 (fun v -> conf.hfsize
<- bound v 5 100);
4511 colorp "background color"
4512 (fun () -> conf.bgcolor
)
4513 (fun v -> conf.bgcolor
<- v);
4514 src#
bool "crop hack"
4515 (fun () -> conf.crophack
)
4516 (fun v -> conf.crophack
<- v);
4517 src#
string "trim fuzz"
4518 (fun () -> irect_to_string conf.trimfuzz
)
4521 conf.trimfuzz
<- irect_of_string v;
4523 then settrim true conf.trimfuzz
;
4525 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4527 src#
string "throttle"
4529 match conf.maxwait
with
4530 | None
-> "show place holder if page is not ready"
4533 then "wait for page to fully render"
4535 "wait " ^ string_of_float
time
4536 ^
" seconds before showing placeholder"
4540 let f = float_of_string
v in
4542 then conf.maxwait
<- None
4543 else conf.maxwait
<- Some
f
4545 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4547 src#
string "ghyll scroll"
4549 match conf.ghyllscroll
with
4551 | Some nab
-> ghyllscroll_to_string nab
4556 if String.length
v = 0
4558 else Some
(ghyllscroll_of_string v)
4560 conf.ghyllscroll
<- gs
4562 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4564 src#
string "selection command"
4565 (fun () -> conf.selcmd
)
4566 (fun v -> conf.selcmd
<- v);
4567 src#
string "synctex command"
4568 (fun () -> conf.stcmd
)
4569 (fun v -> conf.stcmd
<- v);
4570 src#colorspace
"color space"
4571 (fun () -> colorspace_to_string conf.colorspace
)
4573 conf.colorspace
<- colorspace_of_int v;
4580 (fun () -> conf.usepbo
)
4581 (fun v -> conf.usepbo
<- v);
4582 src#
bool "mouse wheel scrolls pages"
4583 (fun () -> conf.wheelbypage
)
4584 (fun v -> conf.wheelbypage
<- v);
4588 src#caption
"Document" 0;
4589 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4590 src#caption2
"Pages"
4591 (fun () -> string_of_int
state.pagecount
) 1;
4592 src#caption2
"Dimensions"
4593 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4597 src#caption
"Trimmed margins" 0;
4598 src#caption2
"Dimensions"
4599 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4603 src#caption
"OpenGL" 0;
4604 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4605 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4606 src#reset prevmode prevuioh
;
4610 let prevmode = state.mode
4611 and prevuioh
= state.uioh in
4612 fillsrc prevmode prevuioh
;
4613 let source = (src :> lvsource
) in
4614 let modehash = findkeyhash conf "info" in
4615 state.uioh <- coe (object (self)
4616 inherit listview ~
source ~trusted
:true ~
modehash as super
4617 val mutable m_prevmemused
= 0
4618 method infochanged
= function
4620 if m_prevmemused
!= state.memused
4622 m_prevmemused
<- state.memused
;
4623 G.postRedisplay "memusedchanged";
4625 | Pdim
-> G.postRedisplay "pdimchanged"
4626 | Docinfo
-> fillsrc prevmode prevuioh
4628 method key key mask
=
4629 if not
(Wsi.withctrl mask
)
4632 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4633 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4634 | _ -> super#
key key mask
4635 else super#
key key mask
4637 G.postRedisplay "info";
4643 inherit lvsourcebase
4644 method getitemcount
= Array.length
state.help
4646 let s, l, _ = state.help
.(n) in
4649 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4653 m_qsearch
<- qsearch;
4654 match state.help
.(active) with
4655 | _, _, Action
f -> Some
(f uioh)
4665 method hasaction
n =
4666 match state.help
.(n) with
4667 | _, _, Action
_ -> true
4674 let modehash = findkeyhash conf "help" in
4675 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4676 G.postRedisplay "help";
4681 let re = Str.regexp
"[\r\n]" in
4683 inherit lvsourcebase
4684 val mutable m_items
= [||]
4686 method getitemcount
= 1 + Array.length m_items
4691 else m_items
.(n-1), 0
4693 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4698 then Buffer.clear
state.errmsgs
;
4699 m_qsearch
<- qsearch;
4706 method hasaction
n =
4710 state.newerrmsgs
<- false;
4711 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4712 m_items
<- Array.of_list
l
4720 let source = (msgsource :> lvsource
) in
4721 let modehash = findkeyhash conf "listview" in
4722 state.uioh <- coe (object
4723 inherit listview ~
source ~trusted
:false ~
modehash as super
4726 then msgsource#reset
;
4729 G.postRedisplay "msgs";
4732 let quickbookmark ?title
() =
4733 match state.layout with
4739 let sec = Unix.gettimeofday
() in
4740 let tm = Unix.localtime
sec in
4741 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4745 (tm.Unix.tm_year
+ 1900)
4748 | Some
title -> title
4750 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4757 let setautoscrollspeed step goingdown
=
4758 let incr = max
1 ((abs step
) / 2) in
4759 let incr = if goingdown
then incr else -incr in
4760 let astep = step
+ incr in
4761 state.autoscroll
<- Some
astep;
4764 let gotounder = function
4765 | Ulinkgoto
(pageno, top) ->
4769 gotopage1 pageno top;
4775 | Uremote
(filename
, pageno) ->
4777 if Sys.file_exists filename
4780 let dir = Filename.dirname
state.path in
4781 let path = Filename.concat
dir filename
in
4782 if Sys.file_exists
path
4786 if String.length
path > 0
4788 let anchor = getanchor () in
4789 let ranchor = state.path, state.password
, anchor in
4790 state.anchor <- (pageno, 0.0, 0.0);
4791 state.ranchors
<- ranchor :: state.ranchors
;
4794 else showtext '
!'
("Could not find " ^ filename
)
4796 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4800 match conf.columns
with
4802 | _ -> state.x != 0 || conf.zoom > 1.0
4805 let existsinrow pageno (columns
, coverA
, coverB
) p =
4806 let last = ((pageno - coverA
) mod columns
) + columns
in
4807 let rec any = function
4810 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4814 then (if l.pageno = last then false else any rest
)
4822 match state.layout with
4824 let pageno = page_of_y state.y in
4825 gotoghyll (getpagey (pageno+1))
4827 match conf.columns
with
4829 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4831 let y = clamp (pgscale state.winh
) in
4834 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4835 gotoghyll (getpagey pageno)
4836 | Cmulti
((c, _, _) as cl, _) ->
4837 if conf.presentation
4838 && (existsinrow l.pageno cl
4839 (fun l -> l.pageh
> l.pagey + l.pagevh))
4841 let y = clamp (pgscale state.winh
) in
4844 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4845 gotoghyll (getpagey pageno)
4847 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4849 let pagey, pageh
= getpageyh l.pageno in
4850 let pagey = pagey + pageh
* l.pagecol
in
4851 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4852 gotoghyll (pagey + pageh
+ ips)
4856 match state.layout with
4858 let pageno = page_of_y state.y in
4859 gotoghyll (getpagey (pageno-1))
4861 match conf.columns
with
4863 if conf.presentation
&& l.pagey != 0
4865 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4867 let pageno = max
0 (l.pageno-1) in
4868 gotoghyll (getpagey pageno)
4869 | Cmulti
((c, _, coverB
) as cl, _) ->
4870 if conf.presentation
&&
4871 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4873 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4876 if l.pageno = state.pagecount
- coverB
4880 let pageno = max
0 (l.pageno-decr) in
4881 gotoghyll (getpagey pageno)
4889 let pageno = max
0 (l.pageno-1) in
4890 let pagey, pageh
= getpageyh pageno in
4893 let pagey, pageh
= getpageyh l.pageno in
4894 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4899 let viewkeyboard key mask
=
4901 let mode = state.mode in
4902 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4905 G.postRedisplay "view:enttext"
4907 let ctrl = Wsi.withctrl mask
in
4909 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4915 | 0xff63 -> (* insert *)
4916 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4918 state.mode <- LinkNav
(Ltgendir
0);
4921 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4923 | 0xff1b | 113 -> (* escape / q *)
4924 begin match state.mstate
with
4926 state.mstate
<- Mnone
;
4927 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4928 G.postRedisplay "kill zoom rect";
4930 begin match state.mode with
4933 G.postRedisplay "esc leave linknav"
4935 match state.ranchors
with
4937 | (path, password
, anchor) :: rest
->
4938 state.ranchors
<- rest
;
4939 state.anchor <- anchor;
4940 opendoc path password
4944 | 0xff08 -> (* backspace *)
4945 gotoghyll (getnav ~
-1)
4953 G.postRedisplay "dehighlight";
4955 | 47 | 63 -> (* / ? *)
4956 let ondone isforw
s =
4957 cbput state.hists
.pat
s;
4958 state.searchpattern
<- s;
4961 let s = String.create
1 in
4962 s.[0] <- Char.chr
key;
4963 enttext (s, "", Some
(onhist state.hists
.pat
),
4964 textentry, ondone (key = 47), true)
4966 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4967 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4968 setzoom (conf.zoom +. incr)
4970 | 43 | 0xffab -> (* + *)
4973 try int_of_string
s with exc
->
4974 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4980 state.text <- "page bias is now " ^ string_of_int
n;
4983 enttext ("page bias: ", "", None
, intentry, ondone, true)
4985 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4986 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4987 setzoom (max
0.01 (conf.zoom -. decr))
4989 | 45 | 0xffad -> (* - *)
4990 let ondone msg
= state.text <- msg
in
4992 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4993 optentry state.mode, ondone, true
4996 | 48 when ctrl -> (* ctrl-0 *)
5001 if state.w <= state.winw
- state.scrollw
5009 | 49 when ctrl -> (* ctrl-1 *)
5011 match conf.columns
with
5012 | Csingle
_ | Cmulti
_ -> 1
5013 | Csplit
(n, _) -> n
5015 let h = state.winh
-
5016 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5018 let zoom = zoomforh
state.winw
h state.scrollw
cols in
5022 | 0xffc6 -> (* f9 *)
5025 | 57 when ctrl -> (* ctrl-9 *)
5028 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5029 when not
ctrl -> (* 0..9 *)
5032 try int_of_string
s with exc
->
5033 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5039 cbput state.hists
.pag
(string_of_int
n);
5040 gotopage1 (n + conf.pagebias
- 1) 0;
5043 let pageentry text key =
5044 match Char.unsafe_chr
key with
5045 | '
g'
-> TEdone
text
5046 | _ -> intentry text key
5048 let text = "x" in text.[0] <- Char.chr
key;
5049 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5052 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5053 reshape state.winw
state.winh
;
5056 conf.hlinks
<- not
conf.hlinks
;
5057 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5058 G.postRedisplay "toggle highlightlinks";
5061 state.glinks
<- true;
5062 let mode = state.mode in
5063 state.mode <- Textentry
(
5064 (":", "", None
, linknentry, linkndone gotounder, false),
5066 state.glinks
<- false;
5070 G.postRedisplay "view:linkent(F)"
5073 state.glinks
<- true;
5074 let mode = state.mode in
5075 state.mode <- Textentry
(
5076 (":", "", None
, linknentry, linkndone (fun under ->
5077 match Ne.pipe () with
5079 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
5082 try popen conf.selcmd
[r, 0; w, -1]; true
5085 (Printf.sprintf
"failed to execute %s: %s"
5086 conf.selcmd
(exntos exn
));
5090 Ne.clo fd
(fun msg
->
5091 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5094 let s = undertext under in
5098 let l = String.length
s in
5099 let n = tempfailureretry
(Unix.write
w s 0) l in
5104 "failed to write %d characters to sel pipe, wrote %d"
5109 (Printf.sprintf
"failed to write to sel pipe: %s"
5119 state.glinks
<- false;
5123 G.postRedisplay "view:linkent"
5126 begin match state.autoscroll
with
5128 conf.autoscrollstep
<- step
;
5129 state.autoscroll
<- None
5131 if conf.autoscrollstep
= 0
5132 then state.autoscroll
<- Some
1
5133 else state.autoscroll
<- Some
conf.autoscrollstep
5136 | 112 when ctrl -> (* ctrl-p *)
5140 setpresentationmode (not
conf.presentation
);
5141 showtext ' '
("presentation mode " ^
5142 if conf.presentation
then "on" else "off");
5145 if List.mem
Wsi.Fullscreen
state.winstate
5146 then doreshape conf.cwinw
conf.cwinh
5147 else Wsi.fullscreen
()
5149 | 112 | 78 -> (* p|N *)
5150 search state.searchpattern
false
5152 | 110 | 0xffc0 -> (* n|F3 *)
5153 search state.searchpattern
true
5156 begin match state.layout with
5159 gotoghyll (getpagey l.pageno)
5165 | 0xff9f | 0xffff -> (* delete *)
5169 showtext ' '
(describe_location ());
5172 begin match state.layout with
5175 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5180 enterbookmarkmode ()
5182 | 104 | 0xffbe -> (* h|F1 *)
5188 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5193 match state.layout with
5195 if String.length
s > 0
5197 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5200 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5204 showtext ' '
"Quick bookmark added";
5207 begin match state.layout with
5209 let rect = getpdimrect
l.pagedimno
in
5213 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5214 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5216 (truncate
(rect.(1) -. rect.(0)),
5217 truncate
(rect.(3) -. rect.(0)))
5219 let w = truncate
((float w)*.conf.zoom)
5220 and h = truncate
((float h)*.conf.zoom) in
5223 state.anchor <- getanchor ();
5224 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5226 G.postRedisplay "z";
5231 | 60 | 62 -> (* < > *)
5232 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5234 | 91 | 93 -> (* [ ] *)
5236 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5238 G.postRedisplay "brightness";
5240 | 99 when state.mode = View
-> (* c *)
5242 match state.prevcolumns
with
5243 | None
-> (1, 0, 0), 1.0
5244 | Some
(columns
, z
) ->
5247 | Csplit
(c, _) -> -c, 0, 0
5248 | Cmulti
((c, a, b), _) -> c, a, b
5249 | Csingle
_ -> 1, 0, 0
5253 setcolumns View
c a b;
5256 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5257 setzoom state.prevzoom
5259 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5260 begin match state.autoscroll
with
5262 begin match state.mode with
5263 | Birdseye beye
-> upbirdseye 1 beye
5266 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5267 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5270 setautoscrollspeed n false
5273 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5274 begin match state.autoscroll
with
5276 begin match state.mode with
5277 | Birdseye beye
-> downbirdseye 1 beye
5280 then gotoy_and_clear_text (clamp (state.winh
/2))
5281 else gotoy_and_clear_text (clamp conf.scrollstep
)
5284 setautoscrollspeed n true
5287 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5288 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5294 else conf.hscrollstep
5296 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5297 state.x <- state.x + dx;
5298 gotoy_and_clear_text state.y
5301 G.postRedisplay "lef/right"
5304 | 0xff55 | 0xff9a -> (* (kp) prior *)
5308 match state.layout with
5310 | l :: _ -> state.y - l.pagey
5312 clamp (pgscale (-state.winh
))
5316 | 0xff56 | 0xff9b -> (* (kp) next *)
5320 match List.rev
state.layout with
5322 | l :: _ -> getpagey l.pageno
5324 clamp (pgscale state.winh
)
5328 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5330 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5331 gotoghyll (clamp state.maxy)
5334 when Wsi.withalt mask
-> (* alt-(kp) right *)
5335 gotoghyll (getnav 1)
5337 when Wsi.withalt mask
-> (* alt-(kp) left *)
5338 gotoghyll (getnav ~
-1)
5343 | 118 when conf.debug
-> (* v *)
5346 match getopaque l.pageno with
5349 let x0, y0, x1, y1 = pagebbox opaque
in
5350 let a,b = float x0, float y0 in
5351 let c,d = float x1, float y0 in
5352 let e,f = float x1, float y1 in
5353 let h,j
= float x0, float y1 in
5354 let rect = (a,b,c,d,e,f,h,j
) in
5356 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5358 G.postRedisplay "v";
5361 vlog "huh? %s" (Wsi.keyname
key)
5364 let linknavkeyboard key mask
linknav =
5365 let getpage pageno =
5366 let rec loop = function
5368 | l :: _ when l.pageno = pageno -> Some
l
5369 | _ :: rest
-> loop rest
5370 in loop state.layout
5372 let doexact (pageno, n) =
5373 match getopaque pageno, getpage pageno with
5374 | Some opaque
, Some
l ->
5375 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5377 let under = getlink opaque
n in
5378 G.postRedisplay "link gotounder";
5384 | 0xff50 -> (* home *)
5385 Some
(findlink opaque LDfirst
), -1
5387 | 0xff57 -> (* end *)
5388 Some
(findlink opaque LDlast
), 1
5390 | 0xff51 -> (* left *)
5391 Some
(findlink opaque
(LDleft
n)), -1
5393 | 0xff53 -> (* right *)
5394 Some
(findlink opaque
(LDright
n)), 1
5396 | 0xff52 -> (* up *)
5397 Some
(findlink opaque
(LDup
n)), -1
5399 | 0xff54 -> (* down *)
5400 Some
(findlink opaque
(LDdown
n)), 1
5405 begin match findpwl
l.pageno dir with
5409 state.mode <- LinkNav
(Ltgendir
dir);
5410 let y, h = getpageyh pageno in
5413 then y + h - state.winh
5418 begin match getopaque pageno, getpage pageno with
5419 | Some opaque
, Some
_ ->
5421 let ld = if dir > 0 then LDfirst
else LDlast
in
5424 begin match link with
5426 showlinktype (getlink opaque
m);
5427 state.mode <- LinkNav
(Ltexact
(pageno, m));
5428 G.postRedisplay "linknav jpage";
5435 begin match opt with
5436 | Some Lnotfound
-> pwl l dir;
5437 | Some
(Lfound
m) ->
5441 let _, y0, _, y1 = getlinkrect opaque
m in
5443 then gotopage1 l.pageno y0
5445 let d = fstate.fontsize
+ 1 in
5446 if y1 - l.pagey > l.pagevh - d
5447 then gotopage1 l.pageno (y1 - state.winh
- state.hscrollh + d)
5448 else G.postRedisplay "linknav";
5450 showlinktype (getlink opaque
m);
5451 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5454 | None
-> viewkeyboard key mask
5456 | _ -> viewkeyboard key mask
5461 G.postRedisplay "leave linknav"
5465 | Ltgendir
_ -> viewkeyboard key mask
5466 | Ltexact exact
-> doexact exact
5469 let keyboard key mask
=
5470 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5471 then wcmd "interrupt"
5472 else state.uioh <- state.uioh#
key key mask
5475 let birdseyekeyboard key mask
5476 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5478 match conf.columns
with
5480 | Cmulti
((c, _, _), _) -> c
5481 | Csplit
_ -> failwith
"bird's eye split mode"
5483 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5485 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5486 let y, h = getpageyh pageno in
5487 let top = (state.winh
- h) / 2 in
5488 gotoy (max
0 (y - top))
5489 | 0xff0d (* enter *)
5490 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5491 | 0xff1b -> leavebirdseye beye
true (* escape *)
5492 | 0xff52 -> upbirdseye incr beye
(* up *)
5493 | 0xff54 -> downbirdseye incr beye
(* down *)
5494 | 0xff51 -> upbirdseye 1 beye
(* left *)
5495 | 0xff53 -> downbirdseye 1 beye
(* right *)
5497 | 0xff55 -> (* prior *)
5498 begin match state.layout with
5502 state.mode <- Birdseye
(
5503 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5505 gotopage1 l.pageno 0;
5508 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5510 | [] -> gotoy (clamp (-state.winh
))
5512 state.mode <- Birdseye
(
5513 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5515 gotopage1 l.pageno 0
5518 | [] -> gotoy (clamp (-state.winh
))
5521 | 0xff56 -> (* next *)
5522 begin match List.rev
state.layout with
5524 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5525 begin match layout with
5527 let incr = l.pageh
- l.pagevh in
5532 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5534 G.postRedisplay "birdseye pagedown";
5536 else gotoy (clamp (incr + conf.interpagespace
*2));
5540 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5541 gotopage1 l.pageno 0;
5544 | [] -> gotoy (clamp state.winh
)
5547 | 0xff50 -> (* home *)
5548 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5551 | 0xff57 -> (* end *)
5552 let pageno = state.pagecount
- 1 in
5553 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5554 if not
(pagevisible state.layout pageno)
5557 match List.rev
state.pdims
with
5559 | (_, _, h, _) :: _ -> h
5561 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5562 else G.postRedisplay "birdseye end";
5563 | _ -> viewkeyboard key mask
5566 let drawpage l linkindexbase
=
5568 match state.mode with
5569 | Textentry
_ -> scalecolor 0.4
5571 | View
-> scalecolor 1.0
5572 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5573 if l.pageno = hooverpageno
5576 if l.pageno = pageno
5582 begin match getopaque l.pageno with
5584 if tileready l l.pagex
l.pagey
5586 let x = l.pagedispx - l.pagex
5587 and y = l.pagedispy - l.pagey in
5589 match conf.columns
with
5590 | Csingle
_ | Cmulti
_ ->
5591 (if conf.hlinks
then 1 else 0)
5593 && not
(isbirdseye state.mode) then 2 else 0)
5597 match state.mode with
5598 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5601 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5608 let scrollindicator () =
5609 let sbw, ph
, sh = state.uioh#
scrollph in
5610 let sbh, pw, sw = state.uioh#scrollpw
in
5612 GlDraw.color (0.64, 0.64, 0.64);
5614 (float (state.winw
- sbw), 0.)
5615 (float state.winw
, float state.winh
)
5618 (0., float (state.winh
- sbh))
5619 (float (state.winw
- state.scrollw
- 1), float state.winh
)
5621 GlDraw.color (0.0, 0.0, 0.0);
5624 (float (state.winw
- sbw), ph
)
5625 (float state.winw
, ph
+. sh)
5628 (pw, float (state.winh
- sbh))
5629 (pw +. sw, float state.winh
)
5634 match state.mstate
with
5635 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5638 | Msel
((x0, y0), (x1, y1)) ->
5639 let rec loop = function
5641 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5642 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5643 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5644 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5646 match getopaque l.pageno with
5648 let x0, y0 = pagetranslatepoint l x0 y0 in
5649 let x1, y1 = pagetranslatepoint l x1 y1 in
5650 seltext opaque
(x0, y0, x1, y1);
5658 let showrects rects
=
5660 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5661 GlDraw.polygon_mode `both `fill
;
5662 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5664 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5666 if l.pageno = pageno
5668 let dx = float (l.pagedispx - l.pagex
) in
5669 let dy = float (l.pagedispy - l.pagey) in
5670 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5671 GlDraw.begins `quads
;
5673 GlDraw.vertex2
(x0+.dx, y0+.dy);
5674 GlDraw.vertex2
(x1+.dx, y1+.dy);
5675 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5676 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5687 GlClear.color (scalecolor2 conf.bgcolor
);
5688 GlClear.clear
[`
color];
5689 let rec loop linkindexbase
= function
5691 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5692 loop linkindexbase rest
5695 loop 0 state.layout;
5697 match state.mode with
5698 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5699 begin match getopaque pageno with
5701 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5708 | None
-> state.rects
5715 begin match state.mstate
with
5716 | Mzoomrect
((x0, y0), (x1, y1)) ->
5718 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5719 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5720 GlDraw.rect (float x0, float y0)
5721 (float x1, float y1);
5730 let zoomrect x y x1 y1 =
5733 and y0 = min
y y1 in
5734 gotoy (state.y + y0);
5735 state.anchor <- getanchor ();
5736 let zoom = (float state.winw
*. conf.zoom) /. float (x1 - x0) in
5738 if state.w < state.winw
- state.scrollw
5739 then (state.winw
- state.scrollw
- state.w) / 2
5742 state.x <- (state.x + margin) - x0;
5744 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5745 state.mstate
<- Mnone
;
5749 let winw = state.winw - state.scrollw
- 1 in
5750 let s = float x /. float winw in
5751 let destx = truncate
(float (state.w + winw) *. s) in
5752 state.x <- winw - destx;
5753 gotoy_and_clear_text state.y;
5754 state.mstate
<- Mscrollx
;
5758 let s = float y /. float state.winh
in
5759 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5760 gotoy_and_clear_text desty;
5761 state.mstate
<- Mscrolly
;
5764 let viewmouse button down
x y mask
=
5766 | n when (n == 4 || n == 5) && not down
->
5767 if Wsi.withctrl mask
5769 match state.mstate
with
5770 | Mzoom
(oldn
, i
) ->
5778 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5780 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5782 let zoom = conf.zoom -. incr in
5784 state.mstate
<- Mzoom
(n, 0);
5786 state.mstate
<- Mzoom
(n, i
+1);
5788 else state.mstate
<- Mzoom
(n, 0)
5790 | _ -> state.mstate
<- Mzoom
(n, 0)
5793 match state.autoscroll
with
5794 | Some step
-> setautoscrollspeed step
(n=4)
5805 then -conf.scrollstep
5806 else conf.scrollstep
5808 let incr = incr * 2 in
5809 let y = clamp incr in
5810 gotoy_and_clear_text y
5813 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5814 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5815 gotoy_and_clear_text state.y
5817 | 1 when Wsi.withshift mask
->
5818 state.mstate
<- Mnone
;
5820 match unproject x y with
5821 | Some
(pageno, ux
, uy
) ->
5822 let cmd = Printf.sprintf
5824 conf.stcmd
state.path pageno ux uy
5830 | 1 when Wsi.withctrl mask
->
5833 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5834 state.mstate
<- Mpan
(x, y)
5837 state.mstate
<- Mnone
5842 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5844 state.mstate
<- Mzoomrect
(p, p)
5847 match state.mstate
with
5848 | Mzoomrect
((x0, y0), _) ->
5849 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5850 then zoomrect x0 y0 x y
5852 state.mstate
<- Mnone
;
5853 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5854 G.postRedisplay "kill accidental zoom rect";
5857 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5858 state.mstate
<- Mnone
5861 | 1 when x > state.winw - state.scrollw
->
5864 let _, position, sh = state.uioh#
scrollph in
5865 if y > truncate
position && y < truncate
(position +. sh)
5866 then state.mstate
<- Mscrolly
5869 state.mstate
<- Mnone
5871 | 1 when y > state.winh
- state.hscrollh ->
5874 let _, position, sw = state.uioh#scrollpw
in
5875 if x > truncate
position && x < truncate
(position +. sw)
5876 then state.mstate
<- Mscrollx
5879 state.mstate
<- Mnone
5882 let dest = if down
then getunder x y else Unone
in
5883 begin match dest with
5887 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5890 | Unone
when down
->
5891 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5892 state.mstate
<- Mpan
(x, y);
5894 | Unone
| Utext
_ ->
5897 if conf.angle
mod 360 = 0
5899 state.mstate
<- Msel
((x, y), (x, y));
5900 G.postRedisplay "mouse select";
5904 match state.mstate
with
5907 | Mzoom
_ | Mscrollx
| Mscrolly
->
5908 state.mstate
<- Mnone
5910 | Mzoomrect
((x0, y0), _) ->
5914 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5915 state.mstate
<- Mnone
5917 | Msel
((x0, y0), (x1, y1)) ->
5918 let rec loop = function
5922 let a0 = l.pagedispy in
5923 let a1 = a0 + l.pagevh in
5924 let b0 = l.pagedispx in
5925 let b1 = b0 + l.pagevw in
5926 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5927 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5931 match getopaque l.pageno with
5934 match Ne.pipe () with
5938 "can not create sel pipe: %s"
5941 let doclose what fd
=
5942 Ne.clo fd
(fun msg
->
5943 dolog
"%s close failed: %s" what msg
)
5946 popen conf.selcmd
[r, 0; w, -1];
5949 G.postRedisplay "copysel";
5951 dolog
"can not execute %S: %s"
5952 conf.selcmd
(exntos exn
);
5960 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5961 state.mstate
<- Mnone
;
5968 let birdseyemouse button down
x y mask
5969 (conf, leftx
, _, hooverpageno
, anchor) =
5972 let rec loop = function
5975 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5976 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5978 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5984 | _ -> viewmouse button down
x y mask
5987 let mouse button down
x y mask
=
5988 state.uioh <- state.uioh#button button down
x y mask
;
5992 state.uioh <- state.uioh#
motion x y
5996 state.uioh <- state.uioh#
pmotion x y;
6002 method key key mask
=
6003 begin match state.mode with
6004 | Textentry
textentry -> textentrykeyboard key mask
textentry
6005 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6006 | View
-> viewkeyboard key mask
6007 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6011 method button button bstate
x y mask
=
6012 begin match state.mode with
6014 | View
-> viewmouse button bstate
x y mask
6015 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6021 begin match state.mode with
6023 | View
| Birdseye
_ | LinkNav
_ ->
6024 match state.mstate
with
6025 | Mzoom
_ | Mnone
-> ()
6030 state.mstate
<- Mpan
(x, y);
6032 then state.x <- state.x + dx;
6034 gotoy_and_clear_text y
6037 state.mstate
<- Msel
(a, (x, y));
6038 G.postRedisplay "motion select";
6041 let y = min
state.winh
(max
0 y) in
6045 let x = min
state.winw (max
0 x) in
6048 | Mzoomrect
(p0
, _) ->
6049 state.mstate
<- Mzoomrect
(p0
, (x, y));
6050 G.postRedisplay "motion zoomrect";
6054 method pmotion x y =
6055 begin match state.mode with
6056 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6057 let rec loop = function
6059 if hooverpageno
!= -1
6061 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6062 G.postRedisplay "pmotion birdseye no hoover";
6065 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6066 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6068 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6069 G.postRedisplay "pmotion birdseye hoover";
6079 match state.mstate
with
6080 | Mnone
-> updateunder x y
6081 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6086 method infochanged
_ = ()
6089 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6090 let p, h = scrollph state.y maxy in
6094 let winw = state.winw - state.scrollw
- 1 in
6095 let fwinw = float winw in
6097 let sw = fwinw /. float state.w in
6098 let sw = fwinw *. sw in
6099 max
sw (float conf.scrollh
)
6102 let f = state.w+winw in
6103 let r = float (winw-state.x) /. float f in
6104 let p = fwinw *. r in
6108 if position +. sw > fwinw
6109 then fwinw -. position
6112 state.hscrollh, position, sw
6116 match state.mode with
6117 | LinkNav
_ -> "links"
6118 | Textentry
_ -> "textentry"
6119 | Birdseye
_ -> "birdseye"
6122 findkeyhash conf modename
6129 let fontpath = ref "";;
6132 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6135 let l = String.length
s in
6136 let b = Buffer.create
l in
6142 try Sys.getenv
"HOME"
6145 ("Can not determine home directory location: " ^ exntos exn
);
6149 let modifier_of_string = function
6150 | "alt" -> Wsi.altmask
6151 | "shift" -> Wsi.shiftmask
6152 | "ctrl" | "control" -> Wsi.ctrlmask
6153 | "meta" -> Wsi.metamask
6158 let r = Str.regexp
"-" in
6160 let elems = Str.full_split
r s in
6163 let m1 = modifier_of_string s in
6165 then (Wsi.namekey
s, m)
6168 | Str.Delim
s when n land 1 = 0 -> g s
6170 | Str.Delim
_ -> (k
, m)
6172 let rec loop n k
m = function
6175 let k, m = f n k m x in
6181 let keys_of_string =
6182 let r = Str.regexp
"[ \t]" in
6184 let elems = Str.split
r s in
6185 List.map
key_of_string elems
6188 let copykeyhashes c =
6189 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6192 let config_of c attrs
=
6196 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6197 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6198 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6199 | "preload" -> { c with preload = bool_of_string
v }
6200 | "page-bias" -> { c with pagebias
= int_of_string
v }
6201 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6202 | "horizontal-scroll-step" ->
6203 { c with hscrollstep
= max
(int_of_string
v) 1 }
6204 | "auto-scroll-step" ->
6205 { c with autoscrollstep
= max
0 (int_of_string
v) }
6206 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6207 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6210 match String.lowercase
v with
6211 | "true" -> Some infinity
6213 | f -> Some
(float_of_string
f)
6215 { c with maxwait
= mw}
6216 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6217 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6218 | "vertical-margin" ->
6219 { c with interpagespace
= max
0 (int_of_string
v) }
6221 let zoom = float_of_string
v /. 100. in
6222 let zoom = max
zoom 0.0 in
6223 { c with zoom = zoom }
6224 | "presentation" -> { c with presentation
= bool_of_string
v }
6225 | "rotation-angle" -> { c with angle
= int_of_string
v }
6226 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6227 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6228 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6229 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6230 | "pixmap-cache-size" ->
6231 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6232 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6233 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6234 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6235 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6236 | "background-color" -> { c with bgcolor
= color_of_string v }
6237 | "scrollbar-in-presentation" ->
6238 { c with scrollbarinpm
= bool_of_string
v }
6239 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6240 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6241 | "mupdf-store-size" ->
6242 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6243 | "checkers" -> { c with checkers
= bool_of_string
v }
6244 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6245 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6246 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6247 | "uri-launcher" -> { c with urilauncher
= unent v }
6248 | "path-launcher" -> { c with pathlauncher
= unent v }
6249 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6250 | "invert-colors" -> { c with invert
= bool_of_string
v }
6251 | "brightness" -> { c with colorscale
= float_of_string
v }
6252 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6254 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6256 let (n, _, _) as nab
= multicolumns_of_string v in
6258 then { c with columns
= Csplit
(-n, [||]) }
6259 else { c with columns
= Cmulti
(nab
, [||]) }
6260 | "birds-eye-columns" ->
6261 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6262 | "selection-command" -> { c with selcmd
= unent v }
6263 | "synctex-command" -> { c with stcmd
= unent v }
6264 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6265 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6266 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6267 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6268 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6271 prerr_endline
("Error processing attribute (`" ^
6272 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6275 let rec fold c = function
6278 let c = apply c k v in
6281 fold { c with keyhashes
= copykeyhashes c } attrs
;
6284 let fromstring f pos
n v d =
6287 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6288 n v pos
(exntos exn
)
6293 let bookmark_of attrs
=
6294 let rec fold title page
rely visy
= function
6295 | ("title", v) :: rest
-> fold v page
rely visy rest
6296 | ("page", v) :: rest
-> fold title v rely visy rest
6297 | ("rely", v) :: rest
-> fold title page
v visy rest
6298 | ("visy", v) :: rest
-> fold title page
rely v rest
6299 | _ :: rest
-> fold title page
rely visy rest
6300 | [] -> title, page
, rely, visy
6302 fold "invalid" "0" "0" "0" attrs
6306 let rec fold path page
rely pan visy
= function
6307 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6308 | ("page", v) :: rest
-> fold path v rely pan visy rest
6309 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6310 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6311 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6312 | _ :: rest
-> fold path page
rely pan visy rest
6313 | [] -> path, page
, rely, pan
, visy
6315 fold "" "0" "0" "0" "0" attrs
6319 let rec fold rs ls
= function
6320 | ("out", v) :: rest
-> fold v ls rest
6321 | ("in", v) :: rest
-> fold rs
v rest
6322 | _ :: rest
-> fold ls rs rest
6328 let setconf dst
src =
6329 dst
.scrollbw
<- src.scrollbw
;
6330 dst
.scrollh
<- src.scrollh
;
6331 dst
.icase
<- src.icase
;
6332 dst
.preload <- src.preload;
6333 dst
.pagebias
<- src.pagebias
;
6334 dst
.verbose
<- src.verbose
;
6335 dst
.scrollstep
<- src.scrollstep
;
6336 dst
.maxhfit
<- src.maxhfit
;
6337 dst
.crophack
<- src.crophack
;
6338 dst
.autoscrollstep
<- src.autoscrollstep
;
6339 dst
.maxwait
<- src.maxwait
;
6340 dst
.hlinks
<- src.hlinks
;
6341 dst
.underinfo
<- src.underinfo
;
6342 dst
.interpagespace
<- src.interpagespace
;
6343 dst
.zoom <- src.zoom;
6344 dst
.presentation
<- src.presentation
;
6345 dst
.angle
<- src.angle
;
6346 dst
.cwinw
<- src.cwinw
;
6347 dst
.cwinh
<- src.cwinh
;
6348 dst
.savebmarks
<- src.savebmarks
;
6349 dst
.memlimit
<- src.memlimit
;
6350 dst
.proportional
<- src.proportional
;
6351 dst
.texcount
<- src.texcount
;
6352 dst
.sliceheight
<- src.sliceheight
;
6353 dst
.thumbw
<- src.thumbw
;
6354 dst
.jumpback
<- src.jumpback
;
6355 dst
.bgcolor
<- src.bgcolor
;
6356 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6357 dst
.tilew
<- src.tilew
;
6358 dst
.tileh
<- src.tileh
;
6359 dst
.mustoresize
<- src.mustoresize
;
6360 dst
.checkers
<- src.checkers
;
6361 dst
.aalevel
<- src.aalevel
;
6362 dst
.trimmargins
<- src.trimmargins
;
6363 dst
.trimfuzz
<- src.trimfuzz
;
6364 dst
.urilauncher
<- src.urilauncher
;
6365 dst
.colorspace
<- src.colorspace
;
6366 dst
.invert
<- src.invert
;
6367 dst
.colorscale
<- src.colorscale
;
6368 dst
.redirectstderr <- src.redirectstderr;
6369 dst
.ghyllscroll
<- src.ghyllscroll
;
6370 dst
.columns
<- src.columns
;
6371 dst
.beyecolumns
<- src.beyecolumns
;
6372 dst
.selcmd
<- src.selcmd
;
6373 dst
.updatecurs
<- src.updatecurs
;
6374 dst
.pathlauncher
<- src.pathlauncher
;
6375 dst
.keyhashes
<- copykeyhashes src;
6376 dst
.hfsize
<- src.hfsize
;
6377 dst
.hscrollstep
<- src.hscrollstep
;
6378 dst
.pgscale <- src.pgscale;
6379 dst
.usepbo
<- src.usepbo
;
6380 dst
.wheelbypage
<- src.wheelbypage
;
6381 dst
.stcmd
<- src.stcmd
;
6385 let h = Hashtbl.create
10 in
6386 let dc = { defconf with angle
= defconf.angle
} in
6387 let rec toplevel v t spos
_ =
6389 | Vdata
| Vcdata
| Vend
-> v
6390 | Vopen
("llppconfig", _, closed
) ->
6393 else { v with f = llppconfig
}
6395 error
"unexpected subelement at top level" s spos
6396 | Vclose
_ -> error
"unexpected close at top level" s spos
6398 and llppconfig
v t spos
_ =
6400 | Vdata
| Vcdata
-> v
6401 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6402 | Vopen
("defaults", attrs
, closed
) ->
6403 let c = config_of dc attrs
in
6407 else { v with f = defaults
}
6409 | Vopen
("ui-font", attrs
, closed
) ->
6410 let rec getsize size
= function
6412 | ("size", v) :: rest
->
6414 fromstring int_of_string spos
"size" v fstate.fontsize
in
6416 | l -> getsize size l
6418 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6421 else { v with f = uifont
(Buffer.create
10) }
6423 | Vopen
("doc", attrs
, closed
) ->
6424 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6425 let path = unent pathent
6426 and pageno = fromstring int_of_string spos
"page" spage
0
6427 and rely = fromstring float_of_string spos
"rely" srely
0.0
6428 and pan
= fromstring int_of_string spos
"pan" span
0
6429 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6430 let c = config_of dc attrs
in
6431 let anchor = (pageno, rely, visy
) in
6433 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6434 else { v with f = doc
path pan
anchor c [] }
6437 error
"unexpected subelement in llppconfig" s spos
6439 | Vclose
"llppconfig" -> { v with f = toplevel }
6440 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6442 and defaults
v t spos
_ =
6444 | Vdata
| Vcdata
-> v
6445 | Vend
-> error
"unexpected end of input in defaults" s spos
6446 | Vopen
("keymap", attrs
, closed
) ->
6448 try List.assoc
"mode" attrs
6449 with Not_found
-> "global" in
6454 let h = findkeyhash dc modename in
6455 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6458 { v with f = pkeymap
ret KeyMap.empty }
6460 | Vopen
(_, _, _) ->
6461 error
"unexpected subelement in defaults" s spos
6463 | Vclose
"defaults" ->
6464 { v with f = llppconfig
}
6466 | Vclose
_ -> error
"unexpected close in defaults" s spos
6468 and uifont
b v t spos
epos =
6471 Buffer.add_substring
b s spos
(epos - spos
);
6473 | Vopen
(_, _, _) ->
6474 error
"unexpected subelement in ui-font" s spos
6475 | Vclose
"ui-font" ->
6476 if String.length
!fontpath = 0
6477 then fontpath := Buffer.contents
b;
6478 { v with f = llppconfig
}
6479 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6480 | Vend
-> error
"unexpected end of input in ui-font" s spos
6482 and doc
path pan
anchor c bookmarks
v t spos
_ =
6484 | Vdata
| Vcdata
-> v
6485 | Vend
-> error
"unexpected end of input in doc" s spos
6486 | Vopen
("bookmarks", _, closed
) ->
6489 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6491 | Vopen
("keymap", attrs
, closed
) ->
6493 try List.assoc
"mode" attrs
6494 with Not_found
-> "global"
6500 let h = findkeyhash c modename in
6501 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6502 doc
path pan
anchor c bookmarks
6504 { v with f = pkeymap
ret KeyMap.empty }
6506 | Vopen
(_, _, _) ->
6507 error
"unexpected subelement in doc" s spos
6510 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6511 { v with f = llppconfig
}
6513 | Vclose
_ -> error
"unexpected close in doc" s spos
6515 and pkeymap
ret keymap
v t spos
_ =
6517 | Vdata
| Vcdata
-> v
6518 | Vend
-> error
"unexpected end of input in keymap" s spos
6519 | Vopen
("map", attrs
, closed
) ->
6520 let r, l = map_of attrs
in
6521 let kss = fromstring keys_of_string spos
"in" r [] in
6522 let lss = fromstring keys_of_string spos
"out" l [] in
6526 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6527 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6530 then { v with f = pkeymap
ret keymap }
6533 { v with f = skip
"map" f }
6536 error
"unexpected subelement in keymap" s spos
6538 | Vclose
"keymap" ->
6539 { v with f = ret keymap }
6541 | Vclose
_ -> error
"unexpected close in keymap" s spos
6543 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6545 | Vdata
| Vcdata
-> v
6546 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6547 | Vopen
("item", attrs
, closed
) ->
6548 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6549 let page = fromstring int_of_string spos
"page" spage
0
6550 and rely = fromstring float_of_string spos
"rely" srely
0.0
6551 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6553 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6556 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6559 { v with f = skip
"item" f }
6562 error
"unexpected subelement in bookmarks" s spos
6564 | Vclose
"bookmarks" ->
6565 { v with f = doc
path pan
anchor c bookmarks }
6567 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6569 and skip tag
f v t spos
_ =
6571 | Vdata
| Vcdata
-> v
6573 error
("unexpected end of input in skipped " ^ tag
) s spos
6574 | Vopen
(tag'
, _, closed
) ->
6578 let f'
() = { v with f = skip tag
f } in
6579 { v with f = skip tag'
f'
}
6583 else error
("unexpected close in skipped " ^ tag
) s spos
6586 parse
{ f = toplevel; accu = () } s;
6592 let len = in_channel_length ic
in
6593 let s = String.create
len in
6594 really_input ic
s 0 len;
6597 | Parse_error
(msg
, s, pos
) ->
6598 let subs = subs s pos
in
6599 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6600 failwith
("parse error: " ^
s)
6603 failwith
("config load error: " ^ exntos exn
)
6609 let dir = Filename.concat
home ".config" in
6610 if Sys.is_directory
dir then dir else home
6613 Filename.concat
dir "llpp.conf"
6616 let confpath = ref defconfpath;;
6619 if Sys.file_exists
!confpath
6622 (try Some
(open_in_bin
!confpath)
6625 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6636 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6645 f (Hashtbl.create
0, defconf)
6650 let pc, pb
, px, pa
=
6652 Hashtbl.find h (Filename.basename
state.path)
6653 with Not_found
-> dc, [], 0, emptyanchor
6657 state.bookmarks <- pb
;
6659 state.scrollw
<- conf.scrollbw
;
6661 then state.anchor <- pa
;
6662 cbput state.hists
.nav pa
;
6668 let add_attrs bb always
dc c =
6671 then Printf.bprintf bb
"\n %s='%b'" s a
6674 then Printf.bprintf bb
"\n %s='%d'" s a
6677 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6680 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6683 then Printf.bprintf bb
"\n %s='%f'" s a
6687 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6691 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6695 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6699 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6705 | Some
(_N
, _A
, _B
) ->
6706 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6716 else string_of_float
f
6718 Printf.bprintf bb
"\n %s='%s'" s v
6723 | Cmulti
((n, a, b), _) when n > 1 ->
6724 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6725 | Csplit
(n, _) when n > 1 ->
6726 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6732 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6735 oi
"width" c.cwinw
dc.cwinw
;
6736 oi
"height" c.cwinh
dc.cwinh
;
6737 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6738 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6739 ob "case-insensitive-search" c.icase
dc.icase
;
6740 ob "preload" c.preload dc.preload;
6741 oi
"page-bias" c.pagebias
dc.pagebias
;
6742 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6743 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6744 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6745 ob "crop-hack" c.crophack
dc.crophack
;
6746 oW
"throttle" c.maxwait
dc.maxwait
;
6747 ob "highlight-links" c.hlinks
dc.hlinks
;
6748 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6749 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6750 oz
"zoom" c.zoom dc.zoom;
6751 ob "presentation" c.presentation
dc.presentation
;
6752 oi
"rotation-angle" c.angle
dc.angle
;
6753 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6754 ob "proportional-display" c.proportional
dc.proportional
;
6755 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6756 oi
"tex-count" c.texcount
dc.texcount
;
6757 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6758 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6759 ob "persistent-location" c.jumpback
dc.jumpback
;
6760 oc
"background-color" c.bgcolor
dc.bgcolor
;
6761 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6762 oi
"tile-width" c.tilew
dc.tilew
;
6763 oi
"tile-height" c.tileh
dc.tileh
;
6764 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6765 ob "checkers" c.checkers
dc.checkers
;
6766 oi
"aalevel" c.aalevel
dc.aalevel
;
6767 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6768 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6769 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6770 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6771 oC
"color-space" c.colorspace
dc.colorspace
;
6772 ob "invert-colors" c.invert
dc.invert
;
6773 oF
"brightness" c.colorscale
dc.colorscale
;
6774 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6775 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6776 oco
"columns" c.columns
dc.columns
;
6777 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6778 os
"selection-command" c.selcmd
dc.selcmd
;
6779 os
"synctex-command" c.stcmd
dc.stcmd
;
6780 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6781 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6782 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6783 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6784 ob "use-pbo" c.usepbo
dc.usepbo
;
6785 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6788 let keymapsbuf always
dc c =
6789 let bb = Buffer.create
16 in
6790 let rec loop = function
6792 | (modename, h) :: rest
->
6793 let dh = findkeyhash dc modename in
6794 if always
|| h <> dh
6796 if Hashtbl.length
h > 0
6798 if Buffer.length
bb > 0
6799 then Buffer.add_char
bb '
\n'
;
6800 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6801 Hashtbl.iter
(fun i
o ->
6802 let isdifferent = always
||
6804 let dO = Hashtbl.find dh i
in
6806 with Not_found
-> true
6811 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6812 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6813 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6814 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6815 Buffer.add_string
bb (Wsi.keyname
k);
6818 let rec loop = function
6820 | km
:: [] -> addkm km
6821 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6825 Buffer.add_string
bb "<map in='";
6829 Buffer.add_string
bb "' out='";
6831 Buffer.add_string
bb "'/>\n"
6834 Buffer.add_string
bb "' out='";
6836 Buffer.add_string
bb "'/>\n"
6838 | KMmulti
(ins, kms
) ->
6839 Buffer.add_char
bb ' '
;
6841 Buffer.add_string
bb "' out='";
6843 Buffer.add_string
bb "'/>\n"
6845 Buffer.add_string
bb "</keymap>";
6855 let uifontsize = fstate.fontsize
in
6856 let bb = Buffer.create
32768 in
6861 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
)
6862 | Wsi.MaxVert
-> (w, conf.cwinh
)
6863 | Wsi.MaxHorz
-> (conf.cwinw
, h)
6865 (state.winw, state.winh
) state.winstate
6870 let dc = if conf.bedefault
then conf else dc in
6871 Buffer.add_string
bb "<llppconfig>\n";
6873 if String.length
!fontpath > 0
6875 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6881 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6884 Buffer.add_string
bb "<defaults ";
6885 add_attrs bb true dc dc;
6886 let kb = keymapsbuf true dc dc in
6887 if Buffer.length
kb > 0
6889 Buffer.add_string
bb ">\n";
6890 Buffer.add_buffer
bb kb;
6891 Buffer.add_string
bb "\n</defaults>\n";
6893 else Buffer.add_string
bb "/>\n";
6895 let adddoc path pan
anchor c bookmarks =
6896 if bookmarks == [] && c = dc && anchor = emptyanchor
6899 Printf.bprintf
bb "<doc path='%s'"
6900 (enent
path 0 (String.length
path));
6902 if anchor <> emptyanchor
6904 let n, rely, visy
= anchor in
6905 Printf.bprintf
bb " page='%d'" n;
6908 Printf.bprintf
bb " rely='%f'" rely
6910 if abs_float visy
> 1e-6
6912 Printf.bprintf
bb " visy='%f'" visy
6917 then Printf.bprintf
bb " pan='%d'" pan
;
6919 add_attrs bb false dc c;
6920 let kb = keymapsbuf false dc c in
6922 begin match bookmarks with
6924 if Buffer.length
kb > 0
6926 Buffer.add_string
bb ">\n";
6927 Buffer.add_buffer
bb kb;
6928 Buffer.add_string
bb "\n</doc>\n";
6930 else Buffer.add_string
bb "/>\n"
6932 Buffer.add_string
bb ">\n<bookmarks>\n";
6933 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6935 "<item title='%s' page='%d'"
6936 (enent
title 0 (String.length
title))
6941 Printf.bprintf
bb " rely='%f'" rely
6943 if abs_float visy
> 1e-6
6945 Printf.bprintf
bb " visy='%f'" visy
6947 Buffer.add_string
bb "/>\n";
6949 Buffer.add_string
bb "</bookmarks>";
6950 if Buffer.length
kb > 0
6952 Buffer.add_string
bb "\n";
6953 Buffer.add_buffer
bb kb;
6955 Buffer.add_string
bb "\n</doc>\n";
6961 match state.mode with
6962 | Birdseye
(c, pan, _, _, _) ->
6964 match conf.columns
with
6965 | Cmulti
((c, _, _), _) -> Some
c
6969 match c.columns
with
6970 | Cmulti
(c, _) -> Cmulti
(c, [||])
6971 | Csingle
_ -> Csingle
[||]
6972 | Csplit
_ -> failwith
"quit from bird's eye while split"
6974 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6975 | _ -> state.x, conf
6977 let basename = Filename.basename state.path in
6978 adddoc basename pan (getanchor ())
6980 let autoscrollstep =
6981 match state.autoscroll
with
6983 | None
-> conf.autoscrollstep
6985 match state.mode with
6986 | Birdseye
(bc
, _, _, _, _) ->
6989 presentation
= bc
.presentation
;
6990 interpagespace
= bc
.interpagespace
;
6991 maxwait
= bc
.maxwait
;
6992 autoscrollstep = autoscrollstep }
6993 | _ -> { conf with autoscrollstep = autoscrollstep }
6995 (if conf.savebmarks
then state.bookmarks else []);
6997 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6999 then adddoc path x anchor c bookmarks
7001 Buffer.add_string
bb "</llppconfig>\n";
7004 if load1 f && Buffer.length
bb > 0
7007 let tmp = !confpath ^
".tmp" in
7008 let oc = open_out_bin
tmp in
7009 Buffer.output_buffer
oc bb;
7011 Unix.rename
tmp !confpath;
7014 ("error while saving configuration: " ^ exntos exn
)
7018 let adderrmsg src msg
=
7019 Buffer.add_string
state.errmsgs msg
;
7020 state.newerrmsgs
<- true;
7024 let adderrfmt src fmt
=
7025 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7029 let cl = splitatspace cmds
in
7031 try Scanf.sscanf
s fmt
f
7033 adderrfmt "remote exec"
7034 "error processing '%S': %s\n" cmds
(exntos exn
)
7037 | "reload" :: [] -> reload ()
7038 | "goto" :: args :: [] ->
7039 scan args "%u %f %f"
7041 let cmd, _ = state.geomcmds
in
7042 if String.length
cmd = 0
7043 then gotopagexy pageno x y
7046 gotopagexy pageno x y;
7049 state.reprf
<- f state.reprf
7051 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7052 | "rect" :: args :: [] ->
7053 scan args "%u %u %f %f %f %f"
7054 (fun pageno color x0 y0 x1 y1 ->
7055 onpagerect pageno (fun w h ->
7056 let _,w1,h1
,_ = getpagedim pageno in
7057 let sw = float w1 /. w
7058 and sh = float h1
/. h in
7062 and y1s
= y1 *. sh in
7063 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7065 state.rects <- (pageno, color, rect) :: state.rects;
7066 G.postRedisplay "rect";
7069 | "activatewin" :: [] -> Wsi.activatewin
()
7070 | "quit" :: [] -> raise Quit
7072 adderrfmt "remote command"
7073 "error processing remote command: %S\n" cmds
;
7077 let scratch = String.create
80 in
7078 let buf = Buffer.create
80 in
7081 try Some
(Unix.read fd
scratch 0 80)
7083 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7084 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7087 match tempfr () with
7093 if Buffer.length
buf > 0
7095 let s = Buffer.contents
buf in
7105 let pos = String.index_from
scratch ppos '
\n'
in
7106 if pos >= n then -1 else pos
7107 with Not_found
-> -1
7111 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7112 let s = Buffer.contents
buf in
7118 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7124 let remoteopen path =
7125 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7127 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7132 let trimcachepath = ref "" in
7133 let rcmdpath = ref "" in
7136 [("-p", Arg.String
(fun s -> state.password
<- s),
7137 "<password> Set password");
7139 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7140 "<path> Set path to the user interface font");
7142 ("-c", Arg.String
(fun s -> Config.confpath := s),
7143 "<path> Set path to the configuration file");
7145 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7146 "<path> Set path to the trim cache file");
7148 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7149 "<named-destination> Set named destination");
7151 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7153 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7154 "<path> Set path to the remote commands source");
7156 ("-v", Arg.Unit
(fun () ->
7158 "%s\nconfiguration path: %s\n"
7162 exit
0), " Print version and exit");
7165 (fun s -> state.path <- s)
7166 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7168 if String.length
state.path = 0
7169 then (prerr_endline
"file name missing"; exit
1);
7171 if not
(Config.load ())
7172 then prerr_endline
"failed to load configuration";
7174 let globalkeyhash = findkeyhash conf "global" in
7175 let wsfd, winw, winh
= Wsi.init
(object
7177 if nogeomcmds state.geomcmds
|| platform == Posx
7180 GlClear.color (scalecolor2 conf.bgcolor
);
7181 GlClear.clear
[`
color];
7183 method display = display ()
7184 method reshape w h = reshape w h
7185 method mouse b d x y m = mouse b d x y m
7186 method motion x y = state.mpos
<- (x, y); motion x y
7187 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7189 let mascm = m land (
7190 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7192 match state.keystate
with
7194 let km = k, mascm in
7197 let modehash = state.uioh#
modehash in
7198 try Hashtbl.find modehash km
7200 try Hashtbl.find globalkeyhash km
7201 with Not_found
-> KMinsrt
(k, m)
7203 | KMinsrt
(k, m) -> keyboard k m
7204 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7205 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7207 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7208 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7209 state.keystate
<- KSnone
7210 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7211 state.keystate
<- KSinto
(keys
, insrt
)
7213 state.keystate
<- KSnone
7215 method enter
x y = state.mpos
<- (x, y); pmotion x y
7216 method leave = state.mpos
<- (-1, -1)
7217 method winstate wsl
= state.winstate
<- wsl
7218 method quit
= raise Quit
7219 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7224 List.exists
GlMisc.check_extension
7225 [ "GL_ARB_texture_rectangle"
7226 ; "GL_EXT_texture_recangle"
7227 ; "GL_NV_texture_rectangle" ]
7229 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7232 match Ne.pipe () with
7234 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7238 match Ne.pipe () with
7240 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7250 setcheckers conf.checkers
;
7254 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7255 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7256 !Config.fontpath, !trimcachepath,
7257 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7261 state.text <- "Opening " ^
(mbtoutf8
state.path);
7263 opendoc state.path state.password
;
7266 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7269 if String.length
!rcmdpath > 0
7270 then remoteopen !rcmdpath
7275 let rec loop deadline
=
7277 match state.errfd
with
7278 | None
-> [state.sr
; state.wsfd]
7279 | Some fd
-> [state.sr
; state.wsfd; fd
]
7284 | Some fd
-> fd
:: r
7288 state.redisplay
<- false;
7295 if deadline
= infinity
7297 else max
0.0 (deadline
-. now)
7302 try Unix.select
r [] [] timeout
7303 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7309 if state.ghyll
== noghyll
7311 match state.autoscroll
with
7312 | Some step
when step
!= 0 ->
7313 let y = state.y + step
in
7317 else if y >= state.maxy then 0 else y
7320 if state.mode = View
7321 then state.text <- "";
7324 else deadline
+. 0.01
7329 let rec checkfds = function
7331 | fd
:: rest
when fd
= state.sr
->
7332 let cmd = readcmd state.sr
in
7336 | fd
:: rest
when fd
= state.wsfd ->
7340 | fd
:: rest
when Some fd
= !optrfd ->
7341 begin match remote fd
with
7342 | None
-> optrfd := remoteopen !rcmdpath;
7343 | opt -> optrfd := opt
7348 let s = String.create
80 in
7349 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7350 if conf.redirectstderr
7352 Buffer.add_substring
state.errmsgs
s 0 n;
7353 state.newerrmsgs
<- true;
7354 state.redisplay
<- true;
7357 prerr_string
(String.sub
s 0 n);
7365 if deadline
= infinity
7369 match state.autoscroll
with
7370 | Some step
when step
!= 0 -> deadline1
7371 | _ -> if state.ghyll
== noghyll then infinity
else deadline1