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
46 | Lfound
of (int * int * int * int * int)
50 | LDfirstvisible
of (int * int * int)
65 | KMmulti
of key list
* key list
67 and keyhash
= (key
, keymap
) Hashtbl.t
70 | KSinto
of (key list
* key list
)
73 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
74 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
76 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
78 external init
: pipe
-> params
-> unit = "ml_init";;
79 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
80 external copysel
: string -> opaque
-> unit = "ml_copysel";;
81 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
82 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
83 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
84 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
85 external measurestr
: int -> string -> float = "ml_measure_string";;
86 external getmaxw
: unit -> float = "ml_getmaxw";;
87 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
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 ignore
(drawstr size x y s
);
168 Gl.disable `texture_2d
;
171 let drawstring1 size x y s
=
175 let drawstring2 size x y fmt
=
176 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
179 let cbcap b
= Array.length b
.store
;;
184 b
.wc
<- (b
.wc
+ 1) mod cap;
186 b
.len
<- min
(b
.len
+ 1) cap;
189 let cbempty b
= b
.len
= 0;;
191 let cbgetg b circular dir
=
195 let rc = b
.rc + dir
in
207 else max
0 (min
rc (b
.len
-1))
213 let cbget b
= cbgetg b
false;;
214 let cbgetc b
= cbgetg b
true;;
231 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
232 dolog " WxH %dx%d" l
.pagew l
.pageh
;
233 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
234 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
235 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
239 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
241 dolog " x0,y0=(% f, % f)" x0 y0
;
242 dolog " x1,y1=(% f, % f)" x1 y1
;
243 dolog " x2,y2=(% f, % f)" x2 y2
;
244 dolog " x3,y3=(% f, % f)" x3 y3
;
249 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
250 and multicol
= columncount
* covercount
* covercount
252 and columncount
= int
253 and covercount
= int;;
256 { mutable scrollbw
: int
257 ; mutable scrollh
: int
258 ; mutable icase
: bool
259 ; mutable preload
: bool
260 ; mutable pagebias
: int
261 ; mutable verbose
: bool
262 ; mutable debug
: bool
263 ; mutable scrollstep
: int
264 ; mutable maxhfit
: bool
265 ; mutable crophack
: bool
266 ; mutable autoscrollstep
: int
267 ; mutable maxwait
: float option
268 ; mutable hlinks
: bool
269 ; mutable underinfo
: bool
270 ; mutable interpagespace
: interpagespace
271 ; mutable zoom
: float
272 ; mutable presentation
: bool
273 ; mutable angle
: angle
276 ; mutable savebmarks
: bool
277 ; mutable proportional
: proportional
278 ; mutable trimmargins
: trimmargins
279 ; mutable trimfuzz
: irect
280 ; mutable memlimit
: memsize
281 ; mutable texcount
: texcount
282 ; mutable sliceheight
: sliceheight
283 ; mutable thumbw
: width
284 ; mutable jumpback
: bool
285 ; mutable bgcolor
: float * float * float
286 ; mutable bedefault
: bool
287 ; mutable scrollbarinpm
: bool
288 ; mutable tilew
: int
289 ; mutable tileh
: int
290 ; mutable mustoresize
: memsize
291 ; mutable checkers
: bool
292 ; mutable aalevel
: int
293 ; mutable urilauncher
: string
294 ; mutable pathlauncher
: string
295 ; mutable colorspace
: colorspace
296 ; mutable invert
: bool
297 ; mutable colorscale
: float
298 ; mutable redirectstderr
: bool
299 ; mutable ghyllscroll
: (int * int * int) option
300 ; mutable columns
: columns
option
301 ; mutable beyecolumns
: columncount
option
302 ; mutable selcmd
: string
303 ; mutable updatecurs
: bool
304 ; mutable keyhashes
: (string * keyhash
) list
308 type anchor
= pageno
* top
;;
310 type outline
= string * int * anchor
;;
312 type rect
= float * float * float * float * float * float * float * float;;
314 type tile
= opaque
* pixmapsize
* elapsed
315 and elapsed
= float;;
316 type pagemapkey
= pageno
* gen
;;
317 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
321 let emptyanchor = (0, 0.0);;
323 type infochange
= | Memused
| Docinfo
| Pdim
;;
325 class type uioh
= object
326 method display
: unit
327 method key
: int -> int -> uioh
328 method button
: int -> bool -> int -> int -> int -> uioh
329 method motion
: int -> int -> uioh
330 method pmotion
: int -> int -> uioh
331 method infochanged
: infochange
-> unit
332 method scrollpw
: (int * float * float)
333 method scrollph
: (int * float * float)
334 method modehash
: keyhash
338 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
339 | Textentry
of (textentry
* onleave
)
341 | LinkNav
of (linktarget
* string)
342 and onleave
= leavetextentrystatus
-> unit
343 and leavetextentrystatus
= | Cancel
| Confirm
344 and helpitem
= string * int * action
347 | Action
of (uioh
-> uioh
)
349 | Ltexact
of ((page
* opaque
* int) * (int * int * int * int))
353 let isbirdseye = function Birdseye _
-> true | _
-> false;;
354 let istextentry = function Textentry _
-> true | _
-> false;;
358 | Loading
of (page
* gen
)
360 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
362 | Outlining
of outline list
365 let emptykeyhash = Hashtbl.create
0;;
366 let nouioh : uioh
= object (self
)
368 method key _ _
= self
369 method button _ _ _ _ _
= self
370 method motion _ _
= self
371 method pmotion _ _
= self
372 method infochanged _
= ()
373 method scrollpw
= (0, nan
, nan
)
374 method scrollph
= (0, nan
, nan
)
375 method modehash
= emptykeyhash
379 { mutable sr
: Unix.file_descr
380 ; mutable sw
: Unix.file_descr
381 ; mutable wsfd
: Unix.file_descr
382 ; mutable errfd
: Unix.file_descr
option
383 ; mutable stderr
: Unix.file_descr
384 ; mutable errmsgs
: Buffer.t
385 ; mutable newerrmsgs
: bool
389 ; mutable scrollw
: int
390 ; mutable hscrollh
: int
391 ; mutable anchor
: anchor
392 ; mutable ranchors
: (string * string * anchor
) list
394 ; mutable layout
: page list
395 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
396 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
397 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
398 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
399 ; mutable pagecount
: int
400 ; mutable currently
: currently
401 ; mutable mstate
: mstate
402 ; mutable searchpattern
: string
403 ; mutable rects
: (pageno
* recttype
* rect
) list
404 ; mutable rects1
: (pageno
* recttype
* rect
) list
405 ; mutable text
: string
406 ; mutable fullscreen
: (width
* height
) option
407 ; mutable mode
: mode
408 ; mutable uioh
: uioh
409 ; mutable outlines
: outline array
410 ; mutable bookmarks
: outline list
411 ; mutable path
: string
412 ; mutable password
: string
413 ; mutable invalidated
: int
414 ; mutable memused
: memsize
416 ; mutable throttle
: (page list
* int * float) option
417 ; mutable autoscroll
: int option
418 ; mutable ghyll
: (int option -> unit)
419 ; mutable help
: helpitem array
420 ; mutable docinfo
: (int * string) list
421 ; mutable texid
: GlTex.texture_id
option
423 ; mutable prevzoom
: float
424 ; mutable progress
: float
425 ; mutable redisplay
: bool
426 ; mutable mpos
: mpos
427 ; mutable keystate
: keystate
430 { pat
: string circbuf
431 ; pag
: string circbuf
432 ; nav
: anchor circbuf
433 ; sel
: string circbuf
454 ; presentation
= false
459 ; proportional
= true
460 ; trimmargins
= false
461 ; trimfuzz
= (0,0,0,0)
462 ; memlimit
= 32 lsl 20
467 ; bgcolor
= (0.5, 0.5, 0.5)
469 ; scrollbarinpm
= true
472 ; mustoresize
= 128 lsl 20
477 | Plinux
| Pfreebsd
| Pdragonflybsd
478 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
479 | Posx
-> "open \"%s\""
480 | Pcygwin
-> "cygstart %s"
481 | Punknown
-> "echo %s")
482 ; pathlauncher
= "lp \"%s\""
485 | Plinux
| Pfreebsd
| Pdragonflybsd
486 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
493 ; redirectstderr
= false
499 let mk n
= (n
, Hashtbl.create
1) in
512 let findkeyhash c name
=
513 try List.assoc name c
.keyhashes
514 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
517 let conf = { defconf with angle
= defconf.angle
};;
520 { mutable fontsize
: int
521 ; mutable wwidth
: float
522 ; mutable maxrows
: int
534 fstate.fontsize
<- n
;
535 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
536 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
540 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
541 let len = String.length s
in
542 if colonpos >= 0 && colonpos + 3 < len
544 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
547 try String.rindex_from s
colonpos ' '
551 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
554 | "http" | "ftp" | "mailto" ->
556 try String.index_from s
colonpos ' '
557 with Not_found
-> len
559 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
567 let shell, farg
= "/bin/sh", "-c" in
569 let args = [|shell; farg
; s
|] in
570 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
574 if String.length
conf.urilauncher
= 0
575 then print_endline uri
577 let url = geturl uri
in
578 if String.length
url = 0
579 then print_endline uri
581 let re = Str.regexp
"%s" in
582 let command = Str.global_replace
re url conf.urilauncher
in
586 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
592 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
593 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
597 let strings = version () :: "" :: Help.keys
in
600 let url = geturl s
in
601 if String.length
url > 0
602 then (s
, 0, Action
(fun u
-> gotouri url; u
))
603 else (s
, 0, Noaction
)
614 ; stderr
= Unix.stderr
615 ; errmsgs
= Buffer.create
0
622 ; anchor
= emptyanchor
626 ; tilelru
= Queue.create
()
627 ; pagemap
= Hashtbl.create
10
628 ; tilemap
= Hashtbl.create
10
645 { nav
= cbnew 10 (0, 0.0)
670 Printf.kprintf prerr_endline fmt
672 Printf.kprintf ignore fmt
676 if String.length
conf.pathlauncher
= 0
677 then print_endline
state.path
679 let re = Str.regexp
"%s" in
680 let command = Str.global_replace
re state.path
conf.pathlauncher
in
684 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
689 let redirectstderr () =
690 if conf.redirectstderr
692 let rfd, wfd
= Unix.pipe
() in
693 state.stderr
<- Unix.dup
Unix.stderr
;
694 state.errfd
<- Some
rfd;
695 Unix.dup2 wfd
Unix.stderr
;
697 state.newerrmsgs
<- false;
698 begin match state.errfd
with
701 Unix.dup2
state.stderr
Unix.stderr
;
705 prerr_string
(Buffer.contents
state.errmsgs
);
707 Buffer.clear
state.errmsgs
;
713 let postRedisplay who
=
715 then prerr_endline
("redisplay for " ^ who
);
716 state.redisplay
<- true;
720 let getopaque pageno
=
721 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
722 with Not_found
-> None
725 let putopaque pageno opaque
=
726 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
729 let pagetranslatepoint l x y
=
730 let dy = y
- l
.pagedispy
in
731 let y = dy + l
.pagey
in
732 let dx = x
- l
.pagedispx
in
733 let x = dx + l
.pagex
in
740 begin match getopaque l
.pageno
with
742 let x0 = l
.pagedispx
in
743 let x1 = x0 + l
.pagevw
in
744 let y0 = l
.pagedispy
in
745 let y1 = y0 + l
.pagevh
in
746 if y >= y0 && y <= y1 && x >= x0 && x <= x1
748 let px, py
= pagetranslatepoint l
x y in
749 match whatsunder opaque
px py
with
762 state.text
<- Printf.sprintf
"%c%s" c s
;
763 G.postRedisplay "showtext";
766 let updateunder x y =
767 match getunder x y with
768 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
770 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
771 Wsi.setcursor
Wsi.CURSOR_INFO
772 | Ulinkgoto
(page
, _
) ->
774 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
775 Wsi.setcursor
Wsi.CURSOR_INFO
777 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
778 Wsi.setcursor
Wsi.CURSOR_TEXT
780 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
781 Wsi.setcursor
Wsi.CURSOR_INHERIT
783 if conf.underinfo
then showtext 'l'
("launch: " ^ s
);
784 Wsi.setcursor
Wsi.CURSOR_INHERIT
786 if conf.underinfo
then showtext 'n'
("named: " ^ s
);
787 Wsi.setcursor
Wsi.CURSOR_INHERIT
788 | Uremote
(filename
, pageno
) ->
789 if conf.underinfo
then showtext 'r'
790 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
791 Wsi.setcursor
Wsi.CURSOR_INFO
795 let b = Buffer.create
(String.length s
+ 1) in
796 Buffer.add_string
b s
;
801 let colorspace_of_string s
=
802 match String.lowercase s
with
806 | _
-> failwith
"invalid colorspace"
809 let int_of_colorspace = function
815 let colorspace_of_int = function
819 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
822 let colorspace_to_string = function
828 let intentry_with_suffix text key
=
830 if key
>= 32 && key
< 127
834 match Char.lowercase
c with
836 let text = addchar text c in
840 let text = addchar text c in
844 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
848 let columns_to_string (n
, a
, b) =
850 then Printf.sprintf
"%d" n
851 else Printf.sprintf
"%d,%d,%d" n a
b;
854 let columns_of_string s
=
856 (int_of_string s
, 0, 0)
858 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
863 let n = Unix.read fd
s 0 4 in
864 if n != 4 then failwith
"incomplete read(len)";
866 lor (Char.code
s.[0] lsl 24)
867 lor (Char.code
s.[1] lsl 16)
868 lor (Char.code
s.[2] lsl 8)
869 lor (Char.code
s.[3] lsl 0)
871 let s = String.create
len in
872 let n = Unix.read fd
s 0 len in
873 if n != len then failwith
"incomplete read(data)";
877 let btod b = if b then 1 else 0;;
880 let b = Buffer.create
16 in
881 Buffer.add_string
b "llll";
884 let s = Buffer.contents
b in
885 let n = String.length
s in
887 s.[0] <- Char.chr
((len lsr 24) land 0xff);
888 s.[1] <- Char.chr
((len lsr 16) land 0xff);
889 s.[2] <- Char.chr
((len lsr 8) land 0xff);
890 s.[3] <- Char.chr
(len land 0xff);
891 let n'
= Unix.write
state.sw
s 0 n in
892 if n'
!= n then failwith
"write failed";
899 let d = conf.winh
- h
in
906 let rec f pn ph pi fh l
=
908 | (n, _
, h
, _
) :: rest
->
909 let ips = calcips h
in
914 if isbirdseye state.mode
&& pn
= 0
919 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
924 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
928 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
931 let fh = f 0 0 0 0 state.pdims
in
936 match conf.columns
with
937 | None
-> calcheight ()
939 if Array.length
b > 0
941 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
946 let getpageyh pageno
=
947 let rec f pn ph pi
y l
=
949 | (n, _
, h
, _
) :: rest
->
950 let ips = calcips h
in
953 let h = if n = pageno
then h else ph
in
954 if conf.presentation
&& n = pageno
956 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
958 y + (pageno
- pn
) * (ph
+ pi
), h
960 let y = y + (if conf.presentation
then pi
else 0) in
961 let y = y + (n - pn
) * (ph
+ pi
) in
965 y + (pageno
- pn
) * (ph
+ pi
), ph
967 f 0 0 0 0 state.pdims
970 let getpageyh pageno
=
971 match conf.columns
with
972 | None
-> getpageyh pageno
974 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
978 let getpagedim pageno
=
981 | (n, _
, _
, _
) as pdim
:: rest
->
983 then (if n = pageno
then pdim
else ppdim
)
988 f (-1, -1, -1, -1) state.pdims
991 let getpagey pageno
= fst
(getpageyh pageno
);;
994 let sh = sh - state.hscrollh
in
995 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
996 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
998 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
999 let ips = calcips h in
1001 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1005 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1007 prev
, pdims
, pdimno
, 0
1009 let dy = dy + yinc in
1010 let py = py + yinc in
1011 if pageno
= state.pagecount
|| dy >= sh
1016 if py + h <= vy - yinc
1018 let py = py + h + ips in
1019 let dy = max
0 (py - y) in
1020 f ~pageno
:(pageno
+1)
1028 let pagey = vy - py in
1029 let pagevh = h - pagey in
1030 let pagevh = min
(sh - dy) pagevh in
1031 let off = if yinc > 0 then py - vy else 0 in
1032 let py = py + h + ips in
1035 if state.w
< conf.winw
- state.scrollw
1036 then (conf.winw
- state.scrollw
- state.w
) / 2
1039 let dispx = xoff + state.x in
1045 let lw = w
- pagex in
1046 min
lw (conf.winw
- state.scrollw
)
1050 ; pagedimno
= pdimno
1054 ; pagey = pagey + off
1056 ; pagevh = pagevh - off
1058 ; pagedispy
= dy + off
1061 let accu = e :: accu in
1062 f ~pageno
:(pageno
+1)
1070 if state.invalidated
= 0
1088 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1089 let sh = sh - state.hscrollh
in
1090 let rec fold accu n =
1091 if n = Array.length
b
1094 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1097 || n = state.pagecount
- coverB
1098 || (n - coverA
) mod columns
= columns
- 1)
1104 let pagey = max
0 (y - vy) in
1105 let pagedispy = if pagey > 0 then 0 else vy - y in
1106 let pagedispx, pagex, pagevw =
1108 if n = coverA
- 1 || n = state.pagecount
- coverB
1109 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1110 else dx + xoff + state.x
1113 then 0, -pdx, w
+ pdx
1114 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1116 let pagevh = min
(h - pagey) (sh - pagedispy) in
1117 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1121 ; pagedimno
= pdimno
1128 ; pagedispx = pagedispx
1129 ; pagedispy = pagedispy
1140 if state.invalidated
= 0
1141 then List.rev
(fold [] 0)
1146 match conf.columns
with
1147 | None
-> layout1 y sh
1148 | Some
c -> layoutN c y sh
1152 let y = state.y + incr
in
1154 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1159 let tilex = l
.pagex mod conf.tilew
in
1160 let tiley = l
.pagey mod conf.tileh
in
1162 let col = l
.pagex / conf.tilew
in
1163 let row = l
.pagey / conf.tileh
in
1166 let a = l
.pagew
- l
.pagex in
1167 let b = conf.winw
- state.scrollw
in
1169 and vh
= l
.pagevh in
1171 let rec rowloop row y0 dispy
h =
1175 let dh = conf.tileh
- y0 in
1176 let dh = min
h dh in
1177 let rec colloop col x0 dispx w
=
1181 let dw = conf.tilew
- x0 in
1182 let dw = min w
dw in
1184 f col row dispx dispy
x0 y0 dw dh;
1185 colloop (col+1) 0 (dispx+dw) (w
-dw)
1188 colloop col tilex l
.pagedispx vw;
1189 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1193 then rowloop row tiley l
.pagedispy vh
;
1196 let gettileopaque l
col row =
1198 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1200 try Some
(Hashtbl.find
state.tilemap
key)
1201 with Not_found
-> None
1204 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1205 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1206 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1209 let drawtiles l color
=
1211 let f col row x y tilex tiley w
h =
1212 match gettileopaque l
col row with
1213 | Some
(opaque
, _
, t
) ->
1214 let params = x, y, w
, h, tilex, tiley in
1218 GlFunc.blend_func `zero `one_minus_src_color
;
1220 drawtile
params opaque
;
1222 then Gl.disable `blend
;
1225 let s = Printf.sprintf
1229 let w = measurestr
fstate.fontsize
s in
1230 GlMisc.push_attrib
[`current
];
1231 GlDraw.color
(0.0, 0.0, 0.0);
1233 (float (x-2), float (y-2))
1234 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1235 GlDraw.color
(1.0, 1.0, 1.0);
1236 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1237 GlMisc.pop_attrib
();
1242 let lw = conf.winw
- state.scrollw
- x in
1245 let lh = conf.winh
- y in
1248 Gl.enable `texture_2d
;
1249 begin match state.texid
with
1251 GlTex.bind_texture `texture_2d id
;
1254 and x1 = float (x+w)
1255 and y1 = float (y+h) in
1257 let tw = float w /. 64.0
1258 and th
= float h /. 64.0 in
1259 let tx0 = float tilex /. 64.0
1260 and ty0
= float tiley /. 64.0 in
1262 and ty1
= ty0
+. th
in
1263 GlDraw.begins `quads
;
1264 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1265 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1266 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1267 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1270 Gl.disable `texture_2d
;
1272 GlDraw.color
(1.0, 1.0, 1.0);
1275 (float (x+w), float (y+h));
1277 if w > 128 && h > fstate.fontsize
+ 10
1279 GlDraw.color
(0.0, 0.0, 0.0);
1282 then (col*conf.tilew
, row*conf.tileh
)
1285 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1292 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1294 let tilevisible1 l
x y =
1296 and ax1
= l
.pagex + l
.pagevw
1298 and ay1
= l
.pagey + l
.pagevh in
1302 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1303 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1305 let rx0 = max
ax0 bx0
1306 and ry0
= max ay0 by0
1307 and rx1
= min ax1
bx1
1308 and ry1
= min ay1 by1
in
1310 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1311 nonemptyintersection
1314 let tilevisible layout n x y =
1315 let rec findpageinlayout = function
1316 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1317 | _
:: rest
-> findpageinlayout rest
1320 findpageinlayout layout
1323 let tileready l
x y =
1324 tilevisible1 l
x y &&
1325 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1328 let tilepage n p
layout =
1329 let rec loop = function
1333 let f col row _ _ _ _ _ _
=
1334 if state.currently
= Idle
1336 match gettileopaque l
col row with
1339 let x = col*conf.tilew
1340 and y = row*conf.tileh
in
1342 let w = l
.pagew
- x in
1346 let h = l
.pageh
- y in
1349 wcmd "tile %s %d %d %d %d" p
x y w h;
1352 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1353 conf.tilew
, conf.tileh
1362 if state.invalidated
= 0 then loop layout;
1365 let preloadlayout visiblepages
=
1366 let presentation = conf.presentation in
1367 let interpagespace = conf.interpagespace in
1368 let maxy = state.maxy in
1369 conf.presentation <- false;
1370 conf.interpagespace <- 0;
1371 state.maxy <- calcheight ();
1373 match visiblepages
with
1375 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1377 let y = if y < conf.winh
then 0 else y - conf.winh
in
1378 let h = state.y - y + conf.winh
*3 in
1379 let pages = layout y h in
1380 conf.presentation <- presentation;
1381 conf.interpagespace <- interpagespace;
1387 let rec loop pages =
1388 if state.currently
!= Idle
1393 begin match getopaque l
.pageno
with
1395 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1396 state.currently
<- Loading
(l
, state.gen
);
1398 tilepage l
.pageno opaque
pages;
1403 if state.invalidated
= 0 then loop pages
1408 if conf.preload && state.currently
= Idle
1409 then load (preloadlayout pages);
1412 let layoutready layout =
1413 let rec fold all ls
=
1414 all
&& match ls
with
1416 let seen = ref false in
1417 let allvisible = ref true in
1418 let foo col row _ _ _ _ _ _
=
1420 allvisible := !allvisible &&
1421 begin match gettileopaque l
col row with
1427 fold (!seen && !allvisible) rest
1430 let alltilesvisible = fold true layout in
1435 let y = bound y 0 state.maxy in
1436 let y, layout, proceed
=
1437 match conf.maxwait
with
1438 | Some time
when state.ghyll
== noghyll ->
1439 begin match state.throttle
with
1441 let layout = layout y conf.winh
in
1442 let ready = layoutready layout in
1446 state.throttle
<- Some
(layout, y, now ());
1448 else G.postRedisplay "gotoy showall (None)";
1450 | Some
(_
, _
, started
) ->
1451 let dt = now () -. started
in
1454 state.throttle
<- None
;
1455 let layout = layout y conf.winh
in
1457 G.postRedisplay "maxwait";
1464 let layout = layout y conf.winh
in
1465 if true || layoutready layout
1466 then G.postRedisplay "gotoy ready";
1472 state.layout <- layout;
1473 begin match state.mode
with
1474 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1475 if not
(pagevisible layout pageno
)
1477 match state.layout with
1480 state.mode
<- Birdseye
(
1481 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1484 | LinkNav
((Ltgendir dir
as lt
, pattern
)) ->
1486 let rec loop = function
1489 match getopaque l
.pageno
with
1493 findlink opaque
(LDfirstvisible
(l
.pagex, l
.pagey, dir
))
1496 | Lnolock
-> showtext '
!'
"failed to acquire lock"; lt
1497 | Lnotfound
-> loop rest
1498 | Lfound
(n, x0, y0, x1, y1) ->
1499 Ltexact
((l
, opaque
, n), (x0, y0, x1, y1))
1503 state.mode
<- LinkNav
(linknav, pattern
)
1508 state.ghyll
<- noghyll;
1511 let conttiling pageno opaque
=
1512 tilepage pageno opaque
1513 (if conf.preload then preloadlayout state.layout else state.layout)
1516 let gotoy_and_clear_text y =
1518 if not
conf.verbose
then state.text <- "";
1522 match state.layout with
1524 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1527 let getanchory (n, top
) =
1528 let y, h = getpageyh n in
1529 y + (truncate
(top
*. float h));
1532 let gotoanchor anchor
=
1533 gotoy (getanchory anchor
);
1537 cbput state.hists
.nav
(getanchor ());
1541 let anchor = cbgetc state.hists
.nav dir
in
1546 let rec scroll f n a b =
1547 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1549 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1551 then s (float f /. float a)
1554 then 1.0 -. s ((float (f-b) /. float (n-b)))
1561 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1562 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1564 let ins = float a *. iv1
1565 and outs
= float (n-b) *. iv1 in
1567 ins +. outs
+. float ones
1569 let rec set (_N
, _A
, _B
) y sy
=
1570 let sum = summa
1.0 _N _A _B
in
1571 let dy = float (y - sy
) in
1575 then state.ghyll
<- noghyll
1578 let s = scroll n _N _A _B
in
1579 let y1 = y1 +. ((s *. dy) /. sum) in
1580 gotoy_and_clear_text (truncate
y1);
1581 state.ghyll
<- gf (n+1) y1;
1585 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1587 gf 0 (float state.y)
1590 match conf.ghyllscroll
with
1592 gotoy_and_clear_text y
1594 if state.ghyll
== noghyll
1595 then set nab
y state.y
1596 else state.ghyll
(Some
y)
1599 let gotopage n top
=
1600 let y, h = getpageyh n in
1601 let y = y + (truncate
(top
*. float h)) in
1605 let gotopage1 n top
=
1606 let y = getpagey n in
1616 state.invalidated
<- state.invalidated
+ 1;
1619 let writeopen path password
=
1620 wcmd "open %s\000%s\000" path password
;
1623 let opendoc path password
=
1626 state.password
<- password
;
1627 state.gen
<- state.gen
+ 1;
1628 state.docinfo
<- [];
1630 setaalevel
conf.aalevel
;
1631 writeopen path password
;
1632 Wsi.settitle
("llpp " ^
Filename.basename path
);
1633 wcmd "geometry %d %d" state.w conf.winh
;
1637 let c = c *. conf.colorscale
in
1641 let scalecolor2 (r
, g
, b) =
1642 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1646 let docolumns = function
1648 | Some
((columns
, coverA
, coverB
), _
) ->
1649 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1650 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1651 if pageno
= state.pagecount
1654 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1656 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1657 pdimno+1, pdim
, rest
1662 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1664 (conf.winw
- state.scrollw
- w) / 2,
1665 y + rowh
+ conf.interpagespace, h
1668 if (pageno
- coverA
) mod columns
= 0
1669 then 0, y + rowh
+ conf.interpagespace, h
1670 else x, y, max rowh
h
1673 let rec fixrow m
= if m
= pageno
then () else
1674 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1677 let y = y + (rowh
- h) / 2 in
1678 a.(m
) <- (pdimno, x, y, pdim
);
1682 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1683 then fixrow (pageno
- columns
);
1684 a.(pageno
) <- (pdimno, x, y, pdim
);
1685 let x = x + w + xoff*2 + conf.interpagespace in
1686 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1688 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1689 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1691 docolumns conf.columns
;
1692 state.maxy <- calcheight ();
1694 if state.w <= conf.winw
- state.scrollw
1698 match state.mode
with
1699 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1700 let y, h = getpageyh pageno
in
1701 let top = (conf.winh
- h) / 2 in
1702 gotoy (max
0 (y - top))
1703 | _
-> gotoanchor state.anchor
1707 let firsttime = ref true in
1709 GlDraw.viewport
0 0 w h;
1710 if state.invalidated
= 0 && not
!firsttime
1711 then state.anchor <- getanchor ();
1715 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1719 setfontsize fstate.fontsize
;
1720 GlMat.mode `modelview
;
1721 GlMat.load_identity
();
1723 GlMat.mode `projection
;
1724 GlMat.load_identity
();
1725 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1726 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1727 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1730 match conf.columns
with
1732 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1735 wcmd "geometry %d %d" w h;
1739 let len = String.length
state.text in
1742 match state.mode
with
1743 | View
-> state.hscrollh
1748 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1749 (x+.w, float (conf.winh
- hscrollh))
1752 let w = float (conf.winw
- state.scrollw
- 1) in
1753 if state.progress
>= 0.0 && state.progress
< 1.0
1755 GlDraw.color
(0.3, 0.3, 0.3);
1756 let w1 = w *. state.progress
in
1758 GlDraw.color
(0.0, 0.0, 0.0);
1762 GlDraw.color
(0.0, 0.0, 0.0);
1766 GlDraw.color
(1.0, 1.0, 1.0);
1767 drawstring fstate.fontsize
1768 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1771 match state.mode
with
1772 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1776 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1778 Printf.sprintf
"%s%s_" prefix
text
1787 if not
(istextentry state.mode
)
1789 let s1 = "(press 'e' to review error messasges)" in
1790 if String.length
s > 0 then s ^
" " ^
s1 else s1
1795 if String.length
s > 0
1800 let len = Queue.length
state.tilelru
in
1802 if state.memused
<= conf.memlimit
1807 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1808 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1809 let (_
, pw
, ph
, _
) = getpagedim n in
1812 && colorspace
= conf.colorspace
1813 && angle
= conf.angle
1818 match state.throttle
with
1821 then preloadlayout state.layout
1823 | Some
(layout, _
, _
) ->
1826 let x = col*conf.tilew
1827 and y = row*conf.tileh
in
1828 tilevisible layout n x y
1830 then Queue.push lruitem
state.tilelru
1832 wcmd "freetile %s" p
;
1833 state.memused
<- state.memused
- s;
1834 state.uioh#infochanged Memused
;
1835 Hashtbl.remove
state.tilemap k
;
1844 Queue.iter
(fun (k
, p
, s) ->
1845 wcmd "freetile %s" p
;
1846 state.memused
<- state.memused
- s;
1847 state.uioh#infochanged Memused
;
1848 Hashtbl.remove
state.tilemap k
;
1850 Queue.clear
state.tilelru
;
1854 let logcurrently = function
1855 | Idle
-> dolog "Idle"
1856 | Loading
(l
, gen
) ->
1857 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1858 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1860 "Tiling %d[%d,%d] page=%s cs=%s angle"
1861 l
.pageno
col row pageopaque
1862 (colorspace_to_string colorspace
)
1864 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1865 angle gen
conf.angle
state.gen
1867 conf.tilew
conf.tileh
1874 (* dolog "%S" cmds; *)
1877 try String.index cmds ' '
1878 with Not_found
-> -1
1883 let l = String.length cmds
in
1884 let op = String.sub cmds
0 spacepos in
1886 if l - spacepos < 2 then ""
1887 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1892 state.uioh#infochanged Pdim
;
1896 state.rects
<- state.rects1
;
1897 G.postRedisplay "clearrects";
1901 try Scanf.sscanf
args "%u" (fun n -> n)
1903 dolog "error processing 'continue' %S: %s"
1904 cmds
(Printexc.to_string exn
);
1907 state.pagecount
<- n;
1908 state.invalidated
<- state.invalidated
- 1;
1909 begin match state.currently
with
1911 state.currently
<- Idle
;
1912 state.outlines
<- Array.of_list
(List.rev
l)
1915 if state.invalidated
= 0
1917 if conf.maxwait
= None
1918 then G.postRedisplay "continue";
1928 then showtext ' '
args
1931 let progress, text =
1933 Scanf.sscanf
args "%f %n"
1935 f, String.sub
args pos
(String.length
args - pos
))
1937 dolog "error processing 'progress' %S: %s"
1938 cmds
(Printexc.to_string exn
);
1942 state.progress <- progress;
1943 G.postRedisplay "progress"
1946 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1948 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1949 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1950 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1952 dolog "error processing 'firstmatch' %S: %s"
1953 cmds
(Printexc.to_string exn
);
1956 let y = (getpagey pageno) + truncate
y0 in
1959 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1962 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1964 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1965 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1966 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1968 dolog "error processing 'match' %S: %s"
1969 cmds
(Printexc.to_string exn
);
1973 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1978 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1980 dolog "error processing 'page' %S: %s"
1981 cmds
(Printexc.to_string exn
);
1984 begin match state.currently
with
1985 | Loading
(l, gen
) ->
1986 vlog "page %d took %f sec" l.pageno t
;
1987 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1988 begin match state.throttle
with
1990 let preloadedpages =
1992 then preloadlayout state.layout
1997 Set.Make
(struct type t
= int let compare = (-) end) in
1999 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2000 IntSet.empty
preloadedpages
2003 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2004 if not
(IntSet.mem
pageno set)
2006 wcmd "freepage %s" opaque
;
2012 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2015 state.currently
<- Idle
;
2018 tilepage l.pageno pageopaque state.layout;
2020 load preloadedpages;
2021 if pagevisible state.layout l.pageno
2022 && layoutready state.layout
2023 then G.postRedisplay "page";
2026 | Some
(layout, _
, _
) ->
2027 state.currently
<- Idle
;
2028 tilepage l.pageno pageopaque layout;
2033 dolog "Inconsistent loading state";
2034 logcurrently state.currently
;
2039 let (x, y, opaque
, size
, t
) =
2041 Scanf.sscanf
args "%u %u %s %u %f"
2042 (fun x y p size t
-> (x, y, p
, size
, t
))
2044 dolog "error processing 'tile' %S: %s"
2045 cmds
(Printexc.to_string exn
);
2048 begin match state.currently
with
2049 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2050 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2052 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2054 wcmd "freetile %s" opaque
;
2055 state.currently
<- Idle
;
2059 puttileopaque l col row gen cs angle opaque size t
;
2060 state.memused
<- state.memused
+ size
;
2061 state.uioh#infochanged Memused
;
2063 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2064 opaque
, size
) state.tilelru
;
2067 match state.throttle
with
2068 | None
-> state.layout
2069 | Some
(layout, _
, _
) -> layout
2072 state.currently
<- Idle
;
2074 && conf.colorspace
= cs
2075 && conf.angle
= angle
2076 && tilevisible layout l.pageno x y
2077 then conttiling l.pageno pageopaque;
2079 begin match state.throttle
with
2081 preload state.layout;
2083 && conf.colorspace
= cs
2084 && conf.angle
= angle
2085 && tilevisible state.layout l.pageno x y
2086 then G.postRedisplay "tile nothrottle";
2088 | Some
(layout, y, _
) ->
2089 let ready = layoutready layout in
2093 state.layout <- layout;
2094 state.throttle
<- None
;
2095 G.postRedisplay "throttle";
2102 dolog "Inconsistent tiling state";
2103 logcurrently state.currently
;
2110 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2112 dolog "error processing 'pdim' %S: %s"
2113 cmds
(Printexc.to_string exn
);
2116 state.uioh#infochanged Pdim
;
2117 state.pdims
<- pdim :: state.pdims
2120 let (l, n, t
, h, pos
) =
2122 Scanf.sscanf
args "%u %u %d %u %n"
2123 (fun l n t
h pos
-> l, n, t
, h, pos
)
2125 dolog "error processing 'o' %S: %s"
2126 cmds
(Printexc.to_string exn
);
2129 let s = String.sub
args pos
(String.length
args - pos
) in
2130 let outline = (s, l, (n, float t
/. float h)) in
2131 begin match state.currently
with
2132 | Outlining outlines
->
2133 state.currently
<- Outlining
(outline :: outlines
)
2135 state.currently
<- Outlining
[outline]
2137 dolog "invalid outlining state";
2138 logcurrently currently
2142 state.docinfo
<- (1, args) :: state.docinfo
2145 state.uioh#infochanged Docinfo
;
2146 state.docinfo
<- List.rev
state.docinfo
2149 dolog "unknown cmd `%S'" cmds
2154 let action = function
2155 | HCprev
-> cbget cb ~
-1
2156 | HCnext
-> cbget cb
1
2157 | HCfirst
-> cbget cb ~
-(cb
.rc)
2158 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2159 and cancel
() = cb
.rc <- rc
2163 let search pattern forward
=
2164 if String.length pattern
> 0
2167 match state.layout with
2170 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2172 wcmd "search %d %d %d %d,%s\000"
2173 (btod conf.icase
) pn py (btod forward
) pattern
;
2176 let intentry text key =
2178 if key >= 32 && key < 127
2184 let text = addchar text c in
2188 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2192 let textentry text key =
2193 if key land 0xff00 = 0xff00
2195 else TEcont
(text ^
Wsi.toutf8
key)
2198 let reqlayout angle proportional
=
2199 match state.throttle
with
2201 if state.invalidated
= 0 then state.anchor <- getanchor ();
2202 conf.angle
<- angle
mod 360;
2203 conf.proportional
<- proportional
;
2205 wcmd "reqlayout %d %d" conf.angle
(btod proportional
);
2209 let settrim trimmargins trimfuzz
=
2210 if state.invalidated
= 0 then state.anchor <- getanchor ();
2211 conf.trimmargins
<- trimmargins
;
2212 conf.trimfuzz
<- trimfuzz
;
2213 let x0, y0, x1, y1 = trimfuzz
in
2215 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1;
2216 Hashtbl.iter
(fun _ opaque
->
2217 wcmd "freepage %s" opaque
;
2219 Hashtbl.clear
state.pagemap
;
2223 match state.throttle
with
2225 let zoom = max
0.01 zoom in
2226 if zoom <> conf.zoom
2228 state.prevzoom
<- conf.zoom;
2231 then (state.x <- 0; 0.0)
2232 else float state.x /. float state.w
2235 reshape conf.winw
conf.winh
;
2238 let x = relx *. float state.w in
2239 state.x <- truncate
x;
2241 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2244 | Some
(layout, y, started
) ->
2246 match conf.maxwait
with
2250 let dt = now () -. started
in
2258 let setcolumns columns coverA coverB
=
2261 conf.columns
<- None
;
2266 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2269 reshape conf.winw
conf.winh
;
2272 let enterbirdseye () =
2273 let zoom = float conf.thumbw
/. float conf.winw
in
2274 let birdseyepageno =
2275 let cy = conf.winh
/ 2 in
2279 let rec fold best
= function
2282 let d = cy - (l.pagedispy + l.pagevh/2)
2283 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2284 if abs
d < abs dbest
2291 state.mode
<- Birdseye
(
2292 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2295 conf.presentation <- false;
2296 conf.interpagespace <- 10;
2297 conf.hlinks
<- false;
2299 state.mstate
<- Mnone
;
2300 conf.maxwait
<- None
;
2302 match conf.beyecolumns
with
2305 Some
((c, 0, 0), [||])
2308 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2311 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2316 reshape conf.winw
conf.winh
;
2319 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2321 conf.zoom <- c.zoom;
2322 conf.presentation <- c.presentation;
2323 conf.interpagespace <- c.interpagespace;
2324 conf.maxwait
<- c.maxwait
;
2325 conf.hlinks
<- c.hlinks
;
2326 conf.beyecolumns
<- (
2327 match conf.columns
with
2328 | Some
((c, _
, _
), _
) -> Some
c
2332 match c.columns
with
2333 | Some
(c, _
) -> Some
(c, [||])
2339 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2342 reshape conf.winw
conf.winh
;
2343 state.anchor <- if goback
then anchor else (pageno, 0.0);
2346 let togglebirdseye () =
2347 match state.mode
with
2348 | Birdseye vals
-> leavebirdseye vals
true
2349 | View
-> enterbirdseye ()
2353 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2354 let pageno = max
0 (pageno - incr
) in
2355 let rec loop = function
2356 | [] -> gotopage1 pageno 0
2357 | l :: _
when l.pageno = pageno ->
2358 if l.pagedispy >= 0 && l.pagey = 0
2359 then G.postRedisplay "upbirdseye"
2360 else gotopage1 pageno 0
2361 | _
:: rest
-> loop rest
2364 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2367 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2368 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2369 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2370 let rec loop = function
2372 let y, h = getpageyh pageno in
2373 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2375 | l :: _
when l.pageno = pageno ->
2376 if l.pagevh != l.pageh
2377 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2378 else G.postRedisplay "downbirdseye"
2379 | _
:: rest
-> loop rest
2384 let optentry mode _
key =
2385 let btos b = if b then "on" else "off" in
2386 if key >= 32 && key < 127
2388 let c = Char.chr
key in
2392 try conf.scrollstep
<- int_of_string
s with exc
->
2393 state.text <- Printf.sprintf
"bad integer `%s': %s"
2394 s (Printexc.to_string exc
)
2396 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2401 conf.autoscrollstep
<- int_of_string
s;
2402 if state.autoscroll
<> None
2403 then state.autoscroll
<- Some
conf.autoscrollstep
2405 state.text <- Printf.sprintf
"bad integer `%s': %s"
2406 s (Printexc.to_string exc
)
2408 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2413 let n, a, b = columns_of_string s in
2416 state.text <- Printf.sprintf
"bad columns `%s': %s"
2417 s (Printexc.to_string exc
)
2419 TEswitch
("columns: ", "", None
, textentry, ondone)
2424 let zoom = float (int_of_string
s) /. 100.0 in
2427 state.text <- Printf.sprintf
"bad integer `%s': %s"
2428 s (Printexc.to_string exc
)
2430 TEswitch
("zoom: ", "", None
, intentry, ondone)
2435 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2437 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2438 begin match mode
with
2440 leavebirdseye beye
false;
2445 state.text <- Printf.sprintf
"bad integer `%s': %s"
2446 s (Printexc.to_string exc
)
2448 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2453 Some
(int_of_string
s)
2455 state.text <- Printf.sprintf
"bad integer `%s': %s"
2456 s (Printexc.to_string exc
);
2459 | Some angle
-> reqlayout angle
conf.proportional
2462 TEswitch
("rotation: ", "", None
, intentry, ondone)
2465 conf.icase
<- not
conf.icase
;
2466 TEdone
("case insensitive search " ^
(btos conf.icase
))
2469 conf.preload <- not
conf.preload;
2471 TEdone
("preload " ^
(btos conf.preload))
2474 conf.verbose
<- not
conf.verbose
;
2475 TEdone
("verbose " ^
(btos conf.verbose
))
2478 conf.debug
<- not
conf.debug
;
2479 TEdone
("debug " ^
(btos conf.debug
))
2482 conf.maxhfit
<- not
conf.maxhfit
;
2484 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2485 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2488 conf.crophack
<- not
conf.crophack
;
2489 TEdone
("crophack " ^
btos conf.crophack
)
2493 match conf.maxwait
with
2495 conf.maxwait
<- Some infinity
;
2496 "always wait for page to complete"
2498 conf.maxwait
<- None
;
2499 "show placeholder if page is not ready"
2504 conf.underinfo
<- not
conf.underinfo
;
2505 TEdone
("underinfo " ^
btos conf.underinfo
)
2508 conf.savebmarks
<- not
conf.savebmarks
;
2509 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2515 match state.layout with
2520 conf.interpagespace <- int_of_string
s;
2521 state.maxy <- calcheight ();
2522 let y = getpagey pageno in
2525 state.text <- Printf.sprintf
"bad integer `%s': %s"
2526 s (Printexc.to_string exc
)
2528 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2531 reqlayout conf.angle
(not
conf.proportional
);
2532 TEdone
("proportional display " ^
btos conf.proportional
)
2535 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2536 TEdone
("trim margins " ^
btos conf.trimmargins
)
2539 conf.invert
<- not
conf.invert
;
2540 TEdone
("invert colors " ^
btos conf.invert
)
2544 cbput state.hists
.sel
s;
2547 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2551 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2557 class type lvsource
= object
2558 method getitemcount
: int
2559 method getitem
: int -> (string * int)
2560 method hasaction
: int -> bool
2569 method getactive
: int
2570 method getfirst
: int
2571 method getqsearch
: string
2572 method setqsearch
: string -> unit
2576 class virtual lvsourcebase
= object
2577 val mutable m_active
= 0
2578 val mutable m_first
= 0
2579 val mutable m_qsearch
= ""
2580 val mutable m_pan
= 0
2581 method getactive
= m_active
2582 method getfirst
= m_first
2583 method getqsearch
= m_qsearch
2584 method getpan
= m_pan
2585 method setqsearch
s = m_qsearch
<- s
2588 let withoutlastutf8 s =
2589 let len = String.length
s in
2597 let b = Char.code
s.[pos
] in
2598 if b land 0b110000 = 0b11000000
2603 if Char.code
s.[len-1] land 0x80 = 0
2607 String.sub
s 0 first;
2610 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2612 state.mode
<- Textentry
(te
, onleave
);
2615 G.postRedisplay "textentrykeyboard enttext";
2617 let histaction cmd
=
2620 | Some
(action, _
) ->
2621 state.mode
<- Textentry
(
2622 (c, action cmd
, opthist
, onkey
, ondone), onleave
2624 G.postRedisplay "textentry histaction"
2627 | 0xff08 -> (* backspace *)
2628 let s = withoutlastutf8 text in
2629 let len = String.length
s in
2633 G.postRedisplay "textentrykeyboard after cancel";
2636 enttext (c, s, opthist
, onkey
, ondone)
2642 G.postRedisplay "textentrykeyboard after confirm"
2644 | 0xff52 -> histaction HCprev
2645 | 0xff54 -> histaction HCnext
2646 | 0xff50 -> histaction HCfirst
2647 | 0xff57 -> histaction HClast
2649 | 0xff1b -> (* escape*)
2650 if String.length
text = 0
2652 begin match opthist
with
2654 | Some
(_
, onhistcancel
) -> onhistcancel
()
2658 G.postRedisplay "textentrykeyboard after cancel2"
2661 enttext (c, "", opthist
, onkey
, ondone)
2664 | 0xff9f | 0xffff -> () (* delete *)
2666 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2667 begin match onkey
text key with
2671 G.postRedisplay "textentrykeyboard after confirm2";
2674 enttext (c, text, opthist
, onkey
, ondone);
2678 G.postRedisplay "textentrykeyboard after cancel3"
2681 state.mode
<- Textentry
(te
, onleave
);
2682 G.postRedisplay "textentrykeyboard switch";
2686 vlog "unhandled key %s" (Wsi.keyname
key)
2689 let firstof first active
=
2690 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2691 then max
0 (active
- (fstate.maxrows
/2))
2695 let calcfirst first active
=
2698 let rows = active
- first in
2699 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2703 let scrollph y maxy =
2704 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2705 let sh = float conf.winh
/. sh in
2706 let sh = max
sh (float conf.scrollh
) in
2711 else float y /. float maxy
2713 let position = (float conf.winh
-. sh) *. percent in
2716 if position +. sh > float conf.winh
2717 then float conf.winh
-. sh
2723 let coe s = (s :> uioh
);;
2725 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2727 val m_pan
= source#getpan
2728 val m_first
= source#getfirst
2729 val m_active
= source#getactive
2730 val m_qsearch
= source#getqsearch
2731 val m_prev_uioh
= state.uioh
2733 method private elemunder
y =
2734 let n = y / (fstate.fontsize
+1) in
2735 if m_first
+ n < source#getitemcount
2737 if source#hasaction
(m_first
+ n)
2738 then Some
(m_first
+ n)
2745 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2746 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2747 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2748 GlDraw.color
(1., 1., 1.);
2749 Gl.enable `texture_2d
;
2750 let fs = fstate.fontsize
in
2752 let ww = fstate.wwidth
in
2753 let tabw = 30.0*.ww in
2754 let itemcount = source#getitemcount
in
2756 if (row - m_first
) * nfs > conf.winh
2759 if row >= 0 && row < itemcount
2761 let (s, level
) = source#getitem
row in
2762 let y = (row - m_first
) * nfs in
2763 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2766 Gl.disable `texture_2d
;
2767 GlDraw.polygon_mode `both `line
;
2768 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2769 GlDraw.rect (1., float (y + 1))
2770 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2771 GlDraw.polygon_mode `both `fill
;
2772 GlDraw.color
(1., 1., 1.);
2773 Gl.enable `texture_2d
;
2776 let drawtabularstring s =
2777 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2780 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2783 let len = String.length
s - tabpos - 1 in
2784 let s1 = String.sub
s 0 tabpos
2785 and s2
= String.sub
s (tabpos + 1) len in
2786 let nx = drawstr x s1 in
2788 let x = x +. (max
tabw sw) in
2795 let _ = drawtabularstring s in
2802 Gl.disable `texture_2d
;
2804 method updownlevel incr
=
2805 let len = source#getitemcount
in
2807 if m_active
>= 0 && m_active
< len
2808 then snd
(source#getitem m_active
)
2812 if i
= len then i
-1 else if i
= -1 then 0 else
2813 let _, l = source#getitem i
in
2814 if l != curlevel then i
else flow (i
+incr
)
2816 let active = flow m_active
in
2817 let first = calcfirst m_first
active in
2818 G.postRedisplay "outline updownlevel";
2819 {< m_active
= active; m_first
= first >}
2821 method private key1
key mask
=
2822 let set1 active first qsearch
=
2823 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2825 let search active pattern incr
=
2828 if n >= 0 && n < source#getitemcount
2830 let s, _ = source#getitem
n in
2832 (try ignore
(Str.search_forward
re s 0); true
2833 with Not_found
-> false)
2835 else loop (n + incr
)
2842 let re = Str.regexp_case_fold pattern
in
2848 let itemcount = source#getitemcount
in
2849 let find start incr
=
2851 if i
= -1 || i
= itemcount
2854 if source#hasaction i
2856 else find (i
+ incr
)
2861 let set active first =
2862 let first = bound first 0 (itemcount - fstate.maxrows
) in
2864 coe {< m_active
= active; m_first
= first >}
2867 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2869 let incr1 = if incr
> 0 then 1 else -1 in
2870 if isvisible m_first m_active
2873 let next = m_active
+ incr
in
2875 if next < 0 || next >= itemcount
2877 else find next incr1
2879 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2885 let first = m_first
+ incr
in
2886 let first = bound first 0 (itemcount - 1) in
2888 let next = m_active
+ incr
in
2889 let next = bound next 0 (itemcount - 1) in
2892 let active = if next = -1 then m_active
else next in
2895 let first = min
next m_first
in
2897 if abs
(next - first) > fstate.maxrows
2903 let first = m_first
+ incr
in
2904 let first = bound first 0 (itemcount - 1) in
2906 let next = m_active
+ incr
in
2907 let next = bound next 0 (itemcount - 1) in
2908 let next = find next incr1 in
2910 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2912 let active = if m_active
= -1 then next else m_active
in
2917 if isvisible first active
2923 G.postRedisplay "listview navigate";
2927 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2928 let incr = if key = 0x72 then -1 else 1 in
2930 match search (m_active
+ incr) m_qsearch
incr with
2932 state.text <- m_qsearch ^
" [not found]";
2935 state.text <- m_qsearch
;
2936 active, firstof m_first
active
2938 G.postRedisplay "listview ctrl-r/s";
2939 set1 active first m_qsearch
;
2941 | 0xff08 -> (* backspace *)
2942 if String.length m_qsearch
= 0
2945 let qsearch = withoutlastutf8 m_qsearch
in
2946 let len = String.length
qsearch in
2950 G.postRedisplay "listview empty qsearch";
2951 set1 m_active m_first
"";
2955 match search m_active
qsearch ~
-1 with
2957 state.text <- qsearch ^
" [not found]";
2960 state.text <- qsearch;
2961 active, firstof m_first
active
2963 G.postRedisplay "listview backspace qsearch";
2964 set1 active first qsearch
2967 | key when (key != 0 && key land 0xff00 != 0xff00) ->
2968 let pattern = m_qsearch ^
Wsi.toutf8
key in
2970 match search m_active
pattern 1 with
2972 state.text <- pattern ^
" [not found]";
2975 state.text <- pattern;
2976 active, firstof m_first
active
2978 G.postRedisplay "listview qsearch add";
2979 set1 active first pattern;
2981 | 0xff1b -> (* escape *)
2983 if String.length m_qsearch
= 0
2985 G.postRedisplay "list view escape";
2988 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2990 | None
-> m_prev_uioh
2995 G.postRedisplay "list view kill qsearch";
2996 source#setqsearch
"";
2997 coe {< m_qsearch
= "" >}
3000 | 0xff0d -> (* return *)
3002 let self = {< m_qsearch
= "" >} in
3003 source#setqsearch
"";
3005 G.postRedisplay "listview enter";
3006 if m_active
>= 0 && m_active
< source#getitemcount
3008 source#exit
(coe self) false m_active m_first m_pan
"";
3011 source#exit
(coe self) true m_active m_first m_pan
"";
3014 begin match opt with
3015 | None
-> m_prev_uioh
3019 | 0xff9f | 0xffff -> (* delete *)
3022 | 0xff52 -> navigate ~
-1 (* up *)
3023 | 0xff54 -> navigate 1 (* down *)
3024 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3025 | 0xff56 -> navigate fstate.maxrows
(* next *)
3027 | 0xff53 -> (* right *)
3029 G.postRedisplay "listview right";
3030 coe {< m_pan
= m_pan
- 1 >}
3032 | 0xff51 -> (* left *)
3034 G.postRedisplay "listview left";
3035 coe {< m_pan
= m_pan
+ 1 >}
3037 | 0xff50 -> (* home *)
3038 let active = find 0 1 in
3039 G.postRedisplay "listview home";
3042 | 0xff57 -> (* end *)
3043 let first = max
0 (itemcount - fstate.maxrows
) in
3044 let active = find (itemcount - 1) ~
-1 in
3045 G.postRedisplay "listview end";
3048 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3052 dolog "listview unknown key %#x" key; coe self
3054 method key key mask
=
3055 match state.mode
with
3056 | Textentry te
-> textentrykeyboard key mask te
; coe self
3057 | _ -> self#key1
key mask
3059 method button button down
x y _ =
3062 | 1 when x > conf.winw
- conf.scrollbw
->
3063 G.postRedisplay "listview scroll";
3066 let _, position, sh = self#
scrollph in
3067 if y > truncate
position && y < truncate
(position +. sh)
3069 state.mstate
<- Mscrolly
;
3073 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3074 let first = truncate
(s *. float source#getitemcount
) in
3075 let first = min source#getitemcount
first in
3076 Some
(coe {< m_first
= first; m_active
= first >})
3078 state.mstate
<- Mnone
;
3081 | 1 when not down
->
3082 begin match self#elemunder
y with
3084 G.postRedisplay "listview click";
3086 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3090 | n when (n == 4 || n == 5) && not down
->
3091 let len = source#getitemcount
in
3093 if n = 5 && m_first
+ fstate.maxrows
>= len
3097 let first = m_first
+ (if n == 4 then -1 else 1) in
3098 bound first 0 (len - 1)
3100 G.postRedisplay "listview wheel";
3101 Some
(coe {< m_first
= first >})
3106 | None
-> m_prev_uioh
3110 match state.mstate
with
3112 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3113 let first = truncate
(s *. float source#getitemcount
) in
3114 let first = min source#getitemcount
first in
3115 G.postRedisplay "listview motion";
3116 coe {< m_first
= first; m_active
= first >}
3119 method pmotion
x y =
3120 if x < conf.winw
- conf.scrollbw
3123 match self#elemunder
y with
3124 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3125 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3129 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3134 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3138 method infochanged
_ = ()
3140 method scrollpw
= (0, 0.0, 0.0)
3142 let nfs = fstate.fontsize
+ 1 in
3143 let y = m_first
* nfs in
3144 let itemcount = source#getitemcount
in
3145 let maxi = max
0 (itemcount - fstate.maxrows
) in
3146 let maxy = maxi * nfs in
3147 let p, h = scrollph y maxy in
3150 method modehash
= modehash
3153 class outlinelistview ~source
=
3156 ~source
:(source
:> lvsource
)
3158 ~modehash
:(findkeyhash conf "outline")
3161 method key key mask
=
3162 let calcfirst first active =
3165 let rows = active - first in
3166 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3170 let active = m_active
+ incr in
3171 let active = bound active 0 (source#getitemcount
- 1) in
3172 let first = calcfirst m_first
active in
3173 G.postRedisplay "outline navigate";
3174 coe {< m_active
= active; m_first
= first >}
3176 let ctrl = Wsi.withctrl mask
in
3178 | 110 when ctrl -> (* ctrl-n *)
3179 source#narrow m_qsearch
;
3180 G.postRedisplay "outline ctrl-n";
3181 coe {< m_first
= 0; m_active
= 0 >}
3183 | 117 when ctrl -> (* ctrl-u *)
3185 G.postRedisplay "outline ctrl-u";
3187 coe {< m_first
= 0; m_active
= 0 >}
3189 | 108 when ctrl -> (* ctrl-l *)
3190 let first = m_active
- (fstate.maxrows
/ 2) in
3191 G.postRedisplay "outline ctrl-l";
3192 coe {< m_first
= first >}
3194 | 0xff9f | 0xffff -> (* delete *)
3195 source#remove m_active
;
3196 G.postRedisplay "outline delete";
3197 let active = max
0 (m_active
-1) in
3198 coe {< m_first
= firstof m_first
active;
3199 m_active
= active >}
3201 | 0xff52 -> navigate ~
-1 (* up *)
3202 | 0xff54 -> navigate 1 (* down *)
3203 | 0xff55 -> (* prior *)
3204 navigate ~
-(fstate.maxrows
)
3205 | 0xff56 -> (* next *)
3206 navigate fstate.maxrows
3208 | 0xff53 -> (* [ctrl-]right *)
3212 G.postRedisplay "outline ctrl right";
3213 {< m_pan
= m_pan
+ 1 >}
3215 else self#updownlevel
1
3219 | 0xff51 -> (* [ctrl-]left *)
3223 G.postRedisplay "outline ctrl left";
3224 {< m_pan
= m_pan
- 1 >}
3226 else self#updownlevel ~
-1
3230 | 0xff50 -> (* home *)
3231 G.postRedisplay "outline home";
3232 coe {< m_first
= 0; m_active
= 0 >}
3234 | 0xff57 -> (* end *)
3235 let active = source#getitemcount
- 1 in
3236 let first = max
0 (active - fstate.maxrows
) in
3237 G.postRedisplay "outline end";
3238 coe {< m_active
= active; m_first
= first >}
3240 | _ -> super#
key key mask
3243 let outlinesource usebookmarks
=
3246 inherit lvsourcebase
3247 val mutable m_items
= empty
3248 val mutable m_orig_items
= empty
3249 val mutable m_prev_items
= empty
3250 val mutable m_narrow_pattern
= ""
3251 val mutable m_hadremovals
= false
3253 method getitemcount
=
3254 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3257 if n == Array.length m_items
&& m_hadremovals
3259 ("[Confirm removal]", 0)
3261 let s, n, _ = m_items
.(n) in
3264 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3265 ignore
(uioh
, first, qsearch);
3266 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3268 if String.length m_narrow_pattern
= 0
3274 if not
confrimremoval
3276 let _, _, anchor = m_items
.(active) in
3281 state.bookmarks
<- Array.to_list m_items
;
3282 m_orig_items
<- m_items
;
3285 else m_items
<- items;
3289 method hasaction
_ = true
3292 if Array.length m_items
!= Array.length m_orig_items
3293 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3296 method narrow
pattern =
3297 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3301 let rec loop accu n =
3304 m_narrow_pattern
<- pattern;
3305 m_items
<- Array.of_list
accu
3308 let (s, _, _) as o = m_items
.(n) in
3310 if (try ignore
(Str.search_forward
re s 0); true
3311 with Not_found
-> false)
3317 loop [] (Array.length m_items
- 1)
3322 then Array.of_list
state.bookmarks
3325 m_items
<- m_orig_items
3330 if m
>= 0 && m
< Array.length m_items
3332 m_hadremovals
<- true;
3333 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3334 let n = if n >= m
then n+1 else n in
3339 method reset
anchor items =
3340 m_hadremovals
<- false;
3341 if m_orig_items
== empty || m_prev_items
!= items
3343 m_orig_items
<- items;
3344 if String.length m_narrow_pattern
= 0
3345 then m_items
<- items;
3347 m_prev_items
<- items;
3348 let rely = getanchory anchor in
3350 let rec loop n best bestd
=
3351 if n = Array.length m_items
3354 let (_, _, anchor) = m_items
.(n) in
3355 let orely = getanchory anchor in
3356 let d = abs
(orely - rely) in
3359 else loop (n+1) best bestd
3364 m_first
<- firstof m_first
active
3368 let enterselector usebookmarks
=
3369 let source = outlinesource usebookmarks
in
3373 then Array.of_list
state.bookmarks
3376 if Array.length
outlines = 0
3378 showtext ' ' errmsg
;
3381 state.text <- source#greetmsg
;
3382 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3383 let anchor = getanchor () in
3384 source#reset
anchor outlines;
3385 state.uioh
<- coe (new outlinelistview ~
source);
3386 G.postRedisplay "enter selector";
3390 let enteroutlinemode =
3391 let f = enterselector false in
3392 fun ()-> f "Document has no outline";
3395 let enterbookmarkmode =
3396 let f = enterselector true in
3397 fun () -> f "Document has no bookmarks (yet)";
3400 let color_of_string s =
3401 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3402 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3406 let color_to_string (r
, g
, b) =
3407 let r = truncate
(r *. 256.0)
3408 and g
= truncate
(g
*. 256.0)
3409 and b = truncate
(b *. 256.0) in
3410 Printf.sprintf
"%d/%d/%d" r g
b
3413 let irect_of_string s =
3414 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3417 let irect_to_string (x0,y0,x1,y1) =
3418 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3421 let makecheckers () =
3422 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3424 converted by Issac Trotts. July 25, 2002 *)
3425 let image_height = 64
3426 and image_width
= 64 in
3430 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3432 for i
= 0 to image_width
- 1 do
3433 for j
= 0 to image_height - 1 do
3434 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3435 (if (i
land 8 ) lxor (j
land 8) = 0
3436 then [|255;255;255|] else [|200;200;200|])
3441 let image = make_image () in
3442 let id = GlTex.gen_texture
() in
3443 GlTex.bind_texture `texture_2d
id;
3444 GlPix.store
(`unpack_alignment
1);
3445 GlTex.image2d
image;
3446 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3449 `mag_filter `nearest
;
3450 `min_filter `nearest
];
3454 let setcheckers enabled
=
3455 match state.texid
with
3457 if enabled
then state.texid
<- Some
(makecheckers ())
3462 GlTex.delete_texture texid
;
3463 state.texid
<- None
;
3467 let int_of_string_with_suffix s =
3468 let l = String.length
s in
3472 let suffix = Char.lowercase
s.[l-1] in
3474 | 'k'
-> String.sub
s 0 (l-1), 10
3475 | 'm'
-> String.sub
s 0 (l-1), 20
3476 | 'g'
-> String.sub
s 0 (l-1), 30
3480 let n = int_of_string
s1 in
3481 let m = n lsl shift
in
3483 then raise
(Failure
"value too large")
3487 let string_with_suffix_of_int n =
3495 if n land ((1 lsl 20) - 1) = 0
3498 if n land ((1 lsl 10) - 1) = 0
3505 let h = n mod 1000 in
3508 then string_of_int
h ^
s
3510 let s = Printf.sprintf
"_%03d%s" h s in
3517 let defghyllscroll = (40, 8, 32);;
3518 let ghyllscroll_of_string s =
3519 let (n, a, b) as nab
=
3522 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3524 if n <= a || n <= b || a >= b
3525 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3529 let ghyllscroll_to_string ((n, a, b) as nab
) =
3530 if nab
= defghyllscroll
3532 else Printf.sprintf
"%d,%d,%d" n a b;
3535 let describe_location () =
3537 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3539 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3540 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3544 else (100. *. (float state.y /. float maxy))
3548 Printf.sprintf
"page %d of %d [%.2f%%]"
3549 (fn+1) state.pagecount
percent
3552 "pages %d-%d of %d [%.2f%%]"
3553 (fn+1) (ln
+1) state.pagecount
percent
3557 let btos b = if b then "\xe2\x88\x9a" else "" in
3558 let showextended = ref false in
3559 let leave mode
= function
3560 | Confirm
-> state.mode
<- mode
3561 | Cancel
-> state.mode
<- mode
in
3564 val mutable m_first_time
= true
3565 val mutable m_l
= []
3566 val mutable m_a
= [||]
3567 val mutable m_prev_uioh
= nouioh
3568 val mutable m_prev_mode
= View
3570 inherit lvsourcebase
3572 method reset prev_mode prev_uioh
=
3573 m_a
<- Array.of_list
(List.rev m_l
);
3575 m_prev_mode
<- prev_mode
;
3576 m_prev_uioh
<- prev_uioh
;
3580 if n >= Array.length m_a
3584 | _, _, _, Action
_ -> m_active
<- n
3588 m_first_time
<- false;
3591 method int name get
set =
3593 (name
, `
int get
, 1, Action
(
3596 try set (int_of_string
s)
3598 state.text <- Printf.sprintf
"bad integer `%s': %s"
3599 s (Printexc.to_string exn
)
3602 let te = name ^
": ", "", None
, intentry, ondone in
3603 state.mode
<- Textentry
(te, leave m_prev_mode
);
3607 method int_with_suffix name get
set =
3609 (name
, `intws get
, 1, Action
(
3612 try set (int_of_string_with_suffix s)
3614 state.text <- Printf.sprintf
"bad integer `%s': %s"
3615 s (Printexc.to_string exn
)
3619 name ^
": ", "", None
, intentry_with_suffix, ondone
3621 state.mode
<- Textentry
(te, leave m_prev_mode
);
3625 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3627 (name
, `
bool (btos, get
), offset
, Action
(
3634 method color name get
set =
3636 (name
, `color get
, 1, Action
(
3638 let invalid = (nan
, nan
, nan
) in
3641 try color_of_string s
3643 state.text <- Printf.sprintf
"bad color `%s': %s"
3644 s (Printexc.to_string exn
);
3650 let te = name ^
": ", "", None
, textentry, ondone in
3651 state.text <- color_to_string (get
());
3652 state.mode
<- Textentry
(te, leave m_prev_mode
);
3656 method string name get
set =
3658 (name
, `
string get
, 1, Action
(
3660 let ondone s = set s in
3661 let te = name ^
": ", "", None
, textentry, ondone in
3662 state.mode
<- Textentry
(te, leave m_prev_mode
);
3666 method colorspace name get
set =
3668 (name
, `
string get
, 1, Action
(
3671 let vals = [| "rgb"; "bgr"; "gray" |] in
3673 inherit lvsourcebase
3676 m_active
<- int_of_colorspace conf.colorspace
;
3679 method getitemcount
= Array.length
vals
3680 method getitem
n = (vals.(n), 0)
3681 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3682 ignore
(uioh
, first, pan
, qsearch);
3683 if not cancel
then set active;
3685 method hasaction
_ = true
3689 let modehash = findkeyhash conf "info" in
3690 coe (new listview ~
source ~trusted
:true ~
modehash)
3693 method caption
s offset
=
3694 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3696 method caption2
s f offset
=
3697 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3699 method getitemcount
= Array.length m_a
3702 let tostr = function
3703 | `
int f -> string_of_int
(f ())
3704 | `intws
f -> string_with_suffix_of_int (f ())
3706 | `color
f -> color_to_string (f ())
3707 | `
bool (btos, f) -> btos (f ())
3710 let name, t
, offset
, _ = m_a
.(n) in
3711 ((let s = tostr t
in
3712 if String.length
s > 0
3713 then Printf.sprintf
"%s\t%s" name s
3717 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3721 m_qsearch
<- qsearch;
3723 match m_a
.(active) with
3724 | _, _, _, Action
f -> f uioh
3736 method hasaction
n =
3738 | _, _, _, Action
_ -> true
3742 let rec fillsrc prevmode prevuioh
=
3743 let sep () = src#caption
"" 0 in
3744 let colorp name get
set =
3746 (fun () -> color_to_string (get
()))
3749 let c = color_of_string v in
3752 state.text <- Printf.sprintf
"bad color `%s': %s"
3753 v (Printexc.to_string exn
);
3756 let oldmode = state.mode
in
3757 let birdseye = isbirdseye state.mode
in
3759 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3761 src#
bool "presentation mode"
3762 (fun () -> conf.presentation)
3764 conf.presentation <- v;
3765 state.anchor <- getanchor ();
3768 src#
bool "ignore case in searches"
3769 (fun () -> conf.icase
)
3770 (fun v -> conf.icase
<- v);
3773 (fun () -> conf.preload)
3774 (fun v -> conf.preload <- v);
3776 src#
bool "highlight links"
3777 (fun () -> conf.hlinks
)
3778 (fun v -> conf.hlinks
<- v);
3780 src#
bool "under info"
3781 (fun () -> conf.underinfo
)
3782 (fun v -> conf.underinfo
<- v);
3784 src#
bool "persistent bookmarks"
3785 (fun () -> conf.savebmarks
)
3786 (fun v -> conf.savebmarks
<- v);
3788 src#
bool "proportional display"
3789 (fun () -> conf.proportional
)
3790 (fun v -> reqlayout conf.angle
v);
3792 src#
bool "trim margins"
3793 (fun () -> conf.trimmargins
)
3794 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3796 src#
bool "persistent location"
3797 (fun () -> conf.jumpback
)
3798 (fun v -> conf.jumpback
<- v);
3801 src#
int "inter-page space"
3802 (fun () -> conf.interpagespace)
3804 conf.interpagespace <- n;
3806 match state.layout with
3811 state.maxy <- calcheight ();
3812 let y = getpagey pageno in
3817 (fun () -> conf.pagebias
)
3818 (fun v -> conf.pagebias
<- v);
3820 src#
int "scroll step"
3821 (fun () -> conf.scrollstep
)
3822 (fun n -> conf.scrollstep
<- n);
3824 src#
int "auto scroll step"
3826 match state.autoscroll
with
3828 | _ -> conf.autoscrollstep
)
3830 if state.autoscroll
<> None
3831 then state.autoscroll
<- Some
n;
3832 conf.autoscrollstep
<- n);
3835 (fun () -> truncate
(conf.zoom *. 100.))
3836 (fun v -> setzoom ((float v) /. 100.));
3839 (fun () -> conf.angle
)
3840 (fun v -> reqlayout v conf.proportional
);
3842 src#
int "scroll bar width"
3843 (fun () -> state.scrollw
)
3847 reshape conf.winw
conf.winh
;
3850 src#
int "scroll handle height"
3851 (fun () -> conf.scrollh
)
3852 (fun v -> conf.scrollh
<- v;);
3854 src#
int "thumbnail width"
3855 (fun () -> conf.thumbw
)
3857 conf.thumbw
<- min
4096 v;
3860 leavebirdseye beye
false;
3865 src#
string "columns"
3867 match conf.columns
with
3869 | Some
(multicol
, _) -> columns_to_string multicol
)
3871 let n, a, b = columns_of_string v in
3875 src#caption
"Presentation mode" 0;
3876 src#
bool "scrollbar visible"
3877 (fun () -> conf.scrollbarinpm
)
3879 if v != conf.scrollbarinpm
3881 conf.scrollbarinpm
<- v;
3882 if conf.presentation
3884 state.scrollw
<- if v then conf.scrollbw
else 0;
3885 reshape conf.winw
conf.winh
;
3891 src#caption
"Pixmap cache" 0;
3892 src#int_with_suffix
"size (advisory)"
3893 (fun () -> conf.memlimit
)
3894 (fun v -> conf.memlimit
<- v);
3897 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3898 (string_with_suffix_of_int state.memused
)
3899 (Hashtbl.length
state.tilemap
)) 1;
3902 src#caption
"Layout" 0;
3903 src#caption2
"Dimension"
3905 Printf.sprintf
"%dx%d (virtual %dx%d)"
3911 src#caption2
"Position" (fun () ->
3912 Printf.sprintf
"%dx%d" state.x state.y
3915 src#caption2
"Visible" (fun () -> describe_location ()) 1
3919 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3920 "Save these parameters as global defaults at exit"
3921 (fun () -> conf.bedefault
)
3922 (fun v -> conf.bedefault
<- v)
3926 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3927 src#
bool ~offset
:0 ~
btos "Extended parameters"
3928 (fun () -> !showextended)
3929 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3933 (fun () -> conf.checkers
)
3934 (fun v -> conf.checkers
<- v; setcheckers v);
3935 src#
bool "update cursor"
3936 (fun () -> conf.updatecurs
)
3937 (fun v -> conf.updatecurs
<- v);
3939 (fun () -> conf.verbose
)
3940 (fun v -> conf.verbose
<- v);
3941 src#
bool "invert colors"
3942 (fun () -> conf.invert
)
3943 (fun v -> conf.invert
<- v);
3945 (fun () -> conf.maxhfit
)
3946 (fun v -> conf.maxhfit
<- v);
3947 src#
bool "redirect stderr"
3948 (fun () -> conf.redirectstderr)
3949 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3950 src#
string "uri launcher"
3951 (fun () -> conf.urilauncher
)
3952 (fun v -> conf.urilauncher
<- v);
3953 src#
string "path launcher"
3954 (fun () -> conf.pathlauncher
)
3955 (fun v -> conf.pathlauncher
<- v);
3956 src#
string "tile size"
3957 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3960 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3961 conf.tileh
<- max
64 w;
3962 conf.tilew
<- max
64 h;
3965 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3966 v (Printexc.to_string exn
));
3967 src#
int "texture count"
3968 (fun () -> conf.texcount
)
3971 then conf.texcount
<- v
3972 else showtext '
!'
" Failed to set texture count please retry later"
3974 src#
int "slice height"
3975 (fun () -> conf.sliceheight
)
3977 conf.sliceheight
<- v;
3978 wcmd "sliceh %d" conf.sliceheight
;
3980 src#
int "anti-aliasing level"
3981 (fun () -> conf.aalevel
)
3983 conf.aalevel
<- bound v 0 8;
3984 state.anchor <- getanchor ();
3985 opendoc state.path
state.password
;
3987 src#
int "ui font size"
3988 (fun () -> fstate.fontsize
)
3989 (fun v -> setfontsize (bound v 5 100));
3990 colorp "background color"
3991 (fun () -> conf.bgcolor
)
3992 (fun v -> conf.bgcolor
<- v);
3993 src#
bool "crop hack"
3994 (fun () -> conf.crophack
)
3995 (fun v -> conf.crophack
<- v);
3996 src#
string "trim fuzz"
3997 (fun () -> irect_to_string conf.trimfuzz
)
4000 conf.trimfuzz
<- irect_of_string v;
4002 then settrim true conf.trimfuzz
;
4004 state.text <- Printf.sprintf
"bad irect `%s': %s"
4005 v (Printexc.to_string exn
)
4007 src#
string "throttle"
4009 match conf.maxwait
with
4010 | None
-> "show place holder if page is not ready"
4013 then "wait for page to fully render"
4015 "wait " ^ string_of_float
time
4016 ^
" seconds before showing placeholder"
4020 let f = float_of_string
v in
4022 then conf.maxwait
<- None
4023 else conf.maxwait
<- Some
f
4025 state.text <- Printf.sprintf
"bad time `%s': %s"
4026 v (Printexc.to_string exn
)
4028 src#
string "ghyll scroll"
4030 match conf.ghyllscroll
with
4032 | Some nab
-> ghyllscroll_to_string nab
4037 if String.length
v = 0
4039 else Some
(ghyllscroll_of_string v)
4041 conf.ghyllscroll
<- gs
4043 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4044 v (Printexc.to_string exn
)
4046 src#
string "selection command"
4047 (fun () -> conf.selcmd
)
4048 (fun v -> conf.selcmd
<- v);
4049 src#colorspace
"color space"
4050 (fun () -> colorspace_to_string conf.colorspace
)
4052 conf.colorspace
<- colorspace_of_int v;
4059 src#caption
"Document" 0;
4060 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4061 src#caption2
"Pages"
4062 (fun () -> string_of_int
state.pagecount
) 1;
4063 src#caption2
"Dimensions"
4064 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4068 src#caption
"Trimmed margins" 0;
4069 src#caption2
"Dimensions"
4070 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4073 src#reset prevmode prevuioh
;
4077 let prevmode = state.mode
4078 and prevuioh
= state.uioh in
4079 fillsrc prevmode prevuioh
;
4080 let source = (src :> lvsource
) in
4081 let modehash = findkeyhash conf "info" in
4082 state.uioh <- coe (object (self)
4083 inherit listview ~
source ~trusted
:true ~
modehash as super
4084 val mutable m_prevmemused
= 0
4085 method infochanged
= function
4087 if m_prevmemused
!= state.memused
4089 m_prevmemused
<- state.memused
;
4090 G.postRedisplay "memusedchanged";
4092 | Pdim
-> G.postRedisplay "pdimchanged"
4093 | Docinfo
-> fillsrc prevmode prevuioh
4095 method key key mask
=
4096 if not
(Wsi.withctrl mask
)
4099 | 0xff51 -> coe (self#updownlevel ~
-1)
4100 | 0xff53 -> coe (self#updownlevel
1)
4101 | _ -> super#
key key mask
4102 else super#
key key mask
4104 G.postRedisplay "info";
4110 inherit lvsourcebase
4111 method getitemcount
= Array.length
state.help
4113 let s, n, _ = state.help
.(n) in
4116 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4120 m_qsearch
<- qsearch;
4121 match state.help
.(active) with
4122 | _, _, Action
f -> Some
(f uioh)
4132 method hasaction
n =
4133 match state.help
.(n) with
4134 | _, _, Action
_ -> true
4141 let modehash = findkeyhash conf "help" in
4142 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4143 G.postRedisplay "help";
4148 let re = Str.regexp
"[\r\n]" in
4150 inherit lvsourcebase
4151 val mutable m_items
= [||]
4153 method getitemcount
= 1 + Array.length m_items
4158 else m_items
.(n-1), 0
4160 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4165 then Buffer.clear
state.errmsgs
;
4166 m_qsearch
<- qsearch;
4173 method hasaction
n =
4177 state.newerrmsgs
<- false;
4178 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4179 m_items
<- Array.of_list
l
4187 let source = (msgsource :> lvsource
) in
4188 let modehash = findkeyhash conf "listview" in
4189 state.uioh <- coe (object
4190 inherit listview ~
source ~trusted
:false ~
modehash as super
4193 then msgsource#reset
;
4196 G.postRedisplay "msgs";
4199 let quickbookmark ?title
() =
4200 match state.layout with
4206 let sec = Unix.gettimeofday
() in
4207 let tm = Unix.localtime
sec in
4208 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4212 (tm.Unix.tm_year
+ 1900)
4215 | Some
title -> title
4218 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4223 state.fullscreen
<- None
;
4227 let setautoscrollspeed step goingdown
=
4228 let incr = max
1 ((abs step
) / 2) in
4229 let incr = if goingdown
then incr else -incr in
4230 let astep = step
+ incr in
4231 state.autoscroll
<- Some
astep;
4234 let viewkeyboard key mask
=
4236 let mode = state.mode in
4237 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4240 G.postRedisplay "view:enttext"
4242 let ctrl = Wsi.withctrl mask
in
4247 | 0xff63 -> (* insert *)
4248 state.mode <- LinkNav
(Ltgendir
0, "");
4251 | 0xff1b | 113 -> (* escape / q *)
4252 begin match state.mstate
with
4254 state.mstate
<- Mnone
;
4255 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4256 G.postRedisplay "kill zoom rect";
4258 match state.ranchors
with
4260 | (path
, password
, anchor) :: rest
->
4261 state.ranchors
<- rest
;
4262 state.anchor <- anchor;
4263 opendoc path password
4266 | 0xff08 -> (* backspace *)
4267 let y = getnav ~
-1 in
4268 gotoy_and_clear_text y
4276 G.postRedisplay "dehighlight";
4278 | 47 | 63 -> (* / ? *)
4279 let ondone isforw
s =
4280 cbput state.hists
.pat
s;
4281 state.searchpattern
<- s;
4284 let s = String.create
1 in
4285 s.[0] <- Char.chr
key;
4286 enttext (s, "", Some
(onhist state.hists
.pat
),
4287 textentry, ondone (key = 47))
4289 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4290 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4291 setzoom (conf.zoom +. incr)
4293 | 43 | 0xffab -> (* + *)
4296 try int_of_string
s with exc
->
4297 state.text <- Printf.sprintf
"bad integer `%s': %s"
4298 s (Printexc.to_string exc
);
4304 state.text <- "page bias is now " ^ string_of_int
n;
4307 enttext ("page bias: ", "", None
, intentry, ondone)
4309 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4310 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4311 setzoom (max
0.01 (conf.zoom -. decr))
4313 | 45 | 0xffad -> (* - *)
4314 let ondone msg
= state.text <- msg
in
4316 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4317 optentry state.mode, ondone
4320 | 48 when ctrl -> (* ctrl-0 *)
4323 | 49 when ctrl -> (* 1 *)
4324 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4328 | 0xffc6 -> (* f9 *)
4331 | 57 when ctrl -> (* ctrl-9 *)
4334 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4335 when not
ctrl -> (* 0..9 *)
4338 try int_of_string
s with exc
->
4339 state.text <- Printf.sprintf
"bad integer `%s': %s"
4340 s (Printexc.to_string exc
);
4346 cbput state.hists
.pag
(string_of_int
n);
4347 gotopage1 (n + conf.pagebias
- 1) 0;
4350 let pageentry text key =
4351 match Char.unsafe_chr
key with
4352 | 'g'
-> TEdone
text
4353 | _ -> intentry text key
4355 let text = "x" in text.[0] <- Char.chr
key;
4356 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4359 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4360 reshape conf.winw
conf.winh
;
4363 conf.hlinks
<- not
conf.hlinks
;
4364 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4365 G.postRedisplay "toggle highlightlinks";
4368 begin match state.autoscroll
with
4370 conf.autoscrollstep
<- step
;
4371 state.autoscroll
<- None
4373 if conf.autoscrollstep
= 0
4374 then state.autoscroll
<- Some
1
4375 else state.autoscroll
<- Some
conf.autoscrollstep
4379 conf.presentation <- not
conf.presentation;
4380 if conf.presentation
4382 if not
conf.scrollbarinpm
4383 then state.scrollw
<- 0;
4386 state.scrollw
<- conf.scrollbw
;
4388 showtext ' '
("presentation mode " ^
4389 if conf.presentation then "on" else "off");
4390 state.anchor <- getanchor ();
4394 begin match state.fullscreen
with
4396 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4399 state.fullscreen
<- None
;
4404 gotoy_and_clear_text 0
4407 gotopage1 (state.pagecount
- 1) 0
4409 | 112 | 78 -> (* p|N *)
4410 search state.searchpattern
false
4412 | 110 | 0xffc0 -> (* n|F3 *)
4413 search state.searchpattern
true
4416 begin match state.layout with
4419 gotoy_and_clear_text (getpagey l.pageno)
4423 begin match List.rev
state.layout with
4426 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4427 gotoy_and_clear_text (getpagey pageno)
4430 | 0xff9f | 0xffff -> (* delete *)
4431 begin match state.layout with
4434 let pageno = max
0 (l.pageno-1) in
4435 gotoy_and_clear_text (getpagey pageno)
4439 showtext ' '
(describe_location ());
4442 begin match state.layout with
4445 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4450 enterbookmarkmode ()
4452 | 104 | 0xffbe -> (* h|F1 *)
4458 | 101 when conf.redirectstderr -> (* e *)
4463 match state.layout with
4466 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4470 enttext ("bookmark: ", "", None
, textentry, ondone)
4474 showtext ' '
"Quick bookmark added";
4477 begin match state.layout with
4479 let rect = getpdimrect
l.pagedimno
in
4483 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4484 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4486 (truncate
(rect.(1) -. rect.(0)),
4487 truncate
(rect.(3) -. rect.(0)))
4489 let w = truncate
((float w)*.conf.zoom)
4490 and h = truncate
((float h)*.conf.zoom) in
4493 state.anchor <- getanchor ();
4494 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4496 G.postRedisplay "z";
4501 | 50 when ctrl -> (* ctrl-2 *)
4502 let maxw = getmaxw
() in
4504 then setzoom (maxw /. float conf.winw
)
4506 | 60 | 62 -> (* < > *)
4507 reqlayout (conf.angle
+ (if key = 60 then 30 else -30)) conf.proportional
4509 | 91 | 93 -> (* [ ] *)
4511 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4513 G.postRedisplay "brightness";
4515 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4516 setzoom state.prevzoom
4518 | 107 | 0xff52 -> (* k up *)
4519 begin match state.autoscroll
with
4521 begin match state.mode with
4522 | Birdseye beye
-> upbirdseye 1 beye
4525 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4526 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4529 setautoscrollspeed n false
4532 | 106 | 0xff54 -> (* j down *)
4533 begin match state.autoscroll
with
4535 begin match state.mode with
4536 | Birdseye beye
-> downbirdseye 1 beye
4539 then gotoy_and_clear_text (clamp (conf.winh
/2))
4540 else gotoy_and_clear_text (clamp conf.scrollstep
)
4543 setautoscrollspeed n true
4546 | 0xff51 | 0xff53 when Wsi.withnone mask
-> (* left / right *)
4554 let dx = if key = 0xff51 then dx else -dx in
4555 state.x <- state.x + dx;
4556 gotoy_and_clear_text state.y
4559 G.postRedisplay "lef/right"
4562 | 0xff55 -> (* prior *)
4566 match state.layout with
4568 | l :: _ -> state.y - l.pagey
4574 | 0xff56 -> (* next *)
4578 match List.rev
state.layout with
4580 | l :: _ -> getpagey l.pageno
4586 | 0xff50 -> gotoghyll 0
4587 | 0xff57 -> gotoghyll (clamp state.maxy)
4588 | 0xff53 when Wsi.withalt mask
->
4589 gotoghyll (getnav ~
-1)
4590 | 0xff51 when Wsi.withalt mask
->
4591 gotoghyll (getnav 1)
4594 state.anchor <- getanchor ();
4595 opendoc state.path
state.password
4600 | 118 when conf.debug
-> (* v *)
4603 match getopaque l.pageno with
4606 let x0, y0, x1, y1 = pagebbox opaque
in
4607 let a,b = float x0, float y0 in
4608 let c,d = float x1, float y0 in
4609 let e,f = float x1, float y1 in
4610 let h,j
= float x0, float y1 in
4611 let rect = (a,b,c,d,e,f,h,j
) in
4613 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4615 G.postRedisplay "v";
4618 vlog "huh? %s" (Wsi.keyname
key)
4621 let gotounder = function
4622 | Ulinkgoto
(pageno, top) ->
4626 gotopage1 pageno top;
4632 | Uremote
(filename
, pageno) ->
4634 if Sys.file_exists filename
4637 let dir = Filename.dirname
state.path in
4638 let path = Filename.concat
dir filename
in
4639 if Sys.file_exists
path
4643 if String.length
path > 0
4645 let anchor = getanchor () in
4646 let ranchor = state.path, state.password
, anchor in
4647 state.anchor <- (pageno, 0.0);
4648 state.ranchors
<- ranchor :: state.ranchors
;
4651 else showtext '
!'
("Could not find " ^ filename
)
4653 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4656 let linknavkeyboard key mask
(linknav, pattern) =
4660 G.postRedisplay "leave linknav"
4663 begin match linknav with
4664 | Ltgendir
_ -> viewkeyboard key mask
4665 | Ltexact
((l, opaque
, n), _) ->
4668 let under = getlink opaque
n in
4674 | 0xff50 -> (* home *)
4675 Some
(findlink opaque LDfirst
), -1
4677 | 0xff57 -> (* end *)
4678 Some
(findlink opaque LDlast
), 1
4680 | 0xff51 -> (* left *)
4681 Some
(findlink opaque
(LDleft
n)), -1
4683 | 0xff53 -> (* right *)
4684 Some
(findlink opaque
(LDright
n)), 1
4686 | 0xff52 -> (* up *)
4687 Some
(findlink opaque
(LDup
n)), -1
4689 | 0xff54 -> (* down *)
4690 Some
(findlink opaque
(LDdown
n)), 1
4694 begin match opt with
4695 | Some Lnolock
-> showtext '
!'
"failed to acquire lock";
4697 begin match findpwl
l.pageno dir with
4700 state.mode <- LinkNav
(Ltgendir
dir, pattern);
4701 let y, h = getpageyh pageno in
4704 then y + h - conf.winh
4710 | Some
(Lfound
(m, x0, y0, x1, y1)) ->
4712 || l.pagedispy + (y1 - l.pagey) > conf.winh
- state.hscrollh
4714 state.mode <- LinkNav
((Ltgendir
0), pattern);
4715 gotoy (state.y + (y0 - l.pagey))
4720 match findpwl
l.pageno dir with
4723 state.mode <- LinkNav
((Ltgendir
dir), pattern);
4724 let y, h = getpageyh pageno in
4727 then y + h - conf.winh
4733 let r = x0, y0, x1, y1 in
4734 state.mode <- LinkNav
(
4735 (Ltexact
((l, opaque
, m), r)), pattern
4737 G.postRedisplay "linknav up"
4740 viewkeyboard key mask
4745 let keyboard key mask
=
4746 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4747 then wcmd "interrupt"
4748 else state.uioh <- state.uioh#
key key mask
4751 let birdseyekeyboard key mask
4752 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4754 match conf.columns
with
4756 | Some
((c, _, _), _) -> c
4759 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4760 let y, h = getpageyh pageno in
4761 let top = (conf.winh
- h) / 2 in
4762 gotoy (max
0 (y - top))
4763 | 0xff0d -> leavebirdseye beye
false
4764 | 0xff1b -> leavebirdseye beye
true (* escape *)
4765 | 0xff52 -> upbirdseye incr beye
(* prior *)
4766 | 0xff54 -> downbirdseye incr beye
(* next *)
4767 | 0xff51 -> upbirdseye 1 beye
(* up *)
4768 | 0xff53 -> downbirdseye 1 beye
(* down *)
4771 begin match state.layout with
4775 state.mode <- Birdseye
(
4776 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4778 gotopage1 l.pageno 0;
4781 let layout = layout (state.y-conf.winh
) conf.winh
in
4783 | [] -> gotoy (clamp (-conf.winh
))
4785 state.mode <- Birdseye
(
4786 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4788 gotopage1 l.pageno 0
4791 | [] -> gotoy (clamp (-conf.winh
))
4795 begin match List.rev
state.layout with
4797 let layout = layout (state.y + conf.winh
) conf.winh
in
4798 begin match layout with
4800 let incr = l.pageh
- l.pagevh in
4805 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4807 G.postRedisplay "birdseye pagedown";
4809 else gotoy (clamp (incr + conf.interpagespace*2));
4813 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4814 gotopage1 l.pageno 0;
4817 | [] -> gotoy (clamp conf.winh
)
4821 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4825 let pageno = state.pagecount
- 1 in
4826 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4827 if not
(pagevisible state.layout pageno)
4830 match List.rev
state.pdims
with
4832 | (_, _, h, _) :: _ -> h
4834 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4835 else G.postRedisplay "birdseye end";
4836 | _ -> viewkeyboard key mask
4841 match state.mode with
4842 | Textentry
_ -> scalecolor 0.4
4844 | View
-> scalecolor 1.0
4845 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4846 if l.pageno = hooverpageno
4849 if l.pageno = pageno
4855 begin match getopaque l.pageno with
4857 if tileready l l.pagex l.pagey
4859 let x = l.pagedispx - l.pagex
4860 and y = l.pagedispy - l.pagey in
4861 postprocess opaque
conf.hlinks
x y;
4867 let scrollindicator () =
4868 let sbw, ph
, sh = state.uioh#
scrollph in
4869 let sbh, pw
, sw = state.uioh#scrollpw
in
4871 GlDraw.color (0.64, 0.64, 0.64);
4873 (float (conf.winw
- sbw), 0.)
4874 (float conf.winw
, float conf.winh
)
4877 (0., float (conf.winh
- sbh))
4878 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4880 GlDraw.color (0.0, 0.0, 0.0);
4883 (float (conf.winw
- sbw), ph
)
4884 (float conf.winw
, ph
+. sh)
4887 (pw
, float (conf.winh
- sbh))
4888 (pw
+. sw, float conf.winh
)
4893 match state.mstate
with
4894 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4897 | Msel
((x0, y0), (x1, y1)) ->
4898 let rec loop = function
4900 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4901 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4902 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4903 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4905 match getopaque l.pageno with
4907 let dx, dy = pagetranslatepoint l 0 0 in
4912 GlMat.mode `modelview
;
4914 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4915 seltext opaque
(x0, y0, x1, y1);
4924 let showrects rects
=
4926 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4927 GlDraw.polygon_mode `both `fill
;
4928 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4930 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4932 if l.pageno = pageno
4934 let dx = float (l.pagedispx - l.pagex) in
4935 let dy = float (l.pagedispy - l.pagey) in
4936 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4937 GlDraw.begins `quads
;
4939 GlDraw.vertex2
(x0+.dx, y0+.dy);
4940 GlDraw.vertex2
(x1+.dx, y1+.dy);
4941 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4942 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4953 GlClear.color (scalecolor2 conf.bgcolor
);
4954 GlClear.clear
[`
color];
4955 List.iter
drawpage state.layout;
4957 match state.mode with
4958 | LinkNav
((Ltexact
((page
, _, _), (x0, y0, x1, y1))), _) ->
4971 begin match state.mstate
with
4972 | Mzoomrect
((x0, y0), (x1, y1)) ->
4974 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4975 GlDraw.polygon_mode `both `fill
;
4976 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4977 GlDraw.rect (float x0, float y0)
4978 (float x1, float y1);
4985 let mx, my
= state.mpos
in
4991 let zoomrect x y x1 y1 =
4994 and y0 = min
y y1 in
4995 gotoy (state.y + y0);
4996 state.anchor <- getanchor ();
4997 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4999 if state.w < conf.winw
- state.scrollw
5000 then (conf.winw
- state.scrollw
- state.w) / 2
5003 state.x <- (state.x + margin) - x0;
5005 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5006 state.mstate
<- Mnone
;
5010 let winw = conf.winw - state.scrollw
- 1 in
5011 let s = float x /. float winw in
5012 let destx = truncate
(float (state.w + winw) *. s) in
5013 state.x <- winw - destx;
5014 gotoy_and_clear_text state.y;
5015 state.mstate
<- Mscrollx
;
5019 let s = float y /. float conf.winh
in
5020 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5021 gotoy_and_clear_text desty;
5022 state.mstate
<- Mscrolly
;
5025 let viewmouse button down
x y mask
=
5027 | n when (n == 4 || n == 5) && not down
->
5028 if Wsi.withctrl mask
5030 match state.mstate
with
5031 | Mzoom
(oldn
, i
) ->
5039 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5041 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5043 let zoom = conf.zoom -. incr in
5045 state.mstate
<- Mzoom
(n, 0);
5047 state.mstate
<- Mzoom
(n, i
+1);
5049 else state.mstate
<- Mzoom
(n, 0)
5051 | _ -> state.mstate
<- Mzoom
(n, 0)
5054 match state.autoscroll
with
5055 | Some step
-> setautoscrollspeed step
(n=4)
5059 then -conf.scrollstep
5060 else conf.scrollstep
5062 let incr = incr * 2 in
5063 let y = clamp incr in
5064 gotoy_and_clear_text y
5067 | 1 when Wsi.withctrl mask
->
5070 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5071 state.mstate
<- Mpan
(x, y)
5074 state.mstate
<- Mnone
5079 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5081 state.mstate
<- Mzoomrect
(p, p)
5084 match state.mstate
with
5085 | Mzoomrect
((x0, y0), _) ->
5086 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5087 then zoomrect x0 y0 x y
5089 state.mstate
<- Mnone
;
5090 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5091 G.postRedisplay "kill accidental zoom rect";
5094 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5095 state.mstate
<- Mnone
5098 | 1 when x > conf.winw - state.scrollw
->
5101 let _, position, sh = state.uioh#
scrollph in
5102 if y > truncate
position && y < truncate
(position +. sh)
5103 then state.mstate
<- Mscrolly
5106 state.mstate
<- Mnone
5108 | 1 when y > conf.winh
- state.hscrollh ->
5111 let _, position, sw = state.uioh#scrollpw
in
5112 if x > truncate
position && x < truncate
(position +. sw)
5113 then state.mstate
<- Mscrollx
5116 state.mstate
<- Mnone
5119 let dest = if down
then getunder x y else Unone
in
5120 begin match dest with
5121 | Ulinkgoto
(pageno, top) ->
5125 gotopage1 pageno top;
5131 | Uremote
(filename
, pageno) ->
5133 if Sys.file_exists filename
5136 let dir = Filename.dirname
state.path in
5137 let path = Filename.concat
dir filename
in
5138 if Sys.file_exists
path
5142 if String.length
path > 0
5144 let anchor = getanchor () in
5145 let ranchor = state.path, state.password
, anchor in
5146 state.anchor <- (pageno, 0.0);
5147 state.ranchors
<- ranchor :: state.ranchors
;
5150 else showtext '
!'
("Could not find " ^ filename
)
5152 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5154 | Unone
when down
->
5155 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5156 state.mstate
<- Mpan
(x, y);
5158 | Unone
| Utext
_ ->
5161 if conf.angle
mod 360 = 0
5163 state.mstate
<- Msel
((x, y), (x, y));
5164 G.postRedisplay "mouse select";
5168 match state.mstate
with
5171 | Mzoom
_ | Mscrollx
| Mscrolly
->
5172 state.mstate
<- Mnone
5174 | Mzoomrect
((x0, y0), _) ->
5178 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5179 state.mstate
<- Mnone
5181 | Msel
((_, y0), (_, y1)) ->
5182 let rec loop = function
5185 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5186 || ((y1 >= l.pagedispy
5187 && y1 <= (l.pagedispy + l.pagevh)))
5189 match getopaque l.pageno with
5191 copysel
conf.selcmd opaque
;
5192 G.postRedisplay "copysel"
5197 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5198 state.mstate
<- Mnone
;
5205 let birdseyemouse button down
x y mask
5206 (conf, leftx
, _, hooverpageno
, anchor) =
5209 let rec loop = function
5212 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5213 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5215 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5221 | _ -> viewmouse button down
x y mask
5224 let mouse button down
x y mask
=
5225 state.uioh <- state.uioh#button button down
x y mask
;
5229 state.uioh <- state.uioh#
motion x y
5233 state.uioh <- state.uioh#
pmotion x y;
5239 method key key mask
=
5240 begin match state.mode with
5241 | Textentry
textentry -> textentrykeyboard key mask
textentry
5242 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5243 | View
-> viewkeyboard key mask
5244 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5248 method button button bstate
x y mask
=
5249 begin match state.mode with
5251 | View
-> viewmouse button bstate
x y mask
5252 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5258 begin match state.mode with
5260 | View
| Birdseye
_ | LinkNav
_ ->
5261 match state.mstate
with
5262 | Mzoom
_ | Mnone
-> ()
5267 state.mstate
<- Mpan
(x, y);
5268 if conf.zoom > 1.0 then state.x <- state.x + dx;
5270 gotoy_and_clear_text y
5273 state.mstate
<- Msel
(a, (x, y));
5274 G.postRedisplay "motion select";
5277 let y = min
conf.winh
(max
0 y) in
5281 let x = min
conf.winw (max
0 x) in
5284 | Mzoomrect
(p0
, _) ->
5285 state.mstate
<- Mzoomrect
(p0
, (x, y));
5286 G.postRedisplay "motion zoomrect";
5290 method pmotion x y =
5291 begin match state.mode with
5292 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5293 let rec loop = function
5295 if hooverpageno
!= -1
5297 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5298 G.postRedisplay "pmotion birdseye no hoover";
5301 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5302 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5304 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5305 G.postRedisplay "pmotion birdseye hoover";
5315 match state.mstate
with
5316 | Mnone
-> updateunder x y
5317 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5322 method infochanged
_ = ()
5325 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5326 let p, h = scrollph state.y maxy in
5330 let winw = conf.winw - state.scrollw
- 1 in
5331 let fwinw = float winw in
5333 let sw = fwinw /. float state.w in
5334 let sw = fwinw *. sw in
5335 max
sw (float conf.scrollh
)
5338 let f = state.w+winw in
5339 let r = float (winw-state.x) /. float f in
5340 let p = fwinw *. r in
5344 if position +. sw > fwinw
5345 then fwinw -. position
5348 state.hscrollh, position, sw
5352 match state.mode with
5353 | LinkNav
_ -> "links"
5354 | Textentry
_ -> "textentry"
5355 | Birdseye
_ -> "birdseye"
5358 findkeyhash conf modename
5365 let fontpath = ref "";;
5368 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5371 let l = String.length
s in
5372 let b = Buffer.create
l in
5378 try Sys.getenv
"HOME"
5381 ("Can not determine home directory location: " ^
5382 Printexc.to_string exn
);
5386 let modifier_of_string = function
5387 | "alt" -> Wsi.altmask
5388 | "shift" -> Wsi.shiftmask
5389 | "ctrl" | "control" -> Wsi.ctrlmask
5390 | "meta" -> Wsi.metamask
5395 let r = Str.regexp
"-" in
5397 let elems = Str.full_split
r s in
5400 let m1 = modifier_of_string s in
5402 then (Wsi.namekey
s, m)
5405 | Str.Delim
s when n land 1 = 0 -> g s
5407 | Str.Delim
_ -> (k
, m)
5409 let rec loop n k
m = function
5412 let k, m = f n k m x in
5418 let keys_of_string =
5419 let r = Str.regexp
"[ \t]" in
5421 let elems = Str.split
r s in
5422 List.map
key_of_string elems
5425 let copykeyhashes c =
5426 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5429 let config_of c attrs
=
5433 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5434 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5435 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5436 | "preload" -> { c with preload = bool_of_string
v }
5437 | "page-bias" -> { c with pagebias
= int_of_string
v }
5438 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5439 | "auto-scroll-step" ->
5440 { c with autoscrollstep
= max
0 (int_of_string
v) }
5441 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5442 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5445 match String.lowercase
v with
5446 | "true" -> Some infinity
5448 | f -> Some
(float_of_string
f)
5450 { c with maxwait
= mw}
5451 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5452 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5453 | "vertical-margin" ->
5454 { c with interpagespace = max
0 (int_of_string
v) }
5456 let zoom = float_of_string
v /. 100. in
5457 let zoom = max
zoom 0.0 in
5458 { c with zoom = zoom }
5459 | "presentation" -> { c with presentation = bool_of_string
v }
5460 | "rotation-angle" -> { c with angle
= int_of_string
v }
5461 | "width" -> { c with winw = max
20 (int_of_string
v) }
5462 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5463 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5464 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5465 | "pixmap-cache-size" ->
5466 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5467 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5468 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5469 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5470 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5471 | "background-color" -> { c with bgcolor
= color_of_string v }
5472 | "scrollbar-in-presentation" ->
5473 { c with scrollbarinpm
= bool_of_string
v }
5474 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5475 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5476 | "mupdf-store-size" ->
5477 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5478 | "checkers" -> { c with checkers
= bool_of_string
v }
5479 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5480 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5481 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5482 | "uri-launcher" -> { c with urilauncher
= unent v }
5483 | "path-launcher" -> { c with pathlauncher
= unent v }
5484 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5485 | "invert-colors" -> { c with invert
= bool_of_string
v }
5486 | "brightness" -> { c with colorscale
= float_of_string
v }
5487 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5489 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5491 let nab = columns_of_string v in
5492 { c with columns
= Some
(nab, [||]) }
5493 | "birds-eye-columns" ->
5494 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5495 | "selection-command" -> { c with selcmd
= unent v }
5496 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5499 prerr_endline
("Error processing attribute (`" ^
5500 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5503 let rec fold c = function
5506 let c = apply c k v in
5509 fold { c with keyhashes
= copykeyhashes c } attrs
;
5512 let fromstring f pos
n v d =
5515 dolog "Error processing attribute (%S=%S) at %d\n%s"
5516 n v pos
(Printexc.to_string exn
)
5521 let bookmark_of attrs
=
5522 let rec fold title page
rely = function
5523 | ("title", v) :: rest
-> fold v page
rely rest
5524 | ("page", v) :: rest
-> fold title v rely rest
5525 | ("rely", v) :: rest
-> fold title page
v rest
5526 | _ :: rest
-> fold title page
rely rest
5527 | [] -> title, page
, rely
5529 fold "invalid" "0" "0" attrs
5533 let rec fold path page
rely pan
= function
5534 | ("path", v) :: rest
-> fold v page
rely pan rest
5535 | ("page", v) :: rest
-> fold path v rely pan rest
5536 | ("rely", v) :: rest
-> fold path page
v pan rest
5537 | ("pan", v) :: rest
-> fold path page
rely v rest
5538 | _ :: rest
-> fold path page
rely pan rest
5539 | [] -> path, page
, rely, pan
5541 fold "" "0" "0" "0" attrs
5545 let rec fold rs ls
= function
5546 | ("out", v) :: rest
-> fold v ls rest
5547 | ("in", v) :: rest
-> fold rs
v rest
5548 | _ :: rest
-> fold ls rs rest
5554 let setconf dst
src =
5555 dst
.scrollbw
<- src.scrollbw
;
5556 dst
.scrollh
<- src.scrollh
;
5557 dst
.icase
<- src.icase
;
5558 dst
.preload <- src.preload;
5559 dst
.pagebias
<- src.pagebias
;
5560 dst
.verbose
<- src.verbose
;
5561 dst
.scrollstep
<- src.scrollstep
;
5562 dst
.maxhfit
<- src.maxhfit
;
5563 dst
.crophack
<- src.crophack
;
5564 dst
.autoscrollstep
<- src.autoscrollstep
;
5565 dst
.maxwait
<- src.maxwait
;
5566 dst
.hlinks
<- src.hlinks
;
5567 dst
.underinfo
<- src.underinfo
;
5568 dst
.interpagespace <- src.interpagespace;
5569 dst
.zoom <- src.zoom;
5570 dst
.presentation <- src.presentation;
5571 dst
.angle
<- src.angle
;
5572 dst
.winw <- src.winw;
5573 dst
.winh
<- src.winh
;
5574 dst
.savebmarks
<- src.savebmarks
;
5575 dst
.memlimit
<- src.memlimit
;
5576 dst
.proportional
<- src.proportional
;
5577 dst
.texcount
<- src.texcount
;
5578 dst
.sliceheight
<- src.sliceheight
;
5579 dst
.thumbw
<- src.thumbw
;
5580 dst
.jumpback
<- src.jumpback
;
5581 dst
.bgcolor
<- src.bgcolor
;
5582 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5583 dst
.tilew
<- src.tilew
;
5584 dst
.tileh
<- src.tileh
;
5585 dst
.mustoresize
<- src.mustoresize
;
5586 dst
.checkers
<- src.checkers
;
5587 dst
.aalevel
<- src.aalevel
;
5588 dst
.trimmargins
<- src.trimmargins
;
5589 dst
.trimfuzz
<- src.trimfuzz
;
5590 dst
.urilauncher
<- src.urilauncher
;
5591 dst
.colorspace
<- src.colorspace
;
5592 dst
.invert
<- src.invert
;
5593 dst
.colorscale
<- src.colorscale
;
5594 dst
.redirectstderr <- src.redirectstderr;
5595 dst
.ghyllscroll
<- src.ghyllscroll
;
5596 dst
.columns
<- src.columns
;
5597 dst
.beyecolumns
<- src.beyecolumns
;
5598 dst
.selcmd
<- src.selcmd
;
5599 dst
.updatecurs
<- src.updatecurs
;
5600 dst
.pathlauncher
<- src.pathlauncher
;
5601 dst
.keyhashes
<- copykeyhashes src;
5605 let h = Hashtbl.create
10 in
5606 let dc = { defconf with angle
= defconf.angle
} in
5607 let rec toplevel v t spos
_ =
5609 | Vdata
| Vcdata
| Vend
-> v
5610 | Vopen
("llppconfig", _, closed
) ->
5613 else { v with f = llppconfig
}
5615 error
"unexpected subelement at top level" s spos
5616 | Vclose
_ -> error
"unexpected close at top level" s spos
5618 and llppconfig
v t spos
_ =
5620 | Vdata
| Vcdata
-> v
5621 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5622 | Vopen
("defaults", attrs
, closed
) ->
5623 let c = config_of dc attrs
in
5627 else { v with f = defaults
}
5629 | Vopen
("ui-font", attrs
, closed
) ->
5630 let rec getsize size
= function
5632 | ("size", v) :: rest
->
5634 fromstring int_of_string spos
"size" v fstate.fontsize
in
5636 | l -> getsize size l
5638 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5641 else { v with f = uifont
(Buffer.create
10) }
5643 | Vopen
("doc", attrs
, closed
) ->
5644 let pathent, spage
, srely
, span
= doc_of attrs
in
5645 let path = unent pathent
5646 and pageno = fromstring int_of_string spos
"page" spage
0
5647 and rely = fromstring float_of_string spos
"rely" srely
0.0
5648 and pan
= fromstring int_of_string spos
"pan" span
0 in
5649 let c = config_of dc attrs
in
5650 let anchor = (pageno, rely) in
5652 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5653 else { v with f = doc
path pan
anchor c [] }
5656 error
"unexpected subelement in llppconfig" s spos
5658 | Vclose
"llppconfig" -> { v with f = toplevel }
5659 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5661 and defaults
v t spos
_ =
5663 | Vdata
| Vcdata
-> v
5664 | Vend
-> error
"unexpected end of input in defaults" s spos
5665 | Vopen
("keymap", attrs
, closed
) ->
5667 try List.assoc
"mode" attrs
5668 with Not_found
-> "global" in
5673 let h = findkeyhash dc modename in
5674 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5677 { v with f = pkeymap
ret KeyMap.empty }
5679 | Vopen
(_, _, _) ->
5680 error
"unexpected subelement in defaults" s spos
5682 | Vclose
"defaults" ->
5683 { v with f = llppconfig
}
5685 | Vclose
_ -> error
"unexpected close in defaults" s spos
5687 and uifont
b v t spos
epos =
5690 Buffer.add_substring
b s spos
(epos - spos
);
5692 | Vopen
(_, _, _) ->
5693 error
"unexpected subelement in ui-font" s spos
5694 | Vclose
"ui-font" ->
5695 if String.length
!fontpath = 0
5696 then fontpath := Buffer.contents
b;
5697 { v with f = llppconfig
}
5698 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5699 | Vend
-> error
"unexpected end of input in ui-font" s spos
5701 and doc
path pan
anchor c bookmarks
v t spos
_ =
5703 | Vdata
| Vcdata
-> v
5704 | Vend
-> error
"unexpected end of input in doc" s spos
5705 | Vopen
("bookmarks", _, closed
) ->
5708 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5710 | Vopen
("keymap", attrs
, closed
) ->
5712 try List.assoc
"mode" attrs
5713 with Not_found
-> "global"
5719 let h = findkeyhash c modename in
5720 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5721 doc
path pan
anchor c bookmarks
5723 { v with f = pkeymap
ret KeyMap.empty }
5725 | Vopen
(_, _, _) ->
5726 error
"unexpected subelement in doc" s spos
5729 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5730 { v with f = llppconfig
}
5732 | Vclose
_ -> error
"unexpected close in doc" s spos
5734 and pkeymap
ret keymap
v t spos
_ =
5736 | Vdata
| Vcdata
-> v
5737 | Vend
-> error
"unexpected end of input in keymap" s spos
5738 | Vopen
("map", attrs
, closed
) ->
5739 let r, l = map_of attrs
in
5740 let kss = fromstring keys_of_string spos
"in" r [] in
5741 let lss = fromstring keys_of_string spos
"out" l [] in
5745 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5746 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5749 then { v with f = pkeymap
ret keymap }
5752 { v with f = skip
"map" f }
5755 error
"unexpected subelement in keymap" s spos
5757 | Vclose
"keymap" ->
5758 { v with f = ret keymap }
5760 | Vclose
_ -> error
"unexpected close in keymap" s spos
5762 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5764 | Vdata
| Vcdata
-> v
5765 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5766 | Vopen
("item", attrs
, closed
) ->
5767 let titleent, spage
, srely
= bookmark_of attrs
in
5768 let page = fromstring int_of_string spos
"page" spage
0
5769 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5770 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5772 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5775 { v with f = skip
"item" f }
5778 error
"unexpected subelement in bookmarks" s spos
5780 | Vclose
"bookmarks" ->
5781 { v with f = doc
path pan
anchor c bookmarks }
5783 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5785 and skip tag
f v t spos
_ =
5787 | Vdata
| Vcdata
-> v
5789 error
("unexpected end of input in skipped " ^ tag
) s spos
5790 | Vopen
(tag'
, _, closed
) ->
5794 let f'
() = { v with f = skip tag
f } in
5795 { v with f = skip tag'
f'
}
5799 else error
("unexpected close in skipped " ^ tag
) s spos
5802 parse
{ f = toplevel; accu = () } s;
5808 let len = in_channel_length ic
in
5809 let s = String.create
len in
5810 really_input ic
s 0 len;
5813 | Parse_error
(msg
, s, pos
) ->
5814 let subs = subs s pos
in
5815 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5816 failwith
("parse error: " ^
s)
5819 failwith
("config load error: " ^
Printexc.to_string exn
)
5825 let dir = Filename.concat
home ".config" in
5826 if Sys.is_directory
dir then dir else home
5829 Filename.concat
dir "llpp.conf"
5832 let confpath = ref defconfpath;;
5835 if Sys.file_exists
!confpath
5838 (try Some
(open_in_bin
!confpath)
5841 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5842 Printexc.to_string exn
);
5851 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5852 Printexc.to_string exn
);
5858 f (Hashtbl.create
0, defconf)
5863 let pc, pb
, px, pa
=
5865 Hashtbl.find h (Filename.basename
state.path)
5866 with Not_found
-> dc, [], 0, (0, 0.0)
5870 state.bookmarks <- pb
;
5872 state.scrollw
<- conf.scrollbw
;
5874 then state.anchor <- pa
;
5875 cbput state.hists
.nav pa
;
5880 let add_attrs bb always
dc c =
5883 then Printf.bprintf bb
"\n %s='%b'" s a
5886 then Printf.bprintf bb
"\n %s='%d'" s a
5889 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5892 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5895 then Printf.bprintf bb
"\n %s='%f'" s a
5899 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5903 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5907 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5911 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5917 | Some
(_N
, _A
, _B
) ->
5918 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5928 else string_of_float
f
5930 Printf.bprintf bb
"\n %s='%s'" s v
5935 | Some
((n, a, b), _) when n > 1 ->
5936 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5942 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5947 then dc.winw, dc.winh
5949 match state.fullscreen
with
5951 | None
-> c.winw, c.winh
5953 let zoom, presentation, interpagespace, maxwait
=
5955 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5957 match state.mode with
5958 | Birdseye
(bc
, _, _, _, _) ->
5959 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5960 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5962 oi
"width" w dc.winw;
5963 oi
"height" h dc.winh
;
5964 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5965 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5966 ob "case-insensitive-search" c.icase
dc.icase
;
5967 ob "preload" c.preload dc.preload;
5968 oi
"page-bias" c.pagebias
dc.pagebias
;
5969 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5970 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5971 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5972 ob "crop-hack" c.crophack
dc.crophack
;
5973 oW
"throttle" maxwait
dc.maxwait
;
5974 ob "highlight-links" c.hlinks
dc.hlinks
;
5975 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5976 oi
"vertical-margin" interpagespace dc.interpagespace;
5977 oz
"zoom" zoom dc.zoom;
5978 ob "presentation" presentation dc.presentation;
5979 oi
"rotation-angle" c.angle
dc.angle
;
5980 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5981 ob "proportional-display" c.proportional
dc.proportional
;
5982 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5983 oi
"tex-count" c.texcount
dc.texcount
;
5984 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5985 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5986 ob "persistent-location" c.jumpback
dc.jumpback
;
5987 oc
"background-color" c.bgcolor
dc.bgcolor
;
5988 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5989 oi
"tile-width" c.tilew
dc.tilew
;
5990 oi
"tile-height" c.tileh
dc.tileh
;
5991 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5992 ob "checkers" c.checkers
dc.checkers
;
5993 oi
"aalevel" c.aalevel
dc.aalevel
;
5994 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5995 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5996 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5997 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
5998 oC
"color-space" c.colorspace
dc.colorspace
;
5999 ob "invert-colors" c.invert
dc.invert
;
6000 oF
"brightness" c.colorscale
dc.colorscale
;
6001 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6002 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6003 oco
"columns" c.columns
dc.columns
;
6004 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6005 os
"selection-command" c.selcmd
dc.selcmd
;
6006 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6009 let keymapsbuf always
dc c =
6010 let bb = Buffer.create
16 in
6011 let rec loop = function
6013 | (modename, h) :: rest
->
6014 let dh = findkeyhash dc modename in
6015 if always
|| h <> dh
6017 if Hashtbl.length
h > 0
6019 if Buffer.length
bb > 0
6020 then Buffer.add_char
bb '
\n'
;
6021 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6022 Hashtbl.iter
(fun i
o ->
6023 let isdifferent = always
||
6025 let dO = Hashtbl.find dh i
in
6027 with Not_found
-> true
6032 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6033 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6034 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6035 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6036 Buffer.add_string
bb (Wsi.keyname
k);
6039 let rec loop = function
6041 | km
:: [] -> addkm km
6042 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6046 Buffer.add_string
bb "<map in='";
6050 Buffer.add_char
bb '
\''
;
6051 Buffer.add_string
bb " out='";
6053 Buffer.add_string
bb "'/>\n"
6056 Buffer.add_char
bb '
\''
;
6057 Buffer.add_string
bb " out='";
6059 Buffer.add_string
bb "'/>\n"
6061 | KMmulti
(ins, kms
) ->
6062 Buffer.add_char
bb ' '
;
6064 Buffer.add_char
bb '
\''
;
6065 Buffer.add_string
bb " out='";
6067 Buffer.add_string
bb "'/>\n"
6069 Buffer.add_string
bb "</keymap>";
6079 let uifontsize = fstate.fontsize
in
6080 let bb = Buffer.create
32768 in
6082 let dc = if conf.bedefault
then conf else dc in
6083 Buffer.add_string
bb "<llppconfig>\n";
6085 if String.length
!fontpath > 0
6087 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6093 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6096 Buffer.add_string
bb "<defaults ";
6097 add_attrs bb true dc dc;
6098 let kb = keymapsbuf true dc dc in
6099 if Buffer.length
kb > 0
6101 Buffer.add_string
bb ">\n";
6102 Buffer.add_buffer
bb kb;
6103 Buffer.add_string
bb "\n</defaults>\n";
6105 else Buffer.add_string
bb "/>\n";
6107 let adddoc path pan
anchor c bookmarks =
6108 if bookmarks == [] && c = dc && anchor = emptyanchor
6111 Printf.bprintf
bb "<doc path='%s'"
6112 (enent
path 0 (String.length
path));
6114 if anchor <> emptyanchor
6116 let n, y = anchor in
6117 Printf.bprintf
bb " page='%d'" n;
6120 Printf.bprintf
bb " rely='%f'" y
6125 then Printf.bprintf
bb " pan='%d'" pan
;
6127 add_attrs bb false dc c;
6128 let kb = keymapsbuf false dc c in
6130 begin match bookmarks with
6132 if Buffer.length
kb > 0
6134 Buffer.add_string
bb ">\n";
6135 Buffer.add_buffer
bb kb;
6136 Buffer.add_string
bb "</doc>\n";
6138 else Buffer.add_string
bb "/>\n"
6140 Buffer.add_string
bb ">\n<bookmarks>\n";
6141 List.iter
(fun (title, _level
, (page, rely)) ->
6143 "<item title='%s' page='%d'"
6144 (enent
title 0 (String.length
title))
6149 Printf.bprintf
bb " rely='%f'" rely
6151 Buffer.add_string
bb "/>\n";
6153 Buffer.add_string
bb "</bookmarks>";
6154 if Buffer.length
kb > 0
6156 Buffer.add_string
bb "\n";
6157 Buffer.add_buffer
bb kb;
6159 Buffer.add_string
bb "\n</doc>\n";
6165 match state.mode with
6166 | Birdseye
(c, pan, _, _, _) ->
6168 match conf.columns
with
6169 | Some
((c, _, _), _) -> Some
c
6172 match c.columns
with
6173 | Some
(c, _) -> Some
(c, [||])
6176 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6177 | _ -> state.x, conf
6179 let basename = Filename.basename state.path in
6180 adddoc basename pan (getanchor ())
6183 match state.autoscroll
with
6185 | None
-> conf.autoscrollstep
}
6186 (if conf.savebmarks
then state.bookmarks else []);
6188 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6190 then adddoc path x y c bookmarks
6192 Buffer.add_string
bb "</llppconfig>";
6195 if Buffer.length
bb > 0
6198 let tmp = !confpath ^
".tmp" in
6199 let oc = open_out_bin
tmp in
6200 Buffer.output_buffer
oc bb;
6202 Unix.rename
tmp !confpath;
6205 ("error while saving configuration: " ^
Printexc.to_string exn
)
6212 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6213 "<password> Set password");
6215 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6216 "<path> Set path to the user interface font");
6218 ("-c", Arg.String
(fun s -> Config.confpath := s),
6219 "<path> Set path to the configuration file");
6221 ("-v", Arg.Unit
(fun () ->
6223 "%s\nconfiguration path: %s\n"
6227 exit
0), " Print version and exit");
6230 (fun s -> state.path <- s)
6231 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6233 if String.length
state.path = 0
6234 then (prerr_endline
"file name missing"; exit
1);
6238 let globalkeyhash = findkeyhash conf "global" in
6239 state.wsfd
<- Wsi.init
(object
6240 method display = display ()
6241 method reshape w h = reshape w h
6242 method mouse b d x y m = mouse b d x y m
6243 method motion x y = state.mpos
<- (x, y); motion x y
6244 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6246 match state.keystate
with
6251 try Hashtbl.find globalkeyhash km
6253 let modehash = state.uioh#
modehash in
6254 try Hashtbl.find modehash km
6255 with Not_found
-> KMinsrt
(k, m)
6257 | KMinsrt
(k, m) -> keyboard k m
6258 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6259 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6261 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land m = m'
->
6262 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6263 state.keystate
<- KSnone
6264 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land m = m'
->
6265 state.keystate
<- KSinto
(keys
, insrt
)
6267 state.keystate
<- KSnone
6269 method enter
x y = state.mpos
<- (x, y); pmotion x y
6270 method leave = state.mpos
<- (-1, -1)
6271 method quit
= raise Quit
6272 end) conf.winw conf.winh
;
6275 List.exists
GlMisc.check_extension
6276 [ "GL_ARB_texture_rectangle"
6277 ; "GL_EXT_texture_recangle"
6278 ; "GL_NV_texture_rectangle" ]
6280 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6282 let cr, sw = Unix.pipe
()
6283 and sr
, cw
= Unix.pipe
() in
6290 setcheckers conf.checkers
;
6294 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6295 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6300 state.text <- "Opening " ^
state.path;
6301 setaalevel
conf.aalevel
;
6302 writeopen state.path state.password
;
6304 setfontsize fstate.fontsize
;
6305 doreshape conf.winw conf.winh
;
6307 let rec loop deadline
=
6309 match state.errfd
with
6310 | None
-> [state.sr
; state.wsfd
]
6311 | Some fd
-> [state.sr
; state.wsfd
; fd
]
6315 state.redisplay
<- false;
6322 if deadline
= infinity
6324 else max
0.0 (deadline
-. now)
6329 try Unix.select
r [] [] timeout
6330 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6336 if state.ghyll
== noghyll
6338 match state.autoscroll
with
6339 | Some step
when step
!= 0 ->
6340 let y = state.y + step
in
6344 else if y >= state.maxy then 0 else y
6347 if state.mode = View
6348 then state.text <- "";
6351 else deadline
+. 0.01
6356 let rec checkfds = function
6358 | fd
:: rest
when fd
= state.sr
->
6359 let cmd = readcmd state.sr
in
6363 | fd
:: rest
when fd
= state.wsfd
->
6368 let s = String.create
80 in
6369 let n = Unix.read fd
s 0 80 in
6370 if conf.redirectstderr
6372 Buffer.add_substring
state.errmsgs
s 0 n;
6373 state.newerrmsgs
<- true;
6374 state.redisplay
<- true;
6377 prerr_string
(String.sub
s 0 n);
6385 if deadline
= infinity
6389 match state.autoscroll
with
6390 | Some step
when step
!= 0 -> deadline1
6391 | _ -> if state.ghyll
== noghyll then infinity
else deadline1