4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
9 | Uremote
of (string * int)
10 and facename
= string;;
12 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
13 let now = Unix.gettimeofday
;;
15 type params
= (angle
* proportional
* trimparams
16 * texcount
* sliceheight
* memsize
17 * colorspace
* fontpath
)
26 and proportional
= bool
27 and trimmargins
= bool
28 and interpagespace
= int
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
43 | Lfound
of (int * int * int * int * int)
47 | LDfirstvisible
of (int * int)
62 | KMmulti
of key list
* key list
64 and keyhash
= (key
, keymap
) Hashtbl.t
67 | KSinto
of (key list
* key list
)
70 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
71 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
73 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
75 external init
: pipe
-> params
-> unit = "ml_init";;
76 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
77 external copysel
: string -> opaque
-> unit = "ml_copysel";;
78 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
79 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
80 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
81 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
82 external measurestr
: int -> string -> float = "ml_measure_string";;
83 external getmaxw
: unit -> float = "ml_getmaxw";;
84 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
85 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
86 external platform
: unit -> platform
= "ml_platform";;
87 external setaalevel
: int -> unit = "ml_setaalevel";;
88 external realloctexts
: int -> bool = "ml_realloctexts";;
89 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
90 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
91 external getlink
: opaque
-> int -> under
= "ml_getlink";;
92 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
94 let platform_to_string = function
95 | Punknown
-> "unknown"
99 | Pfreebsd
-> "FreeBSD"
100 | Pdragonflybsd
-> "DragonflyBSD"
101 | Popenbsd
-> "OpenBSD"
102 | Pnetbsd
-> "NetBSD"
103 | Pcygwin
-> "Cygwin"
106 let platform = platform ();;
112 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
115 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
117 type mpos
= int * int
119 | Msel
of (mpos
* mpos
)
121 | Mscrolly
| Mscrollx
122 | Mzoom
of (int * int)
123 | Mzoomrect
of (mpos
* mpos
)
127 type textentry
= string * string * onhist
option * onkey
* ondone
128 and onkey
= string -> int -> te
129 and ondone
= string -> unit
130 and histcancel
= unit -> unit
131 and onhist
= ((histcmd
-> string) * histcancel
)
132 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
137 | TEswitch
of textentry
148 let bound v minv maxv
=
149 max minv
(min maxv v
);
153 { store
= Array.create n v
160 let drawstring size x y s
=
162 Gl.enable `texture_2d
;
163 ignore
(drawstr size x y s
);
165 Gl.disable `texture_2d
;
168 let drawstring1 size x y s
=
172 let drawstring2 size x y fmt
=
173 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
176 let cbcap b
= Array.length b
.store
;;
181 b
.wc
<- (b
.wc
+ 1) mod cap;
183 b
.len
<- min
(b
.len
+ 1) cap;
186 let cbempty b
= b
.len
= 0;;
188 let cbgetg b circular dir
=
192 let rc = b
.rc + dir
in
204 else max
0 (min
rc (b
.len
-1))
210 let cbget b
= cbgetg b
false;;
211 let cbgetc b
= cbgetg b
true;;
228 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
229 dolog " WxH %dx%d" l
.pagew l
.pageh
;
230 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
231 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
232 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
236 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
238 dolog " x0,y0=(% f, % f)" x0 y0
;
239 dolog " x1,y1=(% f, % f)" x1 y1
;
240 dolog " x2,y2=(% f, % f)" x2 y2
;
241 dolog " x3,y3=(% f, % f)" x3 y3
;
246 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
247 and multicol
= columncount
* covercount
* covercount
249 and columncount
= int
250 and covercount
= int;;
253 { mutable scrollbw
: int
254 ; mutable scrollh
: int
255 ; mutable icase
: bool
256 ; mutable preload
: bool
257 ; mutable pagebias
: int
258 ; mutable verbose
: bool
259 ; mutable debug
: bool
260 ; mutable scrollstep
: int
261 ; mutable maxhfit
: bool
262 ; mutable crophack
: bool
263 ; mutable autoscrollstep
: int
264 ; mutable maxwait
: float option
265 ; mutable hlinks
: bool
266 ; mutable underinfo
: bool
267 ; mutable interpagespace
: interpagespace
268 ; mutable zoom
: float
269 ; mutable presentation
: bool
270 ; mutable angle
: angle
273 ; mutable savebmarks
: bool
274 ; mutable proportional
: proportional
275 ; mutable trimmargins
: trimmargins
276 ; mutable trimfuzz
: irect
277 ; mutable memlimit
: memsize
278 ; mutable texcount
: texcount
279 ; mutable sliceheight
: sliceheight
280 ; mutable thumbw
: width
281 ; mutable jumpback
: bool
282 ; mutable bgcolor
: float * float * float
283 ; mutable bedefault
: bool
284 ; mutable scrollbarinpm
: bool
285 ; mutable tilew
: int
286 ; mutable tileh
: int
287 ; mutable mustoresize
: memsize
288 ; mutable checkers
: bool
289 ; mutable aalevel
: int
290 ; mutable urilauncher
: string
291 ; mutable pathlauncher
: string
292 ; mutable colorspace
: colorspace
293 ; mutable invert
: bool
294 ; mutable colorscale
: float
295 ; mutable redirectstderr
: bool
296 ; mutable ghyllscroll
: (int * int * int) option
297 ; mutable columns
: columns
option
298 ; mutable beyecolumns
: columncount
option
299 ; mutable selcmd
: string
300 ; mutable updatecurs
: bool
301 ; mutable keyhashes
: (string * keyhash
) list
305 type anchor
= pageno
* top
;;
307 type outline
= string * int * anchor
;;
309 type rect
= float * float * float * float * float * float * float * float;;
311 type tile
= opaque
* pixmapsize
* elapsed
312 and elapsed
= float;;
313 type pagemapkey
= pageno
* gen
;;
314 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
318 let emptyanchor = (0, 0.0);;
320 type infochange
= | Memused
| Docinfo
| Pdim
;;
322 class type uioh
= object
323 method display
: unit
324 method key
: int -> int -> uioh
325 method button
: int -> bool -> int -> int -> int -> uioh
326 method motion
: int -> int -> uioh
327 method pmotion
: int -> int -> uioh
328 method infochanged
: infochange
-> unit
329 method scrollpw
: (int * float * float)
330 method scrollph
: (int * float * float)
331 method modehash
: keyhash
335 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
336 | Textentry
of (textentry
* onleave
)
338 | LinkNav
of ((page
* opaque
* int) * (int * int * int * int)) option
339 and onleave
= leavetextentrystatus
-> unit
340 and leavetextentrystatus
= | Cancel
| Confirm
341 and helpitem
= string * int * action
344 | Action
of (uioh
-> uioh
)
347 let isbirdseye = function Birdseye _
-> true | _
-> false;;
348 let istextentry = function Textentry _
-> true | _
-> false;;
352 | Loading
of (page
* gen
)
354 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
356 | Outlining
of outline list
359 let emptykeyhash = Hashtbl.create
0;;
360 let nouioh : uioh
= object (self
)
362 method key _ _
= self
363 method button _ _ _ _ _
= self
364 method motion _ _
= self
365 method pmotion _ _
= self
366 method infochanged _
= ()
367 method scrollpw
= (0, nan
, nan
)
368 method scrollph
= (0, nan
, nan
)
369 method modehash
= emptykeyhash
373 { mutable sr
: Unix.file_descr
374 ; mutable sw
: Unix.file_descr
375 ; mutable wsfd
: Unix.file_descr
376 ; mutable errfd
: Unix.file_descr
option
377 ; mutable stderr
: Unix.file_descr
378 ; mutable errmsgs
: Buffer.t
379 ; mutable newerrmsgs
: bool
383 ; mutable scrollw
: int
384 ; mutable hscrollh
: int
385 ; mutable anchor
: anchor
386 ; mutable ranchors
: (string * string * anchor
) list
388 ; mutable layout
: page list
389 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
390 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
391 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
392 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
393 ; mutable pagecount
: int
394 ; mutable currently
: currently
395 ; mutable mstate
: mstate
396 ; mutable searchpattern
: string
397 ; mutable rects
: (pageno
* recttype
* rect
) list
398 ; mutable rects1
: (pageno
* recttype
* rect
) list
399 ; mutable text
: string
400 ; mutable fullscreen
: (width
* height
) option
401 ; mutable mode
: mode
402 ; mutable uioh
: uioh
403 ; mutable outlines
: outline array
404 ; mutable bookmarks
: outline list
405 ; mutable path
: string
406 ; mutable password
: string
407 ; mutable invalidated
: int
408 ; mutable memused
: memsize
410 ; mutable throttle
: (page list
* int * float) option
411 ; mutable autoscroll
: int option
412 ; mutable ghyll
: (int option -> unit)
413 ; mutable help
: helpitem array
414 ; mutable docinfo
: (int * string) list
415 ; mutable texid
: GlTex.texture_id
option
417 ; mutable prevzoom
: float
418 ; mutable progress
: float
419 ; mutable redisplay
: bool
420 ; mutable mpos
: mpos
421 ; mutable keystate
: keystate
424 { pat
: string circbuf
425 ; pag
: string circbuf
426 ; nav
: anchor circbuf
427 ; sel
: string circbuf
448 ; presentation
= false
453 ; proportional
= true
454 ; trimmargins
= false
455 ; trimfuzz
= (0,0,0,0)
456 ; memlimit
= 32 lsl 20
461 ; bgcolor
= (0.5, 0.5, 0.5)
463 ; scrollbarinpm
= true
466 ; mustoresize
= 128 lsl 20
471 | Plinux
| Pfreebsd
| Pdragonflybsd
472 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
473 | Posx
-> "open \"%s\""
474 | Pcygwin
-> "cygstart %s"
475 | Punknown
-> "echo %s")
476 ; pathlauncher
= "lp \"%s\""
479 | Plinux
| Pfreebsd
| Pdragonflybsd
480 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
487 ; redirectstderr
= false
493 let mk n
= (n
, Hashtbl.create
1) in
506 let findkeyhash c name
=
507 try List.assoc name c
.keyhashes
508 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
511 let conf = { defconf with angle
= defconf.angle
};;
514 { mutable fontsize
: int
515 ; mutable wwidth
: float
516 ; mutable maxrows
: int
528 fstate.fontsize
<- n
;
529 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
530 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
534 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
535 let len = String.length s
in
536 if colonpos >= 0 && colonpos + 3 < len
538 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
541 try String.rindex_from s
colonpos ' '
545 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
548 | "http" | "ftp" | "mailto" ->
550 try String.index_from s
colonpos ' '
551 with Not_found
-> len
553 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
561 let shell, farg
= "/bin/sh", "-c" in
563 let args = [|shell; farg
; s
|] in
564 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
568 if String.length
conf.urilauncher
= 0
569 then print_endline uri
571 let url = geturl uri
in
572 if String.length
url = 0
573 then print_endline uri
575 let re = Str.regexp
"%s" in
576 let command = Str.global_replace
re url conf.urilauncher
in
580 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
586 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
587 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
591 let strings = version () :: "" :: Help.keys
in
594 let url = geturl s
in
595 if String.length
url > 0
596 then (s
, 0, Action
(fun u
-> gotouri url; u
))
597 else (s
, 0, Noaction
)
608 ; stderr
= Unix.stderr
609 ; errmsgs
= Buffer.create
0
616 ; anchor
= emptyanchor
620 ; tilelru
= Queue.create
()
621 ; pagemap
= Hashtbl.create
10
622 ; tilemap
= Hashtbl.create
10
639 { nav
= cbnew 10 (0, 0.0)
664 Printf.kprintf prerr_endline fmt
666 Printf.kprintf ignore fmt
670 if String.length
conf.pathlauncher
= 0
671 then print_endline
state.path
673 let re = Str.regexp
"%s" in
674 let command = Str.global_replace
re state.path
conf.pathlauncher
in
678 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
683 let redirectstderr () =
684 if conf.redirectstderr
686 let rfd, wfd
= Unix.pipe
() in
687 state.stderr
<- Unix.dup
Unix.stderr
;
688 state.errfd
<- Some
rfd;
689 Unix.dup2 wfd
Unix.stderr
;
691 state.newerrmsgs
<- false;
692 begin match state.errfd
with
695 Unix.dup2
state.stderr
Unix.stderr
;
699 prerr_string
(Buffer.contents
state.errmsgs
);
701 Buffer.clear
state.errmsgs
;
707 let postRedisplay who
=
709 then prerr_endline
("redisplay for " ^ who
);
710 state.redisplay
<- true;
714 let getopaque pageno
=
715 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
716 with Not_found
-> None
719 let putopaque pageno opaque
=
720 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
723 let pagetranslatepoint l x y
=
724 let dy = y
- l
.pagedispy
in
725 let y = dy + l
.pagey
in
726 let dx = x
- l
.pagedispx
in
727 let x = dx + l
.pagex
in
734 begin match getopaque l
.pageno
with
736 let x0 = l
.pagedispx
in
737 let x1 = x0 + l
.pagevw
in
738 let y0 = l
.pagedispy
in
739 let y1 = y0 + l
.pagevh
in
740 if y >= y0 && y <= y1 && x >= x0 && x <= x1
742 let px, py
= pagetranslatepoint l
x y in
743 match whatsunder opaque
px py
with
756 state.text
<- Printf.sprintf
"%c%s" c s
;
757 G.postRedisplay "showtext";
760 let updateunder x y =
761 match getunder x y with
762 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
764 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
765 Wsi.setcursor
Wsi.CURSOR_INFO
766 | Ulinkgoto
(page
, _
) ->
768 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
769 Wsi.setcursor
Wsi.CURSOR_INFO
771 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
772 Wsi.setcursor
Wsi.CURSOR_TEXT
774 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
775 Wsi.setcursor
Wsi.CURSOR_INHERIT
777 if conf.underinfo
then showtext 'l'
("launch: " ^ s
);
778 Wsi.setcursor
Wsi.CURSOR_INHERIT
780 if conf.underinfo
then showtext 'n'
("named: " ^ s
);
781 Wsi.setcursor
Wsi.CURSOR_INHERIT
782 | Uremote
(filename
, pageno
) ->
783 if conf.underinfo
then showtext 'r'
784 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
785 Wsi.setcursor
Wsi.CURSOR_INFO
789 let b = Buffer.create
(String.length s
+ 1) in
790 Buffer.add_string
b s
;
795 let colorspace_of_string s
=
796 match String.lowercase s
with
800 | _
-> failwith
"invalid colorspace"
803 let int_of_colorspace = function
809 let colorspace_of_int = function
813 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
816 let colorspace_to_string = function
822 let intentry_with_suffix text key
=
824 if key
>= 32 && key
< 127
828 match Char.lowercase
c with
830 let text = addchar text c in
834 let text = addchar text c in
838 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
842 let columns_to_string (n
, a
, b) =
844 then Printf.sprintf
"%d" n
845 else Printf.sprintf
"%d,%d,%d" n a
b;
848 let columns_of_string s
=
850 (int_of_string s
, 0, 0)
852 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
857 let n = Unix.read fd
s 0 4 in
858 if n != 4 then failwith
"incomplete read(len)";
860 lor (Char.code
s.[0] lsl 24)
861 lor (Char.code
s.[1] lsl 16)
862 lor (Char.code
s.[2] lsl 8)
863 lor (Char.code
s.[3] lsl 0)
865 let s = String.create
len in
866 let n = Unix.read fd
s 0 len in
867 if n != len then failwith
"incomplete read(data)";
871 let btod b = if b then 1 else 0;;
874 let b = Buffer.create
16 in
875 Buffer.add_string
b "llll";
878 let s = Buffer.contents
b in
879 let n = String.length
s in
881 s.[0] <- Char.chr
((len lsr 24) land 0xff);
882 s.[1] <- Char.chr
((len lsr 16) land 0xff);
883 s.[2] <- Char.chr
((len lsr 8) land 0xff);
884 s.[3] <- Char.chr
(len land 0xff);
885 let n'
= Unix.write
state.sw
s 0 n in
886 if n'
!= n then failwith
"write failed";
893 let d = conf.winh
- h
in
900 let rec f pn ph pi fh l
=
902 | (n, _
, h
, _
) :: rest
->
903 let ips = calcips h
in
908 if isbirdseye state.mode
&& pn
= 0
913 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
918 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
922 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
925 let fh = f 0 0 0 0 state.pdims
in
930 match conf.columns
with
931 | None
-> calcheight ()
933 if Array.length
b > 0
935 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
940 let getpageyh pageno
=
941 let rec f pn ph pi
y l
=
943 | (n, _
, h
, _
) :: rest
->
944 let ips = calcips h
in
947 let h = if n = pageno
then h else ph
in
948 if conf.presentation
&& n = pageno
950 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
952 y + (pageno
- pn
) * (ph
+ pi
), h
954 let y = y + (if conf.presentation
then pi
else 0) in
955 let y = y + (n - pn
) * (ph
+ pi
) in
959 y + (pageno
- pn
) * (ph
+ pi
), ph
961 f 0 0 0 0 state.pdims
964 let getpageyh pageno
=
965 match conf.columns
with
966 | None
-> getpageyh pageno
968 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
972 let getpagedim pageno
=
975 | (n, _
, _
, _
) as pdim
:: rest
->
977 then (if n = pageno
then pdim
else ppdim
)
982 f (-1, -1, -1, -1) state.pdims
985 let getpagey pageno
= fst
(getpageyh pageno
);;
988 let sh = sh - state.hscrollh
in
989 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
990 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
992 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
993 let ips = calcips h in
995 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
999 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1001 prev
, pdims
, pdimno
, 0
1003 let dy = dy + yinc in
1004 let py = py + yinc in
1005 if pageno
= state.pagecount
|| dy >= sh
1010 if py + h <= vy - yinc
1012 let py = py + h + ips in
1013 let dy = max
0 (py - y) in
1014 f ~pageno
:(pageno
+1)
1022 let pagey = vy - py in
1023 let pagevh = h - pagey in
1024 let pagevh = min
(sh - dy) pagevh in
1025 let off = if yinc > 0 then py - vy else 0 in
1026 let py = py + h + ips in
1029 if state.w
< conf.winw
- state.scrollw
1030 then (conf.winw
- state.scrollw
- state.w
) / 2
1033 let dispx = xoff + state.x in
1039 let lw = w
- pagex in
1040 min
lw (conf.winw
- state.scrollw
)
1044 ; pagedimno
= pdimno
1048 ; pagey = pagey + off
1050 ; pagevh = pagevh - off
1052 ; pagedispy
= dy + off
1055 let accu = e :: accu in
1056 f ~pageno
:(pageno
+1)
1064 if state.invalidated
= 0
1082 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1083 let sh = sh - state.hscrollh
in
1084 let rec fold accu n =
1085 if n = Array.length
b
1088 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1091 || n = state.pagecount
- coverB
1092 || (n - coverA
) mod columns
= columns
- 1)
1098 let pagey = max
0 (y - vy) in
1099 let pagedispy = if pagey > 0 then 0 else vy - y in
1100 let pagedispx, pagex, pagevw =
1102 if n = coverA
- 1 || n = state.pagecount
- coverB
1103 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1104 else dx + xoff + state.x
1107 then 0, -pdx, w
+ pdx
1108 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1110 let pagevh = min
(h - pagey) (sh - pagedispy) in
1111 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1115 ; pagedimno
= pdimno
1122 ; pagedispx = pagedispx
1123 ; pagedispy = pagedispy
1134 if state.invalidated
= 0
1135 then List.rev
(fold [] 0)
1140 match conf.columns
with
1141 | None
-> layout1 y sh
1142 | Some
c -> layoutN c y sh
1146 let y = state.y + incr
in
1148 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1153 let tilex = l
.pagex mod conf.tilew
in
1154 let tiley = l
.pagey mod conf.tileh
in
1156 let col = l
.pagex / conf.tilew
in
1157 let row = l
.pagey / conf.tileh
in
1160 let a = l
.pagew
- l
.pagex in
1161 let b = conf.winw
- state.scrollw
in
1163 and vh
= l
.pagevh in
1165 let rec rowloop row y0 dispy
h =
1169 let dh = conf.tileh
- y0 in
1170 let dh = min
h dh in
1171 let rec colloop col x0 dispx w
=
1175 let dw = conf.tilew
- x0 in
1176 let dw = min w
dw in
1178 f col row dispx dispy
x0 y0 dw dh;
1179 colloop (col+1) 0 (dispx+dw) (w
-dw)
1182 colloop col tilex l
.pagedispx vw;
1183 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1187 then rowloop row tiley l
.pagedispy vh
;
1190 let gettileopaque l
col row =
1192 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1194 try Some
(Hashtbl.find
state.tilemap
key)
1195 with Not_found
-> None
1198 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1199 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1200 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1203 let drawtiles l color
=
1205 let f col row x y tilex tiley w
h =
1206 match gettileopaque l
col row with
1207 | Some
(opaque
, _
, t
) ->
1208 let params = x, y, w
, h, tilex, tiley in
1212 GlFunc.blend_func `zero `one_minus_src_color
;
1214 drawtile
params opaque
;
1216 then Gl.disable `blend
;
1219 let s = Printf.sprintf
1223 let w = measurestr
fstate.fontsize
s in
1224 GlMisc.push_attrib
[`current
];
1225 GlDraw.color
(0.0, 0.0, 0.0);
1227 (float (x-2), float (y-2))
1228 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1229 GlDraw.color
(1.0, 1.0, 1.0);
1230 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1231 GlMisc.pop_attrib
();
1236 let lw = conf.winw
- state.scrollw
- x in
1239 let lh = conf.winh
- y in
1242 Gl.enable `texture_2d
;
1243 begin match state.texid
with
1245 GlTex.bind_texture `texture_2d id
;
1248 and x1 = float (x+w)
1249 and y1 = float (y+h) in
1251 let tw = float w /. 64.0
1252 and th
= float h /. 64.0 in
1253 let tx0 = float tilex /. 64.0
1254 and ty0
= float tiley /. 64.0 in
1256 and ty1
= ty0
+. th
in
1257 GlDraw.begins `quads
;
1258 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1259 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1260 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1261 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1264 Gl.disable `texture_2d
;
1266 GlDraw.color
(1.0, 1.0, 1.0);
1269 (float (x+w), float (y+h));
1271 if w > 128 && h > fstate.fontsize
+ 10
1273 GlDraw.color
(0.0, 0.0, 0.0);
1276 then (col*conf.tilew
, row*conf.tileh
)
1279 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1286 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1288 let tilevisible1 l
x y =
1290 and ax1
= l
.pagex + l
.pagevw
1292 and ay1
= l
.pagey + l
.pagevh in
1296 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1297 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1299 let rx0 = max
ax0 bx0
1300 and ry0
= max ay0 by0
1301 and rx1
= min ax1
bx1
1302 and ry1
= min ay1 by1
in
1304 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1305 nonemptyintersection
1308 let tilevisible layout n x y =
1309 let rec findpageinlayout = function
1310 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1311 | _
:: rest
-> findpageinlayout rest
1314 findpageinlayout layout
1317 let tileready l
x y =
1318 tilevisible1 l
x y &&
1319 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1322 let tilepage n p
layout =
1323 let rec loop = function
1327 let f col row _ _ _ _ _ _
=
1328 if state.currently
= Idle
1330 match gettileopaque l
col row with
1333 let x = col*conf.tilew
1334 and y = row*conf.tileh
in
1336 let w = l
.pagew
- x in
1340 let h = l
.pageh
- y in
1343 wcmd "tile %s %d %d %d %d" p
x y w h;
1346 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1347 conf.tilew
, conf.tileh
1356 if state.invalidated
= 0 then loop layout;
1359 let preloadlayout visiblepages
=
1360 let presentation = conf.presentation in
1361 let interpagespace = conf.interpagespace in
1362 let maxy = state.maxy in
1363 conf.presentation <- false;
1364 conf.interpagespace <- 0;
1365 state.maxy <- calcheight ();
1367 match visiblepages
with
1369 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1371 let y = if y < conf.winh
then 0 else y - conf.winh
in
1372 let h = state.y - y + conf.winh
*3 in
1373 let pages = layout y h in
1374 conf.presentation <- presentation;
1375 conf.interpagespace <- interpagespace;
1381 let rec loop pages =
1382 if state.currently
!= Idle
1387 begin match getopaque l
.pageno
with
1389 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1390 state.currently
<- Loading
(l
, state.gen
);
1392 tilepage l
.pageno opaque
pages;
1397 if state.invalidated
= 0 then loop pages
1402 if conf.preload && state.currently
= Idle
1403 then load (preloadlayout pages);
1406 let layoutready layout =
1407 let rec fold all ls
=
1408 all
&& match ls
with
1410 let seen = ref false in
1411 let allvisible = ref true in
1412 let foo col row _ _ _ _ _ _
=
1414 allvisible := !allvisible &&
1415 begin match gettileopaque l
col row with
1421 fold (!seen && !allvisible) rest
1424 let alltilesvisible = fold true layout in
1429 let y = bound y 0 state.maxy in
1430 let y, layout, proceed
=
1431 match conf.maxwait
with
1432 | Some time
when state.ghyll
== noghyll ->
1433 begin match state.throttle
with
1435 let layout = layout y conf.winh
in
1436 let ready = layoutready layout in
1440 state.throttle
<- Some
(layout, y, now ());
1442 else G.postRedisplay "gotoy showall (None)";
1444 | Some
(_
, _
, started
) ->
1445 let dt = now () -. started
in
1448 state.throttle
<- None
;
1449 let layout = layout y conf.winh
in
1451 G.postRedisplay "maxwait";
1458 let layout = layout y conf.winh
in
1459 if true || layoutready layout
1460 then G.postRedisplay "gotoy ready";
1466 state.layout <- layout;
1467 begin match state.mode
with
1468 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1469 if not
(pagevisible layout pageno
)
1471 match state.layout with
1474 state.mode
<- Birdseye
(
1475 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1480 let rec loop = function
1483 match getopaque l
.pageno
with
1487 findlink opaque
(LDfirstvisible
(l
.pagex, l
.pagey))
1490 | Lnone
-> loop rest
1491 | Lfound
(n, x0, y0, x1, y1) ->
1492 Some
((l
, opaque
, n), (x0, y0, x1, y1))
1496 state.mode
<- LinkNav
linknav
1501 state.ghyll
<- noghyll;
1504 let conttiling pageno opaque
=
1505 tilepage pageno opaque
1506 (if conf.preload then preloadlayout state.layout else state.layout)
1509 let gotoy_and_clear_text y =
1511 if not
conf.verbose
then state.text <- "";
1515 match state.layout with
1517 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1520 let getanchory (n, top
) =
1521 let y, h = getpageyh n in
1522 y + (truncate
(top
*. float h));
1525 let gotoanchor anchor
=
1526 gotoy (getanchory anchor
);
1530 cbput state.hists
.nav
(getanchor ());
1534 let anchor = cbgetc state.hists
.nav dir
in
1539 let rec scroll f n a b =
1540 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1542 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1544 then s (float f /. float a)
1547 then 1.0 -. s ((float (f-b) /. float (n-b)))
1554 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1555 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1557 let ins = float a *. iv1
1558 and outs
= float (n-b) *. iv1 in
1560 ins +. outs
+. float ones
1562 let rec set (_N
, _A
, _B
) y sy
=
1563 let sum = summa
1.0 _N _A _B
in
1564 let dy = float (y - sy
) in
1568 then state.ghyll
<- noghyll
1571 let s = scroll n _N _A _B
in
1572 let y1 = y1 +. ((s *. dy) /. sum) in
1573 gotoy_and_clear_text (truncate
y1);
1574 state.ghyll
<- gf (n+1) y1;
1578 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1580 gf 0 (float state.y)
1583 match conf.ghyllscroll
with
1585 gotoy_and_clear_text y
1587 if state.ghyll
== noghyll
1588 then set nab
y state.y
1589 else state.ghyll
(Some
y)
1592 let gotopage n top
=
1593 let y, h = getpageyh n in
1594 let y = y + (truncate
(top
*. float h)) in
1598 let gotopage1 n top
=
1599 let y = getpagey n in
1609 state.invalidated
<- state.invalidated
+ 1;
1612 let writeopen path password
=
1613 wcmd "open %s\000%s\000" path password
;
1616 let opendoc path password
=
1619 state.password
<- password
;
1620 state.gen
<- state.gen
+ 1;
1621 state.docinfo
<- [];
1623 setaalevel
conf.aalevel
;
1624 writeopen path password
;
1625 Wsi.settitle
("llpp " ^
Filename.basename path
);
1626 wcmd "geometry %d %d" state.w conf.winh
;
1630 let c = c *. conf.colorscale
in
1634 let scalecolor2 (r
, g
, b) =
1635 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1639 let docolumns = function
1641 | Some
((columns
, coverA
, coverB
), _
) ->
1642 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1643 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1644 if pageno
= state.pagecount
1647 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1649 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1650 pdimno+1, pdim
, rest
1655 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1657 (conf.winw
- state.scrollw
- w) / 2,
1658 y + rowh
+ conf.interpagespace, h
1661 if (pageno
- coverA
) mod columns
= 0
1662 then 0, y + rowh
+ conf.interpagespace, h
1663 else x, y, max rowh
h
1666 let rec fixrow m
= if m
= pageno
then () else
1667 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1670 let y = y + (rowh
- h) / 2 in
1671 a.(m
) <- (pdimno, x, y, pdim
);
1675 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1676 then fixrow (pageno
- columns
);
1677 a.(pageno
) <- (pdimno, x, y, pdim
);
1678 let x = x + w + xoff*2 + conf.interpagespace in
1679 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1681 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1682 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1684 docolumns conf.columns
;
1685 state.maxy <- calcheight ();
1687 if state.w <= conf.winw
- state.scrollw
1691 match state.mode
with
1692 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1693 let y, h = getpageyh pageno
in
1694 let top = (conf.winh
- h) / 2 in
1695 gotoy (max
0 (y - top))
1696 | _
-> gotoanchor state.anchor
1700 let firsttime = ref true in
1702 GlDraw.viewport
0 0 w h;
1703 if state.invalidated
= 0 && not
!firsttime
1704 then state.anchor <- getanchor ();
1708 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1712 setfontsize fstate.fontsize
;
1713 GlMat.mode `modelview
;
1714 GlMat.load_identity
();
1716 GlMat.mode `projection
;
1717 GlMat.load_identity
();
1718 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1719 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1720 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1723 match conf.columns
with
1725 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1728 wcmd "geometry %d %d" w h;
1732 let len = String.length
state.text in
1735 match state.mode
with
1736 | View
-> state.hscrollh
1741 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1742 (x+.w, float (conf.winh
- hscrollh))
1745 let w = float (conf.winw
- state.scrollw
- 1) in
1746 if state.progress
>= 0.0 && state.progress
< 1.0
1748 GlDraw.color
(0.3, 0.3, 0.3);
1749 let w1 = w *. state.progress
in
1751 GlDraw.color
(0.0, 0.0, 0.0);
1755 GlDraw.color
(0.0, 0.0, 0.0);
1759 GlDraw.color
(1.0, 1.0, 1.0);
1760 drawstring fstate.fontsize
1761 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1764 match state.mode
with
1765 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1769 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1771 Printf.sprintf
"%s%s_" prefix
text
1780 if not
(istextentry state.mode
)
1782 let s1 = "(press 'e' to review error messasges)" in
1783 if String.length
s > 0 then s ^
" " ^
s1 else s1
1788 if String.length
s > 0
1793 let len = Queue.length
state.tilelru
in
1795 if state.memused
<= conf.memlimit
1800 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1801 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1802 let (_
, pw
, ph
, _
) = getpagedim n in
1805 && colorspace
= conf.colorspace
1806 && angle
= conf.angle
1811 match state.throttle
with
1814 then preloadlayout state.layout
1816 | Some
(layout, _
, _
) ->
1819 let x = col*conf.tilew
1820 and y = row*conf.tileh
in
1821 tilevisible layout n x y
1823 then Queue.push lruitem
state.tilelru
1825 wcmd "freetile %s" p
;
1826 state.memused
<- state.memused
- s;
1827 state.uioh#infochanged Memused
;
1828 Hashtbl.remove
state.tilemap k
;
1837 Queue.iter
(fun (k
, p
, s) ->
1838 wcmd "freetile %s" p
;
1839 state.memused
<- state.memused
- s;
1840 state.uioh#infochanged Memused
;
1841 Hashtbl.remove
state.tilemap k
;
1843 Queue.clear
state.tilelru
;
1847 let logcurrently = function
1848 | Idle
-> dolog "Idle"
1849 | Loading
(l
, gen
) ->
1850 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1851 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1853 "Tiling %d[%d,%d] page=%s cs=%s angle"
1854 l
.pageno
col row pageopaque
1855 (colorspace_to_string colorspace
)
1857 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1858 angle gen
conf.angle
state.gen
1860 conf.tilew
conf.tileh
1867 (* dolog "%S" cmds; *)
1870 try String.index cmds ' '
1871 with Not_found
-> -1
1876 let l = String.length cmds
in
1877 let op = String.sub cmds
0 spacepos in
1879 if l - spacepos < 2 then ""
1880 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1885 state.uioh#infochanged Pdim
;
1889 state.rects
<- state.rects1
;
1890 G.postRedisplay "clearrects";
1894 try Scanf.sscanf
args "%u" (fun n -> n)
1896 dolog "error processing 'continue' %S: %s"
1897 cmds
(Printexc.to_string exn
);
1900 state.pagecount
<- n;
1901 state.invalidated
<- state.invalidated
- 1;
1902 begin match state.currently
with
1904 state.currently
<- Idle
;
1905 state.outlines
<- Array.of_list
(List.rev
l)
1908 if state.invalidated
= 0
1910 if conf.maxwait
= None
1911 then G.postRedisplay "continue";
1921 then showtext ' '
args
1924 let progress, text =
1926 Scanf.sscanf
args "%f %n"
1928 f, String.sub
args pos
(String.length
args - pos
))
1930 dolog "error processing 'progress' %S: %s"
1931 cmds
(Printexc.to_string exn
);
1935 state.progress <- progress;
1936 G.postRedisplay "progress"
1939 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1941 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1942 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1943 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1945 dolog "error processing 'firstmatch' %S: %s"
1946 cmds
(Printexc.to_string exn
);
1949 let y = (getpagey pageno) + truncate
y0 in
1952 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1955 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1957 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1958 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1959 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1961 dolog "error processing 'match' %S: %s"
1962 cmds
(Printexc.to_string exn
);
1966 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1971 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1973 dolog "error processing 'page' %S: %s"
1974 cmds
(Printexc.to_string exn
);
1977 begin match state.currently
with
1978 | Loading
(l, gen
) ->
1979 vlog "page %d took %f sec" l.pageno t
;
1980 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1981 begin match state.throttle
with
1983 let preloadedpages =
1985 then preloadlayout state.layout
1990 Set.Make
(struct type t
= int let compare = (-) end) in
1992 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1993 IntSet.empty
preloadedpages
1996 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1997 if not
(IntSet.mem
pageno set)
1999 wcmd "freepage %s" opaque
;
2005 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2008 state.currently
<- Idle
;
2011 tilepage l.pageno pageopaque state.layout;
2013 load preloadedpages;
2014 if pagevisible state.layout l.pageno
2015 && layoutready state.layout
2016 then G.postRedisplay "page";
2019 | Some
(layout, _
, _
) ->
2020 state.currently
<- Idle
;
2021 tilepage l.pageno pageopaque layout;
2026 dolog "Inconsistent loading state";
2027 logcurrently state.currently
;
2032 let (x, y, opaque
, size
, t
) =
2034 Scanf.sscanf
args "%u %u %s %u %f"
2035 (fun x y p size t
-> (x, y, p
, size
, t
))
2037 dolog "error processing 'tile' %S: %s"
2038 cmds
(Printexc.to_string exn
);
2041 begin match state.currently
with
2042 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2043 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2045 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2047 wcmd "freetile %s" opaque
;
2048 state.currently
<- Idle
;
2052 puttileopaque l col row gen cs angle opaque size t
;
2053 state.memused
<- state.memused
+ size
;
2054 state.uioh#infochanged Memused
;
2056 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2057 opaque
, size
) state.tilelru
;
2060 match state.throttle
with
2061 | None
-> state.layout
2062 | Some
(layout, _
, _
) -> layout
2065 state.currently
<- Idle
;
2067 && conf.colorspace
= cs
2068 && conf.angle
= angle
2069 && tilevisible layout l.pageno x y
2070 then conttiling l.pageno pageopaque;
2072 begin match state.throttle
with
2074 preload state.layout;
2076 && conf.colorspace
= cs
2077 && conf.angle
= angle
2078 && tilevisible state.layout l.pageno x y
2079 then G.postRedisplay "tile nothrottle";
2081 | Some
(layout, y, _
) ->
2082 let ready = layoutready layout in
2086 state.layout <- layout;
2087 state.throttle
<- None
;
2088 G.postRedisplay "throttle";
2095 dolog "Inconsistent tiling state";
2096 logcurrently state.currently
;
2103 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2105 dolog "error processing 'pdim' %S: %s"
2106 cmds
(Printexc.to_string exn
);
2109 state.uioh#infochanged Pdim
;
2110 state.pdims
<- pdim :: state.pdims
2113 let (l, n, t
, h, pos
) =
2115 Scanf.sscanf
args "%u %u %d %u %n"
2116 (fun l n t
h pos
-> l, n, t
, h, pos
)
2118 dolog "error processing 'o' %S: %s"
2119 cmds
(Printexc.to_string exn
);
2122 let s = String.sub
args pos
(String.length
args - pos
) in
2123 let outline = (s, l, (n, float t
/. float h)) in
2124 begin match state.currently
with
2125 | Outlining outlines
->
2126 state.currently
<- Outlining
(outline :: outlines
)
2128 state.currently
<- Outlining
[outline]
2130 dolog "invalid outlining state";
2131 logcurrently currently
2135 state.docinfo
<- (1, args) :: state.docinfo
2138 state.uioh#infochanged Docinfo
;
2139 state.docinfo
<- List.rev
state.docinfo
2142 dolog "unknown cmd `%S'" cmds
2147 let action = function
2148 | HCprev
-> cbget cb ~
-1
2149 | HCnext
-> cbget cb
1
2150 | HCfirst
-> cbget cb ~
-(cb
.rc)
2151 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2152 and cancel
() = cb
.rc <- rc
2156 let search pattern forward
=
2157 if String.length pattern
> 0
2160 match state.layout with
2163 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2165 wcmd "search %d %d %d %d,%s\000"
2166 (btod conf.icase
) pn py (btod forward
) pattern
;
2169 let intentry text key =
2171 if key >= 32 && key < 127
2177 let text = addchar text c in
2181 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2185 let textentry text key =
2186 if key land 0xff00 = 0xff00
2188 else TEcont
(text ^
Wsi.toutf8
key)
2191 let reqlayout angle proportional
=
2192 match state.throttle
with
2194 if state.invalidated
= 0 then state.anchor <- getanchor ();
2195 conf.angle
<- angle
mod 360;
2196 conf.proportional
<- proportional
;
2198 wcmd "reqlayout %d %d" conf.angle
(btod proportional
);
2202 let settrim trimmargins trimfuzz
=
2203 if state.invalidated
= 0 then state.anchor <- getanchor ();
2204 conf.trimmargins
<- trimmargins
;
2205 conf.trimfuzz
<- trimfuzz
;
2206 let x0, y0, x1, y1 = trimfuzz
in
2208 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1;
2209 Hashtbl.iter
(fun _ opaque
->
2210 wcmd "freepage %s" opaque
;
2212 Hashtbl.clear
state.pagemap
;
2216 match state.throttle
with
2218 let zoom = max
0.01 zoom in
2219 if zoom <> conf.zoom
2221 state.prevzoom
<- conf.zoom;
2224 then (state.x <- 0; 0.0)
2225 else float state.x /. float state.w
2228 reshape conf.winw
conf.winh
;
2231 let x = relx *. float state.w in
2232 state.x <- truncate
x;
2234 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2237 | Some
(layout, y, started
) ->
2239 match conf.maxwait
with
2243 let dt = now () -. started
in
2251 let setcolumns columns coverA coverB
=
2254 conf.columns
<- None
;
2259 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2262 reshape conf.winw
conf.winh
;
2265 let enterbirdseye () =
2266 let zoom = float conf.thumbw
/. float conf.winw
in
2267 let birdseyepageno =
2268 let cy = conf.winh
/ 2 in
2272 let rec fold best
= function
2275 let d = cy - (l.pagedispy + l.pagevh/2)
2276 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2277 if abs
d < abs dbest
2284 state.mode
<- Birdseye
(
2285 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2288 conf.presentation <- false;
2289 conf.interpagespace <- 10;
2290 conf.hlinks
<- false;
2292 state.mstate
<- Mnone
;
2293 conf.maxwait
<- None
;
2295 match conf.beyecolumns
with
2298 Some
((c, 0, 0), [||])
2301 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2304 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2309 reshape conf.winw
conf.winh
;
2312 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2314 conf.zoom <- c.zoom;
2315 conf.presentation <- c.presentation;
2316 conf.interpagespace <- c.interpagespace;
2317 conf.maxwait
<- c.maxwait
;
2318 conf.hlinks
<- c.hlinks
;
2319 conf.beyecolumns
<- (
2320 match conf.columns
with
2321 | Some
((c, _
, _
), _
) -> Some
c
2325 match c.columns
with
2326 | Some
(c, _
) -> Some
(c, [||])
2332 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2335 reshape conf.winw
conf.winh
;
2336 state.anchor <- if goback
then anchor else (pageno, 0.0);
2339 let togglebirdseye () =
2340 match state.mode
with
2341 | Birdseye vals
-> leavebirdseye vals
true
2342 | View
-> enterbirdseye ()
2346 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2347 let pageno = max
0 (pageno - incr
) in
2348 let rec loop = function
2349 | [] -> gotopage1 pageno 0
2350 | l :: _
when l.pageno = pageno ->
2351 if l.pagedispy >= 0 && l.pagey = 0
2352 then G.postRedisplay "upbirdseye"
2353 else gotopage1 pageno 0
2354 | _
:: rest
-> loop rest
2357 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2360 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2361 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2362 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2363 let rec loop = function
2365 let y, h = getpageyh pageno in
2366 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2368 | l :: _
when l.pageno = pageno ->
2369 if l.pagevh != l.pageh
2370 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2371 else G.postRedisplay "downbirdseye"
2372 | _
:: rest
-> loop rest
2377 let optentry mode _
key =
2378 let btos b = if b then "on" else "off" in
2379 if key >= 32 && key < 127
2381 let c = Char.chr
key in
2385 try conf.scrollstep
<- int_of_string
s with exc
->
2386 state.text <- Printf.sprintf
"bad integer `%s': %s"
2387 s (Printexc.to_string exc
)
2389 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2394 conf.autoscrollstep
<- int_of_string
s;
2395 if state.autoscroll
<> None
2396 then state.autoscroll
<- Some
conf.autoscrollstep
2398 state.text <- Printf.sprintf
"bad integer `%s': %s"
2399 s (Printexc.to_string exc
)
2401 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2406 let n, a, b = columns_of_string s in
2409 state.text <- Printf.sprintf
"bad columns `%s': %s"
2410 s (Printexc.to_string exc
)
2412 TEswitch
("columns: ", "", None
, textentry, ondone)
2417 let zoom = float (int_of_string
s) /. 100.0 in
2420 state.text <- Printf.sprintf
"bad integer `%s': %s"
2421 s (Printexc.to_string exc
)
2423 TEswitch
("zoom: ", "", None
, intentry, ondone)
2428 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2430 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2431 begin match mode
with
2433 leavebirdseye beye
false;
2438 state.text <- Printf.sprintf
"bad integer `%s': %s"
2439 s (Printexc.to_string exc
)
2441 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2446 Some
(int_of_string
s)
2448 state.text <- Printf.sprintf
"bad integer `%s': %s"
2449 s (Printexc.to_string exc
);
2452 | Some angle
-> reqlayout angle
conf.proportional
2455 TEswitch
("rotation: ", "", None
, intentry, ondone)
2458 conf.icase
<- not
conf.icase
;
2459 TEdone
("case insensitive search " ^
(btos conf.icase
))
2462 conf.preload <- not
conf.preload;
2464 TEdone
("preload " ^
(btos conf.preload))
2467 conf.verbose
<- not
conf.verbose
;
2468 TEdone
("verbose " ^
(btos conf.verbose
))
2471 conf.debug
<- not
conf.debug
;
2472 TEdone
("debug " ^
(btos conf.debug
))
2475 conf.maxhfit
<- not
conf.maxhfit
;
2477 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2478 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2481 conf.crophack
<- not
conf.crophack
;
2482 TEdone
("crophack " ^
btos conf.crophack
)
2486 match conf.maxwait
with
2488 conf.maxwait
<- Some infinity
;
2489 "always wait for page to complete"
2491 conf.maxwait
<- None
;
2492 "show placeholder if page is not ready"
2497 conf.underinfo
<- not
conf.underinfo
;
2498 TEdone
("underinfo " ^
btos conf.underinfo
)
2501 conf.savebmarks
<- not
conf.savebmarks
;
2502 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2508 match state.layout with
2513 conf.interpagespace <- int_of_string
s;
2514 state.maxy <- calcheight ();
2515 let y = getpagey pageno in
2518 state.text <- Printf.sprintf
"bad integer `%s': %s"
2519 s (Printexc.to_string exc
)
2521 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2524 reqlayout conf.angle
(not
conf.proportional
);
2525 TEdone
("proportional display " ^
btos conf.proportional
)
2528 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2529 TEdone
("trim margins " ^
btos conf.trimmargins
)
2532 conf.invert
<- not
conf.invert
;
2533 TEdone
("invert colors " ^
btos conf.invert
)
2537 cbput state.hists
.sel
s;
2540 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2544 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2550 class type lvsource
= object
2551 method getitemcount
: int
2552 method getitem
: int -> (string * int)
2553 method hasaction
: int -> bool
2562 method getactive
: int
2563 method getfirst
: int
2564 method getqsearch
: string
2565 method setqsearch
: string -> unit
2569 class virtual lvsourcebase
= object
2570 val mutable m_active
= 0
2571 val mutable m_first
= 0
2572 val mutable m_qsearch
= ""
2573 val mutable m_pan
= 0
2574 method getactive
= m_active
2575 method getfirst
= m_first
2576 method getqsearch
= m_qsearch
2577 method getpan
= m_pan
2578 method setqsearch
s = m_qsearch
<- s
2581 let withoutlastutf8 s =
2582 let len = String.length
s in
2590 let b = Char.code
s.[pos
] in
2591 if b land 0b110000 = 0b11000000
2596 if Char.code
s.[len-1] land 0x80 = 0
2600 String.sub
s 0 first;
2603 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2605 state.mode
<- Textentry
(te
, onleave
);
2608 G.postRedisplay "textentrykeyboard enttext";
2610 let histaction cmd
=
2613 | Some
(action, _
) ->
2614 state.mode
<- Textentry
(
2615 (c, action cmd
, opthist
, onkey
, ondone), onleave
2617 G.postRedisplay "textentry histaction"
2620 | 0xff08 -> (* backspace *)
2621 let s = withoutlastutf8 text in
2622 let len = String.length
s in
2626 G.postRedisplay "textentrykeyboard after cancel";
2629 enttext (c, s, opthist
, onkey
, ondone)
2635 G.postRedisplay "textentrykeyboard after confirm"
2637 | 0xff52 -> histaction HCprev
2638 | 0xff54 -> histaction HCnext
2639 | 0xff50 -> histaction HCfirst
2640 | 0xff57 -> histaction HClast
2642 | 0xff1b -> (* escape*)
2643 if String.length
text = 0
2645 begin match opthist
with
2647 | Some
(_
, onhistcancel
) -> onhistcancel
()
2651 G.postRedisplay "textentrykeyboard after cancel2"
2654 enttext (c, "", opthist
, onkey
, ondone)
2657 | 0xff9f | 0xffff -> () (* delete *)
2659 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2660 begin match onkey
text key with
2664 G.postRedisplay "textentrykeyboard after confirm2";
2667 enttext (c, text, opthist
, onkey
, ondone);
2671 G.postRedisplay "textentrykeyboard after cancel3"
2674 state.mode
<- Textentry
(te
, onleave
);
2675 G.postRedisplay "textentrykeyboard switch";
2679 vlog "unhandled key %s" (Wsi.keyname
key)
2682 let firstof first active
=
2683 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2684 then max
0 (active
- (fstate.maxrows
/2))
2688 let calcfirst first active
=
2691 let rows = active
- first in
2692 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2696 let scrollph y maxy =
2697 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2698 let sh = float conf.winh
/. sh in
2699 let sh = max
sh (float conf.scrollh
) in
2704 else float y /. float maxy
2706 let position = (float conf.winh
-. sh) *. percent in
2709 if position +. sh > float conf.winh
2710 then float conf.winh
-. sh
2716 let coe s = (s :> uioh
);;
2718 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2720 val m_pan
= source#getpan
2721 val m_first
= source#getfirst
2722 val m_active
= source#getactive
2723 val m_qsearch
= source#getqsearch
2724 val m_prev_uioh
= state.uioh
2726 method private elemunder
y =
2727 let n = y / (fstate.fontsize
+1) in
2728 if m_first
+ n < source#getitemcount
2730 if source#hasaction
(m_first
+ n)
2731 then Some
(m_first
+ n)
2738 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2739 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2740 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2741 GlDraw.color
(1., 1., 1.);
2742 Gl.enable `texture_2d
;
2743 let fs = fstate.fontsize
in
2745 let ww = fstate.wwidth
in
2746 let tabw = 30.0*.ww in
2747 let itemcount = source#getitemcount
in
2749 if (row - m_first
) * nfs > conf.winh
2752 if row >= 0 && row < itemcount
2754 let (s, level
) = source#getitem
row in
2755 let y = (row - m_first
) * nfs in
2756 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2759 Gl.disable `texture_2d
;
2760 GlDraw.polygon_mode `both `line
;
2761 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2762 GlDraw.rect (1., float (y + 1))
2763 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2764 GlDraw.polygon_mode `both `fill
;
2765 GlDraw.color
(1., 1., 1.);
2766 Gl.enable `texture_2d
;
2769 let drawtabularstring s =
2770 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2773 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2776 let len = String.length
s - tabpos - 1 in
2777 let s1 = String.sub
s 0 tabpos
2778 and s2
= String.sub
s (tabpos + 1) len in
2779 let nx = drawstr x s1 in
2781 let x = x +. (max
tabw sw) in
2788 let _ = drawtabularstring s in
2795 Gl.disable `texture_2d
;
2797 method updownlevel incr
=
2798 let len = source#getitemcount
in
2800 if m_active
>= 0 && m_active
< len
2801 then snd
(source#getitem m_active
)
2805 if i
= len then i
-1 else if i
= -1 then 0 else
2806 let _, l = source#getitem i
in
2807 if l != curlevel then i
else flow (i
+incr
)
2809 let active = flow m_active
in
2810 let first = calcfirst m_first
active in
2811 G.postRedisplay "outline updownlevel";
2812 {< m_active
= active; m_first
= first >}
2814 method private key1
key mask
=
2815 let set1 active first qsearch
=
2816 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2818 let search active pattern incr
=
2821 if n >= 0 && n < source#getitemcount
2823 let s, _ = source#getitem
n in
2825 (try ignore
(Str.search_forward
re s 0); true
2826 with Not_found
-> false)
2828 else loop (n + incr
)
2835 let re = Str.regexp_case_fold pattern
in
2841 let itemcount = source#getitemcount
in
2842 let find start incr
=
2844 if i
= -1 || i
= itemcount
2847 if source#hasaction i
2849 else find (i
+ incr
)
2854 let set active first =
2855 let first = bound first 0 (itemcount - fstate.maxrows
) in
2857 coe {< m_active
= active; m_first
= first >}
2860 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2862 let incr1 = if incr
> 0 then 1 else -1 in
2863 if isvisible m_first m_active
2866 let next = m_active
+ incr
in
2868 if next < 0 || next >= itemcount
2870 else find next incr1
2872 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2878 let first = m_first
+ incr
in
2879 let first = bound first 0 (itemcount - 1) in
2881 let next = m_active
+ incr
in
2882 let next = bound next 0 (itemcount - 1) in
2885 let active = if next = -1 then m_active
else next in
2888 let first = min
next m_first
in
2890 if abs
(next - first) > fstate.maxrows
2896 let first = m_first
+ incr
in
2897 let first = bound first 0 (itemcount - 1) in
2899 let next = m_active
+ incr
in
2900 let next = bound next 0 (itemcount - 1) in
2901 let next = find next incr1 in
2903 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2905 let active = if m_active
= -1 then next else m_active
in
2910 if isvisible first active
2916 G.postRedisplay "listview navigate";
2920 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2921 let incr = if key = 0x72 then -1 else 1 in
2923 match search (m_active
+ incr) m_qsearch
incr with
2925 state.text <- m_qsearch ^
" [not found]";
2928 state.text <- m_qsearch
;
2929 active, firstof m_first
active
2931 G.postRedisplay "listview ctrl-r/s";
2932 set1 active first m_qsearch
;
2934 | 0xff08 -> (* backspace *)
2935 if String.length m_qsearch
= 0
2938 let qsearch = withoutlastutf8 m_qsearch
in
2939 let len = String.length
qsearch in
2943 G.postRedisplay "listview empty qsearch";
2944 set1 m_active m_first
"";
2948 match search m_active
qsearch ~
-1 with
2950 state.text <- qsearch ^
" [not found]";
2953 state.text <- qsearch;
2954 active, firstof m_first
active
2956 G.postRedisplay "listview backspace qsearch";
2957 set1 active first qsearch
2960 | key when ((key >= 32 && key < 127)
2961 || (key != 0 && key land 0xff00 != 0xff00)) ->
2963 if key >= 32 && key < 127
2964 then addchar m_qsearch
(Char.chr
key)
2965 else m_qsearch ^
Wsi.toutf8
key
2968 match search m_active
pattern 1 with
2970 state.text <- pattern ^
" [not found]";
2973 state.text <- pattern;
2974 active, firstof m_first
active
2976 G.postRedisplay "listview qsearch add";
2977 set1 active first pattern;
2979 | 0xff1b -> (* escape *)
2981 if String.length m_qsearch
= 0
2983 G.postRedisplay "list view escape";
2986 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2988 | None
-> m_prev_uioh
2993 G.postRedisplay "list view kill qsearch";
2994 source#setqsearch
"";
2995 coe {< m_qsearch
= "" >}
2998 | 0xff0d -> (* return *)
3000 let self = {< m_qsearch
= "" >} in
3001 source#setqsearch
"";
3003 G.postRedisplay "listview enter";
3004 if m_active
>= 0 && m_active
< source#getitemcount
3006 source#exit
(coe self) false m_active m_first m_pan
"";
3009 source#exit
(coe self) true m_active m_first m_pan
"";
3012 begin match opt with
3013 | None
-> m_prev_uioh
3017 | 0xff9f | 0xffff -> (* delete *)
3020 | 0xff52 -> navigate ~
-1 (* up *)
3021 | 0xff54 -> navigate 1 (* down *)
3022 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3023 | 0xff56 -> navigate fstate.maxrows
(* next *)
3025 | 0xff53 -> (* right *)
3027 G.postRedisplay "listview right";
3028 coe {< m_pan
= m_pan
- 1 >}
3030 | 0xff51 -> (* left *)
3032 G.postRedisplay "listview left";
3033 coe {< m_pan
= m_pan
+ 1 >}
3035 | 0xff50 -> (* home *)
3036 let active = find 0 1 in
3037 G.postRedisplay "listview home";
3040 | 0xff57 -> (* end *)
3041 let first = max
0 (itemcount - fstate.maxrows
) in
3042 let active = find (itemcount - 1) ~
-1 in
3043 G.postRedisplay "listview end";
3046 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3050 dolog "listview unknown key %#x" key; coe self
3052 method key key mask
=
3053 match state.mode
with
3054 | Textentry te
-> textentrykeyboard key mask te
; coe self
3055 | _ -> self#key1
key mask
3057 method button button down
x y _ =
3060 | 1 when x > conf.winw
- conf.scrollbw
->
3061 G.postRedisplay "listview scroll";
3064 let _, position, sh = self#
scrollph in
3065 if y > truncate
position && y < truncate
(position +. sh)
3067 state.mstate
<- Mscrolly
;
3071 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3072 let first = truncate
(s *. float source#getitemcount
) in
3073 let first = min source#getitemcount
first in
3074 Some
(coe {< m_first
= first; m_active
= first >})
3076 state.mstate
<- Mnone
;
3079 | 1 when not down
->
3080 begin match self#elemunder
y with
3082 G.postRedisplay "listview click";
3084 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3088 | n when (n == 4 || n == 5) && not down
->
3089 let len = source#getitemcount
in
3091 if n = 5 && m_first
+ fstate.maxrows
>= len
3095 let first = m_first
+ (if n == 4 then -1 else 1) in
3096 bound first 0 (len - 1)
3098 G.postRedisplay "listview wheel";
3099 Some
(coe {< m_first
= first >})
3104 | None
-> m_prev_uioh
3108 match state.mstate
with
3110 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3111 let first = truncate
(s *. float source#getitemcount
) in
3112 let first = min source#getitemcount
first in
3113 G.postRedisplay "listview motion";
3114 coe {< m_first
= first; m_active
= first >}
3117 method pmotion
x y =
3118 if x < conf.winw
- conf.scrollbw
3121 match self#elemunder
y with
3122 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3123 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3127 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3132 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3136 method infochanged
_ = ()
3138 method scrollpw
= (0, 0.0, 0.0)
3140 let nfs = fstate.fontsize
+ 1 in
3141 let y = m_first
* nfs in
3142 let itemcount = source#getitemcount
in
3143 let maxi = max
0 (itemcount - fstate.maxrows
) in
3144 let maxy = maxi * nfs in
3145 let p, h = scrollph y maxy in
3148 method modehash
= modehash
3151 class outlinelistview ~source
=
3154 ~source
:(source
:> lvsource
)
3156 ~modehash
:(findkeyhash conf "outline")
3159 method key key mask
=
3160 let calcfirst first active =
3163 let rows = active - first in
3164 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3168 let active = m_active
+ incr in
3169 let active = bound active 0 (source#getitemcount
- 1) in
3170 let first = calcfirst m_first
active in
3171 G.postRedisplay "outline navigate";
3172 coe {< m_active
= active; m_first
= first >}
3174 let ctrl = Wsi.withctrl mask
in
3176 | 110 when ctrl -> (* ctrl-n *)
3177 source#narrow m_qsearch
;
3178 G.postRedisplay "outline ctrl-n";
3179 coe {< m_first
= 0; m_active
= 0 >}
3181 | 117 when ctrl -> (* ctrl-u *)
3183 G.postRedisplay "outline ctrl-u";
3185 coe {< m_first
= 0; m_active
= 0 >}
3187 | 108 when ctrl -> (* ctrl-l *)
3188 let first = m_active
- (fstate.maxrows
/ 2) in
3189 G.postRedisplay "outline ctrl-l";
3190 coe {< m_first
= first >}
3192 | 0xff9f | 0xffff -> (* delete *)
3193 source#remove m_active
;
3194 G.postRedisplay "outline delete";
3195 let active = max
0 (m_active
-1) in
3196 coe {< m_first
= firstof m_first
active;
3197 m_active
= active >}
3199 | 0xff52 -> navigate ~
-1 (* up *)
3200 | 0xff54 -> navigate 1 (* down *)
3201 | 0xff55 -> (* prior *)
3202 navigate ~
-(fstate.maxrows
)
3203 | 0xff56 -> (* next *)
3204 navigate fstate.maxrows
3206 | 0xff53 -> (* [ctrl-]right *)
3210 G.postRedisplay "outline ctrl right";
3211 {< m_pan
= m_pan
+ 1 >}
3213 else self#updownlevel
1
3217 | 0xff51 -> (* [ctrl-]left *)
3221 G.postRedisplay "outline ctrl left";
3222 {< m_pan
= m_pan
- 1 >}
3224 else self#updownlevel ~
-1
3228 | 0xff50 -> (* home *)
3229 G.postRedisplay "outline home";
3230 coe {< m_first
= 0; m_active
= 0 >}
3232 | 0xff57 -> (* end *)
3233 let active = source#getitemcount
- 1 in
3234 let first = max
0 (active - fstate.maxrows
) in
3235 G.postRedisplay "outline end";
3236 coe {< m_active
= active; m_first
= first >}
3238 | _ -> super#
key key mask
3241 let outlinesource usebookmarks
=
3244 inherit lvsourcebase
3245 val mutable m_items
= empty
3246 val mutable m_orig_items
= empty
3247 val mutable m_prev_items
= empty
3248 val mutable m_narrow_pattern
= ""
3249 val mutable m_hadremovals
= false
3251 method getitemcount
=
3252 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3255 if n == Array.length m_items
&& m_hadremovals
3257 ("[Confirm removal]", 0)
3259 let s, n, _ = m_items
.(n) in
3262 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3263 ignore
(uioh
, first, qsearch);
3264 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3266 if String.length m_narrow_pattern
= 0
3272 if not
confrimremoval
3274 let _, _, anchor = m_items
.(active) in
3279 state.bookmarks
<- Array.to_list m_items
;
3280 m_orig_items
<- m_items
;
3283 else m_items
<- items;
3287 method hasaction
_ = true
3290 if Array.length m_items
!= Array.length m_orig_items
3291 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3294 method narrow
pattern =
3295 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3299 let rec loop accu n =
3302 m_narrow_pattern
<- pattern;
3303 m_items
<- Array.of_list
accu
3306 let (s, _, _) as o = m_items
.(n) in
3308 if (try ignore
(Str.search_forward
re s 0); true
3309 with Not_found
-> false)
3315 loop [] (Array.length m_items
- 1)
3320 then Array.of_list
state.bookmarks
3323 m_items
<- m_orig_items
3328 if m
>= 0 && m
< Array.length m_items
3330 m_hadremovals
<- true;
3331 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3332 let n = if n >= m
then n+1 else n in
3337 method reset
anchor items =
3338 m_hadremovals
<- false;
3339 if m_orig_items
== empty || m_prev_items
!= items
3341 m_orig_items
<- items;
3342 if String.length m_narrow_pattern
= 0
3343 then m_items
<- items;
3345 m_prev_items
<- items;
3346 let rely = getanchory anchor in
3348 let rec loop n best bestd
=
3349 if n = Array.length m_items
3352 let (_, _, anchor) = m_items
.(n) in
3353 let orely = getanchory anchor in
3354 let d = abs
(orely - rely) in
3357 else loop (n+1) best bestd
3362 m_first
<- firstof m_first
active
3366 let enterselector usebookmarks
=
3367 let source = outlinesource usebookmarks
in
3371 then Array.of_list
state.bookmarks
3374 if Array.length
outlines = 0
3376 showtext ' ' errmsg
;
3379 state.text <- source#greetmsg
;
3380 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3381 let anchor = getanchor () in
3382 source#reset
anchor outlines;
3383 state.uioh
<- coe (new outlinelistview ~
source);
3384 G.postRedisplay "enter selector";
3388 let enteroutlinemode =
3389 let f = enterselector false in
3390 fun ()-> f "Document has no outline";
3393 let enterbookmarkmode =
3394 let f = enterselector true in
3395 fun () -> f "Document has no bookmarks (yet)";
3398 let color_of_string s =
3399 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3400 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3404 let color_to_string (r
, g
, b) =
3405 let r = truncate
(r *. 256.0)
3406 and g
= truncate
(g
*. 256.0)
3407 and b = truncate
(b *. 256.0) in
3408 Printf.sprintf
"%d/%d/%d" r g
b
3411 let irect_of_string s =
3412 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3415 let irect_to_string (x0,y0,x1,y1) =
3416 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3419 let makecheckers () =
3420 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3422 converted by Issac Trotts. July 25, 2002 *)
3423 let image_height = 64
3424 and image_width
= 64 in
3428 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3430 for i
= 0 to image_width
- 1 do
3431 for j
= 0 to image_height - 1 do
3432 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3433 (if (i
land 8 ) lxor (j
land 8) = 0
3434 then [|255;255;255|] else [|200;200;200|])
3439 let image = make_image () in
3440 let id = GlTex.gen_texture
() in
3441 GlTex.bind_texture `texture_2d
id;
3442 GlPix.store
(`unpack_alignment
1);
3443 GlTex.image2d
image;
3444 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3447 `mag_filter `nearest
;
3448 `min_filter `nearest
];
3452 let setcheckers enabled
=
3453 match state.texid
with
3455 if enabled
then state.texid
<- Some
(makecheckers ())
3460 GlTex.delete_texture texid
;
3461 state.texid
<- None
;
3465 let int_of_string_with_suffix s =
3466 let l = String.length
s in
3470 let suffix = Char.lowercase
s.[l-1] in
3472 | 'k'
-> String.sub
s 0 (l-1), 10
3473 | 'm'
-> String.sub
s 0 (l-1), 20
3474 | 'g'
-> String.sub
s 0 (l-1), 30
3478 let n = int_of_string
s1 in
3479 let m = n lsl shift
in
3481 then raise
(Failure
"value too large")
3485 let string_with_suffix_of_int n =
3493 if n land ((1 lsl 20) - 1) = 0
3496 if n land ((1 lsl 10) - 1) = 0
3503 let h = n mod 1000 in
3506 then string_of_int
h ^
s
3508 let s = Printf.sprintf
"_%03d%s" h s in
3515 let defghyllscroll = (40, 8, 32);;
3516 let ghyllscroll_of_string s =
3517 let (n, a, b) as nab
=
3520 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3522 if n <= a || n <= b || a >= b
3523 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3527 let ghyllscroll_to_string ((n, a, b) as nab
) =
3528 if nab
= defghyllscroll
3530 else Printf.sprintf
"%d,%d,%d" n a b;
3533 let describe_location () =
3535 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3537 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3538 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3542 else (100. *. (float state.y /. float maxy))
3546 Printf.sprintf
"page %d of %d [%.2f%%]"
3547 (fn+1) state.pagecount
percent
3550 "pages %d-%d of %d [%.2f%%]"
3551 (fn+1) (ln
+1) state.pagecount
percent
3555 let btos b = if b then "\xe2\x88\x9a" else "" in
3556 let showextended = ref false in
3557 let leave mode
= function
3558 | Confirm
-> state.mode
<- mode
3559 | Cancel
-> state.mode
<- mode
in
3562 val mutable m_first_time
= true
3563 val mutable m_l
= []
3564 val mutable m_a
= [||]
3565 val mutable m_prev_uioh
= nouioh
3566 val mutable m_prev_mode
= View
3568 inherit lvsourcebase
3570 method reset prev_mode prev_uioh
=
3571 m_a
<- Array.of_list
(List.rev m_l
);
3573 m_prev_mode
<- prev_mode
;
3574 m_prev_uioh
<- prev_uioh
;
3578 if n >= Array.length m_a
3582 | _, _, _, Action
_ -> m_active
<- n
3586 m_first_time
<- false;
3589 method int name get
set =
3591 (name
, `
int get
, 1, Action
(
3594 try set (int_of_string
s)
3596 state.text <- Printf.sprintf
"bad integer `%s': %s"
3597 s (Printexc.to_string exn
)
3600 let te = name ^
": ", "", None
, intentry, ondone in
3601 state.mode
<- Textentry
(te, leave m_prev_mode
);
3605 method int_with_suffix name get
set =
3607 (name
, `intws get
, 1, Action
(
3610 try set (int_of_string_with_suffix s)
3612 state.text <- Printf.sprintf
"bad integer `%s': %s"
3613 s (Printexc.to_string exn
)
3617 name ^
": ", "", None
, intentry_with_suffix, ondone
3619 state.mode
<- Textentry
(te, leave m_prev_mode
);
3623 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3625 (name
, `
bool (btos, get
), offset
, Action
(
3632 method color name get
set =
3634 (name
, `color get
, 1, Action
(
3636 let invalid = (nan
, nan
, nan
) in
3639 try color_of_string s
3641 state.text <- Printf.sprintf
"bad color `%s': %s"
3642 s (Printexc.to_string exn
);
3648 let te = name ^
": ", "", None
, textentry, ondone in
3649 state.text <- color_to_string (get
());
3650 state.mode
<- Textentry
(te, leave m_prev_mode
);
3654 method string name get
set =
3656 (name
, `
string get
, 1, Action
(
3658 let ondone s = set s in
3659 let te = name ^
": ", "", None
, textentry, ondone in
3660 state.mode
<- Textentry
(te, leave m_prev_mode
);
3664 method colorspace name get
set =
3666 (name
, `
string get
, 1, Action
(
3669 let vals = [| "rgb"; "bgr"; "gray" |] in
3671 inherit lvsourcebase
3674 m_active
<- int_of_colorspace conf.colorspace
;
3677 method getitemcount
= Array.length
vals
3678 method getitem
n = (vals.(n), 0)
3679 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3680 ignore
(uioh
, first, pan
, qsearch);
3681 if not cancel
then set active;
3683 method hasaction
_ = true
3687 let modehash = findkeyhash conf "info" in
3688 coe (new listview ~
source ~trusted
:true ~
modehash)
3691 method caption
s offset
=
3692 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3694 method caption2
s f offset
=
3695 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3697 method getitemcount
= Array.length m_a
3700 let tostr = function
3701 | `
int f -> string_of_int
(f ())
3702 | `intws
f -> string_with_suffix_of_int (f ())
3704 | `color
f -> color_to_string (f ())
3705 | `
bool (btos, f) -> btos (f ())
3708 let name, t
, offset
, _ = m_a
.(n) in
3709 ((let s = tostr t
in
3710 if String.length
s > 0
3711 then Printf.sprintf
"%s\t%s" name s
3715 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3719 m_qsearch
<- qsearch;
3721 match m_a
.(active) with
3722 | _, _, _, Action
f -> f uioh
3734 method hasaction
n =
3736 | _, _, _, Action
_ -> true
3740 let rec fillsrc prevmode prevuioh
=
3741 let sep () = src#caption
"" 0 in
3742 let colorp name get
set =
3744 (fun () -> color_to_string (get
()))
3747 let c = color_of_string v in
3750 state.text <- Printf.sprintf
"bad color `%s': %s"
3751 v (Printexc.to_string exn
);
3754 let oldmode = state.mode
in
3755 let birdseye = isbirdseye state.mode
in
3757 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3759 src#
bool "presentation mode"
3760 (fun () -> conf.presentation)
3762 conf.presentation <- v;
3763 state.anchor <- getanchor ();
3766 src#
bool "ignore case in searches"
3767 (fun () -> conf.icase
)
3768 (fun v -> conf.icase
<- v);
3771 (fun () -> conf.preload)
3772 (fun v -> conf.preload <- v);
3774 src#
bool "highlight links"
3775 (fun () -> conf.hlinks
)
3776 (fun v -> conf.hlinks
<- v);
3778 src#
bool "under info"
3779 (fun () -> conf.underinfo
)
3780 (fun v -> conf.underinfo
<- v);
3782 src#
bool "persistent bookmarks"
3783 (fun () -> conf.savebmarks
)
3784 (fun v -> conf.savebmarks
<- v);
3786 src#
bool "proportional display"
3787 (fun () -> conf.proportional
)
3788 (fun v -> reqlayout conf.angle
v);
3790 src#
bool "trim margins"
3791 (fun () -> conf.trimmargins
)
3792 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3794 src#
bool "persistent location"
3795 (fun () -> conf.jumpback
)
3796 (fun v -> conf.jumpback
<- v);
3799 src#
int "inter-page space"
3800 (fun () -> conf.interpagespace)
3802 conf.interpagespace <- n;
3804 match state.layout with
3809 state.maxy <- calcheight ();
3810 let y = getpagey pageno in
3815 (fun () -> conf.pagebias
)
3816 (fun v -> conf.pagebias
<- v);
3818 src#
int "scroll step"
3819 (fun () -> conf.scrollstep
)
3820 (fun n -> conf.scrollstep
<- n);
3822 src#
int "auto scroll step"
3824 match state.autoscroll
with
3826 | _ -> conf.autoscrollstep
)
3828 if state.autoscroll
<> None
3829 then state.autoscroll
<- Some
n;
3830 conf.autoscrollstep
<- n);
3833 (fun () -> truncate
(conf.zoom *. 100.))
3834 (fun v -> setzoom ((float v) /. 100.));
3837 (fun () -> conf.angle
)
3838 (fun v -> reqlayout v conf.proportional
);
3840 src#
int "scroll bar width"
3841 (fun () -> state.scrollw
)
3845 reshape conf.winw
conf.winh
;
3848 src#
int "scroll handle height"
3849 (fun () -> conf.scrollh
)
3850 (fun v -> conf.scrollh
<- v;);
3852 src#
int "thumbnail width"
3853 (fun () -> conf.thumbw
)
3855 conf.thumbw
<- min
4096 v;
3858 leavebirdseye beye
false;
3863 src#
string "columns"
3865 match conf.columns
with
3867 | Some
(multicol
, _) -> columns_to_string multicol
)
3869 let n, a, b = columns_of_string v in
3873 src#caption
"Presentation mode" 0;
3874 src#
bool "scrollbar visible"
3875 (fun () -> conf.scrollbarinpm
)
3877 if v != conf.scrollbarinpm
3879 conf.scrollbarinpm
<- v;
3880 if conf.presentation
3882 state.scrollw
<- if v then conf.scrollbw
else 0;
3883 reshape conf.winw
conf.winh
;
3889 src#caption
"Pixmap cache" 0;
3890 src#int_with_suffix
"size (advisory)"
3891 (fun () -> conf.memlimit
)
3892 (fun v -> conf.memlimit
<- v);
3895 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3896 (string_with_suffix_of_int state.memused
)
3897 (Hashtbl.length
state.tilemap
)) 1;
3900 src#caption
"Layout" 0;
3901 src#caption2
"Dimension"
3903 Printf.sprintf
"%dx%d (virtual %dx%d)"
3909 src#caption2
"Position" (fun () ->
3910 Printf.sprintf
"%dx%d" state.x state.y
3913 src#caption2
"Visible" (fun () -> describe_location ()) 1
3917 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3918 "Save these parameters as global defaults at exit"
3919 (fun () -> conf.bedefault
)
3920 (fun v -> conf.bedefault
<- v)
3924 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3925 src#
bool ~offset
:0 ~
btos "Extended parameters"
3926 (fun () -> !showextended)
3927 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3931 (fun () -> conf.checkers
)
3932 (fun v -> conf.checkers
<- v; setcheckers v);
3933 src#
bool "update cursor"
3934 (fun () -> conf.updatecurs
)
3935 (fun v -> conf.updatecurs
<- v);
3937 (fun () -> conf.verbose
)
3938 (fun v -> conf.verbose
<- v);
3939 src#
bool "invert colors"
3940 (fun () -> conf.invert
)
3941 (fun v -> conf.invert
<- v);
3943 (fun () -> conf.maxhfit
)
3944 (fun v -> conf.maxhfit
<- v);
3945 src#
bool "redirect stderr"
3946 (fun () -> conf.redirectstderr)
3947 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3948 src#
string "uri launcher"
3949 (fun () -> conf.urilauncher
)
3950 (fun v -> conf.urilauncher
<- v);
3951 src#
string "path launcher"
3952 (fun () -> conf.pathlauncher
)
3953 (fun v -> conf.pathlauncher
<- v);
3954 src#
string "tile size"
3955 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3958 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3959 conf.tileh
<- max
64 w;
3960 conf.tilew
<- max
64 h;
3963 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3964 v (Printexc.to_string exn
));
3965 src#
int "texture count"
3966 (fun () -> conf.texcount
)
3969 then conf.texcount
<- v
3970 else showtext '
!'
" Failed to set texture count please retry later"
3972 src#
int "slice height"
3973 (fun () -> conf.sliceheight
)
3975 conf.sliceheight
<- v;
3976 wcmd "sliceh %d" conf.sliceheight
;
3978 src#
int "anti-aliasing level"
3979 (fun () -> conf.aalevel
)
3981 conf.aalevel
<- bound v 0 8;
3982 state.anchor <- getanchor ();
3983 opendoc state.path
state.password
;
3985 src#
int "ui font size"
3986 (fun () -> fstate.fontsize
)
3987 (fun v -> setfontsize (bound v 5 100));
3988 colorp "background color"
3989 (fun () -> conf.bgcolor
)
3990 (fun v -> conf.bgcolor
<- v);
3991 src#
bool "crop hack"
3992 (fun () -> conf.crophack
)
3993 (fun v -> conf.crophack
<- v);
3994 src#
string "trim fuzz"
3995 (fun () -> irect_to_string conf.trimfuzz
)
3998 conf.trimfuzz
<- irect_of_string v;
4000 then settrim true conf.trimfuzz
;
4002 state.text <- Printf.sprintf
"bad irect `%s': %s"
4003 v (Printexc.to_string exn
)
4005 src#
string "throttle"
4007 match conf.maxwait
with
4008 | None
-> "show place holder if page is not ready"
4011 then "wait for page to fully render"
4013 "wait " ^ string_of_float
time
4014 ^
" seconds before showing placeholder"
4018 let f = float_of_string
v in
4020 then conf.maxwait
<- None
4021 else conf.maxwait
<- Some
f
4023 state.text <- Printf.sprintf
"bad time `%s': %s"
4024 v (Printexc.to_string exn
)
4026 src#
string "ghyll scroll"
4028 match conf.ghyllscroll
with
4030 | Some nab
-> ghyllscroll_to_string nab
4035 if String.length
v = 0
4037 else Some
(ghyllscroll_of_string v)
4039 conf.ghyllscroll
<- gs
4041 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4042 v (Printexc.to_string exn
)
4044 src#
string "selection command"
4045 (fun () -> conf.selcmd
)
4046 (fun v -> conf.selcmd
<- v);
4047 src#colorspace
"color space"
4048 (fun () -> colorspace_to_string conf.colorspace
)
4050 conf.colorspace
<- colorspace_of_int v;
4057 src#caption
"Document" 0;
4058 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4059 src#caption2
"Pages"
4060 (fun () -> string_of_int
state.pagecount
) 1;
4061 src#caption2
"Dimensions"
4062 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4066 src#caption
"Trimmed margins" 0;
4067 src#caption2
"Dimensions"
4068 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4071 src#reset prevmode prevuioh
;
4075 let prevmode = state.mode
4076 and prevuioh
= state.uioh in
4077 fillsrc prevmode prevuioh
;
4078 let source = (src :> lvsource
) in
4079 let modehash = findkeyhash conf "info" in
4080 state.uioh <- coe (object (self)
4081 inherit listview ~
source ~trusted
:true ~
modehash as super
4082 val mutable m_prevmemused
= 0
4083 method infochanged
= function
4085 if m_prevmemused
!= state.memused
4087 m_prevmemused
<- state.memused
;
4088 G.postRedisplay "memusedchanged";
4090 | Pdim
-> G.postRedisplay "pdimchanged"
4091 | Docinfo
-> fillsrc prevmode prevuioh
4093 method key key mask
=
4094 if not
(Wsi.withctrl mask
)
4097 | 0xff51 -> coe (self#updownlevel ~
-1)
4098 | 0xff53 -> coe (self#updownlevel
1)
4099 | _ -> super#
key key mask
4100 else super#
key key mask
4102 G.postRedisplay "info";
4108 inherit lvsourcebase
4109 method getitemcount
= Array.length
state.help
4111 let s, n, _ = state.help
.(n) in
4114 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4118 m_qsearch
<- qsearch;
4119 match state.help
.(active) with
4120 | _, _, Action
f -> Some
(f uioh)
4130 method hasaction
n =
4131 match state.help
.(n) with
4132 | _, _, Action
_ -> true
4139 let modehash = findkeyhash conf "help" in
4140 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4141 G.postRedisplay "help";
4146 let re = Str.regexp
"[\r\n]" in
4148 inherit lvsourcebase
4149 val mutable m_items
= [||]
4151 method getitemcount
= 1 + Array.length m_items
4156 else m_items
.(n-1), 0
4158 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4163 then Buffer.clear
state.errmsgs
;
4164 m_qsearch
<- qsearch;
4171 method hasaction
n =
4175 state.newerrmsgs
<- false;
4176 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4177 m_items
<- Array.of_list
l
4185 let source = (msgsource :> lvsource
) in
4186 let modehash = findkeyhash conf "listview" in
4187 state.uioh <- coe (object
4188 inherit listview ~
source ~trusted
:false ~
modehash as super
4191 then msgsource#reset
;
4194 G.postRedisplay "msgs";
4197 let quickbookmark ?title
() =
4198 match state.layout with
4204 let sec = Unix.gettimeofday
() in
4205 let tm = Unix.localtime
sec in
4206 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4210 (tm.Unix.tm_year
+ 1900)
4213 | Some
title -> title
4216 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4221 state.fullscreen
<- None
;
4225 let setautoscrollspeed step goingdown
=
4226 let incr = max
1 ((abs step
) / 2) in
4227 let incr = if goingdown
then incr else -incr in
4228 let astep = step
+ incr in
4229 state.autoscroll
<- Some
astep;
4232 let viewkeyboard key mask
=
4234 let mode = state.mode in
4235 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4238 G.postRedisplay "view:enttext"
4240 let ctrl = Wsi.withctrl mask
in
4245 | 0xff63 -> (* insert *)
4246 state.mode <- LinkNav None
;
4249 | 0xff1b | 113 -> (* escape / q *)
4250 begin match state.mstate
with
4252 state.mstate
<- Mnone
;
4253 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4254 G.postRedisplay "kill zoom rect";
4256 match state.ranchors
with
4257 | [] -> raise
Wsi.Quit
4258 | (path
, password
, anchor) :: rest
->
4259 state.ranchors
<- rest
;
4260 state.anchor <- anchor;
4261 opendoc path password
4264 | 0xff08 -> (* backspace *)
4265 let y = getnav ~
-1 in
4266 gotoy_and_clear_text y
4274 G.postRedisplay "dehighlight";
4276 | 47 | 63 -> (* / ? *)
4277 let ondone isforw
s =
4278 cbput state.hists
.pat
s;
4279 state.searchpattern
<- s;
4282 let s = String.create
1 in
4283 s.[0] <- Char.chr
key;
4284 enttext (s, "", Some
(onhist state.hists
.pat
),
4285 textentry, ondone (key = 47))
4287 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4288 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4289 setzoom (conf.zoom +. incr)
4291 | 43 | 0xffab -> (* + *)
4294 try int_of_string
s with exc
->
4295 state.text <- Printf.sprintf
"bad integer `%s': %s"
4296 s (Printexc.to_string exc
);
4302 state.text <- "page bias is now " ^ string_of_int
n;
4305 enttext ("page bias: ", "", None
, intentry, ondone)
4307 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4308 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4309 setzoom (max
0.01 (conf.zoom -. decr))
4311 | 45 | 0xffad -> (* - *)
4312 let ondone msg
= state.text <- msg
in
4314 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4315 optentry state.mode, ondone
4318 | 48 when ctrl -> (* ctrl-0 *)
4321 | 49 when ctrl -> (* 1 *)
4322 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4326 | 0xffc6 -> (* f9 *)
4329 | 57 when ctrl -> (* ctrl-9 *)
4332 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4333 when not
ctrl -> (* 0..9 *)
4336 try int_of_string
s with exc
->
4337 state.text <- Printf.sprintf
"bad integer `%s': %s"
4338 s (Printexc.to_string exc
);
4344 cbput state.hists
.pag
(string_of_int
n);
4345 gotopage1 (n + conf.pagebias
- 1) 0;
4348 let pageentry text key =
4349 match Char.unsafe_chr
key with
4350 | 'g'
-> TEdone
text
4351 | _ -> intentry text key
4353 let text = "x" in text.[0] <- Char.chr
key;
4354 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4357 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4358 reshape conf.winw
conf.winh
;
4361 conf.hlinks
<- not
conf.hlinks
;
4362 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4363 G.postRedisplay "toggle highlightlinks";
4366 begin match state.autoscroll
with
4368 conf.autoscrollstep
<- step
;
4369 state.autoscroll
<- None
4371 if conf.autoscrollstep
= 0
4372 then state.autoscroll
<- Some
1
4373 else state.autoscroll
<- Some
conf.autoscrollstep
4377 conf.presentation <- not
conf.presentation;
4378 if conf.presentation
4380 if not
conf.scrollbarinpm
4381 then state.scrollw
<- 0;
4384 state.scrollw
<- conf.scrollbw
;
4386 showtext ' '
("presentation mode " ^
4387 if conf.presentation then "on" else "off");
4388 state.anchor <- getanchor ();
4392 begin match state.fullscreen
with
4394 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4397 state.fullscreen
<- None
;
4402 gotoy_and_clear_text 0
4405 gotopage1 (state.pagecount
- 1) 0
4407 | 112 | 78 -> (* p|N *)
4408 search state.searchpattern
false
4410 | 110 | 0xffc0 -> (* n|F3 *)
4411 search state.searchpattern
true
4414 begin match state.layout with
4417 gotoy_and_clear_text (getpagey l.pageno)
4421 begin match List.rev
state.layout with
4424 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4425 gotoy_and_clear_text (getpagey pageno)
4428 | 0xff9f | 0xffff -> (* delete *)
4429 begin match state.layout with
4432 let pageno = max
0 (l.pageno-1) in
4433 gotoy_and_clear_text (getpagey pageno)
4437 showtext ' '
(describe_location ());
4440 begin match state.layout with
4443 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4448 enterbookmarkmode ()
4450 | 104 | 0xffbe -> (* h|F1 *)
4456 | 101 when conf.redirectstderr -> (* e *)
4461 match state.layout with
4464 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4468 enttext ("bookmark: ", "", None
, textentry, ondone)
4472 showtext ' '
"Quick bookmark added";
4475 begin match state.layout with
4477 let rect = getpdimrect
l.pagedimno
in
4481 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4482 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4484 (truncate
(rect.(1) -. rect.(0)),
4485 truncate
(rect.(3) -. rect.(0)))
4487 let w = truncate
((float w)*.conf.zoom)
4488 and h = truncate
((float h)*.conf.zoom) in
4491 state.anchor <- getanchor ();
4492 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4494 G.postRedisplay "z";
4499 | 50 when ctrl -> (* ctrl-2 *)
4500 let maxw = getmaxw
() in
4502 then setzoom (maxw /. float conf.winw
)
4504 | 60 | 62 -> (* < > *)
4505 reqlayout (conf.angle
+ (if key = 60 then 30 else -30)) conf.proportional
4507 | 91 | 93 -> (* [ ] *)
4509 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4511 G.postRedisplay "brightness";
4513 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4514 setzoom state.prevzoom
4516 | 107 | 0xff52 -> (* k up *)
4517 begin match state.autoscroll
with
4519 begin match state.mode with
4520 | Birdseye beye
-> upbirdseye 1 beye
4523 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4524 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4527 setautoscrollspeed n false
4530 | 106 | 0xff54 -> (* j down *)
4531 begin match state.autoscroll
with
4533 begin match state.mode with
4534 | Birdseye beye
-> downbirdseye 1 beye
4537 then gotoy_and_clear_text (clamp (conf.winh
/2))
4538 else gotoy_and_clear_text (clamp conf.scrollstep
)
4541 setautoscrollspeed n true
4544 | 0xff51 | 0xff53 when Wsi.withnone mask
-> (* left / right *)
4552 let dx = if key = 0xff51 then dx else -dx in
4553 state.x <- state.x + dx;
4554 gotoy_and_clear_text state.y
4557 G.postRedisplay "lef/right"
4560 | 0xff55 -> (* prior *)
4564 match state.layout with
4566 | l :: _ -> state.y - l.pagey
4572 | 0xff56 -> (* next *)
4576 match List.rev
state.layout with
4578 | l :: _ -> getpagey l.pageno
4584 | 0xff50 -> gotoghyll 0
4585 | 0xff57 -> gotoghyll (clamp state.maxy)
4586 | 0xff53 when Wsi.withalt mask
->
4587 gotoghyll (getnav ~
-1)
4588 | 0xff51 when Wsi.withalt mask
->
4589 gotoghyll (getnav 1)
4592 state.anchor <- getanchor ();
4593 opendoc state.path
state.password
4598 | 118 when conf.debug
-> (* v *)
4601 match getopaque l.pageno with
4604 let x0, y0, x1, y1 = pagebbox opaque
in
4605 let a,b = float x0, float y0 in
4606 let c,d = float x1, float y0 in
4607 let e,f = float x1, float y1 in
4608 let h,j
= float x0, float y1 in
4609 let rect = (a,b,c,d,e,f,h,j
) in
4611 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4613 G.postRedisplay "v";
4616 vlog "huh? %s" (Wsi.keyname
key)
4619 let gotounder = function
4620 | Ulinkgoto
(pageno, top) ->
4624 gotopage1 pageno top;
4630 | Uremote
(filename
, pageno) ->
4632 if Sys.file_exists filename
4635 let dir = Filename.dirname
state.path in
4636 let path = Filename.concat
dir filename
in
4637 if Sys.file_exists
path
4641 if String.length
path > 0
4643 let anchor = getanchor () in
4644 let ranchor = state.path, state.password
, anchor in
4645 state.anchor <- (pageno, 0.0);
4646 state.ranchors
<- ranchor :: state.ranchors
;
4649 else showtext '
!'
("Could not find " ^ filename
)
4651 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4654 let linknavkeyboard key mask
linknav =
4658 G.postRedisplay "leave linknav"
4661 begin match if state.currently
= Idle
then linknav else None
with
4662 | None
-> viewkeyboard key mask
4663 | Some
((l, opaque
, n), _) ->
4666 let under = getlink opaque
n in
4672 | 0xff50 -> (* home *)
4673 Some
(findlink opaque LDfirst
), 1
4675 | 0xff57 -> (* end *)
4676 Some
(findlink opaque LDlast
), -1
4678 | 0xff51 | 0xff53 -> (* left right *)
4684 Some
(findlink opaque
ld), dir
4686 | 0xff52 | 0xff54 -> (* up down *)
4692 Some
(findlink opaque
ld), dir
4696 begin match opt with
4698 begin match findpwl
l.pageno dir with
4701 state.mode <- LinkNav None
;
4702 let y, h = getpageyh pageno in
4705 then y + h - conf.winh
4711 | Some
(Lfound
(m, x0, y0, x1, y1)) ->
4712 if y0 < l.pagey || l.pagedispy + (y0 - l.pagey) > conf.winh
4714 state.mode <- LinkNav None
;
4715 gotoy (state.y + (y0 - l.pagey))
4720 match findpwl
l.pageno dir with
4723 state.mode <- LinkNav None
;
4724 let y, h = getpageyh pageno in
4727 then y + h - conf.winh
4733 let r = x0, y0, x1, y1 in
4734 state.mode <- LinkNav
(Some
((l, opaque
, m), r));
4735 G.postRedisplay "linknav up"
4738 viewkeyboard key mask
4743 let keyboard key mask
=
4744 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4745 then wcmd "interrupt"
4746 else state.uioh <- state.uioh#
key key mask
4749 let birdseyekeyboard key mask
4750 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4752 match conf.columns
with
4754 | Some
((c, _, _), _) -> c
4757 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4758 let y, h = getpageyh pageno in
4759 let top = (conf.winh
- h) / 2 in
4760 gotoy (max
0 (y - top))
4761 | 0xff0d -> leavebirdseye beye
false
4762 | 0xff1b -> leavebirdseye beye
true (* escape *)
4763 | 0xff52 -> upbirdseye incr beye
(* prior *)
4764 | 0xff54 -> downbirdseye incr beye
(* next *)
4765 | 0xff51 -> upbirdseye 1 beye
(* up *)
4766 | 0xff53 -> downbirdseye 1 beye
(* down *)
4769 begin match state.layout with
4773 state.mode <- Birdseye
(
4774 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4776 gotopage1 l.pageno 0;
4779 let layout = layout (state.y-conf.winh
) conf.winh
in
4781 | [] -> gotoy (clamp (-conf.winh
))
4783 state.mode <- Birdseye
(
4784 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4786 gotopage1 l.pageno 0
4789 | [] -> gotoy (clamp (-conf.winh
))
4793 begin match List.rev
state.layout with
4795 let layout = layout (state.y + conf.winh
) conf.winh
in
4796 begin match layout with
4798 let incr = l.pageh
- l.pagevh in
4803 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4805 G.postRedisplay "birdseye pagedown";
4807 else gotoy (clamp (incr + conf.interpagespace*2));
4811 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4812 gotopage1 l.pageno 0;
4815 | [] -> gotoy (clamp conf.winh
)
4819 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4823 let pageno = state.pagecount
- 1 in
4824 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4825 if not
(pagevisible state.layout pageno)
4828 match List.rev
state.pdims
with
4830 | (_, _, h, _) :: _ -> h
4832 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4833 else G.postRedisplay "birdseye end";
4834 | _ -> viewkeyboard key mask
4839 match state.mode with
4840 | Textentry
_ -> scalecolor 0.4
4842 | View
-> scalecolor 1.0
4843 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4844 if l.pageno = hooverpageno
4847 if l.pageno = pageno
4853 begin match getopaque l.pageno with
4855 if tileready l l.pagex l.pagey
4857 let x = l.pagedispx - l.pagex
4858 and y = l.pagedispy - l.pagey in
4859 postprocess opaque
conf.hlinks
x y;
4865 let scrollindicator () =
4866 let sbw, ph
, sh = state.uioh#
scrollph in
4867 let sbh, pw
, sw = state.uioh#scrollpw
in
4869 GlDraw.color (0.64, 0.64, 0.64);
4871 (float (conf.winw
- sbw), 0.)
4872 (float conf.winw
, float conf.winh
)
4875 (0., float (conf.winh
- sbh))
4876 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4878 GlDraw.color (0.0, 0.0, 0.0);
4881 (float (conf.winw
- sbw), ph
)
4882 (float conf.winw
, ph
+. sh)
4885 (pw
, float (conf.winh
- sbh))
4886 (pw
+. sw, float conf.winh
)
4891 match state.mstate
with
4892 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4895 | Msel
((x0, y0), (x1, y1)) ->
4896 let rec loop = function
4898 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4899 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4900 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4901 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4903 match getopaque l.pageno with
4905 let dx, dy = pagetranslatepoint l 0 0 in
4910 GlMat.mode `modelview
;
4912 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4913 seltext opaque
(x0, y0, x1, y1);
4922 let showrects rects
=
4924 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4925 GlDraw.polygon_mode `both `fill
;
4926 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4928 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4930 if l.pageno = pageno
4932 let dx = float (l.pagedispx - l.pagex) in
4933 let dy = float (l.pagedispy - l.pagey) in
4934 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4935 GlDraw.begins `quads
;
4937 GlDraw.vertex2
(x0+.dx, y0+.dy);
4938 GlDraw.vertex2
(x1+.dx, y1+.dy);
4939 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4940 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4951 GlClear.color (scalecolor2 conf.bgcolor
);
4952 GlClear.clear
[`
color];
4953 List.iter
drawpage state.layout;
4955 match state.mode with
4956 | LinkNav
(Some
((page
, _, _), (x0, y0, x1, y1))) ->
4969 begin match state.mstate
with
4970 | Mzoomrect
((x0, y0), (x1, y1)) ->
4972 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4973 GlDraw.polygon_mode `both `fill
;
4974 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4975 GlDraw.rect (float x0, float y0)
4976 (float x1, float y1);
4983 let mx, my
= state.mpos
in
4989 let zoomrect x y x1 y1 =
4992 and y0 = min
y y1 in
4993 gotoy (state.y + y0);
4994 state.anchor <- getanchor ();
4995 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4997 if state.w < conf.winw
- state.scrollw
4998 then (conf.winw
- state.scrollw
- state.w) / 2
5001 state.x <- (state.x + margin) - x0;
5003 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5004 state.mstate
<- Mnone
;
5008 let winw = conf.winw - state.scrollw
- 1 in
5009 let s = float x /. float winw in
5010 let destx = truncate
(float (state.w + winw) *. s) in
5011 state.x <- winw - destx;
5012 gotoy_and_clear_text state.y;
5013 state.mstate
<- Mscrollx
;
5017 let s = float y /. float conf.winh
in
5018 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5019 gotoy_and_clear_text desty;
5020 state.mstate
<- Mscrolly
;
5023 let viewmouse button down
x y mask
=
5025 | n when (n == 4 || n == 5) && not down
->
5026 if Wsi.withctrl mask
5028 match state.mstate
with
5029 | Mzoom
(oldn
, i
) ->
5037 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5039 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5041 let zoom = conf.zoom -. incr in
5043 state.mstate
<- Mzoom
(n, 0);
5045 state.mstate
<- Mzoom
(n, i
+1);
5047 else state.mstate
<- Mzoom
(n, 0)
5049 | _ -> state.mstate
<- Mzoom
(n, 0)
5052 match state.autoscroll
with
5053 | Some step
-> setautoscrollspeed step
(n=4)
5057 then -conf.scrollstep
5058 else conf.scrollstep
5060 let incr = incr * 2 in
5061 let y = clamp incr in
5062 gotoy_and_clear_text y
5065 | 1 when Wsi.withctrl mask
->
5068 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5069 state.mstate
<- Mpan
(x, y)
5072 state.mstate
<- Mnone
5077 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5079 state.mstate
<- Mzoomrect
(p, p)
5082 match state.mstate
with
5083 | Mzoomrect
((x0, y0), _) ->
5084 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5085 then zoomrect x0 y0 x y
5087 state.mstate
<- Mnone
;
5088 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5089 G.postRedisplay "kill accidental zoom rect";
5092 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5093 state.mstate
<- Mnone
5096 | 1 when x > conf.winw - state.scrollw
->
5099 let _, position, sh = state.uioh#
scrollph in
5100 if y > truncate
position && y < truncate
(position +. sh)
5101 then state.mstate
<- Mscrolly
5104 state.mstate
<- Mnone
5106 | 1 when y > conf.winh
- state.hscrollh ->
5109 let _, position, sw = state.uioh#scrollpw
in
5110 if x > truncate
position && x < truncate
(position +. sw)
5111 then state.mstate
<- Mscrollx
5114 state.mstate
<- Mnone
5117 let dest = if down
then getunder x y else Unone
in
5118 begin match dest with
5119 | Ulinkgoto
(pageno, top) ->
5123 gotopage1 pageno top;
5129 | Uremote
(filename
, pageno) ->
5131 if Sys.file_exists filename
5134 let dir = Filename.dirname
state.path in
5135 let path = Filename.concat
dir filename
in
5136 if Sys.file_exists
path
5140 if String.length
path > 0
5142 let anchor = getanchor () in
5143 let ranchor = state.path, state.password
, anchor in
5144 state.anchor <- (pageno, 0.0);
5145 state.ranchors
<- ranchor :: state.ranchors
;
5148 else showtext '
!'
("Could not find " ^ filename
)
5150 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5152 | Unone
when down
->
5153 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5154 state.mstate
<- Mpan
(x, y);
5156 | Unone
| Utext
_ ->
5159 if conf.angle
mod 360 = 0
5161 state.mstate
<- Msel
((x, y), (x, y));
5162 G.postRedisplay "mouse select";
5166 match state.mstate
with
5169 | Mzoom
_ | Mscrollx
| Mscrolly
->
5170 state.mstate
<- Mnone
5172 | Mzoomrect
((x0, y0), _) ->
5176 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5177 state.mstate
<- Mnone
5179 | Msel
((_, y0), (_, y1)) ->
5180 let rec loop = function
5183 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5184 || ((y1 >= l.pagedispy
5185 && y1 <= (l.pagedispy + l.pagevh)))
5187 match getopaque l.pageno with
5189 copysel
conf.selcmd opaque
;
5190 G.postRedisplay "copysel"
5195 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5196 state.mstate
<- Mnone
;
5203 let birdseyemouse button down
x y mask
5204 (conf, leftx
, _, hooverpageno
, anchor) =
5207 let rec loop = function
5210 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5211 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5213 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5219 | _ -> viewmouse button down
x y mask
5222 let mouse button down
x y mask
=
5223 state.uioh <- state.uioh#button button down
x y mask
;
5227 state.uioh <- state.uioh#
motion x y
5231 state.uioh <- state.uioh#
pmotion x y;
5237 method key key mask
=
5238 begin match state.mode with
5239 | Textentry
textentry -> textentrykeyboard key mask
textentry
5240 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5241 | View
-> viewkeyboard key mask
5242 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5246 method button button bstate
x y mask
=
5247 begin match state.mode with
5249 | View
-> viewmouse button bstate
x y mask
5250 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5256 begin match state.mode with
5258 | View
| Birdseye
_ | LinkNav
_ ->
5259 match state.mstate
with
5260 | Mzoom
_ | Mnone
-> ()
5265 state.mstate
<- Mpan
(x, y);
5266 if conf.zoom > 1.0 then state.x <- state.x + dx;
5268 gotoy_and_clear_text y
5271 state.mstate
<- Msel
(a, (x, y));
5272 G.postRedisplay "motion select";
5275 let y = min
conf.winh
(max
0 y) in
5279 let x = min
conf.winw (max
0 x) in
5282 | Mzoomrect
(p0
, _) ->
5283 state.mstate
<- Mzoomrect
(p0
, (x, y));
5284 G.postRedisplay "motion zoomrect";
5288 method pmotion x y =
5289 begin match state.mode with
5290 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5291 let rec loop = function
5293 if hooverpageno
!= -1
5295 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5296 G.postRedisplay "pmotion birdseye no hoover";
5299 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5300 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5302 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5303 G.postRedisplay "pmotion birdseye hoover";
5313 match state.mstate
with
5314 | Mnone
-> updateunder x y
5315 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5320 method infochanged
_ = ()
5323 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5324 let p, h = scrollph state.y maxy in
5328 let winw = conf.winw - state.scrollw
- 1 in
5329 let fwinw = float winw in
5331 let sw = fwinw /. float state.w in
5332 let sw = fwinw *. sw in
5333 max
sw (float conf.scrollh
)
5336 let f = state.w+winw in
5337 let r = float (winw-state.x) /. float f in
5338 let p = fwinw *. r in
5342 if position +. sw > fwinw
5343 then fwinw -. position
5346 state.hscrollh, position, sw
5350 match state.mode with
5351 | LinkNav
_ -> "links"
5352 | Textentry
_ -> "textentry"
5353 | Birdseye
_ -> "birdseye"
5356 findkeyhash conf modename
5363 let fontpath = ref "";;
5366 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5369 let l = String.length
s in
5370 let b = Buffer.create
l in
5376 try Sys.getenv
"HOME"
5379 ("Can not determine home directory location: " ^
5380 Printexc.to_string exn
);
5384 let modifier_of_string = function
5385 | "alt" -> Wsi.altmask
5386 | "shift" -> Wsi.shiftmask
5387 | "ctrl" | "control" -> Wsi.ctrlmask
5388 | "meta" -> Wsi.metamask
5393 let r = Str.regexp
"-" in
5395 let elems = Str.full_split
r s in
5398 let m1 = modifier_of_string s in
5400 then (Wsi.namekey
s, m)
5403 | Str.Delim
s when n land 1 = 0 -> g s
5405 | Str.Delim
_ -> (k
, m)
5407 let rec loop n k
m = function
5410 let k, m = f n k m x in
5416 let keys_of_string =
5417 let r = Str.regexp
"[ \t]" in
5419 let elems = Str.split
r s in
5420 List.map
key_of_string elems
5423 let copykeyhashes c =
5424 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5427 let config_of c attrs
=
5431 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5432 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5433 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5434 | "preload" -> { c with preload = bool_of_string
v }
5435 | "page-bias" -> { c with pagebias
= int_of_string
v }
5436 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5437 | "auto-scroll-step" ->
5438 { c with autoscrollstep
= max
0 (int_of_string
v) }
5439 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5440 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5443 match String.lowercase
v with
5444 | "true" -> Some infinity
5446 | f -> Some
(float_of_string
f)
5448 { c with maxwait
= mw}
5449 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5450 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5451 | "vertical-margin" ->
5452 { c with interpagespace = max
0 (int_of_string
v) }
5454 let zoom = float_of_string
v /. 100. in
5455 let zoom = max
zoom 0.0 in
5456 { c with zoom = zoom }
5457 | "presentation" -> { c with presentation = bool_of_string
v }
5458 | "rotation-angle" -> { c with angle
= int_of_string
v }
5459 | "width" -> { c with winw = max
20 (int_of_string
v) }
5460 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5461 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5462 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5463 | "pixmap-cache-size" ->
5464 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5465 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5466 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5467 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5468 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5469 | "background-color" -> { c with bgcolor
= color_of_string v }
5470 | "scrollbar-in-presentation" ->
5471 { c with scrollbarinpm
= bool_of_string
v }
5472 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5473 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5474 | "mupdf-store-size" ->
5475 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5476 | "checkers" -> { c with checkers
= bool_of_string
v }
5477 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5478 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5479 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5480 | "uri-launcher" -> { c with urilauncher
= unent v }
5481 | "path-launcher" -> { c with pathlauncher
= unent v }
5482 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5483 | "invert-colors" -> { c with invert
= bool_of_string
v }
5484 | "brightness" -> { c with colorscale
= float_of_string
v }
5485 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5487 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5489 let nab = columns_of_string v in
5490 { c with columns
= Some
(nab, [||]) }
5491 | "birds-eye-columns" ->
5492 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5493 | "selection-command" -> { c with selcmd
= unent v }
5494 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5497 prerr_endline
("Error processing attribute (`" ^
5498 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5501 let rec fold c = function
5504 let c = apply c k v in
5507 fold { c with keyhashes
= copykeyhashes c } attrs
;
5510 let fromstring f pos
n v d =
5513 dolog "Error processing attribute (%S=%S) at %d\n%s"
5514 n v pos
(Printexc.to_string exn
)
5519 let bookmark_of attrs
=
5520 let rec fold title page
rely = function
5521 | ("title", v) :: rest
-> fold v page
rely rest
5522 | ("page", v) :: rest
-> fold title v rely rest
5523 | ("rely", v) :: rest
-> fold title page
v rest
5524 | _ :: rest
-> fold title page
rely rest
5525 | [] -> title, page
, rely
5527 fold "invalid" "0" "0" attrs
5531 let rec fold path page
rely pan
= function
5532 | ("path", v) :: rest
-> fold v page
rely pan rest
5533 | ("page", v) :: rest
-> fold path v rely pan rest
5534 | ("rely", v) :: rest
-> fold path page
v pan rest
5535 | ("pan", v) :: rest
-> fold path page
rely v rest
5536 | _ :: rest
-> fold path page
rely pan rest
5537 | [] -> path, page
, rely, pan
5539 fold "" "0" "0" "0" attrs
5543 let rec fold rs ls
= function
5544 | ("out", v) :: rest
-> fold v ls rest
5545 | ("in", v) :: rest
-> fold rs
v rest
5546 | _ :: rest
-> fold ls rs rest
5552 let setconf dst
src =
5553 dst
.scrollbw
<- src.scrollbw
;
5554 dst
.scrollh
<- src.scrollh
;
5555 dst
.icase
<- src.icase
;
5556 dst
.preload <- src.preload;
5557 dst
.pagebias
<- src.pagebias
;
5558 dst
.verbose
<- src.verbose
;
5559 dst
.scrollstep
<- src.scrollstep
;
5560 dst
.maxhfit
<- src.maxhfit
;
5561 dst
.crophack
<- src.crophack
;
5562 dst
.autoscrollstep
<- src.autoscrollstep
;
5563 dst
.maxwait
<- src.maxwait
;
5564 dst
.hlinks
<- src.hlinks
;
5565 dst
.underinfo
<- src.underinfo
;
5566 dst
.interpagespace <- src.interpagespace;
5567 dst
.zoom <- src.zoom;
5568 dst
.presentation <- src.presentation;
5569 dst
.angle
<- src.angle
;
5570 dst
.winw <- src.winw;
5571 dst
.winh
<- src.winh
;
5572 dst
.savebmarks
<- src.savebmarks
;
5573 dst
.memlimit
<- src.memlimit
;
5574 dst
.proportional
<- src.proportional
;
5575 dst
.texcount
<- src.texcount
;
5576 dst
.sliceheight
<- src.sliceheight
;
5577 dst
.thumbw
<- src.thumbw
;
5578 dst
.jumpback
<- src.jumpback
;
5579 dst
.bgcolor
<- src.bgcolor
;
5580 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5581 dst
.tilew
<- src.tilew
;
5582 dst
.tileh
<- src.tileh
;
5583 dst
.mustoresize
<- src.mustoresize
;
5584 dst
.checkers
<- src.checkers
;
5585 dst
.aalevel
<- src.aalevel
;
5586 dst
.trimmargins
<- src.trimmargins
;
5587 dst
.trimfuzz
<- src.trimfuzz
;
5588 dst
.urilauncher
<- src.urilauncher
;
5589 dst
.colorspace
<- src.colorspace
;
5590 dst
.invert
<- src.invert
;
5591 dst
.colorscale
<- src.colorscale
;
5592 dst
.redirectstderr <- src.redirectstderr;
5593 dst
.ghyllscroll
<- src.ghyllscroll
;
5594 dst
.columns
<- src.columns
;
5595 dst
.beyecolumns
<- src.beyecolumns
;
5596 dst
.selcmd
<- src.selcmd
;
5597 dst
.updatecurs
<- src.updatecurs
;
5598 dst
.pathlauncher
<- src.pathlauncher
;
5599 dst
.keyhashes
<- copykeyhashes src;
5603 let h = Hashtbl.create
10 in
5604 let dc = { defconf with angle
= defconf.angle
} in
5605 let rec toplevel v t spos
_ =
5607 | Vdata
| Vcdata
| Vend
-> v
5608 | Vopen
("llppconfig", _, closed
) ->
5611 else { v with f = llppconfig
}
5613 error
"unexpected subelement at top level" s spos
5614 | Vclose
_ -> error
"unexpected close at top level" s spos
5616 and llppconfig
v t spos
_ =
5618 | Vdata
| Vcdata
-> v
5619 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5620 | Vopen
("defaults", attrs
, closed
) ->
5621 let c = config_of dc attrs
in
5625 else { v with f = defaults
}
5627 | Vopen
("ui-font", attrs
, closed
) ->
5628 let rec getsize size
= function
5630 | ("size", v) :: rest
->
5632 fromstring int_of_string spos
"size" v fstate.fontsize
in
5634 | l -> getsize size l
5636 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5639 else { v with f = uifont
(Buffer.create
10) }
5641 | Vopen
("doc", attrs
, closed
) ->
5642 let pathent, spage
, srely
, span
= doc_of attrs
in
5643 let path = unent pathent
5644 and pageno = fromstring int_of_string spos
"page" spage
0
5645 and rely = fromstring float_of_string spos
"rely" srely
0.0
5646 and pan
= fromstring int_of_string spos
"pan" span
0 in
5647 let c = config_of dc attrs
in
5648 let anchor = (pageno, rely) in
5650 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5651 else { v with f = doc
path pan
anchor c [] }
5654 error
"unexpected subelement in llppconfig" s spos
5656 | Vclose
"llppconfig" -> { v with f = toplevel }
5657 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5659 and defaults
v t spos
_ =
5661 | Vdata
| Vcdata
-> v
5662 | Vend
-> error
"unexpected end of input in defaults" s spos
5663 | Vopen
("keymap", attrs
, closed
) ->
5665 try List.assoc
"mode" attrs
5666 with Not_found
-> "global" in
5671 let h = findkeyhash dc modename in
5672 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5675 { v with f = pkeymap
ret KeyMap.empty }
5677 | Vopen
(_, _, _) ->
5678 error
"unexpected subelement in defaults" s spos
5680 | Vclose
"defaults" ->
5681 { v with f = llppconfig
}
5683 | Vclose
_ -> error
"unexpected close in defaults" s spos
5685 and uifont
b v t spos
epos =
5688 Buffer.add_substring
b s spos
(epos - spos
);
5690 | Vopen
(_, _, _) ->
5691 error
"unexpected subelement in ui-font" s spos
5692 | Vclose
"ui-font" ->
5693 if String.length
!fontpath = 0
5694 then fontpath := Buffer.contents
b;
5695 { v with f = llppconfig
}
5696 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5697 | Vend
-> error
"unexpected end of input in ui-font" s spos
5699 and doc
path pan
anchor c bookmarks
v t spos
_ =
5701 | Vdata
| Vcdata
-> v
5702 | Vend
-> error
"unexpected end of input in doc" s spos
5703 | Vopen
("bookmarks", _, closed
) ->
5706 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5708 | Vopen
("keymap", attrs
, closed
) ->
5710 try List.assoc
"mode" attrs
5711 with Not_found
-> "global"
5717 let h = findkeyhash c modename in
5718 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5719 doc
path pan
anchor c bookmarks
5721 { v with f = pkeymap
ret KeyMap.empty }
5723 | Vopen
(_, _, _) ->
5724 error
"unexpected subelement in doc" s spos
5727 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5728 { v with f = llppconfig
}
5730 | Vclose
_ -> error
"unexpected close in doc" s spos
5732 and pkeymap
ret keymap
v t spos
_ =
5734 | Vdata
| Vcdata
-> v
5735 | Vend
-> error
"unexpected end of input in keymap" s spos
5736 | Vopen
("map", attrs
, closed
) ->
5737 let r, l = map_of attrs
in
5738 let kss = fromstring keys_of_string spos
"in" r [] in
5739 let lss = fromstring keys_of_string spos
"out" l [] in
5743 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5744 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5747 then { v with f = pkeymap
ret keymap }
5750 { v with f = skip
"map" f }
5753 error
"unexpected subelement in keymap" s spos
5755 | Vclose
"keymap" ->
5756 { v with f = ret keymap }
5758 | Vclose
_ -> error
"unexpected close in keymap" s spos
5760 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5762 | Vdata
| Vcdata
-> v
5763 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5764 | Vopen
("item", attrs
, closed
) ->
5765 let titleent, spage
, srely
= bookmark_of attrs
in
5766 let page = fromstring int_of_string spos
"page" spage
0
5767 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5768 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5770 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5773 { v with f = skip
"item" f }
5776 error
"unexpected subelement in bookmarks" s spos
5778 | Vclose
"bookmarks" ->
5779 { v with f = doc
path pan
anchor c bookmarks }
5781 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5783 and skip tag
f v t spos
_ =
5785 | Vdata
| Vcdata
-> v
5787 error
("unexpected end of input in skipped " ^ tag
) s spos
5788 | Vopen
(tag'
, _, closed
) ->
5792 let f'
() = { v with f = skip tag
f } in
5793 { v with f = skip tag'
f'
}
5797 else error
("unexpected close in skipped " ^ tag
) s spos
5800 parse
{ f = toplevel; accu = () } s;
5806 let len = in_channel_length ic
in
5807 let s = String.create
len in
5808 really_input ic
s 0 len;
5811 | Parse_error
(msg
, s, pos
) ->
5812 let subs = subs s pos
in
5813 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5814 failwith
("parse error: " ^
s)
5817 failwith
("config load error: " ^
Printexc.to_string exn
)
5823 let dir = Filename.concat
home ".config" in
5824 if Sys.is_directory
dir then dir else home
5827 Filename.concat
dir "llpp.conf"
5830 let confpath = ref defconfpath;;
5833 if Sys.file_exists
!confpath
5836 (try Some
(open_in_bin
!confpath)
5839 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5840 Printexc.to_string exn
);
5849 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5850 Printexc.to_string exn
);
5856 f (Hashtbl.create
0, defconf)
5861 let pc, pb
, px, pa
=
5863 Hashtbl.find h (Filename.basename
state.path)
5864 with Not_found
-> dc, [], 0, (0, 0.0)
5868 state.bookmarks <- pb
;
5870 state.scrollw
<- conf.scrollbw
;
5872 then state.anchor <- pa
;
5873 cbput state.hists
.nav pa
;
5878 let add_attrs bb always
dc c =
5881 then Printf.bprintf bb
"\n %s='%b'" s a
5884 then Printf.bprintf bb
"\n %s='%d'" s a
5887 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5890 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5893 then Printf.bprintf bb
"\n %s='%f'" s a
5897 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5901 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5905 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5909 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5915 | Some
(_N
, _A
, _B
) ->
5916 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5926 else string_of_float
f
5928 Printf.bprintf bb
"\n %s='%s'" s v
5933 | Some
((n, a, b), _) when n > 1 ->
5934 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5940 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5945 then dc.winw, dc.winh
5947 match state.fullscreen
with
5949 | None
-> c.winw, c.winh
5951 let zoom, presentation, interpagespace, maxwait
=
5953 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5955 match state.mode with
5956 | Birdseye
(bc
, _, _, _, _) ->
5957 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5958 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5960 oi
"width" w dc.winw;
5961 oi
"height" h dc.winh
;
5962 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5963 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5964 ob "case-insensitive-search" c.icase
dc.icase
;
5965 ob "preload" c.preload dc.preload;
5966 oi
"page-bias" c.pagebias
dc.pagebias
;
5967 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5968 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5969 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5970 ob "crop-hack" c.crophack
dc.crophack
;
5971 oW
"throttle" maxwait
dc.maxwait
;
5972 ob "highlight-links" c.hlinks
dc.hlinks
;
5973 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5974 oi
"vertical-margin" interpagespace dc.interpagespace;
5975 oz
"zoom" zoom dc.zoom;
5976 ob "presentation" presentation dc.presentation;
5977 oi
"rotation-angle" c.angle
dc.angle
;
5978 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5979 ob "proportional-display" c.proportional
dc.proportional
;
5980 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5981 oi
"tex-count" c.texcount
dc.texcount
;
5982 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5983 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5984 ob "persistent-location" c.jumpback
dc.jumpback
;
5985 oc
"background-color" c.bgcolor
dc.bgcolor
;
5986 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5987 oi
"tile-width" c.tilew
dc.tilew
;
5988 oi
"tile-height" c.tileh
dc.tileh
;
5989 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5990 ob "checkers" c.checkers
dc.checkers
;
5991 oi
"aalevel" c.aalevel
dc.aalevel
;
5992 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5993 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5994 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5995 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
5996 oC
"color-space" c.colorspace
dc.colorspace
;
5997 ob "invert-colors" c.invert
dc.invert
;
5998 oF
"brightness" c.colorscale
dc.colorscale
;
5999 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6000 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6001 oco
"columns" c.columns
dc.columns
;
6002 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6003 os
"selection-command" c.selcmd
dc.selcmd
;
6004 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6007 let keymapsbuf always
dc c =
6008 let bb = Buffer.create
16 in
6009 let rec loop = function
6011 | (modename, h) :: rest
->
6012 let dh = findkeyhash dc modename in
6013 if always
|| h <> dh
6015 if Hashtbl.length
h > 0
6017 if Buffer.length
bb > 0
6018 then Buffer.add_char
bb '
\n'
;
6019 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6020 Hashtbl.iter
(fun i
o ->
6021 let isdifferent = always
||
6023 let dO = Hashtbl.find dh i
in
6025 with Not_found
-> true
6030 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6031 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6032 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6033 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6034 Buffer.add_string
bb (Wsi.keyname
k);
6037 let rec loop = function
6039 | km
:: [] -> addkm km
6040 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6044 Buffer.add_string
bb "<map in='";
6048 Buffer.add_char
bb '
\''
;
6049 Buffer.add_string
bb " out='";
6051 Buffer.add_string
bb "'/>\n"
6054 Buffer.add_char
bb '
\''
;
6055 Buffer.add_string
bb " out='";
6057 Buffer.add_string
bb "'/>\n"
6059 | KMmulti
(ins, kms
) ->
6060 Buffer.add_char
bb ' '
;
6062 Buffer.add_char
bb '
\''
;
6063 Buffer.add_string
bb " out='";
6065 Buffer.add_string
bb "'/>\n"
6067 Buffer.add_string
bb "</keymap>";
6077 let uifontsize = fstate.fontsize
in
6078 let bb = Buffer.create
32768 in
6080 let dc = if conf.bedefault
then conf else dc in
6081 Buffer.add_string
bb "<llppconfig>\n";
6083 if String.length
!fontpath > 0
6085 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6091 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6094 Buffer.add_string
bb "<defaults ";
6095 add_attrs bb true dc dc;
6096 let kb = keymapsbuf true dc dc in
6097 if Buffer.length
kb > 0
6099 Buffer.add_string
bb ">\n";
6100 Buffer.add_buffer
bb kb;
6101 Buffer.add_string
bb "\n</defaults>\n";
6103 else Buffer.add_string
bb "/>\n";
6105 let adddoc path pan
anchor c bookmarks =
6106 if bookmarks == [] && c = dc && anchor = emptyanchor
6109 Printf.bprintf
bb "<doc path='%s'"
6110 (enent
path 0 (String.length
path));
6112 if anchor <> emptyanchor
6114 let n, y = anchor in
6115 Printf.bprintf
bb " page='%d'" n;
6118 Printf.bprintf
bb " rely='%f'" y
6123 then Printf.bprintf
bb " pan='%d'" pan
;
6125 add_attrs bb false dc c;
6126 let kb = keymapsbuf false dc c in
6128 begin match bookmarks with
6130 if Buffer.length
kb > 0
6132 Buffer.add_string
bb ">\n";
6133 Buffer.add_buffer
bb kb;
6134 Buffer.add_string
bb "</doc>\n";
6136 else Buffer.add_string
bb "/>\n"
6138 Buffer.add_string
bb ">\n<bookmarks>\n";
6139 List.iter
(fun (title, _level
, (page, rely)) ->
6141 "<item title='%s' page='%d'"
6142 (enent
title 0 (String.length
title))
6147 Printf.bprintf
bb " rely='%f'" rely
6149 Buffer.add_string
bb "/>\n";
6151 Buffer.add_string
bb "</bookmarks>";
6152 if Buffer.length
kb > 0
6154 Buffer.add_string
bb "\n";
6155 Buffer.add_buffer
bb kb;
6157 Buffer.add_string
bb "\n</doc>\n";
6163 match state.mode with
6164 | Birdseye
(c, pan, _, _, _) ->
6166 match conf.columns
with
6167 | Some
((c, _, _), _) -> Some
c
6170 match c.columns
with
6171 | Some
(c, _) -> Some
(c, [||])
6174 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6175 | _ -> state.x, conf
6177 let basename = Filename.basename state.path in
6178 adddoc basename pan (getanchor ())
6181 match state.autoscroll
with
6183 | None
-> conf.autoscrollstep
}
6184 (if conf.savebmarks
then state.bookmarks else []);
6186 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6188 then adddoc path x y c bookmarks
6190 Buffer.add_string
bb "</llppconfig>";
6193 if Buffer.length
bb > 0
6196 let tmp = !confpath ^
".tmp" in
6197 let oc = open_out_bin
tmp in
6198 Buffer.output_buffer
oc bb;
6200 Unix.rename
tmp !confpath;
6203 ("error while saving configuration: " ^
Printexc.to_string exn
)
6210 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6211 "<password> Set password");
6213 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6214 "<path> Set path to the user interface font");
6216 ("-c", Arg.String
(fun s -> Config.confpath := s),
6217 "<path> Set path to the configuration file");
6219 ("-v", Arg.Unit
(fun () ->
6221 "%s\nconfiguration path: %s\n"
6225 exit
0), " Print version and exit");
6228 (fun s -> state.path <- s)
6229 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6231 if String.length
state.path = 0
6232 then (prerr_endline
"file name missing"; exit
1);
6236 let globalkeyhash = findkeyhash conf "global" in
6237 state.wsfd
<- Wsi.init
(object
6238 method display = display ()
6239 method reshape w h = reshape w h
6240 method mouse b d x y m = mouse b d x y m
6241 method motion x y = state.mpos
<- (x, y); motion x y
6242 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6244 match state.keystate
with
6249 try Hashtbl.find globalkeyhash km
6251 let modehash = state.uioh#
modehash in
6252 try Hashtbl.find modehash km
6253 with Not_found
-> KMinsrt
(k, m)
6255 | KMinsrt
(k, m) -> keyboard k m
6256 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6257 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6259 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land m = m'
->
6260 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6261 state.keystate
<- KSnone
6262 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land m = m'
->
6263 state.keystate
<- KSinto
(keys
, insrt
)
6265 state.keystate
<- KSnone
6267 method enter
x y = state.mpos
<- (x, y); pmotion x y
6268 method leave = state.mpos
<- (-1, -1)
6269 end) conf.winw conf.winh
;
6272 List.exists
GlMisc.check_extension
6273 [ "GL_ARB_texture_rectangle"
6274 ; "GL_EXT_texture_recangle"
6275 ; "GL_NV_texture_rectangle" ]
6277 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6279 let cr, sw = Unix.pipe
()
6280 and sr
, cw
= Unix.pipe
() in
6287 setcheckers conf.checkers
;
6291 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6292 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6297 state.text <- "Opening " ^
state.path;
6298 setaalevel
conf.aalevel
;
6299 writeopen state.path state.password
;
6301 setfontsize fstate.fontsize
;
6302 doreshape conf.winw conf.winh
;
6304 let rec loop deadline
=
6306 match state.errfd
with
6307 | None
-> [state.sr
; state.wsfd
]
6308 | Some fd
-> [state.sr
; state.wsfd
; fd
]
6312 state.redisplay
<- false;
6319 if deadline
= infinity
6321 else max
0.0 (deadline
-. now)
6326 try Unix.select
r [] [] timeout
6327 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6333 if state.ghyll
== noghyll
6335 match state.autoscroll
with
6336 | Some step
when step
!= 0 ->
6337 let y = state.y + step
in
6341 else if y >= state.maxy then 0 else y
6344 if state.mode = View
6345 then state.text <- "";
6348 else deadline
+. 0.01
6353 let rec checkfds = function
6355 | fd
:: rest
when fd
= state.sr
->
6356 let cmd = readcmd state.sr
in
6360 | fd
:: rest
when fd
= state.wsfd
->
6365 let s = String.create
80 in
6366 let n = Unix.read fd
s 0 80 in
6367 if conf.redirectstderr
6369 Buffer.add_substring
state.errmsgs
s 0 n;
6370 state.newerrmsgs
<- true;
6371 state.redisplay
<- true;
6374 prerr_string
(String.sub
s 0 n);
6382 if deadline
= infinity
6386 match state.autoscroll
with
6387 | Some step
when step
!= 0 -> deadline1
6388 | _ -> if state.ghyll
== noghyll then infinity
else deadline1