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
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
) ->
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
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;
2205 match state.mode
with
2206 | LinkNav _
-> state.mode
<- View
2209 conf.proportional
<- proportional
;
2211 wcmd "reqlayout %d %d" conf.angle
(btod proportional
);
2215 let settrim trimmargins trimfuzz
=
2216 if state.invalidated
= 0 then state.anchor <- getanchor ();
2217 conf.trimmargins
<- trimmargins
;
2218 conf.trimfuzz
<- trimfuzz
;
2219 let x0, y0, x1, y1 = trimfuzz
in
2221 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1;
2222 Hashtbl.iter
(fun _ opaque
->
2223 wcmd "freepage %s" opaque
;
2225 Hashtbl.clear
state.pagemap
;
2229 match state.throttle
with
2231 let zoom = max
0.01 zoom in
2232 if zoom <> conf.zoom
2234 state.prevzoom
<- conf.zoom;
2237 then (state.x <- 0; 0.0)
2238 else float state.x /. float state.w
2241 reshape conf.winw
conf.winh
;
2244 let x = relx *. float state.w in
2245 state.x <- truncate
x;
2247 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2250 | Some
(layout, y, started
) ->
2252 match conf.maxwait
with
2256 let dt = now () -. started
in
2264 let setcolumns columns coverA coverB
=
2267 conf.columns
<- None
;
2272 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2275 reshape conf.winw
conf.winh
;
2278 let enterbirdseye () =
2279 let zoom = float conf.thumbw
/. float conf.winw
in
2280 let birdseyepageno =
2281 let cy = conf.winh
/ 2 in
2285 let rec fold best
= function
2288 let d = cy - (l.pagedispy + l.pagevh/2)
2289 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2290 if abs
d < abs dbest
2297 state.mode
<- Birdseye
(
2298 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2301 conf.presentation <- false;
2302 conf.interpagespace <- 10;
2303 conf.hlinks
<- false;
2305 state.mstate
<- Mnone
;
2306 conf.maxwait
<- None
;
2308 match conf.beyecolumns
with
2311 Some
((c, 0, 0), [||])
2314 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2317 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2322 reshape conf.winw
conf.winh
;
2325 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2327 conf.zoom <- c.zoom;
2328 conf.presentation <- c.presentation;
2329 conf.interpagespace <- c.interpagespace;
2330 conf.maxwait
<- c.maxwait
;
2331 conf.hlinks
<- c.hlinks
;
2332 conf.beyecolumns
<- (
2333 match conf.columns
with
2334 | Some
((c, _
, _
), _
) -> Some
c
2338 match c.columns
with
2339 | Some
(c, _
) -> Some
(c, [||])
2345 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2348 reshape conf.winw
conf.winh
;
2349 state.anchor <- if goback
then anchor else (pageno, 0.0);
2352 let togglebirdseye () =
2353 match state.mode
with
2354 | Birdseye vals
-> leavebirdseye vals
true
2355 | View
-> enterbirdseye ()
2359 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2360 let pageno = max
0 (pageno - incr
) in
2361 let rec loop = function
2362 | [] -> gotopage1 pageno 0
2363 | l :: _
when l.pageno = pageno ->
2364 if l.pagedispy >= 0 && l.pagey = 0
2365 then G.postRedisplay "upbirdseye"
2366 else gotopage1 pageno 0
2367 | _
:: rest
-> loop rest
2370 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2373 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2374 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2375 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2376 let rec loop = function
2378 let y, h = getpageyh pageno in
2379 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2381 | l :: _
when l.pageno = pageno ->
2382 if l.pagevh != l.pageh
2383 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2384 else G.postRedisplay "downbirdseye"
2385 | _
:: rest
-> loop rest
2390 let optentry mode _
key =
2391 let btos b = if b then "on" else "off" in
2392 if key >= 32 && key < 127
2394 let c = Char.chr
key in
2398 try conf.scrollstep
<- int_of_string
s with exc
->
2399 state.text <- Printf.sprintf
"bad integer `%s': %s"
2400 s (Printexc.to_string exc
)
2402 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2407 conf.autoscrollstep
<- int_of_string
s;
2408 if state.autoscroll
<> None
2409 then state.autoscroll
<- Some
conf.autoscrollstep
2411 state.text <- Printf.sprintf
"bad integer `%s': %s"
2412 s (Printexc.to_string exc
)
2414 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2419 let n, a, b = columns_of_string s in
2422 state.text <- Printf.sprintf
"bad columns `%s': %s"
2423 s (Printexc.to_string exc
)
2425 TEswitch
("columns: ", "", None
, textentry, ondone)
2430 let zoom = float (int_of_string
s) /. 100.0 in
2433 state.text <- Printf.sprintf
"bad integer `%s': %s"
2434 s (Printexc.to_string exc
)
2436 TEswitch
("zoom: ", "", None
, intentry, ondone)
2441 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2443 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2444 begin match mode
with
2446 leavebirdseye beye
false;
2451 state.text <- Printf.sprintf
"bad integer `%s': %s"
2452 s (Printexc.to_string exc
)
2454 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2459 Some
(int_of_string
s)
2461 state.text <- Printf.sprintf
"bad integer `%s': %s"
2462 s (Printexc.to_string exc
);
2465 | Some angle
-> reqlayout angle
conf.proportional
2468 TEswitch
("rotation: ", "", None
, intentry, ondone)
2471 conf.icase
<- not
conf.icase
;
2472 TEdone
("case insensitive search " ^
(btos conf.icase
))
2475 conf.preload <- not
conf.preload;
2477 TEdone
("preload " ^
(btos conf.preload))
2480 conf.verbose
<- not
conf.verbose
;
2481 TEdone
("verbose " ^
(btos conf.verbose
))
2484 conf.debug
<- not
conf.debug
;
2485 TEdone
("debug " ^
(btos conf.debug
))
2488 conf.maxhfit
<- not
conf.maxhfit
;
2490 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2491 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2494 conf.crophack
<- not
conf.crophack
;
2495 TEdone
("crophack " ^
btos conf.crophack
)
2499 match conf.maxwait
with
2501 conf.maxwait
<- Some infinity
;
2502 "always wait for page to complete"
2504 conf.maxwait
<- None
;
2505 "show placeholder if page is not ready"
2510 conf.underinfo
<- not
conf.underinfo
;
2511 TEdone
("underinfo " ^
btos conf.underinfo
)
2514 conf.savebmarks
<- not
conf.savebmarks
;
2515 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2521 match state.layout with
2526 conf.interpagespace <- int_of_string
s;
2527 state.maxy <- calcheight ();
2528 let y = getpagey pageno in
2531 state.text <- Printf.sprintf
"bad integer `%s': %s"
2532 s (Printexc.to_string exc
)
2534 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2537 reqlayout conf.angle
(not
conf.proportional
);
2538 TEdone
("proportional display " ^
btos conf.proportional
)
2541 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2542 TEdone
("trim margins " ^
btos conf.trimmargins
)
2545 conf.invert
<- not
conf.invert
;
2546 TEdone
("invert colors " ^
btos conf.invert
)
2550 cbput state.hists
.sel
s;
2553 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2557 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2563 class type lvsource
= object
2564 method getitemcount
: int
2565 method getitem
: int -> (string * int)
2566 method hasaction
: int -> bool
2575 method getactive
: int
2576 method getfirst
: int
2577 method getqsearch
: string
2578 method setqsearch
: string -> unit
2582 class virtual lvsourcebase
= object
2583 val mutable m_active
= 0
2584 val mutable m_first
= 0
2585 val mutable m_qsearch
= ""
2586 val mutable m_pan
= 0
2587 method getactive
= m_active
2588 method getfirst
= m_first
2589 method getqsearch
= m_qsearch
2590 method getpan
= m_pan
2591 method setqsearch
s = m_qsearch
<- s
2594 let withoutlastutf8 s =
2595 let len = String.length
s in
2603 let b = Char.code
s.[pos
] in
2604 if b land 0b110000 = 0b11000000
2609 if Char.code
s.[len-1] land 0x80 = 0
2613 String.sub
s 0 first;
2616 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2618 state.mode
<- Textentry
(te
, onleave
);
2621 G.postRedisplay "textentrykeyboard enttext";
2623 let histaction cmd
=
2626 | Some
(action, _
) ->
2627 state.mode
<- Textentry
(
2628 (c, action cmd
, opthist
, onkey
, ondone), onleave
2630 G.postRedisplay "textentry histaction"
2633 | 0xff08 -> (* backspace *)
2634 let s = withoutlastutf8 text in
2635 let len = String.length
s in
2639 G.postRedisplay "textentrykeyboard after cancel";
2642 enttext (c, s, opthist
, onkey
, ondone)
2648 G.postRedisplay "textentrykeyboard after confirm"
2650 | 0xff52 -> histaction HCprev
2651 | 0xff54 -> histaction HCnext
2652 | 0xff50 -> histaction HCfirst
2653 | 0xff57 -> histaction HClast
2655 | 0xff1b -> (* escape*)
2656 if String.length
text = 0
2658 begin match opthist
with
2660 | Some
(_
, onhistcancel
) -> onhistcancel
()
2664 G.postRedisplay "textentrykeyboard after cancel2"
2667 enttext (c, "", opthist
, onkey
, ondone)
2670 | 0xff9f | 0xffff -> () (* delete *)
2672 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2673 begin match onkey
text key with
2677 G.postRedisplay "textentrykeyboard after confirm2";
2680 enttext (c, text, opthist
, onkey
, ondone);
2684 G.postRedisplay "textentrykeyboard after cancel3"
2687 state.mode
<- Textentry
(te
, onleave
);
2688 G.postRedisplay "textentrykeyboard switch";
2692 vlog "unhandled key %s" (Wsi.keyname
key)
2695 let firstof first active
=
2696 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2697 then max
0 (active
- (fstate.maxrows
/2))
2701 let calcfirst first active
=
2704 let rows = active
- first in
2705 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2709 let scrollph y maxy =
2710 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2711 let sh = float conf.winh
/. sh in
2712 let sh = max
sh (float conf.scrollh
) in
2717 else float y /. float maxy
2719 let position = (float conf.winh
-. sh) *. percent in
2722 if position +. sh > float conf.winh
2723 then float conf.winh
-. sh
2729 let coe s = (s :> uioh
);;
2731 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2733 val m_pan
= source#getpan
2734 val m_first
= source#getfirst
2735 val m_active
= source#getactive
2736 val m_qsearch
= source#getqsearch
2737 val m_prev_uioh
= state.uioh
2739 method private elemunder
y =
2740 let n = y / (fstate.fontsize
+1) in
2741 if m_first
+ n < source#getitemcount
2743 if source#hasaction
(m_first
+ n)
2744 then Some
(m_first
+ n)
2751 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2752 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2753 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2754 GlDraw.color
(1., 1., 1.);
2755 Gl.enable `texture_2d
;
2756 let fs = fstate.fontsize
in
2758 let ww = fstate.wwidth
in
2759 let tabw = 30.0*.ww in
2760 let itemcount = source#getitemcount
in
2762 if (row - m_first
) * nfs > conf.winh
2765 if row >= 0 && row < itemcount
2767 let (s, level
) = source#getitem
row in
2768 let y = (row - m_first
) * nfs in
2769 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2772 Gl.disable `texture_2d
;
2773 GlDraw.polygon_mode `both `line
;
2774 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2775 GlDraw.rect (1., float (y + 1))
2776 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2777 GlDraw.polygon_mode `both `fill
;
2778 GlDraw.color
(1., 1., 1.);
2779 Gl.enable `texture_2d
;
2782 let drawtabularstring s =
2783 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2786 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2789 let len = String.length
s - tabpos - 1 in
2790 let s1 = String.sub
s 0 tabpos
2791 and s2
= String.sub
s (tabpos + 1) len in
2792 let nx = drawstr x s1 in
2794 let x = x +. (max
tabw sw) in
2801 let _ = drawtabularstring s in
2808 Gl.disable `texture_2d
;
2810 method updownlevel incr
=
2811 let len = source#getitemcount
in
2813 if m_active
>= 0 && m_active
< len
2814 then snd
(source#getitem m_active
)
2818 if i
= len then i
-1 else if i
= -1 then 0 else
2819 let _, l = source#getitem i
in
2820 if l != curlevel then i
else flow (i
+incr
)
2822 let active = flow m_active
in
2823 let first = calcfirst m_first
active in
2824 G.postRedisplay "outline updownlevel";
2825 {< m_active
= active; m_first
= first >}
2827 method private key1
key mask
=
2828 let set1 active first qsearch
=
2829 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2831 let search active pattern incr
=
2834 if n >= 0 && n < source#getitemcount
2836 let s, _ = source#getitem
n in
2838 (try ignore
(Str.search_forward
re s 0); true
2839 with Not_found
-> false)
2841 else loop (n + incr
)
2848 let re = Str.regexp_case_fold pattern
in
2854 let itemcount = source#getitemcount
in
2855 let find start incr
=
2857 if i
= -1 || i
= itemcount
2860 if source#hasaction i
2862 else find (i
+ incr
)
2867 let set active first =
2868 let first = bound first 0 (itemcount - fstate.maxrows
) in
2870 coe {< m_active
= active; m_first
= first >}
2873 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2875 let incr1 = if incr
> 0 then 1 else -1 in
2876 if isvisible m_first m_active
2879 let next = m_active
+ incr
in
2881 if next < 0 || next >= itemcount
2883 else find next incr1
2885 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2891 let first = m_first
+ incr
in
2892 let first = bound first 0 (itemcount - 1) in
2894 let next = m_active
+ incr
in
2895 let next = bound next 0 (itemcount - 1) in
2898 let active = if next = -1 then m_active
else next in
2901 let first = min
next m_first
in
2903 if abs
(next - first) > fstate.maxrows
2909 let first = m_first
+ incr
in
2910 let first = bound first 0 (itemcount - 1) in
2912 let next = m_active
+ incr
in
2913 let next = bound next 0 (itemcount - 1) in
2914 let next = find next incr1 in
2916 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2918 let active = if m_active
= -1 then next else m_active
in
2923 if isvisible first active
2929 G.postRedisplay "listview navigate";
2933 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2934 let incr = if key = 0x72 then -1 else 1 in
2936 match search (m_active
+ incr) m_qsearch
incr with
2938 state.text <- m_qsearch ^
" [not found]";
2941 state.text <- m_qsearch
;
2942 active, firstof m_first
active
2944 G.postRedisplay "listview ctrl-r/s";
2945 set1 active first m_qsearch
;
2947 | 0xff08 -> (* backspace *)
2948 if String.length m_qsearch
= 0
2951 let qsearch = withoutlastutf8 m_qsearch
in
2952 let len = String.length
qsearch in
2956 G.postRedisplay "listview empty qsearch";
2957 set1 m_active m_first
"";
2961 match search m_active
qsearch ~
-1 with
2963 state.text <- qsearch ^
" [not found]";
2966 state.text <- qsearch;
2967 active, firstof m_first
active
2969 G.postRedisplay "listview backspace qsearch";
2970 set1 active first qsearch
2973 | key when (key != 0 && key land 0xff00 != 0xff00) ->
2974 let pattern = m_qsearch ^
Wsi.toutf8
key in
2976 match search m_active
pattern 1 with
2978 state.text <- pattern ^
" [not found]";
2981 state.text <- pattern;
2982 active, firstof m_first
active
2984 G.postRedisplay "listview qsearch add";
2985 set1 active first pattern;
2987 | 0xff1b -> (* escape *)
2989 if String.length m_qsearch
= 0
2991 G.postRedisplay "list view escape";
2994 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2996 | None
-> m_prev_uioh
3001 G.postRedisplay "list view kill qsearch";
3002 source#setqsearch
"";
3003 coe {< m_qsearch
= "" >}
3006 | 0xff0d -> (* return *)
3008 let self = {< m_qsearch
= "" >} in
3009 source#setqsearch
"";
3011 G.postRedisplay "listview enter";
3012 if m_active
>= 0 && m_active
< source#getitemcount
3014 source#exit
(coe self) false m_active m_first m_pan
"";
3017 source#exit
(coe self) true m_active m_first m_pan
"";
3020 begin match opt with
3021 | None
-> m_prev_uioh
3025 | 0xff9f | 0xffff -> (* delete *)
3028 | 0xff52 -> navigate ~
-1 (* up *)
3029 | 0xff54 -> navigate 1 (* down *)
3030 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3031 | 0xff56 -> navigate fstate.maxrows
(* next *)
3033 | 0xff53 -> (* right *)
3035 G.postRedisplay "listview right";
3036 coe {< m_pan
= m_pan
- 1 >}
3038 | 0xff51 -> (* left *)
3040 G.postRedisplay "listview left";
3041 coe {< m_pan
= m_pan
+ 1 >}
3043 | 0xff50 -> (* home *)
3044 let active = find 0 1 in
3045 G.postRedisplay "listview home";
3048 | 0xff57 -> (* end *)
3049 let first = max
0 (itemcount - fstate.maxrows
) in
3050 let active = find (itemcount - 1) ~
-1 in
3051 G.postRedisplay "listview end";
3054 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3058 dolog "listview unknown key %#x" key; coe self
3060 method key key mask
=
3061 match state.mode
with
3062 | Textentry te
-> textentrykeyboard key mask te
; coe self
3063 | _ -> self#key1
key mask
3065 method button button down
x y _ =
3068 | 1 when x > conf.winw
- conf.scrollbw
->
3069 G.postRedisplay "listview scroll";
3072 let _, position, sh = self#
scrollph in
3073 if y > truncate
position && y < truncate
(position +. sh)
3075 state.mstate
<- Mscrolly
;
3079 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3080 let first = truncate
(s *. float source#getitemcount
) in
3081 let first = min source#getitemcount
first in
3082 Some
(coe {< m_first
= first; m_active
= first >})
3084 state.mstate
<- Mnone
;
3087 | 1 when not down
->
3088 begin match self#elemunder
y with
3090 G.postRedisplay "listview click";
3092 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3096 | n when (n == 4 || n == 5) && not down
->
3097 let len = source#getitemcount
in
3099 if n = 5 && m_first
+ fstate.maxrows
>= len
3103 let first = m_first
+ (if n == 4 then -1 else 1) in
3104 bound first 0 (len - 1)
3106 G.postRedisplay "listview wheel";
3107 Some
(coe {< m_first
= first >})
3112 | None
-> m_prev_uioh
3116 match state.mstate
with
3118 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3119 let first = truncate
(s *. float source#getitemcount
) in
3120 let first = min source#getitemcount
first in
3121 G.postRedisplay "listview motion";
3122 coe {< m_first
= first; m_active
= first >}
3125 method pmotion
x y =
3126 if x < conf.winw
- conf.scrollbw
3129 match self#elemunder
y with
3130 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3131 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3135 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3140 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3144 method infochanged
_ = ()
3146 method scrollpw
= (0, 0.0, 0.0)
3148 let nfs = fstate.fontsize
+ 1 in
3149 let y = m_first
* nfs in
3150 let itemcount = source#getitemcount
in
3151 let maxi = max
0 (itemcount - fstate.maxrows
) in
3152 let maxy = maxi * nfs in
3153 let p, h = scrollph y maxy in
3156 method modehash
= modehash
3159 class outlinelistview ~source
=
3162 ~source
:(source
:> lvsource
)
3164 ~modehash
:(findkeyhash conf "outline")
3167 method key key mask
=
3168 let calcfirst first active =
3171 let rows = active - first in
3172 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3176 let active = m_active
+ incr in
3177 let active = bound active 0 (source#getitemcount
- 1) in
3178 let first = calcfirst m_first
active in
3179 G.postRedisplay "outline navigate";
3180 coe {< m_active
= active; m_first
= first >}
3182 let ctrl = Wsi.withctrl mask
in
3184 | 110 when ctrl -> (* ctrl-n *)
3185 source#narrow m_qsearch
;
3186 G.postRedisplay "outline ctrl-n";
3187 coe {< m_first
= 0; m_active
= 0 >}
3189 | 117 when ctrl -> (* ctrl-u *)
3191 G.postRedisplay "outline ctrl-u";
3193 coe {< m_first
= 0; m_active
= 0 >}
3195 | 108 when ctrl -> (* ctrl-l *)
3196 let first = m_active
- (fstate.maxrows
/ 2) in
3197 G.postRedisplay "outline ctrl-l";
3198 coe {< m_first
= first >}
3200 | 0xff9f | 0xffff -> (* delete *)
3201 source#remove m_active
;
3202 G.postRedisplay "outline delete";
3203 let active = max
0 (m_active
-1) in
3204 coe {< m_first
= firstof m_first
active;
3205 m_active
= active >}
3207 | 0xff52 -> navigate ~
-1 (* up *)
3208 | 0xff54 -> navigate 1 (* down *)
3209 | 0xff55 -> (* prior *)
3210 navigate ~
-(fstate.maxrows
)
3211 | 0xff56 -> (* next *)
3212 navigate fstate.maxrows
3214 | 0xff53 -> (* [ctrl-]right *)
3218 G.postRedisplay "outline ctrl right";
3219 {< m_pan
= m_pan
+ 1 >}
3221 else self#updownlevel
1
3225 | 0xff51 -> (* [ctrl-]left *)
3229 G.postRedisplay "outline ctrl left";
3230 {< m_pan
= m_pan
- 1 >}
3232 else self#updownlevel ~
-1
3236 | 0xff50 -> (* home *)
3237 G.postRedisplay "outline home";
3238 coe {< m_first
= 0; m_active
= 0 >}
3240 | 0xff57 -> (* end *)
3241 let active = source#getitemcount
- 1 in
3242 let first = max
0 (active - fstate.maxrows
) in
3243 G.postRedisplay "outline end";
3244 coe {< m_active
= active; m_first
= first >}
3246 | _ -> super#
key key mask
3249 let outlinesource usebookmarks
=
3252 inherit lvsourcebase
3253 val mutable m_items
= empty
3254 val mutable m_orig_items
= empty
3255 val mutable m_prev_items
= empty
3256 val mutable m_narrow_pattern
= ""
3257 val mutable m_hadremovals
= false
3259 method getitemcount
=
3260 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3263 if n == Array.length m_items
&& m_hadremovals
3265 ("[Confirm removal]", 0)
3267 let s, n, _ = m_items
.(n) in
3270 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3271 ignore
(uioh
, first, qsearch);
3272 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3274 if String.length m_narrow_pattern
= 0
3280 if not
confrimremoval
3282 let _, _, anchor = m_items
.(active) in
3287 state.bookmarks
<- Array.to_list m_items
;
3288 m_orig_items
<- m_items
;
3291 else m_items
<- items;
3295 method hasaction
_ = true
3298 if Array.length m_items
!= Array.length m_orig_items
3299 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3302 method narrow
pattern =
3303 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3307 let rec loop accu n =
3310 m_narrow_pattern
<- pattern;
3311 m_items
<- Array.of_list
accu
3314 let (s, _, _) as o = m_items
.(n) in
3316 if (try ignore
(Str.search_forward
re s 0); true
3317 with Not_found
-> false)
3323 loop [] (Array.length m_items
- 1)
3328 then Array.of_list
state.bookmarks
3331 m_items
<- m_orig_items
3336 if m
>= 0 && m
< Array.length m_items
3338 m_hadremovals
<- true;
3339 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3340 let n = if n >= m
then n+1 else n in
3345 method reset
anchor items =
3346 m_hadremovals
<- false;
3347 if m_orig_items
== empty || m_prev_items
!= items
3349 m_orig_items
<- items;
3350 if String.length m_narrow_pattern
= 0
3351 then m_items
<- items;
3353 m_prev_items
<- items;
3354 let rely = getanchory anchor in
3356 let rec loop n best bestd
=
3357 if n = Array.length m_items
3360 let (_, _, anchor) = m_items
.(n) in
3361 let orely = getanchory anchor in
3362 let d = abs
(orely - rely) in
3365 else loop (n+1) best bestd
3370 m_first
<- firstof m_first
active
3374 let enterselector usebookmarks
=
3375 let source = outlinesource usebookmarks
in
3379 then Array.of_list
state.bookmarks
3382 if Array.length
outlines = 0
3384 showtext ' ' errmsg
;
3387 state.text <- source#greetmsg
;
3388 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3389 let anchor = getanchor () in
3390 source#reset
anchor outlines;
3391 state.uioh
<- coe (new outlinelistview ~
source);
3392 G.postRedisplay "enter selector";
3396 let enteroutlinemode =
3397 let f = enterselector false in
3398 fun ()-> f "Document has no outline";
3401 let enterbookmarkmode =
3402 let f = enterselector true in
3403 fun () -> f "Document has no bookmarks (yet)";
3406 let color_of_string s =
3407 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3408 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3412 let color_to_string (r
, g
, b) =
3413 let r = truncate
(r *. 256.0)
3414 and g
= truncate
(g
*. 256.0)
3415 and b = truncate
(b *. 256.0) in
3416 Printf.sprintf
"%d/%d/%d" r g
b
3419 let irect_of_string s =
3420 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3423 let irect_to_string (x0,y0,x1,y1) =
3424 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3427 let makecheckers () =
3428 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3430 converted by Issac Trotts. July 25, 2002 *)
3431 let image_height = 64
3432 and image_width
= 64 in
3436 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3438 for i
= 0 to image_width
- 1 do
3439 for j
= 0 to image_height - 1 do
3440 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3441 (if (i
land 8 ) lxor (j
land 8) = 0
3442 then [|255;255;255|] else [|200;200;200|])
3447 let image = make_image () in
3448 let id = GlTex.gen_texture
() in
3449 GlTex.bind_texture `texture_2d
id;
3450 GlPix.store
(`unpack_alignment
1);
3451 GlTex.image2d
image;
3452 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3455 `mag_filter `nearest
;
3456 `min_filter `nearest
];
3460 let setcheckers enabled
=
3461 match state.texid
with
3463 if enabled
then state.texid
<- Some
(makecheckers ())
3468 GlTex.delete_texture texid
;
3469 state.texid
<- None
;
3473 let int_of_string_with_suffix s =
3474 let l = String.length
s in
3478 let suffix = Char.lowercase
s.[l-1] in
3480 | 'k'
-> String.sub
s 0 (l-1), 10
3481 | 'm'
-> String.sub
s 0 (l-1), 20
3482 | 'g'
-> String.sub
s 0 (l-1), 30
3486 let n = int_of_string
s1 in
3487 let m = n lsl shift
in
3489 then raise
(Failure
"value too large")
3493 let string_with_suffix_of_int n =
3501 if n land ((1 lsl 20) - 1) = 0
3504 if n land ((1 lsl 10) - 1) = 0
3511 let h = n mod 1000 in
3514 then string_of_int
h ^
s
3516 let s = Printf.sprintf
"_%03d%s" h s in
3523 let defghyllscroll = (40, 8, 32);;
3524 let ghyllscroll_of_string s =
3525 let (n, a, b) as nab
=
3528 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3530 if n <= a || n <= b || a >= b
3531 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3535 let ghyllscroll_to_string ((n, a, b) as nab
) =
3536 if nab
= defghyllscroll
3538 else Printf.sprintf
"%d,%d,%d" n a b;
3541 let describe_location () =
3543 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3545 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3546 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3550 else (100. *. (float state.y /. float maxy))
3554 Printf.sprintf
"page %d of %d [%.2f%%]"
3555 (fn+1) state.pagecount
percent
3558 "pages %d-%d of %d [%.2f%%]"
3559 (fn+1) (ln
+1) state.pagecount
percent
3563 let btos b = if b then "\xe2\x88\x9a" else "" in
3564 let showextended = ref false in
3565 let leave mode
= function
3566 | Confirm
-> state.mode
<- mode
3567 | Cancel
-> state.mode
<- mode
in
3570 val mutable m_first_time
= true
3571 val mutable m_l
= []
3572 val mutable m_a
= [||]
3573 val mutable m_prev_uioh
= nouioh
3574 val mutable m_prev_mode
= View
3576 inherit lvsourcebase
3578 method reset prev_mode prev_uioh
=
3579 m_a
<- Array.of_list
(List.rev m_l
);
3581 m_prev_mode
<- prev_mode
;
3582 m_prev_uioh
<- prev_uioh
;
3586 if n >= Array.length m_a
3590 | _, _, _, Action
_ -> m_active
<- n
3594 m_first_time
<- false;
3597 method int name get
set =
3599 (name
, `
int get
, 1, Action
(
3602 try set (int_of_string
s)
3604 state.text <- Printf.sprintf
"bad integer `%s': %s"
3605 s (Printexc.to_string exn
)
3608 let te = name ^
": ", "", None
, intentry, ondone in
3609 state.mode
<- Textentry
(te, leave m_prev_mode
);
3613 method int_with_suffix name get
set =
3615 (name
, `intws get
, 1, Action
(
3618 try set (int_of_string_with_suffix s)
3620 state.text <- Printf.sprintf
"bad integer `%s': %s"
3621 s (Printexc.to_string exn
)
3625 name ^
": ", "", None
, intentry_with_suffix, ondone
3627 state.mode
<- Textentry
(te, leave m_prev_mode
);
3631 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3633 (name
, `
bool (btos, get
), offset
, Action
(
3640 method color name get
set =
3642 (name
, `color get
, 1, Action
(
3644 let invalid = (nan
, nan
, nan
) in
3647 try color_of_string s
3649 state.text <- Printf.sprintf
"bad color `%s': %s"
3650 s (Printexc.to_string exn
);
3656 let te = name ^
": ", "", None
, textentry, ondone in
3657 state.text <- color_to_string (get
());
3658 state.mode
<- Textentry
(te, leave m_prev_mode
);
3662 method string name get
set =
3664 (name
, `
string get
, 1, Action
(
3666 let ondone s = set s in
3667 let te = name ^
": ", "", None
, textentry, ondone in
3668 state.mode
<- Textentry
(te, leave m_prev_mode
);
3672 method colorspace name get
set =
3674 (name
, `
string get
, 1, Action
(
3677 let vals = [| "rgb"; "bgr"; "gray" |] in
3679 inherit lvsourcebase
3682 m_active
<- int_of_colorspace conf.colorspace
;
3685 method getitemcount
= Array.length
vals
3686 method getitem
n = (vals.(n), 0)
3687 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3688 ignore
(uioh
, first, pan
, qsearch);
3689 if not cancel
then set active;
3691 method hasaction
_ = true
3695 let modehash = findkeyhash conf "info" in
3696 coe (new listview ~
source ~trusted
:true ~
modehash)
3699 method caption
s offset
=
3700 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3702 method caption2
s f offset
=
3703 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3705 method getitemcount
= Array.length m_a
3708 let tostr = function
3709 | `
int f -> string_of_int
(f ())
3710 | `intws
f -> string_with_suffix_of_int (f ())
3712 | `color
f -> color_to_string (f ())
3713 | `
bool (btos, f) -> btos (f ())
3716 let name, t
, offset
, _ = m_a
.(n) in
3717 ((let s = tostr t
in
3718 if String.length
s > 0
3719 then Printf.sprintf
"%s\t%s" name s
3723 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3727 m_qsearch
<- qsearch;
3729 match m_a
.(active) with
3730 | _, _, _, Action
f -> f uioh
3742 method hasaction
n =
3744 | _, _, _, Action
_ -> true
3748 let rec fillsrc prevmode prevuioh
=
3749 let sep () = src#caption
"" 0 in
3750 let colorp name get
set =
3752 (fun () -> color_to_string (get
()))
3755 let c = color_of_string v in
3758 state.text <- Printf.sprintf
"bad color `%s': %s"
3759 v (Printexc.to_string exn
);
3762 let oldmode = state.mode
in
3763 let birdseye = isbirdseye state.mode
in
3765 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3767 src#
bool "presentation mode"
3768 (fun () -> conf.presentation)
3770 conf.presentation <- v;
3771 state.anchor <- getanchor ();
3774 src#
bool "ignore case in searches"
3775 (fun () -> conf.icase
)
3776 (fun v -> conf.icase
<- v);
3779 (fun () -> conf.preload)
3780 (fun v -> conf.preload <- v);
3782 src#
bool "highlight links"
3783 (fun () -> conf.hlinks
)
3784 (fun v -> conf.hlinks
<- v);
3786 src#
bool "under info"
3787 (fun () -> conf.underinfo
)
3788 (fun v -> conf.underinfo
<- v);
3790 src#
bool "persistent bookmarks"
3791 (fun () -> conf.savebmarks
)
3792 (fun v -> conf.savebmarks
<- v);
3794 src#
bool "proportional display"
3795 (fun () -> conf.proportional
)
3796 (fun v -> reqlayout conf.angle
v);
3798 src#
bool "trim margins"
3799 (fun () -> conf.trimmargins
)
3800 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3802 src#
bool "persistent location"
3803 (fun () -> conf.jumpback
)
3804 (fun v -> conf.jumpback
<- v);
3807 src#
int "inter-page space"
3808 (fun () -> conf.interpagespace)
3810 conf.interpagespace <- n;
3812 match state.layout with
3817 state.maxy <- calcheight ();
3818 let y = getpagey pageno in
3823 (fun () -> conf.pagebias
)
3824 (fun v -> conf.pagebias
<- v);
3826 src#
int "scroll step"
3827 (fun () -> conf.scrollstep
)
3828 (fun n -> conf.scrollstep
<- n);
3830 src#
int "auto scroll step"
3832 match state.autoscroll
with
3834 | _ -> conf.autoscrollstep
)
3836 if state.autoscroll
<> None
3837 then state.autoscroll
<- Some
n;
3838 conf.autoscrollstep
<- n);
3841 (fun () -> truncate
(conf.zoom *. 100.))
3842 (fun v -> setzoom ((float v) /. 100.));
3845 (fun () -> conf.angle
)
3846 (fun v -> reqlayout v conf.proportional
);
3848 src#
int "scroll bar width"
3849 (fun () -> state.scrollw
)
3853 reshape conf.winw
conf.winh
;
3856 src#
int "scroll handle height"
3857 (fun () -> conf.scrollh
)
3858 (fun v -> conf.scrollh
<- v;);
3860 src#
int "thumbnail width"
3861 (fun () -> conf.thumbw
)
3863 conf.thumbw
<- min
4096 v;
3866 leavebirdseye beye
false;
3871 src#
string "columns"
3873 match conf.columns
with
3875 | Some
(multicol
, _) -> columns_to_string multicol
)
3877 let n, a, b = columns_of_string v in
3881 src#caption
"Presentation mode" 0;
3882 src#
bool "scrollbar visible"
3883 (fun () -> conf.scrollbarinpm
)
3885 if v != conf.scrollbarinpm
3887 conf.scrollbarinpm
<- v;
3888 if conf.presentation
3890 state.scrollw
<- if v then conf.scrollbw
else 0;
3891 reshape conf.winw
conf.winh
;
3897 src#caption
"Pixmap cache" 0;
3898 src#int_with_suffix
"size (advisory)"
3899 (fun () -> conf.memlimit
)
3900 (fun v -> conf.memlimit
<- v);
3903 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3904 (string_with_suffix_of_int state.memused
)
3905 (Hashtbl.length
state.tilemap
)) 1;
3908 src#caption
"Layout" 0;
3909 src#caption2
"Dimension"
3911 Printf.sprintf
"%dx%d (virtual %dx%d)"
3917 src#caption2
"Position" (fun () ->
3918 Printf.sprintf
"%dx%d" state.x state.y
3921 src#caption2
"Visible" (fun () -> describe_location ()) 1
3925 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3926 "Save these parameters as global defaults at exit"
3927 (fun () -> conf.bedefault
)
3928 (fun v -> conf.bedefault
<- v)
3932 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3933 src#
bool ~offset
:0 ~
btos "Extended parameters"
3934 (fun () -> !showextended)
3935 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3939 (fun () -> conf.checkers
)
3940 (fun v -> conf.checkers
<- v; setcheckers v);
3941 src#
bool "update cursor"
3942 (fun () -> conf.updatecurs
)
3943 (fun v -> conf.updatecurs
<- v);
3945 (fun () -> conf.verbose
)
3946 (fun v -> conf.verbose
<- v);
3947 src#
bool "invert colors"
3948 (fun () -> conf.invert
)
3949 (fun v -> conf.invert
<- v);
3951 (fun () -> conf.maxhfit
)
3952 (fun v -> conf.maxhfit
<- v);
3953 src#
bool "redirect stderr"
3954 (fun () -> conf.redirectstderr)
3955 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3956 src#
string "uri launcher"
3957 (fun () -> conf.urilauncher
)
3958 (fun v -> conf.urilauncher
<- v);
3959 src#
string "path launcher"
3960 (fun () -> conf.pathlauncher
)
3961 (fun v -> conf.pathlauncher
<- v);
3962 src#
string "tile size"
3963 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3966 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3967 conf.tileh
<- max
64 w;
3968 conf.tilew
<- max
64 h;
3971 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3972 v (Printexc.to_string exn
));
3973 src#
int "texture count"
3974 (fun () -> conf.texcount
)
3977 then conf.texcount
<- v
3978 else showtext '
!'
" Failed to set texture count please retry later"
3980 src#
int "slice height"
3981 (fun () -> conf.sliceheight
)
3983 conf.sliceheight
<- v;
3984 wcmd "sliceh %d" conf.sliceheight
;
3986 src#
int "anti-aliasing level"
3987 (fun () -> conf.aalevel
)
3989 conf.aalevel
<- bound v 0 8;
3990 state.anchor <- getanchor ();
3991 opendoc state.path
state.password
;
3993 src#
int "ui font size"
3994 (fun () -> fstate.fontsize
)
3995 (fun v -> setfontsize (bound v 5 100));
3996 colorp "background color"
3997 (fun () -> conf.bgcolor
)
3998 (fun v -> conf.bgcolor
<- v);
3999 src#
bool "crop hack"
4000 (fun () -> conf.crophack
)
4001 (fun v -> conf.crophack
<- v);
4002 src#
string "trim fuzz"
4003 (fun () -> irect_to_string conf.trimfuzz
)
4006 conf.trimfuzz
<- irect_of_string v;
4008 then settrim true conf.trimfuzz
;
4010 state.text <- Printf.sprintf
"bad irect `%s': %s"
4011 v (Printexc.to_string exn
)
4013 src#
string "throttle"
4015 match conf.maxwait
with
4016 | None
-> "show place holder if page is not ready"
4019 then "wait for page to fully render"
4021 "wait " ^ string_of_float
time
4022 ^
" seconds before showing placeholder"
4026 let f = float_of_string
v in
4028 then conf.maxwait
<- None
4029 else conf.maxwait
<- Some
f
4031 state.text <- Printf.sprintf
"bad time `%s': %s"
4032 v (Printexc.to_string exn
)
4034 src#
string "ghyll scroll"
4036 match conf.ghyllscroll
with
4038 | Some nab
-> ghyllscroll_to_string nab
4043 if String.length
v = 0
4045 else Some
(ghyllscroll_of_string v)
4047 conf.ghyllscroll
<- gs
4049 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4050 v (Printexc.to_string exn
)
4052 src#
string "selection command"
4053 (fun () -> conf.selcmd
)
4054 (fun v -> conf.selcmd
<- v);
4055 src#colorspace
"color space"
4056 (fun () -> colorspace_to_string conf.colorspace
)
4058 conf.colorspace
<- colorspace_of_int v;
4065 src#caption
"Document" 0;
4066 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4067 src#caption2
"Pages"
4068 (fun () -> string_of_int
state.pagecount
) 1;
4069 src#caption2
"Dimensions"
4070 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4074 src#caption
"Trimmed margins" 0;
4075 src#caption2
"Dimensions"
4076 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4079 src#reset prevmode prevuioh
;
4083 let prevmode = state.mode
4084 and prevuioh
= state.uioh in
4085 fillsrc prevmode prevuioh
;
4086 let source = (src :> lvsource
) in
4087 let modehash = findkeyhash conf "info" in
4088 state.uioh <- coe (object (self)
4089 inherit listview ~
source ~trusted
:true ~
modehash as super
4090 val mutable m_prevmemused
= 0
4091 method infochanged
= function
4093 if m_prevmemused
!= state.memused
4095 m_prevmemused
<- state.memused
;
4096 G.postRedisplay "memusedchanged";
4098 | Pdim
-> G.postRedisplay "pdimchanged"
4099 | Docinfo
-> fillsrc prevmode prevuioh
4101 method key key mask
=
4102 if not
(Wsi.withctrl mask
)
4105 | 0xff51 -> coe (self#updownlevel ~
-1)
4106 | 0xff53 -> coe (self#updownlevel
1)
4107 | _ -> super#
key key mask
4108 else super#
key key mask
4110 G.postRedisplay "info";
4116 inherit lvsourcebase
4117 method getitemcount
= Array.length
state.help
4119 let s, n, _ = state.help
.(n) in
4122 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4126 m_qsearch
<- qsearch;
4127 match state.help
.(active) with
4128 | _, _, Action
f -> Some
(f uioh)
4138 method hasaction
n =
4139 match state.help
.(n) with
4140 | _, _, Action
_ -> true
4147 let modehash = findkeyhash conf "help" in
4148 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4149 G.postRedisplay "help";
4154 let re = Str.regexp
"[\r\n]" in
4156 inherit lvsourcebase
4157 val mutable m_items
= [||]
4159 method getitemcount
= 1 + Array.length m_items
4164 else m_items
.(n-1), 0
4166 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4171 then Buffer.clear
state.errmsgs
;
4172 m_qsearch
<- qsearch;
4179 method hasaction
n =
4183 state.newerrmsgs
<- false;
4184 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4185 m_items
<- Array.of_list
l
4193 let source = (msgsource :> lvsource
) in
4194 let modehash = findkeyhash conf "listview" in
4195 state.uioh <- coe (object
4196 inherit listview ~
source ~trusted
:false ~
modehash as super
4199 then msgsource#reset
;
4202 G.postRedisplay "msgs";
4205 let quickbookmark ?title
() =
4206 match state.layout with
4212 let sec = Unix.gettimeofday
() in
4213 let tm = Unix.localtime
sec in
4214 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4218 (tm.Unix.tm_year
+ 1900)
4221 | Some
title -> title
4224 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4229 state.fullscreen
<- None
;
4233 let setautoscrollspeed step goingdown
=
4234 let incr = max
1 ((abs step
) / 2) in
4235 let incr = if goingdown
then incr else -incr in
4236 let astep = step
+ incr in
4237 state.autoscroll
<- Some
astep;
4240 let viewkeyboard key mask
=
4242 let mode = state.mode in
4243 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4246 G.postRedisplay "view:enttext"
4248 let ctrl = Wsi.withctrl mask
in
4253 | 0xff63 -> (* insert *)
4254 if conf.angle
mod 360 = 0
4256 state.mode <- LinkNav
(Ltgendir
0);
4259 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4261 | 0xff1b | 113 -> (* escape / q *)
4262 begin match state.mstate
with
4264 state.mstate
<- Mnone
;
4265 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4266 G.postRedisplay "kill zoom rect";
4268 match state.ranchors
with
4270 | (path
, password
, anchor) :: rest
->
4271 state.ranchors
<- rest
;
4272 state.anchor <- anchor;
4273 opendoc path password
4276 | 0xff08 -> (* backspace *)
4277 let y = getnav ~
-1 in
4278 gotoy_and_clear_text y
4286 G.postRedisplay "dehighlight";
4288 | 47 | 63 -> (* / ? *)
4289 let ondone isforw
s =
4290 cbput state.hists
.pat
s;
4291 state.searchpattern
<- s;
4294 let s = String.create
1 in
4295 s.[0] <- Char.chr
key;
4296 enttext (s, "", Some
(onhist state.hists
.pat
),
4297 textentry, ondone (key = 47))
4299 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4300 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4301 setzoom (conf.zoom +. incr)
4303 | 43 | 0xffab -> (* + *)
4306 try int_of_string
s with exc
->
4307 state.text <- Printf.sprintf
"bad integer `%s': %s"
4308 s (Printexc.to_string exc
);
4314 state.text <- "page bias is now " ^ string_of_int
n;
4317 enttext ("page bias: ", "", None
, intentry, ondone)
4319 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4320 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4321 setzoom (max
0.01 (conf.zoom -. decr))
4323 | 45 | 0xffad -> (* - *)
4324 let ondone msg
= state.text <- msg
in
4326 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4327 optentry state.mode, ondone
4330 | 48 when ctrl -> (* ctrl-0 *)
4333 | 49 when ctrl -> (* 1 *)
4334 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4338 | 0xffc6 -> (* f9 *)
4341 | 57 when ctrl -> (* ctrl-9 *)
4344 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4345 when not
ctrl -> (* 0..9 *)
4348 try int_of_string
s with exc
->
4349 state.text <- Printf.sprintf
"bad integer `%s': %s"
4350 s (Printexc.to_string exc
);
4356 cbput state.hists
.pag
(string_of_int
n);
4357 gotopage1 (n + conf.pagebias
- 1) 0;
4360 let pageentry text key =
4361 match Char.unsafe_chr
key with
4362 | 'g'
-> TEdone
text
4363 | _ -> intentry text key
4365 let text = "x" in text.[0] <- Char.chr
key;
4366 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4369 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4370 reshape conf.winw
conf.winh
;
4373 conf.hlinks
<- not
conf.hlinks
;
4374 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4375 G.postRedisplay "toggle highlightlinks";
4378 begin match state.autoscroll
with
4380 conf.autoscrollstep
<- step
;
4381 state.autoscroll
<- None
4383 if conf.autoscrollstep
= 0
4384 then state.autoscroll
<- Some
1
4385 else state.autoscroll
<- Some
conf.autoscrollstep
4389 conf.presentation <- not
conf.presentation;
4390 if conf.presentation
4392 if not
conf.scrollbarinpm
4393 then state.scrollw
<- 0;
4396 state.scrollw
<- conf.scrollbw
;
4398 showtext ' '
("presentation mode " ^
4399 if conf.presentation then "on" else "off");
4400 state.anchor <- getanchor ();
4404 begin match state.fullscreen
with
4406 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4409 state.fullscreen
<- None
;
4414 gotoy_and_clear_text 0
4417 gotopage1 (state.pagecount
- 1) 0
4419 | 112 | 78 -> (* p|N *)
4420 search state.searchpattern
false
4422 | 110 | 0xffc0 -> (* n|F3 *)
4423 search state.searchpattern
true
4426 begin match state.layout with
4429 gotoy_and_clear_text (getpagey l.pageno)
4433 begin match List.rev
state.layout with
4436 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4437 gotoy_and_clear_text (getpagey pageno)
4440 | 0xff9f | 0xffff -> (* delete *)
4441 begin match state.layout with
4444 let pageno = max
0 (l.pageno-1) in
4445 gotoy_and_clear_text (getpagey pageno)
4449 showtext ' '
(describe_location ());
4452 begin match state.layout with
4455 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4460 enterbookmarkmode ()
4462 | 104 | 0xffbe -> (* h|F1 *)
4468 | 101 when conf.redirectstderr -> (* e *)
4473 match state.layout with
4476 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4480 enttext ("bookmark: ", "", None
, textentry, ondone)
4484 showtext ' '
"Quick bookmark added";
4487 begin match state.layout with
4489 let rect = getpdimrect
l.pagedimno
in
4493 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4494 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4496 (truncate
(rect.(1) -. rect.(0)),
4497 truncate
(rect.(3) -. rect.(0)))
4499 let w = truncate
((float w)*.conf.zoom)
4500 and h = truncate
((float h)*.conf.zoom) in
4503 state.anchor <- getanchor ();
4504 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4506 G.postRedisplay "z";
4511 | 50 when ctrl -> (* ctrl-2 *)
4512 let maxw = getmaxw
() in
4514 then setzoom (maxw /. float conf.winw
)
4516 | 60 | 62 -> (* < > *)
4517 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4519 | 91 | 93 -> (* [ ] *)
4521 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4523 G.postRedisplay "brightness";
4525 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4526 setzoom state.prevzoom
4528 | 107 | 0xff52 -> (* k up *)
4529 begin match state.autoscroll
with
4531 begin match state.mode with
4532 | Birdseye beye
-> upbirdseye 1 beye
4535 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4536 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4539 setautoscrollspeed n false
4542 | 106 | 0xff54 -> (* j down *)
4543 begin match state.autoscroll
with
4545 begin match state.mode with
4546 | Birdseye beye
-> downbirdseye 1 beye
4549 then gotoy_and_clear_text (clamp (conf.winh
/2))
4550 else gotoy_and_clear_text (clamp conf.scrollstep
)
4553 setautoscrollspeed n true
4556 | 0xff51 | 0xff53 when Wsi.withnone mask
-> (* left / right *)
4564 let dx = if key = 0xff51 then dx else -dx in
4565 state.x <- state.x + dx;
4566 gotoy_and_clear_text state.y
4569 G.postRedisplay "lef/right"
4572 | 0xff55 -> (* prior *)
4576 match state.layout with
4578 | l :: _ -> state.y - l.pagey
4584 | 0xff56 -> (* next *)
4588 match List.rev
state.layout with
4590 | l :: _ -> getpagey l.pageno
4596 | 0xff50 -> gotoghyll 0
4597 | 0xff57 -> gotoghyll (clamp state.maxy)
4598 | 0xff53 when Wsi.withalt mask
->
4599 gotoghyll (getnav ~
-1)
4600 | 0xff51 when Wsi.withalt mask
->
4601 gotoghyll (getnav 1)
4604 state.anchor <- getanchor ();
4605 opendoc state.path
state.password
4610 | 118 when conf.debug
-> (* v *)
4613 match getopaque l.pageno with
4616 let x0, y0, x1, y1 = pagebbox opaque
in
4617 let a,b = float x0, float y0 in
4618 let c,d = float x1, float y0 in
4619 let e,f = float x1, float y1 in
4620 let h,j
= float x0, float y1 in
4621 let rect = (a,b,c,d,e,f,h,j
) in
4623 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4625 G.postRedisplay "v";
4628 vlog "huh? %s" (Wsi.keyname
key)
4631 let gotounder = function
4632 | Ulinkgoto
(pageno, top) ->
4636 gotopage1 pageno top;
4642 | Uremote
(filename
, pageno) ->
4644 if Sys.file_exists filename
4647 let dir = Filename.dirname
state.path in
4648 let path = Filename.concat
dir filename
in
4649 if Sys.file_exists
path
4653 if String.length
path > 0
4655 let anchor = getanchor () in
4656 let ranchor = state.path, state.password
, anchor in
4657 state.anchor <- (pageno, 0.0);
4658 state.ranchors
<- ranchor :: state.ranchors
;
4661 else showtext '
!'
("Could not find " ^ filename
)
4663 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4666 let linknavkeyboard key mask
linknav =
4670 G.postRedisplay "leave linknav"
4673 begin match linknav with
4674 | Ltgendir
_ -> viewkeyboard key mask
4675 | Ltexact
((l, opaque
, n), _) ->
4678 let under = getlink opaque
n in
4684 | 0xff50 -> (* home *)
4685 Some
(findlink opaque LDfirst
), -1
4687 | 0xff57 -> (* end *)
4688 Some
(findlink opaque LDlast
), 1
4690 | 0xff51 -> (* left *)
4691 Some
(findlink opaque
(LDleft
n)), -1
4693 | 0xff53 -> (* right *)
4694 Some
(findlink opaque
(LDright
n)), 1
4696 | 0xff52 -> (* up *)
4697 Some
(findlink opaque
(LDup
n)), -1
4699 | 0xff54 -> (* down *)
4700 Some
(findlink opaque
(LDdown
n)), 1
4704 begin match opt with
4705 | Some Lnolock
-> showtext '
!'
"failed to acquire lock";
4707 begin match findpwl
l.pageno dir with
4710 state.mode <- LinkNav
(Ltgendir
dir);
4711 let y, h = getpageyh pageno in
4714 then y + h - conf.winh
4720 | Some
(Lfound
(m, x0, y0, x1, y1)) ->
4722 || l.pagedispy + (y1 - l.pagey) > conf.winh
- state.hscrollh
4724 state.mode <- LinkNav
(Ltgendir
0);
4725 gotoy (state.y + (y0 - l.pagey))
4730 match findpwl
l.pageno dir with
4733 state.mode <- LinkNav
(Ltgendir
dir);
4734 let y, h = getpageyh pageno in
4737 then y + h - conf.winh
4743 let r = x0, y0, x1, y1 in
4744 state.mode <- LinkNav
(Ltexact
((l, opaque
, m), r));
4745 G.postRedisplay "linknav up"
4748 state.mode <- LinkNav
(Ltgendir
0);
4749 viewkeyboard key mask
4754 let keyboard key mask
=
4755 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4756 then wcmd "interrupt"
4757 else state.uioh <- state.uioh#
key key mask
4760 let birdseyekeyboard key mask
4761 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4763 match conf.columns
with
4765 | Some
((c, _, _), _) -> c
4768 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4769 let y, h = getpageyh pageno in
4770 let top = (conf.winh
- h) / 2 in
4771 gotoy (max
0 (y - top))
4772 | 0xff0d -> leavebirdseye beye
false
4773 | 0xff1b -> leavebirdseye beye
true (* escape *)
4774 | 0xff52 -> upbirdseye incr beye
(* prior *)
4775 | 0xff54 -> downbirdseye incr beye
(* next *)
4776 | 0xff51 -> upbirdseye 1 beye
(* up *)
4777 | 0xff53 -> downbirdseye 1 beye
(* down *)
4780 begin match state.layout with
4784 state.mode <- Birdseye
(
4785 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4787 gotopage1 l.pageno 0;
4790 let layout = layout (state.y-conf.winh
) conf.winh
in
4792 | [] -> gotoy (clamp (-conf.winh
))
4794 state.mode <- Birdseye
(
4795 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4797 gotopage1 l.pageno 0
4800 | [] -> gotoy (clamp (-conf.winh
))
4804 begin match List.rev
state.layout with
4806 let layout = layout (state.y + conf.winh
) conf.winh
in
4807 begin match layout with
4809 let incr = l.pageh
- l.pagevh in
4814 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4816 G.postRedisplay "birdseye pagedown";
4818 else gotoy (clamp (incr + conf.interpagespace*2));
4822 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4823 gotopage1 l.pageno 0;
4826 | [] -> gotoy (clamp conf.winh
)
4830 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4834 let pageno = state.pagecount
- 1 in
4835 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4836 if not
(pagevisible state.layout pageno)
4839 match List.rev
state.pdims
with
4841 | (_, _, h, _) :: _ -> h
4843 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4844 else G.postRedisplay "birdseye end";
4845 | _ -> viewkeyboard key mask
4850 match state.mode with
4851 | Textentry
_ -> scalecolor 0.4
4853 | View
-> scalecolor 1.0
4854 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4855 if l.pageno = hooverpageno
4858 if l.pageno = pageno
4864 begin match getopaque l.pageno with
4866 if tileready l l.pagex l.pagey
4868 let x = l.pagedispx - l.pagex
4869 and y = l.pagedispy - l.pagey in
4870 postprocess opaque
conf.hlinks
x y;
4876 let scrollindicator () =
4877 let sbw, ph
, sh = state.uioh#
scrollph in
4878 let sbh, pw
, sw = state.uioh#scrollpw
in
4880 GlDraw.color (0.64, 0.64, 0.64);
4882 (float (conf.winw
- sbw), 0.)
4883 (float conf.winw
, float conf.winh
)
4886 (0., float (conf.winh
- sbh))
4887 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4889 GlDraw.color (0.0, 0.0, 0.0);
4892 (float (conf.winw
- sbw), ph
)
4893 (float conf.winw
, ph
+. sh)
4896 (pw
, float (conf.winh
- sbh))
4897 (pw
+. sw, float conf.winh
)
4902 match state.mstate
with
4903 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4906 | Msel
((x0, y0), (x1, y1)) ->
4907 let rec loop = function
4909 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4910 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4911 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4912 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4914 match getopaque l.pageno with
4916 let x0, y0 = pagetranslatepoint l x0 y0 in
4917 let x1, y1 = pagetranslatepoint l x1 y1 in
4918 seltext opaque
(x0, y0, x1, y1);
4926 let showrects rects
=
4928 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4929 GlDraw.polygon_mode `both `fill
;
4930 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4932 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4934 if l.pageno = pageno
4936 let dx = float (l.pagedispx - l.pagex) in
4937 let dy = float (l.pagedispy - l.pagey) in
4938 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4939 GlDraw.begins `quads
;
4941 GlDraw.vertex2
(x0+.dx, y0+.dy);
4942 GlDraw.vertex2
(x1+.dx, y1+.dy);
4943 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4944 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4955 GlClear.color (scalecolor2 conf.bgcolor
);
4956 GlClear.clear
[`
color];
4957 List.iter
drawpage state.layout;
4959 match state.mode with
4960 | LinkNav
(Ltexact
((page
, _, _), (x0, y0, x1, y1))) ->
4973 begin match state.mstate
with
4974 | Mzoomrect
((x0, y0), (x1, y1)) ->
4976 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4977 GlDraw.polygon_mode `both `fill
;
4978 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4979 GlDraw.rect (float x0, float y0)
4980 (float x1, float y1);
4987 let mx, my
= state.mpos
in
4993 let zoomrect x y x1 y1 =
4996 and y0 = min
y y1 in
4997 gotoy (state.y + y0);
4998 state.anchor <- getanchor ();
4999 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5001 if state.w < conf.winw
- state.scrollw
5002 then (conf.winw
- state.scrollw
- state.w) / 2
5005 state.x <- (state.x + margin) - x0;
5007 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5008 state.mstate
<- Mnone
;
5012 let winw = conf.winw - state.scrollw
- 1 in
5013 let s = float x /. float winw in
5014 let destx = truncate
(float (state.w + winw) *. s) in
5015 state.x <- winw - destx;
5016 gotoy_and_clear_text state.y;
5017 state.mstate
<- Mscrollx
;
5021 let s = float y /. float conf.winh
in
5022 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5023 gotoy_and_clear_text desty;
5024 state.mstate
<- Mscrolly
;
5027 let viewmouse button down
x y mask
=
5029 | n when (n == 4 || n == 5) && not down
->
5030 if Wsi.withctrl mask
5032 match state.mstate
with
5033 | Mzoom
(oldn
, i
) ->
5041 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5043 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5045 let zoom = conf.zoom -. incr in
5047 state.mstate
<- Mzoom
(n, 0);
5049 state.mstate
<- Mzoom
(n, i
+1);
5051 else state.mstate
<- Mzoom
(n, 0)
5053 | _ -> state.mstate
<- Mzoom
(n, 0)
5056 match state.autoscroll
with
5057 | Some step
-> setautoscrollspeed step
(n=4)
5061 then -conf.scrollstep
5062 else conf.scrollstep
5064 let incr = incr * 2 in
5065 let y = clamp incr in
5066 gotoy_and_clear_text y
5069 | 1 when Wsi.withctrl mask
->
5072 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5073 state.mstate
<- Mpan
(x, y)
5076 state.mstate
<- Mnone
5081 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5083 state.mstate
<- Mzoomrect
(p, p)
5086 match state.mstate
with
5087 | Mzoomrect
((x0, y0), _) ->
5088 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5089 then zoomrect x0 y0 x y
5091 state.mstate
<- Mnone
;
5092 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5093 G.postRedisplay "kill accidental zoom rect";
5096 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5097 state.mstate
<- Mnone
5100 | 1 when x > conf.winw - state.scrollw
->
5103 let _, position, sh = state.uioh#
scrollph in
5104 if y > truncate
position && y < truncate
(position +. sh)
5105 then state.mstate
<- Mscrolly
5108 state.mstate
<- Mnone
5110 | 1 when y > conf.winh
- state.hscrollh ->
5113 let _, position, sw = state.uioh#scrollpw
in
5114 if x > truncate
position && x < truncate
(position +. sw)
5115 then state.mstate
<- Mscrollx
5118 state.mstate
<- Mnone
5121 let dest = if down
then getunder x y else Unone
in
5122 begin match dest with
5123 | Ulinkgoto
(pageno, top) ->
5127 gotopage1 pageno top;
5133 | Uremote
(filename
, pageno) ->
5135 if Sys.file_exists filename
5138 let dir = Filename.dirname
state.path in
5139 let path = Filename.concat
dir filename
in
5140 if Sys.file_exists
path
5144 if String.length
path > 0
5146 let anchor = getanchor () in
5147 let ranchor = state.path, state.password
, anchor in
5148 state.anchor <- (pageno, 0.0);
5149 state.ranchors
<- ranchor :: state.ranchors
;
5152 else showtext '
!'
("Could not find " ^ filename
)
5154 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5156 | Unone
when down
->
5157 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5158 state.mstate
<- Mpan
(x, y);
5160 | Unone
| Utext
_ ->
5163 if conf.angle
mod 360 = 0
5165 state.mstate
<- Msel
((x, y), (x, y));
5166 G.postRedisplay "mouse select";
5170 match state.mstate
with
5173 | Mzoom
_ | Mscrollx
| Mscrolly
->
5174 state.mstate
<- Mnone
5176 | Mzoomrect
((x0, y0), _) ->
5180 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5181 state.mstate
<- Mnone
5183 | Msel
((_, y0), (_, y1)) ->
5184 let rec loop = function
5187 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5188 || ((y1 >= l.pagedispy
5189 && y1 <= (l.pagedispy + l.pagevh)))
5191 match getopaque l.pageno with
5193 copysel
conf.selcmd opaque
;
5194 G.postRedisplay "copysel"
5199 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5200 state.mstate
<- Mnone
;
5207 let birdseyemouse button down
x y mask
5208 (conf, leftx
, _, hooverpageno
, anchor) =
5211 let rec loop = function
5214 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5215 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5217 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5223 | _ -> viewmouse button down
x y mask
5226 let mouse button down
x y mask
=
5227 state.uioh <- state.uioh#button button down
x y mask
;
5231 state.uioh <- state.uioh#
motion x y
5235 state.uioh <- state.uioh#
pmotion x y;
5241 method key key mask
=
5242 begin match state.mode with
5243 | Textentry
textentry -> textentrykeyboard key mask
textentry
5244 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5245 | View
-> viewkeyboard key mask
5246 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5250 method button button bstate
x y mask
=
5251 begin match state.mode with
5253 | View
-> viewmouse button bstate
x y mask
5254 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5260 begin match state.mode with
5262 | View
| Birdseye
_ | LinkNav
_ ->
5263 match state.mstate
with
5264 | Mzoom
_ | Mnone
-> ()
5269 state.mstate
<- Mpan
(x, y);
5270 if conf.zoom > 1.0 then state.x <- state.x + dx;
5272 gotoy_and_clear_text y
5275 state.mstate
<- Msel
(a, (x, y));
5276 G.postRedisplay "motion select";
5279 let y = min
conf.winh
(max
0 y) in
5283 let x = min
conf.winw (max
0 x) in
5286 | Mzoomrect
(p0
, _) ->
5287 state.mstate
<- Mzoomrect
(p0
, (x, y));
5288 G.postRedisplay "motion zoomrect";
5292 method pmotion x y =
5293 begin match state.mode with
5294 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5295 let rec loop = function
5297 if hooverpageno
!= -1
5299 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5300 G.postRedisplay "pmotion birdseye no hoover";
5303 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5304 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5306 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5307 G.postRedisplay "pmotion birdseye hoover";
5317 match state.mstate
with
5318 | Mnone
-> updateunder x y
5319 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5324 method infochanged
_ = ()
5327 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5328 let p, h = scrollph state.y maxy in
5332 let winw = conf.winw - state.scrollw
- 1 in
5333 let fwinw = float winw in
5335 let sw = fwinw /. float state.w in
5336 let sw = fwinw *. sw in
5337 max
sw (float conf.scrollh
)
5340 let f = state.w+winw in
5341 let r = float (winw-state.x) /. float f in
5342 let p = fwinw *. r in
5346 if position +. sw > fwinw
5347 then fwinw -. position
5350 state.hscrollh, position, sw
5354 match state.mode with
5355 | LinkNav
_ -> "links"
5356 | Textentry
_ -> "textentry"
5357 | Birdseye
_ -> "birdseye"
5360 findkeyhash conf modename
5367 let fontpath = ref "";;
5370 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5373 let l = String.length
s in
5374 let b = Buffer.create
l in
5380 try Sys.getenv
"HOME"
5383 ("Can not determine home directory location: " ^
5384 Printexc.to_string exn
);
5388 let modifier_of_string = function
5389 | "alt" -> Wsi.altmask
5390 | "shift" -> Wsi.shiftmask
5391 | "ctrl" | "control" -> Wsi.ctrlmask
5392 | "meta" -> Wsi.metamask
5397 let r = Str.regexp
"-" in
5399 let elems = Str.full_split
r s in
5402 let m1 = modifier_of_string s in
5404 then (Wsi.namekey
s, m)
5407 | Str.Delim
s when n land 1 = 0 -> g s
5409 | Str.Delim
_ -> (k
, m)
5411 let rec loop n k
m = function
5414 let k, m = f n k m x in
5420 let keys_of_string =
5421 let r = Str.regexp
"[ \t]" in
5423 let elems = Str.split
r s in
5424 List.map
key_of_string elems
5427 let copykeyhashes c =
5428 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5431 let config_of c attrs
=
5435 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5436 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5437 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5438 | "preload" -> { c with preload = bool_of_string
v }
5439 | "page-bias" -> { c with pagebias
= int_of_string
v }
5440 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5441 | "auto-scroll-step" ->
5442 { c with autoscrollstep
= max
0 (int_of_string
v) }
5443 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5444 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5447 match String.lowercase
v with
5448 | "true" -> Some infinity
5450 | f -> Some
(float_of_string
f)
5452 { c with maxwait
= mw}
5453 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5454 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5455 | "vertical-margin" ->
5456 { c with interpagespace = max
0 (int_of_string
v) }
5458 let zoom = float_of_string
v /. 100. in
5459 let zoom = max
zoom 0.0 in
5460 { c with zoom = zoom }
5461 | "presentation" -> { c with presentation = bool_of_string
v }
5462 | "rotation-angle" -> { c with angle
= int_of_string
v }
5463 | "width" -> { c with winw = max
20 (int_of_string
v) }
5464 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5465 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5466 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5467 | "pixmap-cache-size" ->
5468 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5469 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5470 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5471 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5472 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5473 | "background-color" -> { c with bgcolor
= color_of_string v }
5474 | "scrollbar-in-presentation" ->
5475 { c with scrollbarinpm
= bool_of_string
v }
5476 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5477 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5478 | "mupdf-store-size" ->
5479 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5480 | "checkers" -> { c with checkers
= bool_of_string
v }
5481 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5482 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5483 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5484 | "uri-launcher" -> { c with urilauncher
= unent v }
5485 | "path-launcher" -> { c with pathlauncher
= unent v }
5486 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5487 | "invert-colors" -> { c with invert
= bool_of_string
v }
5488 | "brightness" -> { c with colorscale
= float_of_string
v }
5489 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5491 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5493 let nab = columns_of_string v in
5494 { c with columns
= Some
(nab, [||]) }
5495 | "birds-eye-columns" ->
5496 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5497 | "selection-command" -> { c with selcmd
= unent v }
5498 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5501 prerr_endline
("Error processing attribute (`" ^
5502 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5505 let rec fold c = function
5508 let c = apply c k v in
5511 fold { c with keyhashes
= copykeyhashes c } attrs
;
5514 let fromstring f pos
n v d =
5517 dolog "Error processing attribute (%S=%S) at %d\n%s"
5518 n v pos
(Printexc.to_string exn
)
5523 let bookmark_of attrs
=
5524 let rec fold title page
rely = function
5525 | ("title", v) :: rest
-> fold v page
rely rest
5526 | ("page", v) :: rest
-> fold title v rely rest
5527 | ("rely", v) :: rest
-> fold title page
v rest
5528 | _ :: rest
-> fold title page
rely rest
5529 | [] -> title, page
, rely
5531 fold "invalid" "0" "0" attrs
5535 let rec fold path page
rely pan
= function
5536 | ("path", v) :: rest
-> fold v page
rely pan rest
5537 | ("page", v) :: rest
-> fold path v rely pan rest
5538 | ("rely", v) :: rest
-> fold path page
v pan rest
5539 | ("pan", v) :: rest
-> fold path page
rely v rest
5540 | _ :: rest
-> fold path page
rely pan rest
5541 | [] -> path, page
, rely, pan
5543 fold "" "0" "0" "0" attrs
5547 let rec fold rs ls
= function
5548 | ("out", v) :: rest
-> fold v ls rest
5549 | ("in", v) :: rest
-> fold rs
v rest
5550 | _ :: rest
-> fold ls rs rest
5556 let setconf dst
src =
5557 dst
.scrollbw
<- src.scrollbw
;
5558 dst
.scrollh
<- src.scrollh
;
5559 dst
.icase
<- src.icase
;
5560 dst
.preload <- src.preload;
5561 dst
.pagebias
<- src.pagebias
;
5562 dst
.verbose
<- src.verbose
;
5563 dst
.scrollstep
<- src.scrollstep
;
5564 dst
.maxhfit
<- src.maxhfit
;
5565 dst
.crophack
<- src.crophack
;
5566 dst
.autoscrollstep
<- src.autoscrollstep
;
5567 dst
.maxwait
<- src.maxwait
;
5568 dst
.hlinks
<- src.hlinks
;
5569 dst
.underinfo
<- src.underinfo
;
5570 dst
.interpagespace <- src.interpagespace;
5571 dst
.zoom <- src.zoom;
5572 dst
.presentation <- src.presentation;
5573 dst
.angle
<- src.angle
;
5574 dst
.winw <- src.winw;
5575 dst
.winh
<- src.winh
;
5576 dst
.savebmarks
<- src.savebmarks
;
5577 dst
.memlimit
<- src.memlimit
;
5578 dst
.proportional
<- src.proportional
;
5579 dst
.texcount
<- src.texcount
;
5580 dst
.sliceheight
<- src.sliceheight
;
5581 dst
.thumbw
<- src.thumbw
;
5582 dst
.jumpback
<- src.jumpback
;
5583 dst
.bgcolor
<- src.bgcolor
;
5584 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5585 dst
.tilew
<- src.tilew
;
5586 dst
.tileh
<- src.tileh
;
5587 dst
.mustoresize
<- src.mustoresize
;
5588 dst
.checkers
<- src.checkers
;
5589 dst
.aalevel
<- src.aalevel
;
5590 dst
.trimmargins
<- src.trimmargins
;
5591 dst
.trimfuzz
<- src.trimfuzz
;
5592 dst
.urilauncher
<- src.urilauncher
;
5593 dst
.colorspace
<- src.colorspace
;
5594 dst
.invert
<- src.invert
;
5595 dst
.colorscale
<- src.colorscale
;
5596 dst
.redirectstderr <- src.redirectstderr;
5597 dst
.ghyllscroll
<- src.ghyllscroll
;
5598 dst
.columns
<- src.columns
;
5599 dst
.beyecolumns
<- src.beyecolumns
;
5600 dst
.selcmd
<- src.selcmd
;
5601 dst
.updatecurs
<- src.updatecurs
;
5602 dst
.pathlauncher
<- src.pathlauncher
;
5603 dst
.keyhashes
<- copykeyhashes src;
5607 let h = Hashtbl.create
10 in
5608 let dc = { defconf with angle
= defconf.angle
} in
5609 let rec toplevel v t spos
_ =
5611 | Vdata
| Vcdata
| Vend
-> v
5612 | Vopen
("llppconfig", _, closed
) ->
5615 else { v with f = llppconfig
}
5617 error
"unexpected subelement at top level" s spos
5618 | Vclose
_ -> error
"unexpected close at top level" s spos
5620 and llppconfig
v t spos
_ =
5622 | Vdata
| Vcdata
-> v
5623 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5624 | Vopen
("defaults", attrs
, closed
) ->
5625 let c = config_of dc attrs
in
5629 else { v with f = defaults
}
5631 | Vopen
("ui-font", attrs
, closed
) ->
5632 let rec getsize size
= function
5634 | ("size", v) :: rest
->
5636 fromstring int_of_string spos
"size" v fstate.fontsize
in
5638 | l -> getsize size l
5640 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5643 else { v with f = uifont
(Buffer.create
10) }
5645 | Vopen
("doc", attrs
, closed
) ->
5646 let pathent, spage
, srely
, span
= doc_of attrs
in
5647 let path = unent pathent
5648 and pageno = fromstring int_of_string spos
"page" spage
0
5649 and rely = fromstring float_of_string spos
"rely" srely
0.0
5650 and pan
= fromstring int_of_string spos
"pan" span
0 in
5651 let c = config_of dc attrs
in
5652 let anchor = (pageno, rely) in
5654 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5655 else { v with f = doc
path pan
anchor c [] }
5658 error
"unexpected subelement in llppconfig" s spos
5660 | Vclose
"llppconfig" -> { v with f = toplevel }
5661 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5663 and defaults
v t spos
_ =
5665 | Vdata
| Vcdata
-> v
5666 | Vend
-> error
"unexpected end of input in defaults" s spos
5667 | Vopen
("keymap", attrs
, closed
) ->
5669 try List.assoc
"mode" attrs
5670 with Not_found
-> "global" in
5675 let h = findkeyhash dc modename in
5676 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5679 { v with f = pkeymap
ret KeyMap.empty }
5681 | Vopen
(_, _, _) ->
5682 error
"unexpected subelement in defaults" s spos
5684 | Vclose
"defaults" ->
5685 { v with f = llppconfig
}
5687 | Vclose
_ -> error
"unexpected close in defaults" s spos
5689 and uifont
b v t spos
epos =
5692 Buffer.add_substring
b s spos
(epos - spos
);
5694 | Vopen
(_, _, _) ->
5695 error
"unexpected subelement in ui-font" s spos
5696 | Vclose
"ui-font" ->
5697 if String.length
!fontpath = 0
5698 then fontpath := Buffer.contents
b;
5699 { v with f = llppconfig
}
5700 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5701 | Vend
-> error
"unexpected end of input in ui-font" s spos
5703 and doc
path pan
anchor c bookmarks
v t spos
_ =
5705 | Vdata
| Vcdata
-> v
5706 | Vend
-> error
"unexpected end of input in doc" s spos
5707 | Vopen
("bookmarks", _, closed
) ->
5710 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5712 | Vopen
("keymap", attrs
, closed
) ->
5714 try List.assoc
"mode" attrs
5715 with Not_found
-> "global"
5721 let h = findkeyhash c modename in
5722 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5723 doc
path pan
anchor c bookmarks
5725 { v with f = pkeymap
ret KeyMap.empty }
5727 | Vopen
(_, _, _) ->
5728 error
"unexpected subelement in doc" s spos
5731 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5732 { v with f = llppconfig
}
5734 | Vclose
_ -> error
"unexpected close in doc" s spos
5736 and pkeymap
ret keymap
v t spos
_ =
5738 | Vdata
| Vcdata
-> v
5739 | Vend
-> error
"unexpected end of input in keymap" s spos
5740 | Vopen
("map", attrs
, closed
) ->
5741 let r, l = map_of attrs
in
5742 let kss = fromstring keys_of_string spos
"in" r [] in
5743 let lss = fromstring keys_of_string spos
"out" l [] in
5747 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5748 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5751 then { v with f = pkeymap
ret keymap }
5754 { v with f = skip
"map" f }
5757 error
"unexpected subelement in keymap" s spos
5759 | Vclose
"keymap" ->
5760 { v with f = ret keymap }
5762 | Vclose
_ -> error
"unexpected close in keymap" s spos
5764 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5766 | Vdata
| Vcdata
-> v
5767 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5768 | Vopen
("item", attrs
, closed
) ->
5769 let titleent, spage
, srely
= bookmark_of attrs
in
5770 let page = fromstring int_of_string spos
"page" spage
0
5771 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5772 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5774 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5777 { v with f = skip
"item" f }
5780 error
"unexpected subelement in bookmarks" s spos
5782 | Vclose
"bookmarks" ->
5783 { v with f = doc
path pan
anchor c bookmarks }
5785 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5787 and skip tag
f v t spos
_ =
5789 | Vdata
| Vcdata
-> v
5791 error
("unexpected end of input in skipped " ^ tag
) s spos
5792 | Vopen
(tag'
, _, closed
) ->
5796 let f'
() = { v with f = skip tag
f } in
5797 { v with f = skip tag'
f'
}
5801 else error
("unexpected close in skipped " ^ tag
) s spos
5804 parse
{ f = toplevel; accu = () } s;
5810 let len = in_channel_length ic
in
5811 let s = String.create
len in
5812 really_input ic
s 0 len;
5815 | Parse_error
(msg
, s, pos
) ->
5816 let subs = subs s pos
in
5817 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5818 failwith
("parse error: " ^
s)
5821 failwith
("config load error: " ^
Printexc.to_string exn
)
5827 let dir = Filename.concat
home ".config" in
5828 if Sys.is_directory
dir then dir else home
5831 Filename.concat
dir "llpp.conf"
5834 let confpath = ref defconfpath;;
5837 if Sys.file_exists
!confpath
5840 (try Some
(open_in_bin
!confpath)
5843 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5844 Printexc.to_string exn
);
5853 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5854 Printexc.to_string exn
);
5860 f (Hashtbl.create
0, defconf)
5865 let pc, pb
, px, pa
=
5867 Hashtbl.find h (Filename.basename
state.path)
5868 with Not_found
-> dc, [], 0, (0, 0.0)
5872 state.bookmarks <- pb
;
5874 state.scrollw
<- conf.scrollbw
;
5876 then state.anchor <- pa
;
5877 cbput state.hists
.nav pa
;
5882 let add_attrs bb always
dc c =
5885 then Printf.bprintf bb
"\n %s='%b'" s a
5888 then Printf.bprintf bb
"\n %s='%d'" s a
5891 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5894 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5897 then Printf.bprintf bb
"\n %s='%f'" s a
5901 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5905 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5909 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5913 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5919 | Some
(_N
, _A
, _B
) ->
5920 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5930 else string_of_float
f
5932 Printf.bprintf bb
"\n %s='%s'" s v
5937 | Some
((n, a, b), _) when n > 1 ->
5938 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5944 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5949 then dc.winw, dc.winh
5951 match state.fullscreen
with
5953 | None
-> c.winw, c.winh
5955 let zoom, presentation, interpagespace, maxwait
=
5957 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5959 match state.mode with
5960 | Birdseye
(bc
, _, _, _, _) ->
5961 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5962 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5964 oi
"width" w dc.winw;
5965 oi
"height" h dc.winh
;
5966 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5967 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5968 ob "case-insensitive-search" c.icase
dc.icase
;
5969 ob "preload" c.preload dc.preload;
5970 oi
"page-bias" c.pagebias
dc.pagebias
;
5971 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5972 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5973 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5974 ob "crop-hack" c.crophack
dc.crophack
;
5975 oW
"throttle" maxwait
dc.maxwait
;
5976 ob "highlight-links" c.hlinks
dc.hlinks
;
5977 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5978 oi
"vertical-margin" interpagespace dc.interpagespace;
5979 oz
"zoom" zoom dc.zoom;
5980 ob "presentation" presentation dc.presentation;
5981 oi
"rotation-angle" c.angle
dc.angle
;
5982 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5983 ob "proportional-display" c.proportional
dc.proportional
;
5984 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5985 oi
"tex-count" c.texcount
dc.texcount
;
5986 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5987 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5988 ob "persistent-location" c.jumpback
dc.jumpback
;
5989 oc
"background-color" c.bgcolor
dc.bgcolor
;
5990 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5991 oi
"tile-width" c.tilew
dc.tilew
;
5992 oi
"tile-height" c.tileh
dc.tileh
;
5993 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5994 ob "checkers" c.checkers
dc.checkers
;
5995 oi
"aalevel" c.aalevel
dc.aalevel
;
5996 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5997 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5998 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5999 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6000 oC
"color-space" c.colorspace
dc.colorspace
;
6001 ob "invert-colors" c.invert
dc.invert
;
6002 oF
"brightness" c.colorscale
dc.colorscale
;
6003 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6004 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6005 oco
"columns" c.columns
dc.columns
;
6006 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6007 os
"selection-command" c.selcmd
dc.selcmd
;
6008 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6011 let keymapsbuf always
dc c =
6012 let bb = Buffer.create
16 in
6013 let rec loop = function
6015 | (modename, h) :: rest
->
6016 let dh = findkeyhash dc modename in
6017 if always
|| h <> dh
6019 if Hashtbl.length
h > 0
6021 if Buffer.length
bb > 0
6022 then Buffer.add_char
bb '
\n'
;
6023 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6024 Hashtbl.iter
(fun i
o ->
6025 let isdifferent = always
||
6027 let dO = Hashtbl.find dh i
in
6029 with Not_found
-> true
6034 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6035 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6036 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6037 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6038 Buffer.add_string
bb (Wsi.keyname
k);
6041 let rec loop = function
6043 | km
:: [] -> addkm km
6044 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6048 Buffer.add_string
bb "<map in='";
6052 Buffer.add_char
bb '
\''
;
6053 Buffer.add_string
bb " out='";
6055 Buffer.add_string
bb "'/>\n"
6058 Buffer.add_char
bb '
\''
;
6059 Buffer.add_string
bb " out='";
6061 Buffer.add_string
bb "'/>\n"
6063 | KMmulti
(ins, kms
) ->
6064 Buffer.add_char
bb ' '
;
6066 Buffer.add_char
bb '
\''
;
6067 Buffer.add_string
bb " out='";
6069 Buffer.add_string
bb "'/>\n"
6071 Buffer.add_string
bb "</keymap>";
6081 let uifontsize = fstate.fontsize
in
6082 let bb = Buffer.create
32768 in
6084 let dc = if conf.bedefault
then conf else dc in
6085 Buffer.add_string
bb "<llppconfig>\n";
6087 if String.length
!fontpath > 0
6089 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6095 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6098 Buffer.add_string
bb "<defaults ";
6099 add_attrs bb true dc dc;
6100 let kb = keymapsbuf true dc dc in
6101 if Buffer.length
kb > 0
6103 Buffer.add_string
bb ">\n";
6104 Buffer.add_buffer
bb kb;
6105 Buffer.add_string
bb "\n</defaults>\n";
6107 else Buffer.add_string
bb "/>\n";
6109 let adddoc path pan
anchor c bookmarks =
6110 if bookmarks == [] && c = dc && anchor = emptyanchor
6113 Printf.bprintf
bb "<doc path='%s'"
6114 (enent
path 0 (String.length
path));
6116 if anchor <> emptyanchor
6118 let n, y = anchor in
6119 Printf.bprintf
bb " page='%d'" n;
6122 Printf.bprintf
bb " rely='%f'" y
6127 then Printf.bprintf
bb " pan='%d'" pan
;
6129 add_attrs bb false dc c;
6130 let kb = keymapsbuf false dc c in
6132 begin match bookmarks with
6134 if Buffer.length
kb > 0
6136 Buffer.add_string
bb ">\n";
6137 Buffer.add_buffer
bb kb;
6138 Buffer.add_string
bb "</doc>\n";
6140 else Buffer.add_string
bb "/>\n"
6142 Buffer.add_string
bb ">\n<bookmarks>\n";
6143 List.iter
(fun (title, _level
, (page, rely)) ->
6145 "<item title='%s' page='%d'"
6146 (enent
title 0 (String.length
title))
6151 Printf.bprintf
bb " rely='%f'" rely
6153 Buffer.add_string
bb "/>\n";
6155 Buffer.add_string
bb "</bookmarks>";
6156 if Buffer.length
kb > 0
6158 Buffer.add_string
bb "\n";
6159 Buffer.add_buffer
bb kb;
6161 Buffer.add_string
bb "\n</doc>\n";
6167 match state.mode with
6168 | Birdseye
(c, pan, _, _, _) ->
6170 match conf.columns
with
6171 | Some
((c, _, _), _) -> Some
c
6174 match c.columns
with
6175 | Some
(c, _) -> Some
(c, [||])
6178 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6179 | _ -> state.x, conf
6181 let basename = Filename.basename state.path in
6182 adddoc basename pan (getanchor ())
6185 match state.autoscroll
with
6187 | None
-> conf.autoscrollstep
}
6188 (if conf.savebmarks
then state.bookmarks else []);
6190 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6192 then adddoc path x y c bookmarks
6194 Buffer.add_string
bb "</llppconfig>";
6197 if Buffer.length
bb > 0
6200 let tmp = !confpath ^
".tmp" in
6201 let oc = open_out_bin
tmp in
6202 Buffer.output_buffer
oc bb;
6204 Unix.rename
tmp !confpath;
6207 ("error while saving configuration: " ^
Printexc.to_string exn
)
6214 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6215 "<password> Set password");
6217 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6218 "<path> Set path to the user interface font");
6220 ("-c", Arg.String
(fun s -> Config.confpath := s),
6221 "<path> Set path to the configuration file");
6223 ("-v", Arg.Unit
(fun () ->
6225 "%s\nconfiguration path: %s\n"
6229 exit
0), " Print version and exit");
6232 (fun s -> state.path <- s)
6233 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6235 if String.length
state.path = 0
6236 then (prerr_endline
"file name missing"; exit
1);
6240 let globalkeyhash = findkeyhash conf "global" in
6241 state.wsfd
<- Wsi.init
(object
6242 method display = display ()
6243 method reshape w h = reshape w h
6244 method mouse b d x y m = mouse b d x y m
6245 method motion x y = state.mpos
<- (x, y); motion x y
6246 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6248 match state.keystate
with
6253 try Hashtbl.find globalkeyhash km
6255 let modehash = state.uioh#
modehash in
6256 try Hashtbl.find modehash km
6257 with Not_found
-> KMinsrt
(k, m)
6259 | KMinsrt
(k, m) -> keyboard k m
6260 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6261 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6263 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land m = m'
->
6264 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6265 state.keystate
<- KSnone
6266 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land m = m'
->
6267 state.keystate
<- KSinto
(keys
, insrt
)
6269 state.keystate
<- KSnone
6271 method enter
x y = state.mpos
<- (x, y); pmotion x y
6272 method leave = state.mpos
<- (-1, -1)
6273 method quit
= raise Quit
6274 end) conf.winw conf.winh
;
6277 List.exists
GlMisc.check_extension
6278 [ "GL_ARB_texture_rectangle"
6279 ; "GL_EXT_texture_recangle"
6280 ; "GL_NV_texture_rectangle" ]
6282 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6284 let cr, sw = Unix.pipe
()
6285 and sr
, cw
= Unix.pipe
() in
6292 setcheckers conf.checkers
;
6296 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6297 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6302 state.text <- "Opening " ^
state.path;
6303 setaalevel
conf.aalevel
;
6304 writeopen state.path state.password
;
6306 setfontsize fstate.fontsize
;
6307 doreshape conf.winw conf.winh
;
6309 let rec loop deadline
=
6311 match state.errfd
with
6312 | None
-> [state.sr
; state.wsfd
]
6313 | Some fd
-> [state.sr
; state.wsfd
; fd
]
6317 state.redisplay
<- false;
6324 if deadline
= infinity
6326 else max
0.0 (deadline
-. now)
6331 try Unix.select
r [] [] timeout
6332 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6338 if state.ghyll
== noghyll
6340 match state.autoscroll
with
6341 | Some step
when step
!= 0 ->
6342 let y = state.y + step
in
6346 else if y >= state.maxy then 0 else y
6349 if state.mode = View
6350 then state.text <- "";
6353 else deadline
+. 0.01
6358 let rec checkfds = function
6360 | fd
:: rest
when fd
= state.sr
->
6361 let cmd = readcmd state.sr
in
6365 | fd
:: rest
when fd
= state.wsfd
->
6370 let s = String.create
80 in
6371 let n = Unix.read fd
s 0 80 in
6372 if conf.redirectstderr
6374 Buffer.add_substring
state.errmsgs
s 0 n;
6375 state.newerrmsgs
<- true;
6376 state.redisplay
<- true;
6379 prerr_string
(String.sub
s 0 n);
6387 if deadline
= infinity
6391 match state.autoscroll
with
6392 | Some step
when step
!= 0 -> deadline1
6393 | _ -> if state.ghyll
== noghyll then infinity
else deadline1