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
479 ; mutable wthack
: bool
482 ; mutable reprf
: (unit -> unit)
485 { pat
: string circbuf
486 ; pag
: string circbuf
487 ; nav
: anchor circbuf
488 ; sel
: string circbuf
510 ; presentation
= false
515 ; proportional
= true
516 ; trimmargins
= false
517 ; trimfuzz
= (0,0,0,0)
518 ; memlimit
= 32 lsl 20
523 ; bgcolor
= (0.5, 0.5, 0.5)
525 ; scrollbarinpm
= true
528 ; mustoresize
= 256 lsl 20
533 | Plinux
| Pfreebsd
| Pdragonflybsd
534 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
535 | Posx
-> "open \"%s\""
536 | Pcygwin
-> "cygstart \"%s\""
537 | Punknown
-> "echo %s")
538 ; pathlauncher
= "lp \"%s\""
541 | Plinux
| Pfreebsd
| Pdragonflybsd
542 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
549 ; redirectstderr
= false
551 ; columns
= Csingle
[||]
557 ; wheelbypage
= false
558 ; stcmd
= "echo SyncTex"
560 let mk n
= (n
, Hashtbl.create
1) in
574 let wtmode = ref false;;
576 let findkeyhash c name
=
577 try List.assoc name c
.keyhashes
578 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
581 let conf = { defconf with angle
= defconf.angle
};;
583 let pgscale h
= truncate
(float h
*. conf.pgscale);;
586 { mutable fontsize
: int
587 ; mutable wwidth
: float
588 ; mutable maxrows
: int
600 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
601 let len = String.length s
in
602 if colonpos >= 0 && colonpos + 3 < len
604 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
607 try String.rindex_from s
colonpos ' '
611 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
614 | "http" | "ftp" | "mailto" ->
616 try String.index_from s
colonpos ' '
617 with Not_found
-> len
619 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
627 if String.length
conf.urilauncher
= 0
628 then print_endline uri
630 let url = geturl uri
in
631 if String.length
url = 0
632 then print_endline uri
634 let re = Str.regexp
"%s" in
635 let command = Str.global_replace
re url conf.urilauncher
in
639 "failed to execute `%s': %s\n" command (exntos exn
);
645 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
646 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
650 let strings = version () :: "" :: Help.keys
in
653 let url = geturl s
in
654 if String.length
url > 0
655 then (s
, 0, Action
(fun u
-> gotouri url; u
))
656 else (s
, 0, Noaction
)
661 let firstgeomcmds = "", [];;
662 let noreprf () = ();;
669 ; stderr
= Unix.stderr
670 ; errmsgs
= Buffer.create
0
677 ; anchor
= emptyanchor
681 ; tilelru
= Queue.create
()
682 ; pagemap
= Hashtbl.create
10
683 ; tilemap
= Hashtbl.create
10
699 ; geomcmds
= firstgeomcmds
701 { nav
= cbnew 10 emptyanchor
730 fstate.fontsize
<- n
;
731 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
732 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
738 Printf.kprintf prerr_endline fmt
740 Printf.kprintf ignore fmt
744 if String.length
conf.pathlauncher
= 0
745 then print_endline
state.path
747 let re = Str.regexp
"%s" in
748 let command = Str.global_replace
re state.path
conf.pathlauncher
in
751 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
757 type 'a t
= | Res
of 'a
| Exn
of exn
;;
760 try Res
(Unix.pipe ())
765 try tempfailureretry
Unix.close fd
766 with exn
-> f
(exntos exn
)
770 try Res
(tempfailureretry
Unix.dup fd
)
775 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
780 let redirectstderr () =
781 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
782 if conf.redirectstderr
784 match Ne.pipe () with
786 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
789 begin match Ne.dup Unix.stderr
with
791 dolog
"failed to dup stderr: %s" (exntos exn
);
792 Ne.clo r
(clofail "pipe/r");
793 Ne.clo w
(clofail "pipe/w");
795 | Ne.Res dupstderr
->
796 begin match Ne.dup2 w
Unix.stderr
with
798 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
799 Ne.clo dupstderr
(clofail "stderr duplicate");
800 Ne.clo r
(clofail "redir pipe/r");
801 Ne.clo w
(clofail "redir pipe/w");
804 state.stderr
<- dupstderr
;
805 state.errfd
<- Some r
;
809 state.newerrmsgs
<- false;
810 begin match state.errfd
with
812 begin match Ne.dup2 state.stderr
Unix.stderr
with
814 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
816 Ne.clo fd
(clofail "dup of stderr");
821 prerr_string
(Buffer.contents
state.errmsgs
);
823 Buffer.clear
state.errmsgs
;
829 let postRedisplay who
=
831 then prerr_endline
("redisplay for " ^ who
);
832 state.redisplay
<- true;
836 let getopaque pageno
=
837 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
838 with Not_found
-> None
841 let putopaque pageno opaque
=
842 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
845 let pagetranslatepoint l x y
=
846 let dy = y
- l
.pagedispy
in
847 let y = dy + l
.pagey
in
848 let dx = x
- l
.pagedispx
in
849 let x = dx + l
.pagex
in
853 let onppundermouse g
x y d
=
856 begin match getopaque l
.pageno
with
858 let x0 = l
.pagedispx
in
859 let x1 = x0 + l
.pagevw
in
860 let y0 = l
.pagedispy
in
861 let y1 = y0 + l
.pagevh
in
862 if y >= y0 && y <= y1 && x >= x0 && x <= x1
864 let px, py
= pagetranslatepoint l
x y in
865 match g opaque l
px py
with
878 let g opaque _
px py
=
879 match whatsunder opaque
px py
with
881 | under
-> Some under
883 onppundermouse g x y Unone
888 match unproject opaque
x y with
889 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
892 onppundermouse g x y None
;
896 state.text
<- Printf.sprintf
"%c%s" c s
;
897 G.postRedisplay "showtext";
900 let undertext = function
903 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
904 | Utext s
-> "font: " ^ s
905 | Uunexpected s
-> "unexpected: " ^ s
906 | Ulaunch s
-> "launch: " ^ s
907 | Unamed s
-> "named: " ^ s
908 | Uremote
(filename
, pageno
) ->
909 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
912 let updateunder x y =
913 match getunder x y with
914 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
916 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
917 Wsi.setcursor
Wsi.CURSOR_INFO
918 | Ulinkgoto
(pageno
, _
) ->
920 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
921 Wsi.setcursor
Wsi.CURSOR_INFO
923 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
924 Wsi.setcursor
Wsi.CURSOR_TEXT
926 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
927 Wsi.setcursor
Wsi.CURSOR_INHERIT
929 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
930 Wsi.setcursor
Wsi.CURSOR_INHERIT
932 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
933 Wsi.setcursor
Wsi.CURSOR_INHERIT
934 | Uremote
(filename
, pageno
) ->
935 if conf.underinfo
then showtext 'r'
936 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
937 Wsi.setcursor
Wsi.CURSOR_INFO
940 let showlinktype under
=
946 let s = undertext under
in
951 let b = Buffer.create
(String.length
s + 1) in
952 Buffer.add_string
b s;
957 let colorspace_of_string s =
958 match String.lowercase
s with
962 | _
-> failwith
"invalid colorspace"
965 let int_of_colorspace = function
971 let colorspace_of_int = function
975 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
978 let colorspace_to_string = function
984 let intentry_with_suffix text key
=
986 if key
>= 32 && key
< 127
990 match Char.lowercase
c with
992 let text = addchar text c in
996 let text = addchar text c in
1000 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1004 let multicolumns_to_string (n
, a
, b) =
1006 then Printf.sprintf
"%d" n
1007 else Printf.sprintf
"%d,%d,%d" n a
b;
1010 let multicolumns_of_string s =
1012 (int_of_string
s, 0, 0)
1014 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1016 then failwith
"subtly broken"; (n
, a
, b)
1022 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1023 if n != 4 then failwith
"incomplete read(len)";
1025 lor (Char.code
s.[0] lsl 24)
1026 lor (Char.code
s.[1] lsl 16)
1027 lor (Char.code
s.[2] lsl 8)
1028 lor (Char.code
s.[3] lsl 0)
1030 let s = String.create
len in
1031 let n = tempfailureretry
(Unix.read fd
s 0) len in
1032 if n != len then failwith
"incomplete read(data)";
1036 let btod b = if b then 1 else 0;;
1039 let b = Buffer.create
16 in
1040 Buffer.add_string
b "llll";
1043 let s = Buffer.contents
b in
1044 let n = String.length
s in
1046 (* dolog "wcmd %S" (String.sub s 4 len); *)
1047 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1048 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1049 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1050 s.[3] <- Char.chr
(len land 0xff);
1051 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1052 if n'
!= n then failwith
"write failed";
1057 let d = state.winh
- h
in
1058 max
conf.interpagespace
((d + 1) / 2)
1061 let rowyh (c, coverA
, coverB
) b n =
1062 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1064 let _, _, vy
, (_, _, h
, _) = b.(n) in
1067 let n'
= n - coverA
in
1070 let e = min
state.pagecount
(s + c) in
1071 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1072 let _, _, y, (_, _, h
, _) = b.(m
) in
1073 let miny = min
miny y in
1074 let maxh = max
maxh h
in
1075 find (m
+1) miny maxh
1080 match conf.columns
with
1081 | Cmulti
((_, _, _) as cl
, b) ->
1082 if Array.length
b > 0
1084 let y, h
= rowyh cl
b (Array.length
b - 1) in
1085 y + h
+ (if conf.presentation
then calcips h
else 0)
1088 if Array.length
b > 0
1090 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1091 y + h
+ (if conf.presentation
then calcips h
else 0)
1094 if Array.length
b > 0
1096 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1101 let getpageyh pageno
=
1102 let pageno = bound pageno 0 (state.pagecount
-1) in
1103 match conf.columns
with
1105 if Array.length
b = 0
1108 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1110 if conf.presentation
1116 if Array.length
b = 0
1119 let y, h
= rowyh cl
b pageno in
1121 if conf.presentation
1127 if Array.length
b = 0
1131 let (_, _, y, (_, _, h
, _)) = b.(n) in
1135 let getpagedim pageno =
1138 | (n, _, _, _) as pdim
:: rest
->
1140 then (if n = pageno then pdim
else ppdim
)
1145 f (-1, -1, -1, -1) state.pdims
1148 let getpagey pageno = fst
(getpageyh pageno);;
1150 let nogeomcmds cmds
=
1152 | s, [] -> String.length
s = 0
1157 let ((c, coverA
, coverB
) as cl
), b =
1158 match conf.columns
with
1159 | Csingle
b -> (1, 0, 0), b
1160 | Cmulti
(c, b) -> c, b
1161 | Csplit
(_, b) -> (1, 0, 0), b
1163 if Array.length
b = 0
1166 let rec bsearch nmin nmax
=
1168 then bound nmin
0 (state.pagecount
-1)
1170 let n = (nmax
+ nmin
) / 2 in
1171 let vy, h
= rowyh cl
b n in
1173 if conf.presentation
1175 let ips = calcips h
in
1176 let y0 = vy - ips in
1177 let y1 = vy + h
+ ips in
1181 then 0, vy + h
+ conf.interpagespace
1183 let y0 = vy - conf.interpagespace
in
1184 y0, y0 + h
+ conf.interpagespace
1187 if y >= y0 && y < y1
1194 if n < state.pagecount
- coverB
1195 then ((n-coverA
)/c)*c + coverA
1202 then bsearch (n+1) nmax
1203 else bsearch nmin
(n-1)
1206 let r = bsearch 0 (state.pagecount
-1) in
1210 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1211 let sh = sh - state.hscrollh
in
1212 let rec fold accu
n =
1213 if n = Array.length
b
1216 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1219 || n = state.pagecount
- coverB
1220 || (n - coverA
) mod columns
= columns
- 1)
1226 let pagey = max
0 (y - vy) in
1227 let pagedispy = if pagey > 0 then 0 else vy - y in
1228 let pagedispx, pagex
=
1230 if n = coverA
- 1 || n = state.pagecount
- coverB
1231 then state.x + (state.winw
- state.scrollw
- w
) / 2
1232 else dx + xoff
+ state.x
1239 let vw = state.winw
- state.scrollw
- pagedispx in
1240 let pw = w
- pagex
in
1243 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1244 if pagevw > 0 && pagevh > 0
1248 ; pagedimno
= pdimno
1255 ; pagedispx = pagedispx
1256 ; pagedispy = pagedispy
1268 List.rev
(fold [] (page_of_y y));
1271 let layoutS (columns
, b) y sh =
1272 let sh = sh - state.hscrollh
in
1273 let rec fold accu n =
1274 if n = Array.length
b
1277 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1284 let x = xoff
+ state.x in
1285 let pagey = max
0 (y - vy) in
1286 let pagedispy = if pagey > 0 then 0 else vy - y in
1287 let pagedispx, pagex
=
1301 let pagecolw = pagew
/columns
in
1303 if pagecolw < state.winw
1304 then pagedispx + ((state.winw
- state.scrollw
- pagecolw) / 2)
1308 let vw = state.winw
- pagedispx - state.scrollw
in
1309 let pw = pagew
- pagex
in
1312 let pagevw = min
pagevw pagecolw in
1313 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1314 if pagevw > 0 && pagevh > 0
1317 { pageno = n/columns
1318 ; pagedimno
= pdimno
1325 ; pagedispx = pagedispx
1326 ; pagedispy = pagedispy
1327 ; pagecol
= n mod columns
1338 List.rev
(fold [] 0)
1342 if nogeomcmds state.geomcmds
1344 match conf.columns
with
1345 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1346 | Cmulti
c -> layoutN c y sh
1347 | Csplit
s -> layoutS s y sh
1352 let y = state.y + incr
in
1354 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1359 let tilex = l
.pagex
mod conf.tilew
in
1360 let tiley = l
.pagey mod conf.tileh
in
1362 let col = l
.pagex
/ conf.tilew
in
1363 let row = l
.pagey / conf.tileh
in
1365 let rec rowloop row y0 dispy h
=
1369 let dh = conf.tileh
- y0 in
1370 let dh = min h
dh in
1371 let rec colloop col x0 dispx w
=
1375 let dw = conf.tilew
- x0 in
1376 let dw = min w
dw in
1378 f col row dispx dispy
x0 y0 dw dh;
1379 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1382 colloop col tilex l
.pagedispx l
.pagevw;
1383 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1386 if l
.pagevw > 0 && l
.pagevh > 0
1387 then rowloop row tiley l
.pagedispy l
.pagevh;
1390 let gettileopaque l
col row =
1392 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1394 try Some
(Hashtbl.find state.tilemap
key)
1395 with Not_found
-> None
1398 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1399 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1400 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1403 let drawtiles l color
=
1405 let f col row x y tilex tiley w h
=
1406 match gettileopaque l
col row with
1407 | Some
(opaque
, _, t
) ->
1408 let params = x, y, w
, h
, tilex, tiley in
1412 GlFunc.blend_func `zero `one_minus_src_color
;
1414 drawtile
params opaque
;
1416 then Gl.disable `blend
;
1419 let s = Printf.sprintf
1423 let w = measurestr
fstate.fontsize
s in
1424 GlMisc.push_attrib
[`current
];
1425 GlDraw.color
(0.0, 0.0, 0.0);
1427 (float (x-2), float (y-2))
1428 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1429 GlDraw.color
(1.0, 1.0, 1.0);
1430 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1431 GlMisc.pop_attrib
();
1436 let lw = state.winw
- state.scrollw
- x in
1439 let lh = state.winh
- y in
1442 begin match state.texid
with
1444 Gl.enable `texture_2d
;
1445 GlTex.bind_texture `texture_2d id
;
1448 and x1 = float (x+w)
1449 and y1 = float (y+h
) in
1451 let tw = float w /. 16.0
1452 and th
= float h
/. 16.0 in
1453 let tx0 = float tilex /. 16.0
1454 and ty0
= float tiley /. 16.0 in
1456 and ty1
= ty0
+. th
in
1457 GlDraw.begins `quads
;
1458 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1459 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1460 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1461 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1464 Gl.disable `texture_2d
;
1466 GlDraw.color
(1.0, 1.0, 1.0);
1469 (float (x+w), float (y+h
));
1471 if w > 128 && h
> fstate.fontsize
+ 10
1473 GlDraw.color
(0.0, 0.0, 0.0);
1476 then (col*conf.tilew
, row*conf.tileh
)
1479 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1486 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1488 let tilevisible1 l
x y =
1490 and ax1
= l
.pagex
+ l
.pagevw
1492 and ay1
= l
.pagey + l
.pagevh in
1496 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1497 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1499 let rx0 = max
ax0 bx0
1500 and ry0
= max ay0 by0
1501 and rx1
= min ax1
bx1
1502 and ry1
= min ay1 by1
in
1504 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1505 nonemptyintersection
1508 let tilevisible layout n x y =
1509 let rec findpageinlayout m
= function
1510 | l
:: rest
when l
.pageno = n ->
1511 tilevisible1 l
x y || (
1512 match conf.columns
with
1513 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1516 | _ :: rest
-> findpageinlayout 0 rest
1519 findpageinlayout 0 layout;
1522 let tileready l
x y =
1523 tilevisible1 l
x y &&
1524 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1527 let tilepage n p
layout =
1528 let rec loop = function
1532 let f col row _ _ _ _ _ _ =
1533 if state.currently
= Idle
1535 match gettileopaque l
col row with
1538 let x = col*conf.tilew
1539 and y = row*conf.tileh
in
1541 let w = l
.pagew
- x in
1545 let h = l
.pageh
- y in
1550 then getpbo
w h conf.colorspace
1553 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1556 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1557 conf.tilew
, conf.tileh
1566 if nogeomcmds state.geomcmds
1570 let preloadlayout y =
1571 let y = if y < state.winh
then 0 else y - state.winh
in
1572 let h = state.winh
*3 in
1577 let rec loop pages
=
1578 if state.currently
!= Idle
1583 begin match getopaque l
.pageno with
1585 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1586 state.currently
<- Loading
(l
, state.gen
);
1588 tilepage l
.pageno opaque pages
;
1593 if nogeomcmds state.geomcmds
1599 if conf.preload && state.currently
= Idle
1600 then load (preloadlayout state.y);
1603 let layoutready layout =
1604 let rec fold all ls
=
1605 all
&& match ls
with
1607 let seen = ref false in
1608 let allvisible = ref true in
1609 let foo col row _ _ _ _ _ _ =
1611 allvisible := !allvisible &&
1612 begin match gettileopaque l
col row with
1618 fold (!seen && !allvisible) rest
1621 let alltilesvisible = fold true layout in
1626 state.wthack
<- false;
1627 let y = bound y 0 state.maxy
in
1628 let y, layout, proceed
=
1629 match conf.maxwait
with
1630 | Some time
when state.ghyll
== noghyll ->
1631 begin match state.throttle
with
1633 let layout = layout y state.winh
in
1634 let ready = layoutready layout in
1638 state.throttle
<- Some
(layout, y, now ());
1640 else G.postRedisplay "gotoy showall (None)";
1642 | Some
(_, _, started
) ->
1643 let dt = now () -. started
in
1646 state.throttle
<- None
;
1647 let layout = layout y state.winh
in
1649 G.postRedisplay "maxwait";
1656 let layout = layout y state.winh
in
1657 G.postRedisplay "gotoy ready";
1663 state.layout <- layout;
1664 begin match state.mode
with
1665 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1666 let rec loop = function
1668 state.mode
<- LinkNav
(Ltgendir
0)
1669 | l
:: _ when l
.pageno = pageno ->
1670 begin match getopaque pageno with
1672 state.mode
<- LinkNav
(Ltgendir
0)
1674 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1675 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1676 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1677 then state.mode
<- LinkNav
(Ltgendir
0)
1679 | _ :: rest
-> loop rest
1684 begin match state.mode
with
1685 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1686 if not
(pagevisible layout pageno)
1688 match state.layout with
1691 state.mode
<- Birdseye
(
1692 conf, leftx
, l
.pageno, hooverpageno
, anchor
1695 | LinkNav
(Ltgendir dir
as lt
) ->
1697 let rec loop = function
1700 match getopaque l
.pageno with
1706 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1708 if dir
> 0 then LDfirst
else LDlast
1714 | Lnotfound
-> loop rest
1716 showlinktype (getlink opaque
n);
1717 Ltexact
(l
.pageno, n)
1721 state.mode
<- LinkNav
linknav
1726 state.ghyll
<- noghyll;
1729 let mx, my
= state.mpos
in
1734 let conttiling pageno opaque
=
1735 tilepage pageno opaque
1736 (if conf.preload then preloadlayout state.y else state.layout)
1739 let gotoy_and_clear_text y =
1740 if not
conf.verbose
then state.text <- "";
1746 let coloff = l
.pagecol
* l
.pageh
in
1747 float (l
.pagey + coloff) /. float l
.pageh
1754 if conf.presentation
1755 then float l
.pagedispy /. float (calcips l
.pageh
)
1756 else float l
.pagedispy /. float conf.interpagespace
1758 (l
.pageno, top, dtop)
1762 match state.layout with
1763 | l
:: _ -> getanchor1 l
1765 let n = page_of_y state.y in
1769 let y, h = getpageyh n in
1770 let dy = y - state.y in
1772 if conf.presentation
1774 let ips = calcips h in
1775 float (dy + ips) /. float ips
1777 float dy /. float conf.interpagespace
1782 let getanchory (n, top, dtop) =
1783 let y, h = getpageyh n in
1784 if conf.presentation
1786 let ips = calcips h in
1787 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1789 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1792 let gotoanchor anchor
=
1793 gotoy (getanchory anchor
);
1797 cbput state.hists
.nav
(getanchor ());
1801 let anchor = cbgetc state.hists
.nav dir
in
1806 let scroll f n a
b =
1807 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1809 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1811 then s (float f /. float a
)
1814 then 1.0 -. s ((float (f-b) /. float (n-b)))
1821 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1822 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1824 let ins = float a
*. iv1
1825 and outs
= float (n-b) *. iv1 in
1827 ins +. outs
+. float ones
1829 let rec set (_N
, _A
, _B
) y sy
=
1830 let sum = summa
1.0 _N _A _B
in
1831 let dy = float (y - sy
) in
1835 then state.ghyll
<- noghyll
1838 let s = scroll n _N _A _B
in
1839 let y1 = y1 +. ((s *. dy) /. sum) in
1840 gotoy_and_clear_text (truncate
y1);
1841 state.ghyll
<- gf (n+1) y1;
1845 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1847 gf 0 (float state.y)
1850 match conf.ghyllscroll
with
1852 gotoy_and_clear_text y
1854 if state.ghyll
== noghyll
1855 then set nab
y state.y
1856 else state.ghyll
(Some
y)
1859 let gotopage n top =
1860 let y, h = getpageyh n in
1861 let y = y + (truncate
(top *. float h)) in
1865 let gotopage1 n top =
1866 let y = getpagey n in
1871 let invalidate s f =
1876 match state.geomcmds
with
1877 | ps
, [] when String.length ps
= 0 ->
1879 state.geomcmds
<- s, [];
1882 state.geomcmds
<- ps
, [s, f];
1884 | ps
, (s'
, _) :: rest
when s'
= s ->
1885 state.geomcmds
<- ps
, ((s, f) :: rest
);
1888 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1892 Hashtbl.iter
(fun _ opaque
->
1893 wcmd "freepage %s" opaque
;
1895 Hashtbl.clear
state.pagemap
;
1899 if not
(Queue.is_empty
state.tilelru
)
1901 Queue.iter
(fun (k
, p
, s) ->
1902 wcmd "freetile %s" p
;
1903 state.memused
<- state.memused
- s;
1904 Hashtbl.remove
state.tilemap k
;
1906 state.uioh#infochanged Memused
;
1907 Queue.clear
state.tilelru
;
1912 let opendoc path password
=
1914 state.password
<- password
;
1915 state.gen
<- state.gen
+ 1;
1916 state.docinfo
<- [];
1919 setaalevel
conf.aalevel
;
1920 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1921 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1922 invalidate "reqlayout"
1924 wcmd "reqlayout %d %d %s\000"
1925 conf.angle
(btod conf.proportional
) state.nameddest
;
1930 state.anchor <- getanchor ();
1931 state.wthack
<- !wtmode;
1932 opendoc state.path
state.password
;
1936 let c = c *. conf.colorscale
in
1940 let scalecolor2 (r, g, b) =
1941 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
1944 let docolumns = function
1946 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1947 let rec loop pageno pdimno pdim
y ph pdims
=
1948 if pageno = state.pagecount
1951 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1953 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1954 pdimno+1, pdim
, rest
1958 let x = max
0 (((state.winw
- state.scrollw
- w) / 2) - xoff
) in
1960 (if conf.presentation
1961 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1962 else (if pageno = 0 then 0 else conf.interpagespace
)
1965 a.(pageno) <- (pdimno, x, y, pdim
);
1966 loop (pageno+1) pdimno pdim
(y + h) h pdims
1968 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1969 conf.columns
<- Csingle
a;
1971 | Cmulti
((columns
, coverA
, coverB
), _) ->
1972 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1973 let rec loop pageno pdimno pdim
x y rowh pdims
=
1974 let rec fixrow m
= if m
= pageno then () else
1975 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1978 let y = y + (rowh
- h) / 2 in
1979 a.(m
) <- (pdimno, x, y, pdim
);
1983 if pageno = state.pagecount
1984 then fixrow (((pageno - 1) / columns
) * columns
)
1986 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1988 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1989 pdimno+1, pdim
, rest
1994 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1996 let x = (state.winw
- state.scrollw
- w) / 2 in
1998 if conf.presentation
then calcips h else conf.interpagespace
in
1999 x, y + ips + rowh
, h
2002 if (pageno - coverA
) mod columns
= 0
2004 let x = max
0 (state.winw
- state.scrollw
- state.w) / 2 in
2006 if conf.presentation
2008 let ips = calcips h in
2009 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2011 y + (if pageno = 0 then 0 else conf.interpagespace
)
2015 else x, y, max rowh
h
2019 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2022 if pageno = columns
&& conf.presentation
2024 let ips = calcips rowh
in
2025 for i
= 0 to pred columns
2027 let (pdimno, x, y, pdim
) = a.(i
) in
2028 a.(i
) <- (pdimno, x, y+ips, pdim
)
2034 fixrow (pageno - columns
);
2039 a.(pageno) <- (pdimno, x, y, pdim
);
2040 let x = x + w + xoff
*2 + conf.interpagespace
in
2041 loop (pageno+1) pdimno pdim
x y rowh' pdims
2043 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2044 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2047 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2048 let rec loop pageno pdimno pdim
y pdims
=
2049 if pageno = state.pagecount
2052 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2054 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2055 pdimno+1, pdim
, rest
2060 let rec loop1 n x y =
2061 if n = c then y else (
2062 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2063 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2066 let y = loop1 0 0 y in
2067 loop (pageno+1) pdimno pdim
y pdims
2069 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2070 conf.columns
<- Csplit
(c, a);
2074 docolumns conf.columns
;
2075 state.maxy
<- calcheight ();
2077 if state.x = 0 && state.w <= state.winw
- state.scrollw
2081 if state.reprf
== noreprf
2083 begin match state.mode
with
2084 | Birdseye
(_, _, pageno, _, _) ->
2085 let y, h = getpageyh pageno in
2086 let top = (state.winh
- h) / 2 in
2087 gotoy (max
0 (y - top))
2088 | _ -> gotoanchor state.anchor
2090 state.wthack
<- !wtmode && not
(layoutready state.layout);
2094 state.reprf
<- noreprf;
2099 state.wthack
<- false;
2100 GlDraw.viewport
0 0 w h;
2101 let firsttime = state.geomcmds
== firstgeomcmds in
2102 if not
firsttime && nogeomcmds state.geomcmds
2103 then state.anchor <- getanchor ();
2106 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2109 setfontsize fstate.fontsize
;
2110 GlMat.mode `modelview
;
2111 GlMat.load_identity
();
2113 GlMat.mode `projection
;
2114 GlMat.load_identity
();
2115 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2116 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2117 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2122 else float state.x /. float state.w
2124 invalidate "geometry"
2128 then state.x <- truncate
(relx *. float w);
2130 match conf.columns
with
2132 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2133 | Csplit
(c, _) -> w * c
2135 wcmd "geometry %d %d" w h);
2139 let len = String.length
state.text in
2142 match state.mode
with
2145 let h, _, _ = state.uioh#scrollpw
in
2151 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2152 (x+.w, float (state.winh
- hscrollh))
2155 let w = float (state.winw
- state.scrollw
- 1) in
2156 if state.progress
>= 0.0 && state.progress
< 1.0
2158 GlDraw.color
(0.3, 0.3, 0.3);
2159 let w1 = w *. state.progress
in
2161 GlDraw.color
(0.0, 0.0, 0.0);
2165 GlDraw.color
(0.0, 0.0, 0.0);
2169 GlDraw.color
(1.0, 1.0, 1.0);
2170 drawstring fstate.fontsize
2171 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2174 match state.mode
with
2175 | Textentry
((prefix
, text, _, _, _, _), _) ->
2179 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2181 Printf.sprintf
"%s%s_" prefix
text
2190 if not
(istextentry state.mode
)
2192 let s1 = "(press 'e' to review error messasges)" in
2193 if String.length
s > 0 then s ^
" " ^
s1 else s1
2198 if String.length
s > 0
2203 let len = Queue.length
state.tilelru
in
2205 match state.throttle
with
2208 then preloadlayout state.y
2210 | Some
(layout, _, _) ->
2214 if state.memused
<= conf.memlimit
2219 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2220 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2221 let (_, pw, ph
, _) = getpagedim n in
2224 && colorspace
= conf.colorspace
2225 && angle
= conf.angle
2229 let x = col*conf.tilew
2230 and y = row*conf.tileh
in
2231 tilevisible (Lazy.force_val
layout) n x y
2233 then Queue.push lruitem
state.tilelru
2236 wcmd "freetile %s" p
;
2237 state.memused
<- state.memused
- s;
2238 state.uioh#infochanged Memused
;
2239 Hashtbl.remove
state.tilemap k
;
2247 let logcurrently = function
2248 | Idle
-> dolog
"Idle"
2249 | Loading
(l
, gen
) ->
2250 dolog
"Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2251 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2253 "Tiling %d[%d,%d] page=%s cs=%s angle"
2254 l
.pageno col row pageopaque
2255 (colorspace_to_string colorspace
)
2257 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2258 angle gen
conf.angle
state.gen
2260 conf.tilew
conf.tileh
2267 let r = Str.regexp
" " in
2268 fun s -> Str.bounded_split
r s 2;
2271 let onpagerect pageno f =
2273 match conf.columns
with
2274 | Cmulti
(_, b) -> b
2276 | Csplit
(_, b) -> b
2278 if pageno >= 0 && pageno < Array.length
b
2280 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2281 let r = getpdimrect
pdimno in
2282 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2285 let gotopagexy pageno x y =
2286 onpagerect pageno (fun w h ->
2288 let _,w1,_,leftx
= getpagedim pageno in
2289 let wh = state.winh
- state.hscrollh in
2290 let sw = float w1 /. w in
2292 let x = leftx
+ state.x + truncate
x in
2294 if x < 0 || x >= state.winw
- state.scrollw
2298 let py, h = getpageyh pageno in
2299 let y'
= py + truncate
(top *. float h) in
2300 let dy = y'
- state.y in
2302 if x != state.x || not
(dy > 0 && dy < wh)
2304 if conf.presentation
2306 if abs
(py - y'
) > wh
2313 if state.x != sx || state.y != sy
2318 let ww = state.winw
- state.scrollw
in
2323 let x = if -x + ww > w1 then -(w1-ww) else x
2324 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2326 if conf.presentation
2328 if abs
(py - y'
) > wh
2339 if x = 0 && state.w <= state.winw
- state.scrollw
2343 gotoy_and_clear_text y;
2345 else gotoy_and_clear_text state.y;
2346 state.wthack
<- !wtmode && not
(layoutready state.layout);
2351 (* dolog "%S" cmds; *)
2352 let cl = splitatspace cmds
in
2354 try Scanf.sscanf
s fmt
f
2356 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2361 state.uioh#infochanged Pdim
;
2364 | "clearrects" :: [] ->
2365 state.rects
<- state.rects1
;
2366 G.postRedisplay "clearrects";
2368 | "continue" :: args :: [] ->
2369 let n = scan args "%u" (fun n -> n) in
2370 state.pagecount
<- n;
2371 begin match state.currently
with
2373 state.currently
<- Idle
;
2374 state.outlines
<- Array.of_list
(List.rev l
)
2378 let cur, cmds
= state.geomcmds
in
2379 if String.length
cur = 0
2380 then failwith
"umpossible";
2382 begin match List.rev cmds
with
2384 state.geomcmds
<- "", [];
2388 state.geomcmds
<- s, List.rev rest
;
2390 if conf.maxwait
= None
2391 then G.postRedisplay "continue";
2393 | "title" :: args :: [] ->
2396 | "msg" :: args :: [] ->
2399 | "vmsg" :: args :: [] ->
2401 then showtext ' '
args
2403 | "emsg" :: args :: [] ->
2404 Buffer.add_string
state.errmsgs
args;
2405 state.newerrmsgs
<- true;
2406 G.postRedisplay "error message"
2408 | "progress" :: args :: [] ->
2409 let progress, text =
2412 f, String.sub
args pos
(String.length
args - pos
))
2415 state.progress <- progress;
2416 G.postRedisplay "progress"
2418 | "firstmatch" :: args :: [] ->
2419 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2420 scan args "%u %d %f %f %f %f %f %f %f %f"
2421 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2422 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2424 let y = (getpagey pageno) + truncate
y0 in
2427 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2429 | "match" :: args :: [] ->
2430 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2431 scan args "%u %d %f %f %f %f %f %f %f %f"
2432 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2433 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2436 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2438 | "page" :: args :: [] ->
2439 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2440 begin match state.currently
with
2441 | Loading
(l
, gen
) ->
2442 vlog "page %d took %f sec" l
.pageno t
;
2443 Hashtbl.replace
state.pagemap
(l
.pageno, gen
) pageopaque;
2444 begin match state.throttle
with
2446 let preloadedpages =
2448 then preloadlayout state.y
2453 Set.Make
(struct type t
= int let compare = (-) end) in
2455 List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
2456 IntSet.empty
preloadedpages
2459 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2460 if not
(IntSet.mem
pageno set)
2462 wcmd "freepage %s" opaque
;
2468 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2471 state.currently
<- Idle
;
2474 tilepage l
.pageno pageopaque state.layout;
2476 load preloadedpages;
2477 if pagevisible state.layout l
.pageno
2478 && layoutready state.layout
2479 then G.postRedisplay "page";
2482 | Some
(layout, _, _) ->
2483 state.currently
<- Idle
;
2484 tilepage l
.pageno pageopaque layout;
2489 dolog
"Inconsistent loading state";
2490 logcurrently state.currently
;
2494 | "tile" :: args :: [] ->
2495 let (x, y, opaque
, size
, t
) =
2496 scan args "%u %u %s %u %f"
2497 (fun x y p size t
-> (x, y, p
, size
, t
))
2499 begin match state.currently
with
2500 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2501 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
2504 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2506 wcmd "freetile %s" opaque
;
2507 state.currently
<- Idle
;
2511 puttileopaque l
col row gen cs angle opaque size t
;
2512 state.memused
<- state.memused
+ size
;
2513 state.uioh#infochanged Memused
;
2515 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
2516 opaque
, size
) state.tilelru
;
2519 match state.throttle
with
2520 | None
-> state.layout
2521 | Some
(layout, _, _) -> layout
2524 state.currently
<- Idle
;
2526 && conf.colorspace
= cs
2527 && conf.angle
= angle
2528 && tilevisible layout l
.pageno x y
2529 then conttiling l
.pageno pageopaque;
2531 begin match state.throttle
with
2534 then state.wthack
<- not
(layoutready state.layout);
2535 preload state.layout;
2537 && conf.colorspace
= cs
2538 && conf.angle
= angle
2539 && tilevisible state.layout l
.pageno x y
2540 then G.postRedisplay "tile nothrottle";
2542 | Some
(layout, y, _) ->
2543 let ready = layoutready layout in
2546 state.wthack
<- false;
2548 state.layout <- layout;
2549 state.throttle
<- None
;
2550 G.postRedisplay "throttle";
2557 dolog
"Inconsistent tiling state";
2558 logcurrently state.currently
;
2562 | "pdim" :: args :: [] ->
2564 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2566 state.uioh#infochanged Pdim
;
2567 state.pdims
<- pdim :: state.pdims
2569 | "o" :: args :: [] ->
2570 let (l
, n, t
, h, pos
) =
2571 scan args "%u %u %d %u %n"
2572 (fun l
n t
h pos
-> l
, n, t
, h, pos
)
2574 let s = String.sub
args pos
(String.length
args - pos
) in
2575 let outline = (s, l
, (n, float t
/. float h, 0.0)) in
2576 begin match state.currently
with
2577 | Outlining outlines
->
2578 state.currently
<- Outlining
(outline :: outlines
)
2580 state.currently
<- Outlining
[outline]
2582 dolog
"invalid outlining state";
2583 logcurrently currently
2586 | "a" :: args :: [] ->
2588 scan args "%u %d %d" (fun n l t
-> n, l
, t
)
2590 state.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
2592 | "info" :: args :: [] ->
2593 state.docinfo
<- (1, args) :: state.docinfo
2595 | "infoend" :: [] ->
2596 state.uioh#infochanged Docinfo
;
2597 state.docinfo
<- List.rev
state.docinfo
2600 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2605 let action = function
2606 | HCprev
-> cbget cb ~
-1
2607 | HCnext
-> cbget cb
1
2608 | HCfirst
-> cbget cb ~
-(cb
.rc)
2609 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2610 and cancel
() = cb
.rc <- rc
2614 let search pattern forward
=
2615 if String.length pattern
> 0
2618 match state.layout with
2621 l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
2623 wcmd "search %d %d %d %d,%s\000"
2624 (btod conf.icase
) pn py (btod forward
) pattern
;
2627 let intentry text key =
2629 if key >= 32 && key < 127
2635 let text = addchar text c in
2639 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2643 let linknentry text key =
2645 if key >= 32 && key < 127
2651 let text = addchar text c in
2655 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2660 if String.length
s > 0
2663 let l = String.length
s in
2664 let rec loop pos
n = if pos
= l then n else
2665 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2666 loop (pos
+1) (n*26 + m)
2669 let rec loop n = function
2672 match getopaque l.pageno with
2673 | None
-> loop n rest
2675 let m = getlinkcount opaque
in
2678 let under = getlink opaque
n in
2681 else loop (n-m) rest
2683 loop n state.layout;
2687 let textentry text key =
2688 if key land 0xff00 = 0xff00
2690 else TEcont
(text ^ toutf8
key)
2693 let reqlayout angle proportional
=
2694 match state.throttle
with
2696 if nogeomcmds state.geomcmds
2697 then state.anchor <- getanchor ();
2698 conf.angle
<- angle
mod 360;
2701 match state.mode
with
2702 | LinkNav
_ -> state.mode
<- View
2705 conf.proportional
<- proportional
;
2706 invalidate "reqlayout"
2707 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2711 let settrim trimmargins trimfuzz
=
2712 if nogeomcmds state.geomcmds
2713 then state.anchor <- getanchor ();
2714 conf.trimmargins
<- trimmargins
;
2715 conf.trimfuzz
<- trimfuzz
;
2716 let x0, y0, x1, y1 = trimfuzz
in
2717 invalidate "settrim"
2719 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2724 match state.throttle
with
2726 let zoom = max
0.01 zoom in
2727 if zoom <> conf.zoom
2729 state.prevzoom
<- conf.zoom;
2731 reshape state.winw
state.winh
;
2732 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2735 | Some
(layout, y, started
) ->
2737 match conf.maxwait
with
2741 let dt = now () -. started
in
2749 let setcolumns mode columns coverA coverB
=
2750 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2754 then showtext '
!'
"split mode doesn't work in bird's eye"
2756 conf.columns
<- Csplit
(-columns
, [||]);
2764 conf.columns
<- Csingle
[||];
2769 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2773 reshape state.winw
state.winh
;
2776 let enterbirdseye () =
2777 let zoom = float conf.thumbw
/. float state.winw
in
2778 let birdseyepageno =
2779 let cy = state.winh
/ 2 in
2783 let rec fold best
= function
2786 let d = cy - (l.pagedispy + l.pagevh/2)
2787 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2788 if abs
d < abs dbest
2795 state.mode
<- Birdseye
(
2796 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2799 conf.presentation
<- false;
2800 conf.interpagespace
<- 10;
2801 conf.hlinks
<- false;
2803 state.mstate
<- Mnone
;
2804 conf.maxwait
<- None
;
2806 match conf.beyecolumns
with
2809 Cmulti
((c, 0, 0), [||])
2810 | None
-> Csingle
[||]
2812 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2815 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2820 reshape state.winw
state.winh
;
2823 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2825 conf.zoom <- c.zoom;
2826 conf.presentation
<- c.presentation
;
2827 conf.interpagespace
<- c.interpagespace
;
2828 conf.maxwait
<- c.maxwait
;
2829 conf.hlinks
<- c.hlinks
;
2830 conf.beyecolumns
<- (
2831 match conf.columns
with
2832 | Cmulti
((c, _, _), _) -> Some
c
2834 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2837 match c.columns
with
2838 | Cmulti
(c, _) -> Cmulti
(c, [||])
2839 | Csingle
_ -> Csingle
[||]
2840 | Csplit
(c, _) -> Csplit
(c, [||])
2845 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2848 reshape state.winw
state.winh
;
2849 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2852 let togglebirdseye () =
2853 match state.mode
with
2854 | Birdseye vals
-> leavebirdseye vals
true
2855 | View
-> enterbirdseye ()
2859 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2860 let pageno = max
0 (pageno - incr
) in
2861 let rec loop = function
2862 | [] -> gotopage1 pageno 0
2863 | l :: _ when l.pageno = pageno ->
2864 if l.pagedispy >= 0 && l.pagey = 0
2865 then G.postRedisplay "upbirdseye"
2866 else gotopage1 pageno 0
2867 | _ :: rest
-> loop rest
2870 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2873 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2874 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2875 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2876 let rec loop = function
2878 let y, h = getpageyh pageno in
2879 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2881 | l :: _ when l.pageno = pageno ->
2882 if l.pagevh != l.pageh
2883 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2884 else G.postRedisplay "downbirdseye"
2885 | _ :: rest
-> loop rest
2890 let optentry mode
_ key =
2891 let btos b = if b then "on" else "off" in
2892 if key >= 32 && key < 127
2894 let c = Char.chr
key in
2898 try conf.scrollstep
<- int_of_string
s with exc
->
2899 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2901 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2906 conf.autoscrollstep
<- int_of_string
s;
2907 if state.autoscroll
<> None
2908 then state.autoscroll
<- Some
conf.autoscrollstep
2910 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2912 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2917 let n, a, b = multicolumns_of_string s in
2918 setcolumns mode
n a b;
2920 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
2922 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2927 let zoom = float (int_of_string
s) /. 100.0 in
2930 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2932 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2937 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2939 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2940 begin match mode
with
2942 leavebirdseye beye
false;
2947 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2949 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2954 Some
(int_of_string
s)
2956 state.text <- Printf.sprintf
"bad integer `%s': %s"
2960 | Some angle
-> reqlayout angle
conf.proportional
2963 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2966 conf.icase
<- not
conf.icase
;
2967 TEdone
("case insensitive search " ^
(btos conf.icase
))
2970 conf.preload <- not
conf.preload;
2972 TEdone
("preload " ^
(btos conf.preload))
2975 conf.verbose
<- not
conf.verbose
;
2976 TEdone
("verbose " ^
(btos conf.verbose
))
2979 conf.debug
<- not
conf.debug
;
2980 TEdone
("debug " ^
(btos conf.debug
))
2983 conf.maxhfit
<- not
conf.maxhfit
;
2984 state.maxy
<- calcheight ();
2985 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2988 conf.crophack
<- not
conf.crophack
;
2989 TEdone
("crophack " ^
btos conf.crophack
)
2993 match conf.maxwait
with
2995 conf.maxwait
<- Some infinity
;
2996 "always wait for page to complete"
2998 conf.maxwait
<- None
;
2999 "show placeholder if page is not ready"
3004 conf.underinfo
<- not
conf.underinfo
;
3005 TEdone
("underinfo " ^
btos conf.underinfo
)
3008 conf.savebmarks
<- not
conf.savebmarks
;
3009 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3015 match state.layout with
3020 conf.interpagespace
<- int_of_string
s;
3021 docolumns conf.columns
;
3022 state.maxy
<- calcheight ();
3023 let y = getpagey pageno in
3026 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3028 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3031 reqlayout conf.angle
(not
conf.proportional
);
3032 TEdone
("proportional display " ^
btos conf.proportional
)
3035 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3036 TEdone
("trim margins " ^
btos conf.trimmargins
)
3039 conf.invert
<- not
conf.invert
;
3040 TEdone
("invert colors " ^
btos conf.invert
)
3044 cbput state.hists
.sel
s;
3047 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3048 textentry, ondone, true)
3051 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3057 class type lvsource
= object
3058 method getitemcount
: int
3059 method getitem
: int -> (string * int)
3060 method hasaction
: int -> bool
3069 method getactive
: int
3070 method getfirst
: int
3071 method getqsearch
: string
3072 method setqsearch
: string -> unit
3076 class virtual lvsourcebase
= object
3077 val mutable m_active
= 0
3078 val mutable m_first
= 0
3079 val mutable m_qsearch
= ""
3080 val mutable m_pan
= 0
3081 method getactive
= m_active
3082 method getfirst
= m_first
3083 method getqsearch
= m_qsearch
3084 method getpan
= m_pan
3085 method setqsearch
s = m_qsearch
<- s
3088 let withoutlastutf8 s =
3089 let len = String.length
s in
3097 let b = Char.code
s.[pos
] in
3098 if b land 0b11000000 = 0b11000000
3103 if Char.code
s.[len-1] land 0x80 = 0
3107 String.sub
s 0 first;
3110 let textentrykeyboard
3111 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3113 if key >= 0xffb0 && key <= 0xffb9
3114 then key - 0xffb0 + 48 else key
3117 state.mode
<- Textentry
(te
, onleave
);
3120 G.postRedisplay "textentrykeyboard enttext";
3122 let histaction cmd
=
3125 | Some
(action, _) ->
3126 state.mode
<- Textentry
(
3127 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3129 G.postRedisplay "textentry histaction"
3132 | 0xff08 -> (* backspace *)
3133 let s = withoutlastutf8 text in
3134 let len = String.length
s in
3135 if cancelonempty
&& len = 0
3138 G.postRedisplay "textentrykeyboard after cancel";
3141 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3144 | 0xff0d | 0xff8d -> (* (kp) enter *)
3147 G.postRedisplay "textentrykeyboard after confirm"
3149 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3150 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3151 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3152 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3154 | 0xff1b -> (* escape*)
3155 if String.length
text = 0
3157 begin match opthist
with
3159 | Some
(_, onhistcancel
) -> onhistcancel
()
3163 G.postRedisplay "textentrykeyboard after cancel2"
3166 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3169 | 0xff9f | 0xffff -> () (* delete *)
3172 && key land 0xff00 != 0xff00 (* keyboard *)
3173 && key land 0xfe00 != 0xfe00 (* xkb *)
3174 && key land 0xfd00 != 0xfd00 (* 3270 *)
3176 begin match onkey
text key with
3180 G.postRedisplay "textentrykeyboard after confirm2";
3183 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3187 G.postRedisplay "textentrykeyboard after cancel3"
3190 state.mode
<- Textentry
(te
, onleave
);
3191 G.postRedisplay "textentrykeyboard switch";
3195 vlog "unhandled key %s" (Wsi.keyname
key)
3198 let firstof first active
=
3199 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3200 then max
0 (active
- (fstate.maxrows
/2))
3204 let calcfirst first active
=
3207 let rows = active
- first in
3208 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3212 let scrollph y maxy
=
3213 let sh = (float (maxy
+ state.winh
) /. float state.winh
) in
3214 let sh = float state.winh
/. sh in
3215 let sh = max
sh (float conf.scrollh
) in
3220 else float y /. float maxy
3222 let position = (float state.winh
-. sh) *. percent in
3225 if position +. sh > float state.winh
3226 then float state.winh
-. sh
3232 let coe s = (s :> uioh
);;
3234 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3236 val m_pan
= source#getpan
3237 val m_first
= source#getfirst
3238 val m_active
= source#getactive
3239 val m_qsearch
= source#getqsearch
3240 val m_prev_uioh
= state.uioh
3242 method private elemunder
y =
3243 let n = y / (fstate.fontsize
+1) in
3244 if m_first
+ n < source#getitemcount
3246 if source#hasaction
(m_first
+ n)
3247 then Some
(m_first
+ n)
3254 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3255 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3256 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3257 GlDraw.color
(1., 1., 1.);
3258 Gl.enable `texture_2d
;
3259 let fs = fstate.fontsize
in
3261 let ww = fstate.wwidth
in
3262 let tabw = 30.0*.ww in
3263 let itemcount = source#getitemcount
in
3265 if (row - m_first
) > fstate.maxrows
3268 if row >= 0 && row < itemcount
3270 let (s, level
) = source#getitem
row in
3271 let y = (row - m_first
) * nfs in
3272 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3275 Gl.disable `texture_2d
;
3276 GlDraw.polygon_mode `both `line
;
3277 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3278 GlDraw.rect (1., float (y + 1))
3279 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3280 GlDraw.polygon_mode `both `fill
;
3281 GlDraw.color
(1., 1., 1.);
3282 Gl.enable `texture_2d
;
3285 let drawtabularstring s =
3286 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3289 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3292 let len = String.length
s - tabpos - 1 in
3293 let s1 = String.sub
s 0 tabpos
3294 and s2
= String.sub
s (tabpos + 1) len in
3295 let nx = drawstr x s1 in
3297 let x = x +. (max
tabw sw) in
3304 let _ = drawtabularstring s in
3311 Gl.disable `texture_2d
;
3313 method updownlevel incr
=
3314 let len = source#getitemcount
in
3316 if m_active
>= 0 && m_active
< len
3317 then snd
(source#getitem m_active
)
3321 if i
= len then i
-1 else if i
= -1 then 0 else
3322 let _, l = source#getitem i
in
3323 if l != curlevel then i
else flow (i
+incr
)
3325 let active = flow m_active
in
3326 let first = calcfirst m_first
active in
3327 G.postRedisplay "outline updownlevel";
3328 {< m_active
= active; m_first
= first >}
3330 method private key1
key mask
=
3331 let set1 active first qsearch
=
3332 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3334 let search active pattern incr
=
3337 if n >= 0 && n < source#getitemcount
3339 let s, _ = source#getitem
n in
3341 (try ignore
(Str.search_forward
re s 0); true
3342 with Not_found
-> false)
3344 else loop (n + incr
)
3351 let re = Str.regexp_case_fold pattern
in
3357 let itemcount = source#getitemcount
in
3358 let find start incr
=
3360 if i
= -1 || i
= itemcount
3363 if source#hasaction i
3365 else find (i
+ incr
)
3370 let set active first =
3371 let first = bound first 0 (itemcount - fstate.maxrows
) in
3373 coe {< m_active
= active; m_first
= first >}
3376 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3378 let incr1 = if incr
> 0 then 1 else -1 in
3379 if isvisible m_first m_active
3382 let next = m_active
+ incr
in
3384 if next < 0 || next >= itemcount
3386 else find next incr1
3388 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3394 let first = m_first
+ incr
in
3395 let first = bound first 0 (itemcount - 1) in
3397 let next = m_active
+ incr
in
3398 let next = bound next 0 (itemcount - 1) in
3401 let active = if next = -1 then m_active
else next in
3404 let first = min
next m_first
in
3406 if abs
(next - first) > fstate.maxrows
3412 let first = m_first
+ incr
in
3413 let first = bound first 0 (itemcount - 1) in
3415 let next = m_active
+ incr
in
3416 let next = bound next 0 (itemcount - 1) in
3417 let next = find next incr1 in
3419 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3421 let active = if m_active
= -1 then next else m_active
in
3426 if isvisible first active
3432 G.postRedisplay "listview navigate";
3436 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3437 let incr = if key = 0x72 then -1 else 1 in
3439 match search (m_active
+ incr) m_qsearch
incr with
3441 state.text <- m_qsearch ^
" [not found]";
3444 state.text <- m_qsearch
;
3445 active, firstof m_first
active
3447 G.postRedisplay "listview ctrl-r/s";
3448 set1 active first m_qsearch
;
3450 | 0xff08 -> (* backspace *)
3451 if String.length m_qsearch
= 0
3454 let qsearch = withoutlastutf8 m_qsearch
in
3455 let len = String.length
qsearch in
3459 G.postRedisplay "listview empty qsearch";
3460 set1 m_active m_first
"";
3464 match search m_active
qsearch ~
-1 with
3466 state.text <- qsearch ^
" [not found]";
3469 state.text <- qsearch;
3470 active, firstof m_first
active
3472 G.postRedisplay "listview backspace qsearch";
3473 set1 active first qsearch
3476 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3477 let pattern = m_qsearch ^ toutf8
key in
3479 match search m_active
pattern 1 with
3481 state.text <- pattern ^
" [not found]";
3484 state.text <- pattern;
3485 active, firstof m_first
active
3487 G.postRedisplay "listview qsearch add";
3488 set1 active first pattern;
3490 | 0xff1b -> (* escape *)
3492 if String.length m_qsearch
= 0
3494 G.postRedisplay "list view escape";
3497 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3499 | None
-> m_prev_uioh
3504 G.postRedisplay "list view kill qsearch";
3505 source#setqsearch
"";
3506 coe {< m_qsearch
= "" >}
3509 | 0xff0d | 0xff8d -> (* (kp) enter *)
3511 let self = {< m_qsearch
= "" >} in
3512 source#setqsearch
"";
3514 G.postRedisplay "listview enter";
3515 if m_active
>= 0 && m_active
< source#getitemcount
3517 source#exit
(coe self) false m_active m_first m_pan
"";
3520 source#exit
(coe self) true m_active m_first m_pan
"";
3523 begin match opt with
3524 | None
-> m_prev_uioh
3528 | 0xff9f | 0xffff -> (* (kp) delete *)
3531 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3532 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3533 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3534 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3536 | 0xff53 | 0xff98 -> (* (kp) right *)
3538 G.postRedisplay "listview right";
3539 coe {< m_pan
= m_pan
- 1 >}
3541 | 0xff51 | 0xff96 -> (* (kp) left *)
3543 G.postRedisplay "listview left";
3544 coe {< m_pan
= m_pan
+ 1 >}
3546 | 0xff50 | 0xff95 -> (* (kp) home *)
3547 let active = find 0 1 in
3548 G.postRedisplay "listview home";
3551 | 0xff57 | 0xff9c -> (* (kp) end *)
3552 let first = max
0 (itemcount - fstate.maxrows
) in
3553 let active = find (itemcount - 1) ~
-1 in
3554 G.postRedisplay "listview end";
3557 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3561 dolog
"listview unknown key %#x" key; coe self
3563 method key key mask
=
3564 match state.mode
with
3565 | Textentry te
-> textentrykeyboard key mask te
; coe self
3566 | _ -> self#key1
key mask
3568 method button button down
x y _ =
3571 | 1 when x > state.winw
- conf.scrollbw
->
3572 G.postRedisplay "listview scroll";
3575 let _, position, sh = self#
scrollph in
3576 if y > truncate
position && y < truncate
(position +. sh)
3578 state.mstate
<- Mscrolly
;
3582 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3583 let first = truncate
(s *. float source#getitemcount
) in
3584 let first = min source#getitemcount
first in
3585 Some
(coe {< m_first
= first; m_active
= first >})
3587 state.mstate
<- Mnone
;
3590 | 1 when not down
->
3591 begin match self#elemunder
y with
3593 G.postRedisplay "listview click";
3595 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3599 | n when (n == 4 || n == 5) && not down
->
3600 let len = source#getitemcount
in
3602 if n = 5 && m_first
+ fstate.maxrows
>= len
3606 let first = m_first
+ (if n == 4 then -1 else 1) in
3607 bound first 0 (len - 1)
3609 G.postRedisplay "listview wheel";
3610 Some
(coe {< m_first
= first >})
3611 | n when (n = 6 || n = 7) && not down
->
3612 let inc = m_first
+ (if n = 7 then -1 else 1) in
3613 G.postRedisplay "listview hwheel";
3614 Some
(coe {< m_pan
= m_pan
+ inc >})
3619 | None
-> m_prev_uioh
3623 match state.mstate
with
3625 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3626 let first = truncate
(s *. float source#getitemcount
) in
3627 let first = min source#getitemcount
first in
3628 G.postRedisplay "listview motion";
3629 coe {< m_first
= first; m_active
= first >}
3632 method pmotion
x y =
3633 if x < state.winw
- conf.scrollbw
3636 match self#elemunder
y with
3637 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3638 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3642 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3647 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3651 method infochanged
_ = ()
3653 method scrollpw
= (0, 0.0, 0.0)
3655 let nfs = fstate.fontsize
+ 1 in
3656 let y = m_first
* nfs in
3657 let itemcount = source#getitemcount
in
3658 let maxi = max
0 (itemcount - fstate.maxrows
) in
3659 let maxy = maxi * nfs in
3660 let p, h = scrollph y maxy in
3663 method modehash
= modehash
3666 class outlinelistview ~source
=
3669 ~source
:(source
:> lvsource
)
3671 ~modehash
:(findkeyhash conf "outline")
3674 method key key mask
=
3675 let calcfirst first active =
3678 let rows = active - first in
3680 if String.length
state.text = 0
3682 else fstate.maxrows - 2
3684 if rows > maxrows then active - maxrows else first
3688 let active = m_active
+ incr in
3689 let active = bound active 0 (source#getitemcount
- 1) in
3690 let first = calcfirst m_first
active in
3691 G.postRedisplay "outline navigate";
3692 coe {< m_active
= active; m_first
= first >}
3694 let ctrl = Wsi.withctrl mask
in
3696 | 110 when ctrl -> (* ctrl-n *)
3697 source#narrow m_qsearch
;
3698 G.postRedisplay "outline ctrl-n";
3699 coe {< m_first
= 0; m_active
= 0 >}
3701 | 117 when ctrl -> (* ctrl-u *)
3703 G.postRedisplay "outline ctrl-u";
3705 coe {< m_first
= 0; m_active
= 0 >}
3707 | 108 when ctrl -> (* ctrl-l *)
3708 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3709 G.postRedisplay "outline ctrl-l";
3710 coe {< m_first
= first >}
3712 | 0xff9f | 0xffff -> (* (kp) delete *)
3713 source#remove m_active
;
3714 G.postRedisplay "outline delete";
3715 let active = max
0 (m_active
-1) in
3716 coe {< m_first
= firstof m_first
active;
3717 m_active
= active >}
3719 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3720 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3721 | 0xff55 | 0xff9a -> (* (kp) prior *)
3722 navigate ~
-(fstate.maxrows)
3723 | 0xff56 | 0xff9b -> (* (kp) next *)
3724 navigate fstate.maxrows
3726 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3730 G.postRedisplay "outline ctrl right";
3731 {< m_pan
= m_pan
+ 1 >}
3733 else self#updownlevel
1
3737 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3741 G.postRedisplay "outline ctrl left";
3742 {< m_pan
= m_pan
- 1 >}
3744 else self#updownlevel ~
-1
3748 | 0xff50 | 0xff95 -> (* (kp) home *)
3749 G.postRedisplay "outline home";
3750 coe {< m_first
= 0; m_active
= 0 >}
3752 | 0xff57 | 0xff9c -> (* (kp) end *)
3753 let active = source#getitemcount
- 1 in
3754 let first = max
0 (active - fstate.maxrows) in
3755 G.postRedisplay "outline end";
3756 coe {< m_active
= active; m_first
= first >}
3758 | _ -> super#
key key mask
3761 let outlinesource usebookmarks
=
3764 inherit lvsourcebase
3765 val mutable m_items
= empty
3766 val mutable m_orig_items
= empty
3767 val mutable m_prev_items
= empty
3768 val mutable m_narrow_pattern
= ""
3769 val mutable m_hadremovals
= false
3771 method getitemcount
=
3772 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3775 if n == Array.length m_items
&& m_hadremovals
3777 ("[Confirm removal]", 0)
3779 let s, n, _ = m_items
.(n) in
3782 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3783 ignore
(uioh
, first, qsearch);
3784 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3786 if String.length m_narrow_pattern
= 0
3792 if not
confrimremoval
3794 let _, _, anchor = m_items
.(active) in
3795 gotoghyll (getanchory anchor);
3799 state.bookmarks
<- Array.to_list m_items
;
3800 m_orig_items
<- m_items
;
3803 else m_items
<- items;
3807 method hasaction
_ = true
3810 if Array.length m_items
!= Array.length m_orig_items
3811 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3814 method narrow
pattern =
3815 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3819 let rec loop accu n =
3822 m_narrow_pattern
<- pattern;
3823 m_items
<- Array.of_list
accu
3826 let (s, _, _) as o = m_items
.(n) in
3828 if (try ignore
(Str.search_forward
re s 0); true
3829 with Not_found
-> false)
3835 loop [] (Array.length m_items
- 1)
3840 then Array.of_list
state.bookmarks
3843 m_items
<- m_orig_items
3848 if m >= 0 && m < Array.length m_items
3850 m_hadremovals
<- true;
3851 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3852 let n = if n >= m then n+1 else n in
3857 method reset
anchor items =
3858 m_hadremovals
<- false;
3859 if m_orig_items
== empty || m_prev_items
!= items
3861 m_orig_items
<- items;
3862 if String.length m_narrow_pattern
= 0
3863 then m_items
<- items;
3865 m_prev_items
<- items;
3866 let rely = getanchory anchor in
3868 let rec loop n best bestd
=
3869 if n = Array.length m_items
3872 let (_, _, anchor) = m_items
.(n) in
3873 let orely = getanchory anchor in
3874 let d = abs
(orely - rely) in
3877 else loop (n+1) best bestd
3882 m_first
<- firstof m_first
active
3886 let enterselector usebookmarks
=
3887 let source = outlinesource usebookmarks
in
3891 then Array.of_list
state.bookmarks
3894 if Array.length
outlines = 0
3896 showtext ' ' errmsg
;
3899 state.text <- source#greetmsg
;
3900 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3901 let anchor = getanchor () in
3902 source#reset
anchor outlines;
3903 state.uioh
<- coe (new outlinelistview ~
source);
3904 G.postRedisplay "enter selector";
3908 let enteroutlinemode =
3909 let f = enterselector false in
3910 fun ()-> f "Document has no outline";
3913 let enterbookmarkmode =
3914 let f = enterselector true in
3915 fun () -> f "Document has no bookmarks (yet)";
3918 let color_of_string s =
3919 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
3920 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
3924 let color_to_string (r, g, b) =
3925 let r = truncate
(r *. 256.0)
3926 and g = truncate
(g *. 256.0)
3927 and b = truncate
(b *. 256.0) in
3928 Printf.sprintf
"%d/%d/%d" r g b
3931 let irect_of_string s =
3932 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3935 let irect_to_string (x0,y0,x1,y1) =
3936 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3939 let makecheckers () =
3940 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3942 converted by Issac Trotts. July 25, 2002 *)
3943 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3944 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3945 let id = GlTex.gen_texture
() in
3946 GlTex.bind_texture `texture_2d
id;
3947 GlPix.store
(`unpack_alignment
1);
3948 GlTex.image2d
image;
3949 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3950 [ `mag_filter `nearest
; `min_filter `nearest
];
3954 let setcheckers enabled
=
3955 match state.texid
with
3957 if enabled
then state.texid
<- Some
(makecheckers ())
3962 GlTex.delete_texture texid
;
3963 state.texid
<- None
;
3967 let int_of_string_with_suffix s =
3968 let l = String.length
s in
3972 let suffix = Char.lowercase
s.[l-1] in
3974 | 'k'
-> String.sub
s 0 (l-1), 10
3975 | '
m'
-> String.sub
s 0 (l-1), 20
3976 | '
g'
-> String.sub
s 0 (l-1), 30
3980 let n = int_of_string
s1 in
3981 let m = n lsl shift
in
3983 then raise
(Failure
"value too large")
3987 let string_with_suffix_of_int n =
3992 if n land ((1 lsl 30) - 1) = 0
3995 if n land ((1 lsl 20) - 1) = 0
3998 if n land ((1 lsl 10) - 1) = 0
4005 let h = n mod 1000 in
4008 then string_of_int
h ^
s
4010 let s = Printf.sprintf
"_%03d%s" h s in
4017 let defghyllscroll = (40, 8, 32);;
4018 let ghyllscroll_of_string s =
4019 let (n, a, b) as nab
=
4022 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4024 if n <= a || n <= b || a >= b
4025 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4029 let ghyllscroll_to_string ((n, a, b) as nab
) =
4030 if nab
= defghyllscroll
4032 else Printf.sprintf
"%d,%d,%d" n a b;
4035 let describe_location () =
4036 let fn = page_of_y state.y in
4037 let ln = page_of_y (state.y + state.winh
- state.hscrollh) in
4038 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4042 else (100. *. (float state.y /. float maxy))
4046 Printf.sprintf
"page %d of %d [%.2f%%]"
4047 (fn+1) state.pagecount
percent
4050 "pages %d-%d of %d [%.2f%%]"
4051 (fn+1) (ln+1) state.pagecount
percent
4054 let setpresentationmode v
=
4055 let n = page_of_y state.y in
4056 state.anchor <- (n, 0.0, 1.0);
4057 conf.presentation
<- v
;
4058 if conf.presentation
4060 if not
conf.scrollbarinpm
4061 then state.scrollw
<- 0;
4063 else state.scrollw
<- conf.scrollbw
;
4068 let btos b = if b then "\xe2\x88\x9a" else "" in
4069 let showextended = ref false in
4070 let leave mode
= function
4071 | Confirm
-> state.mode
<- mode
4072 | Cancel
-> state.mode
<- mode
in
4075 val mutable m_first_time
= true
4076 val mutable m_l
= []
4077 val mutable m_a
= [||]
4078 val mutable m_prev_uioh
= nouioh
4079 val mutable m_prev_mode
= View
4081 inherit lvsourcebase
4083 method reset prev_mode prev_uioh
=
4084 m_a
<- Array.of_list
(List.rev m_l
);
4086 m_prev_mode
<- prev_mode
;
4087 m_prev_uioh
<- prev_uioh
;
4091 if n >= Array.length m_a
4095 | _, _, _, Action
_ -> m_active
<- n
4099 m_first_time
<- false;
4102 method int name get
set =
4104 (name
, `
int get
, 1, Action
(
4107 try set (int_of_string
s)
4109 state.text <- Printf.sprintf
"bad integer `%s': %s"
4113 let te = name ^
": ", "", None
, intentry, ondone, true in
4114 state.mode
<- Textentry
(te, leave m_prev_mode
);
4118 method int_with_suffix name get
set =
4120 (name
, `intws get
, 1, Action
(
4123 try set (int_of_string_with_suffix s)
4125 state.text <- Printf.sprintf
"bad integer `%s': %s"
4130 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4132 state.mode
<- Textentry
(te, leave m_prev_mode
);
4136 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4138 (name
, `
bool (btos, get
), offset
, Action
(
4145 method color name get
set =
4147 (name
, `color get
, 1, Action
(
4149 let invalid = (nan
, nan
, nan
) in
4152 try color_of_string s
4154 state.text <- Printf.sprintf
"bad color `%s': %s"
4161 let te = name ^
": ", "", None
, textentry, ondone, true in
4162 state.text <- color_to_string (get
());
4163 state.mode
<- Textentry
(te, leave m_prev_mode
);
4167 method string name get
set =
4169 (name
, `
string get
, 1, Action
(
4171 let ondone s = set s in
4172 let te = name ^
": ", "", None
, textentry, ondone, true in
4173 state.mode
<- Textentry
(te, leave m_prev_mode
);
4177 method colorspace name get
set =
4179 (name
, `
string get
, 1, Action
(
4182 let vals = [| "rgb"; "bgr"; "gray" |] in
4184 inherit lvsourcebase
4187 m_active
<- int_of_colorspace conf.colorspace
;
4190 method getitemcount
= Array.length
vals
4191 method getitem
n = (vals.(n), 0)
4192 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4193 ignore
(uioh
, first, pan
, qsearch);
4194 if not cancel
then set active;
4196 method hasaction
_ = true
4200 let modehash = findkeyhash conf "info" in
4201 coe (new listview ~
source ~trusted
:true ~
modehash)
4204 method caption
s offset
=
4205 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4207 method caption2
s f offset
=
4208 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4210 method getitemcount
= Array.length m_a
4213 let tostr = function
4214 | `
int f -> string_of_int
(f ())
4215 | `intws
f -> string_with_suffix_of_int (f ())
4217 | `color
f -> color_to_string (f ())
4218 | `
bool (btos, f) -> btos (f ())
4221 let name, t
, offset
, _ = m_a
.(n) in
4222 ((let s = tostr t
in
4223 if String.length
s > 0
4224 then Printf.sprintf
"%s\t%s" name s
4228 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4232 m_qsearch
<- qsearch;
4234 match m_a
.(active) with
4235 | _, _, _, Action
f -> f uioh
4247 method hasaction
n =
4249 | _, _, _, Action
_ -> true
4253 let rec fillsrc prevmode prevuioh
=
4254 let sep () = src#caption
"" 0 in
4255 let colorp name get
set =
4257 (fun () -> color_to_string (get
()))
4260 let c = color_of_string v in
4263 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4266 let oldmode = state.mode
in
4267 let birdseye = isbirdseye state.mode
in
4269 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4271 src#
bool "presentation mode"
4272 (fun () -> conf.presentation
)
4273 (fun v -> setpresentationmode v);
4275 src#
bool "ignore case in searches"
4276 (fun () -> conf.icase
)
4277 (fun v -> conf.icase
<- v);
4280 (fun () -> conf.preload)
4281 (fun v -> conf.preload <- v);
4283 src#
bool "highlight links"
4284 (fun () -> conf.hlinks
)
4285 (fun v -> conf.hlinks
<- v);
4287 src#
bool "under info"
4288 (fun () -> conf.underinfo
)
4289 (fun v -> conf.underinfo
<- v);
4291 src#
bool "persistent bookmarks"
4292 (fun () -> conf.savebmarks
)
4293 (fun v -> conf.savebmarks
<- v);
4295 src#
bool "proportional display"
4296 (fun () -> conf.proportional
)
4297 (fun v -> reqlayout conf.angle
v);
4299 src#
bool "trim margins"
4300 (fun () -> conf.trimmargins
)
4301 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4303 src#
bool "persistent location"
4304 (fun () -> conf.jumpback
)
4305 (fun v -> conf.jumpback
<- v);
4308 src#
int "inter-page space"
4309 (fun () -> conf.interpagespace
)
4311 conf.interpagespace
<- n;
4312 docolumns conf.columns
;
4314 match state.layout with
4319 state.maxy <- calcheight ();
4320 let y = getpagey pageno in
4325 (fun () -> conf.pagebias
)
4326 (fun v -> conf.pagebias
<- v);
4328 src#
int "scroll step"
4329 (fun () -> conf.scrollstep
)
4330 (fun n -> conf.scrollstep
<- n);
4332 src#
int "horizontal scroll step"
4333 (fun () -> conf.hscrollstep
)
4334 (fun v -> conf.hscrollstep
<- v);
4336 src#
int "auto scroll step"
4338 match state.autoscroll
with
4340 | _ -> conf.autoscrollstep
)
4342 if state.autoscroll
<> None
4343 then state.autoscroll
<- Some
n;
4344 conf.autoscrollstep
<- n);
4347 (fun () -> truncate
(conf.zoom *. 100.))
4348 (fun v -> setzoom ((float v) /. 100.));
4351 (fun () -> conf.angle
)
4352 (fun v -> reqlayout v conf.proportional
);
4354 src#
int "scroll bar width"
4355 (fun () -> state.scrollw
)
4359 reshape state.winw
state.winh
;
4362 src#
int "scroll handle height"
4363 (fun () -> conf.scrollh
)
4364 (fun v -> conf.scrollh
<- v;);
4366 src#
int "thumbnail width"
4367 (fun () -> conf.thumbw
)
4369 conf.thumbw
<- min
4096 v;
4372 leavebirdseye beye
false;
4377 let mode = state.mode in
4378 src#
string "columns"
4380 match conf.columns
with
4382 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4383 | Csplit
(count
, _) -> "-" ^ string_of_int count
4386 let n, a, b = multicolumns_of_string v in
4387 setcolumns mode n a b);
4390 src#caption
"Presentation mode" 0;
4391 src#
bool "scrollbar visible"
4392 (fun () -> conf.scrollbarinpm
)
4394 if v != conf.scrollbarinpm
4396 conf.scrollbarinpm
<- v;
4397 if conf.presentation
4399 state.scrollw
<- if v then conf.scrollbw
else 0;
4400 reshape state.winw
state.winh
;
4406 src#caption
"Pixmap cache" 0;
4407 src#int_with_suffix
"size (advisory)"
4408 (fun () -> conf.memlimit
)
4409 (fun v -> conf.memlimit
<- v);
4412 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4413 (string_with_suffix_of_int state.memused
)
4414 (Hashtbl.length
state.tilemap
)) 1;
4417 src#caption
"Layout" 0;
4418 src#caption2
"Dimension"
4420 Printf.sprintf
"%dx%d (virtual %dx%d)"
4421 state.winw
state.winh
4426 src#caption2
"Position" (fun () ->
4427 Printf.sprintf
"%dx%d" state.x state.y
4430 src#caption2
"Position" (fun () -> describe_location ()) 1
4434 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4435 "Save these parameters as global defaults at exit"
4436 (fun () -> conf.bedefault
)
4437 (fun v -> conf.bedefault
<- v)
4441 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4442 src#
bool ~offset
:0 ~
btos "Extended parameters"
4443 (fun () -> !showextended)
4444 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4448 (fun () -> conf.checkers
)
4449 (fun v -> conf.checkers
<- v; setcheckers v);
4450 src#
bool "update cursor"
4451 (fun () -> conf.updatecurs
)
4452 (fun v -> conf.updatecurs
<- v);
4454 (fun () -> conf.verbose
)
4455 (fun v -> conf.verbose
<- v);
4456 src#
bool "invert colors"
4457 (fun () -> conf.invert
)
4458 (fun v -> conf.invert
<- v);
4460 (fun () -> conf.maxhfit
)
4461 (fun v -> conf.maxhfit
<- v);
4462 src#
bool "redirect stderr"
4463 (fun () -> conf.redirectstderr)
4464 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4465 src#
string "uri launcher"
4466 (fun () -> conf.urilauncher
)
4467 (fun v -> conf.urilauncher
<- v);
4468 src#
string "path launcher"
4469 (fun () -> conf.pathlauncher
)
4470 (fun v -> conf.pathlauncher
<- v);
4471 src#
string "tile size"
4472 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4475 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4476 conf.tilew
<- max
64 w;
4477 conf.tileh
<- max
64 h;
4480 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4483 src#
int "texture count"
4484 (fun () -> conf.texcount
)
4487 then conf.texcount
<- v
4488 else showtext '
!'
" Failed to set texture count please retry later"
4490 src#
int "slice height"
4491 (fun () -> conf.sliceheight
)
4493 conf.sliceheight
<- v;
4494 wcmd "sliceh %d" conf.sliceheight
;
4496 src#
int "anti-aliasing level"
4497 (fun () -> conf.aalevel
)
4499 conf.aalevel
<- bound v 0 8;
4500 state.anchor <- getanchor ();
4501 opendoc state.path
state.password
;
4503 src#
string "page scroll scaling factor"
4504 (fun () -> string_of_float
conf.pgscale)
4507 let s = float_of_string
v in
4510 state.text <- Printf.sprintf
4511 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4514 src#
int "ui font size"
4515 (fun () -> fstate.fontsize
)
4516 (fun v -> setfontsize (bound v 5 100));
4517 src#
int "hint font size"
4518 (fun () -> conf.hfsize
)
4519 (fun v -> conf.hfsize
<- bound v 5 100);
4520 colorp "background color"
4521 (fun () -> conf.bgcolor
)
4522 (fun v -> conf.bgcolor
<- v);
4523 src#
bool "crop hack"
4524 (fun () -> conf.crophack
)
4525 (fun v -> conf.crophack
<- v);
4526 src#
string "trim fuzz"
4527 (fun () -> irect_to_string conf.trimfuzz
)
4530 conf.trimfuzz
<- irect_of_string v;
4532 then settrim true conf.trimfuzz
;
4534 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4536 src#
string "throttle"
4538 match conf.maxwait
with
4539 | None
-> "show place holder if page is not ready"
4542 then "wait for page to fully render"
4544 "wait " ^ string_of_float
time
4545 ^
" seconds before showing placeholder"
4549 let f = float_of_string
v in
4551 then conf.maxwait
<- None
4552 else conf.maxwait
<- Some
f
4554 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4556 src#
string "ghyll scroll"
4558 match conf.ghyllscroll
with
4560 | Some nab
-> ghyllscroll_to_string nab
4565 if String.length
v = 0
4567 else Some
(ghyllscroll_of_string v)
4569 conf.ghyllscroll
<- gs
4571 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4573 src#
string "selection command"
4574 (fun () -> conf.selcmd
)
4575 (fun v -> conf.selcmd
<- v);
4576 src#
string "synctex command"
4577 (fun () -> conf.stcmd
)
4578 (fun v -> conf.stcmd
<- v);
4579 src#colorspace
"color space"
4580 (fun () -> colorspace_to_string conf.colorspace
)
4582 conf.colorspace
<- colorspace_of_int v;
4589 (fun () -> conf.usepbo
)
4590 (fun v -> conf.usepbo
<- v);
4591 src#
bool "mouse wheel scrolls pages"
4592 (fun () -> conf.wheelbypage
)
4593 (fun v -> conf.wheelbypage
<- v);
4597 src#caption
"Document" 0;
4598 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4599 src#caption2
"Pages"
4600 (fun () -> string_of_int
state.pagecount
) 1;
4601 src#caption2
"Dimensions"
4602 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4606 src#caption
"Trimmed margins" 0;
4607 src#caption2
"Dimensions"
4608 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4612 src#caption
"OpenGL" 0;
4613 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4614 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4615 src#reset prevmode prevuioh
;
4619 let prevmode = state.mode
4620 and prevuioh
= state.uioh in
4621 fillsrc prevmode prevuioh
;
4622 let source = (src :> lvsource
) in
4623 let modehash = findkeyhash conf "info" in
4624 state.uioh <- coe (object (self)
4625 inherit listview ~
source ~trusted
:true ~
modehash as super
4626 val mutable m_prevmemused
= 0
4627 method infochanged
= function
4629 if m_prevmemused
!= state.memused
4631 m_prevmemused
<- state.memused
;
4632 G.postRedisplay "memusedchanged";
4634 | Pdim
-> G.postRedisplay "pdimchanged"
4635 | Docinfo
-> fillsrc prevmode prevuioh
4637 method key key mask
=
4638 if not
(Wsi.withctrl mask
)
4641 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4642 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4643 | _ -> super#
key key mask
4644 else super#
key key mask
4646 G.postRedisplay "info";
4652 inherit lvsourcebase
4653 method getitemcount
= Array.length
state.help
4655 let s, l, _ = state.help
.(n) in
4658 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4662 m_qsearch
<- qsearch;
4663 match state.help
.(active) with
4664 | _, _, Action
f -> Some
(f uioh)
4674 method hasaction
n =
4675 match state.help
.(n) with
4676 | _, _, Action
_ -> true
4683 let modehash = findkeyhash conf "help" in
4684 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4685 G.postRedisplay "help";
4690 let re = Str.regexp
"[\r\n]" in
4692 inherit lvsourcebase
4693 val mutable m_items
= [||]
4695 method getitemcount
= 1 + Array.length m_items
4700 else m_items
.(n-1), 0
4702 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4707 then Buffer.clear
state.errmsgs
;
4708 m_qsearch
<- qsearch;
4715 method hasaction
n =
4719 state.newerrmsgs
<- false;
4720 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4721 m_items
<- Array.of_list
l
4729 let source = (msgsource :> lvsource
) in
4730 let modehash = findkeyhash conf "listview" in
4731 state.uioh <- coe (object
4732 inherit listview ~
source ~trusted
:false ~
modehash as super
4735 then msgsource#reset
;
4738 G.postRedisplay "msgs";
4741 let quickbookmark ?title
() =
4742 match state.layout with
4748 let sec = Unix.gettimeofday
() in
4749 let tm = Unix.localtime
sec in
4750 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4754 (tm.Unix.tm_year
+ 1900)
4757 | Some
title -> title
4759 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4766 let setautoscrollspeed step goingdown
=
4767 let incr = max
1 ((abs step
) / 2) in
4768 let incr = if goingdown
then incr else -incr in
4769 let astep = step
+ incr in
4770 state.autoscroll
<- Some
astep;
4773 let gotounder = function
4774 | Ulinkgoto
(pageno, top) ->
4778 gotopage1 pageno top;
4784 | Uremote
(filename
, pageno) ->
4786 if Sys.file_exists filename
4789 let dir = Filename.dirname
state.path in
4790 let path = Filename.concat
dir filename
in
4791 if Sys.file_exists
path
4795 if String.length
path > 0
4797 let anchor = getanchor () in
4798 let ranchor = state.path, state.password
, anchor in
4799 state.anchor <- (pageno, 0.0, 0.0);
4800 state.ranchors
<- ranchor :: state.ranchors
;
4803 else showtext '
!'
("Could not find " ^ filename
)
4805 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4809 match conf.columns
with
4811 | _ -> state.x != 0 || conf.zoom > 1.0
4814 let existsinrow pageno (columns
, coverA
, coverB
) p =
4815 let last = ((pageno - coverA
) mod columns
) + columns
in
4816 let rec any = function
4819 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4823 then (if l.pageno = last then false else any rest
)
4831 match state.layout with
4833 let pageno = page_of_y state.y in
4834 gotoghyll (getpagey (pageno+1))
4836 match conf.columns
with
4838 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4840 let y = clamp (pgscale state.winh
) in
4843 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4844 gotoghyll (getpagey pageno)
4845 | Cmulti
((c, _, _) as cl, _) ->
4846 if conf.presentation
4847 && (existsinrow l.pageno cl
4848 (fun l -> l.pageh
> l.pagey + l.pagevh))
4850 let y = clamp (pgscale state.winh
) in
4853 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4854 gotoghyll (getpagey pageno)
4856 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4858 let pagey, pageh
= getpageyh l.pageno in
4859 let pagey = pagey + pageh
* l.pagecol
in
4860 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4861 gotoghyll (pagey + pageh
+ ips)
4865 match state.layout with
4867 let pageno = page_of_y state.y in
4868 gotoghyll (getpagey (pageno-1))
4870 match conf.columns
with
4872 if conf.presentation
&& l.pagey != 0
4874 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4876 let pageno = max
0 (l.pageno-1) in
4877 gotoghyll (getpagey pageno)
4878 | Cmulti
((c, _, coverB
) as cl, _) ->
4879 if conf.presentation
&&
4880 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4882 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4885 if l.pageno = state.pagecount
- coverB
4889 let pageno = max
0 (l.pageno-decr) in
4890 gotoghyll (getpagey pageno)
4898 let pageno = max
0 (l.pageno-1) in
4899 let pagey, pageh
= getpageyh pageno in
4902 let pagey, pageh
= getpageyh l.pageno in
4903 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4908 let viewkeyboard key mask
=
4910 let mode = state.mode in
4911 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4914 G.postRedisplay "view:enttext"
4916 let ctrl = Wsi.withctrl mask
in
4918 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4924 | 0xff63 -> (* insert *)
4925 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4927 state.mode <- LinkNav
(Ltgendir
0);
4930 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4932 | 0xff1b | 113 -> (* escape / q *)
4933 begin match state.mstate
with
4935 state.mstate
<- Mnone
;
4936 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4937 G.postRedisplay "kill zoom rect";
4939 begin match state.mode with
4942 G.postRedisplay "esc leave linknav"
4944 match state.ranchors
with
4946 | (path, password
, anchor) :: rest
->
4947 state.ranchors
<- rest
;
4948 state.anchor <- anchor;
4949 opendoc path password
4953 | 0xff08 -> (* backspace *)
4954 gotoghyll (getnav ~
-1)
4962 G.postRedisplay "dehighlight";
4964 | 47 | 63 -> (* / ? *)
4965 let ondone isforw
s =
4966 cbput state.hists
.pat
s;
4967 state.searchpattern
<- s;
4970 let s = String.create
1 in
4971 s.[0] <- Char.chr
key;
4972 enttext (s, "", Some
(onhist state.hists
.pat
),
4973 textentry, ondone (key = 47), true)
4975 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4976 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4977 setzoom (conf.zoom +. incr)
4979 | 43 | 0xffab -> (* + *)
4982 try int_of_string
s with exc
->
4983 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
4989 state.text <- "page bias is now " ^ string_of_int
n;
4992 enttext ("page bias: ", "", None
, intentry, ondone, true)
4994 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4995 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4996 setzoom (max
0.01 (conf.zoom -. decr))
4998 | 45 | 0xffad -> (* - *)
4999 let ondone msg
= state.text <- msg
in
5001 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
5002 optentry state.mode, ondone, true
5005 | 48 when ctrl -> (* ctrl-0 *)
5010 if state.w <= state.winw
- state.scrollw
5018 | 49 when ctrl -> (* ctrl-1 *)
5020 match conf.columns
with
5021 | Csingle
_ | Cmulti
_ -> 1
5022 | Csplit
(n, _) -> n
5024 let h = state.winh
-
5025 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5027 let zoom = zoomforh
state.winw
h state.scrollw
cols in
5031 | 0xffc6 -> (* f9 *)
5034 | 57 when ctrl -> (* ctrl-9 *)
5037 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5038 when not
ctrl -> (* 0..9 *)
5041 try int_of_string
s with exc
->
5042 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5048 cbput state.hists
.pag
(string_of_int
n);
5049 gotopage1 (n + conf.pagebias
- 1) 0;
5052 let pageentry text key =
5053 match Char.unsafe_chr
key with
5054 | '
g'
-> TEdone
text
5055 | _ -> intentry text key
5057 let text = "x" in text.[0] <- Char.chr
key;
5058 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5061 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5062 reshape state.winw
state.winh
;
5065 conf.hlinks
<- not
conf.hlinks
;
5066 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5067 G.postRedisplay "toggle highlightlinks";
5070 state.glinks
<- true;
5071 let mode = state.mode in
5072 state.mode <- Textentry
(
5073 (":", "", None
, linknentry, linkndone gotounder, false),
5075 state.glinks
<- false;
5079 G.postRedisplay "view:linkent(F)"
5082 state.glinks
<- true;
5083 let mode = state.mode in
5084 state.mode <- Textentry
(
5085 (":", "", None
, linknentry, linkndone (fun under ->
5086 match Ne.pipe () with
5088 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
5091 try popen conf.selcmd
[r, 0; w, -1]; true
5094 (Printf.sprintf
"failed to execute %s: %s"
5095 conf.selcmd
(exntos exn
));
5099 Ne.clo fd
(fun msg
->
5100 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5103 let s = undertext under in
5107 let l = String.length
s in
5108 let n = tempfailureretry
(Unix.write
w s 0) l in
5113 "failed to write %d characters to sel pipe, wrote %d"
5118 (Printf.sprintf
"failed to write to sel pipe: %s"
5128 state.glinks
<- false;
5132 G.postRedisplay "view:linkent"
5135 begin match state.autoscroll
with
5137 conf.autoscrollstep
<- step
;
5138 state.autoscroll
<- None
5140 if conf.autoscrollstep
= 0
5141 then state.autoscroll
<- Some
1
5142 else state.autoscroll
<- Some
conf.autoscrollstep
5145 | 112 when ctrl -> (* ctrl-p *)
5149 setpresentationmode (not
conf.presentation
);
5150 showtext ' '
("presentation mode " ^
5151 if conf.presentation
then "on" else "off");
5154 if List.mem
Wsi.Fullscreen
state.winstate
5155 then doreshape conf.cwinw
conf.cwinh
5156 else Wsi.fullscreen
()
5158 | 112 | 78 -> (* p|N *)
5159 search state.searchpattern
false
5161 | 110 | 0xffc0 -> (* n|F3 *)
5162 search state.searchpattern
true
5165 begin match state.layout with
5168 gotoghyll (getpagey l.pageno)
5174 | 0xff9f | 0xffff -> (* delete *)
5178 showtext ' '
(describe_location ());
5181 begin match state.layout with
5184 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5189 enterbookmarkmode ()
5191 | 104 | 0xffbe -> (* h|F1 *)
5197 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5202 match state.layout with
5204 if String.length
s > 0
5206 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5209 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5213 showtext ' '
"Quick bookmark added";
5216 begin match state.layout with
5218 let rect = getpdimrect
l.pagedimno
in
5222 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5223 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5225 (truncate
(rect.(1) -. rect.(0)),
5226 truncate
(rect.(3) -. rect.(0)))
5228 let w = truncate
((float w)*.conf.zoom)
5229 and h = truncate
((float h)*.conf.zoom) in
5232 state.anchor <- getanchor ();
5233 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5235 G.postRedisplay "z";
5240 | 60 | 62 -> (* < > *)
5241 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5243 | 91 | 93 -> (* [ ] *)
5245 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5247 G.postRedisplay "brightness";
5249 | 99 when state.mode = View
-> (* c *)
5251 match state.prevcolumns
with
5252 | None
-> (1, 0, 0), 1.0
5253 | Some
(columns
, z
) ->
5256 | Csplit
(c, _) -> -c, 0, 0
5257 | Cmulti
((c, a, b), _) -> c, a, b
5258 | Csingle
_ -> 1, 0, 0
5262 setcolumns View
c a b;
5265 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5266 setzoom state.prevzoom
5268 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5269 begin match state.autoscroll
with
5271 begin match state.mode with
5272 | Birdseye beye
-> upbirdseye 1 beye
5275 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5276 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5279 setautoscrollspeed n false
5282 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5283 begin match state.autoscroll
with
5285 begin match state.mode with
5286 | Birdseye beye
-> downbirdseye 1 beye
5289 then gotoy_and_clear_text (clamp (state.winh
/2))
5290 else gotoy_and_clear_text (clamp conf.scrollstep
)
5293 setautoscrollspeed n true
5296 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5297 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5303 else conf.hscrollstep
5305 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5306 state.x <- state.x + dx;
5307 gotoy_and_clear_text state.y
5310 G.postRedisplay "lef/right"
5313 | 0xff55 | 0xff9a -> (* (kp) prior *)
5317 match state.layout with
5319 | l :: _ -> state.y - l.pagey
5321 clamp (pgscale (-state.winh
))
5325 | 0xff56 | 0xff9b -> (* (kp) next *)
5329 match List.rev
state.layout with
5331 | l :: _ -> getpagey l.pageno
5333 clamp (pgscale state.winh
)
5337 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5339 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5340 gotoghyll (clamp state.maxy)
5343 when Wsi.withalt mask
-> (* alt-(kp) right *)
5344 gotoghyll (getnav 1)
5346 when Wsi.withalt mask
-> (* alt-(kp) left *)
5347 gotoghyll (getnav ~
-1)
5352 | 118 when conf.debug
-> (* v *)
5355 match getopaque l.pageno with
5358 let x0, y0, x1, y1 = pagebbox opaque
in
5359 let a,b = float x0, float y0 in
5360 let c,d = float x1, float y0 in
5361 let e,f = float x1, float y1 in
5362 let h,j
= float x0, float y1 in
5363 let rect = (a,b,c,d,e,f,h,j
) in
5365 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5367 G.postRedisplay "v";
5370 vlog "huh? %s" (Wsi.keyname
key)
5373 let linknavkeyboard key mask
linknav =
5374 let getpage pageno =
5375 let rec loop = function
5377 | l :: _ when l.pageno = pageno -> Some
l
5378 | _ :: rest
-> loop rest
5379 in loop state.layout
5381 let doexact (pageno, n) =
5382 match getopaque pageno, getpage pageno with
5383 | Some opaque
, Some
l ->
5384 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5386 let under = getlink opaque
n in
5387 G.postRedisplay "link gotounder";
5393 | 0xff50 -> (* home *)
5394 Some
(findlink opaque LDfirst
), -1
5396 | 0xff57 -> (* end *)
5397 Some
(findlink opaque LDlast
), 1
5399 | 0xff51 -> (* left *)
5400 Some
(findlink opaque
(LDleft
n)), -1
5402 | 0xff53 -> (* right *)
5403 Some
(findlink opaque
(LDright
n)), 1
5405 | 0xff52 -> (* up *)
5406 Some
(findlink opaque
(LDup
n)), -1
5408 | 0xff54 -> (* down *)
5409 Some
(findlink opaque
(LDdown
n)), 1
5414 begin match findpwl
l.pageno dir with
5418 state.mode <- LinkNav
(Ltgendir
dir);
5419 let y, h = getpageyh pageno in
5422 then y + h - state.winh
5427 begin match getopaque pageno, getpage pageno with
5428 | Some opaque
, Some
_ ->
5430 let ld = if dir > 0 then LDfirst
else LDlast
in
5433 begin match link with
5435 showlinktype (getlink opaque
m);
5436 state.mode <- LinkNav
(Ltexact
(pageno, m));
5437 G.postRedisplay "linknav jpage";
5444 begin match opt with
5445 | Some Lnotfound
-> pwl l dir;
5446 | Some
(Lfound
m) ->
5450 let _, y0, _, y1 = getlinkrect opaque
m in
5452 then gotopage1 l.pageno y0
5454 let d = fstate.fontsize
+ 1 in
5455 if y1 - l.pagey > l.pagevh - d
5456 then gotopage1 l.pageno (y1 - state.winh
- state.hscrollh + d)
5457 else G.postRedisplay "linknav";
5459 showlinktype (getlink opaque
m);
5460 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5463 | None
-> viewkeyboard key mask
5465 | _ -> viewkeyboard key mask
5470 G.postRedisplay "leave linknav"
5474 | Ltgendir
_ -> viewkeyboard key mask
5475 | Ltexact exact
-> doexact exact
5478 let keyboard key mask
=
5479 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5480 then wcmd "interrupt"
5481 else state.uioh <- state.uioh#
key key mask
5484 let birdseyekeyboard key mask
5485 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5487 match conf.columns
with
5489 | Cmulti
((c, _, _), _) -> c
5490 | Csplit
_ -> failwith
"bird's eye split mode"
5492 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5494 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5495 let y, h = getpageyh pageno in
5496 let top = (state.winh
- h) / 2 in
5497 gotoy (max
0 (y - top))
5498 | 0xff0d (* enter *)
5499 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5500 | 0xff1b -> leavebirdseye beye
true (* escape *)
5501 | 0xff52 -> upbirdseye incr beye
(* up *)
5502 | 0xff54 -> downbirdseye incr beye
(* down *)
5503 | 0xff51 -> upbirdseye 1 beye
(* left *)
5504 | 0xff53 -> downbirdseye 1 beye
(* right *)
5506 | 0xff55 -> (* prior *)
5507 begin match state.layout with
5511 state.mode <- Birdseye
(
5512 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5514 gotopage1 l.pageno 0;
5517 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5519 | [] -> gotoy (clamp (-state.winh
))
5521 state.mode <- Birdseye
(
5522 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5524 gotopage1 l.pageno 0
5527 | [] -> gotoy (clamp (-state.winh
))
5530 | 0xff56 -> (* next *)
5531 begin match List.rev
state.layout with
5533 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5534 begin match layout with
5536 let incr = l.pageh
- l.pagevh in
5541 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5543 G.postRedisplay "birdseye pagedown";
5545 else gotoy (clamp (incr + conf.interpagespace
*2));
5549 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5550 gotopage1 l.pageno 0;
5553 | [] -> gotoy (clamp state.winh
)
5556 | 0xff50 -> (* home *)
5557 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5560 | 0xff57 -> (* end *)
5561 let pageno = state.pagecount
- 1 in
5562 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5563 if not
(pagevisible state.layout pageno)
5566 match List.rev
state.pdims
with
5568 | (_, _, h, _) :: _ -> h
5570 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5571 else G.postRedisplay "birdseye end";
5572 | _ -> viewkeyboard key mask
5575 let drawpage l linkindexbase
=
5577 match state.mode with
5578 | Textentry
_ -> scalecolor 0.4
5580 | View
-> scalecolor 1.0
5581 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5582 if l.pageno = hooverpageno
5585 if l.pageno = pageno
5591 begin match getopaque l.pageno with
5593 if tileready l l.pagex
l.pagey
5595 let x = l.pagedispx - l.pagex
5596 and y = l.pagedispy - l.pagey in
5598 match conf.columns
with
5599 | Csingle
_ | Cmulti
_ ->
5600 (if conf.hlinks
then 1 else 0)
5602 && not
(isbirdseye state.mode) then 2 else 0)
5606 match state.mode with
5607 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5610 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5617 let scrollindicator () =
5618 let sbw, ph
, sh = state.uioh#
scrollph in
5619 let sbh, pw, sw = state.uioh#scrollpw
in
5621 GlDraw.color (0.64, 0.64, 0.64);
5623 (float (state.winw
- sbw), 0.)
5624 (float state.winw
, float state.winh
)
5627 (0., float (state.winh
- sbh))
5628 (float (state.winw
- state.scrollw
- 1), float state.winh
)
5630 GlDraw.color (0.0, 0.0, 0.0);
5633 (float (state.winw
- sbw), ph
)
5634 (float state.winw
, ph
+. sh)
5637 (pw, float (state.winh
- sbh))
5638 (pw +. sw, float state.winh
)
5643 match state.mstate
with
5644 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5647 | Msel
((x0, y0), (x1, y1)) ->
5648 let rec loop = function
5650 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5651 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5652 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5653 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5655 match getopaque l.pageno with
5657 let x0, y0 = pagetranslatepoint l x0 y0 in
5658 let x1, y1 = pagetranslatepoint l x1 y1 in
5659 seltext opaque
(x0, y0, x1, y1);
5667 let showrects rects
=
5669 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5670 GlDraw.polygon_mode `both `fill
;
5671 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5673 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5675 if l.pageno = pageno
5677 let dx = float (l.pagedispx - l.pagex
) in
5678 let dy = float (l.pagedispy - l.pagey) in
5679 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5680 GlDraw.begins `quads
;
5682 GlDraw.vertex2
(x0+.dx, y0+.dy);
5683 GlDraw.vertex2
(x1+.dx, y1+.dy);
5684 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5685 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5696 GlClear.color (scalecolor2 conf.bgcolor
);
5697 GlClear.clear
[`
color];
5698 let rec loop linkindexbase
= function
5700 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5701 loop linkindexbase rest
5704 loop 0 state.layout;
5706 match state.mode with
5707 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5708 begin match getopaque pageno with
5710 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5717 | None
-> state.rects
5724 begin match state.mstate
with
5725 | Mzoomrect
((x0, y0), (x1, y1)) ->
5727 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5728 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5729 GlDraw.rect (float x0, float y0)
5730 (float x1, float y1);
5739 let zoomrect x y x1 y1 =
5742 and y0 = min
y y1 in
5743 gotoy (state.y + y0);
5744 state.anchor <- getanchor ();
5745 let zoom = (float state.winw
*. conf.zoom) /. float (x1 - x0) in
5747 if state.w < state.winw
- state.scrollw
5748 then (state.winw
- state.scrollw
- state.w) / 2
5751 state.x <- (state.x + margin) - x0;
5753 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5754 state.mstate
<- Mnone
;
5758 let winw = state.winw - state.scrollw
- 1 in
5759 let s = float x /. float winw in
5760 let destx = truncate
(float (state.w + winw) *. s) in
5761 state.x <- winw - destx;
5762 gotoy_and_clear_text state.y;
5763 state.mstate
<- Mscrollx
;
5767 let s = float y /. float state.winh
in
5768 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5769 gotoy_and_clear_text desty;
5770 state.mstate
<- Mscrolly
;
5773 let viewmouse button down
x y mask
=
5775 | n when (n == 4 || n == 5) && not down
->
5776 if Wsi.withctrl mask
5778 match state.mstate
with
5779 | Mzoom
(oldn
, i
) ->
5787 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5789 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5791 let zoom = conf.zoom -. incr in
5793 state.mstate
<- Mzoom
(n, 0);
5795 state.mstate
<- Mzoom
(n, i
+1);
5797 else state.mstate
<- Mzoom
(n, 0)
5799 | _ -> state.mstate
<- Mzoom
(n, 0)
5802 match state.autoscroll
with
5803 | Some step
-> setautoscrollspeed step
(n=4)
5814 then -conf.scrollstep
5815 else conf.scrollstep
5817 let incr = incr * 2 in
5818 let y = clamp incr in
5819 gotoy_and_clear_text y
5822 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5823 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5824 gotoy_and_clear_text state.y
5826 | 1 when Wsi.withshift mask
->
5827 state.mstate
<- Mnone
;
5829 match unproject x y with
5830 | Some
(pageno, ux
, uy
) ->
5831 let cmd = Printf.sprintf
5833 conf.stcmd
state.path pageno ux uy
5839 | 1 when Wsi.withctrl mask
->
5842 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5843 state.mstate
<- Mpan
(x, y)
5846 state.mstate
<- Mnone
5851 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5853 state.mstate
<- Mzoomrect
(p, p)
5856 match state.mstate
with
5857 | Mzoomrect
((x0, y0), _) ->
5858 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5859 then zoomrect x0 y0 x y
5861 state.mstate
<- Mnone
;
5862 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5863 G.postRedisplay "kill accidental zoom rect";
5866 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5867 state.mstate
<- Mnone
5870 | 1 when x > state.winw - state.scrollw
->
5873 let _, position, sh = state.uioh#
scrollph in
5874 if y > truncate
position && y < truncate
(position +. sh)
5875 then state.mstate
<- Mscrolly
5878 state.mstate
<- Mnone
5880 | 1 when y > state.winh
- state.hscrollh ->
5883 let _, position, sw = state.uioh#scrollpw
in
5884 if x > truncate
position && x < truncate
(position +. sw)
5885 then state.mstate
<- Mscrollx
5888 state.mstate
<- Mnone
5891 let dest = if down
then getunder x y else Unone
in
5892 begin match dest with
5896 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5899 | Unone
when down
->
5900 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5901 state.mstate
<- Mpan
(x, y);
5903 | Unone
| Utext
_ ->
5906 if conf.angle
mod 360 = 0
5908 state.mstate
<- Msel
((x, y), (x, y));
5909 G.postRedisplay "mouse select";
5913 match state.mstate
with
5916 | Mzoom
_ | Mscrollx
| Mscrolly
->
5917 state.mstate
<- Mnone
5919 | Mzoomrect
((x0, y0), _) ->
5923 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5924 state.mstate
<- Mnone
5926 | Msel
((x0, y0), (x1, y1)) ->
5927 let rec loop = function
5931 let a0 = l.pagedispy in
5932 let a1 = a0 + l.pagevh in
5933 let b0 = l.pagedispx in
5934 let b1 = b0 + l.pagevw in
5935 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5936 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5940 match getopaque l.pageno with
5943 match Ne.pipe () with
5947 "can not create sel pipe: %s"
5950 let doclose what fd
=
5951 Ne.clo fd
(fun msg
->
5952 dolog
"%s close failed: %s" what msg
)
5955 popen conf.selcmd
[r, 0; w, -1];
5958 G.postRedisplay "copysel";
5960 dolog
"can not execute %S: %s"
5961 conf.selcmd
(exntos exn
);
5969 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5970 state.mstate
<- Mnone
;
5977 let birdseyemouse button down
x y mask
5978 (conf, leftx
, _, hooverpageno
, anchor) =
5981 let rec loop = function
5984 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5985 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5987 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5993 | _ -> viewmouse button down
x y mask
5996 let mouse button down
x y mask
=
5997 state.uioh <- state.uioh#button button down
x y mask
;
6001 state.uioh <- state.uioh#
motion x y
6005 state.uioh <- state.uioh#
pmotion x y;
6011 method key key mask
=
6012 begin match state.mode with
6013 | Textentry
textentry -> textentrykeyboard key mask
textentry
6014 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6015 | View
-> viewkeyboard key mask
6016 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6020 method button button bstate
x y mask
=
6021 begin match state.mode with
6023 | View
-> viewmouse button bstate
x y mask
6024 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6030 begin match state.mode with
6032 | View
| Birdseye
_ | LinkNav
_ ->
6033 match state.mstate
with
6034 | Mzoom
_ | Mnone
-> ()
6039 state.mstate
<- Mpan
(x, y);
6041 then state.x <- state.x + dx;
6043 gotoy_and_clear_text y
6046 state.mstate
<- Msel
(a, (x, y));
6047 G.postRedisplay "motion select";
6050 let y = min
state.winh
(max
0 y) in
6054 let x = min
state.winw (max
0 x) in
6057 | Mzoomrect
(p0
, _) ->
6058 state.mstate
<- Mzoomrect
(p0
, (x, y));
6059 G.postRedisplay "motion zoomrect";
6063 method pmotion x y =
6064 begin match state.mode with
6065 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6066 let rec loop = function
6068 if hooverpageno
!= -1
6070 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6071 G.postRedisplay "pmotion birdseye no hoover";
6074 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6075 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6077 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6078 G.postRedisplay "pmotion birdseye hoover";
6088 match state.mstate
with
6089 | Mnone
-> updateunder x y
6090 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6095 method infochanged
_ = ()
6098 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6099 let p, h = scrollph state.y maxy in
6103 let winw = state.winw - state.scrollw
- 1 in
6104 let fwinw = float winw in
6106 let sw = fwinw /. float state.w in
6107 let sw = fwinw *. sw in
6108 max
sw (float conf.scrollh
)
6111 let f = state.w+winw in
6112 let r = float (winw-state.x) /. float f in
6113 let p = fwinw *. r in
6117 if position +. sw > fwinw
6118 then fwinw -. position
6121 state.hscrollh, position, sw
6125 match state.mode with
6126 | LinkNav
_ -> "links"
6127 | Textentry
_ -> "textentry"
6128 | Birdseye
_ -> "birdseye"
6131 findkeyhash conf modename
6138 let fontpath = ref "";;
6141 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6144 let l = String.length
s in
6145 let b = Buffer.create
l in
6151 try Sys.getenv
"HOME"
6154 ("Can not determine home directory location: " ^ exntos exn
);
6158 let modifier_of_string = function
6159 | "alt" -> Wsi.altmask
6160 | "shift" -> Wsi.shiftmask
6161 | "ctrl" | "control" -> Wsi.ctrlmask
6162 | "meta" -> Wsi.metamask
6167 let r = Str.regexp
"-" in
6169 let elems = Str.full_split
r s in
6172 let m1 = modifier_of_string s in
6174 then (Wsi.namekey
s, m)
6177 | Str.Delim
s when n land 1 = 0 -> g s
6179 | Str.Delim
_ -> (k
, m)
6181 let rec loop n k
m = function
6184 let k, m = f n k m x in
6190 let keys_of_string =
6191 let r = Str.regexp
"[ \t]" in
6193 let elems = Str.split
r s in
6194 List.map
key_of_string elems
6197 let copykeyhashes c =
6198 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6201 let config_of c attrs
=
6205 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6206 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6207 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6208 | "preload" -> { c with preload = bool_of_string
v }
6209 | "page-bias" -> { c with pagebias
= int_of_string
v }
6210 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6211 | "horizontal-scroll-step" ->
6212 { c with hscrollstep
= max
(int_of_string
v) 1 }
6213 | "auto-scroll-step" ->
6214 { c with autoscrollstep
= max
0 (int_of_string
v) }
6215 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6216 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6219 match String.lowercase
v with
6220 | "true" -> Some infinity
6222 | f -> Some
(float_of_string
f)
6224 { c with maxwait
= mw}
6225 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6226 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6227 | "vertical-margin" ->
6228 { c with interpagespace
= max
0 (int_of_string
v) }
6230 let zoom = float_of_string
v /. 100. in
6231 let zoom = max
zoom 0.0 in
6232 { c with zoom = zoom }
6233 | "presentation" -> { c with presentation
= bool_of_string
v }
6234 | "rotation-angle" -> { c with angle
= int_of_string
v }
6235 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6236 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6237 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6238 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6239 | "pixmap-cache-size" ->
6240 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6241 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6242 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6243 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6244 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6245 | "background-color" -> { c with bgcolor
= color_of_string v }
6246 | "scrollbar-in-presentation" ->
6247 { c with scrollbarinpm
= bool_of_string
v }
6248 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6249 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6250 | "mupdf-store-size" ->
6251 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6252 | "checkers" -> { c with checkers
= bool_of_string
v }
6253 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6254 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6255 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6256 | "uri-launcher" -> { c with urilauncher
= unent v }
6257 | "path-launcher" -> { c with pathlauncher
= unent v }
6258 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6259 | "invert-colors" -> { c with invert
= bool_of_string
v }
6260 | "brightness" -> { c with colorscale
= float_of_string
v }
6261 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6263 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6265 let (n, _, _) as nab
= multicolumns_of_string v in
6267 then { c with columns
= Csplit
(-n, [||]) }
6268 else { c with columns
= Cmulti
(nab
, [||]) }
6269 | "birds-eye-columns" ->
6270 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6271 | "selection-command" -> { c with selcmd
= unent v }
6272 | "synctex-command" -> { c with stcmd
= unent v }
6273 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6274 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6275 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6276 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6277 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6280 prerr_endline
("Error processing attribute (`" ^
6281 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6284 let rec fold c = function
6287 let c = apply c k v in
6290 fold { c with keyhashes
= copykeyhashes c } attrs
;
6293 let fromstring f pos
n v d =
6296 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6297 n v pos
(exntos exn
)
6302 let bookmark_of attrs
=
6303 let rec fold title page
rely visy
= function
6304 | ("title", v) :: rest
-> fold v page
rely visy rest
6305 | ("page", v) :: rest
-> fold title v rely visy rest
6306 | ("rely", v) :: rest
-> fold title page
v visy rest
6307 | ("visy", v) :: rest
-> fold title page
rely v rest
6308 | _ :: rest
-> fold title page
rely visy rest
6309 | [] -> title, page
, rely, visy
6311 fold "invalid" "0" "0" "0" attrs
6315 let rec fold path page
rely pan visy
= function
6316 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6317 | ("page", v) :: rest
-> fold path v rely pan visy rest
6318 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6319 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6320 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6321 | _ :: rest
-> fold path page
rely pan visy rest
6322 | [] -> path, page
, rely, pan
, visy
6324 fold "" "0" "0" "0" "0" attrs
6328 let rec fold rs ls
= function
6329 | ("out", v) :: rest
-> fold v ls rest
6330 | ("in", v) :: rest
-> fold rs
v rest
6331 | _ :: rest
-> fold ls rs rest
6337 let setconf dst
src =
6338 dst
.scrollbw
<- src.scrollbw
;
6339 dst
.scrollh
<- src.scrollh
;
6340 dst
.icase
<- src.icase
;
6341 dst
.preload <- src.preload;
6342 dst
.pagebias
<- src.pagebias
;
6343 dst
.verbose
<- src.verbose
;
6344 dst
.scrollstep
<- src.scrollstep
;
6345 dst
.maxhfit
<- src.maxhfit
;
6346 dst
.crophack
<- src.crophack
;
6347 dst
.autoscrollstep
<- src.autoscrollstep
;
6348 dst
.maxwait
<- src.maxwait
;
6349 dst
.hlinks
<- src.hlinks
;
6350 dst
.underinfo
<- src.underinfo
;
6351 dst
.interpagespace
<- src.interpagespace
;
6352 dst
.zoom <- src.zoom;
6353 dst
.presentation
<- src.presentation
;
6354 dst
.angle
<- src.angle
;
6355 dst
.cwinw
<- src.cwinw
;
6356 dst
.cwinh
<- src.cwinh
;
6357 dst
.savebmarks
<- src.savebmarks
;
6358 dst
.memlimit
<- src.memlimit
;
6359 dst
.proportional
<- src.proportional
;
6360 dst
.texcount
<- src.texcount
;
6361 dst
.sliceheight
<- src.sliceheight
;
6362 dst
.thumbw
<- src.thumbw
;
6363 dst
.jumpback
<- src.jumpback
;
6364 dst
.bgcolor
<- src.bgcolor
;
6365 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6366 dst
.tilew
<- src.tilew
;
6367 dst
.tileh
<- src.tileh
;
6368 dst
.mustoresize
<- src.mustoresize
;
6369 dst
.checkers
<- src.checkers
;
6370 dst
.aalevel
<- src.aalevel
;
6371 dst
.trimmargins
<- src.trimmargins
;
6372 dst
.trimfuzz
<- src.trimfuzz
;
6373 dst
.urilauncher
<- src.urilauncher
;
6374 dst
.colorspace
<- src.colorspace
;
6375 dst
.invert
<- src.invert
;
6376 dst
.colorscale
<- src.colorscale
;
6377 dst
.redirectstderr <- src.redirectstderr;
6378 dst
.ghyllscroll
<- src.ghyllscroll
;
6379 dst
.columns
<- src.columns
;
6380 dst
.beyecolumns
<- src.beyecolumns
;
6381 dst
.selcmd
<- src.selcmd
;
6382 dst
.updatecurs
<- src.updatecurs
;
6383 dst
.pathlauncher
<- src.pathlauncher
;
6384 dst
.keyhashes
<- copykeyhashes src;
6385 dst
.hfsize
<- src.hfsize
;
6386 dst
.hscrollstep
<- src.hscrollstep
;
6387 dst
.pgscale <- src.pgscale;
6388 dst
.usepbo
<- src.usepbo
;
6389 dst
.wheelbypage
<- src.wheelbypage
;
6390 dst
.stcmd
<- src.stcmd
;
6394 let h = Hashtbl.create
10 in
6395 let dc = { defconf with angle
= defconf.angle
} in
6396 let rec toplevel v t spos
_ =
6398 | Vdata
| Vcdata
| Vend
-> v
6399 | Vopen
("llppconfig", _, closed
) ->
6402 else { v with f = llppconfig
}
6404 error
"unexpected subelement at top level" s spos
6405 | Vclose
_ -> error
"unexpected close at top level" s spos
6407 and llppconfig
v t spos
_ =
6409 | Vdata
| Vcdata
-> v
6410 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6411 | Vopen
("defaults", attrs
, closed
) ->
6412 let c = config_of dc attrs
in
6416 else { v with f = defaults
}
6418 | Vopen
("ui-font", attrs
, closed
) ->
6419 let rec getsize size
= function
6421 | ("size", v) :: rest
->
6423 fromstring int_of_string spos
"size" v fstate.fontsize
in
6425 | l -> getsize size l
6427 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6430 else { v with f = uifont
(Buffer.create
10) }
6432 | Vopen
("doc", attrs
, closed
) ->
6433 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6434 let path = unent pathent
6435 and pageno = fromstring int_of_string spos
"page" spage
0
6436 and rely = fromstring float_of_string spos
"rely" srely
0.0
6437 and pan
= fromstring int_of_string spos
"pan" span
0
6438 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6439 let c = config_of dc attrs
in
6440 let anchor = (pageno, rely, visy
) in
6442 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6443 else { v with f = doc
path pan
anchor c [] }
6446 error
"unexpected subelement in llppconfig" s spos
6448 | Vclose
"llppconfig" -> { v with f = toplevel }
6449 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6451 and defaults
v t spos
_ =
6453 | Vdata
| Vcdata
-> v
6454 | Vend
-> error
"unexpected end of input in defaults" s spos
6455 | Vopen
("keymap", attrs
, closed
) ->
6457 try List.assoc
"mode" attrs
6458 with Not_found
-> "global" in
6463 let h = findkeyhash dc modename in
6464 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6467 { v with f = pkeymap
ret KeyMap.empty }
6469 | Vopen
(_, _, _) ->
6470 error
"unexpected subelement in defaults" s spos
6472 | Vclose
"defaults" ->
6473 { v with f = llppconfig
}
6475 | Vclose
_ -> error
"unexpected close in defaults" s spos
6477 and uifont
b v t spos
epos =
6480 Buffer.add_substring
b s spos
(epos - spos
);
6482 | Vopen
(_, _, _) ->
6483 error
"unexpected subelement in ui-font" s spos
6484 | Vclose
"ui-font" ->
6485 if String.length
!fontpath = 0
6486 then fontpath := Buffer.contents
b;
6487 { v with f = llppconfig
}
6488 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6489 | Vend
-> error
"unexpected end of input in ui-font" s spos
6491 and doc
path pan
anchor c bookmarks
v t spos
_ =
6493 | Vdata
| Vcdata
-> v
6494 | Vend
-> error
"unexpected end of input in doc" s spos
6495 | Vopen
("bookmarks", _, closed
) ->
6498 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6500 | Vopen
("keymap", attrs
, closed
) ->
6502 try List.assoc
"mode" attrs
6503 with Not_found
-> "global"
6509 let h = findkeyhash c modename in
6510 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6511 doc
path pan
anchor c bookmarks
6513 { v with f = pkeymap
ret KeyMap.empty }
6515 | Vopen
(_, _, _) ->
6516 error
"unexpected subelement in doc" s spos
6519 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6520 { v with f = llppconfig
}
6522 | Vclose
_ -> error
"unexpected close in doc" s spos
6524 and pkeymap
ret keymap
v t spos
_ =
6526 | Vdata
| Vcdata
-> v
6527 | Vend
-> error
"unexpected end of input in keymap" s spos
6528 | Vopen
("map", attrs
, closed
) ->
6529 let r, l = map_of attrs
in
6530 let kss = fromstring keys_of_string spos
"in" r [] in
6531 let lss = fromstring keys_of_string spos
"out" l [] in
6535 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6536 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6539 then { v with f = pkeymap
ret keymap }
6542 { v with f = skip
"map" f }
6545 error
"unexpected subelement in keymap" s spos
6547 | Vclose
"keymap" ->
6548 { v with f = ret keymap }
6550 | Vclose
_ -> error
"unexpected close in keymap" s spos
6552 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6554 | Vdata
| Vcdata
-> v
6555 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6556 | Vopen
("item", attrs
, closed
) ->
6557 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6558 let page = fromstring int_of_string spos
"page" spage
0
6559 and rely = fromstring float_of_string spos
"rely" srely
0.0
6560 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6562 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6565 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6568 { v with f = skip
"item" f }
6571 error
"unexpected subelement in bookmarks" s spos
6573 | Vclose
"bookmarks" ->
6574 { v with f = doc
path pan
anchor c bookmarks }
6576 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6578 and skip tag
f v t spos
_ =
6580 | Vdata
| Vcdata
-> v
6582 error
("unexpected end of input in skipped " ^ tag
) s spos
6583 | Vopen
(tag'
, _, closed
) ->
6587 let f'
() = { v with f = skip tag
f } in
6588 { v with f = skip tag'
f'
}
6592 else error
("unexpected close in skipped " ^ tag
) s spos
6595 parse
{ f = toplevel; accu = () } s;
6601 let len = in_channel_length ic
in
6602 let s = String.create
len in
6603 really_input ic
s 0 len;
6606 | Parse_error
(msg
, s, pos
) ->
6607 let subs = subs s pos
in
6608 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6609 failwith
("parse error: " ^
s)
6612 failwith
("config load error: " ^ exntos exn
)
6618 let dir = Filename.concat
home ".config" in
6619 if Sys.is_directory
dir then dir else home
6622 Filename.concat
dir "llpp.conf"
6625 let confpath = ref defconfpath;;
6628 if Sys.file_exists
!confpath
6631 (try Some
(open_in_bin
!confpath)
6634 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6645 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6654 f (Hashtbl.create
0, defconf)
6659 let pc, pb
, px, pa
=
6661 Hashtbl.find h (Filename.basename
state.path)
6662 with Not_found
-> dc, [], 0, emptyanchor
6666 state.bookmarks <- pb
;
6668 state.scrollw
<- conf.scrollbw
;
6670 then state.anchor <- pa
;
6671 cbput state.hists
.nav pa
;
6677 let add_attrs bb always
dc c =
6680 then Printf.bprintf bb
"\n %s='%b'" s a
6683 then Printf.bprintf bb
"\n %s='%d'" s a
6686 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6689 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6692 then Printf.bprintf bb
"\n %s='%f'" s a
6696 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6700 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6704 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6708 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6714 | Some
(_N
, _A
, _B
) ->
6715 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6725 else string_of_float
f
6727 Printf.bprintf bb
"\n %s='%s'" s v
6732 | Cmulti
((n, a, b), _) when n > 1 ->
6733 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6734 | Csplit
(n, _) when n > 1 ->
6735 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6741 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6744 oi
"width" c.cwinw
dc.cwinw
;
6745 oi
"height" c.cwinh
dc.cwinh
;
6746 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6747 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6748 ob "case-insensitive-search" c.icase
dc.icase
;
6749 ob "preload" c.preload dc.preload;
6750 oi
"page-bias" c.pagebias
dc.pagebias
;
6751 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6752 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6753 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6754 ob "crop-hack" c.crophack
dc.crophack
;
6755 oW
"throttle" c.maxwait
dc.maxwait
;
6756 ob "highlight-links" c.hlinks
dc.hlinks
;
6757 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6758 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6759 oz
"zoom" c.zoom dc.zoom;
6760 ob "presentation" c.presentation
dc.presentation
;
6761 oi
"rotation-angle" c.angle
dc.angle
;
6762 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6763 ob "proportional-display" c.proportional
dc.proportional
;
6764 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6765 oi
"tex-count" c.texcount
dc.texcount
;
6766 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6767 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6768 ob "persistent-location" c.jumpback
dc.jumpback
;
6769 oc
"background-color" c.bgcolor
dc.bgcolor
;
6770 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6771 oi
"tile-width" c.tilew
dc.tilew
;
6772 oi
"tile-height" c.tileh
dc.tileh
;
6773 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6774 ob "checkers" c.checkers
dc.checkers
;
6775 oi
"aalevel" c.aalevel
dc.aalevel
;
6776 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6777 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6778 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6779 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6780 oC
"color-space" c.colorspace
dc.colorspace
;
6781 ob "invert-colors" c.invert
dc.invert
;
6782 oF
"brightness" c.colorscale
dc.colorscale
;
6783 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6784 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6785 oco
"columns" c.columns
dc.columns
;
6786 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6787 os
"selection-command" c.selcmd
dc.selcmd
;
6788 os
"synctex-command" c.stcmd
dc.stcmd
;
6789 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6790 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6791 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6792 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6793 ob "use-pbo" c.usepbo
dc.usepbo
;
6794 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6797 let keymapsbuf always
dc c =
6798 let bb = Buffer.create
16 in
6799 let rec loop = function
6801 | (modename, h) :: rest
->
6802 let dh = findkeyhash dc modename in
6803 if always
|| h <> dh
6805 if Hashtbl.length
h > 0
6807 if Buffer.length
bb > 0
6808 then Buffer.add_char
bb '
\n'
;
6809 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6810 Hashtbl.iter
(fun i
o ->
6811 let isdifferent = always
||
6813 let dO = Hashtbl.find dh i
in
6815 with Not_found
-> true
6820 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6821 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6822 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6823 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6824 Buffer.add_string
bb (Wsi.keyname
k);
6827 let rec loop = function
6829 | km
:: [] -> addkm km
6830 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6834 Buffer.add_string
bb "<map in='";
6838 Buffer.add_string
bb "' out='";
6840 Buffer.add_string
bb "'/>\n"
6843 Buffer.add_string
bb "' out='";
6845 Buffer.add_string
bb "'/>\n"
6847 | KMmulti
(ins, kms
) ->
6848 Buffer.add_char
bb ' '
;
6850 Buffer.add_string
bb "' out='";
6852 Buffer.add_string
bb "'/>\n"
6854 Buffer.add_string
bb "</keymap>";
6864 let uifontsize = fstate.fontsize
in
6865 let bb = Buffer.create
32768 in
6870 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
)
6871 | Wsi.MaxVert
-> (w, conf.cwinh
)
6872 | Wsi.MaxHorz
-> (conf.cwinw
, h)
6874 (state.winw, state.winh
) state.winstate
6879 let dc = if conf.bedefault
then conf else dc in
6880 Buffer.add_string
bb "<llppconfig>\n";
6882 if String.length
!fontpath > 0
6884 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6890 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6893 Buffer.add_string
bb "<defaults ";
6894 add_attrs bb true dc dc;
6895 let kb = keymapsbuf true dc dc in
6896 if Buffer.length
kb > 0
6898 Buffer.add_string
bb ">\n";
6899 Buffer.add_buffer
bb kb;
6900 Buffer.add_string
bb "\n</defaults>\n";
6902 else Buffer.add_string
bb "/>\n";
6904 let adddoc path pan
anchor c bookmarks =
6905 if bookmarks == [] && c = dc && anchor = emptyanchor
6908 Printf.bprintf
bb "<doc path='%s'"
6909 (enent
path 0 (String.length
path));
6911 if anchor <> emptyanchor
6913 let n, rely, visy
= anchor in
6914 Printf.bprintf
bb " page='%d'" n;
6917 Printf.bprintf
bb " rely='%f'" rely
6919 if abs_float visy
> 1e-6
6921 Printf.bprintf
bb " visy='%f'" visy
6926 then Printf.bprintf
bb " pan='%d'" pan
;
6928 add_attrs bb false dc c;
6929 let kb = keymapsbuf false dc c in
6931 begin match bookmarks with
6933 if Buffer.length
kb > 0
6935 Buffer.add_string
bb ">\n";
6936 Buffer.add_buffer
bb kb;
6937 Buffer.add_string
bb "\n</doc>\n";
6939 else Buffer.add_string
bb "/>\n"
6941 Buffer.add_string
bb ">\n<bookmarks>\n";
6942 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6944 "<item title='%s' page='%d'"
6945 (enent
title 0 (String.length
title))
6950 Printf.bprintf
bb " rely='%f'" rely
6952 if abs_float visy
> 1e-6
6954 Printf.bprintf
bb " visy='%f'" visy
6956 Buffer.add_string
bb "/>\n";
6958 Buffer.add_string
bb "</bookmarks>";
6959 if Buffer.length
kb > 0
6961 Buffer.add_string
bb "\n";
6962 Buffer.add_buffer
bb kb;
6964 Buffer.add_string
bb "\n</doc>\n";
6970 match state.mode with
6971 | Birdseye
(c, pan, _, _, _) ->
6973 match conf.columns
with
6974 | Cmulti
((c, _, _), _) -> Some
c
6978 match c.columns
with
6979 | Cmulti
(c, _) -> Cmulti
(c, [||])
6980 | Csingle
_ -> Csingle
[||]
6981 | Csplit
_ -> failwith
"quit from bird's eye while split"
6983 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6984 | _ -> state.x, conf
6986 let basename = Filename.basename state.path in
6987 adddoc basename pan (getanchor ())
6989 let autoscrollstep =
6990 match state.autoscroll
with
6992 | None
-> conf.autoscrollstep
6994 match state.mode with
6995 | Birdseye
(bc
, _, _, _, _) ->
6998 presentation
= bc
.presentation
;
6999 interpagespace
= bc
.interpagespace
;
7000 maxwait
= bc
.maxwait
;
7001 autoscrollstep = autoscrollstep }
7002 | _ -> { conf with autoscrollstep = autoscrollstep }
7004 (if conf.savebmarks
then state.bookmarks else []);
7006 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7008 then adddoc path x anchor c bookmarks
7010 Buffer.add_string
bb "</llppconfig>\n";
7013 if load1 f && Buffer.length
bb > 0
7016 let tmp = !confpath ^
".tmp" in
7017 let oc = open_out_bin
tmp in
7018 Buffer.output_buffer
oc bb;
7020 Unix.rename
tmp !confpath;
7023 ("error while saving configuration: " ^ exntos exn
)
7027 let adderrmsg src msg
=
7028 Buffer.add_string
state.errmsgs msg
;
7029 state.newerrmsgs
<- true;
7033 let adderrfmt src fmt
=
7034 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7038 let cl = splitatspace cmds
in
7040 try Scanf.sscanf
s fmt
f
7042 adderrfmt "remote exec"
7043 "error processing '%S': %s\n" cmds
(exntos exn
)
7046 | "reload" :: [] -> reload ()
7047 | "goto" :: args :: [] ->
7048 scan args "%u %f %f"
7050 let cmd, _ = state.geomcmds
in
7051 if String.length
cmd = 0
7052 then gotopagexy pageno x y
7055 gotopagexy pageno x y;
7058 state.reprf
<- f state.reprf
7060 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7061 | "rect" :: args :: [] ->
7062 scan args "%u %u %f %f %f %f"
7063 (fun pageno color x0 y0 x1 y1 ->
7064 onpagerect pageno (fun w h ->
7065 let _,w1,h1
,_ = getpagedim pageno in
7066 let sw = float w1 /. w
7067 and sh = float h1
/. h in
7071 and y1s
= y1 *. sh in
7072 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7074 state.rects <- (pageno, color, rect) :: state.rects;
7075 G.postRedisplay "rect";
7078 | "activatewin" :: [] -> Wsi.activatewin
()
7079 | "quit" :: [] -> raise Quit
7081 adderrfmt "remote command"
7082 "error processing remote command: %S\n" cmds
;
7086 let scratch = String.create
80 in
7087 let buf = Buffer.create
80 in
7090 try Some
(Unix.read fd
scratch 0 80)
7092 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7093 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7096 match tempfr () with
7102 if Buffer.length
buf > 0
7104 let s = Buffer.contents
buf in
7114 let pos = String.index_from
scratch ppos '
\n'
in
7115 if pos >= n then -1 else pos
7116 with Not_found
-> -1
7120 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7121 let s = Buffer.contents
buf in
7127 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7133 let remoteopen path =
7134 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7136 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7141 let trimcachepath = ref "" in
7142 let rcmdpath = ref "" in
7145 [("-p", Arg.String
(fun s -> state.password
<- s),
7146 "<password> Set password");
7148 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7149 "<path> Set path to the user interface font");
7151 ("-c", Arg.String
(fun s -> Config.confpath := s),
7152 "<path> Set path to the configuration file");
7154 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7155 "<path> Set path to the trim cache file");
7157 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7158 "<named-destination> Set named destination");
7160 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7162 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7163 "<path> Set path to the remote commands source");
7165 ("-v", Arg.Unit
(fun () ->
7167 "%s\nconfiguration path: %s\n"
7171 exit
0), " Print version and exit");
7174 (fun s -> state.path <- s)
7175 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7177 if String.length
state.path = 0
7178 then (prerr_endline
"file name missing"; exit
1);
7180 if not
(Config.load ())
7181 then prerr_endline
"failed to load configuration";
7183 let globalkeyhash = findkeyhash conf "global" in
7184 let wsfd, winw, winh
= Wsi.init
(object
7186 state.wthack
<- false;
7187 if nogeomcmds state.geomcmds
|| platform == Posx
7190 GlClear.color (scalecolor2 conf.bgcolor
);
7191 GlClear.clear
[`
color];
7193 method display = display ()
7194 method reshape w h = reshape w h
7195 method mouse b d x y m = mouse b d x y m
7196 method motion x y = state.mpos
<- (x, y); motion x y
7197 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7199 let mascm = m land (
7200 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7202 match state.keystate
with
7204 let km = k, mascm in
7207 let modehash = state.uioh#
modehash in
7208 try Hashtbl.find modehash km
7210 try Hashtbl.find globalkeyhash km
7211 with Not_found
-> KMinsrt
(k, m)
7213 | KMinsrt
(k, m) -> keyboard k m
7214 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7215 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7217 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7218 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7219 state.keystate
<- KSnone
7220 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7221 state.keystate
<- KSinto
(keys
, insrt
)
7223 state.keystate
<- KSnone
7225 method enter
x y = state.mpos
<- (x, y); pmotion x y
7226 method leave = state.mpos
<- (-1, -1)
7227 method winstate wsl
= state.winstate
<- wsl
7228 method quit
= raise Quit
7229 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7234 List.exists
GlMisc.check_extension
7235 [ "GL_ARB_texture_rectangle"
7236 ; "GL_EXT_texture_recangle"
7237 ; "GL_NV_texture_rectangle" ]
7239 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7242 match Ne.pipe () with
7244 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7248 match Ne.pipe () with
7250 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7260 setcheckers conf.checkers
;
7264 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7265 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7266 !Config.fontpath, !trimcachepath,
7267 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7271 state.text <- "Opening " ^
(mbtoutf8
state.path);
7273 opendoc state.path state.password
;
7276 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7279 if String.length
!rcmdpath > 0
7280 then remoteopen !rcmdpath
7285 let rec loop deadline
=
7287 match state.errfd
with
7288 | None
-> [state.sr
; state.wsfd]
7289 | Some fd
-> [state.sr
; state.wsfd; fd
]
7294 | Some fd
-> fd
:: r
7296 if state.redisplay
&& not
state.wthack
7298 state.redisplay
<- false;
7305 if deadline
= infinity
7307 else max
0.0 (deadline
-. now)
7312 try Unix.select
r [] [] timeout
7313 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7319 if state.ghyll
== noghyll
7321 match state.autoscroll
with
7322 | Some step
when step
!= 0 ->
7323 let y = state.y + step
in
7327 else if y >= state.maxy then 0 else y
7330 if state.mode = View
7331 then state.text <- "";
7334 else deadline
+. 0.01
7339 let rec checkfds = function
7341 | fd
:: rest
when fd
= state.sr
->
7342 let cmd = readcmd state.sr
in
7346 | fd
:: rest
when fd
= state.wsfd ->
7350 | fd
:: rest
when Some fd
= !optrfd ->
7351 begin match remote fd
with
7352 | None
-> optrfd := remoteopen !rcmdpath;
7353 | opt -> optrfd := opt
7358 let s = String.create
80 in
7359 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7360 if conf.redirectstderr
7362 Buffer.add_substring
state.errmsgs
s 0 n;
7363 state.newerrmsgs
<- true;
7364 state.redisplay
<- true;
7367 prerr_string
(String.sub
s 0 n);
7375 if deadline
= infinity
7379 match state.autoscroll
with
7380 | Some step
when step
!= 0 -> deadline1
7381 | _ -> if state.ghyll
== noghyll then infinity
else deadline1