8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 type params
= (angle
* fitmodel
* trimparams
17 * texcount
* sliceheight
* memsize
18 * colorspace
* fontpath
* trimcachepath
28 and trimmargins
= bool
29 and interpagespace
= int
36 and trimcachepath
= string
39 and irect
= (int * int * int * int)
40 and trimparams
= (trimmargins
* irect
)
41 and colorspace
= | Rgb
| Bgr
| Gray
42 and fitmodel
= | FitWidth
| FitProportional
| FitPage
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 fitmodel
: fitmodel
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
383 method eformsgs
: bool
387 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
388 | Textentry
of (textentry
* onleave
)
390 | LinkNav
of linktarget
391 and onleave
= leavetextentrystatus
-> unit
392 and leavetextentrystatus
= | Cancel
| Confirm
393 and helpitem
= string * int * action
396 | Action
of (uioh
-> uioh
)
398 | Ltexact
of (pageno
* int)
402 let isbirdseye = function Birdseye _
-> true | _
-> false;;
403 let istextentry = function Textentry _
-> true | _
-> false;;
407 | Loading
of (page
* gen
)
409 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
411 | Outlining
of outline list
414 let emptykeyhash = Hashtbl.create
0;;
415 let nouioh : uioh
= object (self
)
417 method key _ _
= self
418 method button _ _ _ _ _
= self
419 method motion _ _
= self
420 method pmotion _ _
= self
421 method infochanged _
= ()
422 method scrollpw
= (0, nan
, nan
)
423 method scrollph
= (0, nan
, nan
)
424 method modehash
= emptykeyhash
425 method eformsgs
= false
429 { mutable sr
: Unix.file_descr
430 ; mutable sw
: Unix.file_descr
431 ; mutable wsfd
: Unix.file_descr
432 ; mutable errfd
: Unix.file_descr
option
433 ; mutable stderr
: Unix.file_descr
434 ; mutable errmsgs
: Buffer.t
435 ; mutable newerrmsgs
: bool
439 ; mutable scrollw
: int
440 ; mutable hscrollh
: int
441 ; mutable anchor
: anchor
442 ; mutable ranchors
: (string * string * anchor
) list
444 ; mutable layout
: page list
445 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
446 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
447 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
448 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
449 ; mutable pagecount
: int
450 ; mutable currently
: currently
451 ; mutable mstate
: mstate
452 ; mutable searchpattern
: string
453 ; mutable rects
: (pageno
* recttype
* rect
) list
454 ; mutable rects1
: (pageno
* recttype
* rect
) list
455 ; mutable text
: string
456 ; mutable winstate
: Wsi.winstate list
457 ; mutable mode
: mode
458 ; mutable uioh
: uioh
459 ; mutable outlines
: outline array
460 ; mutable bookmarks
: outline list
461 ; mutable path
: string
462 ; mutable password
: string
463 ; mutable nameddest
: string
464 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
465 ; mutable memused
: memsize
467 ; mutable throttle
: (page list
* int * float) option
468 ; mutable autoscroll
: int option
469 ; mutable ghyll
: (int option -> unit)
470 ; mutable help
: helpitem array
471 ; mutable docinfo
: (int * string) list
472 ; mutable texid
: GlTex.texture_id
option
474 ; mutable prevzoom
: float
475 ; mutable progress
: float
476 ; mutable redisplay
: bool
477 ; mutable mpos
: mpos
478 ; mutable keystate
: keystate
479 ; mutable glinks
: bool
480 ; mutable prevcolumns
: (columns
* float) option
483 ; mutable reprf
: (unit -> unit)
486 { pat
: string circbuf
487 ; pag
: string circbuf
488 ; nav
: anchor circbuf
489 ; sel
: string circbuf
511 ; presentation
= false
516 ; fitmodel
= FitProportional
517 ; trimmargins
= false
518 ; trimfuzz
= (0,0,0,0)
519 ; memlimit
= 32 lsl 20
524 ; bgcolor
= (0.5, 0.5, 0.5)
526 ; scrollbarinpm
= true
529 ; mustoresize
= 256 lsl 20
534 | Plinux
| Pfreebsd
| Pdragonflybsd
535 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
536 | Posx
-> "open \"%s\""
537 | Pcygwin
-> "cygstart \"%s\""
538 | Punknown
-> "echo %s")
539 ; pathlauncher
= "lp \"%s\""
542 | Plinux
| Pfreebsd
| Pdragonflybsd
543 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
550 ; redirectstderr
= false
552 ; columns
= Csingle
[||]
558 ; wheelbypage
= false
559 ; stcmd
= "echo SyncTex"
561 let mk n
= (n
, Hashtbl.create
1) in
575 let wtmode = ref false;;
577 let findkeyhash c name
=
578 try List.assoc name c
.keyhashes
579 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
582 let conf = { defconf with angle
= defconf.angle
};;
584 let pgscale h
= truncate
(float h
*. conf.pgscale);;
587 { mutable fontsize
: int
588 ; mutable wwidth
: float
589 ; mutable maxrows
: int
601 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
602 let len = String.length s
in
603 if colonpos >= 0 && colonpos + 3 < len
605 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
608 try String.rindex_from s
colonpos ' '
612 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
615 | "http" | "ftp" | "mailto" ->
617 try String.index_from s
colonpos ' '
618 with Not_found
-> len
620 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
628 if String.length
conf.urilauncher
= 0
629 then print_endline uri
631 let url = geturl uri
in
632 if String.length
url = 0
633 then print_endline uri
635 let re = Str.regexp
"%s" in
636 let command = Str.global_replace
re url conf.urilauncher
in
640 "failed to execute `%s': %s\n" command (exntos exn
);
646 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
647 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
651 let strings = version () :: "" :: Help.keys
in
654 let url = geturl s
in
655 if String.length
url > 0
656 then (s
, 0, Action
(fun u
-> gotouri url; u
))
657 else (s
, 0, Noaction
)
662 let firstgeomcmds = "", [];;
663 let noreprf () = ();;
670 ; stderr
= Unix.stderr
671 ; errmsgs
= Buffer.create
0
678 ; anchor
= emptyanchor
682 ; tilelru
= Queue.create
()
683 ; pagemap
= Hashtbl.create
10
684 ; tilemap
= Hashtbl.create
10
700 ; geomcmds
= firstgeomcmds
702 { nav
= cbnew 10 emptyanchor
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 fitmodel_of_string s =
985 match String.lowercase
s with
986 | "width" -> FitWidth
987 | "proportional" -> FitProportional
989 | _
-> failwith
"invalid fit model"
992 let int_of_fitmodel = function
994 | FitProportional
-> 1
998 let fitmodel_of_int = function
1000 | 1 -> FitProportional
1002 | n
-> failwith
("invalid fit model index " ^ string_of_int n
)
1005 let fitmodel_to_string = function
1006 | FitWidth
-> "width"
1007 | FitProportional
-> "proportional"
1011 let intentry_with_suffix text key
=
1013 if key
>= 32 && key
< 127
1017 match Char.lowercase
c with
1019 let text = addchar text c in
1022 | 'k'
| 'm'
| '
g'
->
1023 let text = addchar text c in
1027 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1031 let multicolumns_to_string (n
, a
, b) =
1033 then Printf.sprintf
"%d" n
1034 else Printf.sprintf
"%d,%d,%d" n a
b;
1037 let multicolumns_of_string s =
1039 (int_of_string
s, 0, 0)
1041 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1043 then failwith
"subtly broken"; (n
, a
, b)
1049 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1050 if n != 4 then failwith
"incomplete read(len)";
1052 lor (Char.code
s.[0] lsl 24)
1053 lor (Char.code
s.[1] lsl 16)
1054 lor (Char.code
s.[2] lsl 8)
1055 lor (Char.code
s.[3] lsl 0)
1057 let s = String.create
len in
1058 let n = tempfailureretry
(Unix.read fd
s 0) len in
1059 if n != len then failwith
"incomplete read(data)";
1063 let btod b = if b then 1 else 0;;
1066 let b = Buffer.create
16 in
1067 Buffer.add_string
b "llll";
1070 let s = Buffer.contents
b in
1071 let n = String.length
s in
1073 (* dolog "wcmd %S" (String.sub s 4 len); *)
1074 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1075 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1076 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1077 s.[3] <- Char.chr
(len land 0xff);
1078 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1079 if n'
!= n then failwith
"write failed";
1084 let d = state.winh
- h
in
1085 max
conf.interpagespace
((d + 1) / 2)
1088 let rowyh (c, coverA
, coverB
) b n =
1089 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1091 let _, _, vy
, (_, _, h
, _) = b.(n) in
1094 let n'
= n - coverA
in
1097 let e = min
state.pagecount
(s + c) in
1098 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1099 let _, _, y, (_, _, h
, _) = b.(m
) in
1100 let miny = min
miny y in
1101 let maxh = max
maxh h
in
1102 find (m
+1) miny maxh
1107 match conf.columns
with
1108 | Cmulti
((_, _, _) as cl
, b) ->
1109 if Array.length
b > 0
1111 let y, h
= rowyh cl
b (Array.length
b - 1) in
1112 y + h
+ (if conf.presentation
then calcips h
else 0)
1115 if Array.length
b > 0
1117 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1118 y + h
+ (if conf.presentation
then calcips h
else 0)
1121 if Array.length
b > 0
1123 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1128 let getpageyh pageno
=
1129 let pageno = bound pageno 0 (state.pagecount
-1) in
1130 match conf.columns
with
1132 if Array.length
b = 0
1135 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1137 if conf.presentation
1143 if Array.length
b = 0
1146 let y, h
= rowyh cl
b pageno in
1148 if conf.presentation
1154 if Array.length
b = 0
1158 let (_, _, y, (_, _, h
, _)) = b.(n) in
1162 let getpagedim pageno =
1165 | (n, _, _, _) as pdim
:: rest
->
1167 then (if n = pageno then pdim
else ppdim
)
1172 f (-1, -1, -1, -1) state.pdims
1175 let getpagey pageno = fst
(getpageyh pageno);;
1177 let nogeomcmds cmds
=
1179 | s, [] -> String.length
s = 0
1184 let ((c, coverA
, coverB
) as cl
), b =
1185 match conf.columns
with
1186 | Csingle
b -> (1, 0, 0), b
1187 | Cmulti
(c, b) -> c, b
1188 | Csplit
(_, b) -> (1, 0, 0), b
1190 if Array.length
b = 0
1193 let rec bsearch nmin nmax
=
1195 then bound nmin
0 (state.pagecount
-1)
1197 let n = (nmax
+ nmin
) / 2 in
1198 let vy, h
= rowyh cl
b n in
1200 if conf.presentation
1202 let ips = calcips h
in
1203 let y0 = vy - ips in
1204 let y1 = vy + h
+ ips in
1208 then 0, vy + h
+ conf.interpagespace
1210 let y0 = vy - conf.interpagespace
in
1211 y0, y0 + h
+ conf.interpagespace
1214 if y >= y0 && y < y1
1221 if n < state.pagecount
- coverB
1222 then ((n-coverA
)/c)*c + coverA
1229 then bsearch (n+1) nmax
1230 else bsearch nmin
(n-1)
1233 let r = bsearch 0 (state.pagecount
-1) in
1237 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1238 let sh = sh - state.hscrollh
in
1239 let rec fold accu
n =
1240 if n = Array.length
b
1243 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1246 || n = state.pagecount
- coverB
1247 || (n - coverA
) mod columns
= columns
- 1)
1253 let pagey = max
0 (y - vy) in
1254 let pagedispy = if pagey > 0 then 0 else vy - y in
1255 let pagedispx, pagex
=
1257 if n = coverA
- 1 || n = state.pagecount
- coverB
1258 then state.x + (state.winw
- state.scrollw
- w
) / 2
1259 else dx + xoff
+ state.x
1266 let vw = state.winw
- state.scrollw
- pagedispx in
1267 let pw = w
- pagex
in
1270 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1271 if pagevw > 0 && pagevh > 0
1275 ; pagedimno
= pdimno
1282 ; pagedispx = pagedispx
1283 ; pagedispy = pagedispy
1295 List.rev
(fold [] (page_of_y y));
1298 let layoutS (columns
, b) y sh =
1299 let sh = sh - state.hscrollh
in
1300 let rec fold accu n =
1301 if n = Array.length
b
1304 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1311 let x = xoff
+ state.x in
1312 let pagey = max
0 (y - vy) in
1313 let pagedispy = if pagey > 0 then 0 else vy - y in
1314 let pagedispx, pagex
=
1328 let pagecolw = pagew
/columns
in
1330 if pagecolw < state.winw
1331 then pagedispx + ((state.winw
- state.scrollw
- pagecolw) / 2)
1335 let vw = state.winw
- pagedispx - state.scrollw
in
1336 let pw = pagew
- pagex
in
1339 let pagevw = min
pagevw pagecolw in
1340 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1341 if pagevw > 0 && pagevh > 0
1344 { pageno = n/columns
1345 ; pagedimno
= pdimno
1352 ; pagedispx = pagedispx
1353 ; pagedispy = pagedispy
1354 ; pagecol
= n mod columns
1365 List.rev
(fold [] 0)
1369 if nogeomcmds state.geomcmds
1371 match conf.columns
with
1372 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1373 | Cmulti
c -> layoutN c y sh
1374 | Csplit
s -> layoutS s y sh
1379 let y = state.y + incr
in
1381 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1386 let tilex = l
.pagex
mod conf.tilew
in
1387 let tiley = l
.pagey mod conf.tileh
in
1389 let col = l
.pagex
/ conf.tilew
in
1390 let row = l
.pagey / conf.tileh
in
1392 let rec rowloop row y0 dispy h
=
1396 let dh = conf.tileh
- y0 in
1397 let dh = min h
dh in
1398 let rec colloop col x0 dispx w
=
1402 let dw = conf.tilew
- x0 in
1403 let dw = min w
dw in
1405 f col row dispx dispy
x0 y0 dw dh;
1406 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1409 colloop col tilex l
.pagedispx l
.pagevw;
1410 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1413 if l
.pagevw > 0 && l
.pagevh > 0
1414 then rowloop row tiley l
.pagedispy l
.pagevh;
1417 let gettileopaque l
col row =
1419 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1421 try Some
(Hashtbl.find state.tilemap
key)
1422 with Not_found
-> None
1425 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1426 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1427 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1430 let drawtiles l color
=
1432 let f col row x y tilex tiley w h
=
1433 match gettileopaque l
col row with
1434 | Some
(opaque
, _, t
) ->
1435 let params = x, y, w
, h
, tilex, tiley in
1439 GlFunc.blend_func `zero `one_minus_src_color
;
1441 drawtile
params opaque
;
1443 then Gl.disable `blend
;
1446 let s = Printf.sprintf
1450 let w = measurestr
fstate.fontsize
s in
1451 GlMisc.push_attrib
[`current
];
1452 GlDraw.color
(0.0, 0.0, 0.0);
1454 (float (x-2), float (y-2))
1455 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1456 GlDraw.color
(1.0, 1.0, 1.0);
1457 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1458 GlMisc.pop_attrib
();
1463 let lw = state.winw
- state.scrollw
- x in
1466 let lh = state.winh
- y in
1469 begin match state.texid
with
1471 Gl.enable `texture_2d
;
1472 GlTex.bind_texture `texture_2d id
;
1475 and x1 = float (x+w)
1476 and y1 = float (y+h
) in
1478 let tw = float w /. 16.0
1479 and th
= float h
/. 16.0 in
1480 let tx0 = float tilex /. 16.0
1481 and ty0
= float tiley /. 16.0 in
1483 and ty1
= ty0
+. th
in
1484 GlDraw.begins `quads
;
1485 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1486 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1487 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1488 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1491 Gl.disable `texture_2d
;
1493 GlDraw.color
(1.0, 1.0, 1.0);
1496 (float (x+w), float (y+h
));
1498 if w > 128 && h
> fstate.fontsize
+ 10
1500 GlDraw.color
(0.0, 0.0, 0.0);
1503 then (col*conf.tilew
, row*conf.tileh
)
1506 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1513 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1515 let tilevisible1 l
x y =
1517 and ax1
= l
.pagex
+ l
.pagevw
1519 and ay1
= l
.pagey + l
.pagevh in
1523 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1524 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1526 let rx0 = max
ax0 bx0
1527 and ry0
= max ay0 by0
1528 and rx1
= min ax1
bx1
1529 and ry1
= min ay1 by1
in
1531 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1532 nonemptyintersection
1535 let tilevisible layout n x y =
1536 let rec findpageinlayout m
= function
1537 | l
:: rest
when l
.pageno = n ->
1538 tilevisible1 l
x y || (
1539 match conf.columns
with
1540 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1543 | _ :: rest
-> findpageinlayout 0 rest
1546 findpageinlayout 0 layout;
1549 let tileready l
x y =
1550 tilevisible1 l
x y &&
1551 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1554 let tilepage n p
layout =
1555 let rec loop = function
1559 let f col row _ _ _ _ _ _ =
1560 if state.currently
= Idle
1562 match gettileopaque l
col row with
1565 let x = col*conf.tilew
1566 and y = row*conf.tileh
in
1568 let w = l
.pagew
- x in
1572 let h = l
.pageh
- y in
1577 then getpbo
w h conf.colorspace
1580 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1583 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1584 conf.tilew
, conf.tileh
1593 if nogeomcmds state.geomcmds
1597 let preloadlayout y =
1598 let y = if y < state.winh
then 0 else y - state.winh
in
1599 let h = state.winh
*3 in
1604 let rec loop pages
=
1605 if state.currently
!= Idle
1610 begin match getopaque l
.pageno with
1612 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1613 state.currently
<- Loading
(l
, state.gen
);
1615 tilepage l
.pageno opaque pages
;
1620 if nogeomcmds state.geomcmds
1626 if conf.preload && state.currently
= Idle
1627 then load (preloadlayout state.y);
1630 let layoutready layout =
1631 let rec fold all ls
=
1632 all
&& match ls
with
1634 let seen = ref false in
1635 let allvisible = ref true in
1636 let foo col row _ _ _ _ _ _ =
1638 allvisible := !allvisible &&
1639 begin match gettileopaque l
col row with
1645 fold (!seen && !allvisible) rest
1648 let alltilesvisible = fold true layout in
1653 let y = bound y 0 state.maxy
in
1654 let y, layout, proceed
=
1655 match conf.maxwait
with
1656 | Some time
when state.ghyll
== noghyll ->
1657 begin match state.throttle
with
1659 let layout = layout y state.winh
in
1660 let ready = layoutready layout in
1664 state.throttle
<- Some
(layout, y, now ());
1666 else G.postRedisplay "gotoy showall (None)";
1668 | Some
(_, _, started
) ->
1669 let dt = now () -. started
in
1672 state.throttle
<- None
;
1673 let layout = layout y state.winh
in
1675 G.postRedisplay "maxwait";
1682 let layout = layout y state.winh
in
1683 if not
!wtmode || layoutready layout
1684 then G.postRedisplay "gotoy ready";
1690 state.layout <- layout;
1691 begin match state.mode
with
1692 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1693 let rec loop = function
1695 state.mode
<- LinkNav
(Ltgendir
0)
1696 | l
:: _ when l
.pageno = pageno ->
1697 begin match getopaque pageno with
1699 state.mode
<- LinkNav
(Ltgendir
0)
1701 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1702 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1703 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1704 then state.mode
<- LinkNav
(Ltgendir
0)
1706 | _ :: rest
-> loop rest
1711 begin match state.mode
with
1712 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1713 if not
(pagevisible layout pageno)
1715 match state.layout with
1718 state.mode
<- Birdseye
(
1719 conf, leftx
, l
.pageno, hooverpageno
, anchor
1722 | LinkNav
(Ltgendir dir
as lt
) ->
1724 let rec loop = function
1727 match getopaque l
.pageno with
1733 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1735 if dir
> 0 then LDfirst
else LDlast
1741 | Lnotfound
-> loop rest
1743 showlinktype (getlink opaque
n);
1744 Ltexact
(l
.pageno, n)
1748 state.mode
<- LinkNav
linknav
1753 state.ghyll
<- noghyll;
1756 let mx, my
= state.mpos
in
1761 let conttiling pageno opaque
=
1762 tilepage pageno opaque
1763 (if conf.preload then preloadlayout state.y else state.layout)
1766 let gotoy_and_clear_text y =
1767 if not
conf.verbose
then state.text <- "";
1773 let coloff = l
.pagecol
* l
.pageh
in
1774 float (l
.pagey + coloff) /. float l
.pageh
1781 if conf.presentation
1782 then float l
.pagedispy /. float (calcips l
.pageh
)
1783 else float l
.pagedispy /. float conf.interpagespace
1785 (l
.pageno, top, dtop)
1789 match state.layout with
1790 | l
:: _ -> getanchor1 l
1792 let n = page_of_y state.y in
1796 let y, h = getpageyh n in
1797 let dy = y - state.y in
1799 if conf.presentation
1801 let ips = calcips h in
1802 float (dy + ips) /. float ips
1804 float dy /. float conf.interpagespace
1809 let getanchory (n, top, dtop) =
1810 let y, h = getpageyh n in
1811 if conf.presentation
1813 let ips = calcips h in
1814 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1816 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1819 let gotoanchor anchor
=
1820 gotoy (getanchory anchor
);
1824 cbput state.hists
.nav
(getanchor ());
1828 let anchor = cbgetc state.hists
.nav dir
in
1833 let scroll f n a
b =
1834 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1836 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1838 then s (float f /. float a
)
1841 then 1.0 -. s ((float (f-b) /. float (n-b)))
1848 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1849 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1851 let ins = float a
*. iv1
1852 and outs
= float (n-b) *. iv1 in
1854 ins +. outs
+. float ones
1856 let rec set (_N
, _A
, _B
) y sy
=
1857 let sum = summa
1.0 _N _A _B
in
1858 let dy = float (y - sy
) in
1862 then state.ghyll
<- noghyll
1865 let s = scroll n _N _A _B
in
1866 let y1 = y1 +. ((s *. dy) /. sum) in
1867 gotoy_and_clear_text (truncate
y1);
1868 state.ghyll
<- gf (n+1) y1;
1872 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1874 gf 0 (float state.y)
1877 match conf.ghyllscroll
with
1879 gotoy_and_clear_text y
1881 if state.ghyll
== noghyll
1882 then set nab
y state.y
1883 else state.ghyll
(Some
y)
1886 let gotopage n top =
1887 let y, h = getpageyh n in
1888 let y = y + (truncate
(top *. float h)) in
1892 let gotopage1 n top =
1893 let y = getpagey n in
1898 let invalidate s f =
1903 match state.geomcmds
with
1904 | ps
, [] when String.length ps
= 0 ->
1906 state.geomcmds
<- s, [];
1909 state.geomcmds
<- ps
, [s, f];
1911 | ps
, (s'
, _) :: rest
when s'
= s ->
1912 state.geomcmds
<- ps
, ((s, f) :: rest
);
1915 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1919 Hashtbl.iter
(fun _ opaque
->
1920 wcmd "freepage %s" opaque
;
1922 Hashtbl.clear
state.pagemap
;
1926 if not
(Queue.is_empty
state.tilelru
)
1928 Queue.iter
(fun (k
, p
, s) ->
1929 wcmd "freetile %s" p
;
1930 state.memused
<- state.memused
- s;
1931 Hashtbl.remove
state.tilemap k
;
1933 state.uioh#infochanged Memused
;
1934 Queue.clear
state.tilelru
;
1939 let opendoc path password
=
1941 state.password
<- password
;
1942 state.gen
<- state.gen
+ 1;
1943 state.docinfo
<- [];
1946 setaalevel
conf.aalevel
;
1947 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1948 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
1949 invalidate "reqlayout"
1951 wcmd "reqlayout %d %d %s\000"
1952 conf.angle
(int_of_fitmodel conf.fitmodel
) state.nameddest
;
1957 state.anchor <- getanchor ();
1958 opendoc state.path
state.password
;
1962 let c = c *. conf.colorscale
in
1966 let scalecolor2 (r, g, b) =
1967 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
1970 let docolumns = function
1972 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1973 let rec loop pageno pdimno pdim
y ph pdims
=
1974 if pageno = state.pagecount
1977 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1979 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1980 pdimno+1, pdim
, rest
1984 let x = max
0 (((state.winw
- state.scrollw
- w) / 2) - xoff
) in
1986 (if conf.presentation
1987 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1988 else (if pageno = 0 then 0 else conf.interpagespace
)
1991 a.(pageno) <- (pdimno, x, y, pdim
);
1992 loop (pageno+1) pdimno pdim
(y + h) h pdims
1994 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1995 conf.columns
<- Csingle
a;
1997 | Cmulti
((columns
, coverA
, coverB
), _) ->
1998 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1999 let rec loop pageno pdimno pdim
x y rowh pdims
=
2000 let rec fixrow m
= if m
= pageno then () else
2001 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2004 let y = y + (rowh
- h) / 2 in
2005 a.(m
) <- (pdimno, x, y, pdim
);
2009 if pageno = state.pagecount
2010 then fixrow (((pageno - 1) / columns
) * columns
)
2012 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2014 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2015 pdimno+1, pdim
, rest
2020 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2022 let x = (state.winw
- state.scrollw
- w) / 2 in
2024 if conf.presentation
then calcips h else conf.interpagespace
in
2025 x, y + ips + rowh
, h
2028 if (pageno - coverA
) mod columns
= 0
2030 let x = max
0 (state.winw
- state.scrollw
- state.w) / 2 in
2032 if conf.presentation
2034 let ips = calcips h in
2035 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2037 y + (if pageno = 0 then 0 else conf.interpagespace
)
2041 else x, y, max rowh
h
2045 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2048 if pageno = columns
&& conf.presentation
2050 let ips = calcips rowh
in
2051 for i
= 0 to pred columns
2053 let (pdimno, x, y, pdim
) = a.(i
) in
2054 a.(i
) <- (pdimno, x, y+ips, pdim
)
2060 fixrow (pageno - columns
);
2065 a.(pageno) <- (pdimno, x, y, pdim
);
2066 let x = x + w + xoff
*2 + conf.interpagespace
in
2067 loop (pageno+1) pdimno pdim
x y rowh' pdims
2069 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2070 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2073 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2074 let rec loop pageno pdimno pdim
y pdims
=
2075 if pageno = state.pagecount
2078 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2080 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2081 pdimno+1, pdim
, rest
2086 let rec loop1 n x y =
2087 if n = c then y else (
2088 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2089 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2092 let y = loop1 0 0 y in
2093 loop (pageno+1) pdimno pdim
y pdims
2095 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2096 conf.columns
<- Csplit
(c, a);
2100 docolumns conf.columns
;
2101 state.maxy
<- calcheight ();
2103 if state.x = 0 && state.w <= state.winw
- state.scrollw
2107 if state.reprf
== noreprf
2109 match state.mode
with
2110 | Birdseye
(_, _, pageno, _, _) ->
2111 let y, h = getpageyh pageno in
2112 let top = (state.winh
- h) / 2 in
2113 gotoy (max
0 (y - top))
2114 | _ -> gotoanchor state.anchor
2118 state.reprf
<- noreprf;
2123 GlDraw.viewport
0 0 w h;
2124 let firsttime = state.geomcmds
== firstgeomcmds in
2125 if not
firsttime && nogeomcmds state.geomcmds
2126 then state.anchor <- getanchor ();
2129 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2132 setfontsize fstate.fontsize
;
2133 GlMat.mode `modelview
;
2134 GlMat.load_identity
();
2136 GlMat.mode `projection
;
2137 GlMat.load_identity
();
2138 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2139 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2140 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2145 else float state.x /. float state.w
2147 invalidate "geometry"
2151 then state.x <- truncate
(relx *. float w);
2153 match conf.columns
with
2155 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2156 | Csplit
(c, _) -> w * c
2158 wcmd "geometry %d %d" w (h - conf.interpagespace
));
2162 let len = String.length
state.text in
2165 match state.mode
with
2168 let h, _, _ = state.uioh#scrollpw
in
2174 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2175 (x+.w, float (state.winh
- hscrollh))
2178 let w = float (state.winw
- state.scrollw
- 1) in
2179 if state.progress
>= 0.0 && state.progress
< 1.0
2181 GlDraw.color
(0.3, 0.3, 0.3);
2182 let w1 = w *. state.progress
in
2184 GlDraw.color
(0.0, 0.0, 0.0);
2188 GlDraw.color
(0.0, 0.0, 0.0);
2192 GlDraw.color
(1.0, 1.0, 1.0);
2193 drawstring fstate.fontsize
2194 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2197 match state.mode
with
2198 | Textentry
((prefix
, text, _, _, _, _), _) ->
2202 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2204 Printf.sprintf
"%s%s_" prefix
text
2213 if not
(istextentry state.mode
) && state.uioh#eformsgs
2215 let s1 = "(press 'e' to review error messasges)" in
2216 if String.length
s > 0 then s ^
" " ^
s1 else s1
2221 if String.length
s > 0
2226 let len = Queue.length
state.tilelru
in
2228 match state.throttle
with
2231 then preloadlayout state.y
2233 | Some
(layout, _, _) ->
2237 if state.memused
<= conf.memlimit
2242 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2243 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2244 let (_, pw, ph
, _) = getpagedim n in
2247 && colorspace
= conf.colorspace
2248 && angle
= conf.angle
2252 let x = col*conf.tilew
2253 and y = row*conf.tileh
in
2254 tilevisible (Lazy.force_val
layout) n x y
2256 then Queue.push lruitem
state.tilelru
2259 wcmd "freetile %s" p
;
2260 state.memused
<- state.memused
- s;
2261 state.uioh#infochanged Memused
;
2262 Hashtbl.remove
state.tilemap k
;
2270 let logcurrently = function
2271 | Idle
-> dolog
"Idle"
2272 | Loading
(l
, gen
) ->
2273 dolog
"Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2274 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2276 "Tiling %d[%d,%d] page=%s cs=%s angle"
2277 l
.pageno col row pageopaque
2278 (colorspace_to_string colorspace
)
2280 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2281 angle gen
conf.angle
state.gen
2283 conf.tilew
conf.tileh
2290 let r = Str.regexp
" " in
2291 fun s -> Str.bounded_split
r s 2;
2294 let onpagerect pageno f =
2296 match conf.columns
with
2297 | Cmulti
(_, b) -> b
2299 | Csplit
(_, b) -> b
2301 if pageno >= 0 && pageno < Array.length
b
2303 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2304 let r = getpdimrect
pdimno in
2305 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2308 let gotopagexy1 pageno x y =
2309 onpagerect pageno (fun w h ->
2311 let _,w1,_,leftx
= getpagedim pageno in
2312 let wh = state.winh
- state.hscrollh in
2313 let sw = float w1 /. w in
2315 let x = leftx
+ state.x + truncate
x in
2317 if x < 0 || x >= state.winw
- state.scrollw
2321 let py, h = getpageyh pageno in
2322 let pdy = truncate
(top *. float h) in
2323 let y'
= py + pdy in
2324 let dy = y'
- state.y in
2326 if x != state.x || not
(dy > 0 && dy < wh)
2328 if conf.presentation
2330 if abs
(py - y'
) > wh
2337 if state.x != sx || state.y != sy
2342 let ww = state.winw
- state.scrollw
in
2344 and qy
= pdy / wh in
2346 and y = py + qy
* wh in
2347 let x = if -x + ww > w1 then -(w1-ww) else x
2348 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2350 if conf.presentation
2352 if abs
(py - y'
) > wh
2363 if x = 0 && state.w <= state.winw
- state.scrollw
2367 gotoy_and_clear_text y;
2369 else gotoy_and_clear_text state.y;
2373 let gotopagexy pageno x y =
2374 match state.mode
with
2375 | Birdseye
_ -> gotopage pageno 0.0
2376 | _ -> gotopagexy1 pageno x y
2380 (* dolog "%S" cmds; *)
2381 let cl = splitatspace cmds
in
2383 try Scanf.sscanf
s fmt
f
2385 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2390 state.uioh#infochanged Pdim
;
2393 | "clearrects" :: [] ->
2394 state.rects
<- state.rects1
;
2395 G.postRedisplay "clearrects";
2397 | "continue" :: args :: [] ->
2398 let n = scan args "%u" (fun n -> n) in
2399 state.pagecount
<- n;
2400 begin match state.currently
with
2402 state.currently
<- Idle
;
2403 state.outlines
<- Array.of_list
(List.rev l
)
2407 let cur, cmds
= state.geomcmds
in
2408 if String.length
cur = 0
2409 then failwith
"umpossible";
2411 begin match List.rev cmds
with
2413 state.geomcmds
<- "", [];
2417 state.geomcmds
<- s, List.rev rest
;
2419 if conf.maxwait
= None
&& not
!wtmode
2420 then G.postRedisplay "continue";
2422 | "title" :: args :: [] ->
2425 | "msg" :: args :: [] ->
2428 | "vmsg" :: args :: [] ->
2430 then showtext ' '
args
2432 | "emsg" :: args :: [] ->
2433 Buffer.add_string
state.errmsgs
args;
2434 state.newerrmsgs
<- true;
2435 G.postRedisplay "error message"
2437 | "progress" :: args :: [] ->
2438 let progress, text =
2441 f, String.sub
args pos
(String.length
args - pos
))
2444 state.progress <- progress;
2445 G.postRedisplay "progress"
2447 | "firstmatch" :: args :: [] ->
2448 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2449 scan args "%u %d %f %f %f %f %f %f %f %f"
2450 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2451 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2453 let y = (getpagey pageno) + truncate
y0 in
2456 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2458 | "match" :: args :: [] ->
2459 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2460 scan args "%u %d %f %f %f %f %f %f %f %f"
2461 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2462 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2465 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2467 | "page" :: args :: [] ->
2468 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2469 begin match state.currently
with
2470 | Loading
(l
, gen
) ->
2471 vlog "page %d took %f sec" l
.pageno t
;
2472 Hashtbl.replace
state.pagemap
(l
.pageno, gen
) pageopaque;
2473 begin match state.throttle
with
2475 let preloadedpages =
2477 then preloadlayout state.y
2482 Set.Make
(struct type t
= int let compare = (-) end) in
2484 List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
2485 IntSet.empty
preloadedpages
2488 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2489 if not
(IntSet.mem
pageno set)
2491 wcmd "freepage %s" opaque
;
2497 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2500 state.currently
<- Idle
;
2503 tilepage l
.pageno pageopaque state.layout;
2505 load preloadedpages;
2506 if pagevisible state.layout l
.pageno
2507 && layoutready state.layout
2508 then G.postRedisplay "page";
2511 | Some
(layout, _, _) ->
2512 state.currently
<- Idle
;
2513 tilepage l
.pageno pageopaque layout;
2518 dolog
"Inconsistent loading state";
2519 logcurrently state.currently
;
2523 | "tile" :: args :: [] ->
2524 let (x, y, opaque
, size
, t
) =
2525 scan args "%u %u %s %u %f"
2526 (fun x y p size t
-> (x, y, p
, size
, t
))
2528 begin match state.currently
with
2529 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2530 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
2533 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2535 wcmd "freetile %s" opaque
;
2536 state.currently
<- Idle
;
2540 puttileopaque l
col row gen cs angle opaque size t
;
2541 state.memused
<- state.memused
+ size
;
2542 state.uioh#infochanged Memused
;
2544 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
2545 opaque
, size
) state.tilelru
;
2548 match state.throttle
with
2549 | None
-> state.layout
2550 | Some
(layout, _, _) -> layout
2553 state.currently
<- Idle
;
2555 && conf.colorspace
= cs
2556 && conf.angle
= angle
2557 && tilevisible layout l
.pageno x y
2558 then conttiling l
.pageno pageopaque;
2560 begin match state.throttle
with
2562 preload state.layout;
2564 && conf.colorspace
= cs
2565 && conf.angle
= angle
2566 && tilevisible state.layout l
.pageno x y
2567 && (not
!wtmode || layoutready state.layout)
2568 then G.postRedisplay "tile nothrottle";
2570 | Some
(layout, y, _) ->
2571 let ready = layoutready layout in
2575 state.layout <- layout;
2576 state.throttle
<- None
;
2577 G.postRedisplay "throttle";
2584 dolog
"Inconsistent tiling state";
2585 logcurrently state.currently
;
2589 | "pdim" :: args :: [] ->
2591 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2593 state.uioh#infochanged Pdim
;
2594 state.pdims
<- pdim :: state.pdims
2596 | "o" :: args :: [] ->
2597 let (l
, n, t
, h, pos
) =
2598 scan args "%u %u %d %u %n"
2599 (fun l
n t
h pos
-> l
, n, t
, h, pos
)
2601 let s = String.sub
args pos
(String.length
args - pos
) in
2602 let outline = (s, l
, (n, float t
/. float h, 0.0)) in
2603 begin match state.currently
with
2604 | Outlining outlines
->
2605 state.currently
<- Outlining
(outline :: outlines
)
2607 state.currently
<- Outlining
[outline]
2609 dolog
"invalid outlining state";
2610 logcurrently currently
2613 | "a" :: args :: [] ->
2615 scan args "%u %d %d" (fun n l t
-> n, l
, t
)
2617 state.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
2619 | "info" :: args :: [] ->
2620 state.docinfo
<- (1, args) :: state.docinfo
2622 | "infoend" :: [] ->
2623 state.uioh#infochanged Docinfo
;
2624 state.docinfo
<- List.rev
state.docinfo
2627 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2632 let action = function
2633 | HCprev
-> cbget cb ~
-1
2634 | HCnext
-> cbget cb
1
2635 | HCfirst
-> cbget cb ~
-(cb
.rc)
2636 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2637 and cancel
() = cb
.rc <- rc
2641 let search pattern forward
=
2642 if String.length pattern
> 0
2645 match state.layout with
2648 l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
2650 wcmd "search %d %d %d %d,%s\000"
2651 (btod conf.icase
) pn py (btod forward
) pattern
;
2654 let intentry text key =
2656 if key >= 32 && key < 127
2662 let text = addchar text c in
2666 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2670 let linknentry text key =
2672 if key >= 32 && key < 127
2678 let text = addchar text c in
2682 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2687 if String.length
s > 0
2690 let l = String.length
s in
2691 let rec loop pos
n = if pos
= l then n else
2692 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2693 loop (pos
+1) (n*26 + m)
2696 let rec loop n = function
2699 match getopaque l.pageno with
2700 | None
-> loop n rest
2702 let m = getlinkcount opaque
in
2705 let under = getlink opaque
n in
2708 else loop (n-m) rest
2710 loop n state.layout;
2714 let textentry text key =
2715 if key land 0xff00 = 0xff00
2717 else TEcont
(text ^ toutf8
key)
2720 let reqlayout angle fitmodel
=
2721 match state.throttle
with
2723 if nogeomcmds state.geomcmds
2724 then state.anchor <- getanchor ();
2725 conf.angle
<- angle
mod 360;
2728 match state.mode
with
2729 | LinkNav
_ -> state.mode
<- View
2732 conf.fitmodel
<- fitmodel
;
2733 invalidate "reqlayout"
2735 wcmd "reqlayout %d %d" conf.angle
(int_of_fitmodel fitmodel
));
2739 let settrim trimmargins trimfuzz
=
2740 if nogeomcmds state.geomcmds
2741 then state.anchor <- getanchor ();
2742 conf.trimmargins
<- trimmargins
;
2743 conf.trimfuzz
<- trimfuzz
;
2744 let x0, y0, x1, y1 = trimfuzz
in
2745 invalidate "settrim"
2747 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2752 match state.throttle
with
2754 let zoom = max
0.0001 zoom in
2755 if zoom <> conf.zoom
2757 state.prevzoom
<- conf.zoom;
2759 reshape state.winw
state.winh
;
2760 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2763 | Some
(layout, y, started
) ->
2765 match conf.maxwait
with
2769 let dt = now () -. started
in
2777 let setcolumns mode columns coverA coverB
=
2778 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2782 then showtext '
!'
"split mode doesn't work in bird's eye"
2784 conf.columns
<- Csplit
(-columns
, [||]);
2792 conf.columns
<- Csingle
[||];
2797 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2801 reshape state.winw
state.winh
;
2804 let enterbirdseye () =
2805 let zoom = float conf.thumbw
/. float state.winw
in
2806 let birdseyepageno =
2807 let cy = state.winh
/ 2 in
2811 let rec fold best
= function
2814 let d = cy - (l.pagedispy + l.pagevh/2)
2815 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2816 if abs
d < abs dbest
2823 state.mode
<- Birdseye
(
2824 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2827 conf.presentation
<- false;
2828 conf.interpagespace
<- 10;
2829 conf.hlinks
<- false;
2831 state.mstate
<- Mnone
;
2832 conf.maxwait
<- None
;
2834 match conf.beyecolumns
with
2837 Cmulti
((c, 0, 0), [||])
2838 | None
-> Csingle
[||]
2840 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2843 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2848 reshape state.winw
state.winh
;
2851 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2853 conf.zoom <- c.zoom;
2854 conf.presentation
<- c.presentation
;
2855 conf.interpagespace
<- c.interpagespace
;
2856 conf.maxwait
<- c.maxwait
;
2857 conf.hlinks
<- c.hlinks
;
2858 conf.beyecolumns
<- (
2859 match conf.columns
with
2860 | Cmulti
((c, _, _), _) -> Some
c
2862 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2865 match c.columns
with
2866 | Cmulti
(c, _) -> Cmulti
(c, [||])
2867 | Csingle
_ -> Csingle
[||]
2868 | Csplit
(c, _) -> Csplit
(c, [||])
2873 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2876 reshape state.winw
state.winh
;
2877 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2880 let togglebirdseye () =
2881 match state.mode
with
2882 | Birdseye vals
-> leavebirdseye vals
true
2883 | View
-> enterbirdseye ()
2887 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2888 let pageno = max
0 (pageno - incr
) in
2889 let rec loop = function
2890 | [] -> gotopage1 pageno 0
2891 | l :: _ when l.pageno = pageno ->
2892 if l.pagedispy >= 0 && l.pagey = 0
2893 then G.postRedisplay "upbirdseye"
2894 else gotopage1 pageno 0
2895 | _ :: rest
-> loop rest
2898 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2901 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2902 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2903 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2904 let rec loop = function
2906 let y, h = getpageyh pageno in
2907 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2909 | l :: _ when l.pageno = pageno ->
2910 if l.pagevh != l.pageh
2911 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2912 else G.postRedisplay "downbirdseye"
2913 | _ :: rest
-> loop rest
2918 let optentry mode
_ key =
2919 let btos b = if b then "on" else "off" in
2920 if key >= 32 && key < 127
2922 let c = Char.chr
key in
2926 try conf.scrollstep
<- int_of_string
s with exc
->
2927 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2929 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2934 conf.autoscrollstep
<- int_of_string
s;
2935 if state.autoscroll
<> None
2936 then state.autoscroll
<- Some
conf.autoscrollstep
2938 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2940 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2945 let n, a, b = multicolumns_of_string s in
2946 setcolumns mode
n a b;
2948 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
2950 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2955 let zoom = float (int_of_string
s) /. 100.0 in
2958 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2960 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2965 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2967 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2968 begin match mode
with
2970 leavebirdseye beye
false;
2975 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2977 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2982 Some
(int_of_string
s)
2984 state.text <- Printf.sprintf
"bad integer `%s': %s"
2988 | Some angle
-> reqlayout angle
conf.fitmodel
2991 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2994 conf.icase
<- not
conf.icase
;
2995 TEdone
("case insensitive search " ^
(btos conf.icase
))
2998 conf.preload <- not
conf.preload;
3000 TEdone
("preload " ^
(btos conf.preload))
3003 conf.verbose
<- not
conf.verbose
;
3004 TEdone
("verbose " ^
(btos conf.verbose
))
3007 conf.debug
<- not
conf.debug
;
3008 TEdone
("debug " ^
(btos conf.debug
))
3011 conf.maxhfit
<- not
conf.maxhfit
;
3012 state.maxy
<- calcheight ();
3013 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3016 conf.crophack
<- not
conf.crophack
;
3017 TEdone
("crophack " ^
btos conf.crophack
)
3021 match conf.maxwait
with
3023 conf.maxwait
<- Some infinity
;
3024 "always wait for page to complete"
3026 conf.maxwait
<- None
;
3027 "show placeholder if page is not ready"
3032 conf.underinfo
<- not
conf.underinfo
;
3033 TEdone
("underinfo " ^
btos conf.underinfo
)
3036 conf.savebmarks
<- not
conf.savebmarks
;
3037 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3043 match state.layout with
3048 conf.interpagespace
<- int_of_string
s;
3049 docolumns conf.columns
;
3050 state.maxy
<- calcheight ();
3051 let y = getpagey pageno in
3054 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3056 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3060 match conf.fitmodel
with
3061 | FitProportional
-> FitWidth
3062 | _ -> FitProportional
3064 reqlayout conf.angle
fm;
3065 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3068 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3069 TEdone
("trim margins " ^
btos conf.trimmargins
)
3072 conf.invert
<- not
conf.invert
;
3073 TEdone
("invert colors " ^
btos conf.invert
)
3077 cbput state.hists
.sel
s;
3080 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3081 textentry, ondone, true)
3084 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3090 class type lvsource
= object
3091 method getitemcount
: int
3092 method getitem
: int -> (string * int)
3093 method hasaction
: int -> bool
3102 method getactive
: int
3103 method getfirst
: int
3104 method getqsearch
: string
3105 method setqsearch
: string -> unit
3109 class virtual lvsourcebase
= object
3110 val mutable m_active
= 0
3111 val mutable m_first
= 0
3112 val mutable m_qsearch
= ""
3113 val mutable m_pan
= 0
3114 method getactive
= m_active
3115 method getfirst
= m_first
3116 method getqsearch
= m_qsearch
3117 method getpan
= m_pan
3118 method setqsearch
s = m_qsearch
<- s
3121 let withoutlastutf8 s =
3122 let len = String.length
s in
3130 let b = Char.code
s.[pos
] in
3131 if b land 0b11000000 = 0b11000000
3136 if Char.code
s.[len-1] land 0x80 = 0
3140 String.sub
s 0 first;
3143 let textentrykeyboard
3144 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3146 if key >= 0xffb0 && key <= 0xffb9
3147 then key - 0xffb0 + 48 else key
3150 state.mode
<- Textentry
(te
, onleave
);
3153 G.postRedisplay "textentrykeyboard enttext";
3155 let histaction cmd
=
3158 | Some
(action, _) ->
3159 state.mode
<- Textentry
(
3160 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3162 G.postRedisplay "textentry histaction"
3165 | 0xff08 -> (* backspace *)
3166 let s = withoutlastutf8 text in
3167 let len = String.length
s in
3168 if cancelonempty
&& len = 0
3171 G.postRedisplay "textentrykeyboard after cancel";
3174 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3177 | 0xff0d | 0xff8d -> (* (kp) enter *)
3180 G.postRedisplay "textentrykeyboard after confirm"
3182 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3183 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3184 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3185 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3187 | 0xff1b -> (* escape*)
3188 if String.length
text = 0
3190 begin match opthist
with
3192 | Some
(_, onhistcancel
) -> onhistcancel
()
3196 G.postRedisplay "textentrykeyboard after cancel2"
3199 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3202 | 0xff9f | 0xffff -> () (* delete *)
3205 && key land 0xff00 != 0xff00 (* keyboard *)
3206 && key land 0xfe00 != 0xfe00 (* xkb *)
3207 && key land 0xfd00 != 0xfd00 (* 3270 *)
3209 begin match onkey
text key with
3213 G.postRedisplay "textentrykeyboard after confirm2";
3216 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3220 G.postRedisplay "textentrykeyboard after cancel3"
3223 state.mode
<- Textentry
(te
, onleave
);
3224 G.postRedisplay "textentrykeyboard switch";
3228 vlog "unhandled key %s" (Wsi.keyname
key)
3231 let firstof first active
=
3232 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3233 then max
0 (active
- (fstate.maxrows
/2))
3237 let calcfirst first active
=
3240 let rows = active
- first in
3241 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3245 let scrollph y maxy
=
3246 let sh = (float (maxy
+ state.winh
) /. float state.winh
) in
3247 let sh = float state.winh
/. sh in
3248 let sh = max
sh (float conf.scrollh
) in
3253 else float y /. float maxy
3255 let position = (float state.winh
-. sh) *. percent in
3258 if position +. sh > float state.winh
3259 then float state.winh
-. sh
3265 let coe s = (s :> uioh
);;
3267 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3269 val m_pan
= source#getpan
3270 val m_first
= source#getfirst
3271 val m_active
= source#getactive
3272 val m_qsearch
= source#getqsearch
3273 val m_prev_uioh
= state.uioh
3275 method private elemunder
y =
3276 let n = y / (fstate.fontsize
+1) in
3277 if m_first
+ n < source#getitemcount
3279 if source#hasaction
(m_first
+ n)
3280 then Some
(m_first
+ n)
3287 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3288 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3289 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3290 GlDraw.color
(1., 1., 1.);
3291 Gl.enable `texture_2d
;
3292 let fs = fstate.fontsize
in
3294 let ww = fstate.wwidth
in
3295 let tabw = 30.0*.ww in
3296 let itemcount = source#getitemcount
in
3298 if (row - m_first
) > fstate.maxrows
3301 if row >= 0 && row < itemcount
3303 let (s, level
) = source#getitem
row in
3304 let y = (row - m_first
) * nfs in
3305 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3308 Gl.disable `texture_2d
;
3309 GlDraw.polygon_mode `both `line
;
3310 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3311 GlDraw.color
(1., 1., 1.) ~
alpha;
3312 GlDraw.rect (1., float (y + 1))
3313 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3314 GlDraw.polygon_mode `both `fill
;
3315 GlDraw.color
(1., 1., 1.);
3316 Gl.enable `texture_2d
;
3319 let drawtabularstring s =
3320 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3323 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3326 let len = String.length
s - tabpos - 1 in
3327 let s1 = String.sub
s 0 tabpos
3328 and s2
= String.sub
s (tabpos + 1) len in
3329 let nx = drawstr x s1 in
3331 let x = x +. (max
tabw sw) in
3338 let _ = drawtabularstring s in
3345 Gl.disable `texture_2d
;
3347 method updownlevel incr
=
3348 let len = source#getitemcount
in
3350 if m_active
>= 0 && m_active
< len
3351 then snd
(source#getitem m_active
)
3355 if i
= len then i
-1 else if i
= -1 then 0 else
3356 let _, l = source#getitem i
in
3357 if l != curlevel then i
else flow (i
+incr
)
3359 let active = flow m_active
in
3360 let first = calcfirst m_first
active in
3361 G.postRedisplay "outline updownlevel";
3362 {< m_active
= active; m_first
= first >}
3364 method private key1
key mask
=
3365 let set1 active first qsearch
=
3366 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3368 let search active pattern incr
=
3369 let active = if active = -1 then m_first
else active in
3372 if n >= 0 && n < source#getitemcount
3374 let s, _ = source#getitem
n in
3376 (try ignore
(Str.search_forward
re s 0); true
3377 with Not_found
-> false)
3379 else loop (n + incr
)
3386 let re = Str.regexp_case_fold pattern
in
3392 let itemcount = source#getitemcount
in
3393 let find start incr
=
3395 if i
= -1 || i
= itemcount
3398 if source#hasaction i
3400 else find (i
+ incr
)
3405 let set active first =
3406 let first = bound first 0 (itemcount - fstate.maxrows
) in
3408 coe {< m_active
= active; m_first
= first >}
3411 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3413 let incr1 = if incr
> 0 then 1 else -1 in
3414 if isvisible m_first m_active
3417 let next = m_active
+ incr
in
3419 if next < 0 || next >= itemcount
3421 else find next incr1
3423 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3429 let first = m_first
+ incr
in
3430 let first = bound first 0 (itemcount - 1) in
3432 let next = m_active
+ incr
in
3433 let next = bound next 0 (itemcount - 1) in
3436 let active = if next = -1 then m_active
else next in
3439 let first = min
next m_first
in
3441 if abs
(next - first) > fstate.maxrows
3447 let first = m_first
+ incr
in
3448 let first = bound first 0 (itemcount - 1) in
3450 let next = m_active
+ incr
in
3451 let next = bound next 0 (itemcount - 1) in
3452 let next = find next incr1 in
3454 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3456 let active = if m_active
= -1 then next else m_active
in
3461 if isvisible first active
3467 G.postRedisplay "listview navigate";
3471 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3472 let incr = if key = 0x72 then -1 else 1 in
3474 match search (m_active
+ incr) m_qsearch
incr with
3476 state.text <- m_qsearch ^
" [not found]";
3479 state.text <- m_qsearch
;
3480 active, firstof m_first
active
3482 G.postRedisplay "listview ctrl-r/s";
3483 set1 active first m_qsearch
;
3485 | 0xff08 -> (* backspace *)
3486 if String.length m_qsearch
= 0
3489 let qsearch = withoutlastutf8 m_qsearch
in
3490 let len = String.length
qsearch in
3494 G.postRedisplay "listview empty qsearch";
3495 set1 m_active m_first
"";
3499 match search m_active
qsearch ~
-1 with
3501 state.text <- qsearch ^
" [not found]";
3504 state.text <- qsearch;
3505 active, firstof m_first
active
3507 G.postRedisplay "listview backspace qsearch";
3508 set1 active first qsearch
3511 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3512 let pattern = m_qsearch ^ toutf8
key in
3514 match search m_active
pattern 1 with
3516 state.text <- pattern ^
" [not found]";
3519 state.text <- pattern;
3520 active, firstof m_first
active
3522 G.postRedisplay "listview qsearch add";
3523 set1 active first pattern;
3525 | 0xff1b -> (* escape *)
3527 if String.length m_qsearch
= 0
3529 G.postRedisplay "list view escape";
3532 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3534 | None
-> m_prev_uioh
3539 G.postRedisplay "list view kill qsearch";
3540 source#setqsearch
"";
3541 coe {< m_qsearch
= "" >}
3544 | 0xff0d | 0xff8d -> (* (kp) enter *)
3546 let self = {< m_qsearch
= "" >} in
3547 source#setqsearch
"";
3549 G.postRedisplay "listview enter";
3550 if m_active
>= 0 && m_active
< source#getitemcount
3552 source#exit
(coe self) false m_active m_first m_pan
"";
3555 source#exit
(coe self) true m_active m_first m_pan
"";
3558 begin match opt with
3559 | None
-> m_prev_uioh
3563 | 0xff9f | 0xffff -> (* (kp) delete *)
3566 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3567 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3568 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3569 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3571 | 0xff53 | 0xff98 -> (* (kp) right *)
3573 G.postRedisplay "listview right";
3574 coe {< m_pan
= m_pan
- 1 >}
3576 | 0xff51 | 0xff96 -> (* (kp) left *)
3578 G.postRedisplay "listview left";
3579 coe {< m_pan
= m_pan
+ 1 >}
3581 | 0xff50 | 0xff95 -> (* (kp) home *)
3582 let active = find 0 1 in
3583 G.postRedisplay "listview home";
3586 | 0xff57 | 0xff9c -> (* (kp) end *)
3587 let first = max
0 (itemcount - fstate.maxrows
) in
3588 let active = find (itemcount - 1) ~
-1 in
3589 G.postRedisplay "listview end";
3592 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3596 dolog
"listview unknown key %#x" key; coe self
3598 method key key mask
=
3599 match state.mode
with
3600 | Textentry te
-> textentrykeyboard key mask te
; coe self
3601 | _ -> self#key1
key mask
3603 method button button down
x y _ =
3606 | 1 when x > state.winw
- conf.scrollbw
->
3607 G.postRedisplay "listview scroll";
3610 let _, position, sh = self#
scrollph in
3611 if y > truncate
position && y < truncate
(position +. sh)
3613 state.mstate
<- Mscrolly
;
3617 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3618 let first = truncate
(s *. float source#getitemcount
) in
3619 let first = min source#getitemcount
first in
3620 Some
(coe {< m_first
= first; m_active
= first >})
3622 state.mstate
<- Mnone
;
3625 | 1 when not down
->
3626 begin match self#elemunder
y with
3628 G.postRedisplay "listview click";
3630 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3634 | n when (n == 4 || n == 5) && not down
->
3635 let len = source#getitemcount
in
3637 if n = 5 && m_first
+ fstate.maxrows
>= len
3641 let first = m_first
+ (if n == 4 then -1 else 1) in
3642 bound first 0 (len - 1)
3644 G.postRedisplay "listview wheel";
3645 Some
(coe {< m_first
= first >})
3646 | n when (n = 6 || n = 7) && not down
->
3647 let inc = m_first
+ (if n = 7 then -1 else 1) in
3648 G.postRedisplay "listview hwheel";
3649 Some
(coe {< m_pan
= m_pan
+ inc >})
3654 | None
-> m_prev_uioh
3658 match state.mstate
with
3660 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3661 let first = truncate
(s *. float source#getitemcount
) in
3662 let first = min source#getitemcount
first in
3663 G.postRedisplay "listview motion";
3664 coe {< m_first
= first; m_active
= first >}
3667 method pmotion
x y =
3668 if x < state.winw
- conf.scrollbw
3671 match self#elemunder
y with
3672 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3673 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3677 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3682 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3686 method infochanged
_ = ()
3688 method scrollpw
= (0, 0.0, 0.0)
3690 let nfs = fstate.fontsize
+ 1 in
3691 let y = m_first
* nfs in
3692 let itemcount = source#getitemcount
in
3693 let maxi = max
0 (itemcount - fstate.maxrows
) in
3694 let maxy = maxi * nfs in
3695 let p, h = scrollph y maxy in
3698 method modehash
= modehash
3699 method eformsgs
= false
3702 class outlinelistview ~source
=
3705 ~source
:(source
:> lvsource
)
3707 ~modehash
:(findkeyhash conf "outline")
3710 method key key mask
=
3711 let calcfirst first active =
3714 let rows = active - first in
3716 if String.length
state.text = 0
3718 else fstate.maxrows - 2
3720 if rows > maxrows then active - maxrows else first
3724 let active = m_active
+ incr in
3725 let active = bound active 0 (source#getitemcount
- 1) in
3726 let first = calcfirst m_first
active in
3727 G.postRedisplay "outline navigate";
3728 coe {< m_active
= active; m_first
= first >}
3730 let ctrl = Wsi.withctrl mask
in
3732 | 110 when ctrl -> (* ctrl-n *)
3733 source#narrow m_qsearch
;
3734 G.postRedisplay "outline ctrl-n";
3735 coe {< m_first
= 0; m_active
= 0 >}
3737 | 117 when ctrl -> (* ctrl-u *)
3739 G.postRedisplay "outline ctrl-u";
3741 coe {< m_first
= 0; m_active
= 0 >}
3743 | 108 when ctrl -> (* ctrl-l *)
3744 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3745 G.postRedisplay "outline ctrl-l";
3746 coe {< m_first
= first >}
3748 | 0xff9f | 0xffff -> (* (kp) delete *)
3749 source#remove m_active
;
3750 G.postRedisplay "outline delete";
3751 let active = max
0 (m_active
-1) in
3752 coe {< m_first
= firstof m_first
active;
3753 m_active
= active >}
3755 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3756 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3757 | 0xff55 | 0xff9a -> (* (kp) prior *)
3758 navigate ~
-(fstate.maxrows)
3759 | 0xff56 | 0xff9b -> (* (kp) next *)
3760 navigate fstate.maxrows
3762 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3766 G.postRedisplay "outline ctrl right";
3767 {< m_pan
= m_pan
+ 1 >}
3769 else self#updownlevel
1
3773 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3777 G.postRedisplay "outline ctrl left";
3778 {< m_pan
= m_pan
- 1 >}
3780 else self#updownlevel ~
-1
3784 | 0xff50 | 0xff95 -> (* (kp) home *)
3785 G.postRedisplay "outline home";
3786 coe {< m_first
= 0; m_active
= 0 >}
3788 | 0xff57 | 0xff9c -> (* (kp) end *)
3789 let active = source#getitemcount
- 1 in
3790 let first = max
0 (active - fstate.maxrows) in
3791 G.postRedisplay "outline end";
3792 coe {< m_active
= active; m_first
= first >}
3794 | _ -> super#
key key mask
3797 let outlinesource usebookmarks
=
3800 inherit lvsourcebase
3801 val mutable m_items
= empty
3802 val mutable m_orig_items
= empty
3803 val mutable m_prev_items
= empty
3804 val mutable m_narrow_pattern
= ""
3805 val mutable m_hadremovals
= false
3807 method getitemcount
=
3808 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3811 if n == Array.length m_items
&& m_hadremovals
3813 ("[Confirm removal]", 0)
3815 let s, n, _ = m_items
.(n) in
3818 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3819 ignore
(uioh
, first, qsearch);
3820 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3822 if String.length m_narrow_pattern
= 0
3828 if not
confrimremoval
3830 let _, _, anchor = m_items
.(active) in
3831 gotoghyll (getanchory anchor);
3835 state.bookmarks
<- Array.to_list m_items
;
3836 m_orig_items
<- m_items
;
3839 else m_items
<- items;
3843 method hasaction
_ = true
3846 if Array.length m_items
!= Array.length m_orig_items
3847 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3850 method narrow
pattern =
3851 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3855 let rec loop accu n =
3858 m_narrow_pattern
<- pattern;
3859 m_items
<- Array.of_list
accu
3862 let (s, _, _) as o = m_items
.(n) in
3864 if (try ignore
(Str.search_forward
re s 0); true
3865 with Not_found
-> false)
3871 loop [] (Array.length m_items
- 1)
3876 then Array.of_list
state.bookmarks
3879 m_items
<- m_orig_items
3884 if m >= 0 && m < Array.length m_items
3886 m_hadremovals
<- true;
3887 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3888 let n = if n >= m then n+1 else n in
3893 method reset
anchor items =
3894 m_hadremovals
<- false;
3895 if m_orig_items
== empty || m_prev_items
!= items
3897 m_orig_items
<- items;
3898 if String.length m_narrow_pattern
= 0
3899 then m_items
<- items;
3901 m_prev_items
<- items;
3902 let rely = getanchory anchor in
3904 let rec loop n best bestd
=
3905 if n = Array.length m_items
3908 let (_, _, anchor) = m_items
.(n) in
3909 let orely = getanchory anchor in
3910 let d = abs
(orely - rely) in
3913 else loop (n+1) best bestd
3918 m_first
<- firstof m_first
active
3922 let enterselector usebookmarks
=
3923 let source = outlinesource usebookmarks
in
3927 then Array.of_list
state.bookmarks
3930 if Array.length
outlines = 0
3932 showtext ' ' errmsg
;
3935 state.text <- source#greetmsg
;
3936 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3937 let anchor = getanchor () in
3938 source#reset
anchor outlines;
3939 state.uioh
<- coe (new outlinelistview ~
source);
3940 G.postRedisplay "enter selector";
3944 let enteroutlinemode =
3945 let f = enterselector false in
3946 fun ()-> f "Document has no outline";
3949 let enterbookmarkmode =
3950 let f = enterselector true in
3951 fun () -> f "Document has no bookmarks (yet)";
3954 let color_of_string s =
3955 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
3956 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
3960 let color_to_string (r, g, b) =
3961 let r = truncate
(r *. 256.0)
3962 and g = truncate
(g *. 256.0)
3963 and b = truncate
(b *. 256.0) in
3964 Printf.sprintf
"%d/%d/%d" r g b
3967 let irect_of_string s =
3968 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3971 let irect_to_string (x0,y0,x1,y1) =
3972 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3975 let makecheckers () =
3976 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3978 converted by Issac Trotts. July 25, 2002 *)
3979 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3980 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3981 let id = GlTex.gen_texture
() in
3982 GlTex.bind_texture `texture_2d
id;
3983 GlPix.store
(`unpack_alignment
1);
3984 GlTex.image2d
image;
3985 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3986 [ `mag_filter `nearest
; `min_filter `nearest
];
3990 let setcheckers enabled
=
3991 match state.texid
with
3993 if enabled
then state.texid
<- Some
(makecheckers ())
3998 GlTex.delete_texture texid
;
3999 state.texid
<- None
;
4003 let int_of_string_with_suffix s =
4004 let l = String.length
s in
4008 let suffix = Char.lowercase
s.[l-1] in
4010 | 'k'
-> String.sub
s 0 (l-1), 10
4011 | '
m'
-> String.sub
s 0 (l-1), 20
4012 | '
g'
-> String.sub
s 0 (l-1), 30
4016 let n = int_of_string
s1 in
4017 let m = n lsl shift
in
4019 then raise
(Failure
"value too large")
4023 let string_with_suffix_of_int n =
4028 if n land ((1 lsl 30) - 1) = 0
4031 if n land ((1 lsl 20) - 1) = 0
4034 if n land ((1 lsl 10) - 1) = 0
4041 let h = n mod 1000 in
4044 then string_of_int
h ^
s
4046 let s = Printf.sprintf
"_%03d%s" h s in
4053 let defghyllscroll = (40, 8, 32);;
4054 let ghyllscroll_of_string s =
4055 let (n, a, b) as nab
=
4058 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4060 if n <= a || n <= b || a >= b
4061 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4065 let ghyllscroll_to_string ((n, a, b) as nab
) =
4066 if nab
= defghyllscroll
4068 else Printf.sprintf
"%d,%d,%d" n a b;
4071 let describe_location () =
4072 let fn = page_of_y state.y in
4073 let ln = page_of_y (state.y + state.winh
- state.hscrollh) in
4074 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4078 else (100. *. (float state.y /. float maxy))
4082 Printf.sprintf
"page %d of %d [%.2f%%]"
4083 (fn+1) state.pagecount
percent
4086 "pages %d-%d of %d [%.2f%%]"
4087 (fn+1) (ln+1) state.pagecount
percent
4090 let setpresentationmode v
=
4091 let n = page_of_y state.y in
4092 state.anchor <- (n, 0.0, 1.0);
4093 conf.presentation
<- v
;
4094 if conf.presentation
4096 if not
conf.scrollbarinpm
4097 then state.scrollw
<- 0;
4099 else state.scrollw
<- conf.scrollbw
;
4104 let btos b = if b then "\xe2\x88\x9a" else "" in
4105 let showextended = ref false in
4106 let leave mode
= function
4107 | Confirm
-> state.mode
<- mode
4108 | Cancel
-> state.mode
<- mode
in
4111 val mutable m_first_time
= true
4112 val mutable m_l
= []
4113 val mutable m_a
= [||]
4114 val mutable m_prev_uioh
= nouioh
4115 val mutable m_prev_mode
= View
4117 inherit lvsourcebase
4119 method reset prev_mode prev_uioh
=
4120 m_a
<- Array.of_list
(List.rev m_l
);
4122 m_prev_mode
<- prev_mode
;
4123 m_prev_uioh
<- prev_uioh
;
4127 if n >= Array.length m_a
4131 | _, _, _, Action
_ -> m_active
<- n
4135 m_first_time
<- false;
4138 method int name get
set =
4140 (name
, `
int get
, 1, Action
(
4143 try set (int_of_string
s)
4145 state.text <- Printf.sprintf
"bad integer `%s': %s"
4149 let te = name ^
": ", "", None
, intentry, ondone, true in
4150 state.mode
<- Textentry
(te, leave m_prev_mode
);
4154 method int_with_suffix name get
set =
4156 (name
, `intws get
, 1, Action
(
4159 try set (int_of_string_with_suffix s)
4161 state.text <- Printf.sprintf
"bad integer `%s': %s"
4166 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4168 state.mode
<- Textentry
(te, leave m_prev_mode
);
4172 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4174 (name
, `
bool (btos, get
), offset
, Action
(
4181 method color name get
set =
4183 (name
, `color get
, 1, Action
(
4185 let invalid = (nan
, nan
, nan
) in
4188 try color_of_string s
4190 state.text <- Printf.sprintf
"bad color `%s': %s"
4197 let te = name ^
": ", "", None
, textentry, ondone, true in
4198 state.text <- color_to_string (get
());
4199 state.mode
<- Textentry
(te, leave m_prev_mode
);
4203 method string name get
set =
4205 (name
, `
string get
, 1, Action
(
4207 let ondone s = set s in
4208 let te = name ^
": ", "", None
, textentry, ondone, true in
4209 state.mode
<- Textentry
(te, leave m_prev_mode
);
4213 method colorspace name get
set =
4215 (name
, `
string get
, 1, Action
(
4218 let vals = [| "rgb"; "bgr"; "gray" |] in
4220 inherit lvsourcebase
4223 m_active
<- int_of_colorspace conf.colorspace
;
4226 method getitemcount
= Array.length
vals
4227 method getitem
n = (vals.(n), 0)
4228 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4229 ignore
(uioh
, first, pan
, qsearch);
4230 if not cancel
then set active;
4232 method hasaction
_ = true
4236 let modehash = findkeyhash conf "info" in
4237 coe (new listview ~
source ~trusted
:true ~
modehash)
4240 method fitmodel name get
set =
4242 (name
, `
string get
, 1, Action
(
4245 let vals = [| "fit width"; "proportional"; "fit page" |] in
4247 inherit lvsourcebase
4250 m_active
<- int_of_fitmodel conf.fitmodel
;
4253 method getitemcount
= Array.length
vals
4254 method getitem
n = (vals.(n), 0)
4255 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4256 ignore
(uioh
, first, pan
, qsearch);
4257 if not cancel
then set active;
4259 method hasaction
_ = true
4263 let modehash = findkeyhash conf "info" in
4264 coe (new listview ~
source ~trusted
:true ~
modehash)
4267 method caption
s offset
=
4268 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4270 method caption2
s f offset
=
4271 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4273 method getitemcount
= Array.length m_a
4276 let tostr = function
4277 | `
int f -> string_of_int
(f ())
4278 | `intws
f -> string_with_suffix_of_int (f ())
4280 | `color
f -> color_to_string (f ())
4281 | `
bool (btos, f) -> btos (f ())
4284 let name, t
, offset
, _ = m_a
.(n) in
4285 ((let s = tostr t
in
4286 if String.length
s > 0
4287 then Printf.sprintf
"%s\t%s" name s
4291 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4295 m_qsearch
<- qsearch;
4297 match m_a
.(active) with
4298 | _, _, _, Action
f -> f uioh
4310 method hasaction
n =
4312 | _, _, _, Action
_ -> true
4316 let rec fillsrc prevmode prevuioh
=
4317 let sep () = src#caption
"" 0 in
4318 let colorp name get
set =
4320 (fun () -> color_to_string (get
()))
4323 let c = color_of_string v in
4326 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4329 let oldmode = state.mode
in
4330 let birdseye = isbirdseye state.mode
in
4332 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4334 src#
bool "presentation mode"
4335 (fun () -> conf.presentation
)
4336 (fun v -> setpresentationmode v);
4338 src#
bool "ignore case in searches"
4339 (fun () -> conf.icase
)
4340 (fun v -> conf.icase
<- v);
4343 (fun () -> conf.preload)
4344 (fun v -> conf.preload <- v);
4346 src#
bool "highlight links"
4347 (fun () -> conf.hlinks
)
4348 (fun v -> conf.hlinks
<- v);
4350 src#
bool "under info"
4351 (fun () -> conf.underinfo
)
4352 (fun v -> conf.underinfo
<- v);
4354 src#
bool "persistent bookmarks"
4355 (fun () -> conf.savebmarks
)
4356 (fun v -> conf.savebmarks
<- v);
4358 src#fitmodel
"fit model"
4359 (fun () -> fitmodel_to_string conf.fitmodel
)
4360 (fun v -> reqlayout conf.angle
(fitmodel_of_int v));
4362 src#
bool "trim margins"
4363 (fun () -> conf.trimmargins
)
4364 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4366 src#
bool "persistent location"
4367 (fun () -> conf.jumpback
)
4368 (fun v -> conf.jumpback
<- v);
4371 src#
int "inter-page space"
4372 (fun () -> conf.interpagespace
)
4374 conf.interpagespace
<- n;
4375 docolumns conf.columns
;
4377 match state.layout with
4382 state.maxy <- calcheight ();
4383 let y = getpagey pageno in
4388 (fun () -> conf.pagebias
)
4389 (fun v -> conf.pagebias
<- v);
4391 src#
int "scroll step"
4392 (fun () -> conf.scrollstep
)
4393 (fun n -> conf.scrollstep
<- n);
4395 src#
int "horizontal scroll step"
4396 (fun () -> conf.hscrollstep
)
4397 (fun v -> conf.hscrollstep
<- v);
4399 src#
int "auto scroll step"
4401 match state.autoscroll
with
4403 | _ -> conf.autoscrollstep
)
4405 if state.autoscroll
<> None
4406 then state.autoscroll
<- Some
n;
4407 conf.autoscrollstep
<- n);
4410 (fun () -> truncate
(conf.zoom *. 100.))
4411 (fun v -> setzoom ((float v) /. 100.));
4414 (fun () -> conf.angle
)
4415 (fun v -> reqlayout v conf.fitmodel
);
4417 src#
int "scroll bar width"
4418 (fun () -> state.scrollw
)
4422 reshape state.winw
state.winh
;
4425 src#
int "scroll handle height"
4426 (fun () -> conf.scrollh
)
4427 (fun v -> conf.scrollh
<- v;);
4429 src#
int "thumbnail width"
4430 (fun () -> conf.thumbw
)
4432 conf.thumbw
<- min
4096 v;
4435 leavebirdseye beye
false;
4440 let mode = state.mode in
4441 src#
string "columns"
4443 match conf.columns
with
4445 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4446 | Csplit
(count
, _) -> "-" ^ string_of_int count
4449 let n, a, b = multicolumns_of_string v in
4450 setcolumns mode n a b);
4453 src#caption
"Presentation mode" 0;
4454 src#
bool "scrollbar visible"
4455 (fun () -> conf.scrollbarinpm
)
4457 if v != conf.scrollbarinpm
4459 conf.scrollbarinpm
<- v;
4460 if conf.presentation
4462 state.scrollw
<- if v then conf.scrollbw
else 0;
4463 reshape state.winw
state.winh
;
4469 src#caption
"Pixmap cache" 0;
4470 src#int_with_suffix
"size (advisory)"
4471 (fun () -> conf.memlimit
)
4472 (fun v -> conf.memlimit
<- v);
4475 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4476 (string_with_suffix_of_int state.memused
)
4477 (Hashtbl.length
state.tilemap
)) 1;
4480 src#caption
"Layout" 0;
4481 src#caption2
"Dimension"
4483 Printf.sprintf
"%dx%d (virtual %dx%d)"
4484 state.winw
state.winh
4489 src#caption2
"Position" (fun () ->
4490 Printf.sprintf
"%dx%d" state.x state.y
4493 src#caption2
"Position" (fun () -> describe_location ()) 1
4497 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4498 "Save these parameters as global defaults at exit"
4499 (fun () -> conf.bedefault
)
4500 (fun v -> conf.bedefault
<- v)
4504 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4505 src#
bool ~offset
:0 ~
btos "Extended parameters"
4506 (fun () -> !showextended)
4507 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4511 (fun () -> conf.checkers
)
4512 (fun v -> conf.checkers
<- v; setcheckers v);
4513 src#
bool "update cursor"
4514 (fun () -> conf.updatecurs
)
4515 (fun v -> conf.updatecurs
<- v);
4517 (fun () -> conf.verbose
)
4518 (fun v -> conf.verbose
<- v);
4519 src#
bool "invert colors"
4520 (fun () -> conf.invert
)
4521 (fun v -> conf.invert
<- v);
4523 (fun () -> conf.maxhfit
)
4524 (fun v -> conf.maxhfit
<- v);
4525 src#
bool "redirect stderr"
4526 (fun () -> conf.redirectstderr)
4527 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4528 src#
string "uri launcher"
4529 (fun () -> conf.urilauncher
)
4530 (fun v -> conf.urilauncher
<- v);
4531 src#
string "path launcher"
4532 (fun () -> conf.pathlauncher
)
4533 (fun v -> conf.pathlauncher
<- v);
4534 src#
string "tile size"
4535 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4538 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4539 conf.tilew
<- max
64 w;
4540 conf.tileh
<- max
64 h;
4543 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4546 src#
int "texture count"
4547 (fun () -> conf.texcount
)
4550 then conf.texcount
<- v
4551 else showtext '
!'
" Failed to set texture count please retry later"
4553 src#
int "slice height"
4554 (fun () -> conf.sliceheight
)
4556 conf.sliceheight
<- v;
4557 wcmd "sliceh %d" conf.sliceheight
;
4559 src#
int "anti-aliasing level"
4560 (fun () -> conf.aalevel
)
4562 conf.aalevel
<- bound v 0 8;
4563 state.anchor <- getanchor ();
4564 opendoc state.path
state.password
;
4566 src#
string "page scroll scaling factor"
4567 (fun () -> string_of_float
conf.pgscale)
4570 let s = float_of_string
v in
4573 state.text <- Printf.sprintf
4574 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4577 src#
int "ui font size"
4578 (fun () -> fstate.fontsize
)
4579 (fun v -> setfontsize (bound v 5 100));
4580 src#
int "hint font size"
4581 (fun () -> conf.hfsize
)
4582 (fun v -> conf.hfsize
<- bound v 5 100);
4583 colorp "background color"
4584 (fun () -> conf.bgcolor
)
4585 (fun v -> conf.bgcolor
<- v);
4586 src#
bool "crop hack"
4587 (fun () -> conf.crophack
)
4588 (fun v -> conf.crophack
<- v);
4589 src#
string "trim fuzz"
4590 (fun () -> irect_to_string conf.trimfuzz
)
4593 conf.trimfuzz
<- irect_of_string v;
4595 then settrim true conf.trimfuzz
;
4597 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4599 src#
string "throttle"
4601 match conf.maxwait
with
4602 | None
-> "show place holder if page is not ready"
4605 then "wait for page to fully render"
4607 "wait " ^ string_of_float
time
4608 ^
" seconds before showing placeholder"
4612 let f = float_of_string
v in
4614 then conf.maxwait
<- None
4615 else conf.maxwait
<- Some
f
4617 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4619 src#
string "ghyll scroll"
4621 match conf.ghyllscroll
with
4623 | Some nab
-> ghyllscroll_to_string nab
4628 if String.length
v = 0
4630 else Some
(ghyllscroll_of_string v)
4632 conf.ghyllscroll
<- gs
4634 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4636 src#
string "selection command"
4637 (fun () -> conf.selcmd
)
4638 (fun v -> conf.selcmd
<- v);
4639 src#
string "synctex command"
4640 (fun () -> conf.stcmd
)
4641 (fun v -> conf.stcmd
<- v);
4642 src#colorspace
"color space"
4643 (fun () -> colorspace_to_string conf.colorspace
)
4645 conf.colorspace
<- colorspace_of_int v;
4652 (fun () -> conf.usepbo
)
4653 (fun v -> conf.usepbo
<- v);
4654 src#
bool "mouse wheel scrolls pages"
4655 (fun () -> conf.wheelbypage
)
4656 (fun v -> conf.wheelbypage
<- v);
4660 src#caption
"Document" 0;
4661 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4662 src#caption2
"Pages"
4663 (fun () -> string_of_int
state.pagecount
) 1;
4664 src#caption2
"Dimensions"
4665 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4669 src#caption
"Trimmed margins" 0;
4670 src#caption2
"Dimensions"
4671 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4675 src#caption
"OpenGL" 0;
4676 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4677 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4678 src#reset prevmode prevuioh
;
4682 let prevmode = state.mode
4683 and prevuioh
= state.uioh in
4684 fillsrc prevmode prevuioh
;
4685 let source = (src :> lvsource
) in
4686 let modehash = findkeyhash conf "info" in
4687 state.uioh <- coe (object (self)
4688 inherit listview ~
source ~trusted
:true ~
modehash as super
4689 val mutable m_prevmemused
= 0
4690 method infochanged
= function
4692 if m_prevmemused
!= state.memused
4694 m_prevmemused
<- state.memused
;
4695 G.postRedisplay "memusedchanged";
4697 | Pdim
-> G.postRedisplay "pdimchanged"
4698 | Docinfo
-> fillsrc prevmode prevuioh
4700 method key key mask
=
4701 if not
(Wsi.withctrl mask
)
4704 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4705 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4706 | _ -> super#
key key mask
4707 else super#
key key mask
4709 G.postRedisplay "info";
4715 inherit lvsourcebase
4716 method getitemcount
= Array.length
state.help
4718 let s, l, _ = state.help
.(n) in
4721 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4725 m_qsearch
<- qsearch;
4726 match state.help
.(active) with
4727 | _, _, Action
f -> Some
(f uioh)
4737 method hasaction
n =
4738 match state.help
.(n) with
4739 | _, _, Action
_ -> true
4746 let modehash = findkeyhash conf "help" in
4747 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4748 G.postRedisplay "help";
4753 let re = Str.regexp
"[\r\n]" in
4755 inherit lvsourcebase
4756 val mutable m_items
= [||]
4758 method getitemcount
= 1 + Array.length m_items
4763 else m_items
.(n-1), 0
4765 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4770 then Buffer.clear
state.errmsgs
;
4771 m_qsearch
<- qsearch;
4778 method hasaction
n =
4782 state.newerrmsgs
<- false;
4783 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4784 m_items
<- Array.of_list
l
4792 let source = (msgsource :> lvsource
) in
4793 let modehash = findkeyhash conf "listview" in
4794 state.uioh <- coe (object
4795 inherit listview ~
source ~trusted
:false ~
modehash as super
4798 then msgsource#reset
;
4801 G.postRedisplay "msgs";
4804 let quickbookmark ?title
() =
4805 match state.layout with
4811 let sec = Unix.gettimeofday
() in
4812 let tm = Unix.localtime
sec in
4813 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4817 (tm.Unix.tm_year
+ 1900)
4820 | Some
title -> title
4822 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4825 let setautoscrollspeed step goingdown
=
4826 let incr = max
1 ((abs step
) / 2) in
4827 let incr = if goingdown
then incr else -incr in
4828 let astep = step
+ incr in
4829 state.autoscroll
<- Some
astep;
4832 let gotounder = function
4833 | Ulinkgoto
(pageno, top) ->
4837 gotopage1 pageno top;
4843 | Uremote
(filename
, pageno) ->
4845 if Sys.file_exists filename
4848 let dir = Filename.dirname
state.path in
4849 let path = Filename.concat
dir filename
in
4850 if Sys.file_exists
path
4854 if String.length
path > 0
4856 let anchor = getanchor () in
4857 let ranchor = state.path, state.password
, anchor in
4858 state.anchor <- (pageno, 0.0, 0.0);
4859 state.ranchors
<- ranchor :: state.ranchors
;
4862 else showtext '
!'
("Could not find " ^ filename
)
4864 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4868 match conf.columns
with
4870 | _ -> state.x != 0 || conf.zoom > 1.0
4873 let existsinrow pageno (columns
, coverA
, coverB
) p =
4874 let last = ((pageno - coverA
) mod columns
) + columns
in
4875 let rec any = function
4878 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4882 then (if l.pageno = last then false else any rest
)
4890 match state.layout with
4892 let pageno = page_of_y state.y in
4893 gotoghyll (getpagey (pageno+1))
4895 match conf.columns
with
4897 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4899 let y = clamp (pgscale state.winh
) in
4902 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4903 gotoghyll (getpagey pageno)
4904 | Cmulti
((c, _, _) as cl, _) ->
4905 if conf.presentation
4906 && (existsinrow l.pageno cl
4907 (fun l -> l.pageh
> l.pagey + l.pagevh))
4909 let y = clamp (pgscale state.winh
) in
4912 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4913 gotoghyll (getpagey pageno)
4915 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4917 let pagey, pageh
= getpageyh l.pageno in
4918 let pagey = pagey + pageh
* l.pagecol
in
4919 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4920 gotoghyll (pagey + pageh
+ ips)
4924 match state.layout with
4926 let pageno = page_of_y state.y in
4927 gotoghyll (getpagey (pageno-1))
4929 match conf.columns
with
4931 if conf.presentation
&& l.pagey != 0
4933 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4935 let pageno = max
0 (l.pageno-1) in
4936 gotoghyll (getpagey pageno)
4937 | Cmulti
((c, _, coverB
) as cl, _) ->
4938 if conf.presentation
&&
4939 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4941 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4944 if l.pageno = state.pagecount
- coverB
4948 let pageno = max
0 (l.pageno-decr) in
4949 gotoghyll (getpagey pageno)
4957 let pageno = max
0 (l.pageno-1) in
4958 let pagey, pageh
= getpageyh pageno in
4961 let pagey, pageh
= getpageyh l.pageno in
4962 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4967 let viewkeyboard key mask
=
4969 let mode = state.mode in
4970 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4973 G.postRedisplay "view:enttext"
4975 let ctrl = Wsi.withctrl mask
in
4977 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4983 | 0xff63 -> (* insert *)
4984 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4986 state.mode <- LinkNav
(Ltgendir
0);
4989 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4991 | 0xff1b | 113 -> (* escape / q *)
4992 begin match state.mstate
with
4994 state.mstate
<- Mnone
;
4995 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4996 G.postRedisplay "kill zoom rect";
4998 begin match state.mode with
5001 G.postRedisplay "esc leave linknav"
5003 match state.ranchors
with
5005 | (path, password
, anchor) :: rest
->
5006 state.ranchors
<- rest
;
5007 state.anchor <- anchor;
5008 opendoc path password
5012 | 0xff08 -> (* backspace *)
5013 gotoghyll (getnav ~
-1)
5021 G.postRedisplay "dehighlight";
5023 | 47 | 63 -> (* / ? *)
5024 let ondone isforw
s =
5025 cbput state.hists
.pat
s;
5026 state.searchpattern
<- s;
5029 let s = String.create
1 in
5030 s.[0] <- Char.chr
key;
5031 enttext (s, "", Some
(onhist state.hists
.pat
),
5032 textentry, ondone (key = 47), true)
5034 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5035 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5036 setzoom (conf.zoom +. incr)
5038 | 43 | 0xffab -> (* + *)
5041 try int_of_string
s with exc
->
5042 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5048 state.text <- "page bias is now " ^ string_of_int
n;
5051 enttext ("page bias: ", "", None
, intentry, ondone, true)
5053 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5054 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5055 setzoom (max
0.01 (conf.zoom -. decr))
5057 | 45 | 0xffad -> (* - *)
5058 let ondone msg
= state.text <- msg
in
5060 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
5061 optentry state.mode, ondone, true
5064 | 48 when ctrl -> (* ctrl-0 *)
5069 if state.w <= state.winw
- state.scrollw
5077 | 49 | 50 when ctrl -> (* ctrl-1/2 *)
5079 match conf.columns
with
5080 | Csingle
_ | Cmulti
_ -> 1
5081 | Csplit
(n, _) -> n
5083 let h = state.winh
-
5084 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5086 let zoom = zoomforh
state.winw
h state.scrollw
cols in
5087 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5090 | 51 when ctrl -> (* ctrl-3 *)
5092 match conf.fitmodel
with
5093 | FitWidth
-> FitProportional
5094 | FitProportional
-> FitPage
5095 | FitPage
-> FitWidth
5097 state.text <- "fit model " ^
fitmodel_to_string fm;
5098 reqlayout conf.angle
fm
5100 | 0xffc6 -> (* f9 *)
5103 | 57 when ctrl -> (* ctrl-9 *)
5106 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5107 when not
ctrl -> (* 0..9 *)
5110 try int_of_string
s with exc
->
5111 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5117 cbput state.hists
.pag
(string_of_int
n);
5118 gotopage1 (n + conf.pagebias
- 1) 0;
5121 let pageentry text key =
5122 match Char.unsafe_chr
key with
5123 | '
g'
-> TEdone
text
5124 | _ -> intentry text key
5126 let text = "x" in text.[0] <- Char.chr
key;
5127 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5130 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5131 reshape state.winw
state.winh
;
5134 conf.hlinks
<- not
conf.hlinks
;
5135 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5136 G.postRedisplay "toggle highlightlinks";
5139 state.glinks
<- true;
5140 let mode = state.mode in
5141 state.mode <- Textentry
(
5142 (":", "", None
, linknentry, linkndone gotounder, false),
5144 state.glinks
<- false;
5148 G.postRedisplay "view:linkent(F)"
5151 state.glinks
<- true;
5152 let mode = state.mode in
5153 state.mode <- Textentry
(
5154 (":", "", None
, linknentry, linkndone (fun under ->
5155 match Ne.pipe () with
5157 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
5160 try popen conf.selcmd
[r, 0; w, -1]; true
5163 (Printf.sprintf
"failed to execute %s: %s"
5164 conf.selcmd
(exntos exn
));
5168 Ne.clo fd
(fun msg
->
5169 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5172 let s = undertext under in
5176 let l = String.length
s in
5177 let n = tempfailureretry
(Unix.write
w s 0) l in
5182 "failed to write %d characters to sel pipe, wrote %d"
5187 (Printf.sprintf
"failed to write to sel pipe: %s"
5197 state.glinks
<- false;
5201 G.postRedisplay "view:linkent"
5204 begin match state.autoscroll
with
5206 conf.autoscrollstep
<- step
;
5207 state.autoscroll
<- None
5209 if conf.autoscrollstep
= 0
5210 then state.autoscroll
<- Some
1
5211 else state.autoscroll
<- Some
conf.autoscrollstep
5214 | 112 when ctrl -> (* ctrl-p *)
5218 setpresentationmode (not
conf.presentation
);
5219 showtext ' '
("presentation mode " ^
5220 if conf.presentation
then "on" else "off");
5223 if List.mem
Wsi.Fullscreen
state.winstate
5224 then Wsi.reshape conf.cwinw
conf.cwinh
5225 else Wsi.fullscreen
()
5227 | 112 | 78 -> (* p|N *)
5228 search state.searchpattern
false
5230 | 110 | 0xffc0 -> (* n|F3 *)
5231 search state.searchpattern
true
5234 begin match state.layout with
5237 gotoghyll (getpagey l.pageno)
5243 | 0xff9f | 0xffff -> (* delete *)
5247 showtext ' '
(describe_location ());
5250 begin match state.layout with
5253 Wsi.reshape (l.pagew
+ state.scrollw
) l.pageh
;
5258 enterbookmarkmode ()
5260 | 104 | 0xffbe -> (* h|F1 *)
5266 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5271 match state.layout with
5273 if String.length
s > 0
5275 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5278 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5282 showtext ' '
"Quick bookmark added";
5285 begin match state.layout with
5287 let rect = getpdimrect
l.pagedimno
in
5291 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5292 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5294 (truncate
(rect.(1) -. rect.(0)),
5295 truncate
(rect.(3) -. rect.(0)))
5297 let w = truncate
((float w)*.conf.zoom)
5298 and h = truncate
((float h)*.conf.zoom) in
5301 state.anchor <- getanchor ();
5302 Wsi.reshape (w + state.scrollw
) (h + conf.interpagespace
)
5304 G.postRedisplay "z";
5309 | 60 | 62 -> (* < > *)
5310 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5312 | 91 | 93 -> (* [ ] *)
5314 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5316 G.postRedisplay "brightness";
5318 | 99 when state.mode = View
-> (* c *)
5320 match state.prevcolumns
with
5321 | None
-> (1, 0, 0), 1.0
5322 | Some
(columns
, z
) ->
5325 | Csplit
(c, _) -> -c, 0, 0
5326 | Cmulti
((c, a, b), _) -> c, a, b
5327 | Csingle
_ -> 1, 0, 0
5331 setcolumns View
c a b;
5334 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5335 setzoom state.prevzoom
5337 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5338 begin match state.autoscroll
with
5340 begin match state.mode with
5341 | Birdseye beye
-> upbirdseye 1 beye
5344 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5346 if not
(Wsi.withshift mask
) && conf.presentation
5348 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5352 setautoscrollspeed n false
5355 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5356 begin match state.autoscroll
with
5358 begin match state.mode with
5359 | Birdseye beye
-> downbirdseye 1 beye
5362 then gotoy_and_clear_text (clamp (state.winh
/2))
5364 if not
(Wsi.withshift mask
) && conf.presentation
5366 else gotoy_and_clear_text (clamp conf.scrollstep
)
5370 setautoscrollspeed n true
5373 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5374 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5380 else conf.hscrollstep
5382 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5383 state.x <- state.x + dx;
5384 gotoy_and_clear_text state.y
5387 G.postRedisplay "lef/right"
5390 | 0xff55 | 0xff9a -> (* (kp) prior *)
5394 match state.layout with
5396 | l :: _ -> state.y - l.pagey
5398 clamp (pgscale (-state.winh
))
5402 | 0xff56 | 0xff9b -> (* (kp) next *)
5406 match List.rev
state.layout with
5408 | l :: _ -> getpagey l.pageno
5410 clamp (pgscale state.winh
)
5414 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5416 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5417 gotoghyll (clamp state.maxy)
5420 when Wsi.withalt mask
-> (* alt-(kp) right *)
5421 gotoghyll (getnav 1)
5423 when Wsi.withalt mask
-> (* alt-(kp) left *)
5424 gotoghyll (getnav ~
-1)
5429 | 118 when conf.debug
-> (* v *)
5432 match getopaque l.pageno with
5435 let x0, y0, x1, y1 = pagebbox opaque
in
5436 let a,b = float x0, float y0 in
5437 let c,d = float x1, float y0 in
5438 let e,f = float x1, float y1 in
5439 let h,j
= float x0, float y1 in
5440 let rect = (a,b,c,d,e,f,h,j
) in
5442 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5444 G.postRedisplay "v";
5447 vlog "huh? %s" (Wsi.keyname
key)
5450 let linknavkeyboard key mask
linknav =
5451 let getpage pageno =
5452 let rec loop = function
5454 | l :: _ when l.pageno = pageno -> Some
l
5455 | _ :: rest
-> loop rest
5456 in loop state.layout
5458 let doexact (pageno, n) =
5459 match getopaque pageno, getpage pageno with
5460 | Some opaque
, Some
l ->
5461 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5463 let under = getlink opaque
n in
5464 G.postRedisplay "link gotounder";
5470 | 0xff50 -> (* home *)
5471 Some
(findlink opaque LDfirst
), -1
5473 | 0xff57 -> (* end *)
5474 Some
(findlink opaque LDlast
), 1
5476 | 0xff51 -> (* left *)
5477 Some
(findlink opaque
(LDleft
n)), -1
5479 | 0xff53 -> (* right *)
5480 Some
(findlink opaque
(LDright
n)), 1
5482 | 0xff52 -> (* up *)
5483 Some
(findlink opaque
(LDup
n)), -1
5485 | 0xff54 -> (* down *)
5486 Some
(findlink opaque
(LDdown
n)), 1
5491 begin match findpwl
l.pageno dir with
5495 state.mode <- LinkNav
(Ltgendir
dir);
5496 let y, h = getpageyh pageno in
5499 then y + h - state.winh
5504 begin match getopaque pageno, getpage pageno with
5505 | Some opaque
, Some
_ ->
5507 let ld = if dir > 0 then LDfirst
else LDlast
in
5510 begin match link with
5512 showlinktype (getlink opaque
m);
5513 state.mode <- LinkNav
(Ltexact
(pageno, m));
5514 G.postRedisplay "linknav jpage";
5521 begin match opt with
5522 | Some Lnotfound
-> pwl l dir;
5523 | Some
(Lfound
m) ->
5527 let _, y0, _, y1 = getlinkrect opaque
m in
5529 then gotopage1 l.pageno y0
5531 let d = fstate.fontsize
+ 1 in
5532 if y1 - l.pagey > l.pagevh - d
5533 then gotopage1 l.pageno (y1 - state.winh
- state.hscrollh + d)
5534 else G.postRedisplay "linknav";
5536 showlinktype (getlink opaque
m);
5537 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5540 | None
-> viewkeyboard key mask
5542 | _ -> viewkeyboard key mask
5547 G.postRedisplay "leave linknav"
5551 | Ltgendir
_ -> viewkeyboard key mask
5552 | Ltexact exact
-> doexact exact
5555 let keyboard key mask
=
5556 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5557 then wcmd "interrupt"
5558 else state.uioh <- state.uioh#
key key mask
5561 let birdseyekeyboard key mask
5562 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5564 match conf.columns
with
5566 | Cmulti
((c, _, _), _) -> c
5567 | Csplit
_ -> failwith
"bird's eye split mode"
5569 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5571 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5572 let y, h = getpageyh pageno in
5573 let top = (state.winh
- h) / 2 in
5574 gotoy (max
0 (y - top))
5575 | 0xff0d (* enter *)
5576 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5577 | 0xff1b -> leavebirdseye beye
true (* escape *)
5578 | 0xff52 -> upbirdseye incr beye
(* up *)
5579 | 0xff54 -> downbirdseye incr beye
(* down *)
5580 | 0xff51 -> upbirdseye 1 beye
(* left *)
5581 | 0xff53 -> downbirdseye 1 beye
(* right *)
5583 | 0xff55 -> (* prior *)
5584 begin match state.layout with
5588 state.mode <- Birdseye
(
5589 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5591 gotopage1 l.pageno 0;
5594 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5596 | [] -> gotoy (clamp (-state.winh
))
5598 state.mode <- Birdseye
(
5599 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5601 gotopage1 l.pageno 0
5604 | [] -> gotoy (clamp (-state.winh
))
5607 | 0xff56 -> (* next *)
5608 begin match List.rev
state.layout with
5610 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5611 begin match layout with
5613 let incr = l.pageh
- l.pagevh in
5618 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5620 G.postRedisplay "birdseye pagedown";
5622 else gotoy (clamp (incr + conf.interpagespace
*2));
5626 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5627 gotopage1 l.pageno 0;
5630 | [] -> gotoy (clamp state.winh
)
5633 | 0xff50 -> (* home *)
5634 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5637 | 0xff57 -> (* end *)
5638 let pageno = state.pagecount
- 1 in
5639 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5640 if not
(pagevisible state.layout pageno)
5643 match List.rev
state.pdims
with
5645 | (_, _, h, _) :: _ -> h
5647 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5648 else G.postRedisplay "birdseye end";
5649 | _ -> viewkeyboard key mask
5652 let drawpage l linkindexbase
=
5654 match state.mode with
5655 | Textentry
_ -> scalecolor 0.4
5657 | View
-> scalecolor 1.0
5658 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5659 if l.pageno = hooverpageno
5662 if l.pageno = pageno
5668 begin match getopaque l.pageno with
5670 if tileready l l.pagex
l.pagey
5672 let x = l.pagedispx - l.pagex
5673 and y = l.pagedispy - l.pagey in
5675 match conf.columns
with
5676 | Csingle
_ | Cmulti
_ ->
5677 (if conf.hlinks
then 1 else 0)
5679 && not
(isbirdseye state.mode) then 2 else 0)
5683 match state.mode with
5684 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5687 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5694 let scrollindicator () =
5695 let sbw, ph
, sh = state.uioh#
scrollph in
5696 let sbh, pw, sw = state.uioh#scrollpw
in
5698 GlDraw.color (0.64, 0.64, 0.64);
5700 (float (state.winw
- sbw), 0.)
5701 (float state.winw
, float state.winh
)
5704 (0., float (state.winh
- sbh))
5705 (float (state.winw
- state.scrollw
- 1), float state.winh
)
5707 GlDraw.color (0.0, 0.0, 0.0);
5710 (float (state.winw
- sbw), ph
)
5711 (float state.winw
, ph
+. sh)
5714 (pw, float (state.winh
- sbh))
5715 (pw +. sw, float state.winh
)
5720 match state.mstate
with
5721 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5724 | Msel
((x0, y0), (x1, y1)) ->
5725 let rec loop = function
5727 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5728 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5729 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5730 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5732 match getopaque l.pageno with
5734 let x0, y0 = pagetranslatepoint l x0 y0 in
5735 let x1, y1 = pagetranslatepoint l x1 y1 in
5736 seltext opaque
(x0, y0, x1, y1);
5744 let showrects rects
=
5746 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5747 GlDraw.polygon_mode `both `fill
;
5748 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5750 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5752 if l.pageno = pageno
5754 let dx = float (l.pagedispx - l.pagex
) in
5755 let dy = float (l.pagedispy - l.pagey) in
5756 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5757 GlDraw.begins `quads
;
5759 GlDraw.vertex2
(x0+.dx, y0+.dy);
5760 GlDraw.vertex2
(x1+.dx, y1+.dy);
5761 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5762 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5773 GlClear.color (scalecolor2 conf.bgcolor
);
5774 GlClear.clear
[`
color];
5775 let rec loop linkindexbase
= function
5777 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5778 loop linkindexbase rest
5781 loop 0 state.layout;
5783 match state.mode with
5784 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5785 begin match getopaque pageno with
5787 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5794 | None
-> state.rects
5801 begin match state.mstate
with
5802 | Mzoomrect
((x0, y0), (x1, y1)) ->
5804 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5805 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5806 GlDraw.rect (float x0, float y0)
5807 (float x1, float y1);
5816 let zoomrect x y x1 y1 =
5819 and y0 = min
y y1 in
5820 gotoy (state.y + y0);
5821 state.anchor <- getanchor ();
5822 let zoom = (float state.winw
*. conf.zoom) /. float (x1 - x0) in
5824 if state.w < state.winw
- state.scrollw
5825 then (state.winw
- state.scrollw
- state.w) / 2
5828 state.x <- (state.x + margin) - x0;
5830 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5831 state.mstate
<- Mnone
;
5835 let winw = state.winw - state.scrollw
- 1 in
5836 let s = float x /. float winw in
5837 let destx = truncate
(float (state.w + winw) *. s) in
5838 state.x <- winw - destx;
5839 gotoy_and_clear_text state.y;
5840 state.mstate
<- Mscrollx
;
5844 let s = float y /. float state.winh
in
5845 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5846 gotoy_and_clear_text desty;
5847 state.mstate
<- Mscrolly
;
5850 let viewmouse button down
x y mask
=
5852 | n when (n == 4 || n == 5) && not down
->
5853 if Wsi.withctrl mask
5855 match state.mstate
with
5856 | Mzoom
(oldn
, i
) ->
5864 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5866 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5868 let zoom = conf.zoom -. incr in
5870 state.mstate
<- Mzoom
(n, 0);
5872 state.mstate
<- Mzoom
(n, i
+1);
5874 else state.mstate
<- Mzoom
(n, 0)
5876 | _ -> state.mstate
<- Mzoom
(n, 0)
5879 match state.autoscroll
with
5880 | Some step
-> setautoscrollspeed step
(n=4)
5882 if conf.wheelbypage
|| conf.presentation
5891 then -conf.scrollstep
5892 else conf.scrollstep
5894 let incr = incr * 2 in
5895 let y = clamp incr in
5896 gotoy_and_clear_text y
5899 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5900 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5901 gotoy_and_clear_text state.y
5903 | 1 when Wsi.withshift mask
->
5904 state.mstate
<- Mnone
;
5907 match unproject x y with
5908 | Some
(pageno, ux
, uy
) ->
5909 let cmd = Printf.sprintf
5911 conf.stcmd
state.path pageno ux uy
5917 | 1 when Wsi.withctrl mask
->
5920 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5921 state.mstate
<- Mpan
(x, y)
5924 state.mstate
<- Mnone
5929 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5931 state.mstate
<- Mzoomrect
(p, p)
5934 match state.mstate
with
5935 | Mzoomrect
((x0, y0), _) ->
5936 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5937 then zoomrect x0 y0 x y
5939 state.mstate
<- Mnone
;
5940 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5941 G.postRedisplay "kill accidental zoom rect";
5944 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5945 state.mstate
<- Mnone
5948 | 1 when x > state.winw - state.scrollw
->
5951 let _, position, sh = state.uioh#
scrollph in
5952 if y > truncate
position && y < truncate
(position +. sh)
5953 then state.mstate
<- Mscrolly
5956 state.mstate
<- Mnone
5958 | 1 when y > state.winh
- state.hscrollh ->
5961 let _, position, sw = state.uioh#scrollpw
in
5962 if x > truncate
position && x < truncate
(position +. sw)
5963 then state.mstate
<- Mscrollx
5966 state.mstate
<- Mnone
5969 let dest = if down
then getunder x y else Unone
in
5970 begin match dest with
5974 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5977 | Unone
when down
->
5978 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5979 state.mstate
<- Mpan
(x, y);
5981 | Unone
| Utext
_ ->
5984 if conf.angle
mod 360 = 0
5986 state.mstate
<- Msel
((x, y), (x, y));
5987 G.postRedisplay "mouse select";
5991 match state.mstate
with
5994 | Mzoom
_ | Mscrollx
| Mscrolly
->
5995 state.mstate
<- Mnone
5997 | Mzoomrect
((x0, y0), _) ->
6001 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6002 state.mstate
<- Mnone
6004 | Msel
((x0, y0), (x1, y1)) ->
6005 let rec loop = function
6009 let a0 = l.pagedispy in
6010 let a1 = a0 + l.pagevh in
6011 let b0 = l.pagedispx in
6012 let b1 = b0 + l.pagevw in
6013 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6014 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6018 match getopaque l.pageno with
6021 match Ne.pipe () with
6025 "can not create sel pipe: %s"
6028 let doclose what fd
=
6029 Ne.clo fd
(fun msg
->
6030 dolog
"%s close failed: %s" what msg
)
6033 popen conf.selcmd
[r, 0; w, -1];
6036 G.postRedisplay "copysel";
6038 dolog
"can not execute %S: %s"
6039 conf.selcmd
(exntos exn
);
6047 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6048 state.mstate
<- Mnone
;
6055 let birdseyemouse button down
x y mask
6056 (conf, leftx
, _, hooverpageno
, anchor) =
6059 let rec loop = function
6062 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6063 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6065 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6071 | _ -> viewmouse button down
x y mask
6074 let mouse button down
x y mask
=
6075 state.uioh <- state.uioh#button button down
x y mask
;
6079 state.uioh <- state.uioh#
motion x y
6083 state.uioh <- state.uioh#
pmotion x y;
6089 method key key mask
=
6090 begin match state.mode with
6091 | Textentry
textentry -> textentrykeyboard key mask
textentry
6092 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6093 | View
-> viewkeyboard key mask
6094 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6098 method button button bstate
x y mask
=
6099 begin match state.mode with
6101 | View
-> viewmouse button bstate
x y mask
6102 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6108 begin match state.mode with
6110 | View
| Birdseye
_ | LinkNav
_ ->
6111 match state.mstate
with
6112 | Mzoom
_ | Mnone
-> ()
6117 state.mstate
<- Mpan
(x, y);
6119 then state.x <- state.x + dx;
6121 gotoy_and_clear_text y
6124 state.mstate
<- Msel
(a, (x, y));
6125 G.postRedisplay "motion select";
6128 let y = min
state.winh
(max
0 y) in
6132 let x = min
state.winw (max
0 x) in
6135 | Mzoomrect
(p0
, _) ->
6136 state.mstate
<- Mzoomrect
(p0
, (x, y));
6137 G.postRedisplay "motion zoomrect";
6141 method pmotion x y =
6142 begin match state.mode with
6143 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6144 let rec loop = function
6146 if hooverpageno
!= -1
6148 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6149 G.postRedisplay "pmotion birdseye no hoover";
6152 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6153 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6155 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6156 G.postRedisplay "pmotion birdseye hoover";
6166 match state.mstate
with
6167 | Mnone
-> updateunder x y
6168 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6173 method infochanged
_ = ()
6176 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6177 let p, h = scrollph state.y maxy in
6181 let winw = state.winw - state.scrollw
- 1 in
6182 let fwinw = float winw in
6184 let sw = fwinw /. float state.w in
6185 let sw = fwinw *. sw in
6186 max
sw (float conf.scrollh
)
6189 let f = state.w+winw in
6190 let r = float (winw-state.x) /. float f in
6191 let p = fwinw *. r in
6195 if position +. sw > fwinw
6196 then fwinw -. position
6199 state.hscrollh, position, sw
6203 match state.mode with
6204 | LinkNav
_ -> "links"
6205 | Textentry
_ -> "textentry"
6206 | Birdseye
_ -> "birdseye"
6209 findkeyhash conf modename
6211 method eformsgs
= true
6218 let fontpath = ref "";;
6221 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6224 let l = String.length
s in
6225 let b = Buffer.create
l in
6231 try Sys.getenv
"HOME"
6234 ("Can not determine home directory location: " ^ exntos exn
);
6238 let modifier_of_string = function
6239 | "alt" -> Wsi.altmask
6240 | "shift" -> Wsi.shiftmask
6241 | "ctrl" | "control" -> Wsi.ctrlmask
6242 | "meta" -> Wsi.metamask
6247 let r = Str.regexp
"-" in
6249 let elems = Str.full_split
r s in
6252 let m1 = modifier_of_string s in
6254 then (Wsi.namekey
s, m)
6257 | Str.Delim
s when n land 1 = 0 -> g s
6259 | Str.Delim
_ -> (k
, m)
6261 let rec loop n k
m = function
6264 let k, m = f n k m x in
6270 let keys_of_string =
6271 let r = Str.regexp
"[ \t]" in
6273 let elems = Str.split
r s in
6274 List.map
key_of_string elems
6277 let copykeyhashes c =
6278 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6281 let config_of c attrs
=
6285 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6286 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6287 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6288 | "preload" -> { c with preload = bool_of_string
v }
6289 | "page-bias" -> { c with pagebias
= int_of_string
v }
6290 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6291 | "horizontal-scroll-step" ->
6292 { c with hscrollstep
= max
(int_of_string
v) 1 }
6293 | "auto-scroll-step" ->
6294 { c with autoscrollstep
= max
0 (int_of_string
v) }
6295 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6296 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6299 match String.lowercase
v with
6300 | "true" -> Some infinity
6302 | f -> Some
(float_of_string
f)
6304 { c with maxwait
= mw}
6305 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6306 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6307 | "vertical-margin" ->
6308 { c with interpagespace
= max
0 (int_of_string
v) }
6310 let zoom = float_of_string
v /. 100. in
6311 let zoom = max
zoom 0.0 in
6312 { c with zoom = zoom }
6313 | "presentation" -> { c with presentation
= bool_of_string
v }
6314 | "rotation-angle" -> { c with angle
= int_of_string
v }
6315 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6316 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6317 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6318 | "proportional-display" ->
6321 then FitProportional
6324 { c with fitmodel
= fm }
6325 | "fit-model" -> { c with fitmodel
= fitmodel_of_string v }
6326 | "pixmap-cache-size" ->
6327 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6328 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6329 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6330 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6331 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6332 | "background-color" -> { c with bgcolor
= color_of_string v }
6333 | "scrollbar-in-presentation" ->
6334 { c with scrollbarinpm
= bool_of_string
v }
6335 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6336 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6337 | "mupdf-store-size" ->
6338 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6339 | "checkers" -> { c with checkers
= bool_of_string
v }
6340 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6341 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6342 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6343 | "uri-launcher" -> { c with urilauncher
= unent v }
6344 | "path-launcher" -> { c with pathlauncher
= unent v }
6345 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6346 | "invert-colors" -> { c with invert
= bool_of_string
v }
6347 | "brightness" -> { c with colorscale
= float_of_string
v }
6348 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6350 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6352 let (n, _, _) as nab
= multicolumns_of_string v in
6354 then { c with columns
= Csplit
(-n, [||]) }
6355 else { c with columns
= Cmulti
(nab
, [||]) }
6356 | "birds-eye-columns" ->
6357 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6358 | "selection-command" -> { c with selcmd
= unent v }
6359 | "synctex-command" -> { c with stcmd
= unent v }
6360 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6361 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6362 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6363 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6364 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6367 prerr_endline
("Error processing attribute (`" ^
6368 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6371 let rec fold c = function
6374 let c = apply c k v in
6377 fold { c with keyhashes
= copykeyhashes c } attrs
;
6380 let fromstring f pos
n v d =
6383 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6384 n v pos
(exntos exn
)
6389 let bookmark_of attrs
=
6390 let rec fold title page
rely visy
= function
6391 | ("title", v) :: rest
-> fold v page
rely visy rest
6392 | ("page", v) :: rest
-> fold title v rely visy rest
6393 | ("rely", v) :: rest
-> fold title page
v visy rest
6394 | ("visy", v) :: rest
-> fold title page
rely v rest
6395 | _ :: rest
-> fold title page
rely visy rest
6396 | [] -> title, page
, rely, visy
6398 fold "invalid" "0" "0" "0" attrs
6402 let rec fold path page
rely pan visy
= function
6403 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6404 | ("page", v) :: rest
-> fold path v rely pan visy rest
6405 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6406 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6407 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6408 | _ :: rest
-> fold path page
rely pan visy rest
6409 | [] -> path, page
, rely, pan
, visy
6411 fold "" "0" "0" "0" "0" attrs
6415 let rec fold rs ls
= function
6416 | ("out", v) :: rest
-> fold v ls rest
6417 | ("in", v) :: rest
-> fold rs
v rest
6418 | _ :: rest
-> fold ls rs rest
6424 let setconf dst
src =
6425 dst
.scrollbw
<- src.scrollbw
;
6426 dst
.scrollh
<- src.scrollh
;
6427 dst
.icase
<- src.icase
;
6428 dst
.preload <- src.preload;
6429 dst
.pagebias
<- src.pagebias
;
6430 dst
.verbose
<- src.verbose
;
6431 dst
.scrollstep
<- src.scrollstep
;
6432 dst
.maxhfit
<- src.maxhfit
;
6433 dst
.crophack
<- src.crophack
;
6434 dst
.autoscrollstep
<- src.autoscrollstep
;
6435 dst
.maxwait
<- src.maxwait
;
6436 dst
.hlinks
<- src.hlinks
;
6437 dst
.underinfo
<- src.underinfo
;
6438 dst
.interpagespace
<- src.interpagespace
;
6439 dst
.zoom <- src.zoom;
6440 dst
.presentation
<- src.presentation
;
6441 dst
.angle
<- src.angle
;
6442 dst
.cwinw
<- src.cwinw
;
6443 dst
.cwinh
<- src.cwinh
;
6444 dst
.savebmarks
<- src.savebmarks
;
6445 dst
.memlimit
<- src.memlimit
;
6446 dst
.fitmodel
<- src.fitmodel
;
6447 dst
.texcount
<- src.texcount
;
6448 dst
.sliceheight
<- src.sliceheight
;
6449 dst
.thumbw
<- src.thumbw
;
6450 dst
.jumpback
<- src.jumpback
;
6451 dst
.bgcolor
<- src.bgcolor
;
6452 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6453 dst
.tilew
<- src.tilew
;
6454 dst
.tileh
<- src.tileh
;
6455 dst
.mustoresize
<- src.mustoresize
;
6456 dst
.checkers
<- src.checkers
;
6457 dst
.aalevel
<- src.aalevel
;
6458 dst
.trimmargins
<- src.trimmargins
;
6459 dst
.trimfuzz
<- src.trimfuzz
;
6460 dst
.urilauncher
<- src.urilauncher
;
6461 dst
.colorspace
<- src.colorspace
;
6462 dst
.invert
<- src.invert
;
6463 dst
.colorscale
<- src.colorscale
;
6464 dst
.redirectstderr <- src.redirectstderr;
6465 dst
.ghyllscroll
<- src.ghyllscroll
;
6466 dst
.columns
<- src.columns
;
6467 dst
.beyecolumns
<- src.beyecolumns
;
6468 dst
.selcmd
<- src.selcmd
;
6469 dst
.updatecurs
<- src.updatecurs
;
6470 dst
.pathlauncher
<- src.pathlauncher
;
6471 dst
.keyhashes
<- copykeyhashes src;
6472 dst
.hfsize
<- src.hfsize
;
6473 dst
.hscrollstep
<- src.hscrollstep
;
6474 dst
.pgscale <- src.pgscale;
6475 dst
.usepbo
<- src.usepbo
;
6476 dst
.wheelbypage
<- src.wheelbypage
;
6477 dst
.stcmd
<- src.stcmd
;
6481 let h = Hashtbl.create
10 in
6482 let dc = { defconf with angle
= defconf.angle
} in
6483 let rec toplevel v t spos
_ =
6485 | Vdata
| Vcdata
| Vend
-> v
6486 | Vopen
("llppconfig", _, closed
) ->
6489 else { v with f = llppconfig
}
6491 error
"unexpected subelement at top level" s spos
6492 | Vclose
_ -> error
"unexpected close at top level" s spos
6494 and llppconfig
v t spos
_ =
6496 | Vdata
| Vcdata
-> v
6497 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6498 | Vopen
("defaults", attrs
, closed
) ->
6499 let c = config_of dc attrs
in
6503 else { v with f = defaults
}
6505 | Vopen
("ui-font", attrs
, closed
) ->
6506 let rec getsize size
= function
6508 | ("size", v) :: rest
->
6510 fromstring int_of_string spos
"size" v fstate.fontsize
in
6512 | l -> getsize size l
6514 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6517 else { v with f = uifont
(Buffer.create
10) }
6519 | Vopen
("doc", attrs
, closed
) ->
6520 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6521 let path = unent pathent
6522 and pageno = fromstring int_of_string spos
"page" spage
0
6523 and rely = fromstring float_of_string spos
"rely" srely
0.0
6524 and pan
= fromstring int_of_string spos
"pan" span
0
6525 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6526 let c = config_of dc attrs
in
6527 let anchor = (pageno, rely, visy
) in
6529 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6530 else { v with f = doc
path pan
anchor c [] }
6533 error
"unexpected subelement in llppconfig" s spos
6535 | Vclose
"llppconfig" -> { v with f = toplevel }
6536 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6538 and defaults
v t spos
_ =
6540 | Vdata
| Vcdata
-> v
6541 | Vend
-> error
"unexpected end of input in defaults" s spos
6542 | Vopen
("keymap", attrs
, closed
) ->
6544 try List.assoc
"mode" attrs
6545 with Not_found
-> "global" in
6550 let h = findkeyhash dc modename in
6551 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6554 { v with f = pkeymap
ret KeyMap.empty }
6556 | Vopen
(_, _, _) ->
6557 error
"unexpected subelement in defaults" s spos
6559 | Vclose
"defaults" ->
6560 { v with f = llppconfig
}
6562 | Vclose
_ -> error
"unexpected close in defaults" s spos
6564 and uifont
b v t spos
epos =
6567 Buffer.add_substring
b s spos
(epos - spos
);
6569 | Vopen
(_, _, _) ->
6570 error
"unexpected subelement in ui-font" s spos
6571 | Vclose
"ui-font" ->
6572 if String.length
!fontpath = 0
6573 then fontpath := Buffer.contents
b;
6574 { v with f = llppconfig
}
6575 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6576 | Vend
-> error
"unexpected end of input in ui-font" s spos
6578 and doc
path pan
anchor c bookmarks
v t spos
_ =
6580 | Vdata
| Vcdata
-> v
6581 | Vend
-> error
"unexpected end of input in doc" s spos
6582 | Vopen
("bookmarks", _, closed
) ->
6585 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6587 | Vopen
("keymap", attrs
, closed
) ->
6589 try List.assoc
"mode" attrs
6590 with Not_found
-> "global"
6596 let h = findkeyhash c modename in
6597 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6598 doc
path pan
anchor c bookmarks
6600 { v with f = pkeymap
ret KeyMap.empty }
6602 | Vopen
(_, _, _) ->
6603 error
"unexpected subelement in doc" s spos
6606 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6607 { v with f = llppconfig
}
6609 | Vclose
_ -> error
"unexpected close in doc" s spos
6611 and pkeymap
ret keymap
v t spos
_ =
6613 | Vdata
| Vcdata
-> v
6614 | Vend
-> error
"unexpected end of input in keymap" s spos
6615 | Vopen
("map", attrs
, closed
) ->
6616 let r, l = map_of attrs
in
6617 let kss = fromstring keys_of_string spos
"in" r [] in
6618 let lss = fromstring keys_of_string spos
"out" l [] in
6622 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6623 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6626 then { v with f = pkeymap
ret keymap }
6629 { v with f = skip
"map" f }
6632 error
"unexpected subelement in keymap" s spos
6634 | Vclose
"keymap" ->
6635 { v with f = ret keymap }
6637 | Vclose
_ -> error
"unexpected close in keymap" s spos
6639 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6641 | Vdata
| Vcdata
-> v
6642 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6643 | Vopen
("item", attrs
, closed
) ->
6644 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6645 let page = fromstring int_of_string spos
"page" spage
0
6646 and rely = fromstring float_of_string spos
"rely" srely
0.0
6647 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6649 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6652 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6655 { v with f = skip
"item" f }
6658 error
"unexpected subelement in bookmarks" s spos
6660 | Vclose
"bookmarks" ->
6661 { v with f = doc
path pan
anchor c bookmarks }
6663 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6665 and skip tag
f v t spos
_ =
6667 | Vdata
| Vcdata
-> v
6669 error
("unexpected end of input in skipped " ^ tag
) s spos
6670 | Vopen
(tag'
, _, closed
) ->
6674 let f'
() = { v with f = skip tag
f } in
6675 { v with f = skip tag'
f'
}
6679 else error
("unexpected close in skipped " ^ tag
) s spos
6682 parse
{ f = toplevel; accu = () } s;
6688 let len = in_channel_length ic
in
6689 let s = String.create
len in
6690 really_input ic
s 0 len;
6693 | Parse_error
(msg
, s, pos
) ->
6694 let subs = subs s pos
in
6695 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6696 failwith
("parse error: " ^
s)
6699 failwith
("config load error: " ^ exntos exn
)
6705 let dir = Filename.concat
home ".config" in
6706 if Sys.is_directory
dir then dir else home
6709 Filename.concat
dir "llpp.conf"
6712 let confpath = ref defconfpath;;
6715 if Sys.file_exists
!confpath
6718 (try Some
(open_in_bin
!confpath)
6721 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6732 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6741 f (Hashtbl.create
0, defconf)
6746 let pc, pb
, px, pa
=
6748 Hashtbl.find h (Filename.basename
state.path)
6749 with Not_found
-> dc, [], 0, emptyanchor
6753 state.bookmarks <- pb
;
6755 state.scrollw
<- conf.scrollbw
;
6757 then state.anchor <- pa
;
6758 cbput state.hists
.nav pa
;
6764 let add_attrs bb always
dc c =
6767 then Printf.bprintf bb
"\n %s='%b'" s a
6770 then Printf.bprintf bb
"\n %s='%d'" s a
6773 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6776 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6779 then Printf.bprintf bb
"\n %s='%f'" s a
6783 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6787 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6791 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6795 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6801 | Some
(_N
, _A
, _B
) ->
6802 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6812 else string_of_float
f
6814 Printf.bprintf bb
"\n %s='%s'" s v
6819 | Cmulti
((n, a, b), _) when n > 1 ->
6820 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6821 | Csplit
(n, _) when n > 1 ->
6822 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6828 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6833 Printf.bprintf bb
"\n %s='%s'" s (fitmodel_to_string a)
6835 oi
"width" c.cwinw
dc.cwinw
;
6836 oi
"height" c.cwinh
dc.cwinh
;
6837 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6838 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6839 ob "case-insensitive-search" c.icase
dc.icase
;
6840 ob "preload" c.preload dc.preload;
6841 oi
"page-bias" c.pagebias
dc.pagebias
;
6842 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6843 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6844 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6845 ob "crop-hack" c.crophack
dc.crophack
;
6846 oW
"throttle" c.maxwait
dc.maxwait
;
6847 ob "highlight-links" c.hlinks
dc.hlinks
;
6848 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6849 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6850 oz
"zoom" c.zoom dc.zoom;
6851 ob "presentation" c.presentation
dc.presentation
;
6852 oi
"rotation-angle" c.angle
dc.angle
;
6853 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6854 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
6855 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6856 oi
"tex-count" c.texcount
dc.texcount
;
6857 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6858 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6859 ob "persistent-location" c.jumpback
dc.jumpback
;
6860 oc
"background-color" c.bgcolor
dc.bgcolor
;
6861 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6862 oi
"tile-width" c.tilew
dc.tilew
;
6863 oi
"tile-height" c.tileh
dc.tileh
;
6864 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6865 ob "checkers" c.checkers
dc.checkers
;
6866 oi
"aalevel" c.aalevel
dc.aalevel
;
6867 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6868 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6869 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6870 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6871 oC
"color-space" c.colorspace
dc.colorspace
;
6872 ob "invert-colors" c.invert
dc.invert
;
6873 oF
"brightness" c.colorscale
dc.colorscale
;
6874 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6875 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6876 oco
"columns" c.columns
dc.columns
;
6877 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6878 os
"selection-command" c.selcmd
dc.selcmd
;
6879 os
"synctex-command" c.stcmd
dc.stcmd
;
6880 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6881 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6882 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6883 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6884 ob "use-pbo" c.usepbo
dc.usepbo
;
6885 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6888 let keymapsbuf always
dc c =
6889 let bb = Buffer.create
16 in
6890 let rec loop = function
6892 | (modename, h) :: rest
->
6893 let dh = findkeyhash dc modename in
6894 if always
|| h <> dh
6896 if Hashtbl.length
h > 0
6898 if Buffer.length
bb > 0
6899 then Buffer.add_char
bb '
\n'
;
6900 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6901 Hashtbl.iter
(fun i
o ->
6902 let isdifferent = always
||
6904 let dO = Hashtbl.find dh i
in
6906 with Not_found
-> true
6911 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6912 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6913 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6914 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6915 Buffer.add_string
bb (Wsi.keyname
k);
6918 let rec loop = function
6920 | km
:: [] -> addkm km
6921 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6925 Buffer.add_string
bb "<map in='";
6929 Buffer.add_string
bb "' out='";
6931 Buffer.add_string
bb "'/>\n"
6934 Buffer.add_string
bb "' out='";
6936 Buffer.add_string
bb "'/>\n"
6938 | KMmulti
(ins, kms
) ->
6939 Buffer.add_char
bb ' '
;
6941 Buffer.add_string
bb "' out='";
6943 Buffer.add_string
bb "'/>\n"
6945 Buffer.add_string
bb "</keymap>";
6955 let uifontsize = fstate.fontsize
in
6956 let bb = Buffer.create
32768 in
6961 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
)
6962 | Wsi.MaxVert
-> (w, conf.cwinh
)
6963 | Wsi.MaxHorz
-> (conf.cwinw
, h)
6965 (state.winw, state.winh
) state.winstate
6970 let dc = if conf.bedefault
then conf else dc in
6971 Buffer.add_string
bb "<llppconfig>\n";
6973 if String.length
!fontpath > 0
6975 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6981 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6984 Buffer.add_string
bb "<defaults ";
6985 add_attrs bb true dc dc;
6986 let kb = keymapsbuf true dc dc in
6987 if Buffer.length
kb > 0
6989 Buffer.add_string
bb ">\n";
6990 Buffer.add_buffer
bb kb;
6991 Buffer.add_string
bb "\n</defaults>\n";
6993 else Buffer.add_string
bb "/>\n";
6995 let adddoc path pan
anchor c bookmarks =
6996 if bookmarks == [] && c = dc && anchor = emptyanchor
6999 Printf.bprintf
bb "<doc path='%s'"
7000 (enent
path 0 (String.length
path));
7002 if anchor <> emptyanchor
7004 let n, rely, visy
= anchor in
7005 Printf.bprintf
bb " page='%d'" n;
7008 Printf.bprintf
bb " rely='%f'" rely
7010 if abs_float visy
> 1e-6
7012 Printf.bprintf
bb " visy='%f'" visy
7017 then Printf.bprintf
bb " pan='%d'" pan
;
7019 add_attrs bb false dc c;
7020 let kb = keymapsbuf false dc c in
7022 begin match bookmarks with
7024 if Buffer.length
kb > 0
7026 Buffer.add_string
bb ">\n";
7027 Buffer.add_buffer
bb kb;
7028 Buffer.add_string
bb "\n</doc>\n";
7030 else Buffer.add_string
bb "/>\n"
7032 Buffer.add_string
bb ">\n<bookmarks>\n";
7033 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7035 "<item title='%s' page='%d'"
7036 (enent
title 0 (String.length
title))
7041 Printf.bprintf
bb " rely='%f'" rely
7043 if abs_float visy
> 1e-6
7045 Printf.bprintf
bb " visy='%f'" visy
7047 Buffer.add_string
bb "/>\n";
7049 Buffer.add_string
bb "</bookmarks>";
7050 if Buffer.length
kb > 0
7052 Buffer.add_string
bb "\n";
7053 Buffer.add_buffer
bb kb;
7055 Buffer.add_string
bb "\n</doc>\n";
7061 match state.mode with
7062 | Birdseye
(c, pan, _, _, _) ->
7064 match conf.columns
with
7065 | Cmulti
((c, _, _), _) -> Some
c
7069 match c.columns
with
7070 | Cmulti
(c, _) -> Cmulti
(c, [||])
7071 | Csingle
_ -> Csingle
[||]
7072 | Csplit
_ -> failwith
"quit from bird's eye while split"
7074 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7075 | _ -> state.x, conf
7077 let basename = Filename.basename state.path in
7078 adddoc basename pan (getanchor ())
7080 let autoscrollstep =
7081 match state.autoscroll
with
7083 | None
-> conf.autoscrollstep
7085 match state.mode with
7086 | Birdseye
(bc
, _, _, _, _) ->
7089 presentation
= bc
.presentation
;
7090 interpagespace
= bc
.interpagespace
;
7091 maxwait
= bc
.maxwait
;
7092 autoscrollstep = autoscrollstep }
7093 | _ -> { conf with autoscrollstep = autoscrollstep }
7095 (if conf.savebmarks
then state.bookmarks else []);
7097 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7099 then adddoc path x anchor c bookmarks
7101 Buffer.add_string
bb "</llppconfig>\n";
7104 if load1 f && Buffer.length
bb > 0
7107 let tmp = !confpath ^
".tmp" in
7108 let oc = open_out_bin
tmp in
7109 Buffer.output_buffer
oc bb;
7111 Unix.rename
tmp !confpath;
7114 ("error while saving configuration: " ^ exntos exn
)
7118 let adderrmsg src msg
=
7119 Buffer.add_string
state.errmsgs msg
;
7120 state.newerrmsgs
<- true;
7124 let adderrfmt src fmt
=
7125 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7129 let cl = splitatspace cmds
in
7131 try Scanf.sscanf
s fmt
f
7133 adderrfmt "remote exec"
7134 "error processing '%S': %s\n" cmds
(exntos exn
)
7137 | "reload" :: [] -> reload ()
7138 | "goto" :: args :: [] ->
7139 scan args "%u %f %f"
7141 let cmd, _ = state.geomcmds
in
7142 if String.length
cmd = 0
7143 then gotopagexy pageno x y
7146 gotopagexy pageno x y;
7149 state.reprf
<- f state.reprf
7151 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7152 | "rect" :: args :: [] ->
7153 scan args "%u %u %f %f %f %f"
7154 (fun pageno color x0 y0 x1 y1 ->
7155 onpagerect pageno (fun w h ->
7156 let _,w1,h1
,_ = getpagedim pageno in
7157 let sw = float w1 /. w
7158 and sh = float h1
/. h in
7162 and y1s
= y1 *. sh in
7163 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7165 state.rects <- (pageno, color, rect) :: state.rects;
7166 G.postRedisplay "rect";
7169 | "activatewin" :: [] -> Wsi.activatewin
()
7170 | "quit" :: [] -> raise Quit
7172 adderrfmt "remote command"
7173 "error processing remote command: %S\n" cmds
;
7177 let scratch = String.create
80 in
7178 let buf = Buffer.create
80 in
7181 try Some
(Unix.read fd
scratch 0 80)
7183 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7184 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7187 match tempfr () with
7193 if Buffer.length
buf > 0
7195 let s = Buffer.contents
buf in
7205 let pos = String.index_from
scratch ppos '
\n'
in
7206 if pos >= n then -1 else pos
7207 with Not_found
-> -1
7211 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7212 let s = Buffer.contents
buf in
7218 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7224 let remoteopen path =
7225 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7227 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7232 let trimcachepath = ref "" in
7233 let rcmdpath = ref "" in
7236 [("-p", Arg.String
(fun s -> state.password
<- s),
7237 "<password> Set password");
7239 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7240 "<path> Set path to the user interface font");
7242 ("-c", Arg.String
(fun s -> Config.confpath := s),
7243 "<path> Set path to the configuration file");
7245 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7246 "<path> Set path to the trim cache file");
7248 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7249 "<named-destination> Set named destination");
7251 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7253 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7254 "<path> Set path to the remote commands source");
7256 ("-v", Arg.Unit
(fun () ->
7258 "%s\nconfiguration path: %s\n"
7262 exit
0), " Print version and exit");
7265 (fun s -> state.path <- s)
7266 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7268 if String.length
state.path = 0
7269 then (prerr_endline
"file name missing"; exit
1);
7271 if not
(Config.load ())
7272 then prerr_endline
"failed to load configuration";
7274 let globalkeyhash = findkeyhash conf "global" in
7275 let wsfd, winw, winh
= Wsi.init
(object
7277 if nogeomcmds state.geomcmds
|| platform == Posx
7280 GlClear.color (scalecolor2 conf.bgcolor
);
7281 GlClear.clear
[`
color];
7283 method display = display ()
7284 method reshape w h = reshape w h
7285 method mouse b d x y m = mouse b d x y m
7286 method motion x y = state.mpos
<- (x, y); motion x y
7287 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7289 let mascm = m land (
7290 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7292 match state.keystate
with
7294 let km = k, mascm in
7297 let modehash = state.uioh#
modehash in
7298 try Hashtbl.find modehash km
7300 try Hashtbl.find globalkeyhash km
7301 with Not_found
-> KMinsrt
(k, m)
7303 | KMinsrt
(k, m) -> keyboard k m
7304 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7305 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7307 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7308 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7309 state.keystate
<- KSnone
7310 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7311 state.keystate
<- KSinto
(keys
, insrt
)
7313 state.keystate
<- KSnone
7315 method enter
x y = state.mpos
<- (x, y); pmotion x y
7316 method leave = state.mpos
<- (-1, -1)
7317 method winstate wsl
= state.winstate
<- wsl
7318 method quit
= raise Quit
7319 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7324 List.exists
GlMisc.check_extension
7325 [ "GL_ARB_texture_rectangle"
7326 ; "GL_EXT_texture_recangle"
7327 ; "GL_NV_texture_rectangle" ]
7329 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7332 match Ne.pipe () with
7334 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7338 match Ne.pipe () with
7340 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7350 setcheckers conf.checkers
;
7354 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7355 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7356 !Config.fontpath, !trimcachepath,
7357 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7361 state.text <- "Opening " ^
(mbtoutf8
state.path);
7363 opendoc state.path state.password
;
7366 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7369 if String.length
!rcmdpath > 0
7370 then remoteopen !rcmdpath
7375 let rec loop deadline
=
7377 match state.errfd
with
7378 | None
-> [state.sr
; state.wsfd]
7379 | Some fd
-> [state.sr
; state.wsfd; fd
]
7384 | Some fd
-> fd
:: r
7388 state.redisplay
<- false;
7395 if deadline
= infinity
7397 else max
0.0 (deadline
-. now)
7402 try Unix.select
r [] [] timeout
7403 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7409 if state.ghyll
== noghyll
7411 match state.autoscroll
with
7412 | Some step
when step
!= 0 ->
7413 let y = state.y + step
in
7417 else if y >= state.maxy then 0 else y
7420 if state.mode = View
7421 then state.text <- "";
7424 else deadline
+. 0.01
7429 let rec checkfds = function
7431 | fd
:: rest
when fd
= state.sr
->
7432 let cmd = readcmd state.sr
in
7436 | fd
:: rest
when fd
= state.wsfd ->
7440 | fd
:: rest
when Some fd
= !optrfd ->
7441 begin match remote fd
with
7442 | None
-> optrfd := remoteopen !rcmdpath;
7443 | opt -> optrfd := opt
7448 let s = String.create
80 in
7449 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7450 if conf.redirectstderr
7452 Buffer.add_substring
state.errmsgs
s 0 n;
7453 state.newerrmsgs
<- true;
7454 state.redisplay
<- true;
7457 prerr_string
(String.sub
s 0 n);
7465 if deadline
= infinity
7469 match state.autoscroll
with
7470 | Some step
when step
!= 0 -> deadline1
7471 | _ -> if state.ghyll
== noghyll then infinity
else deadline1