3 let tempfailureretry = Wsi.tempfailureretry;;
8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
17 let now = Unix.gettimeofday
;;
19 type params
= (angle
* proportional
* trimparams
20 * texcount
* sliceheight
* memsize
21 * colorspace
* fontpath
* trimcachepath
31 and proportional
= bool
32 and trimmargins
= bool
33 and interpagespace
= int
40 and trimcachepath
= string
43 and irect
= (int * int * int * int)
44 and trimparams
= (trimmargins
* irect
)
45 and colorspace
= | Rgb
| Bgr
| Gray
55 | LDfirstvisible
of (int * int * int)
70 | KMmulti
of key list
* key list
72 and keyhash
= (key
, keymap
) Hashtbl.t
75 | KSinto
of (key list
* key list
)
78 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
79 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
81 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
83 external init
: pipe
-> params
-> unit = "ml_init";;
84 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
85 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
86 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
87 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
88 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
89 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
90 external measurestr
: int -> string -> float = "ml_measure_string";;
91 external getmaxw
: unit -> float = "ml_getmaxw";;
92 external postprocess
:
93 opaque
-> int -> int -> int -> (int * string * int) -> int
95 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
96 external platform
: unit -> platform
= "ml_platform";;
97 external setaalevel
: int -> unit = "ml_setaalevel";;
98 external realloctexts
: int -> bool = "ml_realloctexts";;
99 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
100 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
101 external getlink
: opaque
-> int -> under
= "ml_getlink";;
102 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
103 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
104 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
105 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
106 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
107 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
108 external freepbo
: string -> unit = "ml_freepbo";;
109 external unmappbo
: string -> unit = "ml_unmappbo";;
110 external pbousable
: unit -> bool = "ml_pbo_usable";;
111 external unproject
: opaque
-> int -> int -> (int * int) option
114 let platform_to_string = function
115 | Punknown
-> "unknown"
119 | Pfreebsd
-> "FreeBSD"
120 | Pdragonflybsd
-> "DragonflyBSD"
121 | Popenbsd
-> "OpenBSD"
122 | Pnetbsd
-> "NetBSD"
123 | Pcygwin
-> "Cygwin"
126 let platform = platform ();;
129 if platform = Pcygwin
131 let sh = "/bin/sh" in
132 let args = [|sh; "-c"; cmd
|] in
133 let rec std si so se
= function
135 | (fd
, 0) :: rest
-> std fd so se rest
136 | (fd
, -1) :: rest
->
137 Unix.set_close_on_exec fd
;
140 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
142 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
143 ignore
(Unix.create_process
sh args si so se
)
152 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
155 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
157 type mpos
= int * int
159 | Msel
of (mpos
* mpos
)
161 | Mscrolly
| Mscrollx
162 | Mzoom
of (int * int)
163 | Mzoomrect
of (mpos
* mpos
)
167 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
168 and onkey
= string -> int -> te
169 and ondone
= string -> unit
170 and histcancel
= unit -> unit
171 and onhist
= ((histcmd
-> string) * histcancel
)
172 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
173 and cancelonempty
= bool
178 | TEswitch
of textentry
189 let bound v minv maxv
=
190 max minv
(min maxv v
);
194 { store
= Array.create n v
201 let cbcap b
= Array.length b
.store
;;
206 b
.wc
<- (b
.wc
+ 1) mod cap;
208 b
.len
<- min
(b
.len
+ 1) cap;
211 let cbempty b
= b
.len
= 0;;
213 let cbgetg b circular dir
=
217 let rc = b
.rc + dir
in
229 else bound rc 0 (b
.len
-1)
235 let cbget b
= cbgetg b
false;;
236 let cbgetc b
= cbgetg b
true;;
238 let drawstring size x y s
=
240 Gl.enable `texture_2d
;
241 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
242 ignore
(drawstr size x y s
);
244 Gl.disable `texture_2d
;
247 let drawstring1 size x y s
=
251 let drawstring2 size x y fmt
=
252 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
271 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
272 dolog " WxH %dx%d" l
.pagew l
.pageh
;
273 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
274 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
275 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
276 dolog " column %d" l
.pagecol
;
280 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
282 dolog " x0,y0=(% f, % f)" x0 y0
;
283 dolog " x1,y1=(% f, % f)" x1 y1
;
284 dolog " x2,y2=(% f, % f)" x2 y2
;
285 dolog " x3,y3=(% f, % f)" x3 y3
;
289 type multicolumns
= multicol
* pagegeom
290 and singlecolumn
= pagegeom
291 and splitcolumns
= columncount
* pagegeom
292 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
293 and multicol
= columncount
* covercount
* covercount
295 and columncount
= int
296 and covercount
= int;;
299 { mutable scrollbw
: int
300 ; mutable scrollh
: int
301 ; mutable icase
: bool
302 ; mutable preload
: bool
303 ; mutable pagebias
: int
304 ; mutable verbose
: bool
305 ; mutable debug
: bool
306 ; mutable scrollstep
: int
307 ; mutable hscrollstep
: int
308 ; mutable maxhfit
: bool
309 ; mutable crophack
: bool
310 ; mutable autoscrollstep
: int
311 ; mutable maxwait
: float option
312 ; mutable hlinks
: bool
313 ; mutable underinfo
: bool
314 ; mutable interpagespace
: interpagespace
315 ; mutable zoom
: float
316 ; mutable presentation
: bool
317 ; mutable angle
: angle
318 ; mutable cwinw
: int
319 ; mutable cwinh
: int
320 ; mutable savebmarks
: bool
321 ; mutable proportional
: proportional
322 ; mutable trimmargins
: trimmargins
323 ; mutable trimfuzz
: irect
324 ; mutable memlimit
: memsize
325 ; mutable texcount
: texcount
326 ; mutable sliceheight
: sliceheight
327 ; mutable thumbw
: width
328 ; mutable jumpback
: bool
329 ; mutable bgcolor
: float * float * float
330 ; mutable bedefault
: bool
331 ; mutable scrollbarinpm
: bool
332 ; mutable tilew
: int
333 ; mutable tileh
: int
334 ; mutable mustoresize
: memsize
335 ; mutable checkers
: bool
336 ; mutable aalevel
: int
337 ; mutable urilauncher
: string
338 ; mutable pathlauncher
: string
339 ; mutable colorspace
: colorspace
340 ; mutable invert
: bool
341 ; mutable colorscale
: float
342 ; mutable redirectstderr
: bool
343 ; mutable ghyllscroll
: (int * int * int) option
344 ; mutable columns
: columns
345 ; mutable beyecolumns
: columncount
option
346 ; mutable selcmd
: string
347 ; mutable updatecurs
: bool
348 ; mutable keyhashes
: (string * keyhash
) list
349 ; mutable hfsize
: int
350 ; mutable pgscale
: float
351 ; mutable usepbo
: bool
352 ; mutable wheelbypage
: bool
353 ; mutable stcmd
: string
356 | Csingle
of singlecolumn
357 | Cmulti
of multicolumns
358 | Csplit
of splitcolumns
361 type anchor
= pageno
* top
* dtop
;;
363 type outline
= string * int * anchor
;;
365 type rect
= float * float * float * float * float * float * float * float;;
367 type tile
= opaque
* pixmapsize
* elapsed
368 and elapsed
= float;;
369 type pagemapkey
= pageno
* gen
;;
370 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
374 let emptyanchor = (0, 0.0, 0.0);;
376 type infochange
= | Memused
| Docinfo
| Pdim
;;
378 class type uioh
= object
379 method display
: unit
380 method key
: int -> int -> uioh
381 method button
: int -> bool -> int -> int -> int -> uioh
382 method motion
: int -> int -> uioh
383 method pmotion
: int -> int -> uioh
384 method infochanged
: infochange
-> unit
385 method scrollpw
: (int * float * float)
386 method scrollph
: (int * float * float)
387 method modehash
: keyhash
391 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
392 | Textentry
of (textentry
* onleave
)
394 | LinkNav
of linktarget
395 and onleave
= leavetextentrystatus
-> unit
396 and leavetextentrystatus
= | Cancel
| Confirm
397 and helpitem
= string * int * action
400 | Action
of (uioh
-> uioh
)
402 | Ltexact
of (pageno
* int)
406 let isbirdseye = function Birdseye _
-> true | _
-> false;;
407 let istextentry = function Textentry _
-> true | _
-> false;;
411 | Loading
of (page
* gen
)
413 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
415 | Outlining
of outline list
418 let emptykeyhash = Hashtbl.create
0;;
419 let nouioh : uioh
= object (self
)
421 method key _ _
= self
422 method button _ _ _ _ _
= self
423 method motion _ _
= self
424 method pmotion _ _
= self
425 method infochanged _
= ()
426 method scrollpw
= (0, nan
, nan
)
427 method scrollph
= (0, nan
, nan
)
428 method modehash
= emptykeyhash
432 { mutable sr
: Unix.file_descr
433 ; mutable sw
: Unix.file_descr
434 ; mutable wsfd
: Unix.file_descr
435 ; mutable errfd
: Unix.file_descr
option
436 ; mutable stderr
: Unix.file_descr
437 ; mutable errmsgs
: Buffer.t
438 ; mutable newerrmsgs
: bool
442 ; mutable scrollw
: int
443 ; mutable hscrollh
: int
444 ; mutable anchor
: anchor
445 ; mutable ranchors
: (string * string * anchor
) list
447 ; mutable layout
: page list
448 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
449 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
450 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
451 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
452 ; mutable pagecount
: int
453 ; mutable currently
: currently
454 ; mutable mstate
: mstate
455 ; mutable searchpattern
: string
456 ; mutable rects
: (pageno
* recttype
* rect
) list
457 ; mutable rects1
: (pageno
* recttype
* rect
) list
458 ; mutable text
: string
459 ; mutable winstate
: Wsi.winstate list
460 ; mutable mode
: mode
461 ; mutable uioh
: uioh
462 ; mutable outlines
: outline array
463 ; mutable bookmarks
: outline list
464 ; mutable path
: string
465 ; mutable password
: string
466 ; mutable nameddest
: string
467 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
468 ; mutable memused
: memsize
470 ; mutable throttle
: (page list
* int * float) option
471 ; mutable autoscroll
: int option
472 ; mutable ghyll
: (int option -> unit)
473 ; mutable help
: helpitem array
474 ; mutable docinfo
: (int * string) list
475 ; mutable texid
: GlTex.texture_id
option
477 ; mutable prevzoom
: float
478 ; mutable progress
: float
479 ; mutable redisplay
: bool
480 ; mutable mpos
: mpos
481 ; mutable keystate
: keystate
482 ; mutable glinks
: bool
483 ; mutable prevcolumns
: (columns
* float) option
484 ; mutable wthack
: bool
487 ; mutable reprf
: (unit -> unit)
490 { pat
: string circbuf
491 ; pag
: string circbuf
492 ; nav
: anchor circbuf
493 ; sel
: string circbuf
515 ; presentation
= false
520 ; proportional
= true
521 ; trimmargins
= false
522 ; trimfuzz
= (0,0,0,0)
523 ; memlimit
= 32 lsl 20
528 ; bgcolor
= (0.5, 0.5, 0.5)
530 ; scrollbarinpm
= true
533 ; mustoresize
= 256 lsl 20
538 | Plinux
| Pfreebsd
| Pdragonflybsd
539 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
540 | Posx
-> "open \"%s\""
541 | Pcygwin
-> "cygstart \"%s\""
542 | Punknown
-> "echo %s")
543 ; pathlauncher
= "lp \"%s\""
546 | Plinux
| Pfreebsd
| Pdragonflybsd
547 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
554 ; redirectstderr
= false
556 ; columns
= Csingle
[||]
562 ; wheelbypage
= false
563 ; stcmd
= "echo SyncTex"
565 let mk n
= (n
, Hashtbl.create
1) in
579 let wtmode = ref false;;
581 let findkeyhash c name
=
582 try List.assoc name c
.keyhashes
583 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
586 let conf = { defconf with angle
= defconf.angle
};;
588 let pgscale h
= truncate
(float h
*. conf.pgscale);;
591 { mutable fontsize
: int
592 ; mutable wwidth
: float
593 ; mutable maxrows
: int
605 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
606 let len = String.length s
in
607 if colonpos >= 0 && colonpos + 3 < len
609 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
612 try String.rindex_from s
colonpos ' '
616 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
619 | "http" | "ftp" | "mailto" ->
621 try String.index_from s
colonpos ' '
622 with Not_found
-> len
624 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
632 if String.length
conf.urilauncher
= 0
633 then print_endline uri
635 let url = geturl uri
in
636 if String.length
url = 0
637 then print_endline uri
639 let re = Str.regexp
"%s" in
640 let command = Str.global_replace
re url conf.urilauncher
in
644 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
650 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
651 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
655 let strings = version () :: "" :: Help.keys
in
658 let url = geturl s
in
659 if String.length
url > 0
660 then (s
, 0, Action
(fun u
-> gotouri url; u
))
661 else (s
, 0, Noaction
)
666 let firstgeomcmds = "", [];;
667 let noreprf () = ();;
674 ; stderr
= Unix.stderr
675 ; errmsgs
= Buffer.create
0
682 ; anchor
= emptyanchor
686 ; tilelru
= Queue.create
()
687 ; pagemap
= Hashtbl.create
10
688 ; tilemap
= Hashtbl.create
10
704 ; geomcmds
= firstgeomcmds
706 { nav
= cbnew 10 emptyanchor
735 fstate.fontsize
<- n
;
736 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
737 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
743 Printf.kprintf prerr_endline fmt
745 Printf.kprintf ignore fmt
749 if String.length
conf.pathlauncher
= 0
750 then print_endline
state.path
752 let re = Str.regexp
"%s" in
753 let command = Str.global_replace
re state.path
conf.pathlauncher
in
757 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
763 type 'a t
= | Res
of 'a
| Exn
of exn
;;
766 try Res
(Unix.pipe ())
771 try tempfailureretry Unix.close fd
772 with exn
-> f
(Printexc.to_string exn
)
776 try Res
(tempfailureretry Unix.dup fd
)
781 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
786 let redirectstderr () =
787 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
788 if conf.redirectstderr
790 match Ne.pipe () with
792 dolog "failed to create stderr redirection pipes: %s"
793 (Printexc.to_string exn
)
796 begin match Ne.dup Unix.stderr
with
798 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
799 Ne.clo r
(clofail "pipe/r");
800 Ne.clo w
(clofail "pipe/w");
802 | Ne.Res dupstderr
->
803 begin match Ne.dup2 w
Unix.stderr
with
805 dolog "failed to dup2 to stderr: %s"
806 (Printexc.to_string exn
);
807 Ne.clo dupstderr
(clofail "stderr duplicate");
808 Ne.clo r
(clofail "redir pipe/r");
809 Ne.clo w
(clofail "redir pipe/w");
812 state.stderr
<- dupstderr
;
813 state.errfd
<- Some r
;
817 state.newerrmsgs
<- false;
818 begin match state.errfd
with
820 begin match Ne.dup2 state.stderr
Unix.stderr
with
822 dolog "failed to dup2 original stderr: %s"
823 (Printexc.to_string exn
)
825 Ne.clo fd
(clofail "dup of stderr");
830 prerr_string
(Buffer.contents
state.errmsgs
);
832 Buffer.clear
state.errmsgs
;
838 let postRedisplay who
=
840 then prerr_endline
("redisplay for " ^ who
);
841 state.redisplay
<- true;
845 let getopaque pageno
=
846 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
847 with Not_found
-> None
850 let putopaque pageno opaque
=
851 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
854 let pagetranslatepoint l x y
=
855 let dy = y
- l
.pagedispy
in
856 let y = dy + l
.pagey
in
857 let dx = x
- l
.pagedispx
in
858 let x = dx + l
.pagex
in
862 let onppundermouse g
x y d
=
865 begin match getopaque l
.pageno
with
867 let x0 = l
.pagedispx
in
868 let x1 = x0 + l
.pagevw
in
869 let y0 = l
.pagedispy
in
870 let y1 = y0 + l
.pagevh
in
871 if y >= y0 && y <= y1 && x >= x0 && x <= x1
873 let px, py
= pagetranslatepoint l
x y in
874 match g opaque l
px py
with
887 let g opaque _
px py
=
888 match whatsunder opaque
px py
with
890 | under
-> Some under
892 onppundermouse g x y Unone
897 match unproject opaque
x y with
898 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
901 onppundermouse g x y None
;
905 state.text
<- Printf.sprintf
"%c%s" c s
;
906 G.postRedisplay "showtext";
909 let undertext = function
912 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
913 | Utext s
-> "font: " ^ s
914 | Uunexpected s
-> "unexpected: " ^ s
915 | Ulaunch s
-> "launch: " ^ s
916 | Unamed s
-> "named: " ^ s
917 | Uremote
(filename
, pageno
) ->
918 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
921 let updateunder x y =
922 match getunder x y with
923 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
925 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
926 Wsi.setcursor
Wsi.CURSOR_INFO
927 | Ulinkgoto
(pageno
, _
) ->
929 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
930 Wsi.setcursor
Wsi.CURSOR_INFO
932 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
933 Wsi.setcursor
Wsi.CURSOR_TEXT
935 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
936 Wsi.setcursor
Wsi.CURSOR_INHERIT
938 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
939 Wsi.setcursor
Wsi.CURSOR_INHERIT
941 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
942 Wsi.setcursor
Wsi.CURSOR_INHERIT
943 | Uremote
(filename
, pageno
) ->
944 if conf.underinfo
then showtext 'r'
945 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
946 Wsi.setcursor
Wsi.CURSOR_INFO
949 let showlinktype under
=
955 let s = undertext under
in
960 let b = Buffer.create
(String.length
s + 1) in
961 Buffer.add_string
b s;
966 let colorspace_of_string s =
967 match String.lowercase
s with
971 | _
-> failwith
"invalid colorspace"
974 let int_of_colorspace = function
980 let colorspace_of_int = function
984 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
987 let colorspace_to_string = function
993 let intentry_with_suffix text key
=
995 if key
>= 32 && key
< 127
999 match Char.lowercase
c with
1001 let text = addchar text c in
1004 | 'k'
| 'm'
| '
g'
->
1005 let text = addchar text c in
1009 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1013 let multicolumns_to_string (n
, a
, b) =
1015 then Printf.sprintf
"%d" n
1016 else Printf.sprintf
"%d,%d,%d" n a
b;
1019 let multicolumns_of_string s =
1021 (int_of_string
s, 0, 0)
1023 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1025 then failwith
"subtly broken"; (n
, a
, b)
1031 let n = tempfailureretry (Unix.read fd
s 0) 4 in
1032 if n != 4 then failwith
"incomplete read(len)";
1034 lor (Char.code
s.[0] lsl 24)
1035 lor (Char.code
s.[1] lsl 16)
1036 lor (Char.code
s.[2] lsl 8)
1037 lor (Char.code
s.[3] lsl 0)
1039 let s = String.create
len in
1040 let n = tempfailureretry (Unix.read fd
s 0) len in
1041 if n != len then failwith
"incomplete read(data)";
1045 let btod b = if b then 1 else 0;;
1048 let b = Buffer.create
16 in
1049 Buffer.add_string
b "llll";
1052 let s = Buffer.contents
b in
1053 let n = String.length
s in
1055 (* dolog "wcmd %S" (String.sub s 4 len); *)
1056 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1057 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1058 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1059 s.[3] <- Char.chr
(len land 0xff);
1060 let n'
= tempfailureretry (Unix.write
state.sw
s 0) n in
1061 if n'
!= n then failwith
"write failed";
1066 let d = state.winh
- h
in
1067 max
conf.interpagespace
((d + 1) / 2)
1070 let rowyh (c, coverA
, coverB
) b n =
1071 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1073 let _, _, vy
, (_, _, h
, _) = b.(n) in
1076 let n'
= n - coverA
in
1079 let e = min
state.pagecount
(s + c) in
1080 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1081 let _, _, y, (_, _, h
, _) = b.(m
) in
1082 let miny = min
miny y in
1083 let maxh = max
maxh h
in
1084 find (m
+1) miny maxh
1089 match conf.columns
with
1090 | Cmulti
((_, _, _) as cl
, b) ->
1091 if Array.length
b > 0
1093 let y, h
= rowyh cl
b (Array.length
b - 1) in
1094 y + h
+ (if conf.presentation
then calcips h
else 0)
1097 if Array.length
b > 0
1099 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1100 y + h
+ (if conf.presentation
then calcips h
else 0)
1103 if Array.length
b > 0
1105 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1110 let getpageyh pageno
=
1111 let pageno = bound pageno 0 (state.pagecount
-1) in
1112 match conf.columns
with
1114 if Array.length
b = 0
1117 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1119 if conf.presentation
1125 if Array.length
b = 0
1128 let y, h
= rowyh cl
b pageno in
1130 if conf.presentation
1136 if Array.length
b = 0
1140 let (_, _, y, (_, _, h
, _)) = b.(n) in
1144 let getpagedim pageno =
1147 | (n, _, _, _) as pdim
:: rest
->
1149 then (if n = pageno then pdim
else ppdim
)
1154 f (-1, -1, -1, -1) state.pdims
1157 let getpagey pageno = fst
(getpageyh pageno);;
1159 let nogeomcmds cmds
=
1161 | s, [] -> String.length
s = 0
1166 let ((c, coverA
, coverB
) as cl
), b =
1167 match conf.columns
with
1168 | Csingle
b -> (1, 0, 0), b
1169 | Cmulti
(c, b) -> c, b
1170 | Csplit
(_, b) -> (1, 0, 0), b
1172 if Array.length
b = 0
1175 let rec bsearch nmin nmax
=
1177 then bound nmin
0 (state.pagecount
-1)
1179 let n = (nmax
+ nmin
) / 2 in
1180 let vy, h
= rowyh cl
b n in
1182 if conf.presentation
1184 let ips = calcips h
in
1185 let y0 = vy - ips in
1186 let y1 = vy + h
+ ips in
1190 then 0, vy + h
+ conf.interpagespace
1192 let y0 = vy - conf.interpagespace
in
1193 y0, y0 + h
+ conf.interpagespace
1196 if y >= y0 && y < y1
1203 if n < state.pagecount
- coverB
1204 then ((n-coverA
)/c)*c + coverA
1211 then bsearch (n+1) nmax
1212 else bsearch nmin
(n-1)
1215 let r = bsearch 0 (state.pagecount
-1) in
1219 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1220 let sh = sh - state.hscrollh
in
1221 let rec fold accu
n =
1222 if n = Array.length
b
1225 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1228 || n = state.pagecount
- coverB
1229 || (n - coverA
) mod columns
= columns
- 1)
1235 let pagey = max
0 (y - vy) in
1236 let pagedispy = if pagey > 0 then 0 else vy - y in
1237 let pagedispx, pagex
=
1239 if n = coverA
- 1 || n = state.pagecount
- coverB
1240 then state.x + (state.winw
- state.scrollw
- w
) / 2
1241 else dx + xoff
+ state.x
1248 let vw = state.winw
- state.scrollw
- pagedispx in
1249 let pw = w
- pagex
in
1252 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1253 if pagevw > 0 && pagevh > 0
1257 ; pagedimno
= pdimno
1264 ; pagedispx = pagedispx
1265 ; pagedispy = pagedispy
1277 List.rev
(fold [] (page_of_y y));
1280 let layoutS (columns
, b) y sh =
1281 let sh = sh - state.hscrollh
in
1282 let rec fold accu n =
1283 if n = Array.length
b
1286 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1293 let x = xoff
+ state.x in
1294 let pagey = max
0 (y - vy) in
1295 let pagedispy = if pagey > 0 then 0 else vy - y in
1296 let pagedispx, pagex
=
1310 let pagecolw = pagew
/columns
in
1312 if pagecolw < state.winw
1313 then pagedispx + ((state.winw
- state.scrollw
- pagecolw) / 2)
1317 let vw = state.winw
- pagedispx - state.scrollw
in
1318 let pw = pagew
- pagex
in
1321 let pagevw = min
pagevw pagecolw in
1322 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1323 if pagevw > 0 && pagevh > 0
1326 { pageno = n/columns
1327 ; pagedimno
= pdimno
1334 ; pagedispx = pagedispx
1335 ; pagedispy = pagedispy
1336 ; pagecol
= n mod columns
1347 List.rev
(fold [] 0)
1351 if nogeomcmds state.geomcmds
1353 match conf.columns
with
1354 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1355 | Cmulti
c -> layoutN c y sh
1356 | Csplit
s -> layoutS s y sh
1361 let y = state.y + incr
in
1363 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1368 let tilex = l
.pagex
mod conf.tilew
in
1369 let tiley = l
.pagey mod conf.tileh
in
1371 let col = l
.pagex
/ conf.tilew
in
1372 let row = l
.pagey / conf.tileh
in
1374 let rec rowloop row y0 dispy h
=
1378 let dh = conf.tileh
- y0 in
1379 let dh = min h
dh in
1380 let rec colloop col x0 dispx w
=
1384 let dw = conf.tilew
- x0 in
1385 let dw = min w
dw in
1387 f col row dispx dispy
x0 y0 dw dh;
1388 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1391 colloop col tilex l
.pagedispx l
.pagevw;
1392 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1395 if l
.pagevw > 0 && l
.pagevh > 0
1396 then rowloop row tiley l
.pagedispy l
.pagevh;
1399 let gettileopaque l
col row =
1401 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1403 try Some
(Hashtbl.find state.tilemap
key)
1404 with Not_found
-> None
1407 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1408 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1409 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1412 let drawtiles l color
=
1414 let f col row x y tilex tiley w h
=
1415 match gettileopaque l
col row with
1416 | Some
(opaque
, _, t
) ->
1417 let params = x, y, w
, h
, tilex, tiley in
1421 GlFunc.blend_func `zero `one_minus_src_color
;
1423 drawtile
params opaque
;
1425 then Gl.disable `blend
;
1428 let s = Printf.sprintf
1432 let w = measurestr
fstate.fontsize
s in
1433 GlMisc.push_attrib
[`current
];
1434 GlDraw.color
(0.0, 0.0, 0.0);
1436 (float (x-2), float (y-2))
1437 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1438 GlDraw.color
(1.0, 1.0, 1.0);
1439 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1440 GlMisc.pop_attrib
();
1445 let lw = state.winw
- state.scrollw
- x in
1448 let lh = state.winh
- y in
1451 begin match state.texid
with
1453 Gl.enable `texture_2d
;
1454 GlTex.bind_texture `texture_2d id
;
1457 and x1 = float (x+w)
1458 and y1 = float (y+h
) in
1460 let tw = float w /. 16.0
1461 and th
= float h
/. 16.0 in
1462 let tx0 = float tilex /. 16.0
1463 and ty0
= float tiley /. 16.0 in
1465 and ty1
= ty0
+. th
in
1466 GlDraw.begins `quads
;
1467 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1468 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1469 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1470 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1473 Gl.disable `texture_2d
;
1475 GlDraw.color
(1.0, 1.0, 1.0);
1478 (float (x+w), float (y+h
));
1480 if w > 128 && h
> fstate.fontsize
+ 10
1482 GlDraw.color
(0.0, 0.0, 0.0);
1485 then (col*conf.tilew
, row*conf.tileh
)
1488 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1495 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1497 let tilevisible1 l
x y =
1499 and ax1
= l
.pagex
+ l
.pagevw
1501 and ay1
= l
.pagey + l
.pagevh in
1505 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1506 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1508 let rx0 = max
ax0 bx0
1509 and ry0
= max ay0 by0
1510 and rx1
= min ax1
bx1
1511 and ry1
= min ay1 by1
in
1513 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1514 nonemptyintersection
1517 let tilevisible layout n x y =
1518 let rec findpageinlayout m
= function
1519 | l
:: rest
when l
.pageno = n ->
1520 tilevisible1 l
x y || (
1521 match conf.columns
with
1522 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1525 | _ :: rest
-> findpageinlayout 0 rest
1528 findpageinlayout 0 layout;
1531 let tileready l
x y =
1532 tilevisible1 l
x y &&
1533 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1536 let tilepage n p
layout =
1537 let rec loop = function
1541 let f col row _ _ _ _ _ _ =
1542 if state.currently
= Idle
1544 match gettileopaque l
col row with
1547 let x = col*conf.tilew
1548 and y = row*conf.tileh
in
1550 let w = l
.pagew
- x in
1554 let h = l
.pageh
- y in
1559 then getpbo
w h conf.colorspace
1562 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1565 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1566 conf.tilew
, conf.tileh
1575 if nogeomcmds state.geomcmds
1579 let preloadlayout y =
1580 let y = if y < state.winh
then 0 else y - state.winh
in
1581 let h = state.winh
*3 in
1586 let rec loop pages
=
1587 if state.currently
!= Idle
1592 begin match getopaque l
.pageno with
1594 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1595 state.currently
<- Loading
(l
, state.gen
);
1597 tilepage l
.pageno opaque pages
;
1602 if nogeomcmds state.geomcmds
1608 if conf.preload && state.currently
= Idle
1609 then load (preloadlayout state.y);
1612 let layoutready layout =
1613 let rec fold all ls
=
1614 all
&& match ls
with
1616 let seen = ref false in
1617 let allvisible = ref true in
1618 let foo col row _ _ _ _ _ _ =
1620 allvisible := !allvisible &&
1621 begin match gettileopaque l
col row with
1627 fold (!seen && !allvisible) rest
1630 let alltilesvisible = fold true layout in
1635 state.wthack
<- false;
1636 let y = bound y 0 state.maxy
in
1637 let y, layout, proceed
=
1638 match conf.maxwait
with
1639 | Some time
when state.ghyll
== noghyll ->
1640 begin match state.throttle
with
1642 let layout = layout y state.winh
in
1643 let ready = layoutready layout in
1647 state.throttle
<- Some
(layout, y, now ());
1649 else G.postRedisplay "gotoy showall (None)";
1651 | Some
(_, _, started
) ->
1652 let dt = now () -. started
in
1655 state.throttle
<- None
;
1656 let layout = layout y state.winh
in
1658 G.postRedisplay "maxwait";
1665 let layout = layout y state.winh
in
1666 G.postRedisplay "gotoy ready";
1672 state.layout <- layout;
1673 begin match state.mode
with
1674 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1675 let rec loop = function
1677 state.mode
<- LinkNav
(Ltgendir
0)
1678 | l
:: _ when l
.pageno = pageno ->
1679 begin match getopaque pageno with
1681 state.mode
<- LinkNav
(Ltgendir
0)
1683 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1684 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1685 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1686 then state.mode
<- LinkNav
(Ltgendir
0)
1688 | _ :: rest
-> loop rest
1693 begin match state.mode
with
1694 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1695 if not
(pagevisible layout pageno)
1697 match state.layout with
1700 state.mode
<- Birdseye
(
1701 conf, leftx
, l
.pageno, hooverpageno
, anchor
1704 | LinkNav
(Ltgendir dir
as lt
) ->
1706 let rec loop = function
1709 match getopaque l
.pageno with
1715 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1717 if dir
> 0 then LDfirst
else LDlast
1723 | Lnotfound
-> loop rest
1725 showlinktype (getlink opaque
n);
1726 Ltexact
(l
.pageno, n)
1730 state.mode
<- LinkNav
linknav
1735 state.ghyll
<- noghyll;
1738 let mx, my
= state.mpos
in
1743 let conttiling pageno opaque
=
1744 tilepage pageno opaque
1745 (if conf.preload then preloadlayout state.y else state.layout)
1748 let gotoy_and_clear_text y =
1749 if not
conf.verbose
then state.text <- "";
1755 let coloff = l
.pagecol
* l
.pageh
in
1756 float (l
.pagey + coloff) /. float l
.pageh
1763 if conf.presentation
1764 then float l
.pagedispy /. float (calcips l
.pageh
)
1765 else float l
.pagedispy /. float conf.interpagespace
1767 (l
.pageno, top, dtop)
1771 match state.layout with
1772 | l
:: _ -> getanchor1 l
1774 let n = page_of_y state.y in
1778 let y, h = getpageyh n in
1779 let dy = y - state.y in
1781 if conf.presentation
1783 let ips = calcips h in
1784 float (dy + ips) /. float ips
1786 float dy /. float conf.interpagespace
1791 let getanchory (n, top, dtop) =
1792 let y, h = getpageyh n in
1793 if conf.presentation
1795 let ips = calcips h in
1796 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1798 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1801 let gotoanchor anchor
=
1802 gotoy (getanchory anchor
);
1806 cbput state.hists
.nav
(getanchor ());
1810 let anchor = cbgetc state.hists
.nav dir
in
1815 let scroll f n a
b =
1816 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1818 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1820 then s (float f /. float a
)
1823 then 1.0 -. s ((float (f-b) /. float (n-b)))
1830 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1831 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1833 let ins = float a
*. iv1
1834 and outs
= float (n-b) *. iv1 in
1836 ins +. outs
+. float ones
1838 let rec set (_N
, _A
, _B
) y sy
=
1839 let sum = summa
1.0 _N _A _B
in
1840 let dy = float (y - sy
) in
1844 then state.ghyll
<- noghyll
1847 let s = scroll n _N _A _B
in
1848 let y1 = y1 +. ((s *. dy) /. sum) in
1849 gotoy_and_clear_text (truncate
y1);
1850 state.ghyll
<- gf (n+1) y1;
1854 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1856 gf 0 (float state.y)
1859 match conf.ghyllscroll
with
1861 gotoy_and_clear_text y
1863 if state.ghyll
== noghyll
1864 then set nab
y state.y
1865 else state.ghyll
(Some
y)
1868 let gotopage n top =
1869 let y, h = getpageyh n in
1870 let y = y + (truncate
(top *. float h)) in
1874 let gotopage1 n top =
1875 let y = getpagey n in
1880 let invalidate s f =
1885 match state.geomcmds
with
1886 | ps
, [] when String.length ps
= 0 ->
1888 state.geomcmds
<- s, [];
1891 state.geomcmds
<- ps
, [s, f];
1893 | ps
, (s'
, _) :: rest
when s'
= s ->
1894 state.geomcmds
<- ps
, ((s, f) :: rest
);
1897 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1901 Hashtbl.iter
(fun _ opaque
->
1902 wcmd "freepage %s" opaque
;
1904 Hashtbl.clear
state.pagemap
;
1907 let opendoc path password
=
1909 state.password
<- password
;
1910 state.gen
<- state.gen
+ 1;
1911 state.docinfo
<- [];
1914 setaalevel
conf.aalevel
;
1915 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1916 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1917 invalidate "reqlayout"
1919 wcmd "reqlayout %d %d %s\000"
1920 conf.angle
(btod conf.proportional
) state.nameddest
;
1925 state.anchor <- getanchor ();
1926 state.wthack
<- !wtmode;
1927 opendoc state.path
state.password
;
1931 let c = c *. conf.colorscale
in
1935 let scalecolor2 (r, g, b) =
1936 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
1939 let docolumns = function
1941 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1942 let rec loop pageno pdimno pdim
y ph pdims
=
1943 if pageno = state.pagecount
1946 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1948 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1949 pdimno+1, pdim
, rest
1953 let x = max
0 (((state.winw
- state.scrollw
- w) / 2) - xoff
) in
1955 (if conf.presentation
1956 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1957 else (if pageno = 0 then 0 else conf.interpagespace
)
1960 a.(pageno) <- (pdimno, x, y, pdim
);
1961 loop (pageno+1) pdimno pdim
(y + h) h pdims
1963 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1964 conf.columns
<- Csingle
a;
1966 | Cmulti
((columns
, coverA
, coverB
), _) ->
1967 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1968 let rec loop pageno pdimno pdim
x y rowh pdims
=
1969 let rec fixrow m
= if m
= pageno then () else
1970 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1973 let y = y + (rowh
- h) / 2 in
1974 a.(m
) <- (pdimno, x, y, pdim
);
1978 if pageno = state.pagecount
1979 then fixrow (((pageno - 1) / columns
) * columns
)
1981 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1983 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1984 pdimno+1, pdim
, rest
1989 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1991 let x = (state.winw
- state.scrollw
- w) / 2 in
1993 if conf.presentation
then calcips h else conf.interpagespace
in
1994 x, y + ips + rowh
, h
1997 if (pageno - coverA
) mod columns
= 0
1999 let x = max
0 (state.winw
- state.scrollw
- state.w) / 2 in
2001 if conf.presentation
2003 let ips = calcips h in
2004 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2006 y + (if pageno = 0 then 0 else conf.interpagespace
)
2010 else x, y, max rowh
h
2014 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2017 if pageno = columns
&& conf.presentation
2019 let ips = calcips rowh
in
2020 for i
= 0 to pred columns
2022 let (pdimno, x, y, pdim
) = a.(i
) in
2023 a.(i
) <- (pdimno, x, y+ips, pdim
)
2029 fixrow (pageno - columns
);
2034 a.(pageno) <- (pdimno, x, y, pdim
);
2035 let x = x + w + xoff
*2 + conf.interpagespace
in
2036 loop (pageno+1) pdimno pdim
x y rowh' pdims
2038 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2039 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2042 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2043 let rec loop pageno pdimno pdim
y pdims
=
2044 if pageno = state.pagecount
2047 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2049 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2050 pdimno+1, pdim
, rest
2055 let rec loop1 n x y =
2056 if n = c then y else (
2057 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2058 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2061 let y = loop1 0 0 y in
2062 loop (pageno+1) pdimno pdim
y pdims
2064 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2065 conf.columns
<- Csplit
(c, a);
2069 docolumns conf.columns
;
2070 state.maxy
<- calcheight ();
2072 if state.w <= state.winw
- state.scrollw
2076 if state.reprf
== noreprf
2078 let wthack = state.wthack in
2079 begin match state.mode
with
2080 | Birdseye
(_, _, pageno, _, _) ->
2081 let y, h = getpageyh pageno in
2082 let top = (state.winh
- h) / 2 in
2083 gotoy (max
0 (y - top))
2084 | _ -> gotoanchor state.anchor
2086 state.wthack <- wthack;
2087 state.reprf
<- noreprf;
2092 state.wthack <- false;
2093 GlDraw.viewport
0 0 w h;
2094 let firsttime = state.geomcmds
== firstgeomcmds in
2095 if not
firsttime && nogeomcmds state.geomcmds
2096 then state.anchor <- getanchor ();
2099 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2102 setfontsize fstate.fontsize
;
2103 GlMat.mode `modelview
;
2104 GlMat.load_identity
();
2106 GlMat.mode `projection
;
2107 GlMat.load_identity
();
2108 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2109 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2110 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2115 else float state.x /. float state.w
2117 invalidate "geometry"
2121 then state.x <- truncate
(relx *. float w);
2123 match conf.columns
with
2125 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2126 | Csplit
(c, _) -> w * c
2128 wcmd "geometry %d %d" w h);
2132 let len = String.length
state.text in
2135 match state.mode
with
2138 let h, _, _ = state.uioh#scrollpw
in
2144 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2145 (x+.w, float (state.winh
- hscrollh))
2148 let w = float (state.winw
- state.scrollw
- 1) in
2149 if state.progress
>= 0.0 && state.progress
< 1.0
2151 GlDraw.color
(0.3, 0.3, 0.3);
2152 let w1 = w *. state.progress
in
2154 GlDraw.color
(0.0, 0.0, 0.0);
2158 GlDraw.color
(0.0, 0.0, 0.0);
2162 GlDraw.color
(1.0, 1.0, 1.0);
2163 drawstring fstate.fontsize
2164 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2167 match state.mode
with
2168 | Textentry
((prefix
, text, _, _, _, _), _) ->
2172 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2174 Printf.sprintf
"%s%s_" prefix
text
2183 if not
(istextentry state.mode
)
2185 let s1 = "(press 'e' to review error messasges)" in
2186 if String.length
s > 0 then s ^
" " ^
s1 else s1
2191 if String.length
s > 0
2196 let len = Queue.length
state.tilelru
in
2198 match state.throttle
with
2201 then preloadlayout state.y
2203 | Some
(layout, _, _) ->
2207 if state.memused
<= conf.memlimit
2212 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2213 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2214 let (_, pw, ph
, _) = getpagedim n in
2217 && colorspace
= conf.colorspace
2218 && angle
= conf.angle
2222 let x = col*conf.tilew
2223 and y = row*conf.tileh
in
2224 tilevisible (Lazy.force_val
layout) n x y
2226 then Queue.push lruitem
state.tilelru
2229 wcmd "freetile %s" p
;
2230 state.memused
<- state.memused
- s;
2231 state.uioh#infochanged Memused
;
2232 Hashtbl.remove
state.tilemap k
;
2241 Queue.iter
(fun (k
, p
, s) ->
2242 wcmd "freetile %s" p
;
2243 state.memused
<- state.memused
- s;
2244 state.uioh#infochanged Memused
;
2245 Hashtbl.remove
state.tilemap k
;
2247 Queue.clear
state.tilelru
;
2251 let logcurrently = function
2252 | Idle
-> dolog "Idle"
2253 | Loading
(l
, gen
) ->
2254 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2255 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2257 "Tiling %d[%d,%d] page=%s cs=%s angle"
2258 l
.pageno col row pageopaque
2259 (colorspace_to_string colorspace
)
2261 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2262 angle gen
conf.angle
state.gen
2264 conf.tilew
conf.tileh
2271 let r = Str.regexp
" " in
2272 fun s -> Str.bounded_split
r s 2;
2275 let onpagerect pageno f =
2277 match conf.columns
with
2278 | Cmulti
(_, b) -> b
2280 | Csplit
(_, b) -> b
2282 if pageno >= 0 && pageno < Array.length
b
2284 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2285 let r = getpdimrect
pdimno in
2286 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2289 let gotopagexy pageno x y =
2290 onpagerect pageno (fun w h ->
2292 let _,w1,_,leftx
= getpagedim pageno in
2293 let sw = float w1 /. w in
2295 let x = leftx
+ state.x + truncate
x in
2297 if x < 0 || x >= state.winw
- state.scrollw
2298 then (state.x <- state.x - x; true)
2301 let y, h = getpageyh pageno in
2302 let y'
= y + truncate
(top *. float h) in
2303 let dy = y'
- state.y in
2304 if newpan || not
(dy > 0 && dy < state.winh
- state.hscrollh)
2307 if conf.presentation
2309 if abs
(y - y'
) > state.winh
- state.hscrollh
2315 state.wthack <- !wtmode && not
(layoutready state.layout);
2321 (* dolog "%S" cmds; *)
2322 let cl = splitatspace cmds
in
2324 try Scanf.sscanf
s fmt
f
2326 dolog "error processing '%S': %s" cmds
(Printexc.to_string exn
);
2331 state.uioh#infochanged Pdim
;
2334 | "clearrects" :: [] ->
2335 state.rects
<- state.rects1
;
2336 G.postRedisplay "clearrects";
2338 | "continue" :: args :: [] ->
2339 let n = scan args "%u" (fun n -> n) in
2340 state.pagecount
<- n;
2341 begin match state.currently
with
2343 state.currently
<- Idle
;
2344 state.outlines
<- Array.of_list
(List.rev l
)
2348 let cur, cmds
= state.geomcmds
in
2349 if String.length
cur = 0
2350 then failwith
"umpossible";
2352 begin match List.rev cmds
with
2354 state.geomcmds
<- "", [];
2358 state.geomcmds
<- s, List.rev rest
;
2360 if conf.maxwait
= None
2361 then G.postRedisplay "continue";
2363 | "title" :: args :: [] ->
2366 | "msg" :: args :: [] ->
2369 | "vmsg" :: args :: [] ->
2371 then showtext ' '
args
2373 | "emsg" :: args :: [] ->
2374 Buffer.add_string
state.errmsgs
args;
2375 state.newerrmsgs
<- true;
2376 G.postRedisplay "error message"
2378 | "progress" :: args :: [] ->
2379 let progress, text =
2382 f, String.sub
args pos
(String.length
args - pos
))
2385 state.progress <- progress;
2386 G.postRedisplay "progress"
2388 | "firstmatch" :: args :: [] ->
2389 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2390 scan args "%u %d %f %f %f %f %f %f %f %f"
2391 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2392 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2394 let y = (getpagey pageno) + truncate
y0 in
2397 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2399 | "match" :: args :: [] ->
2400 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2401 scan args "%u %d %f %f %f %f %f %f %f %f"
2402 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2403 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2406 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2408 | "page" :: args :: [] ->
2409 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2410 begin match state.currently
with
2411 | Loading
(l
, gen
) ->
2412 vlog "page %d took %f sec" l
.pageno t
;
2413 Hashtbl.replace
state.pagemap
(l
.pageno, gen
) pageopaque;
2414 begin match state.throttle
with
2416 let preloadedpages =
2418 then preloadlayout state.y
2423 Set.Make
(struct type t
= int let compare = (-) end) in
2425 List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
2426 IntSet.empty
preloadedpages
2429 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2430 if not
(IntSet.mem
pageno set)
2432 wcmd "freepage %s" opaque
;
2438 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2441 state.currently
<- Idle
;
2444 tilepage l
.pageno pageopaque state.layout;
2446 load preloadedpages;
2447 if pagevisible state.layout l
.pageno
2448 && layoutready state.layout
2449 then G.postRedisplay "page";
2452 | Some
(layout, _, _) ->
2453 state.currently
<- Idle
;
2454 tilepage l
.pageno pageopaque layout;
2459 dolog "Inconsistent loading state";
2460 logcurrently state.currently
;
2464 | "tile" :: args :: [] ->
2465 let (x, y, opaque
, size
, t
) =
2466 scan args "%u %u %s %u %f"
2467 (fun x y p size t
-> (x, y, p
, size
, t
))
2469 begin match state.currently
with
2470 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2471 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
2474 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2476 wcmd "freetile %s" opaque
;
2477 state.currently
<- Idle
;
2481 puttileopaque l
col row gen cs angle opaque size t
;
2482 state.memused
<- state.memused
+ size
;
2483 state.uioh#infochanged Memused
;
2485 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
2486 opaque
, size
) state.tilelru
;
2489 match state.throttle
with
2490 | None
-> state.layout
2491 | Some
(layout, _, _) -> layout
2494 state.currently
<- Idle
;
2496 && conf.colorspace
= cs
2497 && conf.angle
= angle
2498 && tilevisible layout l
.pageno x y
2499 then conttiling l
.pageno pageopaque;
2501 begin match state.throttle
with
2504 then state.wthack <- not
(layoutready state.layout);
2505 preload state.layout;
2507 && conf.colorspace
= cs
2508 && conf.angle
= angle
2509 && tilevisible state.layout l
.pageno x y
2510 then G.postRedisplay "tile nothrottle";
2512 | Some
(layout, y, _) ->
2513 let ready = layoutready layout in
2516 state.wthack <- false;
2518 state.layout <- layout;
2519 state.throttle
<- None
;
2520 G.postRedisplay "throttle";
2527 dolog "Inconsistent tiling state";
2528 logcurrently state.currently
;
2532 | "pdim" :: args :: [] ->
2534 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2536 state.uioh#infochanged Pdim
;
2537 state.pdims
<- pdim :: state.pdims
2539 | "o" :: args :: [] ->
2540 let (l
, n, t
, h, pos
) =
2541 scan args "%u %u %d %u %n"
2542 (fun l
n t
h pos
-> l
, n, t
, h, pos
)
2544 let s = String.sub
args pos
(String.length
args - pos
) in
2545 let outline = (s, l
, (n, float t
/. float h, 0.0)) in
2546 begin match state.currently
with
2547 | Outlining outlines
->
2548 state.currently
<- Outlining
(outline :: outlines
)
2550 state.currently
<- Outlining
[outline]
2552 dolog "invalid outlining state";
2553 logcurrently currently
2556 | "a" :: args :: [] ->
2558 scan args "%u %d %d" (fun n l t
-> n, l
, t
)
2560 state.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
2562 | "info" :: args :: [] ->
2563 state.docinfo
<- (1, args) :: state.docinfo
2565 | "infoend" :: [] ->
2566 state.uioh#infochanged Docinfo
;
2567 state.docinfo
<- List.rev
state.docinfo
2570 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2575 let action = function
2576 | HCprev
-> cbget cb ~
-1
2577 | HCnext
-> cbget cb
1
2578 | HCfirst
-> cbget cb ~
-(cb
.rc)
2579 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2580 and cancel
() = cb
.rc <- rc
2584 let search pattern forward
=
2585 if String.length pattern
> 0
2588 match state.layout with
2591 l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
2593 wcmd "search %d %d %d %d,%s\000"
2594 (btod conf.icase
) pn py
(btod forward
) pattern
;
2597 let intentry text key =
2599 if key >= 32 && key < 127
2605 let text = addchar text c in
2609 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2613 let linknentry text key =
2615 if key >= 32 && key < 127
2621 let text = addchar text c in
2625 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2630 if String.length
s > 0
2633 let l = String.length
s in
2634 let rec loop pos
n = if pos
= l then n else
2635 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2636 loop (pos
+1) (n*26 + m)
2639 let rec loop n = function
2642 match getopaque l.pageno with
2643 | None
-> loop n rest
2645 let m = getlinkcount opaque
in
2648 let under = getlink opaque
n in
2651 else loop (n-m) rest
2653 loop n state.layout;
2657 let textentry text key =
2658 if key land 0xff00 = 0xff00
2660 else TEcont
(text ^
Wsi.toutf8
key)
2663 let reqlayout angle proportional
=
2664 match state.throttle
with
2666 if nogeomcmds state.geomcmds
2667 then state.anchor <- getanchor ();
2668 conf.angle
<- angle
mod 360;
2671 match state.mode
with
2672 | LinkNav
_ -> state.mode
<- View
2675 conf.proportional
<- proportional
;
2676 invalidate "reqlayout"
2677 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2681 let settrim trimmargins trimfuzz
=
2682 if nogeomcmds state.geomcmds
2683 then state.anchor <- getanchor ();
2684 conf.trimmargins
<- trimmargins
;
2685 conf.trimfuzz
<- trimfuzz
;
2686 let x0, y0, x1, y1 = trimfuzz
in
2687 invalidate "settrim"
2689 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2694 match state.throttle
with
2696 let zoom = max
0.01 zoom in
2697 if zoom <> conf.zoom
2699 state.prevzoom
<- conf.zoom;
2701 reshape state.winw
state.winh
;
2702 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2705 | Some
(layout, y, started
) ->
2707 match conf.maxwait
with
2711 let dt = now () -. started
in
2719 let setcolumns mode columns coverA coverB
=
2720 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2724 then showtext '
!'
"split mode doesn't work in bird's eye"
2726 conf.columns
<- Csplit
(-columns
, [||]);
2734 conf.columns
<- Csingle
[||];
2739 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2743 reshape state.winw
state.winh
;
2746 let enterbirdseye () =
2747 let zoom = float conf.thumbw
/. float state.winw
in
2748 let birdseyepageno =
2749 let cy = state.winh
/ 2 in
2753 let rec fold best
= function
2756 let d = cy - (l.pagedispy + l.pagevh/2)
2757 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2758 if abs
d < abs dbest
2765 state.mode
<- Birdseye
(
2766 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2769 conf.presentation
<- false;
2770 conf.interpagespace
<- 10;
2771 conf.hlinks
<- false;
2773 state.mstate
<- Mnone
;
2774 conf.maxwait
<- None
;
2776 match conf.beyecolumns
with
2779 Cmulti
((c, 0, 0), [||])
2780 | None
-> Csingle
[||]
2782 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2785 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2790 reshape state.winw
state.winh
;
2793 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2795 conf.zoom <- c.zoom;
2796 conf.presentation
<- c.presentation
;
2797 conf.interpagespace
<- c.interpagespace
;
2798 conf.maxwait
<- c.maxwait
;
2799 conf.hlinks
<- c.hlinks
;
2800 conf.beyecolumns
<- (
2801 match conf.columns
with
2802 | Cmulti
((c, _, _), _) -> Some
c
2804 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2807 match c.columns
with
2808 | Cmulti
(c, _) -> Cmulti
(c, [||])
2809 | Csingle
_ -> Csingle
[||]
2810 | Csplit
(c, _) -> Csplit
(c, [||])
2815 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2818 reshape state.winw
state.winh
;
2819 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2822 let togglebirdseye () =
2823 match state.mode
with
2824 | Birdseye vals
-> leavebirdseye vals
true
2825 | View
-> enterbirdseye ()
2829 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2830 let pageno = max
0 (pageno - incr
) in
2831 let rec loop = function
2832 | [] -> gotopage1 pageno 0
2833 | l :: _ when l.pageno = pageno ->
2834 if l.pagedispy >= 0 && l.pagey = 0
2835 then G.postRedisplay "upbirdseye"
2836 else gotopage1 pageno 0
2837 | _ :: rest
-> loop rest
2840 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2843 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2844 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2845 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2846 let rec loop = function
2848 let y, h = getpageyh pageno in
2849 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2851 | l :: _ when l.pageno = pageno ->
2852 if l.pagevh != l.pageh
2853 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2854 else G.postRedisplay "downbirdseye"
2855 | _ :: rest
-> loop rest
2860 let optentry mode
_ key =
2861 let btos b = if b then "on" else "off" in
2862 if key >= 32 && key < 127
2864 let c = Char.chr
key in
2868 try conf.scrollstep
<- int_of_string
s with exc
->
2869 state.text <- Printf.sprintf
"bad integer `%s': %s"
2870 s (Printexc.to_string exc
)
2872 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2877 conf.autoscrollstep
<- int_of_string
s;
2878 if state.autoscroll
<> None
2879 then state.autoscroll
<- Some
conf.autoscrollstep
2881 state.text <- Printf.sprintf
"bad integer `%s': %s"
2882 s (Printexc.to_string exc
)
2884 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2889 let n, a, b = multicolumns_of_string s in
2890 setcolumns mode
n a b;
2892 state.text <- Printf.sprintf
"bad columns `%s': %s"
2893 s (Printexc.to_string exc
)
2895 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2900 let zoom = float (int_of_string
s) /. 100.0 in
2903 state.text <- Printf.sprintf
"bad integer `%s': %s"
2904 s (Printexc.to_string exc
)
2906 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2911 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2913 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2914 begin match mode
with
2916 leavebirdseye beye
false;
2921 state.text <- Printf.sprintf
"bad integer `%s': %s"
2922 s (Printexc.to_string exc
)
2924 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2929 Some
(int_of_string
s)
2931 state.text <- Printf.sprintf
"bad integer `%s': %s"
2932 s (Printexc.to_string exc
);
2935 | Some angle
-> reqlayout angle
conf.proportional
2938 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2941 conf.icase
<- not
conf.icase
;
2942 TEdone
("case insensitive search " ^
(btos conf.icase
))
2945 conf.preload <- not
conf.preload;
2947 TEdone
("preload " ^
(btos conf.preload))
2950 conf.verbose
<- not
conf.verbose
;
2951 TEdone
("verbose " ^
(btos conf.verbose
))
2954 conf.debug
<- not
conf.debug
;
2955 TEdone
("debug " ^
(btos conf.debug
))
2958 conf.maxhfit
<- not
conf.maxhfit
;
2959 state.maxy
<- calcheight ();
2960 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2963 conf.crophack
<- not
conf.crophack
;
2964 TEdone
("crophack " ^
btos conf.crophack
)
2968 match conf.maxwait
with
2970 conf.maxwait
<- Some infinity
;
2971 "always wait for page to complete"
2973 conf.maxwait
<- None
;
2974 "show placeholder if page is not ready"
2979 conf.underinfo
<- not
conf.underinfo
;
2980 TEdone
("underinfo " ^
btos conf.underinfo
)
2983 conf.savebmarks
<- not
conf.savebmarks
;
2984 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2990 match state.layout with
2995 conf.interpagespace
<- int_of_string
s;
2996 docolumns conf.columns
;
2997 state.maxy
<- calcheight ();
2998 let y = getpagey pageno in
3001 state.text <- Printf.sprintf
"bad integer `%s': %s"
3002 s (Printexc.to_string exc
)
3004 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3007 reqlayout conf.angle
(not
conf.proportional
);
3008 TEdone
("proportional display " ^
btos conf.proportional
)
3011 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3012 TEdone
("trim margins " ^
btos conf.trimmargins
)
3015 conf.invert
<- not
conf.invert
;
3016 TEdone
("invert colors " ^
btos conf.invert
)
3020 cbput state.hists
.sel
s;
3023 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3024 textentry, ondone, true)
3027 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3033 class type lvsource
= object
3034 method getitemcount
: int
3035 method getitem
: int -> (string * int)
3036 method hasaction
: int -> bool
3045 method getactive
: int
3046 method getfirst
: int
3047 method getqsearch
: string
3048 method setqsearch
: string -> unit
3052 class virtual lvsourcebase
= object
3053 val mutable m_active
= 0
3054 val mutable m_first
= 0
3055 val mutable m_qsearch
= ""
3056 val mutable m_pan
= 0
3057 method getactive
= m_active
3058 method getfirst
= m_first
3059 method getqsearch
= m_qsearch
3060 method getpan
= m_pan
3061 method setqsearch
s = m_qsearch
<- s
3064 let withoutlastutf8 s =
3065 let len = String.length
s in
3073 let b = Char.code
s.[pos
] in
3074 if b land 0b11000000 = 0b11000000
3079 if Char.code
s.[len-1] land 0x80 = 0
3083 String.sub
s 0 first;
3086 let textentrykeyboard
3087 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3089 if key >= 0xffb0 && key <= 0xffb9
3090 then key - 0xffb0 + 48 else key
3093 state.mode
<- Textentry
(te
, onleave
);
3096 G.postRedisplay "textentrykeyboard enttext";
3098 let histaction cmd
=
3101 | Some
(action, _) ->
3102 state.mode
<- Textentry
(
3103 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3105 G.postRedisplay "textentry histaction"
3108 | 0xff08 -> (* backspace *)
3109 let s = withoutlastutf8 text in
3110 let len = String.length
s in
3111 if cancelonempty
&& len = 0
3114 G.postRedisplay "textentrykeyboard after cancel";
3117 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3120 | 0xff0d | 0xff8d -> (* (kp) enter *)
3123 G.postRedisplay "textentrykeyboard after confirm"
3125 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3126 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3127 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3128 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3130 | 0xff1b -> (* escape*)
3131 if String.length
text = 0
3133 begin match opthist
with
3135 | Some
(_, onhistcancel
) -> onhistcancel
()
3139 G.postRedisplay "textentrykeyboard after cancel2"
3142 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3145 | 0xff9f | 0xffff -> () (* delete *)
3148 && key land 0xff00 != 0xff00 (* keyboard *)
3149 && key land 0xfe00 != 0xfe00 (* xkb *)
3150 && key land 0xfd00 != 0xfd00 (* 3270 *)
3152 begin match onkey
text key with
3156 G.postRedisplay "textentrykeyboard after confirm2";
3159 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3163 G.postRedisplay "textentrykeyboard after cancel3"
3166 state.mode
<- Textentry
(te
, onleave
);
3167 G.postRedisplay "textentrykeyboard switch";
3171 vlog "unhandled key %s" (Wsi.keyname
key)
3174 let firstof first active
=
3175 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3176 then max
0 (active
- (fstate.maxrows
/2))
3180 let calcfirst first active
=
3183 let rows = active
- first in
3184 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3188 let scrollph y maxy
=
3189 let sh = (float (maxy
+ state.winh
) /. float state.winh
) in
3190 let sh = float state.winh
/. sh in
3191 let sh = max
sh (float conf.scrollh
) in
3196 else float y /. float maxy
3198 let position = (float state.winh
-. sh) *. percent in
3201 if position +. sh > float state.winh
3202 then float state.winh
-. sh
3208 let coe s = (s :> uioh
);;
3210 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3212 val m_pan
= source#getpan
3213 val m_first
= source#getfirst
3214 val m_active
= source#getactive
3215 val m_qsearch
= source#getqsearch
3216 val m_prev_uioh
= state.uioh
3218 method private elemunder
y =
3219 let n = y / (fstate.fontsize
+1) in
3220 if m_first
+ n < source#getitemcount
3222 if source#hasaction
(m_first
+ n)
3223 then Some
(m_first
+ n)
3230 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3231 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3232 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3233 GlDraw.color
(1., 1., 1.);
3234 Gl.enable `texture_2d
;
3235 let fs = fstate.fontsize
in
3237 let ww = fstate.wwidth
in
3238 let tabw = 30.0*.ww in
3239 let itemcount = source#getitemcount
in
3241 if (row - m_first
) > fstate.maxrows
3244 if row >= 0 && row < itemcount
3246 let (s, level
) = source#getitem
row in
3247 let y = (row - m_first
) * nfs in
3248 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3251 Gl.disable `texture_2d
;
3252 GlDraw.polygon_mode `both `line
;
3253 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3254 GlDraw.rect (1., float (y + 1))
3255 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3256 GlDraw.polygon_mode `both `fill
;
3257 GlDraw.color
(1., 1., 1.);
3258 Gl.enable `texture_2d
;
3261 let drawtabularstring s =
3262 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3265 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3268 let len = String.length
s - tabpos - 1 in
3269 let s1 = String.sub
s 0 tabpos
3270 and s2
= String.sub
s (tabpos + 1) len in
3271 let nx = drawstr x s1 in
3273 let x = x +. (max
tabw sw) in
3280 let _ = drawtabularstring s in
3287 Gl.disable `texture_2d
;
3289 method updownlevel incr
=
3290 let len = source#getitemcount
in
3292 if m_active
>= 0 && m_active
< len
3293 then snd
(source#getitem m_active
)
3297 if i
= len then i
-1 else if i
= -1 then 0 else
3298 let _, l = source#getitem i
in
3299 if l != curlevel then i
else flow (i
+incr
)
3301 let active = flow m_active
in
3302 let first = calcfirst m_first
active in
3303 G.postRedisplay "outline updownlevel";
3304 {< m_active
= active; m_first
= first >}
3306 method private key1
key mask
=
3307 let set1 active first qsearch
=
3308 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3310 let search active pattern incr
=
3313 if n >= 0 && n < source#getitemcount
3315 let s, _ = source#getitem
n in
3317 (try ignore
(Str.search_forward
re s 0); true
3318 with Not_found
-> false)
3320 else loop (n + incr
)
3327 let re = Str.regexp_case_fold pattern
in
3333 let itemcount = source#getitemcount
in
3334 let find start incr
=
3336 if i
= -1 || i
= itemcount
3339 if source#hasaction i
3341 else find (i
+ incr
)
3346 let set active first =
3347 let first = bound first 0 (itemcount - fstate.maxrows
) in
3349 coe {< m_active
= active; m_first
= first >}
3352 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3354 let incr1 = if incr
> 0 then 1 else -1 in
3355 if isvisible m_first m_active
3358 let next = m_active
+ incr
in
3360 if next < 0 || next >= itemcount
3362 else find next incr1
3364 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3370 let first = m_first
+ incr
in
3371 let first = bound first 0 (itemcount - 1) in
3373 let next = m_active
+ incr
in
3374 let next = bound next 0 (itemcount - 1) in
3377 let active = if next = -1 then m_active
else next in
3380 let first = min
next m_first
in
3382 if abs
(next - first) > fstate.maxrows
3388 let first = m_first
+ incr
in
3389 let first = bound first 0 (itemcount - 1) in
3391 let next = m_active
+ incr
in
3392 let next = bound next 0 (itemcount - 1) in
3393 let next = find next incr1 in
3395 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3397 let active = if m_active
= -1 then next else m_active
in
3402 if isvisible first active
3408 G.postRedisplay "listview navigate";
3412 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3413 let incr = if key = 0x72 then -1 else 1 in
3415 match search (m_active
+ incr) m_qsearch
incr with
3417 state.text <- m_qsearch ^
" [not found]";
3420 state.text <- m_qsearch
;
3421 active, firstof m_first
active
3423 G.postRedisplay "listview ctrl-r/s";
3424 set1 active first m_qsearch
;
3426 | 0xff08 -> (* backspace *)
3427 if String.length m_qsearch
= 0
3430 let qsearch = withoutlastutf8 m_qsearch
in
3431 let len = String.length
qsearch in
3435 G.postRedisplay "listview empty qsearch";
3436 set1 m_active m_first
"";
3440 match search m_active
qsearch ~
-1 with
3442 state.text <- qsearch ^
" [not found]";
3445 state.text <- qsearch;
3446 active, firstof m_first
active
3448 G.postRedisplay "listview backspace qsearch";
3449 set1 active first qsearch
3452 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3453 let pattern = m_qsearch ^
Wsi.toutf8
key in
3455 match search m_active
pattern 1 with
3457 state.text <- pattern ^
" [not found]";
3460 state.text <- pattern;
3461 active, firstof m_first
active
3463 G.postRedisplay "listview qsearch add";
3464 set1 active first pattern;
3466 | 0xff1b -> (* escape *)
3468 if String.length m_qsearch
= 0
3470 G.postRedisplay "list view escape";
3473 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3475 | None
-> m_prev_uioh
3480 G.postRedisplay "list view kill qsearch";
3481 source#setqsearch
"";
3482 coe {< m_qsearch
= "" >}
3485 | 0xff0d | 0xff8d -> (* (kp) enter *)
3487 let self = {< m_qsearch
= "" >} in
3488 source#setqsearch
"";
3490 G.postRedisplay "listview enter";
3491 if m_active
>= 0 && m_active
< source#getitemcount
3493 source#exit
(coe self) false m_active m_first m_pan
"";
3496 source#exit
(coe self) true m_active m_first m_pan
"";
3499 begin match opt with
3500 | None
-> m_prev_uioh
3504 | 0xff9f | 0xffff -> (* (kp) delete *)
3507 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3508 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3509 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3510 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3512 | 0xff53 | 0xff98 -> (* (kp) right *)
3514 G.postRedisplay "listview right";
3515 coe {< m_pan
= m_pan
- 1 >}
3517 | 0xff51 | 0xff96 -> (* (kp) left *)
3519 G.postRedisplay "listview left";
3520 coe {< m_pan
= m_pan
+ 1 >}
3522 | 0xff50 | 0xff95 -> (* (kp) home *)
3523 let active = find 0 1 in
3524 G.postRedisplay "listview home";
3527 | 0xff57 | 0xff9c -> (* (kp) end *)
3528 let first = max
0 (itemcount - fstate.maxrows
) in
3529 let active = find (itemcount - 1) ~
-1 in
3530 G.postRedisplay "listview end";
3533 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3537 dolog "listview unknown key %#x" key; coe self
3539 method key key mask
=
3540 match state.mode
with
3541 | Textentry te
-> textentrykeyboard key mask te
; coe self
3542 | _ -> self#key1
key mask
3544 method button button down
x y _ =
3547 | 1 when x > state.winw
- conf.scrollbw
->
3548 G.postRedisplay "listview scroll";
3551 let _, position, sh = self#
scrollph in
3552 if y > truncate
position && y < truncate
(position +. sh)
3554 state.mstate
<- Mscrolly
;
3558 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3559 let first = truncate
(s *. float source#getitemcount
) in
3560 let first = min source#getitemcount
first in
3561 Some
(coe {< m_first
= first; m_active
= first >})
3563 state.mstate
<- Mnone
;
3566 | 1 when not down
->
3567 begin match self#elemunder
y with
3569 G.postRedisplay "listview click";
3571 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3575 | n when (n == 4 || n == 5) && not down
->
3576 let len = source#getitemcount
in
3578 if n = 5 && m_first
+ fstate.maxrows
>= len
3582 let first = m_first
+ (if n == 4 then -1 else 1) in
3583 bound first 0 (len - 1)
3585 G.postRedisplay "listview wheel";
3586 Some
(coe {< m_first
= first >})
3587 | n when (n = 6 || n = 7) && not down
->
3588 let inc = m_first
+ (if n = 7 then -1 else 1) in
3589 G.postRedisplay "listview hwheel";
3590 Some
(coe {< m_pan
= m_pan
+ inc >})
3595 | None
-> m_prev_uioh
3599 match state.mstate
with
3601 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3602 let first = truncate
(s *. float source#getitemcount
) in
3603 let first = min source#getitemcount
first in
3604 G.postRedisplay "listview motion";
3605 coe {< m_first
= first; m_active
= first >}
3608 method pmotion
x y =
3609 if x < state.winw
- conf.scrollbw
3612 match self#elemunder
y with
3613 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3614 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3618 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3623 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3627 method infochanged
_ = ()
3629 method scrollpw
= (0, 0.0, 0.0)
3631 let nfs = fstate.fontsize
+ 1 in
3632 let y = m_first
* nfs in
3633 let itemcount = source#getitemcount
in
3634 let maxi = max
0 (itemcount - fstate.maxrows
) in
3635 let maxy = maxi * nfs in
3636 let p, h = scrollph y maxy in
3639 method modehash
= modehash
3642 class outlinelistview ~source
=
3645 ~source
:(source
:> lvsource
)
3647 ~modehash
:(findkeyhash conf "outline")
3650 method key key mask
=
3651 let calcfirst first active =
3654 let rows = active - first in
3656 if String.length
state.text = 0
3658 else fstate.maxrows - 2
3660 if rows > maxrows then active - maxrows else first
3664 let active = m_active
+ incr in
3665 let active = bound active 0 (source#getitemcount
- 1) in
3666 let first = calcfirst m_first
active in
3667 G.postRedisplay "outline navigate";
3668 coe {< m_active
= active; m_first
= first >}
3670 let ctrl = Wsi.withctrl mask
in
3672 | 110 when ctrl -> (* ctrl-n *)
3673 source#narrow m_qsearch
;
3674 G.postRedisplay "outline ctrl-n";
3675 coe {< m_first
= 0; m_active
= 0 >}
3677 | 117 when ctrl -> (* ctrl-u *)
3679 G.postRedisplay "outline ctrl-u";
3681 coe {< m_first
= 0; m_active
= 0 >}
3683 | 108 when ctrl -> (* ctrl-l *)
3684 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3685 G.postRedisplay "outline ctrl-l";
3686 coe {< m_first
= first >}
3688 | 0xff9f | 0xffff -> (* (kp) delete *)
3689 source#remove m_active
;
3690 G.postRedisplay "outline delete";
3691 let active = max
0 (m_active
-1) in
3692 coe {< m_first
= firstof m_first
active;
3693 m_active
= active >}
3695 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3696 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3697 | 0xff55 | 0xff9a -> (* (kp) prior *)
3698 navigate ~
-(fstate.maxrows)
3699 | 0xff56 | 0xff9b -> (* (kp) next *)
3700 navigate fstate.maxrows
3702 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3706 G.postRedisplay "outline ctrl right";
3707 {< m_pan
= m_pan
+ 1 >}
3709 else self#updownlevel
1
3713 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3717 G.postRedisplay "outline ctrl left";
3718 {< m_pan
= m_pan
- 1 >}
3720 else self#updownlevel ~
-1
3724 | 0xff50 | 0xff95 -> (* (kp) home *)
3725 G.postRedisplay "outline home";
3726 coe {< m_first
= 0; m_active
= 0 >}
3728 | 0xff57 | 0xff9c -> (* (kp) end *)
3729 let active = source#getitemcount
- 1 in
3730 let first = max
0 (active - fstate.maxrows) in
3731 G.postRedisplay "outline end";
3732 coe {< m_active
= active; m_first
= first >}
3734 | _ -> super#
key key mask
3737 let outlinesource usebookmarks
=
3740 inherit lvsourcebase
3741 val mutable m_items
= empty
3742 val mutable m_orig_items
= empty
3743 val mutable m_prev_items
= empty
3744 val mutable m_narrow_pattern
= ""
3745 val mutable m_hadremovals
= false
3747 method getitemcount
=
3748 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3751 if n == Array.length m_items
&& m_hadremovals
3753 ("[Confirm removal]", 0)
3755 let s, n, _ = m_items
.(n) in
3758 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3759 ignore
(uioh
, first, qsearch);
3760 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3762 if String.length m_narrow_pattern
= 0
3768 if not
confrimremoval
3770 let _, _, anchor = m_items
.(active) in
3771 gotoghyll (getanchory anchor);
3775 state.bookmarks
<- Array.to_list m_items
;
3776 m_orig_items
<- m_items
;
3779 else m_items
<- items;
3783 method hasaction
_ = true
3786 if Array.length m_items
!= Array.length m_orig_items
3787 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3790 method narrow
pattern =
3791 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3795 let rec loop accu n =
3798 m_narrow_pattern
<- pattern;
3799 m_items
<- Array.of_list
accu
3802 let (s, _, _) as o = m_items
.(n) in
3804 if (try ignore
(Str.search_forward
re s 0); true
3805 with Not_found
-> false)
3811 loop [] (Array.length m_items
- 1)
3816 then Array.of_list
state.bookmarks
3819 m_items
<- m_orig_items
3824 if m >= 0 && m < Array.length m_items
3826 m_hadremovals
<- true;
3827 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3828 let n = if n >= m then n+1 else n in
3833 method reset
anchor items =
3834 m_hadremovals
<- false;
3835 if m_orig_items
== empty || m_prev_items
!= items
3837 m_orig_items
<- items;
3838 if String.length m_narrow_pattern
= 0
3839 then m_items
<- items;
3841 m_prev_items
<- items;
3842 let rely = getanchory anchor in
3844 let rec loop n best bestd
=
3845 if n = Array.length m_items
3848 let (_, _, anchor) = m_items
.(n) in
3849 let orely = getanchory anchor in
3850 let d = abs
(orely - rely) in
3853 else loop (n+1) best bestd
3858 m_first
<- firstof m_first
active
3862 let enterselector usebookmarks
=
3863 let source = outlinesource usebookmarks
in
3867 then Array.of_list
state.bookmarks
3870 if Array.length
outlines = 0
3872 showtext ' ' errmsg
;
3875 state.text <- source#greetmsg
;
3876 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3877 let anchor = getanchor () in
3878 source#reset
anchor outlines;
3879 state.uioh
<- coe (new outlinelistview ~
source);
3880 G.postRedisplay "enter selector";
3884 let enteroutlinemode =
3885 let f = enterselector false in
3886 fun ()-> f "Document has no outline";
3889 let enterbookmarkmode =
3890 let f = enterselector true in
3891 fun () -> f "Document has no bookmarks (yet)";
3894 let color_of_string s =
3895 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
3896 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
3900 let color_to_string (r, g, b) =
3901 let r = truncate
(r *. 256.0)
3902 and g = truncate
(g *. 256.0)
3903 and b = truncate
(b *. 256.0) in
3904 Printf.sprintf
"%d/%d/%d" r g b
3907 let irect_of_string s =
3908 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3911 let irect_to_string (x0,y0,x1,y1) =
3912 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3915 let makecheckers () =
3916 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3918 converted by Issac Trotts. July 25, 2002 *)
3919 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3920 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3921 let id = GlTex.gen_texture
() in
3922 GlTex.bind_texture `texture_2d
id;
3923 GlPix.store
(`unpack_alignment
1);
3924 GlTex.image2d
image;
3925 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3926 [ `mag_filter `nearest
; `min_filter `nearest
];
3930 let setcheckers enabled
=
3931 match state.texid
with
3933 if enabled
then state.texid
<- Some
(makecheckers ())
3938 GlTex.delete_texture texid
;
3939 state.texid
<- None
;
3943 let int_of_string_with_suffix s =
3944 let l = String.length
s in
3948 let suffix = Char.lowercase
s.[l-1] in
3950 | 'k'
-> String.sub
s 0 (l-1), 10
3951 | '
m'
-> String.sub
s 0 (l-1), 20
3952 | '
g'
-> String.sub
s 0 (l-1), 30
3956 let n = int_of_string
s1 in
3957 let m = n lsl shift
in
3959 then raise
(Failure
"value too large")
3963 let string_with_suffix_of_int n =
3968 if n land ((1 lsl 30) - 1) = 0
3971 if n land ((1 lsl 20) - 1) = 0
3974 if n land ((1 lsl 10) - 1) = 0
3981 let h = n mod 1000 in
3984 then string_of_int
h ^
s
3986 let s = Printf.sprintf
"_%03d%s" h s in
3993 let defghyllscroll = (40, 8, 32);;
3994 let ghyllscroll_of_string s =
3995 let (n, a, b) as nab
=
3998 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4000 if n <= a || n <= b || a >= b
4001 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4005 let ghyllscroll_to_string ((n, a, b) as nab
) =
4006 if nab
= defghyllscroll
4008 else Printf.sprintf
"%d,%d,%d" n a b;
4011 let describe_location () =
4013 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
4015 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
4016 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4020 else (100. *. (float state.y /. float maxy))
4024 Printf.sprintf
"page %d of %d [%.2f%%]"
4025 (fn+1) state.pagecount
percent
4028 "pages %d-%d of %d [%.2f%%]"
4029 (fn+1) (ln
+1) state.pagecount
percent
4032 let setpresentationmode v
=
4033 let (n, _, _) = getanchor () in
4034 let _, h = getpageyh n in
4035 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
4036 state.anchor <- (n, 0.0, float ips);
4037 conf.presentation
<- v
;
4038 if conf.presentation
4040 if not
conf.scrollbarinpm
4041 then state.scrollw
<- 0;
4043 else state.scrollw
<- conf.scrollbw
;
4048 let btos b = if b then "\xe2\x88\x9a" else "" in
4049 let showextended = ref false in
4050 let leave mode
= function
4051 | Confirm
-> state.mode
<- mode
4052 | Cancel
-> state.mode
<- mode
in
4055 val mutable m_first_time
= true
4056 val mutable m_l
= []
4057 val mutable m_a
= [||]
4058 val mutable m_prev_uioh
= nouioh
4059 val mutable m_prev_mode
= View
4061 inherit lvsourcebase
4063 method reset prev_mode prev_uioh
=
4064 m_a
<- Array.of_list
(List.rev m_l
);
4066 m_prev_mode
<- prev_mode
;
4067 m_prev_uioh
<- prev_uioh
;
4071 if n >= Array.length m_a
4075 | _, _, _, Action
_ -> m_active
<- n
4079 m_first_time
<- false;
4082 method int name get
set =
4084 (name
, `
int get
, 1, Action
(
4087 try set (int_of_string
s)
4089 state.text <- Printf.sprintf
"bad integer `%s': %s"
4090 s (Printexc.to_string exn
)
4093 let te = name ^
": ", "", None
, intentry, ondone, true in
4094 state.mode
<- Textentry
(te, leave m_prev_mode
);
4098 method int_with_suffix name get
set =
4100 (name
, `intws get
, 1, Action
(
4103 try set (int_of_string_with_suffix s)
4105 state.text <- Printf.sprintf
"bad integer `%s': %s"
4106 s (Printexc.to_string exn
)
4110 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4112 state.mode
<- Textentry
(te, leave m_prev_mode
);
4116 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4118 (name
, `
bool (btos, get
), offset
, Action
(
4125 method color name get
set =
4127 (name
, `color get
, 1, Action
(
4129 let invalid = (nan
, nan
, nan
) in
4132 try color_of_string s
4134 state.text <- Printf.sprintf
"bad color `%s': %s"
4135 s (Printexc.to_string exn
);
4141 let te = name ^
": ", "", None
, textentry, ondone, true in
4142 state.text <- color_to_string (get
());
4143 state.mode
<- Textentry
(te, leave m_prev_mode
);
4147 method string name get
set =
4149 (name
, `
string get
, 1, Action
(
4151 let ondone s = set s in
4152 let te = name ^
": ", "", None
, textentry, ondone, true in
4153 state.mode
<- Textentry
(te, leave m_prev_mode
);
4157 method colorspace name get
set =
4159 (name
, `
string get
, 1, Action
(
4162 let vals = [| "rgb"; "bgr"; "gray" |] in
4164 inherit lvsourcebase
4167 m_active
<- int_of_colorspace conf.colorspace
;
4170 method getitemcount
= Array.length
vals
4171 method getitem
n = (vals.(n), 0)
4172 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4173 ignore
(uioh
, first, pan
, qsearch);
4174 if not cancel
then set active;
4176 method hasaction
_ = true
4180 let modehash = findkeyhash conf "info" in
4181 coe (new listview ~
source ~trusted
:true ~
modehash)
4184 method caption
s offset
=
4185 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4187 method caption2
s f offset
=
4188 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4190 method getitemcount
= Array.length m_a
4193 let tostr = function
4194 | `
int f -> string_of_int
(f ())
4195 | `intws
f -> string_with_suffix_of_int (f ())
4197 | `color
f -> color_to_string (f ())
4198 | `
bool (btos, f) -> btos (f ())
4201 let name, t
, offset
, _ = m_a
.(n) in
4202 ((let s = tostr t
in
4203 if String.length
s > 0
4204 then Printf.sprintf
"%s\t%s" name s
4208 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4212 m_qsearch
<- qsearch;
4214 match m_a
.(active) with
4215 | _, _, _, Action
f -> f uioh
4227 method hasaction
n =
4229 | _, _, _, Action
_ -> true
4233 let rec fillsrc prevmode prevuioh
=
4234 let sep () = src#caption
"" 0 in
4235 let colorp name get
set =
4237 (fun () -> color_to_string (get
()))
4240 let c = color_of_string v in
4243 state.text <- Printf.sprintf
"bad color `%s': %s"
4244 v (Printexc.to_string exn
);
4247 let oldmode = state.mode
in
4248 let birdseye = isbirdseye state.mode
in
4250 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4252 src#
bool "presentation mode"
4253 (fun () -> conf.presentation
)
4254 (fun v -> setpresentationmode v);
4256 src#
bool "ignore case in searches"
4257 (fun () -> conf.icase
)
4258 (fun v -> conf.icase
<- v);
4261 (fun () -> conf.preload)
4262 (fun v -> conf.preload <- v);
4264 src#
bool "highlight links"
4265 (fun () -> conf.hlinks
)
4266 (fun v -> conf.hlinks
<- v);
4268 src#
bool "under info"
4269 (fun () -> conf.underinfo
)
4270 (fun v -> conf.underinfo
<- v);
4272 src#
bool "persistent bookmarks"
4273 (fun () -> conf.savebmarks
)
4274 (fun v -> conf.savebmarks
<- v);
4276 src#
bool "proportional display"
4277 (fun () -> conf.proportional
)
4278 (fun v -> reqlayout conf.angle
v);
4280 src#
bool "trim margins"
4281 (fun () -> conf.trimmargins
)
4282 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4284 src#
bool "persistent location"
4285 (fun () -> conf.jumpback
)
4286 (fun v -> conf.jumpback
<- v);
4289 src#
int "inter-page space"
4290 (fun () -> conf.interpagespace
)
4292 conf.interpagespace
<- n;
4293 docolumns conf.columns
;
4295 match state.layout with
4300 state.maxy <- calcheight ();
4301 let y = getpagey pageno in
4306 (fun () -> conf.pagebias
)
4307 (fun v -> conf.pagebias
<- v);
4309 src#
int "scroll step"
4310 (fun () -> conf.scrollstep
)
4311 (fun n -> conf.scrollstep
<- n);
4313 src#
int "horizontal scroll step"
4314 (fun () -> conf.hscrollstep
)
4315 (fun v -> conf.hscrollstep
<- v);
4317 src#
int "auto scroll step"
4319 match state.autoscroll
with
4321 | _ -> conf.autoscrollstep
)
4323 if state.autoscroll
<> None
4324 then state.autoscroll
<- Some
n;
4325 conf.autoscrollstep
<- n);
4328 (fun () -> truncate
(conf.zoom *. 100.))
4329 (fun v -> setzoom ((float v) /. 100.));
4332 (fun () -> conf.angle
)
4333 (fun v -> reqlayout v conf.proportional
);
4335 src#
int "scroll bar width"
4336 (fun () -> state.scrollw
)
4340 reshape state.winw
state.winh
;
4343 src#
int "scroll handle height"
4344 (fun () -> conf.scrollh
)
4345 (fun v -> conf.scrollh
<- v;);
4347 src#
int "thumbnail width"
4348 (fun () -> conf.thumbw
)
4350 conf.thumbw
<- min
4096 v;
4353 leavebirdseye beye
false;
4358 let mode = state.mode in
4359 src#
string "columns"
4361 match conf.columns
with
4363 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4364 | Csplit
(count
, _) -> "-" ^ string_of_int count
4367 let n, a, b = multicolumns_of_string v in
4368 setcolumns mode n a b);
4371 src#caption
"Presentation mode" 0;
4372 src#
bool "scrollbar visible"
4373 (fun () -> conf.scrollbarinpm
)
4375 if v != conf.scrollbarinpm
4377 conf.scrollbarinpm
<- v;
4378 if conf.presentation
4380 state.scrollw
<- if v then conf.scrollbw
else 0;
4381 reshape state.winw
state.winh
;
4387 src#caption
"Pixmap cache" 0;
4388 src#int_with_suffix
"size (advisory)"
4389 (fun () -> conf.memlimit
)
4390 (fun v -> conf.memlimit
<- v);
4393 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4394 (string_with_suffix_of_int state.memused
)
4395 (Hashtbl.length
state.tilemap
)) 1;
4398 src#caption
"Layout" 0;
4399 src#caption2
"Dimension"
4401 Printf.sprintf
"%dx%d (virtual %dx%d)"
4402 state.winw
state.winh
4407 src#caption2
"Position" (fun () ->
4408 Printf.sprintf
"%dx%d" state.x state.y
4411 src#caption2
"Visible" (fun () -> describe_location ()) 1
4415 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4416 "Save these parameters as global defaults at exit"
4417 (fun () -> conf.bedefault
)
4418 (fun v -> conf.bedefault
<- v)
4422 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4423 src#
bool ~offset
:0 ~
btos "Extended parameters"
4424 (fun () -> !showextended)
4425 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4429 (fun () -> conf.checkers
)
4430 (fun v -> conf.checkers
<- v; setcheckers v);
4431 src#
bool "update cursor"
4432 (fun () -> conf.updatecurs
)
4433 (fun v -> conf.updatecurs
<- v);
4435 (fun () -> conf.verbose
)
4436 (fun v -> conf.verbose
<- v);
4437 src#
bool "invert colors"
4438 (fun () -> conf.invert
)
4439 (fun v -> conf.invert
<- v);
4441 (fun () -> conf.maxhfit
)
4442 (fun v -> conf.maxhfit
<- v);
4443 src#
bool "redirect stderr"
4444 (fun () -> conf.redirectstderr)
4445 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4446 src#
string "uri launcher"
4447 (fun () -> conf.urilauncher
)
4448 (fun v -> conf.urilauncher
<- v);
4449 src#
string "path launcher"
4450 (fun () -> conf.pathlauncher
)
4451 (fun v -> conf.pathlauncher
<- v);
4452 src#
string "tile size"
4453 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4456 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4457 conf.tilew
<- max
64 w;
4458 conf.tileh
<- max
64 h;
4461 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4462 v (Printexc.to_string exn
));
4463 src#
int "texture count"
4464 (fun () -> conf.texcount
)
4467 then conf.texcount
<- v
4468 else showtext '
!'
" Failed to set texture count please retry later"
4470 src#
int "slice height"
4471 (fun () -> conf.sliceheight
)
4473 conf.sliceheight
<- v;
4474 wcmd "sliceh %d" conf.sliceheight
;
4476 src#
int "anti-aliasing level"
4477 (fun () -> conf.aalevel
)
4479 conf.aalevel
<- bound v 0 8;
4480 state.anchor <- getanchor ();
4481 opendoc state.path
state.password
;
4483 src#
string "page scroll scaling factor"
4484 (fun () -> string_of_float
conf.pgscale)
4487 let s = float_of_string
v in
4490 state.text <- Printf.sprintf
4491 "bad page scroll scaling factor `%s': %s"
4492 v (Printexc.to_string exn
)
4495 src#
int "ui font size"
4496 (fun () -> fstate.fontsize
)
4497 (fun v -> setfontsize (bound v 5 100));
4498 src#
int "hint font size"
4499 (fun () -> conf.hfsize
)
4500 (fun v -> conf.hfsize
<- bound v 5 100);
4501 colorp "background color"
4502 (fun () -> conf.bgcolor
)
4503 (fun v -> conf.bgcolor
<- v);
4504 src#
bool "crop hack"
4505 (fun () -> conf.crophack
)
4506 (fun v -> conf.crophack
<- v);
4507 src#
string "trim fuzz"
4508 (fun () -> irect_to_string conf.trimfuzz
)
4511 conf.trimfuzz
<- irect_of_string v;
4513 then settrim true conf.trimfuzz
;
4515 state.text <- Printf.sprintf
"bad irect `%s': %s"
4516 v (Printexc.to_string exn
)
4518 src#
string "throttle"
4520 match conf.maxwait
with
4521 | None
-> "show place holder if page is not ready"
4524 then "wait for page to fully render"
4526 "wait " ^ string_of_float
time
4527 ^
" seconds before showing placeholder"
4531 let f = float_of_string
v in
4533 then conf.maxwait
<- None
4534 else conf.maxwait
<- Some
f
4536 state.text <- Printf.sprintf
"bad time `%s': %s"
4537 v (Printexc.to_string exn
)
4539 src#
string "ghyll scroll"
4541 match conf.ghyllscroll
with
4543 | Some nab
-> ghyllscroll_to_string nab
4548 if String.length
v = 0
4550 else Some
(ghyllscroll_of_string v)
4552 conf.ghyllscroll
<- gs
4554 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4555 v (Printexc.to_string exn
)
4557 src#
string "selection command"
4558 (fun () -> conf.selcmd
)
4559 (fun v -> conf.selcmd
<- v);
4560 src#
string "synctex command"
4561 (fun () -> conf.stcmd
)
4562 (fun v -> conf.stcmd
<- v);
4563 src#colorspace
"color space"
4564 (fun () -> colorspace_to_string conf.colorspace
)
4566 conf.colorspace
<- colorspace_of_int v;
4573 (fun () -> conf.usepbo
)
4574 (fun v -> conf.usepbo
<- v);
4575 src#
bool "mouse wheel scrolls pages"
4576 (fun () -> conf.wheelbypage
)
4577 (fun v -> conf.wheelbypage
<- v);
4581 src#caption
"Document" 0;
4582 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4583 src#caption2
"Pages"
4584 (fun () -> string_of_int
state.pagecount
) 1;
4585 src#caption2
"Dimensions"
4586 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4590 src#caption
"Trimmed margins" 0;
4591 src#caption2
"Dimensions"
4592 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4596 src#caption
"OpenGL" 0;
4597 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4598 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4599 src#reset prevmode prevuioh
;
4603 let prevmode = state.mode
4604 and prevuioh
= state.uioh in
4605 fillsrc prevmode prevuioh
;
4606 let source = (src :> lvsource
) in
4607 let modehash = findkeyhash conf "info" in
4608 state.uioh <- coe (object (self)
4609 inherit listview ~
source ~trusted
:true ~
modehash as super
4610 val mutable m_prevmemused
= 0
4611 method infochanged
= function
4613 if m_prevmemused
!= state.memused
4615 m_prevmemused
<- state.memused
;
4616 G.postRedisplay "memusedchanged";
4618 | Pdim
-> G.postRedisplay "pdimchanged"
4619 | Docinfo
-> fillsrc prevmode prevuioh
4621 method key key mask
=
4622 if not
(Wsi.withctrl mask
)
4625 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4626 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4627 | _ -> super#
key key mask
4628 else super#
key key mask
4630 G.postRedisplay "info";
4636 inherit lvsourcebase
4637 method getitemcount
= Array.length
state.help
4639 let s, l, _ = state.help
.(n) in
4642 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4646 m_qsearch
<- qsearch;
4647 match state.help
.(active) with
4648 | _, _, Action
f -> Some
(f uioh)
4658 method hasaction
n =
4659 match state.help
.(n) with
4660 | _, _, Action
_ -> true
4667 let modehash = findkeyhash conf "help" in
4668 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4669 G.postRedisplay "help";
4674 let re = Str.regexp
"[\r\n]" in
4676 inherit lvsourcebase
4677 val mutable m_items
= [||]
4679 method getitemcount
= 1 + Array.length m_items
4684 else m_items
.(n-1), 0
4686 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4691 then Buffer.clear
state.errmsgs
;
4692 m_qsearch
<- qsearch;
4699 method hasaction
n =
4703 state.newerrmsgs
<- false;
4704 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4705 m_items
<- Array.of_list
l
4713 let source = (msgsource :> lvsource
) in
4714 let modehash = findkeyhash conf "listview" in
4715 state.uioh <- coe (object
4716 inherit listview ~
source ~trusted
:false ~
modehash as super
4719 then msgsource#reset
;
4722 G.postRedisplay "msgs";
4725 let quickbookmark ?title
() =
4726 match state.layout with
4732 let sec = Unix.gettimeofday
() in
4733 let tm = Unix.localtime
sec in
4734 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4738 (tm.Unix.tm_year
+ 1900)
4741 | Some
title -> title
4743 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4750 let setautoscrollspeed step goingdown
=
4751 let incr = max
1 ((abs step
) / 2) in
4752 let incr = if goingdown
then incr else -incr in
4753 let astep = step
+ incr in
4754 state.autoscroll
<- Some
astep;
4757 let gotounder = function
4758 | Ulinkgoto
(pageno, top) ->
4762 gotopage1 pageno top;
4768 | Uremote
(filename
, pageno) ->
4770 if Sys.file_exists filename
4773 let dir = Filename.dirname
state.path in
4774 let path = Filename.concat
dir filename
in
4775 if Sys.file_exists
path
4779 if String.length
path > 0
4781 let anchor = getanchor () in
4782 let ranchor = state.path, state.password
, anchor in
4783 state.anchor <- (pageno, 0.0, 0.0);
4784 state.ranchors
<- ranchor :: state.ranchors
;
4787 else showtext '
!'
("Could not find " ^ filename
)
4789 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4793 match conf.columns
with
4795 | _ -> conf.zoom > 1.0
4798 let existsinrow pageno (columns
, coverA
, coverB
) p =
4799 let last = ((pageno - coverA
) mod columns
) + columns
in
4800 let rec any = function
4803 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4807 then (if l.pageno = last then false else any rest
)
4815 match state.layout with
4818 match conf.columns
with
4820 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4822 let y = clamp (pgscale state.winh
) in
4825 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4826 gotoghyll (getpagey pageno)
4827 | Cmulti
((c, _, _) as cl, _) ->
4828 if conf.presentation
4829 && (existsinrow l.pageno cl
4830 (fun l -> l.pageh
> l.pagey + l.pagevh))
4832 let y = clamp (pgscale state.winh
) in
4835 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4836 gotoghyll (getpagey pageno)
4838 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4840 let pagey, pageh
= getpageyh l.pageno in
4841 let pagey = pagey + pageh
* l.pagecol
in
4842 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4843 gotoghyll (pagey + pageh
+ ips)
4847 match state.layout with
4850 match conf.columns
with
4852 if conf.presentation
&& l.pagey != 0
4854 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4856 let pageno = max
0 (l.pageno-1) in
4857 gotoghyll (getpagey pageno)
4858 | Cmulti
((c, _, coverB
) as cl, _) ->
4859 if conf.presentation
&&
4860 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
4862 gotoghyll (clamp (pgscale ~
-(state.winh
)))
4865 if l.pageno = state.pagecount
- coverB
4869 let pageno = max
0 (l.pageno-decr) in
4870 gotoghyll (getpagey pageno)
4878 let pageno = max
0 (l.pageno-1) in
4879 let pagey, pageh
= getpageyh pageno in
4882 let pagey, pageh
= getpageyh l.pageno in
4883 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4888 let viewkeyboard key mask
=
4890 let mode = state.mode in
4891 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4894 G.postRedisplay "view:enttext"
4896 let ctrl = Wsi.withctrl mask
in
4898 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4904 | 0xff63 -> (* insert *)
4905 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4907 state.mode <- LinkNav
(Ltgendir
0);
4910 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4912 | 0xff1b | 113 -> (* escape / q *)
4913 begin match state.mstate
with
4915 state.mstate
<- Mnone
;
4916 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4917 G.postRedisplay "kill zoom rect";
4919 begin match state.mode with
4922 G.postRedisplay "esc leave linknav"
4924 match state.ranchors
with
4926 | (path, password
, anchor) :: rest
->
4927 state.ranchors
<- rest
;
4928 state.anchor <- anchor;
4929 opendoc path password
4933 | 0xff08 -> (* backspace *)
4934 gotoghyll (getnav ~
-1)
4942 G.postRedisplay "dehighlight";
4944 | 47 | 63 -> (* / ? *)
4945 let ondone isforw
s =
4946 cbput state.hists
.pat
s;
4947 state.searchpattern
<- s;
4950 let s = String.create
1 in
4951 s.[0] <- Char.chr
key;
4952 enttext (s, "", Some
(onhist state.hists
.pat
),
4953 textentry, ondone (key = 47), true)
4955 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4956 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4957 setzoom (conf.zoom +. incr)
4959 | 43 | 0xffab -> (* + *)
4962 try int_of_string
s with exc
->
4963 state.text <- Printf.sprintf
"bad integer `%s': %s"
4964 s (Printexc.to_string exc
);
4970 state.text <- "page bias is now " ^ string_of_int
n;
4973 enttext ("page bias: ", "", None
, intentry, ondone, true)
4975 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4976 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4977 setzoom (max
0.01 (conf.zoom -. decr))
4979 | 45 | 0xffad -> (* - *)
4980 let ondone msg
= state.text <- msg
in
4982 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4983 optentry state.mode, ondone, true
4986 | 48 when ctrl -> (* ctrl-0 *)
4989 | 49 when ctrl -> (* ctrl-1 *)
4991 match conf.columns
with
4992 | Csingle
_ | Cmulti
_ -> 1
4993 | Csplit
(n, _) -> n
4995 let zoom = zoomforh
state.winw
state.winh
state.scrollw
cols in
4999 | 0xffc6 -> (* f9 *)
5002 | 57 when ctrl -> (* ctrl-9 *)
5005 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5006 when not
ctrl -> (* 0..9 *)
5009 try int_of_string
s with exc
->
5010 state.text <- Printf.sprintf
"bad integer `%s': %s"
5011 s (Printexc.to_string exc
);
5017 cbput state.hists
.pag
(string_of_int
n);
5018 gotopage1 (n + conf.pagebias
- 1) 0;
5021 let pageentry text key =
5022 match Char.unsafe_chr
key with
5023 | '
g'
-> TEdone
text
5024 | _ -> intentry text key
5026 let text = "x" in text.[0] <- Char.chr
key;
5027 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5030 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5031 reshape state.winw
state.winh
;
5034 conf.hlinks
<- not
conf.hlinks
;
5035 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5036 G.postRedisplay "toggle highlightlinks";
5039 state.glinks
<- true;
5040 let mode = state.mode in
5041 state.mode <- Textentry
(
5042 (":", "", None
, linknentry, linkndone gotounder, false),
5044 state.glinks
<- false;
5048 G.postRedisplay "view:linkent(F)"
5051 state.glinks
<- true;
5052 let mode = state.mode in
5053 state.mode <- Textentry
(
5054 (":", "", None
, linknentry, linkndone (fun under ->
5055 match Ne.pipe () with
5057 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
5058 (Printexc.to_string exn
));
5061 try popen conf.selcmd
[r, 0; w, -1]; true
5064 (Printf.sprintf
"failed to execute %s: %s"
5065 conf.selcmd
(Printexc.to_string exn
));
5069 Ne.clo fd
(fun msg
->
5070 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5073 let s = undertext under in
5077 let l = String.length
s in
5078 let n = tempfailureretry (Unix.write
w s 0) l in
5083 "failed to write %d characters to sel pipe, wrote %d"
5088 (Printf.sprintf
"failed to write to sel pipe: %s"
5089 (Printexc.to_string exn
)
5098 state.glinks
<- false;
5102 G.postRedisplay "view:linkent"
5105 begin match state.autoscroll
with
5107 conf.autoscrollstep
<- step
;
5108 state.autoscroll
<- None
5110 if conf.autoscrollstep
= 0
5111 then state.autoscroll
<- Some
1
5112 else state.autoscroll
<- Some
conf.autoscrollstep
5115 | 112 when ctrl -> (* ctrl-p *)
5119 setpresentationmode (not
conf.presentation
);
5120 showtext ' '
("presentation mode " ^
5121 if conf.presentation
then "on" else "off");
5124 if List.mem
Wsi.Fullscreen
state.winstate
5125 then doreshape conf.cwinw
conf.cwinh
5126 else Wsi.fullscreen
()
5128 | 112 | 78 -> (* p|N *)
5129 search state.searchpattern
false
5131 | 110 | 0xffc0 -> (* n|F3 *)
5132 search state.searchpattern
true
5135 begin match state.layout with
5138 gotoghyll (getpagey l.pageno)
5144 | 0xff9f | 0xffff -> (* delete *)
5148 showtext ' '
(describe_location ());
5151 begin match state.layout with
5154 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5159 enterbookmarkmode ()
5161 | 104 | 0xffbe -> (* h|F1 *)
5167 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5172 match state.layout with
5174 if String.length
s > 0
5176 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5179 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5183 showtext ' '
"Quick bookmark added";
5186 begin match state.layout with
5188 let rect = getpdimrect
l.pagedimno
in
5192 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5193 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5195 (truncate
(rect.(1) -. rect.(0)),
5196 truncate
(rect.(3) -. rect.(0)))
5198 let w = truncate
((float w)*.conf.zoom)
5199 and h = truncate
((float h)*.conf.zoom) in
5202 state.anchor <- getanchor ();
5203 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5205 G.postRedisplay "z";
5210 | 50 when ctrl -> (* ctrl-2 *)
5211 let maxw = getmaxw
() in
5213 then setzoom (maxw /. float state.winw
)
5215 | 60 | 62 -> (* < > *)
5216 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5218 | 91 | 93 -> (* [ ] *)
5220 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5222 G.postRedisplay "brightness";
5224 | 99 when state.mode = View
-> (* c *)
5226 match state.prevcolumns
with
5227 | None
-> (1, 0, 0), 1.0
5228 | Some
(columns
, z
) ->
5231 | Csplit
(c, _) -> -c, 0, 0
5232 | Cmulti
((c, a, b), _) -> c, a, b
5233 | Csingle
_ -> 1, 0, 0
5237 setcolumns View
c a b;
5240 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5241 setzoom state.prevzoom
5243 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5244 begin match state.autoscroll
with
5246 begin match state.mode with
5247 | Birdseye beye
-> upbirdseye 1 beye
5250 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5251 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5254 setautoscrollspeed n false
5257 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5258 begin match state.autoscroll
with
5260 begin match state.mode with
5261 | Birdseye beye
-> downbirdseye 1 beye
5264 then gotoy_and_clear_text (clamp (state.winh
/2))
5265 else gotoy_and_clear_text (clamp conf.scrollstep
)
5268 setautoscrollspeed n true
5271 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5272 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5278 else conf.hscrollstep
5280 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5281 state.x <- state.x + dx;
5282 gotoy_and_clear_text state.y
5285 G.postRedisplay "lef/right"
5288 | 0xff55 | 0xff9a -> (* (kp) prior *)
5292 match state.layout with
5294 | l :: _ -> state.y - l.pagey
5296 clamp (pgscale (-state.winh
))
5300 | 0xff56 | 0xff9b -> (* (kp) next *)
5304 match List.rev
state.layout with
5306 | l :: _ -> getpagey l.pageno
5308 clamp (pgscale state.winh
)
5312 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5314 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5315 gotoghyll (clamp state.maxy)
5318 when Wsi.withalt mask
-> (* alt-(kp) right *)
5319 gotoghyll (getnav 1)
5321 when Wsi.withalt mask
-> (* alt-(kp) left *)
5322 gotoghyll (getnav ~
-1)
5327 | 118 when conf.debug
-> (* v *)
5330 match getopaque l.pageno with
5333 let x0, y0, x1, y1 = pagebbox opaque
in
5334 let a,b = float x0, float y0 in
5335 let c,d = float x1, float y0 in
5336 let e,f = float x1, float y1 in
5337 let h,j
= float x0, float y1 in
5338 let rect = (a,b,c,d,e,f,h,j
) in
5340 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5342 G.postRedisplay "v";
5345 vlog "huh? %s" (Wsi.keyname
key)
5348 let linknavkeyboard key mask
linknav =
5349 let getpage pageno =
5350 let rec loop = function
5352 | l :: _ when l.pageno = pageno -> Some
l
5353 | _ :: rest
-> loop rest
5354 in loop state.layout
5356 let doexact (pageno, n) =
5357 match getopaque pageno, getpage pageno with
5358 | Some opaque
, Some
l ->
5359 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5361 let under = getlink opaque
n in
5362 G.postRedisplay "link gotounder";
5368 | 0xff50 -> (* home *)
5369 Some
(findlink opaque LDfirst
), -1
5371 | 0xff57 -> (* end *)
5372 Some
(findlink opaque LDlast
), 1
5374 | 0xff51 -> (* left *)
5375 Some
(findlink opaque
(LDleft
n)), -1
5377 | 0xff53 -> (* right *)
5378 Some
(findlink opaque
(LDright
n)), 1
5380 | 0xff52 -> (* up *)
5381 Some
(findlink opaque
(LDup
n)), -1
5383 | 0xff54 -> (* down *)
5384 Some
(findlink opaque
(LDdown
n)), 1
5389 begin match findpwl
l.pageno dir with
5393 state.mode <- LinkNav
(Ltgendir
dir);
5394 let y, h = getpageyh pageno in
5397 then y + h - state.winh
5402 begin match getopaque pageno, getpage pageno with
5403 | Some opaque
, Some
_ ->
5405 let ld = if dir > 0 then LDfirst
else LDlast
in
5408 begin match link with
5410 showlinktype (getlink opaque
m);
5411 state.mode <- LinkNav
(Ltexact
(pageno, m));
5412 G.postRedisplay "linknav jpage";
5419 begin match opt with
5420 | Some Lnotfound
-> pwl l dir;
5421 | Some
(Lfound
m) ->
5425 let _, y0, _, y1 = getlinkrect opaque
m in
5427 then gotopage1 l.pageno y0
5429 let d = fstate.fontsize
+ 1 in
5430 if y1 - l.pagey > l.pagevh - d
5431 then gotopage1 l.pageno (y1 - state.winh
- state.hscrollh + d)
5432 else G.postRedisplay "linknav";
5434 showlinktype (getlink opaque
m);
5435 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5438 | None
-> viewkeyboard key mask
5440 | _ -> viewkeyboard key mask
5445 G.postRedisplay "leave linknav"
5449 | Ltgendir
_ -> viewkeyboard key mask
5450 | Ltexact exact
-> doexact exact
5453 let keyboard key mask
=
5454 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5455 then wcmd "interrupt"
5456 else state.uioh <- state.uioh#
key key mask
5459 let birdseyekeyboard key mask
5460 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5462 match conf.columns
with
5464 | Cmulti
((c, _, _), _) -> c
5465 | Csplit
_ -> failwith
"bird's eye split mode"
5467 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5469 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5470 let y, h = getpageyh pageno in
5471 let top = (state.winh
- h) / 2 in
5472 gotoy (max
0 (y - top))
5473 | 0xff0d (* enter *)
5474 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5475 | 0xff1b -> leavebirdseye beye
true (* escape *)
5476 | 0xff52 -> upbirdseye incr beye
(* up *)
5477 | 0xff54 -> downbirdseye incr beye
(* down *)
5478 | 0xff51 -> upbirdseye 1 beye
(* left *)
5479 | 0xff53 -> downbirdseye 1 beye
(* right *)
5481 | 0xff55 -> (* prior *)
5482 begin match state.layout with
5486 state.mode <- Birdseye
(
5487 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5489 gotopage1 l.pageno 0;
5492 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5494 | [] -> gotoy (clamp (-state.winh
))
5496 state.mode <- Birdseye
(
5497 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5499 gotopage1 l.pageno 0
5502 | [] -> gotoy (clamp (-state.winh
))
5505 | 0xff56 -> (* next *)
5506 begin match List.rev
state.layout with
5508 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5509 begin match layout with
5511 let incr = l.pageh
- l.pagevh in
5516 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5518 G.postRedisplay "birdseye pagedown";
5520 else gotoy (clamp (incr + conf.interpagespace
*2));
5524 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5525 gotopage1 l.pageno 0;
5528 | [] -> gotoy (clamp state.winh
)
5531 | 0xff50 -> (* home *)
5532 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5535 | 0xff57 -> (* end *)
5536 let pageno = state.pagecount
- 1 in
5537 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5538 if not
(pagevisible state.layout pageno)
5541 match List.rev
state.pdims
with
5543 | (_, _, h, _) :: _ -> h
5545 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5546 else G.postRedisplay "birdseye end";
5547 | _ -> viewkeyboard key mask
5550 let drawpage l linkindexbase
=
5552 match state.mode with
5553 | Textentry
_ -> scalecolor 0.4
5555 | View
-> scalecolor 1.0
5556 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5557 if l.pageno = hooverpageno
5560 if l.pageno = pageno
5566 begin match getopaque l.pageno with
5568 if tileready l l.pagex
l.pagey
5570 let x = l.pagedispx - l.pagex
5571 and y = l.pagedispy - l.pagey in
5573 match conf.columns
with
5574 | Csingle
_ | Cmulti
_ ->
5575 (if conf.hlinks
then 1 else 0)
5577 && not
(isbirdseye state.mode) then 2 else 0)
5581 match state.mode with
5582 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5585 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5592 let scrollindicator () =
5593 let sbw, ph
, sh = state.uioh#
scrollph in
5594 let sbh, pw, sw = state.uioh#scrollpw
in
5596 GlDraw.color (0.64, 0.64, 0.64);
5598 (float (state.winw
- sbw), 0.)
5599 (float state.winw
, float state.winh
)
5602 (0., float (state.winh
- sbh))
5603 (float (state.winw
- state.scrollw
- 1), float state.winh
)
5605 GlDraw.color (0.0, 0.0, 0.0);
5608 (float (state.winw
- sbw), ph
)
5609 (float state.winw
, ph
+. sh)
5612 (pw, float (state.winh
- sbh))
5613 (pw +. sw, float state.winh
)
5618 match state.mstate
with
5619 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5622 | Msel
((x0, y0), (x1, y1)) ->
5623 let rec loop = function
5625 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5626 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5627 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5628 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5630 match getopaque l.pageno with
5632 let x0, y0 = pagetranslatepoint l x0 y0 in
5633 let x1, y1 = pagetranslatepoint l x1 y1 in
5634 seltext opaque
(x0, y0, x1, y1);
5642 let showrects rects
=
5644 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5645 GlDraw.polygon_mode `both `fill
;
5646 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5648 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5650 if l.pageno = pageno
5652 let dx = float (l.pagedispx - l.pagex
) in
5653 let dy = float (l.pagedispy - l.pagey) in
5654 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5655 GlDraw.begins `quads
;
5657 GlDraw.vertex2
(x0+.dx, y0+.dy);
5658 GlDraw.vertex2
(x1+.dx, y1+.dy);
5659 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5660 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5671 GlClear.color (scalecolor2 conf.bgcolor
);
5672 GlClear.clear
[`
color];
5673 let rec loop linkindexbase
= function
5675 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5676 loop linkindexbase rest
5679 loop 0 state.layout;
5681 match state.mode with
5682 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5683 begin match getopaque pageno with
5685 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5692 | None
-> state.rects
5699 begin match state.mstate
with
5700 | Mzoomrect
((x0, y0), (x1, y1)) ->
5702 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5703 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5704 GlDraw.rect (float x0, float y0)
5705 (float x1, float y1);
5714 let zoomrect x y x1 y1 =
5717 and y0 = min
y y1 in
5718 gotoy (state.y + y0);
5719 state.anchor <- getanchor ();
5720 let zoom = (float state.winw
*. conf.zoom) /. float (x1 - x0) in
5722 if state.w < state.winw
- state.scrollw
5723 then (state.winw
- state.scrollw
- state.w) / 2
5726 state.x <- (state.x + margin) - x0;
5728 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5729 state.mstate
<- Mnone
;
5733 let winw = state.winw - state.scrollw
- 1 in
5734 let s = float x /. float winw in
5735 let destx = truncate
(float (state.w + winw) *. s) in
5736 state.x <- winw - destx;
5737 gotoy_and_clear_text state.y;
5738 state.mstate
<- Mscrollx
;
5742 let s = float y /. float state.winh
in
5743 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5744 gotoy_and_clear_text desty;
5745 state.mstate
<- Mscrolly
;
5748 let viewmouse button down
x y mask
=
5750 | n when (n == 4 || n == 5) && not down
->
5751 if Wsi.withctrl mask
5753 match state.mstate
with
5754 | Mzoom
(oldn
, i
) ->
5762 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5764 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5766 let zoom = conf.zoom -. incr in
5768 state.mstate
<- Mzoom
(n, 0);
5770 state.mstate
<- Mzoom
(n, i
+1);
5772 else state.mstate
<- Mzoom
(n, 0)
5774 | _ -> state.mstate
<- Mzoom
(n, 0)
5777 match state.autoscroll
with
5778 | Some step
-> setautoscrollspeed step
(n=4)
5789 then -conf.scrollstep
5790 else conf.scrollstep
5792 let incr = incr * 2 in
5793 let y = clamp incr in
5794 gotoy_and_clear_text y
5797 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5798 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5799 gotoy_and_clear_text state.y
5801 | 1 when Wsi.withshift mask
->
5802 state.mstate
<- Mnone
;
5804 match unproject x y with
5805 | Some
(pageno, ux
, uy
) ->
5806 let cmd = Printf.sprintf
5808 conf.stcmd
state.path pageno ux uy
5814 | 1 when Wsi.withctrl mask
->
5817 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5818 state.mstate
<- Mpan
(x, y)
5821 state.mstate
<- Mnone
5826 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5828 state.mstate
<- Mzoomrect
(p, p)
5831 match state.mstate
with
5832 | Mzoomrect
((x0, y0), _) ->
5833 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5834 then zoomrect x0 y0 x y
5836 state.mstate
<- Mnone
;
5837 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5838 G.postRedisplay "kill accidental zoom rect";
5841 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5842 state.mstate
<- Mnone
5845 | 1 when x > state.winw - state.scrollw
->
5848 let _, position, sh = state.uioh#
scrollph in
5849 if y > truncate
position && y < truncate
(position +. sh)
5850 then state.mstate
<- Mscrolly
5853 state.mstate
<- Mnone
5855 | 1 when y > state.winh
- state.hscrollh ->
5858 let _, position, sw = state.uioh#scrollpw
in
5859 if x > truncate
position && x < truncate
(position +. sw)
5860 then state.mstate
<- Mscrollx
5863 state.mstate
<- Mnone
5866 let dest = if down
then getunder x y else Unone
in
5867 begin match dest with
5871 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5874 | Unone
when down
->
5875 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5876 state.mstate
<- Mpan
(x, y);
5878 | Unone
| Utext
_ ->
5881 if conf.angle
mod 360 = 0
5883 state.mstate
<- Msel
((x, y), (x, y));
5884 G.postRedisplay "mouse select";
5888 match state.mstate
with
5891 | Mzoom
_ | Mscrollx
| Mscrolly
->
5892 state.mstate
<- Mnone
5894 | Mzoomrect
((x0, y0), _) ->
5898 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5899 state.mstate
<- Mnone
5901 | Msel
((x0, y0), (x1, y1)) ->
5902 let rec loop = function
5906 let a0 = l.pagedispy in
5907 let a1 = a0 + l.pagevh in
5908 let b0 = l.pagedispx in
5909 let b1 = b0 + l.pagevw in
5910 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5911 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5915 match getopaque l.pageno with
5918 match Ne.pipe () with
5922 "can not create sel pipe: %s"
5923 (Printexc.to_string exn
));
5925 let doclose what fd
=
5926 Ne.clo fd
(fun msg
->
5927 dolog "%s close failed: %s" what msg
)
5930 popen conf.selcmd
[r, 0; w, -1];
5933 G.postRedisplay "copysel";
5935 dolog "can not execute %S: %s"
5936 conf.selcmd
(Printexc.to_string exn
);
5944 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5945 state.mstate
<- Mnone
;
5952 let birdseyemouse button down
x y mask
5953 (conf, leftx
, _, hooverpageno
, anchor) =
5956 let rec loop = function
5959 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5960 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5962 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5968 | _ -> viewmouse button down
x y mask
5971 let mouse button down
x y mask
=
5972 state.uioh <- state.uioh#button button down
x y mask
;
5976 state.uioh <- state.uioh#
motion x y
5980 state.uioh <- state.uioh#
pmotion x y;
5986 method key key mask
=
5987 begin match state.mode with
5988 | Textentry
textentry -> textentrykeyboard key mask
textentry
5989 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5990 | View
-> viewkeyboard key mask
5991 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5995 method button button bstate
x y mask
=
5996 begin match state.mode with
5998 | View
-> viewmouse button bstate
x y mask
5999 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6005 begin match state.mode with
6007 | View
| Birdseye
_ | LinkNav
_ ->
6008 match state.mstate
with
6009 | Mzoom
_ | Mnone
-> ()
6014 state.mstate
<- Mpan
(x, y);
6016 then state.x <- state.x + dx;
6018 gotoy_and_clear_text y
6021 state.mstate
<- Msel
(a, (x, y));
6022 G.postRedisplay "motion select";
6025 let y = min
state.winh
(max
0 y) in
6029 let x = min
state.winw (max
0 x) in
6032 | Mzoomrect
(p0
, _) ->
6033 state.mstate
<- Mzoomrect
(p0
, (x, y));
6034 G.postRedisplay "motion zoomrect";
6038 method pmotion x y =
6039 begin match state.mode with
6040 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6041 let rec loop = function
6043 if hooverpageno
!= -1
6045 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6046 G.postRedisplay "pmotion birdseye no hoover";
6049 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6050 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6052 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6053 G.postRedisplay "pmotion birdseye hoover";
6063 match state.mstate
with
6064 | Mnone
-> updateunder x y
6065 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6070 method infochanged
_ = ()
6073 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6074 let p, h = scrollph state.y maxy in
6078 let winw = state.winw - state.scrollw
- 1 in
6079 let fwinw = float winw in
6081 let sw = fwinw /. float state.w in
6082 let sw = fwinw *. sw in
6083 max
sw (float conf.scrollh
)
6086 let f = state.w+winw in
6087 let r = float (winw-state.x) /. float f in
6088 let p = fwinw *. r in
6092 if position +. sw > fwinw
6093 then fwinw -. position
6096 state.hscrollh, position, sw
6100 match state.mode with
6101 | LinkNav
_ -> "links"
6102 | Textentry
_ -> "textentry"
6103 | Birdseye
_ -> "birdseye"
6106 findkeyhash conf modename
6113 let fontpath = ref "";;
6116 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6119 let l = String.length
s in
6120 let b = Buffer.create
l in
6126 try Sys.getenv
"HOME"
6129 ("Can not determine home directory location: " ^
6130 Printexc.to_string exn
);
6134 let modifier_of_string = function
6135 | "alt" -> Wsi.altmask
6136 | "shift" -> Wsi.shiftmask
6137 | "ctrl" | "control" -> Wsi.ctrlmask
6138 | "meta" -> Wsi.metamask
6143 let r = Str.regexp
"-" in
6145 let elems = Str.full_split
r s in
6148 let m1 = modifier_of_string s in
6150 then (Wsi.namekey
s, m)
6153 | Str.Delim
s when n land 1 = 0 -> g s
6155 | Str.Delim
_ -> (k
, m)
6157 let rec loop n k
m = function
6160 let k, m = f n k m x in
6166 let keys_of_string =
6167 let r = Str.regexp
"[ \t]" in
6169 let elems = Str.split
r s in
6170 List.map
key_of_string elems
6173 let copykeyhashes c =
6174 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6177 let config_of c attrs
=
6181 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6182 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6183 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6184 | "preload" -> { c with preload = bool_of_string
v }
6185 | "page-bias" -> { c with pagebias
= int_of_string
v }
6186 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6187 | "horizontal-scroll-step" ->
6188 { c with hscrollstep
= max
(int_of_string
v) 1 }
6189 | "auto-scroll-step" ->
6190 { c with autoscrollstep
= max
0 (int_of_string
v) }
6191 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6192 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6195 match String.lowercase
v with
6196 | "true" -> Some infinity
6198 | f -> Some
(float_of_string
f)
6200 { c with maxwait
= mw}
6201 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6202 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6203 | "vertical-margin" ->
6204 { c with interpagespace
= max
0 (int_of_string
v) }
6206 let zoom = float_of_string
v /. 100. in
6207 let zoom = max
zoom 0.0 in
6208 { c with zoom = zoom }
6209 | "presentation" -> { c with presentation
= bool_of_string
v }
6210 | "rotation-angle" -> { c with angle
= int_of_string
v }
6211 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6212 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6213 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6214 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6215 | "pixmap-cache-size" ->
6216 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6217 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6218 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6219 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6220 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6221 | "background-color" -> { c with bgcolor
= color_of_string v }
6222 | "scrollbar-in-presentation" ->
6223 { c with scrollbarinpm
= bool_of_string
v }
6224 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6225 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6226 | "mupdf-store-size" ->
6227 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6228 | "checkers" -> { c with checkers
= bool_of_string
v }
6229 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6230 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6231 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6232 | "uri-launcher" -> { c with urilauncher
= unent v }
6233 | "path-launcher" -> { c with pathlauncher
= unent v }
6234 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6235 | "invert-colors" -> { c with invert
= bool_of_string
v }
6236 | "brightness" -> { c with colorscale
= float_of_string
v }
6237 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6239 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6241 let (n, _, _) as nab
= multicolumns_of_string v in
6243 then { c with columns
= Csplit
(-n, [||]) }
6244 else { c with columns
= Cmulti
(nab
, [||]) }
6245 | "birds-eye-columns" ->
6246 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6247 | "selection-command" -> { c with selcmd
= unent v }
6248 | "synctex-command" -> { c with stcmd
= unent v }
6249 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6250 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6251 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6252 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6253 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6256 prerr_endline
("Error processing attribute (`" ^
6257 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6260 let rec fold c = function
6263 let c = apply c k v in
6266 fold { c with keyhashes
= copykeyhashes c } attrs
;
6269 let fromstring f pos
n v d =
6272 dolog "Error processing attribute (%S=%S) at %d\n%s"
6273 n v pos
(Printexc.to_string exn
)
6278 let bookmark_of attrs
=
6279 let rec fold title page
rely visy
= function
6280 | ("title", v) :: rest
-> fold v page
rely visy rest
6281 | ("page", v) :: rest
-> fold title v rely visy rest
6282 | ("rely", v) :: rest
-> fold title page
v visy rest
6283 | ("visy", v) :: rest
-> fold title page
rely v rest
6284 | _ :: rest
-> fold title page
rely visy rest
6285 | [] -> title, page
, rely, visy
6287 fold "invalid" "0" "0" "0" attrs
6291 let rec fold path page
rely pan visy
= function
6292 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6293 | ("page", v) :: rest
-> fold path v rely pan visy rest
6294 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6295 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6296 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6297 | _ :: rest
-> fold path page
rely pan visy rest
6298 | [] -> path, page
, rely, pan
, visy
6300 fold "" "0" "0" "0" "0" attrs
6304 let rec fold rs ls
= function
6305 | ("out", v) :: rest
-> fold v ls rest
6306 | ("in", v) :: rest
-> fold rs
v rest
6307 | _ :: rest
-> fold ls rs rest
6313 let setconf dst
src =
6314 dst
.scrollbw
<- src.scrollbw
;
6315 dst
.scrollh
<- src.scrollh
;
6316 dst
.icase
<- src.icase
;
6317 dst
.preload <- src.preload;
6318 dst
.pagebias
<- src.pagebias
;
6319 dst
.verbose
<- src.verbose
;
6320 dst
.scrollstep
<- src.scrollstep
;
6321 dst
.maxhfit
<- src.maxhfit
;
6322 dst
.crophack
<- src.crophack
;
6323 dst
.autoscrollstep
<- src.autoscrollstep
;
6324 dst
.maxwait
<- src.maxwait
;
6325 dst
.hlinks
<- src.hlinks
;
6326 dst
.underinfo
<- src.underinfo
;
6327 dst
.interpagespace
<- src.interpagespace
;
6328 dst
.zoom <- src.zoom;
6329 dst
.presentation
<- src.presentation
;
6330 dst
.angle
<- src.angle
;
6331 dst
.cwinw
<- src.cwinw
;
6332 dst
.cwinh
<- src.cwinh
;
6333 dst
.savebmarks
<- src.savebmarks
;
6334 dst
.memlimit
<- src.memlimit
;
6335 dst
.proportional
<- src.proportional
;
6336 dst
.texcount
<- src.texcount
;
6337 dst
.sliceheight
<- src.sliceheight
;
6338 dst
.thumbw
<- src.thumbw
;
6339 dst
.jumpback
<- src.jumpback
;
6340 dst
.bgcolor
<- src.bgcolor
;
6341 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6342 dst
.tilew
<- src.tilew
;
6343 dst
.tileh
<- src.tileh
;
6344 dst
.mustoresize
<- src.mustoresize
;
6345 dst
.checkers
<- src.checkers
;
6346 dst
.aalevel
<- src.aalevel
;
6347 dst
.trimmargins
<- src.trimmargins
;
6348 dst
.trimfuzz
<- src.trimfuzz
;
6349 dst
.urilauncher
<- src.urilauncher
;
6350 dst
.colorspace
<- src.colorspace
;
6351 dst
.invert
<- src.invert
;
6352 dst
.colorscale
<- src.colorscale
;
6353 dst
.redirectstderr <- src.redirectstderr;
6354 dst
.ghyllscroll
<- src.ghyllscroll
;
6355 dst
.columns
<- src.columns
;
6356 dst
.beyecolumns
<- src.beyecolumns
;
6357 dst
.selcmd
<- src.selcmd
;
6358 dst
.updatecurs
<- src.updatecurs
;
6359 dst
.pathlauncher
<- src.pathlauncher
;
6360 dst
.keyhashes
<- copykeyhashes src;
6361 dst
.hfsize
<- src.hfsize
;
6362 dst
.hscrollstep
<- src.hscrollstep
;
6363 dst
.pgscale <- src.pgscale;
6364 dst
.usepbo
<- src.usepbo
;
6365 dst
.wheelbypage
<- src.wheelbypage
;
6366 dst
.stcmd
<- src.stcmd
;
6370 let h = Hashtbl.create
10 in
6371 let dc = { defconf with angle
= defconf.angle
} in
6372 let rec toplevel v t spos
_ =
6374 | Vdata
| Vcdata
| Vend
-> v
6375 | Vopen
("llppconfig", _, closed
) ->
6378 else { v with f = llppconfig
}
6380 error
"unexpected subelement at top level" s spos
6381 | Vclose
_ -> error
"unexpected close at top level" s spos
6383 and llppconfig
v t spos
_ =
6385 | Vdata
| Vcdata
-> v
6386 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6387 | Vopen
("defaults", attrs
, closed
) ->
6388 let c = config_of dc attrs
in
6392 else { v with f = defaults
}
6394 | Vopen
("ui-font", attrs
, closed
) ->
6395 let rec getsize size
= function
6397 | ("size", v) :: rest
->
6399 fromstring int_of_string spos
"size" v fstate.fontsize
in
6401 | l -> getsize size l
6403 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6406 else { v with f = uifont
(Buffer.create
10) }
6408 | Vopen
("doc", attrs
, closed
) ->
6409 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6410 let path = unent pathent
6411 and pageno = fromstring int_of_string spos
"page" spage
0
6412 and rely = fromstring float_of_string spos
"rely" srely
0.0
6413 and pan
= fromstring int_of_string spos
"pan" span
0
6414 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6415 let c = config_of dc attrs
in
6416 let anchor = (pageno, rely, visy
) in
6418 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6419 else { v with f = doc
path pan
anchor c [] }
6422 error
"unexpected subelement in llppconfig" s spos
6424 | Vclose
"llppconfig" -> { v with f = toplevel }
6425 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6427 and defaults
v t spos
_ =
6429 | Vdata
| Vcdata
-> v
6430 | Vend
-> error
"unexpected end of input in defaults" s spos
6431 | Vopen
("keymap", attrs
, closed
) ->
6433 try List.assoc
"mode" attrs
6434 with Not_found
-> "global" in
6439 let h = findkeyhash dc modename in
6440 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6443 { v with f = pkeymap
ret KeyMap.empty }
6445 | Vopen
(_, _, _) ->
6446 error
"unexpected subelement in defaults" s spos
6448 | Vclose
"defaults" ->
6449 { v with f = llppconfig
}
6451 | Vclose
_ -> error
"unexpected close in defaults" s spos
6453 and uifont
b v t spos
epos =
6456 Buffer.add_substring
b s spos
(epos - spos
);
6458 | Vopen
(_, _, _) ->
6459 error
"unexpected subelement in ui-font" s spos
6460 | Vclose
"ui-font" ->
6461 if String.length
!fontpath = 0
6462 then fontpath := Buffer.contents
b;
6463 { v with f = llppconfig
}
6464 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6465 | Vend
-> error
"unexpected end of input in ui-font" s spos
6467 and doc
path pan
anchor c bookmarks
v t spos
_ =
6469 | Vdata
| Vcdata
-> v
6470 | Vend
-> error
"unexpected end of input in doc" s spos
6471 | Vopen
("bookmarks", _, closed
) ->
6474 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6476 | Vopen
("keymap", attrs
, closed
) ->
6478 try List.assoc
"mode" attrs
6479 with Not_found
-> "global"
6485 let h = findkeyhash c modename in
6486 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6487 doc
path pan
anchor c bookmarks
6489 { v with f = pkeymap
ret KeyMap.empty }
6491 | Vopen
(_, _, _) ->
6492 error
"unexpected subelement in doc" s spos
6495 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6496 { v with f = llppconfig
}
6498 | Vclose
_ -> error
"unexpected close in doc" s spos
6500 and pkeymap
ret keymap
v t spos
_ =
6502 | Vdata
| Vcdata
-> v
6503 | Vend
-> error
"unexpected end of input in keymap" s spos
6504 | Vopen
("map", attrs
, closed
) ->
6505 let r, l = map_of attrs
in
6506 let kss = fromstring keys_of_string spos
"in" r [] in
6507 let lss = fromstring keys_of_string spos
"out" l [] in
6511 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6512 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6515 then { v with f = pkeymap
ret keymap }
6518 { v with f = skip
"map" f }
6521 error
"unexpected subelement in keymap" s spos
6523 | Vclose
"keymap" ->
6524 { v with f = ret keymap }
6526 | Vclose
_ -> error
"unexpected close in keymap" s spos
6528 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6530 | Vdata
| Vcdata
-> v
6531 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6532 | Vopen
("item", attrs
, closed
) ->
6533 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6534 let page = fromstring int_of_string spos
"page" spage
0
6535 and rely = fromstring float_of_string spos
"rely" srely
0.0
6536 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6538 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6541 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6544 { v with f = skip
"item" f }
6547 error
"unexpected subelement in bookmarks" s spos
6549 | Vclose
"bookmarks" ->
6550 { v with f = doc
path pan
anchor c bookmarks }
6552 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6554 and skip tag
f v t spos
_ =
6556 | Vdata
| Vcdata
-> v
6558 error
("unexpected end of input in skipped " ^ tag
) s spos
6559 | Vopen
(tag'
, _, closed
) ->
6563 let f'
() = { v with f = skip tag
f } in
6564 { v with f = skip tag'
f'
}
6568 else error
("unexpected close in skipped " ^ tag
) s spos
6571 parse
{ f = toplevel; accu = () } s;
6577 let len = in_channel_length ic
in
6578 let s = String.create
len in
6579 really_input ic
s 0 len;
6582 | Parse_error
(msg
, s, pos
) ->
6583 let subs = subs s pos
in
6584 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6585 failwith
("parse error: " ^
s)
6588 failwith
("config load error: " ^
Printexc.to_string exn
)
6594 let dir = Filename.concat
home ".config" in
6595 if Sys.is_directory
dir then dir else home
6598 Filename.concat
dir "llpp.conf"
6601 let confpath = ref defconfpath;;
6604 if Sys.file_exists
!confpath
6607 (try Some
(open_in_bin
!confpath)
6610 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6611 Printexc.to_string exn
);
6621 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6622 Printexc.to_string exn
);
6630 f (Hashtbl.create
0, defconf)
6635 let pc, pb
, px, pa
=
6637 Hashtbl.find h (Filename.basename
state.path)
6638 with Not_found
-> dc, [], 0, emptyanchor
6642 state.bookmarks <- pb
;
6644 state.scrollw
<- conf.scrollbw
;
6646 then state.anchor <- pa
;
6647 cbput state.hists
.nav pa
;
6653 let add_attrs bb always
dc c =
6656 then Printf.bprintf bb
"\n %s='%b'" s a
6659 then Printf.bprintf bb
"\n %s='%d'" s a
6662 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6665 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6668 then Printf.bprintf bb
"\n %s='%f'" s a
6672 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6676 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6680 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6684 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6690 | Some
(_N
, _A
, _B
) ->
6691 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6701 else string_of_float
f
6703 Printf.bprintf bb
"\n %s='%s'" s v
6708 | Cmulti
((n, a, b), _) when n > 1 ->
6709 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6710 | Csplit
(n, _) when n > 1 ->
6711 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6717 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6720 oi
"width" c.cwinw
dc.cwinw
;
6721 oi
"height" c.cwinh
dc.cwinh
;
6722 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6723 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6724 ob "case-insensitive-search" c.icase
dc.icase
;
6725 ob "preload" c.preload dc.preload;
6726 oi
"page-bias" c.pagebias
dc.pagebias
;
6727 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6728 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6729 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6730 ob "crop-hack" c.crophack
dc.crophack
;
6731 oW
"throttle" c.maxwait
dc.maxwait
;
6732 ob "highlight-links" c.hlinks
dc.hlinks
;
6733 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6734 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6735 oz
"zoom" c.zoom dc.zoom;
6736 ob "presentation" c.presentation
dc.presentation
;
6737 oi
"rotation-angle" c.angle
dc.angle
;
6738 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6739 ob "proportional-display" c.proportional
dc.proportional
;
6740 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6741 oi
"tex-count" c.texcount
dc.texcount
;
6742 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6743 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6744 ob "persistent-location" c.jumpback
dc.jumpback
;
6745 oc
"background-color" c.bgcolor
dc.bgcolor
;
6746 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6747 oi
"tile-width" c.tilew
dc.tilew
;
6748 oi
"tile-height" c.tileh
dc.tileh
;
6749 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6750 ob "checkers" c.checkers
dc.checkers
;
6751 oi
"aalevel" c.aalevel
dc.aalevel
;
6752 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6753 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6754 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6755 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6756 oC
"color-space" c.colorspace
dc.colorspace
;
6757 ob "invert-colors" c.invert
dc.invert
;
6758 oF
"brightness" c.colorscale
dc.colorscale
;
6759 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6760 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6761 oco
"columns" c.columns
dc.columns
;
6762 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6763 os
"selection-command" c.selcmd
dc.selcmd
;
6764 os
"synctex-command" c.stcmd
dc.stcmd
;
6765 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6766 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6767 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6768 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6769 ob "use-pbo" c.usepbo
dc.usepbo
;
6770 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6773 let keymapsbuf always
dc c =
6774 let bb = Buffer.create
16 in
6775 let rec loop = function
6777 | (modename, h) :: rest
->
6778 let dh = findkeyhash dc modename in
6779 if always
|| h <> dh
6781 if Hashtbl.length
h > 0
6783 if Buffer.length
bb > 0
6784 then Buffer.add_char
bb '
\n'
;
6785 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6786 Hashtbl.iter
(fun i
o ->
6787 let isdifferent = always
||
6789 let dO = Hashtbl.find dh i
in
6791 with Not_found
-> true
6796 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6797 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6798 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6799 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6800 Buffer.add_string
bb (Wsi.keyname
k);
6803 let rec loop = function
6805 | km
:: [] -> addkm km
6806 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6810 Buffer.add_string
bb "<map in='";
6814 Buffer.add_string
bb "' out='";
6816 Buffer.add_string
bb "'/>\n"
6819 Buffer.add_string
bb "' out='";
6821 Buffer.add_string
bb "'/>\n"
6823 | KMmulti
(ins, kms
) ->
6824 Buffer.add_char
bb ' '
;
6826 Buffer.add_string
bb "' out='";
6828 Buffer.add_string
bb "'/>\n"
6830 Buffer.add_string
bb "</keymap>";
6840 let uifontsize = fstate.fontsize
in
6841 let bb = Buffer.create
32768 in
6846 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
)
6847 | Wsi.MaxVert
-> (w, conf.cwinh
)
6848 | Wsi.MaxHorz
-> (conf.cwinw
, h)
6850 (state.winw, state.winh
) state.winstate
6855 let dc = if conf.bedefault
then conf else dc in
6856 Buffer.add_string
bb "<llppconfig>\n";
6858 if String.length
!fontpath > 0
6860 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6866 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6869 Buffer.add_string
bb "<defaults ";
6870 add_attrs bb true dc dc;
6871 let kb = keymapsbuf true dc dc in
6872 if Buffer.length
kb > 0
6874 Buffer.add_string
bb ">\n";
6875 Buffer.add_buffer
bb kb;
6876 Buffer.add_string
bb "\n</defaults>\n";
6878 else Buffer.add_string
bb "/>\n";
6880 let adddoc path pan
anchor c bookmarks =
6881 if bookmarks == [] && c = dc && anchor = emptyanchor
6884 Printf.bprintf
bb "<doc path='%s'"
6885 (enent
path 0 (String.length
path));
6887 if anchor <> emptyanchor
6889 let n, rely, visy
= anchor in
6890 Printf.bprintf
bb " page='%d'" n;
6893 Printf.bprintf
bb " rely='%f'" rely
6895 if abs_float visy
> 1e-6
6897 Printf.bprintf
bb " visy='%f'" visy
6902 then Printf.bprintf
bb " pan='%d'" pan
;
6904 add_attrs bb false dc c;
6905 let kb = keymapsbuf false dc c in
6907 begin match bookmarks with
6909 if Buffer.length
kb > 0
6911 Buffer.add_string
bb ">\n";
6912 Buffer.add_buffer
bb kb;
6913 Buffer.add_string
bb "\n</doc>\n";
6915 else Buffer.add_string
bb "/>\n"
6917 Buffer.add_string
bb ">\n<bookmarks>\n";
6918 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6920 "<item title='%s' page='%d'"
6921 (enent
title 0 (String.length
title))
6926 Printf.bprintf
bb " rely='%f'" rely
6928 if abs_float visy
> 1e-6
6930 Printf.bprintf
bb " visy='%f'" visy
6932 Buffer.add_string
bb "/>\n";
6934 Buffer.add_string
bb "</bookmarks>";
6935 if Buffer.length
kb > 0
6937 Buffer.add_string
bb "\n";
6938 Buffer.add_buffer
bb kb;
6940 Buffer.add_string
bb "\n</doc>\n";
6946 match state.mode with
6947 | Birdseye
(c, pan, _, _, _) ->
6949 match conf.columns
with
6950 | Cmulti
((c, _, _), _) -> Some
c
6954 match c.columns
with
6955 | Cmulti
(c, _) -> Cmulti
(c, [||])
6956 | Csingle
_ -> Csingle
[||]
6957 | Csplit
_ -> failwith
"quit from bird's eye while split"
6959 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6960 | _ -> state.x, conf
6962 let basename = Filename.basename state.path in
6963 adddoc basename pan (getanchor ())
6965 let autoscrollstep =
6966 match state.autoscroll
with
6968 | None
-> conf.autoscrollstep
6970 match state.mode with
6971 | Birdseye
(bc
, _, _, _, _) ->
6974 presentation
= bc
.presentation
;
6975 interpagespace
= bc
.interpagespace
;
6976 maxwait
= bc
.maxwait
;
6977 autoscrollstep = autoscrollstep }
6978 | _ -> { conf with autoscrollstep = autoscrollstep }
6980 (if conf.savebmarks
then state.bookmarks else []);
6982 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6984 then adddoc path x anchor c bookmarks
6986 Buffer.add_string
bb "</llppconfig>\n";
6989 if load1 f && Buffer.length
bb > 0
6992 let tmp = !confpath ^
".tmp" in
6993 let oc = open_out_bin
tmp in
6994 Buffer.output_buffer
oc bb;
6996 Unix.rename
tmp !confpath;
6999 ("error while saving configuration: " ^
Printexc.to_string exn
)
7003 let adderrmsg src msg
=
7004 Buffer.add_string
state.errmsgs msg
;
7005 state.newerrmsgs
<- true;
7009 let adderrfmt src fmt
=
7010 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7014 let cl = splitatspace cmds
in
7016 try Scanf.sscanf
s fmt
f
7018 adderrfmt "remote exec"
7019 "error processing '%S': %s\n" cmds
(Printexc.to_string exn
)
7022 | "reload" :: [] -> reload ()
7023 | "goto" :: args :: [] ->
7024 let cmd, _ = state.geomcmds
in
7025 scan args "%u %f %f"
7027 if String.length
cmd = 0
7028 then gotopagexy pageno x y
7030 let prevf = state.reprf
in
7032 gotopagexy pageno x y;
7037 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7038 | "rect" :: args :: [] ->
7039 scan args "%u %u %f %f %f %f"
7040 (fun pageno color x0 y0 x1 y1 ->
7041 onpagerect pageno (fun w h ->
7042 let _,w1,h1
,_ = getpagedim pageno in
7043 let sw = float w1 /. w
7044 and sh = float h1
/. h in
7048 and y1s
= y1 *. sh in
7049 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7051 state.rects <- (pageno, color, rect) :: state.rects;
7052 G.postRedisplay "rect";
7055 | "activatewin" :: [] -> Wsi.activatewin
()
7056 | "quit" :: [] -> raise Quit
7058 adderrfmt "remote command"
7059 "error processing remote command: %S\n" cmds
;
7063 let scratch = String.create
80 in
7064 let buf = Buffer.create
80 in
7067 try Some
(Unix.read fd
scratch 0 80)
7069 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7070 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7073 match tempfr () with
7079 if Buffer.length
buf > 0
7081 let s = Buffer.contents
buf in
7091 let pos = String.index_from
scratch ppos '
\n'
in
7092 if pos >= n then -1 else pos
7093 with Not_found
-> -1
7097 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7098 let s = Buffer.contents
buf in
7104 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7110 let remoteopen path =
7111 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7113 adderrfmt "remoteopen" "error opening %S: %s" path (Printexc.to_string exn
);
7118 let trimcachepath = ref "" in
7119 let rcmdpath = ref "" in
7122 [("-p", Arg.String
(fun s -> state.password
<- s) ,
7123 "<password> Set password");
7125 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7126 "<path> Set path to the user interface font");
7128 ("-c", Arg.String
(fun s -> Config.confpath := s),
7129 "<path> Set path to the configuration file");
7131 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7132 "<path> Set path to the trim cache file");
7134 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7135 "<named-destination> Set named destination");
7137 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7139 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7140 "<path> Set path to the remote commands source");
7142 ("-v", Arg.Unit
(fun () ->
7144 "%s\nconfiguration path: %s\n"
7148 exit
0), " Print version and exit");
7151 (fun s -> state.path <- s)
7152 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7154 if String.length
state.path = 0
7155 then (prerr_endline
"file name missing"; exit
1);
7157 if not
(Config.load ())
7158 then prerr_endline
"failed to load configuration";
7160 let globalkeyhash = findkeyhash conf "global" in
7161 let wsfd, winw, winh
= Wsi.init
(object
7163 state.wthack <- false;
7164 if nogeomcmds state.geomcmds
|| platform == Posx
7167 GlClear.color (scalecolor2 conf.bgcolor
);
7168 GlClear.clear
[`
color];
7170 method display = display ()
7171 method reshape w h = reshape w h
7172 method mouse b d x y m = mouse b d x y m
7173 method motion x y = state.mpos
<- (x, y); motion x y
7174 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7176 let mascm = m land (
7177 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7179 match state.keystate
with
7181 let km = k, mascm in
7184 let modehash = state.uioh#
modehash in
7185 try Hashtbl.find modehash km
7187 try Hashtbl.find globalkeyhash km
7188 with Not_found
-> KMinsrt
(k, m)
7190 | KMinsrt
(k, m) -> keyboard k m
7191 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7192 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7194 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7195 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7196 state.keystate
<- KSnone
7197 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7198 state.keystate
<- KSinto
(keys
, insrt
)
7200 state.keystate
<- KSnone
7202 method enter
x y = state.mpos
<- (x, y); pmotion x y
7203 method leave = state.mpos
<- (-1, -1)
7204 method winstate wsl
= state.winstate
<- wsl
7205 method quit
= raise Quit
7206 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7211 List.exists
GlMisc.check_extension
7212 [ "GL_ARB_texture_rectangle"
7213 ; "GL_EXT_texture_recangle"
7214 ; "GL_NV_texture_rectangle" ]
7216 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7219 match Ne.pipe () with
7221 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7225 match Ne.pipe () with
7227 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7237 setcheckers conf.checkers
;
7241 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7242 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7243 !Config.fontpath, !trimcachepath,
7244 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7248 state.text <- "Opening " ^
(mbtoutf8
state.path);
7250 opendoc state.path state.password
;
7253 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7256 if String.length
!rcmdpath > 0
7257 then remoteopen !rcmdpath
7262 let rec loop deadline
=
7264 match state.errfd
with
7265 | None
-> [state.sr
; state.wsfd]
7266 | Some fd
-> [state.sr
; state.wsfd; fd
]
7271 | Some fd
-> fd
:: r
7273 if state.redisplay
&& not
state.wthack
7275 state.redisplay
<- false;
7282 if deadline
= infinity
7284 else max
0.0 (deadline
-. now)
7289 try Unix.select
r [] [] timeout
7290 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7296 if state.ghyll
== noghyll
7298 match state.autoscroll
with
7299 | Some step
when step
!= 0 ->
7300 let y = state.y + step
in
7304 else if y >= state.maxy then 0 else y
7307 if state.mode = View
7308 then state.text <- "";
7311 else deadline
+. 0.01
7316 let rec checkfds = function
7318 | fd
:: rest
when fd
= state.sr
->
7319 let cmd = readcmd state.sr
in
7323 | fd
:: rest
when fd
= state.wsfd ->
7327 | fd
:: rest
when Some fd
= !optrfd ->
7328 begin match remote fd
with
7329 | None
-> optrfd := remoteopen !rcmdpath;
7330 | opt -> optrfd := opt
7335 let s = String.create
80 in
7336 let n = tempfailureretry (Unix.read fd
s 0) 80 in
7337 if conf.redirectstderr
7339 Buffer.add_substring
state.errmsgs
s 0 n;
7340 state.newerrmsgs
<- true;
7341 state.redisplay
<- true;
7344 prerr_string
(String.sub
s 0 n);
7352 if deadline
= infinity
7356 match state.autoscroll
with
7357 | Some step
when step
!= 0 -> deadline1
7358 | _ -> if state.ghyll
== noghyll then infinity
else deadline1