6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: string -> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
87 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
88 external platform
: unit -> platform
= "ml_platform";;
89 external setaalevel
: int -> unit = "ml_setaalevel";;
90 external realloctexts
: int -> bool = "ml_realloctexts";;
91 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
92 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
93 external getlink
: opaque
-> int -> under
= "ml_getlink";;
94 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
95 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
97 let platform_to_string = function
98 | Punknown
-> "unknown"
102 | Pfreebsd
-> "FreeBSD"
103 | Pdragonflybsd
-> "DragonflyBSD"
104 | Popenbsd
-> "OpenBSD"
105 | Pnetbsd
-> "NetBSD"
106 | Pcygwin
-> "Cygwin"
109 let platform = platform ();;
115 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
118 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
120 type mpos
= int * int
122 | Msel
of (mpos
* mpos
)
124 | Mscrolly
| Mscrollx
125 | Mzoom
of (int * int)
126 | Mzoomrect
of (mpos
* mpos
)
130 type textentry
= string * string * onhist
option * onkey
* ondone
131 and onkey
= string -> int -> te
132 and ondone
= string -> unit
133 and histcancel
= unit -> unit
134 and onhist
= ((histcmd
-> string) * histcancel
)
135 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
140 | TEswitch
of textentry
151 let bound v minv maxv
=
152 max minv
(min maxv v
);
156 { store
= Array.create n v
163 let drawstring size x y s
=
165 Gl.enable `texture_2d
;
166 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
167 ignore
(drawstr size x y s
);
169 Gl.disable `texture_2d
;
172 let drawstring1 size x y s
=
176 let drawstring2 size x y fmt
=
177 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
180 let cbcap b
= Array.length b
.store
;;
185 b
.wc
<- (b
.wc
+ 1) mod cap;
187 b
.len
<- min
(b
.len
+ 1) cap;
190 let cbempty b
= b
.len
= 0;;
192 let cbgetg b circular dir
=
196 let rc = b
.rc + dir
in
208 else max
0 (min
rc (b
.len
-1))
214 let cbget b
= cbgetg b
false;;
215 let cbgetc b
= cbgetg b
true;;
232 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
233 dolog " WxH %dx%d" l
.pagew l
.pageh
;
234 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
235 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
236 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
240 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
242 dolog " x0,y0=(% f, % f)" x0 y0
;
243 dolog " x1,y1=(% f, % f)" x1 y1
;
244 dolog " x2,y2=(% f, % f)" x2 y2
;
245 dolog " x3,y3=(% f, % f)" x3 y3
;
250 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
251 and multicol
= columncount
* covercount
* covercount
253 and columncount
= int
254 and covercount
= int;;
257 { mutable scrollbw
: int
258 ; mutable scrollh
: int
259 ; mutable icase
: bool
260 ; mutable preload
: bool
261 ; mutable pagebias
: int
262 ; mutable verbose
: bool
263 ; mutable debug
: bool
264 ; mutable scrollstep
: int
265 ; mutable maxhfit
: bool
266 ; mutable crophack
: bool
267 ; mutable autoscrollstep
: int
268 ; mutable maxwait
: float option
269 ; mutable hlinks
: bool
270 ; mutable underinfo
: bool
271 ; mutable interpagespace
: interpagespace
272 ; mutable zoom
: float
273 ; mutable presentation
: bool
274 ; mutable angle
: angle
277 ; mutable savebmarks
: bool
278 ; mutable proportional
: proportional
279 ; mutable trimmargins
: trimmargins
280 ; mutable trimfuzz
: irect
281 ; mutable memlimit
: memsize
282 ; mutable texcount
: texcount
283 ; mutable sliceheight
: sliceheight
284 ; mutable thumbw
: width
285 ; mutable jumpback
: bool
286 ; mutable bgcolor
: float * float * float
287 ; mutable bedefault
: bool
288 ; mutable scrollbarinpm
: bool
289 ; mutable tilew
: int
290 ; mutable tileh
: int
291 ; mutable mustoresize
: memsize
292 ; mutable checkers
: bool
293 ; mutable aalevel
: int
294 ; mutable urilauncher
: string
295 ; mutable pathlauncher
: string
296 ; mutable colorspace
: colorspace
297 ; mutable invert
: bool
298 ; mutable colorscale
: float
299 ; mutable redirectstderr
: bool
300 ; mutable ghyllscroll
: (int * int * int) option
301 ; mutable columns
: columns
option
302 ; mutable beyecolumns
: columncount
option
303 ; mutable selcmd
: string
304 ; mutable updatecurs
: bool
305 ; mutable keyhashes
: (string * keyhash
) list
309 type anchor
= pageno
* top
;;
311 type outline
= string * int * anchor
;;
313 type rect
= float * float * float * float * float * float * float * float;;
315 type tile
= opaque
* pixmapsize
* elapsed
316 and elapsed
= float;;
317 type pagemapkey
= pageno
* gen
;;
318 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
322 let emptyanchor = (0, 0.0);;
324 type infochange
= | Memused
| Docinfo
| Pdim
;;
326 class type uioh
= object
327 method display
: unit
328 method key
: int -> int -> uioh
329 method button
: int -> bool -> int -> int -> int -> uioh
330 method motion
: int -> int -> uioh
331 method pmotion
: int -> int -> uioh
332 method infochanged
: infochange
-> unit
333 method scrollpw
: (int * float * float)
334 method scrollph
: (int * float * float)
335 method modehash
: keyhash
339 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
340 | Textentry
of (textentry
* onleave
)
342 | LinkNav
of linktarget
343 and onleave
= leavetextentrystatus
-> unit
344 and leavetextentrystatus
= | Cancel
| Confirm
345 and helpitem
= string * int * action
348 | Action
of (uioh
-> uioh
)
350 | Ltexact
of (pageno
* int)
354 let isbirdseye = function Birdseye _
-> true | _
-> false;;
355 let istextentry = function Textentry _
-> true | _
-> false;;
359 | Loading
of (page
* gen
)
361 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
363 | Outlining
of outline list
366 let emptykeyhash = Hashtbl.create
0;;
367 let nouioh : uioh
= object (self
)
369 method key _ _
= self
370 method button _ _ _ _ _
= self
371 method motion _ _
= self
372 method pmotion _ _
= self
373 method infochanged _
= ()
374 method scrollpw
= (0, nan
, nan
)
375 method scrollph
= (0, nan
, nan
)
376 method modehash
= emptykeyhash
380 { mutable sr
: Unix.file_descr
381 ; mutable sw
: Unix.file_descr
382 ; mutable wsfd
: Unix.file_descr
383 ; mutable errfd
: Unix.file_descr
option
384 ; mutable stderr
: Unix.file_descr
385 ; mutable errmsgs
: Buffer.t
386 ; mutable newerrmsgs
: bool
390 ; mutable scrollw
: int
391 ; mutable hscrollh
: int
392 ; mutable anchor
: anchor
393 ; mutable ranchors
: (string * string * anchor
) list
395 ; mutable layout
: page list
396 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
397 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
398 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
399 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
400 ; mutable pagecount
: int
401 ; mutable currently
: currently
402 ; mutable mstate
: mstate
403 ; mutable searchpattern
: string
404 ; mutable rects
: (pageno
* recttype
* rect
) list
405 ; mutable rects1
: (pageno
* recttype
* rect
) list
406 ; mutable text
: string
407 ; mutable fullscreen
: (width
* height
) option
408 ; mutable mode
: mode
409 ; mutable uioh
: uioh
410 ; mutable outlines
: outline array
411 ; mutable bookmarks
: outline list
412 ; mutable path
: string
413 ; mutable password
: string
414 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
415 ; mutable memused
: memsize
417 ; mutable throttle
: (page list
* int * float) option
418 ; mutable autoscroll
: int option
419 ; mutable ghyll
: (int option -> unit)
420 ; mutable help
: helpitem array
421 ; mutable docinfo
: (int * string) list
422 ; mutable texid
: GlTex.texture_id
option
424 ; mutable prevzoom
: float
425 ; mutable progress
: float
426 ; mutable redisplay
: bool
427 ; mutable mpos
: mpos
428 ; mutable keystate
: keystate
431 { pat
: string circbuf
432 ; pag
: string circbuf
433 ; nav
: anchor circbuf
434 ; sel
: string circbuf
455 ; presentation
= false
460 ; proportional
= true
461 ; trimmargins
= false
462 ; trimfuzz
= (0,0,0,0)
463 ; memlimit
= 32 lsl 20
468 ; bgcolor
= (0.5, 0.5, 0.5)
470 ; scrollbarinpm
= true
473 ; mustoresize
= 128 lsl 20
478 | Plinux
| Pfreebsd
| Pdragonflybsd
479 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
480 | Posx
-> "open \"%s\""
481 | Pcygwin
-> "cygstart %s"
482 | Punknown
-> "echo %s")
483 ; pathlauncher
= "lp \"%s\""
486 | Plinux
| Pfreebsd
| Pdragonflybsd
487 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
494 ; redirectstderr
= false
500 let mk n
= (n
, Hashtbl.create
1) in
513 let findkeyhash c name
=
514 try List.assoc name c
.keyhashes
515 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
518 let conf = { defconf with angle
= defconf.angle
};;
521 { mutable fontsize
: int
522 ; mutable wwidth
: float
523 ; mutable maxrows
: int
535 fstate.fontsize
<- n
;
536 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
537 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
541 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
542 let len = String.length s
in
543 if colonpos >= 0 && colonpos + 3 < len
545 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
548 try String.rindex_from s
colonpos ' '
552 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
555 | "http" | "ftp" | "mailto" ->
557 try String.index_from s
colonpos ' '
558 with Not_found
-> len
560 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
568 let shell, farg
= "/bin/sh", "-c" in
570 let args = [|shell; farg
; s
|] in
571 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
575 if String.length
conf.urilauncher
= 0
576 then print_endline uri
578 let url = geturl uri
in
579 if String.length
url = 0
580 then print_endline uri
582 let re = Str.regexp
"%s" in
583 let command = Str.global_replace
re url conf.urilauncher
in
587 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
593 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
594 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
598 let strings = version () :: "" :: Help.keys
in
601 let url = geturl s
in
602 if String.length
url > 0
603 then (s
, 0, Action
(fun u
-> gotouri url; u
))
604 else (s
, 0, Noaction
)
609 let firstgeomcmds = "", [];;
616 ; stderr
= Unix.stderr
617 ; errmsgs
= Buffer.create
0
624 ; anchor
= emptyanchor
628 ; tilelru
= Queue.create
()
629 ; pagemap
= Hashtbl.create
10
630 ; tilemap
= Hashtbl.create
10
645 ; geomcmds
= firstgeomcmds
647 { nav
= cbnew 10 (0, 0.0)
672 Printf.kprintf prerr_endline fmt
674 Printf.kprintf ignore fmt
678 if String.length
conf.pathlauncher
= 0
679 then print_endline
state.path
681 let re = Str.regexp
"%s" in
682 let command = Str.global_replace
re state.path
conf.pathlauncher
in
686 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
691 let redirectstderr () =
692 if conf.redirectstderr
694 let rfd, wfd
= Unix.pipe
() in
695 state.stderr
<- Unix.dup
Unix.stderr
;
696 state.errfd
<- Some
rfd;
697 Unix.dup2 wfd
Unix.stderr
;
699 state.newerrmsgs
<- false;
700 begin match state.errfd
with
703 Unix.dup2
state.stderr
Unix.stderr
;
707 prerr_string
(Buffer.contents
state.errmsgs
);
709 Buffer.clear
state.errmsgs
;
715 let postRedisplay who
=
717 then prerr_endline
("redisplay for " ^ who
);
718 state.redisplay
<- true;
722 let getopaque pageno
=
723 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
724 with Not_found
-> None
727 let putopaque pageno opaque
=
728 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
731 let pagetranslatepoint l x y
=
732 let dy = y
- l
.pagedispy
in
733 let y = dy + l
.pagey
in
734 let dx = x
- l
.pagedispx
in
735 let x = dx + l
.pagex
in
742 begin match getopaque l
.pageno
with
744 let x0 = l
.pagedispx
in
745 let x1 = x0 + l
.pagevw
in
746 let y0 = l
.pagedispy
in
747 let y1 = y0 + l
.pagevh
in
748 if y >= y0 && y <= y1 && x >= x0 && x <= x1
750 let px, py
= pagetranslatepoint l
x y in
751 match whatsunder opaque
px py
with
764 state.text
<- Printf.sprintf
"%c%s" c s
;
765 G.postRedisplay "showtext";
768 let updateunder x y =
769 match getunder x y with
770 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
772 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
773 Wsi.setcursor
Wsi.CURSOR_INFO
774 | Ulinkgoto
(page
, _
) ->
776 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
777 Wsi.setcursor
Wsi.CURSOR_INFO
779 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
780 Wsi.setcursor
Wsi.CURSOR_TEXT
782 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
783 Wsi.setcursor
Wsi.CURSOR_INHERIT
785 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
786 Wsi.setcursor
Wsi.CURSOR_INHERIT
788 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
789 Wsi.setcursor
Wsi.CURSOR_INHERIT
790 | Uremote
(filename
, pageno
) ->
791 if conf.underinfo
then showtext 'r'
792 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
793 Wsi.setcursor
Wsi.CURSOR_INFO
796 let showlinktype under
=
802 showtext 'u'
("ri: " ^ uri
)
803 | Ulinkgoto
(page
, _
) ->
804 showtext 'p'
("age: " ^ string_of_int
(page
+1));
806 showtext '
f'
("ont: " ^ s
);
808 showtext 'u'
("nexpected: " ^ s
);
810 showtext 'l'
("aunch: " ^ s
);
812 showtext 'n'
("amed: " ^ s
);
813 | Uremote
(filename
, pageno
) ->
814 showtext 'r'
(Printf.sprintf
"emote: %s (%d)" filename pageno
);
818 let b = Buffer.create
(String.length s
+ 1) in
819 Buffer.add_string
b s
;
824 let colorspace_of_string s
=
825 match String.lowercase s
with
829 | _
-> failwith
"invalid colorspace"
832 let int_of_colorspace = function
838 let colorspace_of_int = function
842 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
845 let colorspace_to_string = function
851 let intentry_with_suffix text key
=
853 if key
>= 32 && key
< 127
857 match Char.lowercase
c with
859 let text = addchar text c in
863 let text = addchar text c in
867 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
871 let columns_to_string (n
, a
, b) =
873 then Printf.sprintf
"%d" n
874 else Printf.sprintf
"%d,%d,%d" n a
b;
877 let columns_of_string s
=
879 (int_of_string s
, 0, 0)
881 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
886 let n = Unix.read fd
s 0 4 in
887 if n != 4 then failwith
"incomplete read(len)";
889 lor (Char.code
s.[0] lsl 24)
890 lor (Char.code
s.[1] lsl 16)
891 lor (Char.code
s.[2] lsl 8)
892 lor (Char.code
s.[3] lsl 0)
894 let s = String.create
len in
895 let n = Unix.read fd
s 0 len in
896 if n != len then failwith
"incomplete read(data)";
900 let btod b = if b then 1 else 0;;
903 let b = Buffer.create
16 in
904 Buffer.add_string
b "llll";
907 let s = Buffer.contents
b in
908 let n = String.length
s in
910 (* dolog "wcmd %S" (String.sub s 4 len); *)
911 s.[0] <- Char.chr
((len lsr 24) land 0xff);
912 s.[1] <- Char.chr
((len lsr 16) land 0xff);
913 s.[2] <- Char.chr
((len lsr 8) land 0xff);
914 s.[3] <- Char.chr
(len land 0xff);
915 let n'
= Unix.write
state.sw
s 0 n in
916 if n'
!= n then failwith
"write failed";
923 let d = conf.winh
- h
in
930 let rec f pn ph pi fh l
=
932 | (n, _
, h
, _
) :: rest
->
933 let ips = calcips h
in
938 if isbirdseye state.mode
&& pn
= 0
943 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
948 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
952 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
955 let fh = f 0 0 0 0 state.pdims
in
960 match conf.columns
with
961 | None
-> calcheight ()
963 if Array.length
b > 0
965 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
970 let getpageyh pageno
=
971 let rec f pn ph pi
y l
=
973 | (n, _
, h
, _
) :: rest
->
974 let ips = calcips h
in
977 let h = if n = pageno
then h else ph
in
978 if conf.presentation
&& n = pageno
980 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
982 y + (pageno
- pn
) * (ph
+ pi
), h
984 let y = y + (if conf.presentation
then pi
else 0) in
985 let y = y + (n - pn
) * (ph
+ pi
) in
989 y + (pageno
- pn
) * (ph
+ pi
), ph
991 f 0 0 0 0 state.pdims
994 let getpageyh pageno
=
995 match conf.columns
with
996 | None
-> getpageyh pageno
998 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1002 let getpagedim pageno
=
1005 | (n, _
, _
, _
) as pdim
:: rest
->
1007 then (if n = pageno
then pdim
else ppdim
)
1012 f (-1, -1, -1, -1) state.pdims
1015 let getpagey pageno
= fst
(getpageyh pageno
);;
1017 let nogeomcmds cmds
=
1019 | s, [] -> String.length
s = 0
1024 let sh = sh - state.hscrollh
in
1025 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1026 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1028 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1029 let ips = calcips h in
1031 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1035 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1037 prev
, pdims
, pdimno
, 0
1039 let dy = dy + yinc in
1040 let py = py + yinc in
1041 if pageno
= state.pagecount
|| dy >= sh
1046 if py + h <= vy - yinc
1048 let py = py + h + ips in
1049 let dy = max
0 (py - y) in
1050 f ~pageno
:(pageno
+1)
1058 let pagey = vy - py in
1059 let pagevh = h - pagey in
1060 let pagevh = min
(sh - dy) pagevh in
1061 let off = if yinc > 0 then py - vy else 0 in
1062 let py = py + h + ips in
1065 if state.w
< conf.winw
- state.scrollw
1066 then (conf.winw
- state.scrollw
- state.w
) / 2
1069 let dispx = xoff + state.x in
1075 let lw = w
- pagex in
1076 min
lw (conf.winw
- state.scrollw
)
1080 ; pagedimno
= pdimno
1084 ; pagey = pagey + off
1086 ; pagevh = pagevh - off
1088 ; pagedispy
= dy + off
1091 let accu = e :: accu in
1092 f ~pageno
:(pageno
+1)
1100 if nogeomcmds state.geomcmds
1118 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1119 let sh = sh - state.hscrollh
in
1120 let rec fold accu n =
1121 if n = Array.length
b
1124 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1127 || n = state.pagecount
- coverB
1128 || (n - coverA
) mod columns
= columns
- 1)
1134 let pagey = max
0 (y - vy) in
1135 let pagedispy = if pagey > 0 then 0 else vy - y in
1136 let pagedispx, pagex, pagevw =
1138 if n = coverA
- 1 || n = state.pagecount
- coverB
1139 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1140 else dx + xoff + state.x
1143 then 0, -pdx, w
+ pdx
1144 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1146 let pagevh = min
(h - pagey) (sh - pagedispy) in
1147 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1151 ; pagedimno
= pdimno
1158 ; pagedispx = pagedispx
1159 ; pagedispy = pagedispy
1170 if nogeomcmds state.geomcmds
1171 then List.rev
(fold [] 0)
1176 match conf.columns
with
1177 | None
-> layout1 y sh
1178 | Some
c -> layoutN c y sh
1182 let y = state.y + incr
in
1184 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1189 let tilex = l
.pagex mod conf.tilew
in
1190 let tiley = l
.pagey mod conf.tileh
in
1192 let col = l
.pagex / conf.tilew
in
1193 let row = l
.pagey / conf.tileh
in
1196 let a = l
.pagew
- l
.pagex in
1197 let b = conf.winw
- state.scrollw
in
1199 and vh
= l
.pagevh in
1201 let rec rowloop row y0 dispy
h =
1205 let dh = conf.tileh
- y0 in
1206 let dh = min
h dh in
1207 let rec colloop col x0 dispx w
=
1211 let dw = conf.tilew
- x0 in
1212 let dw = min w
dw in
1214 f col row dispx dispy
x0 y0 dw dh;
1215 colloop (col+1) 0 (dispx+dw) (w
-dw)
1218 colloop col tilex l
.pagedispx vw;
1219 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1223 then rowloop row tiley l
.pagedispy vh
;
1226 let gettileopaque l
col row =
1228 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1230 try Some
(Hashtbl.find
state.tilemap
key)
1231 with Not_found
-> None
1234 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1235 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1236 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1239 let drawtiles l color
=
1241 let f col row x y tilex tiley w
h =
1242 match gettileopaque l
col row with
1243 | Some
(opaque
, _
, t
) ->
1244 let params = x, y, w
, h, tilex, tiley in
1248 GlFunc.blend_func `zero `one_minus_src_color
;
1250 drawtile
params opaque
;
1252 then Gl.disable `blend
;
1255 let s = Printf.sprintf
1259 let w = measurestr
fstate.fontsize
s in
1260 GlMisc.push_attrib
[`current
];
1261 GlDraw.color
(0.0, 0.0, 0.0);
1263 (float (x-2), float (y-2))
1264 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1265 GlDraw.color
(1.0, 1.0, 1.0);
1266 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1267 GlMisc.pop_attrib
();
1272 let lw = conf.winw
- state.scrollw
- x in
1275 let lh = conf.winh
- y in
1278 Gl.enable `texture_2d
;
1279 begin match state.texid
with
1281 GlTex.bind_texture `texture_2d id
;
1284 and x1 = float (x+w)
1285 and y1 = float (y+h) in
1287 let tw = float w /. 64.0
1288 and th
= float h /. 64.0 in
1289 let tx0 = float tilex /. 64.0
1290 and ty0
= float tiley /. 64.0 in
1292 and ty1
= ty0
+. th
in
1293 GlDraw.begins `quads
;
1294 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1295 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1296 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1297 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1300 Gl.disable `texture_2d
;
1302 GlDraw.color
(1.0, 1.0, 1.0);
1305 (float (x+w), float (y+h));
1307 if w > 128 && h > fstate.fontsize
+ 10
1309 GlDraw.color
(0.0, 0.0, 0.0);
1312 then (col*conf.tilew
, row*conf.tileh
)
1315 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1322 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1324 let tilevisible1 l
x y =
1326 and ax1
= l
.pagex + l
.pagevw
1328 and ay1
= l
.pagey + l
.pagevh in
1332 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1333 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1335 let rx0 = max
ax0 bx0
1336 and ry0
= max ay0 by0
1337 and rx1
= min ax1
bx1
1338 and ry1
= min ay1 by1
in
1340 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1341 nonemptyintersection
1344 let tilevisible layout n x y =
1345 let rec findpageinlayout = function
1346 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1347 | _
:: rest
-> findpageinlayout rest
1350 findpageinlayout layout
1353 let tileready l
x y =
1354 tilevisible1 l
x y &&
1355 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1358 let tilepage n p
layout =
1359 let rec loop = function
1363 let f col row _ _ _ _ _ _
=
1364 if state.currently
= Idle
1366 match gettileopaque l
col row with
1369 let x = col*conf.tilew
1370 and y = row*conf.tileh
in
1372 let w = l
.pagew
- x in
1376 let h = l
.pageh
- y in
1379 wcmd "tile %s %d %d %d %d" p
x y w h;
1382 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1383 conf.tilew
, conf.tileh
1392 if nogeomcmds state.geomcmds
1396 let preloadlayout visiblepages
=
1397 let presentation = conf.presentation in
1398 let interpagespace = conf.interpagespace in
1399 let maxy = state.maxy in
1400 conf.presentation <- false;
1401 conf.interpagespace <- 0;
1402 state.maxy <- calcheight ();
1404 match visiblepages
with
1406 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1408 let y = if y < conf.winh
then 0 else y - conf.winh
in
1409 let h = state.y - y + conf.winh
*3 in
1410 let pages = layout y h in
1411 conf.presentation <- presentation;
1412 conf.interpagespace <- interpagespace;
1418 let rec loop pages =
1419 if state.currently
!= Idle
1424 begin match getopaque l
.pageno
with
1426 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1427 state.currently
<- Loading
(l
, state.gen
);
1429 tilepage l
.pageno opaque
pages;
1434 if nogeomcmds state.geomcmds
1440 if conf.preload && state.currently
= Idle
1441 then load (preloadlayout pages);
1444 let layoutready layout =
1445 let rec fold all ls
=
1446 all
&& match ls
with
1448 let seen = ref false in
1449 let allvisible = ref true in
1450 let foo col row _ _ _ _ _ _
=
1452 allvisible := !allvisible &&
1453 begin match gettileopaque l
col row with
1459 fold (!seen && !allvisible) rest
1462 let alltilesvisible = fold true layout in
1467 let y = bound y 0 state.maxy in
1468 let y, layout, proceed
=
1469 match conf.maxwait
with
1470 | Some time
when state.ghyll
== noghyll ->
1471 begin match state.throttle
with
1473 let layout = layout y conf.winh
in
1474 let ready = layoutready layout in
1478 state.throttle
<- Some
(layout, y, now ());
1480 else G.postRedisplay "gotoy showall (None)";
1482 | Some
(_
, _
, started
) ->
1483 let dt = now () -. started
in
1486 state.throttle
<- None
;
1487 let layout = layout y conf.winh
in
1489 G.postRedisplay "maxwait";
1496 let layout = layout y conf.winh
in
1497 if true || layoutready layout
1498 then G.postRedisplay "gotoy ready";
1504 state.layout <- layout;
1505 begin match state.mode
with
1506 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1507 let rec loop = function
1509 state.mode
<- LinkNav
(Ltgendir
0)
1510 | l
:: _
when l
.pageno
= pageno
->
1511 begin match getopaque pageno
with
1513 state.mode
<- LinkNav
(Ltgendir
0)
1515 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1516 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1517 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1518 then state.mode
<- LinkNav
(Ltgendir
0)
1520 | _
:: rest
-> loop rest
1525 begin match state.mode
with
1526 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1527 if not
(pagevisible layout pageno
)
1529 match state.layout with
1532 state.mode
<- Birdseye
(
1533 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1536 | LinkNav
(Ltgendir dir
as lt
) ->
1538 let rec loop = function
1541 match getopaque l
.pageno
with
1547 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1549 if dir
> 0 then LDfirst
else LDlast
1555 | Lnotfound
-> loop rest
1557 showlinktype (getlink opaque
n);
1558 Ltexact
(l
.pageno
, n)
1562 state.mode
<- LinkNav
linknav
1567 state.ghyll
<- noghyll;
1570 let mx, my
= state.mpos
in
1575 let conttiling pageno opaque
=
1576 tilepage pageno opaque
1577 (if conf.preload then preloadlayout state.layout else state.layout)
1580 let gotoy_and_clear_text y =
1581 if not
conf.verbose
then state.text <- "";
1586 match state.layout with
1588 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1591 let getanchory (n, top
) =
1592 let y, h = getpageyh n in
1593 y + (truncate
(top
*. float h));
1596 let gotoanchor anchor
=
1597 gotoy (getanchory anchor
);
1601 cbput state.hists
.nav
(getanchor ());
1605 let anchor = cbgetc state.hists
.nav dir
in
1610 let rec scroll f n a b =
1611 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1613 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1615 then s (float f /. float a)
1618 then 1.0 -. s ((float (f-b) /. float (n-b)))
1625 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1626 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1628 let ins = float a *. iv1
1629 and outs
= float (n-b) *. iv1 in
1631 ins +. outs
+. float ones
1633 let rec set (_N
, _A
, _B
) y sy
=
1634 let sum = summa
1.0 _N _A _B
in
1635 let dy = float (y - sy
) in
1639 then state.ghyll
<- noghyll
1642 let s = scroll n _N _A _B
in
1643 let y1 = y1 +. ((s *. dy) /. sum) in
1644 gotoy_and_clear_text (truncate
y1);
1645 state.ghyll
<- gf (n+1) y1;
1649 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1651 gf 0 (float state.y)
1654 match conf.ghyllscroll
with
1656 gotoy_and_clear_text y
1658 if state.ghyll
== noghyll
1659 then set nab
y state.y
1660 else state.ghyll
(Some
y)
1663 let gotopage n top
=
1664 let y, h = getpageyh n in
1665 let y = y + (truncate
(top
*. float h)) in
1669 let gotopage1 n top
=
1670 let y = getpagey n in
1675 let invalidate s f =
1680 match state.geomcmds
with
1681 | ps
, [] when String.length ps
= 0 ->
1683 state.geomcmds
<- s, [];
1686 state.geomcmds
<- ps
, [s, f];
1688 | ps
, (s'
, _
) :: rest
when s'
= s ->
1689 state.geomcmds
<- ps
, ((s, f) :: rest
);
1692 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1695 let opendoc path password
=
1697 state.password
<- password
;
1698 state.gen
<- state.gen
+ 1;
1699 state.docinfo
<- [];
1701 setaalevel
conf.aalevel
;
1702 Wsi.settitle
("llpp " ^
Filename.basename path
);
1703 wcmd "open %s\000%s\000" path password
;
1704 invalidate "reqlayout"
1706 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1710 let c = c *. conf.colorscale
in
1714 let scalecolor2 (r
, g
, b) =
1715 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1719 let docolumns = function
1721 | Some
((columns
, coverA
, coverB
), _
) ->
1722 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1723 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1724 if pageno
= state.pagecount
1727 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1729 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1730 pdimno+1, pdim
, rest
1735 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1737 (conf.winw
- state.scrollw
- w) / 2,
1738 y + rowh
+ conf.interpagespace, h
1741 if (pageno
- coverA
) mod columns
= 0
1742 then 0, y + rowh
+ conf.interpagespace, h
1743 else x, y, max rowh
h
1746 let rec fixrow m
= if m
= pageno
then () else
1747 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1750 let y = y + (rowh
- h) / 2 in
1751 a.(m
) <- (pdimno, x, y, pdim
);
1755 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1756 then fixrow (pageno
- columns
);
1757 a.(pageno
) <- (pdimno, x, y, pdim
);
1758 let x = x + w + xoff*2 + conf.interpagespace in
1759 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1761 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1762 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1764 docolumns conf.columns
;
1765 state.maxy <- calcheight ();
1767 if state.w <= conf.winw
- state.scrollw
1771 match state.mode
with
1772 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1773 let y, h = getpageyh pageno
in
1774 let top = (conf.winh
- h) / 2 in
1775 gotoy (max
0 (y - top))
1776 | _
-> gotoanchor state.anchor
1780 GlDraw.viewport
0 0 w h;
1781 if state.geomcmds
!= firstgeomcmds && nogeomcmds state.geomcmds
1782 then state.anchor <- getanchor ();
1785 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1788 setfontsize fstate.fontsize
;
1789 GlMat.mode `modelview
;
1790 GlMat.load_identity
();
1792 GlMat.mode `projection
;
1793 GlMat.load_identity
();
1794 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1795 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1796 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1801 else float state.x /. float state.w
1803 invalidate "geometry"
1806 state.x <- truncate
(relx *. float w);
1808 match conf.columns
with
1810 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1812 wcmd "geometry %d %d" w h);
1816 let len = String.length
state.text in
1819 match state.mode
with
1821 | View
-> state.hscrollh
1826 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1827 (x+.w, float (conf.winh
- hscrollh))
1830 let w = float (conf.winw
- state.scrollw
- 1) in
1831 if state.progress
>= 0.0 && state.progress
< 1.0
1833 GlDraw.color
(0.3, 0.3, 0.3);
1834 let w1 = w *. state.progress
in
1836 GlDraw.color
(0.0, 0.0, 0.0);
1840 GlDraw.color
(0.0, 0.0, 0.0);
1844 GlDraw.color
(1.0, 1.0, 1.0);
1845 drawstring fstate.fontsize
1846 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1849 match state.mode
with
1850 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1854 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1856 Printf.sprintf
"%s%s_" prefix
text
1865 if not
(istextentry state.mode
)
1867 let s1 = "(press 'e' to review error messasges)" in
1868 if String.length
s > 0 then s ^
" " ^
s1 else s1
1873 if String.length
s > 0
1878 let len = Queue.length
state.tilelru
in
1880 if state.memused
<= conf.memlimit
1885 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1886 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1887 let (_
, pw
, ph
, _
) = getpagedim n in
1890 && colorspace
= conf.colorspace
1891 && angle
= conf.angle
1896 match state.throttle
with
1899 then preloadlayout state.layout
1901 | Some
(layout, _
, _
) ->
1904 let x = col*conf.tilew
1905 and y = row*conf.tileh
in
1906 tilevisible layout n x y
1908 then Queue.push lruitem
state.tilelru
1910 wcmd "freetile %s" p
;
1911 state.memused
<- state.memused
- s;
1912 state.uioh#infochanged Memused
;
1913 Hashtbl.remove
state.tilemap k
;
1922 Queue.iter
(fun (k
, p
, s) ->
1923 wcmd "freetile %s" p
;
1924 state.memused
<- state.memused
- s;
1925 state.uioh#infochanged Memused
;
1926 Hashtbl.remove
state.tilemap k
;
1928 Queue.clear
state.tilelru
;
1932 let logcurrently = function
1933 | Idle
-> dolog "Idle"
1934 | Loading
(l
, gen
) ->
1935 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1936 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1938 "Tiling %d[%d,%d] page=%s cs=%s angle"
1939 l
.pageno
col row pageopaque
1940 (colorspace_to_string colorspace
)
1942 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1943 angle gen
conf.angle
state.gen
1945 conf.tilew
conf.tileh
1952 (* dolog "%S" cmds; *)
1955 try String.index cmds ' '
1956 with Not_found
-> -1
1961 let l = String.length cmds
in
1962 let op = String.sub cmds
0 spacepos in
1964 if l - spacepos < 2 then ""
1965 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1970 state.uioh#infochanged Pdim
;
1974 state.rects
<- state.rects1
;
1975 G.postRedisplay "clearrects";
1979 try Scanf.sscanf
args "%u" (fun n -> n)
1981 dolog "error processing 'continue' %S: %s"
1982 cmds
(Printexc.to_string exn
);
1985 state.pagecount
<- n;
1986 begin match state.currently
with
1988 state.currently
<- Idle
;
1989 state.outlines
<- Array.of_list
(List.rev
l)
1993 let cur, cmds
= state.geomcmds
in
1994 if String.length
cur = 0
1995 then failwith
"umpossible";
1997 begin match List.rev cmds
with
1999 state.geomcmds
<- "", [];
2003 state.geomcmds
<- s, List.rev rest
;
2005 if conf.maxwait
= None
2006 then G.postRedisplay "continue";
2016 then showtext ' '
args
2019 let progress, text =
2021 Scanf.sscanf
args "%f %n"
2023 f, String.sub
args pos
(String.length
args - pos
))
2025 dolog "error processing 'progress' %S: %s"
2026 cmds
(Printexc.to_string exn
);
2030 state.progress <- progress;
2031 G.postRedisplay "progress"
2034 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2036 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2037 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2038 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2040 dolog "error processing 'firstmatch' %S: %s"
2041 cmds
(Printexc.to_string exn
);
2044 let y = (getpagey pageno) + truncate
y0 in
2047 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2050 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2052 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2053 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2054 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2056 dolog "error processing 'match' %S: %s"
2057 cmds
(Printexc.to_string exn
);
2061 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2066 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2068 dolog "error processing 'page' %S: %s"
2069 cmds
(Printexc.to_string exn
);
2072 begin match state.currently
with
2073 | Loading
(l, gen
) ->
2074 vlog "page %d took %f sec" l.pageno t
;
2075 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2076 begin match state.throttle
with
2078 let preloadedpages =
2080 then preloadlayout state.layout
2085 Set.Make
(struct type t
= int let compare = (-) end) in
2087 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2088 IntSet.empty
preloadedpages
2091 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2092 if not
(IntSet.mem
pageno set)
2094 wcmd "freepage %s" opaque
;
2100 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2103 state.currently
<- Idle
;
2106 tilepage l.pageno pageopaque state.layout;
2108 load preloadedpages;
2109 if pagevisible state.layout l.pageno
2110 && layoutready state.layout
2111 then G.postRedisplay "page";
2114 | Some
(layout, _
, _
) ->
2115 state.currently
<- Idle
;
2116 tilepage l.pageno pageopaque layout;
2121 dolog "Inconsistent loading state";
2122 logcurrently state.currently
;
2127 let (x, y, opaque
, size
, t
) =
2129 Scanf.sscanf
args "%u %u %s %u %f"
2130 (fun x y p size t
-> (x, y, p
, size
, t
))
2132 dolog "error processing 'tile' %S: %s"
2133 cmds
(Printexc.to_string exn
);
2136 begin match state.currently
with
2137 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2138 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2140 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2142 wcmd "freetile %s" opaque
;
2143 state.currently
<- Idle
;
2147 puttileopaque l col row gen cs angle opaque size t
;
2148 state.memused
<- state.memused
+ size
;
2149 state.uioh#infochanged Memused
;
2151 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2152 opaque
, size
) state.tilelru
;
2155 match state.throttle
with
2156 | None
-> state.layout
2157 | Some
(layout, _
, _
) -> layout
2160 state.currently
<- Idle
;
2162 && conf.colorspace
= cs
2163 && conf.angle
= angle
2164 && tilevisible layout l.pageno x y
2165 then conttiling l.pageno pageopaque;
2167 begin match state.throttle
with
2169 preload state.layout;
2171 && conf.colorspace
= cs
2172 && conf.angle
= angle
2173 && tilevisible state.layout l.pageno x y
2174 then G.postRedisplay "tile nothrottle";
2176 | Some
(layout, y, _
) ->
2177 let ready = layoutready layout in
2181 state.layout <- layout;
2182 state.throttle
<- None
;
2183 G.postRedisplay "throttle";
2190 dolog "Inconsistent tiling state";
2191 logcurrently state.currently
;
2198 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2200 dolog "error processing 'pdim' %S: %s"
2201 cmds
(Printexc.to_string exn
);
2204 state.uioh#infochanged Pdim
;
2205 state.pdims
<- pdim :: state.pdims
2208 let (l, n, t
, h, pos
) =
2210 Scanf.sscanf
args "%u %u %d %u %n"
2211 (fun l n t
h pos
-> l, n, t
, h, pos
)
2213 dolog "error processing 'o' %S: %s"
2214 cmds
(Printexc.to_string exn
);
2217 let s = String.sub
args pos
(String.length
args - pos
) in
2218 let outline = (s, l, (n, float t
/. float h)) in
2219 begin match state.currently
with
2220 | Outlining outlines
->
2221 state.currently
<- Outlining
(outline :: outlines
)
2223 state.currently
<- Outlining
[outline]
2225 dolog "invalid outlining state";
2226 logcurrently currently
2230 state.docinfo
<- (1, args) :: state.docinfo
2233 state.uioh#infochanged Docinfo
;
2234 state.docinfo
<- List.rev
state.docinfo
2237 dolog "unknown cmd `%S'" cmds
2242 let action = function
2243 | HCprev
-> cbget cb ~
-1
2244 | HCnext
-> cbget cb
1
2245 | HCfirst
-> cbget cb ~
-(cb
.rc)
2246 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2247 and cancel
() = cb
.rc <- rc
2251 let search pattern forward
=
2252 if String.length pattern
> 0
2255 match state.layout with
2258 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2260 wcmd "search %d %d %d %d,%s\000"
2261 (btod conf.icase
) pn py (btod forward
) pattern
;
2264 let intentry text key =
2266 if key >= 32 && key < 127
2272 let text = addchar text c in
2276 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2280 let textentry text key =
2281 if key land 0xff00 = 0xff00
2283 else TEcont
(text ^
Wsi.toutf8
key)
2286 let reqlayout angle proportional
=
2287 match state.throttle
with
2289 if nogeomcmds state.geomcmds
2290 then state.anchor <- getanchor ();
2291 conf.angle
<- angle
mod 360;
2294 match state.mode
with
2295 | LinkNav _
-> state.mode
<- View
2298 conf.proportional
<- proportional
;
2299 invalidate "reqlayout"
2300 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2304 let settrim trimmargins trimfuzz
=
2305 if nogeomcmds state.geomcmds
2306 then state.anchor <- getanchor ();
2307 conf.trimmargins
<- trimmargins
;
2308 conf.trimfuzz
<- trimfuzz
;
2309 let x0, y0, x1, y1 = trimfuzz
in
2310 invalidate "settrim"
2312 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2313 Hashtbl.iter
(fun _ opaque
->
2314 wcmd "freepage %s" opaque
;
2316 Hashtbl.clear
state.pagemap
;
2320 match state.throttle
with
2322 let zoom = max
0.01 zoom in
2323 if zoom <> conf.zoom
2325 state.prevzoom
<- conf.zoom;
2327 reshape conf.winw
conf.winh
;
2328 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2331 | Some
(layout, y, started
) ->
2333 match conf.maxwait
with
2337 let dt = now () -. started
in
2345 let setcolumns columns coverA coverB
=
2348 conf.columns
<- None
;
2353 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2356 reshape conf.winw
conf.winh
;
2359 let enterbirdseye () =
2360 let zoom = float conf.thumbw
/. float conf.winw
in
2361 let birdseyepageno =
2362 let cy = conf.winh
/ 2 in
2366 let rec fold best
= function
2369 let d = cy - (l.pagedispy + l.pagevh/2)
2370 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2371 if abs
d < abs dbest
2378 state.mode
<- Birdseye
(
2379 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2382 conf.presentation <- false;
2383 conf.interpagespace <- 10;
2384 conf.hlinks
<- false;
2386 state.mstate
<- Mnone
;
2387 conf.maxwait
<- None
;
2389 match conf.beyecolumns
with
2392 Some
((c, 0, 0), [||])
2395 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2398 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2403 reshape conf.winw
conf.winh
;
2406 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2408 conf.zoom <- c.zoom;
2409 conf.presentation <- c.presentation;
2410 conf.interpagespace <- c.interpagespace;
2411 conf.maxwait
<- c.maxwait
;
2412 conf.hlinks
<- c.hlinks
;
2413 conf.beyecolumns
<- (
2414 match conf.columns
with
2415 | Some
((c, _
, _
), _
) -> Some
c
2419 match c.columns
with
2420 | Some
(c, _
) -> Some
(c, [||])
2426 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2429 reshape conf.winw
conf.winh
;
2430 state.anchor <- if goback
then anchor else (pageno, 0.0);
2433 let togglebirdseye () =
2434 match state.mode
with
2435 | Birdseye vals
-> leavebirdseye vals
true
2436 | View
-> enterbirdseye ()
2440 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2441 let pageno = max
0 (pageno - incr
) in
2442 let rec loop = function
2443 | [] -> gotopage1 pageno 0
2444 | l :: _
when l.pageno = pageno ->
2445 if l.pagedispy >= 0 && l.pagey = 0
2446 then G.postRedisplay "upbirdseye"
2447 else gotopage1 pageno 0
2448 | _
:: rest
-> loop rest
2451 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2454 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2455 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2456 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2457 let rec loop = function
2459 let y, h = getpageyh pageno in
2460 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2462 | l :: _
when l.pageno = pageno ->
2463 if l.pagevh != l.pageh
2464 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2465 else G.postRedisplay "downbirdseye"
2466 | _
:: rest
-> loop rest
2471 let optentry mode _
key =
2472 let btos b = if b then "on" else "off" in
2473 if key >= 32 && key < 127
2475 let c = Char.chr
key in
2479 try conf.scrollstep
<- int_of_string
s with exc
->
2480 state.text <- Printf.sprintf
"bad integer `%s': %s"
2481 s (Printexc.to_string exc
)
2483 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2488 conf.autoscrollstep
<- int_of_string
s;
2489 if state.autoscroll
<> None
2490 then state.autoscroll
<- Some
conf.autoscrollstep
2492 state.text <- Printf.sprintf
"bad integer `%s': %s"
2493 s (Printexc.to_string exc
)
2495 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2500 let n, a, b = columns_of_string s in
2503 state.text <- Printf.sprintf
"bad columns `%s': %s"
2504 s (Printexc.to_string exc
)
2506 TEswitch
("columns: ", "", None
, textentry, ondone)
2511 let zoom = float (int_of_string
s) /. 100.0 in
2514 state.text <- Printf.sprintf
"bad integer `%s': %s"
2515 s (Printexc.to_string exc
)
2517 TEswitch
("zoom: ", "", None
, intentry, ondone)
2522 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2524 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2525 begin match mode
with
2527 leavebirdseye beye
false;
2532 state.text <- Printf.sprintf
"bad integer `%s': %s"
2533 s (Printexc.to_string exc
)
2535 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2540 Some
(int_of_string
s)
2542 state.text <- Printf.sprintf
"bad integer `%s': %s"
2543 s (Printexc.to_string exc
);
2546 | Some angle
-> reqlayout angle
conf.proportional
2549 TEswitch
("rotation: ", "", None
, intentry, ondone)
2552 conf.icase
<- not
conf.icase
;
2553 TEdone
("case insensitive search " ^
(btos conf.icase
))
2556 conf.preload <- not
conf.preload;
2558 TEdone
("preload " ^
(btos conf.preload))
2561 conf.verbose
<- not
conf.verbose
;
2562 TEdone
("verbose " ^
(btos conf.verbose
))
2565 conf.debug
<- not
conf.debug
;
2566 TEdone
("debug " ^
(btos conf.debug
))
2569 conf.maxhfit
<- not
conf.maxhfit
;
2571 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2572 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2575 conf.crophack
<- not
conf.crophack
;
2576 TEdone
("crophack " ^
btos conf.crophack
)
2580 match conf.maxwait
with
2582 conf.maxwait
<- Some infinity
;
2583 "always wait for page to complete"
2585 conf.maxwait
<- None
;
2586 "show placeholder if page is not ready"
2591 conf.underinfo
<- not
conf.underinfo
;
2592 TEdone
("underinfo " ^
btos conf.underinfo
)
2595 conf.savebmarks
<- not
conf.savebmarks
;
2596 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2602 match state.layout with
2607 conf.interpagespace <- int_of_string
s;
2608 state.maxy <- calcheight ();
2609 let y = getpagey pageno in
2612 state.text <- Printf.sprintf
"bad integer `%s': %s"
2613 s (Printexc.to_string exc
)
2615 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2618 reqlayout conf.angle
(not
conf.proportional
);
2619 TEdone
("proportional display " ^
btos conf.proportional
)
2622 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2623 TEdone
("trim margins " ^
btos conf.trimmargins
)
2626 conf.invert
<- not
conf.invert
;
2627 TEdone
("invert colors " ^
btos conf.invert
)
2631 cbput state.hists
.sel
s;
2634 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2638 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2644 class type lvsource
= object
2645 method getitemcount
: int
2646 method getitem
: int -> (string * int)
2647 method hasaction
: int -> bool
2656 method getactive
: int
2657 method getfirst
: int
2658 method getqsearch
: string
2659 method setqsearch
: string -> unit
2663 class virtual lvsourcebase
= object
2664 val mutable m_active
= 0
2665 val mutable m_first
= 0
2666 val mutable m_qsearch
= ""
2667 val mutable m_pan
= 0
2668 method getactive
= m_active
2669 method getfirst
= m_first
2670 method getqsearch
= m_qsearch
2671 method getpan
= m_pan
2672 method setqsearch
s = m_qsearch
<- s
2675 let withoutlastutf8 s =
2676 let len = String.length
s in
2684 let b = Char.code
s.[pos
] in
2685 if b land 0b110000 = 0b11000000
2690 if Char.code
s.[len-1] land 0x80 = 0
2694 String.sub
s 0 first;
2697 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2699 state.mode
<- Textentry
(te
, onleave
);
2702 G.postRedisplay "textentrykeyboard enttext";
2704 let histaction cmd
=
2707 | Some
(action, _
) ->
2708 state.mode
<- Textentry
(
2709 (c, action cmd
, opthist
, onkey
, ondone), onleave
2711 G.postRedisplay "textentry histaction"
2714 | 0xff08 -> (* backspace *)
2715 let s = withoutlastutf8 text in
2716 let len = String.length
s in
2720 G.postRedisplay "textentrykeyboard after cancel";
2723 enttext (c, s, opthist
, onkey
, ondone)
2729 G.postRedisplay "textentrykeyboard after confirm"
2731 | 0xff52 -> histaction HCprev
2732 | 0xff54 -> histaction HCnext
2733 | 0xff50 -> histaction HCfirst
2734 | 0xff57 -> histaction HClast
2736 | 0xff1b -> (* escape*)
2737 if String.length
text = 0
2739 begin match opthist
with
2741 | Some
(_
, onhistcancel
) -> onhistcancel
()
2745 G.postRedisplay "textentrykeyboard after cancel2"
2748 enttext (c, "", opthist
, onkey
, ondone)
2751 | 0xff9f | 0xffff -> () (* delete *)
2753 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2754 begin match onkey
text key with
2758 G.postRedisplay "textentrykeyboard after confirm2";
2761 enttext (c, text, opthist
, onkey
, ondone);
2765 G.postRedisplay "textentrykeyboard after cancel3"
2768 state.mode
<- Textentry
(te
, onleave
);
2769 G.postRedisplay "textentrykeyboard switch";
2773 vlog "unhandled key %s" (Wsi.keyname
key)
2776 let firstof first active
=
2777 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2778 then max
0 (active
- (fstate.maxrows
/2))
2782 let calcfirst first active
=
2785 let rows = active
- first in
2786 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2790 let scrollph y maxy =
2791 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2792 let sh = float conf.winh
/. sh in
2793 let sh = max
sh (float conf.scrollh
) in
2798 else float y /. float maxy
2800 let position = (float conf.winh
-. sh) *. percent in
2803 if position +. sh > float conf.winh
2804 then float conf.winh
-. sh
2810 let coe s = (s :> uioh
);;
2812 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2814 val m_pan
= source#getpan
2815 val m_first
= source#getfirst
2816 val m_active
= source#getactive
2817 val m_qsearch
= source#getqsearch
2818 val m_prev_uioh
= state.uioh
2820 method private elemunder
y =
2821 let n = y / (fstate.fontsize
+1) in
2822 if m_first
+ n < source#getitemcount
2824 if source#hasaction
(m_first
+ n)
2825 then Some
(m_first
+ n)
2832 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2833 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2834 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2835 GlDraw.color
(1., 1., 1.);
2836 Gl.enable `texture_2d
;
2837 let fs = fstate.fontsize
in
2839 let ww = fstate.wwidth
in
2840 let tabw = 30.0*.ww in
2841 let itemcount = source#getitemcount
in
2843 if (row - m_first
) * nfs > conf.winh
2846 if row >= 0 && row < itemcount
2848 let (s, level
) = source#getitem
row in
2849 let y = (row - m_first
) * nfs in
2850 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2853 Gl.disable `texture_2d
;
2854 GlDraw.polygon_mode `both `line
;
2855 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2856 GlDraw.rect (1., float (y + 1))
2857 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2858 GlDraw.polygon_mode `both `fill
;
2859 GlDraw.color
(1., 1., 1.);
2860 Gl.enable `texture_2d
;
2863 let drawtabularstring s =
2864 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2867 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2870 let len = String.length
s - tabpos - 1 in
2871 let s1 = String.sub
s 0 tabpos
2872 and s2
= String.sub
s (tabpos + 1) len in
2873 let nx = drawstr x s1 in
2875 let x = x +. (max
tabw sw) in
2882 let _ = drawtabularstring s in
2889 Gl.disable `texture_2d
;
2891 method updownlevel incr
=
2892 let len = source#getitemcount
in
2894 if m_active
>= 0 && m_active
< len
2895 then snd
(source#getitem m_active
)
2899 if i
= len then i
-1 else if i
= -1 then 0 else
2900 let _, l = source#getitem i
in
2901 if l != curlevel then i
else flow (i
+incr
)
2903 let active = flow m_active
in
2904 let first = calcfirst m_first
active in
2905 G.postRedisplay "outline updownlevel";
2906 {< m_active
= active; m_first
= first >}
2908 method private key1
key mask
=
2909 let set1 active first qsearch
=
2910 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2912 let search active pattern incr
=
2915 if n >= 0 && n < source#getitemcount
2917 let s, _ = source#getitem
n in
2919 (try ignore
(Str.search_forward
re s 0); true
2920 with Not_found
-> false)
2922 else loop (n + incr
)
2929 let re = Str.regexp_case_fold pattern
in
2935 let itemcount = source#getitemcount
in
2936 let find start incr
=
2938 if i
= -1 || i
= itemcount
2941 if source#hasaction i
2943 else find (i
+ incr
)
2948 let set active first =
2949 let first = bound first 0 (itemcount - fstate.maxrows
) in
2951 coe {< m_active
= active; m_first
= first >}
2954 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2956 let incr1 = if incr
> 0 then 1 else -1 in
2957 if isvisible m_first m_active
2960 let next = m_active
+ incr
in
2962 if next < 0 || next >= itemcount
2964 else find next incr1
2966 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2972 let first = m_first
+ incr
in
2973 let first = bound first 0 (itemcount - 1) in
2975 let next = m_active
+ incr
in
2976 let next = bound next 0 (itemcount - 1) in
2979 let active = if next = -1 then m_active
else next in
2982 let first = min
next m_first
in
2984 if abs
(next - first) > fstate.maxrows
2990 let first = m_first
+ incr
in
2991 let first = bound first 0 (itemcount - 1) in
2993 let next = m_active
+ incr
in
2994 let next = bound next 0 (itemcount - 1) in
2995 let next = find next incr1 in
2997 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2999 let active = if m_active
= -1 then next else m_active
in
3004 if isvisible first active
3010 G.postRedisplay "listview navigate";
3014 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3015 let incr = if key = 0x72 then -1 else 1 in
3017 match search (m_active
+ incr) m_qsearch
incr with
3019 state.text <- m_qsearch ^
" [not found]";
3022 state.text <- m_qsearch
;
3023 active, firstof m_first
active
3025 G.postRedisplay "listview ctrl-r/s";
3026 set1 active first m_qsearch
;
3028 | 0xff08 -> (* backspace *)
3029 if String.length m_qsearch
= 0
3032 let qsearch = withoutlastutf8 m_qsearch
in
3033 let len = String.length
qsearch in
3037 G.postRedisplay "listview empty qsearch";
3038 set1 m_active m_first
"";
3042 match search m_active
qsearch ~
-1 with
3044 state.text <- qsearch ^
" [not found]";
3047 state.text <- qsearch;
3048 active, firstof m_first
active
3050 G.postRedisplay "listview backspace qsearch";
3051 set1 active first qsearch
3054 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3055 let pattern = m_qsearch ^
Wsi.toutf8
key in
3057 match search m_active
pattern 1 with
3059 state.text <- pattern ^
" [not found]";
3062 state.text <- pattern;
3063 active, firstof m_first
active
3065 G.postRedisplay "listview qsearch add";
3066 set1 active first pattern;
3068 | 0xff1b -> (* escape *)
3070 if String.length m_qsearch
= 0
3072 G.postRedisplay "list view escape";
3075 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3077 | None
-> m_prev_uioh
3082 G.postRedisplay "list view kill qsearch";
3083 source#setqsearch
"";
3084 coe {< m_qsearch
= "" >}
3087 | 0xff0d -> (* return *)
3089 let self = {< m_qsearch
= "" >} in
3090 source#setqsearch
"";
3092 G.postRedisplay "listview enter";
3093 if m_active
>= 0 && m_active
< source#getitemcount
3095 source#exit
(coe self) false m_active m_first m_pan
"";
3098 source#exit
(coe self) true m_active m_first m_pan
"";
3101 begin match opt with
3102 | None
-> m_prev_uioh
3106 | 0xff9f | 0xffff -> (* delete *)
3109 | 0xff52 -> navigate ~
-1 (* up *)
3110 | 0xff54 -> navigate 1 (* down *)
3111 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3112 | 0xff56 -> navigate fstate.maxrows
(* next *)
3114 | 0xff53 -> (* right *)
3116 G.postRedisplay "listview right";
3117 coe {< m_pan
= m_pan
- 1 >}
3119 | 0xff51 -> (* left *)
3121 G.postRedisplay "listview left";
3122 coe {< m_pan
= m_pan
+ 1 >}
3124 | 0xff50 -> (* home *)
3125 let active = find 0 1 in
3126 G.postRedisplay "listview home";
3129 | 0xff57 -> (* end *)
3130 let first = max
0 (itemcount - fstate.maxrows
) in
3131 let active = find (itemcount - 1) ~
-1 in
3132 G.postRedisplay "listview end";
3135 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3139 dolog "listview unknown key %#x" key; coe self
3141 method key key mask
=
3142 match state.mode
with
3143 | Textentry te
-> textentrykeyboard key mask te
; coe self
3144 | _ -> self#key1
key mask
3146 method button button down
x y _ =
3149 | 1 when x > conf.winw
- conf.scrollbw
->
3150 G.postRedisplay "listview scroll";
3153 let _, position, sh = self#
scrollph in
3154 if y > truncate
position && y < truncate
(position +. sh)
3156 state.mstate
<- Mscrolly
;
3160 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3161 let first = truncate
(s *. float source#getitemcount
) in
3162 let first = min source#getitemcount
first in
3163 Some
(coe {< m_first
= first; m_active
= first >})
3165 state.mstate
<- Mnone
;
3168 | 1 when not down
->
3169 begin match self#elemunder
y with
3171 G.postRedisplay "listview click";
3173 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3177 | n when (n == 4 || n == 5) && not down
->
3178 let len = source#getitemcount
in
3180 if n = 5 && m_first
+ fstate.maxrows
>= len
3184 let first = m_first
+ (if n == 4 then -1 else 1) in
3185 bound first 0 (len - 1)
3187 G.postRedisplay "listview wheel";
3188 Some
(coe {< m_first
= first >})
3193 | None
-> m_prev_uioh
3197 match state.mstate
with
3199 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3200 let first = truncate
(s *. float source#getitemcount
) in
3201 let first = min source#getitemcount
first in
3202 G.postRedisplay "listview motion";
3203 coe {< m_first
= first; m_active
= first >}
3206 method pmotion
x y =
3207 if x < conf.winw
- conf.scrollbw
3210 match self#elemunder
y with
3211 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3212 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3216 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3221 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3225 method infochanged
_ = ()
3227 method scrollpw
= (0, 0.0, 0.0)
3229 let nfs = fstate.fontsize
+ 1 in
3230 let y = m_first
* nfs in
3231 let itemcount = source#getitemcount
in
3232 let maxi = max
0 (itemcount - fstate.maxrows
) in
3233 let maxy = maxi * nfs in
3234 let p, h = scrollph y maxy in
3237 method modehash
= modehash
3240 class outlinelistview ~source
=
3243 ~source
:(source
:> lvsource
)
3245 ~modehash
:(findkeyhash conf "outline")
3248 method key key mask
=
3249 let calcfirst first active =
3252 let rows = active - first in
3253 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3257 let active = m_active
+ incr in
3258 let active = bound active 0 (source#getitemcount
- 1) in
3259 let first = calcfirst m_first
active in
3260 G.postRedisplay "outline navigate";
3261 coe {< m_active
= active; m_first
= first >}
3263 let ctrl = Wsi.withctrl mask
in
3265 | 110 when ctrl -> (* ctrl-n *)
3266 source#narrow m_qsearch
;
3267 G.postRedisplay "outline ctrl-n";
3268 coe {< m_first
= 0; m_active
= 0 >}
3270 | 117 when ctrl -> (* ctrl-u *)
3272 G.postRedisplay "outline ctrl-u";
3274 coe {< m_first
= 0; m_active
= 0 >}
3276 | 108 when ctrl -> (* ctrl-l *)
3277 let first = m_active
- (fstate.maxrows
/ 2) in
3278 G.postRedisplay "outline ctrl-l";
3279 coe {< m_first
= first >}
3281 | 0xff9f | 0xffff -> (* delete *)
3282 source#remove m_active
;
3283 G.postRedisplay "outline delete";
3284 let active = max
0 (m_active
-1) in
3285 coe {< m_first
= firstof m_first
active;
3286 m_active
= active >}
3288 | 0xff52 -> navigate ~
-1 (* up *)
3289 | 0xff54 -> navigate 1 (* down *)
3290 | 0xff55 -> (* prior *)
3291 navigate ~
-(fstate.maxrows
)
3292 | 0xff56 -> (* next *)
3293 navigate fstate.maxrows
3295 | 0xff53 -> (* [ctrl-]right *)
3299 G.postRedisplay "outline ctrl right";
3300 {< m_pan
= m_pan
+ 1 >}
3302 else self#updownlevel
1
3306 | 0xff51 -> (* [ctrl-]left *)
3310 G.postRedisplay "outline ctrl left";
3311 {< m_pan
= m_pan
- 1 >}
3313 else self#updownlevel ~
-1
3317 | 0xff50 -> (* home *)
3318 G.postRedisplay "outline home";
3319 coe {< m_first
= 0; m_active
= 0 >}
3321 | 0xff57 -> (* end *)
3322 let active = source#getitemcount
- 1 in
3323 let first = max
0 (active - fstate.maxrows
) in
3324 G.postRedisplay "outline end";
3325 coe {< m_active
= active; m_first
= first >}
3327 | _ -> super#
key key mask
3330 let outlinesource usebookmarks
=
3333 inherit lvsourcebase
3334 val mutable m_items
= empty
3335 val mutable m_orig_items
= empty
3336 val mutable m_prev_items
= empty
3337 val mutable m_narrow_pattern
= ""
3338 val mutable m_hadremovals
= false
3340 method getitemcount
=
3341 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3344 if n == Array.length m_items
&& m_hadremovals
3346 ("[Confirm removal]", 0)
3348 let s, n, _ = m_items
.(n) in
3351 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3352 ignore
(uioh
, first, qsearch);
3353 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3355 if String.length m_narrow_pattern
= 0
3361 if not
confrimremoval
3363 let _, _, anchor = m_items
.(active) in
3368 state.bookmarks
<- Array.to_list m_items
;
3369 m_orig_items
<- m_items
;
3372 else m_items
<- items;
3376 method hasaction
_ = true
3379 if Array.length m_items
!= Array.length m_orig_items
3380 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3383 method narrow
pattern =
3384 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3388 let rec loop accu n =
3391 m_narrow_pattern
<- pattern;
3392 m_items
<- Array.of_list
accu
3395 let (s, _, _) as o = m_items
.(n) in
3397 if (try ignore
(Str.search_forward
re s 0); true
3398 with Not_found
-> false)
3404 loop [] (Array.length m_items
- 1)
3409 then Array.of_list
state.bookmarks
3412 m_items
<- m_orig_items
3417 if m
>= 0 && m
< Array.length m_items
3419 m_hadremovals
<- true;
3420 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3421 let n = if n >= m
then n+1 else n in
3426 method reset
anchor items =
3427 m_hadremovals
<- false;
3428 if m_orig_items
== empty || m_prev_items
!= items
3430 m_orig_items
<- items;
3431 if String.length m_narrow_pattern
= 0
3432 then m_items
<- items;
3434 m_prev_items
<- items;
3435 let rely = getanchory anchor in
3437 let rec loop n best bestd
=
3438 if n = Array.length m_items
3441 let (_, _, anchor) = m_items
.(n) in
3442 let orely = getanchory anchor in
3443 let d = abs
(orely - rely) in
3446 else loop (n+1) best bestd
3451 m_first
<- firstof m_first
active
3455 let enterselector usebookmarks
=
3456 let source = outlinesource usebookmarks
in
3460 then Array.of_list
state.bookmarks
3463 if Array.length
outlines = 0
3465 showtext ' ' errmsg
;
3468 state.text <- source#greetmsg
;
3469 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3470 let anchor = getanchor () in
3471 source#reset
anchor outlines;
3472 state.uioh
<- coe (new outlinelistview ~
source);
3473 G.postRedisplay "enter selector";
3477 let enteroutlinemode =
3478 let f = enterselector false in
3479 fun ()-> f "Document has no outline";
3482 let enterbookmarkmode =
3483 let f = enterselector true in
3484 fun () -> f "Document has no bookmarks (yet)";
3487 let color_of_string s =
3488 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3489 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3493 let color_to_string (r
, g
, b) =
3494 let r = truncate
(r *. 256.0)
3495 and g
= truncate
(g
*. 256.0)
3496 and b = truncate
(b *. 256.0) in
3497 Printf.sprintf
"%d/%d/%d" r g
b
3500 let irect_of_string s =
3501 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3504 let irect_to_string (x0,y0,x1,y1) =
3505 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3508 let makecheckers () =
3509 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3511 converted by Issac Trotts. July 25, 2002 *)
3512 let image_height = 64
3513 and image_width
= 64 in
3517 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3519 for i
= 0 to image_width
- 1 do
3520 for j
= 0 to image_height - 1 do
3521 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3522 (if (i
land 8 ) lxor (j
land 8) = 0
3523 then [|255;255;255|] else [|200;200;200|])
3528 let image = make_image () in
3529 let id = GlTex.gen_texture
() in
3530 GlTex.bind_texture `texture_2d
id;
3531 GlPix.store
(`unpack_alignment
1);
3532 GlTex.image2d
image;
3533 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3536 `mag_filter `nearest
;
3537 `min_filter `nearest
];
3541 let setcheckers enabled
=
3542 match state.texid
with
3544 if enabled
then state.texid
<- Some
(makecheckers ())
3549 GlTex.delete_texture texid
;
3550 state.texid
<- None
;
3554 let int_of_string_with_suffix s =
3555 let l = String.length
s in
3559 let suffix = Char.lowercase
s.[l-1] in
3561 | 'k'
-> String.sub
s 0 (l-1), 10
3562 | 'm'
-> String.sub
s 0 (l-1), 20
3563 | 'g'
-> String.sub
s 0 (l-1), 30
3567 let n = int_of_string
s1 in
3568 let m = n lsl shift
in
3570 then raise
(Failure
"value too large")
3574 let string_with_suffix_of_int n =
3582 if n land ((1 lsl 20) - 1) = 0
3585 if n land ((1 lsl 10) - 1) = 0
3592 let h = n mod 1000 in
3595 then string_of_int
h ^
s
3597 let s = Printf.sprintf
"_%03d%s" h s in
3604 let defghyllscroll = (40, 8, 32);;
3605 let ghyllscroll_of_string s =
3606 let (n, a, b) as nab
=
3609 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3611 if n <= a || n <= b || a >= b
3612 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3616 let ghyllscroll_to_string ((n, a, b) as nab
) =
3617 if nab
= defghyllscroll
3619 else Printf.sprintf
"%d,%d,%d" n a b;
3622 let describe_location () =
3624 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3626 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3627 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3631 else (100. *. (float state.y /. float maxy))
3635 Printf.sprintf
"page %d of %d [%.2f%%]"
3636 (fn+1) state.pagecount
percent
3639 "pages %d-%d of %d [%.2f%%]"
3640 (fn+1) (ln
+1) state.pagecount
percent
3644 let btos b = if b then "\xe2\x88\x9a" else "" in
3645 let showextended = ref false in
3646 let leave mode
= function
3647 | Confirm
-> state.mode
<- mode
3648 | Cancel
-> state.mode
<- mode
in
3651 val mutable m_first_time
= true
3652 val mutable m_l
= []
3653 val mutable m_a
= [||]
3654 val mutable m_prev_uioh
= nouioh
3655 val mutable m_prev_mode
= View
3657 inherit lvsourcebase
3659 method reset prev_mode prev_uioh
=
3660 m_a
<- Array.of_list
(List.rev m_l
);
3662 m_prev_mode
<- prev_mode
;
3663 m_prev_uioh
<- prev_uioh
;
3667 if n >= Array.length m_a
3671 | _, _, _, Action
_ -> m_active
<- n
3675 m_first_time
<- false;
3678 method int name get
set =
3680 (name
, `
int get
, 1, Action
(
3683 try set (int_of_string
s)
3685 state.text <- Printf.sprintf
"bad integer `%s': %s"
3686 s (Printexc.to_string exn
)
3689 let te = name ^
": ", "", None
, intentry, ondone in
3690 state.mode
<- Textentry
(te, leave m_prev_mode
);
3694 method int_with_suffix name get
set =
3696 (name
, `intws get
, 1, Action
(
3699 try set (int_of_string_with_suffix s)
3701 state.text <- Printf.sprintf
"bad integer `%s': %s"
3702 s (Printexc.to_string exn
)
3706 name ^
": ", "", None
, intentry_with_suffix, ondone
3708 state.mode
<- Textentry
(te, leave m_prev_mode
);
3712 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3714 (name
, `
bool (btos, get
), offset
, Action
(
3721 method color name get
set =
3723 (name
, `color get
, 1, Action
(
3725 let invalid = (nan
, nan
, nan
) in
3728 try color_of_string s
3730 state.text <- Printf.sprintf
"bad color `%s': %s"
3731 s (Printexc.to_string exn
);
3737 let te = name ^
": ", "", None
, textentry, ondone in
3738 state.text <- color_to_string (get
());
3739 state.mode
<- Textentry
(te, leave m_prev_mode
);
3743 method string name get
set =
3745 (name
, `
string get
, 1, Action
(
3747 let ondone s = set s in
3748 let te = name ^
": ", "", None
, textentry, ondone in
3749 state.mode
<- Textentry
(te, leave m_prev_mode
);
3753 method colorspace name get
set =
3755 (name
, `
string get
, 1, Action
(
3758 let vals = [| "rgb"; "bgr"; "gray" |] in
3760 inherit lvsourcebase
3763 m_active
<- int_of_colorspace conf.colorspace
;
3766 method getitemcount
= Array.length
vals
3767 method getitem
n = (vals.(n), 0)
3768 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3769 ignore
(uioh
, first, pan
, qsearch);
3770 if not cancel
then set active;
3772 method hasaction
_ = true
3776 let modehash = findkeyhash conf "info" in
3777 coe (new listview ~
source ~trusted
:true ~
modehash)
3780 method caption
s offset
=
3781 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3783 method caption2
s f offset
=
3784 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3786 method getitemcount
= Array.length m_a
3789 let tostr = function
3790 | `
int f -> string_of_int
(f ())
3791 | `intws
f -> string_with_suffix_of_int (f ())
3793 | `color
f -> color_to_string (f ())
3794 | `
bool (btos, f) -> btos (f ())
3797 let name, t
, offset
, _ = m_a
.(n) in
3798 ((let s = tostr t
in
3799 if String.length
s > 0
3800 then Printf.sprintf
"%s\t%s" name s
3804 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3808 m_qsearch
<- qsearch;
3810 match m_a
.(active) with
3811 | _, _, _, Action
f -> f uioh
3823 method hasaction
n =
3825 | _, _, _, Action
_ -> true
3829 let rec fillsrc prevmode prevuioh
=
3830 let sep () = src#caption
"" 0 in
3831 let colorp name get
set =
3833 (fun () -> color_to_string (get
()))
3836 let c = color_of_string v in
3839 state.text <- Printf.sprintf
"bad color `%s': %s"
3840 v (Printexc.to_string exn
);
3843 let oldmode = state.mode
in
3844 let birdseye = isbirdseye state.mode
in
3846 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3848 src#
bool "presentation mode"
3849 (fun () -> conf.presentation)
3851 conf.presentation <- v;
3852 state.anchor <- getanchor ();
3855 src#
bool "ignore case in searches"
3856 (fun () -> conf.icase
)
3857 (fun v -> conf.icase
<- v);
3860 (fun () -> conf.preload)
3861 (fun v -> conf.preload <- v);
3863 src#
bool "highlight links"
3864 (fun () -> conf.hlinks
)
3865 (fun v -> conf.hlinks
<- v);
3867 src#
bool "under info"
3868 (fun () -> conf.underinfo
)
3869 (fun v -> conf.underinfo
<- v);
3871 src#
bool "persistent bookmarks"
3872 (fun () -> conf.savebmarks
)
3873 (fun v -> conf.savebmarks
<- v);
3875 src#
bool "proportional display"
3876 (fun () -> conf.proportional
)
3877 (fun v -> reqlayout conf.angle
v);
3879 src#
bool "trim margins"
3880 (fun () -> conf.trimmargins
)
3881 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3883 src#
bool "persistent location"
3884 (fun () -> conf.jumpback
)
3885 (fun v -> conf.jumpback
<- v);
3888 src#
int "inter-page space"
3889 (fun () -> conf.interpagespace)
3891 conf.interpagespace <- n;
3893 match state.layout with
3898 state.maxy <- calcheight ();
3899 let y = getpagey pageno in
3904 (fun () -> conf.pagebias
)
3905 (fun v -> conf.pagebias
<- v);
3907 src#
int "scroll step"
3908 (fun () -> conf.scrollstep
)
3909 (fun n -> conf.scrollstep
<- n);
3911 src#
int "auto scroll step"
3913 match state.autoscroll
with
3915 | _ -> conf.autoscrollstep
)
3917 if state.autoscroll
<> None
3918 then state.autoscroll
<- Some
n;
3919 conf.autoscrollstep
<- n);
3922 (fun () -> truncate
(conf.zoom *. 100.))
3923 (fun v -> setzoom ((float v) /. 100.));
3926 (fun () -> conf.angle
)
3927 (fun v -> reqlayout v conf.proportional
);
3929 src#
int "scroll bar width"
3930 (fun () -> state.scrollw
)
3934 reshape conf.winw
conf.winh
;
3937 src#
int "scroll handle height"
3938 (fun () -> conf.scrollh
)
3939 (fun v -> conf.scrollh
<- v;);
3941 src#
int "thumbnail width"
3942 (fun () -> conf.thumbw
)
3944 conf.thumbw
<- min
4096 v;
3947 leavebirdseye beye
false;
3952 src#
string "columns"
3954 match conf.columns
with
3956 | Some
(multicol
, _) -> columns_to_string multicol
)
3958 let n, a, b = columns_of_string v in
3962 src#caption
"Presentation mode" 0;
3963 src#
bool "scrollbar visible"
3964 (fun () -> conf.scrollbarinpm
)
3966 if v != conf.scrollbarinpm
3968 conf.scrollbarinpm
<- v;
3969 if conf.presentation
3971 state.scrollw
<- if v then conf.scrollbw
else 0;
3972 reshape conf.winw
conf.winh
;
3978 src#caption
"Pixmap cache" 0;
3979 src#int_with_suffix
"size (advisory)"
3980 (fun () -> conf.memlimit
)
3981 (fun v -> conf.memlimit
<- v);
3984 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3985 (string_with_suffix_of_int state.memused
)
3986 (Hashtbl.length
state.tilemap
)) 1;
3989 src#caption
"Layout" 0;
3990 src#caption2
"Dimension"
3992 Printf.sprintf
"%dx%d (virtual %dx%d)"
3998 src#caption2
"Position" (fun () ->
3999 Printf.sprintf
"%dx%d" state.x state.y
4002 src#caption2
"Visible" (fun () -> describe_location ()) 1
4006 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4007 "Save these parameters as global defaults at exit"
4008 (fun () -> conf.bedefault
)
4009 (fun v -> conf.bedefault
<- v)
4013 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4014 src#
bool ~offset
:0 ~
btos "Extended parameters"
4015 (fun () -> !showextended)
4016 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4020 (fun () -> conf.checkers
)
4021 (fun v -> conf.checkers
<- v; setcheckers v);
4022 src#
bool "update cursor"
4023 (fun () -> conf.updatecurs
)
4024 (fun v -> conf.updatecurs
<- v);
4026 (fun () -> conf.verbose
)
4027 (fun v -> conf.verbose
<- v);
4028 src#
bool "invert colors"
4029 (fun () -> conf.invert
)
4030 (fun v -> conf.invert
<- v);
4032 (fun () -> conf.maxhfit
)
4033 (fun v -> conf.maxhfit
<- v);
4034 src#
bool "redirect stderr"
4035 (fun () -> conf.redirectstderr)
4036 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4037 src#
string "uri launcher"
4038 (fun () -> conf.urilauncher
)
4039 (fun v -> conf.urilauncher
<- v);
4040 src#
string "path launcher"
4041 (fun () -> conf.pathlauncher
)
4042 (fun v -> conf.pathlauncher
<- v);
4043 src#
string "tile size"
4044 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4047 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4048 conf.tileh
<- max
64 w;
4049 conf.tilew
<- max
64 h;
4052 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4053 v (Printexc.to_string exn
));
4054 src#
int "texture count"
4055 (fun () -> conf.texcount
)
4058 then conf.texcount
<- v
4059 else showtext '
!'
" Failed to set texture count please retry later"
4061 src#
int "slice height"
4062 (fun () -> conf.sliceheight
)
4064 conf.sliceheight
<- v;
4065 wcmd "sliceh %d" conf.sliceheight
;
4067 src#
int "anti-aliasing level"
4068 (fun () -> conf.aalevel
)
4070 conf.aalevel
<- bound v 0 8;
4071 state.anchor <- getanchor ();
4072 opendoc state.path
state.password
;
4074 src#
int "ui font size"
4075 (fun () -> fstate.fontsize
)
4076 (fun v -> setfontsize (bound v 5 100));
4077 colorp "background color"
4078 (fun () -> conf.bgcolor
)
4079 (fun v -> conf.bgcolor
<- v);
4080 src#
bool "crop hack"
4081 (fun () -> conf.crophack
)
4082 (fun v -> conf.crophack
<- v);
4083 src#
string "trim fuzz"
4084 (fun () -> irect_to_string conf.trimfuzz
)
4087 conf.trimfuzz
<- irect_of_string v;
4089 then settrim true conf.trimfuzz
;
4091 state.text <- Printf.sprintf
"bad irect `%s': %s"
4092 v (Printexc.to_string exn
)
4094 src#
string "throttle"
4096 match conf.maxwait
with
4097 | None
-> "show place holder if page is not ready"
4100 then "wait for page to fully render"
4102 "wait " ^ string_of_float
time
4103 ^
" seconds before showing placeholder"
4107 let f = float_of_string
v in
4109 then conf.maxwait
<- None
4110 else conf.maxwait
<- Some
f
4112 state.text <- Printf.sprintf
"bad time `%s': %s"
4113 v (Printexc.to_string exn
)
4115 src#
string "ghyll scroll"
4117 match conf.ghyllscroll
with
4119 | Some nab
-> ghyllscroll_to_string nab
4124 if String.length
v = 0
4126 else Some
(ghyllscroll_of_string v)
4128 conf.ghyllscroll
<- gs
4130 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4131 v (Printexc.to_string exn
)
4133 src#
string "selection command"
4134 (fun () -> conf.selcmd
)
4135 (fun v -> conf.selcmd
<- v);
4136 src#colorspace
"color space"
4137 (fun () -> colorspace_to_string conf.colorspace
)
4139 conf.colorspace
<- colorspace_of_int v;
4146 src#caption
"Document" 0;
4147 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4148 src#caption2
"Pages"
4149 (fun () -> string_of_int
state.pagecount
) 1;
4150 src#caption2
"Dimensions"
4151 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4155 src#caption
"Trimmed margins" 0;
4156 src#caption2
"Dimensions"
4157 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4160 src#reset prevmode prevuioh
;
4164 let prevmode = state.mode
4165 and prevuioh
= state.uioh in
4166 fillsrc prevmode prevuioh
;
4167 let source = (src :> lvsource
) in
4168 let modehash = findkeyhash conf "info" in
4169 state.uioh <- coe (object (self)
4170 inherit listview ~
source ~trusted
:true ~
modehash as super
4171 val mutable m_prevmemused
= 0
4172 method infochanged
= function
4174 if m_prevmemused
!= state.memused
4176 m_prevmemused
<- state.memused
;
4177 G.postRedisplay "memusedchanged";
4179 | Pdim
-> G.postRedisplay "pdimchanged"
4180 | Docinfo
-> fillsrc prevmode prevuioh
4182 method key key mask
=
4183 if not
(Wsi.withctrl mask
)
4186 | 0xff51 -> coe (self#updownlevel ~
-1)
4187 | 0xff53 -> coe (self#updownlevel
1)
4188 | _ -> super#
key key mask
4189 else super#
key key mask
4191 G.postRedisplay "info";
4197 inherit lvsourcebase
4198 method getitemcount
= Array.length
state.help
4200 let s, n, _ = state.help
.(n) in
4203 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4207 m_qsearch
<- qsearch;
4208 match state.help
.(active) with
4209 | _, _, Action
f -> Some
(f uioh)
4219 method hasaction
n =
4220 match state.help
.(n) with
4221 | _, _, Action
_ -> true
4228 let modehash = findkeyhash conf "help" in
4229 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4230 G.postRedisplay "help";
4235 let re = Str.regexp
"[\r\n]" in
4237 inherit lvsourcebase
4238 val mutable m_items
= [||]
4240 method getitemcount
= 1 + Array.length m_items
4245 else m_items
.(n-1), 0
4247 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4252 then Buffer.clear
state.errmsgs
;
4253 m_qsearch
<- qsearch;
4260 method hasaction
n =
4264 state.newerrmsgs
<- false;
4265 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4266 m_items
<- Array.of_list
l
4274 let source = (msgsource :> lvsource
) in
4275 let modehash = findkeyhash conf "listview" in
4276 state.uioh <- coe (object
4277 inherit listview ~
source ~trusted
:false ~
modehash as super
4280 then msgsource#reset
;
4283 G.postRedisplay "msgs";
4286 let quickbookmark ?title
() =
4287 match state.layout with
4293 let sec = Unix.gettimeofday
() in
4294 let tm = Unix.localtime
sec in
4295 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4299 (tm.Unix.tm_year
+ 1900)
4302 | Some
title -> title
4305 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4310 state.fullscreen
<- None
;
4314 let setautoscrollspeed step goingdown
=
4315 let incr = max
1 ((abs step
) / 2) in
4316 let incr = if goingdown
then incr else -incr in
4317 let astep = step
+ incr in
4318 state.autoscroll
<- Some
astep;
4321 let viewkeyboard key mask
=
4323 let mode = state.mode in
4324 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4327 G.postRedisplay "view:enttext"
4329 let ctrl = Wsi.withctrl mask
in
4334 | 0xff63 -> (* insert *)
4335 if conf.angle
mod 360 = 0
4337 state.mode <- LinkNav
(Ltgendir
0);
4340 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4342 | 0xff1b | 113 -> (* escape / q *)
4343 begin match state.mstate
with
4345 state.mstate
<- Mnone
;
4346 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4347 G.postRedisplay "kill zoom rect";
4349 match state.ranchors
with
4351 | (path
, password
, anchor) :: rest
->
4352 state.ranchors
<- rest
;
4353 state.anchor <- anchor;
4354 opendoc path password
4357 | 0xff08 -> (* backspace *)
4358 let y = getnav ~
-1 in
4359 gotoy_and_clear_text y
4367 G.postRedisplay "dehighlight";
4369 | 47 | 63 -> (* / ? *)
4370 let ondone isforw
s =
4371 cbput state.hists
.pat
s;
4372 state.searchpattern
<- s;
4375 let s = String.create
1 in
4376 s.[0] <- Char.chr
key;
4377 enttext (s, "", Some
(onhist state.hists
.pat
),
4378 textentry, ondone (key = 47))
4380 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4381 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4382 setzoom (conf.zoom +. incr)
4384 | 43 | 0xffab -> (* + *)
4387 try int_of_string
s with exc
->
4388 state.text <- Printf.sprintf
"bad integer `%s': %s"
4389 s (Printexc.to_string exc
);
4395 state.text <- "page bias is now " ^ string_of_int
n;
4398 enttext ("page bias: ", "", None
, intentry, ondone)
4400 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4401 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4402 setzoom (max
0.01 (conf.zoom -. decr))
4404 | 45 | 0xffad -> (* - *)
4405 let ondone msg
= state.text <- msg
in
4407 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4408 optentry state.mode, ondone
4411 | 48 when ctrl -> (* ctrl-0 *)
4414 | 49 when ctrl -> (* 1 *)
4415 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4419 | 0xffc6 -> (* f9 *)
4422 | 57 when ctrl -> (* ctrl-9 *)
4425 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4426 when not
ctrl -> (* 0..9 *)
4429 try int_of_string
s with exc
->
4430 state.text <- Printf.sprintf
"bad integer `%s': %s"
4431 s (Printexc.to_string exc
);
4437 cbput state.hists
.pag
(string_of_int
n);
4438 gotopage1 (n + conf.pagebias
- 1) 0;
4441 let pageentry text key =
4442 match Char.unsafe_chr
key with
4443 | 'g'
-> TEdone
text
4444 | _ -> intentry text key
4446 let text = "x" in text.[0] <- Char.chr
key;
4447 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4450 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4451 reshape conf.winw
conf.winh
;
4454 conf.hlinks
<- not
conf.hlinks
;
4455 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4456 G.postRedisplay "toggle highlightlinks";
4459 begin match state.autoscroll
with
4461 conf.autoscrollstep
<- step
;
4462 state.autoscroll
<- None
4464 if conf.autoscrollstep
= 0
4465 then state.autoscroll
<- Some
1
4466 else state.autoscroll
<- Some
conf.autoscrollstep
4470 conf.presentation <- not
conf.presentation;
4471 if conf.presentation
4473 if not
conf.scrollbarinpm
4474 then state.scrollw
<- 0;
4477 state.scrollw
<- conf.scrollbw
;
4479 showtext ' '
("presentation mode " ^
4480 if conf.presentation then "on" else "off");
4481 state.anchor <- getanchor ();
4485 begin match state.fullscreen
with
4487 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4490 state.fullscreen
<- None
;
4495 gotoy_and_clear_text 0
4498 gotopage1 (state.pagecount
- 1) 0
4500 | 112 | 78 -> (* p|N *)
4501 search state.searchpattern
false
4503 | 110 | 0xffc0 -> (* n|F3 *)
4504 search state.searchpattern
true
4507 begin match state.layout with
4510 gotoy_and_clear_text (getpagey l.pageno)
4514 begin match List.rev
state.layout with
4517 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4518 gotoy_and_clear_text (getpagey pageno)
4521 | 0xff9f | 0xffff -> (* delete *)
4522 begin match state.layout with
4525 let pageno = max
0 (l.pageno-1) in
4526 gotoy_and_clear_text (getpagey pageno)
4530 showtext ' '
(describe_location ());
4533 begin match state.layout with
4536 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4541 enterbookmarkmode ()
4543 | 104 | 0xffbe -> (* h|F1 *)
4549 | 101 when conf.redirectstderr -> (* e *)
4554 match state.layout with
4557 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4561 enttext ("bookmark: ", "", None
, textentry, ondone)
4565 showtext ' '
"Quick bookmark added";
4568 begin match state.layout with
4570 let rect = getpdimrect
l.pagedimno
in
4574 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4575 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4577 (truncate
(rect.(1) -. rect.(0)),
4578 truncate
(rect.(3) -. rect.(0)))
4580 let w = truncate
((float w)*.conf.zoom)
4581 and h = truncate
((float h)*.conf.zoom) in
4584 state.anchor <- getanchor ();
4585 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4587 G.postRedisplay "z";
4592 | 50 when ctrl -> (* ctrl-2 *)
4593 let maxw = getmaxw
() in
4595 then setzoom (maxw /. float conf.winw
)
4597 | 60 | 62 -> (* < > *)
4598 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4600 | 91 | 93 -> (* [ ] *)
4602 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4604 G.postRedisplay "brightness";
4606 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4607 setzoom state.prevzoom
4609 | 107 | 0xff52 -> (* k up *)
4610 begin match state.autoscroll
with
4612 begin match state.mode with
4613 | Birdseye beye
-> upbirdseye 1 beye
4616 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4617 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4620 setautoscrollspeed n false
4623 | 106 | 0xff54 -> (* j down *)
4624 begin match state.autoscroll
with
4626 begin match state.mode with
4627 | Birdseye beye
-> downbirdseye 1 beye
4630 then gotoy_and_clear_text (clamp (conf.winh
/2))
4631 else gotoy_and_clear_text (clamp conf.scrollstep
)
4634 setautoscrollspeed n true
4637 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4645 let dx = if key = 0xff51 then dx else -dx in
4646 state.x <- state.x + dx;
4647 gotoy_and_clear_text state.y
4650 G.postRedisplay "lef/right"
4653 | 0xff55 -> (* prior *)
4657 match state.layout with
4659 | l :: _ -> state.y - l.pagey
4665 | 0xff56 -> (* next *)
4669 match List.rev
state.layout with
4671 | l :: _ -> getpagey l.pageno
4677 | 0xff50 -> gotoghyll 0
4678 | 0xff57 -> gotoghyll (clamp state.maxy)
4679 | 0xff53 when Wsi.withalt mask
->
4680 gotoghyll (getnav ~
-1)
4681 | 0xff51 when Wsi.withalt mask
->
4682 gotoghyll (getnav 1)
4685 state.anchor <- getanchor ();
4686 opendoc state.path
state.password
4691 | 118 when conf.debug
-> (* v *)
4694 match getopaque l.pageno with
4697 let x0, y0, x1, y1 = pagebbox opaque
in
4698 let a,b = float x0, float y0 in
4699 let c,d = float x1, float y0 in
4700 let e,f = float x1, float y1 in
4701 let h,j
= float x0, float y1 in
4702 let rect = (a,b,c,d,e,f,h,j
) in
4704 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4706 G.postRedisplay "v";
4709 vlog "huh? %s" (Wsi.keyname
key)
4712 let gotounder = function
4713 | Ulinkgoto
(pageno, top) ->
4717 gotopage1 pageno top;
4723 | Uremote
(filename
, pageno) ->
4725 if Sys.file_exists filename
4728 let dir = Filename.dirname
state.path in
4729 let path = Filename.concat
dir filename
in
4730 if Sys.file_exists
path
4734 if String.length
path > 0
4736 let anchor = getanchor () in
4737 let ranchor = state.path, state.password
, anchor in
4738 state.anchor <- (pageno, 0.0);
4739 state.ranchors
<- ranchor :: state.ranchors
;
4742 else showtext '
!'
("Could not find " ^ filename
)
4744 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4747 let linknavkeyboard key mask
linknav =
4748 let getpage pageno =
4749 let rec loop = function
4751 | l :: _ when l.pageno = pageno -> Some
l
4752 | _ :: rest
-> loop rest
4753 in loop state.layout
4755 let doexact (pageno, n) =
4756 match getopaque pageno, getpage pageno with
4757 | Some opaque
, Some
l ->
4760 let under = getlink opaque
n in
4761 G.postRedisplay "link gotounder";
4767 | 0xff50 -> (* home *)
4768 Some
(findlink opaque LDfirst
), -1
4770 | 0xff57 -> (* end *)
4771 Some
(findlink opaque LDlast
), 1
4773 | 0xff51 -> (* left *)
4774 Some
(findlink opaque
(LDleft
n)), -1
4776 | 0xff53 -> (* right *)
4777 Some
(findlink opaque
(LDright
n)), 1
4779 | 0xff52 -> (* up *)
4780 Some
(findlink opaque
(LDup
n)), -1
4782 | 0xff54 -> (* down *)
4783 Some
(findlink opaque
(LDdown
n)), 1
4788 begin match findpwl
l.pageno dir with
4792 state.mode <- LinkNav
(Ltgendir
dir);
4793 let y, h = getpageyh pageno in
4796 then y + h - conf.winh
4801 begin match getopaque pageno, getpage pageno with
4802 | Some opaque
, Some
_ ->
4804 let ld = if dir > 0 then LDfirst
else LDlast
in
4807 begin match link with
4809 showlinktype (getlink opaque
m);
4810 state.mode <- LinkNav
(Ltexact
(pageno, m));
4811 G.postRedisplay "linknav jpage";
4818 begin match opt with
4819 | Some Lnotfound
-> pwl l dir;
4820 | Some
(Lfound
m) ->
4824 let _, y0, _, y1 = getlinkrect opaque
m in
4826 then gotopage1 l.pageno y0
4828 let d = fstate.fontsize
+ 1 in
4829 if y1 - l.pagey > l.pagevh - d
4830 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
4831 else G.postRedisplay "linknav";
4833 showlinktype (getlink opaque
m);
4834 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
4837 | None
-> viewkeyboard key mask
4839 | _ -> viewkeyboard key mask
4844 G.postRedisplay "leave linknav"
4848 | Ltgendir
_ -> viewkeyboard key mask
4849 | Ltexact exact
-> doexact exact
4852 let keyboard key mask
=
4853 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4854 then wcmd "interrupt"
4855 else state.uioh <- state.uioh#
key key mask
4858 let birdseyekeyboard key mask
4859 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4861 match conf.columns
with
4863 | Some
((c, _, _), _) -> c
4866 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4867 let y, h = getpageyh pageno in
4868 let top = (conf.winh
- h) / 2 in
4869 gotoy (max
0 (y - top))
4870 | 0xff0d -> leavebirdseye beye
false
4871 | 0xff1b -> leavebirdseye beye
true (* escape *)
4872 | 0xff52 -> upbirdseye incr beye
(* prior *)
4873 | 0xff54 -> downbirdseye incr beye
(* next *)
4874 | 0xff51 -> upbirdseye 1 beye
(* up *)
4875 | 0xff53 -> downbirdseye 1 beye
(* down *)
4878 begin match state.layout with
4882 state.mode <- Birdseye
(
4883 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4885 gotopage1 l.pageno 0;
4888 let layout = layout (state.y-conf.winh
) conf.winh
in
4890 | [] -> gotoy (clamp (-conf.winh
))
4892 state.mode <- Birdseye
(
4893 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4895 gotopage1 l.pageno 0
4898 | [] -> gotoy (clamp (-conf.winh
))
4902 begin match List.rev
state.layout with
4904 let layout = layout (state.y + conf.winh
) conf.winh
in
4905 begin match layout with
4907 let incr = l.pageh
- l.pagevh in
4912 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4914 G.postRedisplay "birdseye pagedown";
4916 else gotoy (clamp (incr + conf.interpagespace*2));
4920 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4921 gotopage1 l.pageno 0;
4924 | [] -> gotoy (clamp conf.winh
)
4928 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4932 let pageno = state.pagecount
- 1 in
4933 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4934 if not
(pagevisible state.layout pageno)
4937 match List.rev
state.pdims
with
4939 | (_, _, h, _) :: _ -> h
4941 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4942 else G.postRedisplay "birdseye end";
4943 | _ -> viewkeyboard key mask
4948 match state.mode with
4949 | Textentry
_ -> scalecolor 0.4
4951 | View
-> scalecolor 1.0
4952 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4953 if l.pageno = hooverpageno
4956 if l.pageno = pageno
4962 begin match getopaque l.pageno with
4964 if tileready l l.pagex l.pagey
4966 let x = l.pagedispx - l.pagex
4967 and y = l.pagedispy - l.pagey in
4968 postprocess opaque
conf.hlinks
x y;
4974 let scrollindicator () =
4975 let sbw, ph
, sh = state.uioh#
scrollph in
4976 let sbh, pw
, sw = state.uioh#scrollpw
in
4978 GlDraw.color (0.64, 0.64, 0.64);
4980 (float (conf.winw
- sbw), 0.)
4981 (float conf.winw
, float conf.winh
)
4984 (0., float (conf.winh
- sbh))
4985 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4987 GlDraw.color (0.0, 0.0, 0.0);
4990 (float (conf.winw
- sbw), ph
)
4991 (float conf.winw
, ph
+. sh)
4994 (pw
, float (conf.winh
- sbh))
4995 (pw
+. sw, float conf.winh
)
5000 match state.mstate
with
5001 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5004 | Msel
((x0, y0), (x1, y1)) ->
5005 let rec loop = function
5007 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5008 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5009 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5010 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5012 match getopaque l.pageno with
5014 let x0, y0 = pagetranslatepoint l x0 y0 in
5015 let x1, y1 = pagetranslatepoint l x1 y1 in
5016 seltext opaque
(x0, y0, x1, y1);
5024 let showrects rects
=
5026 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5027 GlDraw.polygon_mode `both `fill
;
5028 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5030 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5032 if l.pageno = pageno
5034 let dx = float (l.pagedispx - l.pagex) in
5035 let dy = float (l.pagedispy - l.pagey) in
5036 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5037 GlDraw.begins `quads
;
5039 GlDraw.vertex2
(x0+.dx, y0+.dy);
5040 GlDraw.vertex2
(x1+.dx, y1+.dy);
5041 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5042 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5053 GlClear.color (scalecolor2 conf.bgcolor
);
5054 GlClear.clear
[`
color];
5055 List.iter
drawpage state.layout;
5057 match state.mode with
5058 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5059 begin match getopaque pageno with
5061 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5068 | None
-> state.rects
5075 begin match state.mstate
with
5076 | Mzoomrect
((x0, y0), (x1, y1)) ->
5078 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5079 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5080 GlDraw.rect (float x0, float y0)
5081 (float x1, float y1);
5090 let zoomrect x y x1 y1 =
5093 and y0 = min
y y1 in
5094 gotoy (state.y + y0);
5095 state.anchor <- getanchor ();
5096 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5098 if state.w < conf.winw
- state.scrollw
5099 then (conf.winw
- state.scrollw
- state.w) / 2
5102 state.x <- (state.x + margin) - x0;
5104 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5105 state.mstate
<- Mnone
;
5109 let winw = conf.winw - state.scrollw
- 1 in
5110 let s = float x /. float winw in
5111 let destx = truncate
(float (state.w + winw) *. s) in
5112 state.x <- winw - destx;
5113 gotoy_and_clear_text state.y;
5114 state.mstate
<- Mscrollx
;
5118 let s = float y /. float conf.winh
in
5119 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5120 gotoy_and_clear_text desty;
5121 state.mstate
<- Mscrolly
;
5124 let viewmouse button down
x y mask
=
5126 | n when (n == 4 || n == 5) && not down
->
5127 if Wsi.withctrl mask
5129 match state.mstate
with
5130 | Mzoom
(oldn
, i
) ->
5138 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5140 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5142 let zoom = conf.zoom -. incr in
5144 state.mstate
<- Mzoom
(n, 0);
5146 state.mstate
<- Mzoom
(n, i
+1);
5148 else state.mstate
<- Mzoom
(n, 0)
5150 | _ -> state.mstate
<- Mzoom
(n, 0)
5153 match state.autoscroll
with
5154 | Some step
-> setautoscrollspeed step
(n=4)
5158 then -conf.scrollstep
5159 else conf.scrollstep
5161 let incr = incr * 2 in
5162 let y = clamp incr in
5163 gotoy_and_clear_text y
5166 | 1 when Wsi.withctrl mask
->
5169 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5170 state.mstate
<- Mpan
(x, y)
5173 state.mstate
<- Mnone
5178 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5180 state.mstate
<- Mzoomrect
(p, p)
5183 match state.mstate
with
5184 | Mzoomrect
((x0, y0), _) ->
5185 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5186 then zoomrect x0 y0 x y
5188 state.mstate
<- Mnone
;
5189 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5190 G.postRedisplay "kill accidental zoom rect";
5193 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5194 state.mstate
<- Mnone
5197 | 1 when x > conf.winw - state.scrollw
->
5200 let _, position, sh = state.uioh#
scrollph in
5201 if y > truncate
position && y < truncate
(position +. sh)
5202 then state.mstate
<- Mscrolly
5205 state.mstate
<- Mnone
5207 | 1 when y > conf.winh
- state.hscrollh ->
5210 let _, position, sw = state.uioh#scrollpw
in
5211 if x > truncate
position && x < truncate
(position +. sw)
5212 then state.mstate
<- Mscrollx
5215 state.mstate
<- Mnone
5218 let dest = if down
then getunder x y else Unone
in
5219 begin match dest with
5220 | Ulinkgoto
(pageno, top) ->
5224 gotopage1 pageno top;
5230 | Uremote
(filename
, pageno) ->
5232 if Sys.file_exists filename
5235 let dir = Filename.dirname
state.path in
5236 let path = Filename.concat
dir filename
in
5237 if Sys.file_exists
path
5241 if String.length
path > 0
5243 let anchor = getanchor () in
5244 let ranchor = state.path, state.password
, anchor in
5245 state.anchor <- (pageno, 0.0);
5246 state.ranchors
<- ranchor :: state.ranchors
;
5249 else showtext '
!'
("Could not find " ^ filename
)
5251 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5253 | Unone
when down
->
5254 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5255 state.mstate
<- Mpan
(x, y);
5257 | Unone
| Utext
_ ->
5260 if conf.angle
mod 360 = 0
5262 state.mstate
<- Msel
((x, y), (x, y));
5263 G.postRedisplay "mouse select";
5267 match state.mstate
with
5270 | Mzoom
_ | Mscrollx
| Mscrolly
->
5271 state.mstate
<- Mnone
5273 | Mzoomrect
((x0, y0), _) ->
5277 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5278 state.mstate
<- Mnone
5280 | Msel
((_, y0), (_, y1)) ->
5281 let rec loop = function
5284 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5285 || ((y1 >= l.pagedispy
5286 && y1 <= (l.pagedispy + l.pagevh)))
5288 match getopaque l.pageno with
5290 copysel
conf.selcmd opaque
;
5291 G.postRedisplay "copysel"
5296 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5297 state.mstate
<- Mnone
;
5304 let birdseyemouse button down
x y mask
5305 (conf, leftx
, _, hooverpageno
, anchor) =
5308 let rec loop = function
5311 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5312 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5314 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5320 | _ -> viewmouse button down
x y mask
5323 let mouse button down
x y mask
=
5324 state.uioh <- state.uioh#button button down
x y mask
;
5328 state.uioh <- state.uioh#
motion x y
5332 state.uioh <- state.uioh#
pmotion x y;
5338 method key key mask
=
5339 begin match state.mode with
5340 | Textentry
textentry -> textentrykeyboard key mask
textentry
5341 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5342 | View
-> viewkeyboard key mask
5343 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5347 method button button bstate
x y mask
=
5348 begin match state.mode with
5350 | View
-> viewmouse button bstate
x y mask
5351 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5357 begin match state.mode with
5359 | View
| Birdseye
_ | LinkNav
_ ->
5360 match state.mstate
with
5361 | Mzoom
_ | Mnone
-> ()
5366 state.mstate
<- Mpan
(x, y);
5367 if conf.zoom > 1.0 then state.x <- state.x + dx;
5369 gotoy_and_clear_text y
5372 state.mstate
<- Msel
(a, (x, y));
5373 G.postRedisplay "motion select";
5376 let y = min
conf.winh
(max
0 y) in
5380 let x = min
conf.winw (max
0 x) in
5383 | Mzoomrect
(p0
, _) ->
5384 state.mstate
<- Mzoomrect
(p0
, (x, y));
5385 G.postRedisplay "motion zoomrect";
5389 method pmotion x y =
5390 begin match state.mode with
5391 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5392 let rec loop = function
5394 if hooverpageno
!= -1
5396 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5397 G.postRedisplay "pmotion birdseye no hoover";
5400 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5401 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5403 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5404 G.postRedisplay "pmotion birdseye hoover";
5414 match state.mstate
with
5415 | Mnone
-> updateunder x y
5416 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5421 method infochanged
_ = ()
5424 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5425 let p, h = scrollph state.y maxy in
5429 let winw = conf.winw - state.scrollw
- 1 in
5430 let fwinw = float winw in
5432 let sw = fwinw /. float state.w in
5433 let sw = fwinw *. sw in
5434 max
sw (float conf.scrollh
)
5437 let f = state.w+winw in
5438 let r = float (winw-state.x) /. float f in
5439 let p = fwinw *. r in
5443 if position +. sw > fwinw
5444 then fwinw -. position
5447 state.hscrollh, position, sw
5451 match state.mode with
5452 | LinkNav
_ -> "links"
5453 | Textentry
_ -> "textentry"
5454 | Birdseye
_ -> "birdseye"
5457 findkeyhash conf modename
5464 let fontpath = ref "";;
5467 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5470 let l = String.length
s in
5471 let b = Buffer.create
l in
5477 try Sys.getenv
"HOME"
5480 ("Can not determine home directory location: " ^
5481 Printexc.to_string exn
);
5485 let modifier_of_string = function
5486 | "alt" -> Wsi.altmask
5487 | "shift" -> Wsi.shiftmask
5488 | "ctrl" | "control" -> Wsi.ctrlmask
5489 | "meta" -> Wsi.metamask
5494 let r = Str.regexp
"-" in
5496 let elems = Str.full_split
r s in
5499 let m1 = modifier_of_string s in
5501 then (Wsi.namekey
s, m)
5504 | Str.Delim
s when n land 1 = 0 -> g s
5506 | Str.Delim
_ -> (k
, m)
5508 let rec loop n k
m = function
5511 let k, m = f n k m x in
5517 let keys_of_string =
5518 let r = Str.regexp
"[ \t]" in
5520 let elems = Str.split
r s in
5521 List.map
key_of_string elems
5524 let copykeyhashes c =
5525 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5528 let config_of c attrs
=
5532 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5533 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5534 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5535 | "preload" -> { c with preload = bool_of_string
v }
5536 | "page-bias" -> { c with pagebias
= int_of_string
v }
5537 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5538 | "auto-scroll-step" ->
5539 { c with autoscrollstep
= max
0 (int_of_string
v) }
5540 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5541 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5544 match String.lowercase
v with
5545 | "true" -> Some infinity
5547 | f -> Some
(float_of_string
f)
5549 { c with maxwait
= mw}
5550 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5551 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5552 | "vertical-margin" ->
5553 { c with interpagespace = max
0 (int_of_string
v) }
5555 let zoom = float_of_string
v /. 100. in
5556 let zoom = max
zoom 0.0 in
5557 { c with zoom = zoom }
5558 | "presentation" -> { c with presentation = bool_of_string
v }
5559 | "rotation-angle" -> { c with angle
= int_of_string
v }
5560 | "width" -> { c with winw = max
20 (int_of_string
v) }
5561 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5562 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5563 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5564 | "pixmap-cache-size" ->
5565 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5566 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5567 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5568 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5569 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5570 | "background-color" -> { c with bgcolor
= color_of_string v }
5571 | "scrollbar-in-presentation" ->
5572 { c with scrollbarinpm
= bool_of_string
v }
5573 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5574 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5575 | "mupdf-store-size" ->
5576 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5577 | "checkers" -> { c with checkers
= bool_of_string
v }
5578 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5579 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5580 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5581 | "uri-launcher" -> { c with urilauncher
= unent v }
5582 | "path-launcher" -> { c with pathlauncher
= unent v }
5583 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5584 | "invert-colors" -> { c with invert
= bool_of_string
v }
5585 | "brightness" -> { c with colorscale
= float_of_string
v }
5586 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5588 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5590 let nab = columns_of_string v in
5591 { c with columns
= Some
(nab, [||]) }
5592 | "birds-eye-columns" ->
5593 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5594 | "selection-command" -> { c with selcmd
= unent v }
5595 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5598 prerr_endline
("Error processing attribute (`" ^
5599 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5602 let rec fold c = function
5605 let c = apply c k v in
5608 fold { c with keyhashes
= copykeyhashes c } attrs
;
5611 let fromstring f pos
n v d =
5614 dolog "Error processing attribute (%S=%S) at %d\n%s"
5615 n v pos
(Printexc.to_string exn
)
5620 let bookmark_of attrs
=
5621 let rec fold title page
rely = function
5622 | ("title", v) :: rest
-> fold v page
rely rest
5623 | ("page", v) :: rest
-> fold title v rely rest
5624 | ("rely", v) :: rest
-> fold title page
v rest
5625 | _ :: rest
-> fold title page
rely rest
5626 | [] -> title, page
, rely
5628 fold "invalid" "0" "0" attrs
5632 let rec fold path page
rely pan
= function
5633 | ("path", v) :: rest
-> fold v page
rely pan rest
5634 | ("page", v) :: rest
-> fold path v rely pan rest
5635 | ("rely", v) :: rest
-> fold path page
v pan rest
5636 | ("pan", v) :: rest
-> fold path page
rely v rest
5637 | _ :: rest
-> fold path page
rely pan rest
5638 | [] -> path, page
, rely, pan
5640 fold "" "0" "0" "0" attrs
5644 let rec fold rs ls
= function
5645 | ("out", v) :: rest
-> fold v ls rest
5646 | ("in", v) :: rest
-> fold rs
v rest
5647 | _ :: rest
-> fold ls rs rest
5653 let setconf dst
src =
5654 dst
.scrollbw
<- src.scrollbw
;
5655 dst
.scrollh
<- src.scrollh
;
5656 dst
.icase
<- src.icase
;
5657 dst
.preload <- src.preload;
5658 dst
.pagebias
<- src.pagebias
;
5659 dst
.verbose
<- src.verbose
;
5660 dst
.scrollstep
<- src.scrollstep
;
5661 dst
.maxhfit
<- src.maxhfit
;
5662 dst
.crophack
<- src.crophack
;
5663 dst
.autoscrollstep
<- src.autoscrollstep
;
5664 dst
.maxwait
<- src.maxwait
;
5665 dst
.hlinks
<- src.hlinks
;
5666 dst
.underinfo
<- src.underinfo
;
5667 dst
.interpagespace <- src.interpagespace;
5668 dst
.zoom <- src.zoom;
5669 dst
.presentation <- src.presentation;
5670 dst
.angle
<- src.angle
;
5671 dst
.winw <- src.winw;
5672 dst
.winh
<- src.winh
;
5673 dst
.savebmarks
<- src.savebmarks
;
5674 dst
.memlimit
<- src.memlimit
;
5675 dst
.proportional
<- src.proportional
;
5676 dst
.texcount
<- src.texcount
;
5677 dst
.sliceheight
<- src.sliceheight
;
5678 dst
.thumbw
<- src.thumbw
;
5679 dst
.jumpback
<- src.jumpback
;
5680 dst
.bgcolor
<- src.bgcolor
;
5681 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5682 dst
.tilew
<- src.tilew
;
5683 dst
.tileh
<- src.tileh
;
5684 dst
.mustoresize
<- src.mustoresize
;
5685 dst
.checkers
<- src.checkers
;
5686 dst
.aalevel
<- src.aalevel
;
5687 dst
.trimmargins
<- src.trimmargins
;
5688 dst
.trimfuzz
<- src.trimfuzz
;
5689 dst
.urilauncher
<- src.urilauncher
;
5690 dst
.colorspace
<- src.colorspace
;
5691 dst
.invert
<- src.invert
;
5692 dst
.colorscale
<- src.colorscale
;
5693 dst
.redirectstderr <- src.redirectstderr;
5694 dst
.ghyllscroll
<- src.ghyllscroll
;
5695 dst
.columns
<- src.columns
;
5696 dst
.beyecolumns
<- src.beyecolumns
;
5697 dst
.selcmd
<- src.selcmd
;
5698 dst
.updatecurs
<- src.updatecurs
;
5699 dst
.pathlauncher
<- src.pathlauncher
;
5700 dst
.keyhashes
<- copykeyhashes src;
5704 let h = Hashtbl.create
10 in
5705 let dc = { defconf with angle
= defconf.angle
} in
5706 let rec toplevel v t spos
_ =
5708 | Vdata
| Vcdata
| Vend
-> v
5709 | Vopen
("llppconfig", _, closed
) ->
5712 else { v with f = llppconfig
}
5714 error
"unexpected subelement at top level" s spos
5715 | Vclose
_ -> error
"unexpected close at top level" s spos
5717 and llppconfig
v t spos
_ =
5719 | Vdata
| Vcdata
-> v
5720 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5721 | Vopen
("defaults", attrs
, closed
) ->
5722 let c = config_of dc attrs
in
5726 else { v with f = defaults
}
5728 | Vopen
("ui-font", attrs
, closed
) ->
5729 let rec getsize size
= function
5731 | ("size", v) :: rest
->
5733 fromstring int_of_string spos
"size" v fstate.fontsize
in
5735 | l -> getsize size l
5737 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5740 else { v with f = uifont
(Buffer.create
10) }
5742 | Vopen
("doc", attrs
, closed
) ->
5743 let pathent, spage
, srely
, span
= doc_of attrs
in
5744 let path = unent pathent
5745 and pageno = fromstring int_of_string spos
"page" spage
0
5746 and rely = fromstring float_of_string spos
"rely" srely
0.0
5747 and pan
= fromstring int_of_string spos
"pan" span
0 in
5748 let c = config_of dc attrs
in
5749 let anchor = (pageno, rely) in
5751 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5752 else { v with f = doc
path pan
anchor c [] }
5755 error
"unexpected subelement in llppconfig" s spos
5757 | Vclose
"llppconfig" -> { v with f = toplevel }
5758 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5760 and defaults
v t spos
_ =
5762 | Vdata
| Vcdata
-> v
5763 | Vend
-> error
"unexpected end of input in defaults" s spos
5764 | Vopen
("keymap", attrs
, closed
) ->
5766 try List.assoc
"mode" attrs
5767 with Not_found
-> "global" in
5772 let h = findkeyhash dc modename in
5773 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5776 { v with f = pkeymap
ret KeyMap.empty }
5778 | Vopen
(_, _, _) ->
5779 error
"unexpected subelement in defaults" s spos
5781 | Vclose
"defaults" ->
5782 { v with f = llppconfig
}
5784 | Vclose
_ -> error
"unexpected close in defaults" s spos
5786 and uifont
b v t spos
epos =
5789 Buffer.add_substring
b s spos
(epos - spos
);
5791 | Vopen
(_, _, _) ->
5792 error
"unexpected subelement in ui-font" s spos
5793 | Vclose
"ui-font" ->
5794 if String.length
!fontpath = 0
5795 then fontpath := Buffer.contents
b;
5796 { v with f = llppconfig
}
5797 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5798 | Vend
-> error
"unexpected end of input in ui-font" s spos
5800 and doc
path pan
anchor c bookmarks
v t spos
_ =
5802 | Vdata
| Vcdata
-> v
5803 | Vend
-> error
"unexpected end of input in doc" s spos
5804 | Vopen
("bookmarks", _, closed
) ->
5807 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5809 | Vopen
("keymap", attrs
, closed
) ->
5811 try List.assoc
"mode" attrs
5812 with Not_found
-> "global"
5818 let h = findkeyhash c modename in
5819 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5820 doc
path pan
anchor c bookmarks
5822 { v with f = pkeymap
ret KeyMap.empty }
5824 | Vopen
(_, _, _) ->
5825 error
"unexpected subelement in doc" s spos
5828 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5829 { v with f = llppconfig
}
5831 | Vclose
_ -> error
"unexpected close in doc" s spos
5833 and pkeymap
ret keymap
v t spos
_ =
5835 | Vdata
| Vcdata
-> v
5836 | Vend
-> error
"unexpected end of input in keymap" s spos
5837 | Vopen
("map", attrs
, closed
) ->
5838 let r, l = map_of attrs
in
5839 let kss = fromstring keys_of_string spos
"in" r [] in
5840 let lss = fromstring keys_of_string spos
"out" l [] in
5844 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5845 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5848 then { v with f = pkeymap
ret keymap }
5851 { v with f = skip
"map" f }
5854 error
"unexpected subelement in keymap" s spos
5856 | Vclose
"keymap" ->
5857 { v with f = ret keymap }
5859 | Vclose
_ -> error
"unexpected close in keymap" s spos
5861 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5863 | Vdata
| Vcdata
-> v
5864 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5865 | Vopen
("item", attrs
, closed
) ->
5866 let titleent, spage
, srely
= bookmark_of attrs
in
5867 let page = fromstring int_of_string spos
"page" spage
0
5868 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5869 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5871 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5874 { v with f = skip
"item" f }
5877 error
"unexpected subelement in bookmarks" s spos
5879 | Vclose
"bookmarks" ->
5880 { v with f = doc
path pan
anchor c bookmarks }
5882 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5884 and skip tag
f v t spos
_ =
5886 | Vdata
| Vcdata
-> v
5888 error
("unexpected end of input in skipped " ^ tag
) s spos
5889 | Vopen
(tag'
, _, closed
) ->
5893 let f'
() = { v with f = skip tag
f } in
5894 { v with f = skip tag'
f'
}
5898 else error
("unexpected close in skipped " ^ tag
) s spos
5901 parse
{ f = toplevel; accu = () } s;
5907 let len = in_channel_length ic
in
5908 let s = String.create
len in
5909 really_input ic
s 0 len;
5912 | Parse_error
(msg
, s, pos
) ->
5913 let subs = subs s pos
in
5914 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5915 failwith
("parse error: " ^
s)
5918 failwith
("config load error: " ^
Printexc.to_string exn
)
5924 let dir = Filename.concat
home ".config" in
5925 if Sys.is_directory
dir then dir else home
5928 Filename.concat
dir "llpp.conf"
5931 let confpath = ref defconfpath;;
5934 if Sys.file_exists
!confpath
5937 (try Some
(open_in_bin
!confpath)
5940 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5941 Printexc.to_string exn
);
5950 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5951 Printexc.to_string exn
);
5957 f (Hashtbl.create
0, defconf)
5962 let pc, pb
, px, pa
=
5964 Hashtbl.find h (Filename.basename
state.path)
5965 with Not_found
-> dc, [], 0, (0, 0.0)
5969 state.bookmarks <- pb
;
5971 state.scrollw
<- conf.scrollbw
;
5973 then state.anchor <- pa
;
5974 cbput state.hists
.nav pa
;
5979 let add_attrs bb always
dc c =
5982 then Printf.bprintf bb
"\n %s='%b'" s a
5985 then Printf.bprintf bb
"\n %s='%d'" s a
5988 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5991 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5994 then Printf.bprintf bb
"\n %s='%f'" s a
5998 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6002 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6006 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6010 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6016 | Some
(_N
, _A
, _B
) ->
6017 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6027 else string_of_float
f
6029 Printf.bprintf bb
"\n %s='%s'" s v
6034 | Some
((n, a, b), _) when n > 1 ->
6035 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6041 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6046 then dc.winw, dc.winh
6048 match state.fullscreen
with
6050 | None
-> c.winw, c.winh
6052 let zoom, presentation, interpagespace, maxwait
=
6054 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6056 match state.mode with
6057 | Birdseye
(bc
, _, _, _, _) ->
6058 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6059 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6061 oi
"width" w dc.winw;
6062 oi
"height" h dc.winh
;
6063 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6064 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6065 ob "case-insensitive-search" c.icase
dc.icase
;
6066 ob "preload" c.preload dc.preload;
6067 oi
"page-bias" c.pagebias
dc.pagebias
;
6068 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6069 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6070 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6071 ob "crop-hack" c.crophack
dc.crophack
;
6072 oW
"throttle" maxwait
dc.maxwait
;
6073 ob "highlight-links" c.hlinks
dc.hlinks
;
6074 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6075 oi
"vertical-margin" interpagespace dc.interpagespace;
6076 oz
"zoom" zoom dc.zoom;
6077 ob "presentation" presentation dc.presentation;
6078 oi
"rotation-angle" c.angle
dc.angle
;
6079 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6080 ob "proportional-display" c.proportional
dc.proportional
;
6081 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6082 oi
"tex-count" c.texcount
dc.texcount
;
6083 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6084 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6085 ob "persistent-location" c.jumpback
dc.jumpback
;
6086 oc
"background-color" c.bgcolor
dc.bgcolor
;
6087 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6088 oi
"tile-width" c.tilew
dc.tilew
;
6089 oi
"tile-height" c.tileh
dc.tileh
;
6090 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6091 ob "checkers" c.checkers
dc.checkers
;
6092 oi
"aalevel" c.aalevel
dc.aalevel
;
6093 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6094 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6095 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6096 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6097 oC
"color-space" c.colorspace
dc.colorspace
;
6098 ob "invert-colors" c.invert
dc.invert
;
6099 oF
"brightness" c.colorscale
dc.colorscale
;
6100 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6101 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6102 oco
"columns" c.columns
dc.columns
;
6103 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6104 os
"selection-command" c.selcmd
dc.selcmd
;
6105 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6108 let keymapsbuf always
dc c =
6109 let bb = Buffer.create
16 in
6110 let rec loop = function
6112 | (modename, h) :: rest
->
6113 let dh = findkeyhash dc modename in
6114 if always
|| h <> dh
6116 if Hashtbl.length
h > 0
6118 if Buffer.length
bb > 0
6119 then Buffer.add_char
bb '
\n'
;
6120 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6121 Hashtbl.iter
(fun i
o ->
6122 let isdifferent = always
||
6124 let dO = Hashtbl.find dh i
in
6126 with Not_found
-> true
6131 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6132 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6133 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6134 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6135 Buffer.add_string
bb (Wsi.keyname
k);
6138 let rec loop = function
6140 | km
:: [] -> addkm km
6141 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6145 Buffer.add_string
bb "<map in='";
6149 Buffer.add_string
bb "' out='";
6151 Buffer.add_string
bb "'/>\n"
6154 Buffer.add_string
bb "' out='";
6156 Buffer.add_string
bb "'/>\n"
6158 | KMmulti
(ins, kms
) ->
6159 Buffer.add_char
bb ' '
;
6161 Buffer.add_string
bb "' out='";
6163 Buffer.add_string
bb "'/>\n"
6165 Buffer.add_string
bb "</keymap>";
6175 let uifontsize = fstate.fontsize
in
6176 let bb = Buffer.create
32768 in
6178 let dc = if conf.bedefault
then conf else dc in
6179 Buffer.add_string
bb "<llppconfig>\n";
6181 if String.length
!fontpath > 0
6183 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6189 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6192 Buffer.add_string
bb "<defaults ";
6193 add_attrs bb true dc dc;
6194 let kb = keymapsbuf true dc dc in
6195 if Buffer.length
kb > 0
6197 Buffer.add_string
bb ">\n";
6198 Buffer.add_buffer
bb kb;
6199 Buffer.add_string
bb "\n</defaults>\n";
6201 else Buffer.add_string
bb "/>\n";
6203 let adddoc path pan
anchor c bookmarks =
6204 if bookmarks == [] && c = dc && anchor = emptyanchor
6207 Printf.bprintf
bb "<doc path='%s'"
6208 (enent
path 0 (String.length
path));
6210 if anchor <> emptyanchor
6212 let n, y = anchor in
6213 Printf.bprintf
bb " page='%d'" n;
6216 Printf.bprintf
bb " rely='%f'" y
6221 then Printf.bprintf
bb " pan='%d'" pan
;
6223 add_attrs bb false dc c;
6224 let kb = keymapsbuf false dc c in
6226 begin match bookmarks with
6228 if Buffer.length
kb > 0
6230 Buffer.add_string
bb ">\n";
6231 Buffer.add_buffer
bb kb;
6232 Buffer.add_string
bb "</doc>\n";
6234 else Buffer.add_string
bb "/>\n"
6236 Buffer.add_string
bb ">\n<bookmarks>\n";
6237 List.iter
(fun (title, _level
, (page, rely)) ->
6239 "<item title='%s' page='%d'"
6240 (enent
title 0 (String.length
title))
6245 Printf.bprintf
bb " rely='%f'" rely
6247 Buffer.add_string
bb "/>\n";
6249 Buffer.add_string
bb "</bookmarks>";
6250 if Buffer.length
kb > 0
6252 Buffer.add_string
bb "\n";
6253 Buffer.add_buffer
bb kb;
6255 Buffer.add_string
bb "\n</doc>\n";
6261 match state.mode with
6262 | Birdseye
(c, pan, _, _, _) ->
6264 match conf.columns
with
6265 | Some
((c, _, _), _) -> Some
c
6268 match c.columns
with
6269 | Some
(c, _) -> Some
(c, [||])
6272 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6273 | _ -> state.x, conf
6275 let basename = Filename.basename state.path in
6276 adddoc basename pan (getanchor ())
6279 match state.autoscroll
with
6281 | None
-> conf.autoscrollstep
}
6282 (if conf.savebmarks
then state.bookmarks else []);
6284 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6286 then adddoc path x y c bookmarks
6288 Buffer.add_string
bb "</llppconfig>";
6291 if Buffer.length
bb > 0
6294 let tmp = !confpath ^
".tmp" in
6295 let oc = open_out_bin
tmp in
6296 Buffer.output_buffer
oc bb;
6298 Unix.rename
tmp !confpath;
6301 ("error while saving configuration: " ^
Printexc.to_string exn
)
6308 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6309 "<password> Set password");
6311 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6312 "<path> Set path to the user interface font");
6314 ("-c", Arg.String
(fun s -> Config.confpath := s),
6315 "<path> Set path to the configuration file");
6317 ("-v", Arg.Unit
(fun () ->
6319 "%s\nconfiguration path: %s\n"
6323 exit
0), " Print version and exit");
6326 (fun s -> state.path <- s)
6327 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6329 if String.length
state.path = 0
6330 then (prerr_endline
"file name missing"; exit
1);
6334 let globalkeyhash = findkeyhash conf "global" in
6335 let wsfd, winw, winh
= Wsi.init
(object
6337 if nogeomcmds state.geomcmds
6339 method display = display ()
6340 method reshape w h = reshape w h
6341 method mouse b d x y m = mouse b d x y m
6342 method motion x y = state.mpos
<- (x, y); motion x y
6343 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6345 let mascm = m land (
6346 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6348 match state.keystate
with
6350 let km = k, mascm in
6353 try Hashtbl.find globalkeyhash km
6355 let modehash = state.uioh#
modehash in
6356 try Hashtbl.find modehash km
6357 with Not_found
-> KMinsrt
(k, m)
6359 | KMinsrt
(k, m) -> keyboard k m
6360 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6361 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6363 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6364 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6365 state.keystate
<- KSnone
6366 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6367 state.keystate
<- KSinto
(keys
, insrt
)
6369 state.keystate
<- KSnone
6371 method enter
x y = state.mpos
<- (x, y); pmotion x y
6372 method leave = state.mpos
<- (-1, -1)
6373 method quit
= raise Quit
6374 end) conf.winw conf.winh
in
6379 List.exists
GlMisc.check_extension
6380 [ "GL_ARB_texture_rectangle"
6381 ; "GL_EXT_texture_recangle"
6382 ; "GL_NV_texture_rectangle" ]
6384 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6386 let cr, sw = Unix.pipe
()
6387 and sr
, cw
= Unix.pipe
() in
6394 setcheckers conf.checkers
;
6398 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6399 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6404 state.text <- "Opening " ^
state.path;
6405 opendoc state.path state.password
;
6407 setfontsize fstate.fontsize
;
6410 let rec loop deadline
=
6412 match state.errfd
with
6413 | None
-> [state.sr
; state.wsfd]
6414 | Some fd
-> [state.sr
; state.wsfd; fd
]
6418 state.redisplay
<- false;
6425 if deadline
= infinity
6427 else max
0.0 (deadline
-. now)
6432 try Unix.select
r [] [] timeout
6433 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6439 if state.ghyll
== noghyll
6441 match state.autoscroll
with
6442 | Some step
when step
!= 0 ->
6443 let y = state.y + step
in
6447 else if y >= state.maxy then 0 else y
6450 if state.mode = View
6451 then state.text <- "";
6454 else deadline
+. 0.01
6459 let rec checkfds = function
6461 | fd
:: rest
when fd
= state.sr
->
6462 let cmd = readcmd state.sr
in
6466 | fd
:: rest
when fd
= state.wsfd ->
6471 let s = String.create
80 in
6472 let n = Unix.read fd
s 0 80 in
6473 if conf.redirectstderr
6475 Buffer.add_substring
state.errmsgs
s 0 n;
6476 state.newerrmsgs
<- true;
6477 state.redisplay
<- true;
6480 prerr_string
(String.sub
s 0 n);
6488 if deadline
= infinity
6492 match state.autoscroll
with
6493 | Some step
when step
!= 0 -> deadline1
6494 | _ -> if state.ghyll
== noghyll then infinity
else deadline1