6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
45 | Lfound
of (int * int * int * int * int)
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: string -> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
87 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
88 external platform
: unit -> platform
= "ml_platform";;
89 external setaalevel
: int -> unit = "ml_setaalevel";;
90 external realloctexts
: int -> bool = "ml_realloctexts";;
91 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
92 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
93 external getlink
: opaque
-> int -> under
= "ml_getlink";;
94 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
96 let platform_to_string = function
97 | Punknown
-> "unknown"
101 | Pfreebsd
-> "FreeBSD"
102 | Pdragonflybsd
-> "DragonflyBSD"
103 | Popenbsd
-> "OpenBSD"
104 | Pnetbsd
-> "NetBSD"
105 | Pcygwin
-> "Cygwin"
108 let platform = platform ();;
114 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
117 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
119 type mpos
= int * int
121 | Msel
of (mpos
* mpos
)
123 | Mscrolly
| Mscrollx
124 | Mzoom
of (int * int)
125 | Mzoomrect
of (mpos
* mpos
)
129 type textentry
= string * string * onhist
option * onkey
* ondone
130 and onkey
= string -> int -> te
131 and ondone
= string -> unit
132 and histcancel
= unit -> unit
133 and onhist
= ((histcmd
-> string) * histcancel
)
134 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
139 | TEswitch
of textentry
150 let bound v minv maxv
=
151 max minv
(min maxv v
);
155 { store
= Array.create n v
162 let drawstring size x y s
=
164 Gl.enable `texture_2d
;
165 ignore
(drawstr size x y s
);
167 Gl.disable `texture_2d
;
170 let drawstring1 size x y s
=
174 let drawstring2 size x y fmt
=
175 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
178 let cbcap b
= Array.length b
.store
;;
183 b
.wc
<- (b
.wc
+ 1) mod cap;
185 b
.len
<- min
(b
.len
+ 1) cap;
188 let cbempty b
= b
.len
= 0;;
190 let cbgetg b circular dir
=
194 let rc = b
.rc + dir
in
206 else max
0 (min
rc (b
.len
-1))
212 let cbget b
= cbgetg b
false;;
213 let cbgetc b
= cbgetg b
true;;
230 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
231 dolog " WxH %dx%d" l
.pagew l
.pageh
;
232 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
233 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
234 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
238 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
240 dolog " x0,y0=(% f, % f)" x0 y0
;
241 dolog " x1,y1=(% f, % f)" x1 y1
;
242 dolog " x2,y2=(% f, % f)" x2 y2
;
243 dolog " x3,y3=(% f, % f)" x3 y3
;
248 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
249 and multicol
= columncount
* covercount
* covercount
251 and columncount
= int
252 and covercount
= int;;
255 { mutable scrollbw
: int
256 ; mutable scrollh
: int
257 ; mutable icase
: bool
258 ; mutable preload
: bool
259 ; mutable pagebias
: int
260 ; mutable verbose
: bool
261 ; mutable debug
: bool
262 ; mutable scrollstep
: int
263 ; mutable maxhfit
: bool
264 ; mutable crophack
: bool
265 ; mutable autoscrollstep
: int
266 ; mutable maxwait
: float option
267 ; mutable hlinks
: bool
268 ; mutable underinfo
: bool
269 ; mutable interpagespace
: interpagespace
270 ; mutable zoom
: float
271 ; mutable presentation
: bool
272 ; mutable angle
: angle
275 ; mutable savebmarks
: bool
276 ; mutable proportional
: proportional
277 ; mutable trimmargins
: trimmargins
278 ; mutable trimfuzz
: irect
279 ; mutable memlimit
: memsize
280 ; mutable texcount
: texcount
281 ; mutable sliceheight
: sliceheight
282 ; mutable thumbw
: width
283 ; mutable jumpback
: bool
284 ; mutable bgcolor
: float * float * float
285 ; mutable bedefault
: bool
286 ; mutable scrollbarinpm
: bool
287 ; mutable tilew
: int
288 ; mutable tileh
: int
289 ; mutable mustoresize
: memsize
290 ; mutable checkers
: bool
291 ; mutable aalevel
: int
292 ; mutable urilauncher
: string
293 ; mutable pathlauncher
: string
294 ; mutable colorspace
: colorspace
295 ; mutable invert
: bool
296 ; mutable colorscale
: float
297 ; mutable redirectstderr
: bool
298 ; mutable ghyllscroll
: (int * int * int) option
299 ; mutable columns
: columns
option
300 ; mutable beyecolumns
: columncount
option
301 ; mutable selcmd
: string
302 ; mutable updatecurs
: bool
303 ; mutable keyhashes
: (string * keyhash
) list
307 type anchor
= pageno
* top
;;
309 type outline
= string * int * anchor
;;
311 type rect
= float * float * float * float * float * float * float * float;;
313 type tile
= opaque
* pixmapsize
* elapsed
314 and elapsed
= float;;
315 type pagemapkey
= pageno
* gen
;;
316 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
320 let emptyanchor = (0, 0.0);;
322 type infochange
= | Memused
| Docinfo
| Pdim
;;
324 class type uioh
= object
325 method display
: unit
326 method key
: int -> int -> uioh
327 method button
: int -> bool -> int -> int -> int -> uioh
328 method motion
: int -> int -> uioh
329 method pmotion
: int -> int -> uioh
330 method infochanged
: infochange
-> unit
331 method scrollpw
: (int * float * float)
332 method scrollph
: (int * float * float)
333 method modehash
: keyhash
337 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
338 | Textentry
of (textentry
* onleave
)
340 | LinkNav
of linktarget
341 and onleave
= leavetextentrystatus
-> unit
342 and leavetextentrystatus
= | Cancel
| Confirm
343 and helpitem
= string * int * action
346 | Action
of (uioh
-> uioh
)
348 | Ltexact
of ((pageno
* int) * (int * int * int * int))
352 let isbirdseye = function Birdseye _
-> true | _
-> false;;
353 let istextentry = function Textentry _
-> true | _
-> false;;
357 | Loading
of (page
* gen
)
359 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
361 | Outlining
of outline list
364 let emptykeyhash = Hashtbl.create
0;;
365 let nouioh : uioh
= object (self
)
367 method key _ _
= self
368 method button _ _ _ _ _
= self
369 method motion _ _
= self
370 method pmotion _ _
= self
371 method infochanged _
= ()
372 method scrollpw
= (0, nan
, nan
)
373 method scrollph
= (0, nan
, nan
)
374 method modehash
= emptykeyhash
378 { mutable sr
: Unix.file_descr
379 ; mutable sw
: Unix.file_descr
380 ; mutable wsfd
: Unix.file_descr
381 ; mutable errfd
: Unix.file_descr
option
382 ; mutable stderr
: Unix.file_descr
383 ; mutable errmsgs
: Buffer.t
384 ; mutable newerrmsgs
: bool
388 ; mutable scrollw
: int
389 ; mutable hscrollh
: int
390 ; mutable anchor
: anchor
391 ; mutable ranchors
: (string * string * anchor
) list
393 ; mutable layout
: page list
394 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
395 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
396 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
397 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
398 ; mutable pagecount
: int
399 ; mutable currently
: currently
400 ; mutable mstate
: mstate
401 ; mutable searchpattern
: string
402 ; mutable rects
: (pageno
* recttype
* rect
) list
403 ; mutable rects1
: (pageno
* recttype
* rect
) list
404 ; mutable text
: string
405 ; mutable fullscreen
: (width
* height
) option
406 ; mutable mode
: mode
407 ; mutable uioh
: uioh
408 ; mutable outlines
: outline array
409 ; mutable bookmarks
: outline list
410 ; mutable path
: string
411 ; mutable password
: string
412 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
413 ; mutable memused
: memsize
415 ; mutable throttle
: (page list
* int * float) option
416 ; mutable autoscroll
: int option
417 ; mutable ghyll
: (int option -> unit)
418 ; mutable help
: helpitem array
419 ; mutable docinfo
: (int * string) list
420 ; mutable texid
: GlTex.texture_id
option
422 ; mutable prevzoom
: float
423 ; mutable progress
: float
424 ; mutable redisplay
: bool
425 ; mutable mpos
: mpos
426 ; mutable keystate
: keystate
429 { pat
: string circbuf
430 ; pag
: string circbuf
431 ; nav
: anchor circbuf
432 ; sel
: string circbuf
453 ; presentation
= false
458 ; proportional
= true
459 ; trimmargins
= false
460 ; trimfuzz
= (0,0,0,0)
461 ; memlimit
= 32 lsl 20
466 ; bgcolor
= (0.5, 0.5, 0.5)
468 ; scrollbarinpm
= true
471 ; mustoresize
= 128 lsl 20
476 | Plinux
| Pfreebsd
| Pdragonflybsd
477 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
478 | Posx
-> "open \"%s\""
479 | Pcygwin
-> "cygstart %s"
480 | Punknown
-> "echo %s")
481 ; pathlauncher
= "lp \"%s\""
484 | Plinux
| Pfreebsd
| Pdragonflybsd
485 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
492 ; redirectstderr
= false
498 let mk n
= (n
, Hashtbl.create
1) in
511 let findkeyhash c name
=
512 try List.assoc name c
.keyhashes
513 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
516 let conf = { defconf with angle
= defconf.angle
};;
519 { mutable fontsize
: int
520 ; mutable wwidth
: float
521 ; mutable maxrows
: int
533 fstate.fontsize
<- n
;
534 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
535 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
539 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
540 let len = String.length s
in
541 if colonpos >= 0 && colonpos + 3 < len
543 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
546 try String.rindex_from s
colonpos ' '
550 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
553 | "http" | "ftp" | "mailto" ->
555 try String.index_from s
colonpos ' '
556 with Not_found
-> len
558 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
566 let shell, farg
= "/bin/sh", "-c" in
568 let args = [|shell; farg
; s
|] in
569 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
573 if String.length
conf.urilauncher
= 0
574 then print_endline uri
576 let url = geturl uri
in
577 if String.length
url = 0
578 then print_endline uri
580 let re = Str.regexp
"%s" in
581 let command = Str.global_replace
re url conf.urilauncher
in
585 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
591 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
592 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
596 let strings = version () :: "" :: Help.keys
in
599 let url = geturl s
in
600 if String.length
url > 0
601 then (s
, 0, Action
(fun u
-> gotouri url; u
))
602 else (s
, 0, Noaction
)
607 let firstgeomcmds = "", [];;
614 ; stderr
= Unix.stderr
615 ; errmsgs
= Buffer.create
0
622 ; anchor
= emptyanchor
626 ; tilelru
= Queue.create
()
627 ; pagemap
= Hashtbl.create
10
628 ; tilemap
= Hashtbl.create
10
643 ; geomcmds
= firstgeomcmds
645 { nav
= cbnew 10 (0, 0.0)
670 Printf.kprintf prerr_endline fmt
672 Printf.kprintf ignore fmt
676 if String.length
conf.pathlauncher
= 0
677 then print_endline
state.path
679 let re = Str.regexp
"%s" in
680 let command = Str.global_replace
re state.path
conf.pathlauncher
in
684 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
689 let redirectstderr () =
690 if conf.redirectstderr
692 let rfd, wfd
= Unix.pipe
() in
693 state.stderr
<- Unix.dup
Unix.stderr
;
694 state.errfd
<- Some
rfd;
695 Unix.dup2 wfd
Unix.stderr
;
697 state.newerrmsgs
<- false;
698 begin match state.errfd
with
701 Unix.dup2
state.stderr
Unix.stderr
;
705 prerr_string
(Buffer.contents
state.errmsgs
);
707 Buffer.clear
state.errmsgs
;
713 let postRedisplay who
=
715 then prerr_endline
("redisplay for " ^ who
);
716 state.redisplay
<- true;
720 let getopaque pageno
=
721 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
722 with Not_found
-> None
725 let putopaque pageno opaque
=
726 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
729 let pagetranslatepoint l x y
=
730 let dy = y
- l
.pagedispy
in
731 let y = dy + l
.pagey
in
732 let dx = x
- l
.pagedispx
in
733 let x = dx + l
.pagex
in
740 begin match getopaque l
.pageno
with
742 let x0 = l
.pagedispx
in
743 let x1 = x0 + l
.pagevw
in
744 let y0 = l
.pagedispy
in
745 let y1 = y0 + l
.pagevh
in
746 if y >= y0 && y <= y1 && x >= x0 && x <= x1
748 let px, py
= pagetranslatepoint l
x y in
749 match whatsunder opaque
px py
with
762 state.text
<- Printf.sprintf
"%c%s" c s
;
763 G.postRedisplay "showtext";
766 let updateunder x y =
767 match getunder x y with
768 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
770 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
771 Wsi.setcursor
Wsi.CURSOR_INFO
772 | Ulinkgoto
(page
, _
) ->
774 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
775 Wsi.setcursor
Wsi.CURSOR_INFO
777 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
778 Wsi.setcursor
Wsi.CURSOR_TEXT
780 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
781 Wsi.setcursor
Wsi.CURSOR_INHERIT
783 if conf.underinfo
then showtext 'l'
("launch: " ^ s
);
784 Wsi.setcursor
Wsi.CURSOR_INHERIT
786 if conf.underinfo
then showtext 'n'
("named: " ^ s
);
787 Wsi.setcursor
Wsi.CURSOR_INHERIT
788 | Uremote
(filename
, pageno
) ->
789 if conf.underinfo
then showtext 'r'
790 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
791 Wsi.setcursor
Wsi.CURSOR_INFO
795 let b = Buffer.create
(String.length s
+ 1) in
796 Buffer.add_string
b s
;
801 let colorspace_of_string s
=
802 match String.lowercase s
with
806 | _
-> failwith
"invalid colorspace"
809 let int_of_colorspace = function
815 let colorspace_of_int = function
819 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
822 let colorspace_to_string = function
828 let intentry_with_suffix text key
=
830 if key
>= 32 && key
< 127
834 match Char.lowercase
c with
836 let text = addchar text c in
840 let text = addchar text c in
844 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
848 let columns_to_string (n
, a
, b) =
850 then Printf.sprintf
"%d" n
851 else Printf.sprintf
"%d,%d,%d" n a
b;
854 let columns_of_string s
=
856 (int_of_string s
, 0, 0)
858 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
863 let n = Unix.read fd
s 0 4 in
864 if n != 4 then failwith
"incomplete read(len)";
866 lor (Char.code
s.[0] lsl 24)
867 lor (Char.code
s.[1] lsl 16)
868 lor (Char.code
s.[2] lsl 8)
869 lor (Char.code
s.[3] lsl 0)
871 let s = String.create
len in
872 let n = Unix.read fd
s 0 len in
873 if n != len then failwith
"incomplete read(data)";
877 let btod b = if b then 1 else 0;;
880 let b = Buffer.create
16 in
881 Buffer.add_string
b "llll";
884 let s = Buffer.contents
b in
885 let n = String.length
s in
887 (* dolog "wcmd %S" (String.sub s 4 len); *)
888 s.[0] <- Char.chr
((len lsr 24) land 0xff);
889 s.[1] <- Char.chr
((len lsr 16) land 0xff);
890 s.[2] <- Char.chr
((len lsr 8) land 0xff);
891 s.[3] <- Char.chr
(len land 0xff);
892 let n'
= Unix.write
state.sw
s 0 n in
893 if n'
!= n then failwith
"write failed";
900 let d = conf.winh
- h
in
907 let rec f pn ph pi fh l
=
909 | (n, _
, h
, _
) :: rest
->
910 let ips = calcips h
in
915 if isbirdseye state.mode
&& pn
= 0
920 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
925 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
929 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
932 let fh = f 0 0 0 0 state.pdims
in
937 match conf.columns
with
938 | None
-> calcheight ()
940 if Array.length
b > 0
942 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
947 let getpageyh pageno
=
948 let rec f pn ph pi
y l
=
950 | (n, _
, h
, _
) :: rest
->
951 let ips = calcips h
in
954 let h = if n = pageno
then h else ph
in
955 if conf.presentation
&& n = pageno
957 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
959 y + (pageno
- pn
) * (ph
+ pi
), h
961 let y = y + (if conf.presentation
then pi
else 0) in
962 let y = y + (n - pn
) * (ph
+ pi
) in
966 y + (pageno
- pn
) * (ph
+ pi
), ph
968 f 0 0 0 0 state.pdims
971 let getpageyh pageno
=
972 match conf.columns
with
973 | None
-> getpageyh pageno
975 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
979 let getpagedim pageno
=
982 | (n, _
, _
, _
) as pdim
:: rest
->
984 then (if n = pageno
then pdim
else ppdim
)
989 f (-1, -1, -1, -1) state.pdims
992 let getpagey pageno
= fst
(getpageyh pageno
);;
994 let nogeomcmds cmds
=
996 | s, [] -> String.length
s = 0
1001 let sh = sh - state.hscrollh
in
1002 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1003 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1005 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1006 let ips = calcips h in
1008 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1012 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1014 prev
, pdims
, pdimno
, 0
1016 let dy = dy + yinc in
1017 let py = py + yinc in
1018 if pageno
= state.pagecount
|| dy >= sh
1023 if py + h <= vy - yinc
1025 let py = py + h + ips in
1026 let dy = max
0 (py - y) in
1027 f ~pageno
:(pageno
+1)
1035 let pagey = vy - py in
1036 let pagevh = h - pagey in
1037 let pagevh = min
(sh - dy) pagevh in
1038 let off = if yinc > 0 then py - vy else 0 in
1039 let py = py + h + ips in
1042 if state.w
< conf.winw
- state.scrollw
1043 then (conf.winw
- state.scrollw
- state.w
) / 2
1046 let dispx = xoff + state.x in
1052 let lw = w
- pagex in
1053 min
lw (conf.winw
- state.scrollw
)
1057 ; pagedimno
= pdimno
1061 ; pagey = pagey + off
1063 ; pagevh = pagevh - off
1065 ; pagedispy
= dy + off
1068 let accu = e :: accu in
1069 f ~pageno
:(pageno
+1)
1077 if nogeomcmds state.geomcmds
1095 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1096 let sh = sh - state.hscrollh
in
1097 let rec fold accu n =
1098 if n = Array.length
b
1101 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1104 || n = state.pagecount
- coverB
1105 || (n - coverA
) mod columns
= columns
- 1)
1111 let pagey = max
0 (y - vy) in
1112 let pagedispy = if pagey > 0 then 0 else vy - y in
1113 let pagedispx, pagex, pagevw =
1115 if n = coverA
- 1 || n = state.pagecount
- coverB
1116 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1117 else dx + xoff + state.x
1120 then 0, -pdx, w
+ pdx
1121 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1123 let pagevh = min
(h - pagey) (sh - pagedispy) in
1124 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1128 ; pagedimno
= pdimno
1135 ; pagedispx = pagedispx
1136 ; pagedispy = pagedispy
1147 if nogeomcmds state.geomcmds
1148 then List.rev
(fold [] 0)
1153 match conf.columns
with
1154 | None
-> layout1 y sh
1155 | Some
c -> layoutN c y sh
1159 let y = state.y + incr
in
1161 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1166 let tilex = l
.pagex mod conf.tilew
in
1167 let tiley = l
.pagey mod conf.tileh
in
1169 let col = l
.pagex / conf.tilew
in
1170 let row = l
.pagey / conf.tileh
in
1173 let a = l
.pagew
- l
.pagex in
1174 let b = conf.winw
- state.scrollw
in
1176 and vh
= l
.pagevh in
1178 let rec rowloop row y0 dispy
h =
1182 let dh = conf.tileh
- y0 in
1183 let dh = min
h dh in
1184 let rec colloop col x0 dispx w
=
1188 let dw = conf.tilew
- x0 in
1189 let dw = min w
dw in
1191 f col row dispx dispy
x0 y0 dw dh;
1192 colloop (col+1) 0 (dispx+dw) (w
-dw)
1195 colloop col tilex l
.pagedispx vw;
1196 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1200 then rowloop row tiley l
.pagedispy vh
;
1203 let gettileopaque l
col row =
1205 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1207 try Some
(Hashtbl.find
state.tilemap
key)
1208 with Not_found
-> None
1211 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1212 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1213 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1216 let drawtiles l color
=
1218 let f col row x y tilex tiley w
h =
1219 match gettileopaque l
col row with
1220 | Some
(opaque
, _
, t
) ->
1221 let params = x, y, w
, h, tilex, tiley in
1225 GlFunc.blend_func `zero `one_minus_src_color
;
1227 drawtile
params opaque
;
1229 then Gl.disable `blend
;
1232 let s = Printf.sprintf
1236 let w = measurestr
fstate.fontsize
s in
1237 GlMisc.push_attrib
[`current
];
1238 GlDraw.color
(0.0, 0.0, 0.0);
1240 (float (x-2), float (y-2))
1241 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1242 GlDraw.color
(1.0, 1.0, 1.0);
1243 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1244 GlMisc.pop_attrib
();
1249 let lw = conf.winw
- state.scrollw
- x in
1252 let lh = conf.winh
- y in
1255 Gl.enable `texture_2d
;
1256 begin match state.texid
with
1258 GlTex.bind_texture `texture_2d id
;
1261 and x1 = float (x+w)
1262 and y1 = float (y+h) in
1264 let tw = float w /. 64.0
1265 and th
= float h /. 64.0 in
1266 let tx0 = float tilex /. 64.0
1267 and ty0
= float tiley /. 64.0 in
1269 and ty1
= ty0
+. th
in
1270 GlDraw.begins `quads
;
1271 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1272 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1273 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1274 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1277 Gl.disable `texture_2d
;
1279 GlDraw.color
(1.0, 1.0, 1.0);
1282 (float (x+w), float (y+h));
1284 if w > 128 && h > fstate.fontsize
+ 10
1286 GlDraw.color
(0.0, 0.0, 0.0);
1289 then (col*conf.tilew
, row*conf.tileh
)
1292 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1299 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1301 let tilevisible1 l
x y =
1303 and ax1
= l
.pagex + l
.pagevw
1305 and ay1
= l
.pagey + l
.pagevh in
1309 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1310 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1312 let rx0 = max
ax0 bx0
1313 and ry0
= max ay0 by0
1314 and rx1
= min ax1
bx1
1315 and ry1
= min ay1 by1
in
1317 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1318 nonemptyintersection
1321 let tilevisible layout n x y =
1322 let rec findpageinlayout = function
1323 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1324 | _
:: rest
-> findpageinlayout rest
1327 findpageinlayout layout
1330 let tileready l
x y =
1331 tilevisible1 l
x y &&
1332 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1335 let tilepage n p
layout =
1336 let rec loop = function
1340 let f col row _ _ _ _ _ _
=
1341 if state.currently
= Idle
1343 match gettileopaque l
col row with
1346 let x = col*conf.tilew
1347 and y = row*conf.tileh
in
1349 let w = l
.pagew
- x in
1353 let h = l
.pageh
- y in
1356 wcmd "tile %s %d %d %d %d" p
x y w h;
1359 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1360 conf.tilew
, conf.tileh
1369 if nogeomcmds state.geomcmds
1373 let preloadlayout visiblepages
=
1374 let presentation = conf.presentation in
1375 let interpagespace = conf.interpagespace in
1376 let maxy = state.maxy in
1377 conf.presentation <- false;
1378 conf.interpagespace <- 0;
1379 state.maxy <- calcheight ();
1381 match visiblepages
with
1383 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1385 let y = if y < conf.winh
then 0 else y - conf.winh
in
1386 let h = state.y - y + conf.winh
*3 in
1387 let pages = layout y h in
1388 conf.presentation <- presentation;
1389 conf.interpagespace <- interpagespace;
1395 let rec loop pages =
1396 if state.currently
!= Idle
1401 begin match getopaque l
.pageno
with
1403 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1404 state.currently
<- Loading
(l
, state.gen
);
1406 tilepage l
.pageno opaque
pages;
1411 if nogeomcmds state.geomcmds
1417 if conf.preload && state.currently
= Idle
1418 then load (preloadlayout pages);
1421 let layoutready layout =
1422 let rec fold all ls
=
1423 all
&& match ls
with
1425 let seen = ref false in
1426 let allvisible = ref true in
1427 let foo col row _ _ _ _ _ _
=
1429 allvisible := !allvisible &&
1430 begin match gettileopaque l
col row with
1436 fold (!seen && !allvisible) rest
1439 let alltilesvisible = fold true layout in
1444 let y = bound y 0 state.maxy in
1445 let y, layout, proceed
=
1446 match conf.maxwait
with
1447 | Some time
when state.ghyll
== noghyll ->
1448 begin match state.throttle
with
1450 let layout = layout y conf.winh
in
1451 let ready = layoutready layout in
1455 state.throttle
<- Some
(layout, y, now ());
1457 else G.postRedisplay "gotoy showall (None)";
1459 | Some
(_
, _
, started
) ->
1460 let dt = now () -. started
in
1463 state.throttle
<- None
;
1464 let layout = layout y conf.winh
in
1466 G.postRedisplay "maxwait";
1473 let layout = layout y conf.winh
in
1474 if true || layoutready layout
1475 then G.postRedisplay "gotoy ready";
1481 state.layout <- layout;
1482 begin match state.mode
with
1483 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1484 if not
(pagevisible layout pageno
)
1486 match state.layout with
1489 state.mode
<- Birdseye
(
1490 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1493 | LinkNav
(Ltgendir dir
as lt
) ->
1495 let rec loop = function
1498 match getopaque l
.pageno
with
1504 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1506 if dir
> 0 then LDfirst
else LDlast
1512 | Lnotfound
-> loop rest
1513 | Lfound
(n, x0, y0, x1, y1) ->
1514 Ltexact
((l
.pageno
, n), (x0, y0, x1, y1))
1518 state.mode
<- LinkNav
linknav
1523 state.ghyll
<- noghyll;
1526 let conttiling pageno opaque
=
1527 tilepage pageno opaque
1528 (if conf.preload then preloadlayout state.layout else state.layout)
1531 let gotoy_and_clear_text y =
1533 if not
conf.verbose
then state.text <- "";
1537 match state.layout with
1539 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1542 let getanchory (n, top
) =
1543 let y, h = getpageyh n in
1544 y + (truncate
(top
*. float h));
1547 let gotoanchor anchor
=
1548 gotoy (getanchory anchor
);
1552 cbput state.hists
.nav
(getanchor ());
1556 let anchor = cbgetc state.hists
.nav dir
in
1561 let rec scroll f n a b =
1562 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1564 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1566 then s (float f /. float a)
1569 then 1.0 -. s ((float (f-b) /. float (n-b)))
1576 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1577 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1579 let ins = float a *. iv1
1580 and outs
= float (n-b) *. iv1 in
1582 ins +. outs
+. float ones
1584 let rec set (_N
, _A
, _B
) y sy
=
1585 let sum = summa
1.0 _N _A _B
in
1586 let dy = float (y - sy
) in
1590 then state.ghyll
<- noghyll
1593 let s = scroll n _N _A _B
in
1594 let y1 = y1 +. ((s *. dy) /. sum) in
1595 gotoy_and_clear_text (truncate
y1);
1596 state.ghyll
<- gf (n+1) y1;
1600 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1602 gf 0 (float state.y)
1605 match conf.ghyllscroll
with
1607 gotoy_and_clear_text y
1609 if state.ghyll
== noghyll
1610 then set nab
y state.y
1611 else state.ghyll
(Some
y)
1614 let gotopage n top
=
1615 let y, h = getpageyh n in
1616 let y = y + (truncate
(top
*. float h)) in
1620 let gotopage1 n top
=
1621 let y = getpagey n in
1626 let invalidate s f =
1631 match state.geomcmds
with
1632 | ps
, [] when String.length ps
= 0 ->
1634 state.geomcmds
<- s, [];
1637 state.geomcmds
<- ps
, [s, f];
1639 | ps
, (s'
, _
) :: rest
when s'
= s ->
1640 state.geomcmds
<- ps
, ((s, f) :: rest
);
1643 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1646 let opendoc path password
=
1648 state.password
<- password
;
1649 state.gen
<- state.gen
+ 1;
1650 state.docinfo
<- [];
1652 setaalevel
conf.aalevel
;
1653 Wsi.settitle
("llpp " ^
Filename.basename path
);
1654 wcmd "open %s\000%s\000" path password
;
1655 invalidate "reqlayout"
1657 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1661 let c = c *. conf.colorscale
in
1665 let scalecolor2 (r
, g
, b) =
1666 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1670 let docolumns = function
1672 | Some
((columns
, coverA
, coverB
), _
) ->
1673 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1674 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1675 if pageno
= state.pagecount
1678 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1680 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1681 pdimno+1, pdim
, rest
1686 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1688 (conf.winw
- state.scrollw
- w) / 2,
1689 y + rowh
+ conf.interpagespace, h
1692 if (pageno
- coverA
) mod columns
= 0
1693 then 0, y + rowh
+ conf.interpagespace, h
1694 else x, y, max rowh
h
1697 let rec fixrow m
= if m
= pageno
then () else
1698 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1701 let y = y + (rowh
- h) / 2 in
1702 a.(m
) <- (pdimno, x, y, pdim
);
1706 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1707 then fixrow (pageno
- columns
);
1708 a.(pageno
) <- (pdimno, x, y, pdim
);
1709 let x = x + w + xoff*2 + conf.interpagespace in
1710 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1712 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1713 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1715 docolumns conf.columns
;
1716 state.maxy <- calcheight ();
1718 if state.w <= conf.winw
- state.scrollw
1722 match state.mode
with
1723 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1724 let y, h = getpageyh pageno
in
1725 let top = (conf.winh
- h) / 2 in
1726 gotoy (max
0 (y - top))
1727 | _
-> gotoanchor state.anchor
1731 GlDraw.viewport
0 0 w h;
1732 if state.geomcmds
!= firstgeomcmds && nogeomcmds state.geomcmds
1733 then state.anchor <- getanchor ();
1736 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1739 setfontsize fstate.fontsize
;
1740 GlMat.mode `modelview
;
1741 GlMat.load_identity
();
1743 GlMat.mode `projection
;
1744 GlMat.load_identity
();
1745 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1746 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1747 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1749 invalidate "geometry"
1753 match conf.columns
with
1755 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1757 wcmd "geometry %d %d" w h);
1761 let len = String.length
state.text in
1764 match state.mode
with
1765 | View
-> state.hscrollh
1770 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1771 (x+.w, float (conf.winh
- hscrollh))
1774 let w = float (conf.winw
- state.scrollw
- 1) in
1775 if state.progress
>= 0.0 && state.progress
< 1.0
1777 GlDraw.color
(0.3, 0.3, 0.3);
1778 let w1 = w *. state.progress
in
1780 GlDraw.color
(0.0, 0.0, 0.0);
1784 GlDraw.color
(0.0, 0.0, 0.0);
1788 GlDraw.color
(1.0, 1.0, 1.0);
1789 drawstring fstate.fontsize
1790 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1793 match state.mode
with
1794 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1798 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1800 Printf.sprintf
"%s%s_" prefix
text
1809 if not
(istextentry state.mode
)
1811 let s1 = "(press 'e' to review error messasges)" in
1812 if String.length
s > 0 then s ^
" " ^
s1 else s1
1817 if String.length
s > 0
1822 let len = Queue.length
state.tilelru
in
1824 if state.memused
<= conf.memlimit
1829 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1830 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1831 let (_
, pw
, ph
, _
) = getpagedim n in
1834 && colorspace
= conf.colorspace
1835 && angle
= conf.angle
1840 match state.throttle
with
1843 then preloadlayout state.layout
1845 | Some
(layout, _
, _
) ->
1848 let x = col*conf.tilew
1849 and y = row*conf.tileh
in
1850 tilevisible layout n x y
1852 then Queue.push lruitem
state.tilelru
1854 wcmd "freetile %s" p
;
1855 state.memused
<- state.memused
- s;
1856 state.uioh#infochanged Memused
;
1857 Hashtbl.remove
state.tilemap k
;
1866 Queue.iter
(fun (k
, p
, s) ->
1867 wcmd "freetile %s" p
;
1868 state.memused
<- state.memused
- s;
1869 state.uioh#infochanged Memused
;
1870 Hashtbl.remove
state.tilemap k
;
1872 Queue.clear
state.tilelru
;
1876 let logcurrently = function
1877 | Idle
-> dolog "Idle"
1878 | Loading
(l
, gen
) ->
1879 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1880 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1882 "Tiling %d[%d,%d] page=%s cs=%s angle"
1883 l
.pageno
col row pageopaque
1884 (colorspace_to_string colorspace
)
1886 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1887 angle gen
conf.angle
state.gen
1889 conf.tilew
conf.tileh
1896 (* dolog "%S" cmds; *)
1899 try String.index cmds ' '
1900 with Not_found
-> -1
1905 let l = String.length cmds
in
1906 let op = String.sub cmds
0 spacepos in
1908 if l - spacepos < 2 then ""
1909 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1914 state.uioh#infochanged Pdim
;
1918 state.rects
<- state.rects1
;
1919 G.postRedisplay "clearrects";
1923 try Scanf.sscanf
args "%u" (fun n -> n)
1925 dolog "error processing 'continue' %S: %s"
1926 cmds
(Printexc.to_string exn
);
1929 state.pagecount
<- n;
1930 begin match state.currently
with
1932 state.currently
<- Idle
;
1933 state.outlines
<- Array.of_list
(List.rev
l)
1937 let cur, cmds
= state.geomcmds
in
1938 if String.length
cur = 0
1939 then failwith
"umpossible";
1941 begin match List.rev cmds
with
1943 state.geomcmds
<- "", [];
1947 state.geomcmds
<- s, List.rev rest
;
1949 if conf.maxwait
= None
1950 then G.postRedisplay "continue";
1960 then showtext ' '
args
1963 let progress, text =
1965 Scanf.sscanf
args "%f %n"
1967 f, String.sub
args pos
(String.length
args - pos
))
1969 dolog "error processing 'progress' %S: %s"
1970 cmds
(Printexc.to_string exn
);
1974 state.progress <- progress;
1975 G.postRedisplay "progress"
1978 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1980 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1981 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1982 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1984 dolog "error processing 'firstmatch' %S: %s"
1985 cmds
(Printexc.to_string exn
);
1988 let y = (getpagey pageno) + truncate
y0 in
1991 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1994 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1996 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1997 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1998 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2000 dolog "error processing 'match' %S: %s"
2001 cmds
(Printexc.to_string exn
);
2005 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2010 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2012 dolog "error processing 'page' %S: %s"
2013 cmds
(Printexc.to_string exn
);
2016 begin match state.currently
with
2017 | Loading
(l, gen
) ->
2018 vlog "page %d took %f sec" l.pageno t
;
2019 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2020 begin match state.throttle
with
2022 let preloadedpages =
2024 then preloadlayout state.layout
2029 Set.Make
(struct type t
= int let compare = (-) end) in
2031 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2032 IntSet.empty
preloadedpages
2035 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2036 if not
(IntSet.mem
pageno set)
2038 wcmd "freepage %s" opaque
;
2044 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2047 state.currently
<- Idle
;
2050 tilepage l.pageno pageopaque state.layout;
2052 load preloadedpages;
2053 if pagevisible state.layout l.pageno
2054 && layoutready state.layout
2055 then G.postRedisplay "page";
2058 | Some
(layout, _
, _
) ->
2059 state.currently
<- Idle
;
2060 tilepage l.pageno pageopaque layout;
2065 dolog "Inconsistent loading state";
2066 logcurrently state.currently
;
2071 let (x, y, opaque
, size
, t
) =
2073 Scanf.sscanf
args "%u %u %s %u %f"
2074 (fun x y p size t
-> (x, y, p
, size
, t
))
2076 dolog "error processing 'tile' %S: %s"
2077 cmds
(Printexc.to_string exn
);
2080 begin match state.currently
with
2081 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2082 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2084 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2086 wcmd "freetile %s" opaque
;
2087 state.currently
<- Idle
;
2091 puttileopaque l col row gen cs angle opaque size t
;
2092 state.memused
<- state.memused
+ size
;
2093 state.uioh#infochanged Memused
;
2095 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2096 opaque
, size
) state.tilelru
;
2099 match state.throttle
with
2100 | None
-> state.layout
2101 | Some
(layout, _
, _
) -> layout
2104 state.currently
<- Idle
;
2106 && conf.colorspace
= cs
2107 && conf.angle
= angle
2108 && tilevisible layout l.pageno x y
2109 then conttiling l.pageno pageopaque;
2111 begin match state.throttle
with
2113 preload state.layout;
2115 && conf.colorspace
= cs
2116 && conf.angle
= angle
2117 && tilevisible state.layout l.pageno x y
2118 then G.postRedisplay "tile nothrottle";
2120 | Some
(layout, y, _
) ->
2121 let ready = layoutready layout in
2125 state.layout <- layout;
2126 state.throttle
<- None
;
2127 G.postRedisplay "throttle";
2134 dolog "Inconsistent tiling state";
2135 logcurrently state.currently
;
2142 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2144 dolog "error processing 'pdim' %S: %s"
2145 cmds
(Printexc.to_string exn
);
2148 state.uioh#infochanged Pdim
;
2149 state.pdims
<- pdim :: state.pdims
2152 let (l, n, t
, h, pos
) =
2154 Scanf.sscanf
args "%u %u %d %u %n"
2155 (fun l n t
h pos
-> l, n, t
, h, pos
)
2157 dolog "error processing 'o' %S: %s"
2158 cmds
(Printexc.to_string exn
);
2161 let s = String.sub
args pos
(String.length
args - pos
) in
2162 let outline = (s, l, (n, float t
/. float h)) in
2163 begin match state.currently
with
2164 | Outlining outlines
->
2165 state.currently
<- Outlining
(outline :: outlines
)
2167 state.currently
<- Outlining
[outline]
2169 dolog "invalid outlining state";
2170 logcurrently currently
2174 state.docinfo
<- (1, args) :: state.docinfo
2177 state.uioh#infochanged Docinfo
;
2178 state.docinfo
<- List.rev
state.docinfo
2181 dolog "unknown cmd `%S'" cmds
2186 let action = function
2187 | HCprev
-> cbget cb ~
-1
2188 | HCnext
-> cbget cb
1
2189 | HCfirst
-> cbget cb ~
-(cb
.rc)
2190 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2191 and cancel
() = cb
.rc <- rc
2195 let search pattern forward
=
2196 if String.length pattern
> 0
2199 match state.layout with
2202 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2204 wcmd "search %d %d %d %d,%s\000"
2205 (btod conf.icase
) pn py (btod forward
) pattern
;
2208 let intentry text key =
2210 if key >= 32 && key < 127
2216 let text = addchar text c in
2220 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2224 let textentry text key =
2225 if key land 0xff00 = 0xff00
2227 else TEcont
(text ^
Wsi.toutf8
key)
2230 let reqlayout angle proportional
=
2231 match state.throttle
with
2233 if nogeomcmds state.geomcmds
2234 then state.anchor <- getanchor ();
2235 conf.angle
<- angle
mod 360;
2238 match state.mode
with
2239 | LinkNav _
-> state.mode
<- View
2242 conf.proportional
<- proportional
;
2243 invalidate "reqlayout"
2244 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2248 let settrim trimmargins trimfuzz
=
2249 if nogeomcmds state.geomcmds
2250 then state.anchor <- getanchor ();
2251 conf.trimmargins
<- trimmargins
;
2252 conf.trimfuzz
<- trimfuzz
;
2253 let x0, y0, x1, y1 = trimfuzz
in
2254 invalidate "settrim"
2256 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2257 Hashtbl.iter
(fun _ opaque
->
2258 wcmd "freepage %s" opaque
;
2260 Hashtbl.clear
state.pagemap
;
2264 match state.throttle
with
2266 let zoom = max
0.01 zoom in
2267 if zoom <> conf.zoom
2269 state.prevzoom
<- conf.zoom;
2272 then (state.x <- 0; 0.0)
2273 else float state.x /. float state.w
2276 reshape conf.winw
conf.winh
;
2279 let x = relx *. float state.w in
2280 state.x <- truncate
x;
2282 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2285 | Some
(layout, y, started
) ->
2287 match conf.maxwait
with
2291 let dt = now () -. started
in
2299 let setcolumns columns coverA coverB
=
2302 conf.columns
<- None
;
2307 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2310 reshape conf.winw
conf.winh
;
2313 let enterbirdseye () =
2314 let zoom = float conf.thumbw
/. float conf.winw
in
2315 let birdseyepageno =
2316 let cy = conf.winh
/ 2 in
2320 let rec fold best
= function
2323 let d = cy - (l.pagedispy + l.pagevh/2)
2324 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2325 if abs
d < abs dbest
2332 state.mode
<- Birdseye
(
2333 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2336 conf.presentation <- false;
2337 conf.interpagespace <- 10;
2338 conf.hlinks
<- false;
2340 state.mstate
<- Mnone
;
2341 conf.maxwait
<- None
;
2343 match conf.beyecolumns
with
2346 Some
((c, 0, 0), [||])
2349 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2352 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2357 reshape conf.winw
conf.winh
;
2360 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2362 conf.zoom <- c.zoom;
2363 conf.presentation <- c.presentation;
2364 conf.interpagespace <- c.interpagespace;
2365 conf.maxwait
<- c.maxwait
;
2366 conf.hlinks
<- c.hlinks
;
2367 conf.beyecolumns
<- (
2368 match conf.columns
with
2369 | Some
((c, _
, _
), _
) -> Some
c
2373 match c.columns
with
2374 | Some
(c, _
) -> Some
(c, [||])
2380 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2383 reshape conf.winw
conf.winh
;
2384 state.anchor <- if goback
then anchor else (pageno, 0.0);
2387 let togglebirdseye () =
2388 match state.mode
with
2389 | Birdseye vals
-> leavebirdseye vals
true
2390 | View
-> enterbirdseye ()
2394 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2395 let pageno = max
0 (pageno - incr
) in
2396 let rec loop = function
2397 | [] -> gotopage1 pageno 0
2398 | l :: _
when l.pageno = pageno ->
2399 if l.pagedispy >= 0 && l.pagey = 0
2400 then G.postRedisplay "upbirdseye"
2401 else gotopage1 pageno 0
2402 | _
:: rest
-> loop rest
2405 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2408 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2409 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2410 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2411 let rec loop = function
2413 let y, h = getpageyh pageno in
2414 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2416 | l :: _
when l.pageno = pageno ->
2417 if l.pagevh != l.pageh
2418 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2419 else G.postRedisplay "downbirdseye"
2420 | _
:: rest
-> loop rest
2425 let optentry mode _
key =
2426 let btos b = if b then "on" else "off" in
2427 if key >= 32 && key < 127
2429 let c = Char.chr
key in
2433 try conf.scrollstep
<- int_of_string
s with exc
->
2434 state.text <- Printf.sprintf
"bad integer `%s': %s"
2435 s (Printexc.to_string exc
)
2437 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2442 conf.autoscrollstep
<- int_of_string
s;
2443 if state.autoscroll
<> None
2444 then state.autoscroll
<- Some
conf.autoscrollstep
2446 state.text <- Printf.sprintf
"bad integer `%s': %s"
2447 s (Printexc.to_string exc
)
2449 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2454 let n, a, b = columns_of_string s in
2457 state.text <- Printf.sprintf
"bad columns `%s': %s"
2458 s (Printexc.to_string exc
)
2460 TEswitch
("columns: ", "", None
, textentry, ondone)
2465 let zoom = float (int_of_string
s) /. 100.0 in
2468 state.text <- Printf.sprintf
"bad integer `%s': %s"
2469 s (Printexc.to_string exc
)
2471 TEswitch
("zoom: ", "", None
, intentry, ondone)
2476 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2478 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2479 begin match mode
with
2481 leavebirdseye beye
false;
2486 state.text <- Printf.sprintf
"bad integer `%s': %s"
2487 s (Printexc.to_string exc
)
2489 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2494 Some
(int_of_string
s)
2496 state.text <- Printf.sprintf
"bad integer `%s': %s"
2497 s (Printexc.to_string exc
);
2500 | Some angle
-> reqlayout angle
conf.proportional
2503 TEswitch
("rotation: ", "", None
, intentry, ondone)
2506 conf.icase
<- not
conf.icase
;
2507 TEdone
("case insensitive search " ^
(btos conf.icase
))
2510 conf.preload <- not
conf.preload;
2512 TEdone
("preload " ^
(btos conf.preload))
2515 conf.verbose
<- not
conf.verbose
;
2516 TEdone
("verbose " ^
(btos conf.verbose
))
2519 conf.debug
<- not
conf.debug
;
2520 TEdone
("debug " ^
(btos conf.debug
))
2523 conf.maxhfit
<- not
conf.maxhfit
;
2525 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2526 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2529 conf.crophack
<- not
conf.crophack
;
2530 TEdone
("crophack " ^
btos conf.crophack
)
2534 match conf.maxwait
with
2536 conf.maxwait
<- Some infinity
;
2537 "always wait for page to complete"
2539 conf.maxwait
<- None
;
2540 "show placeholder if page is not ready"
2545 conf.underinfo
<- not
conf.underinfo
;
2546 TEdone
("underinfo " ^
btos conf.underinfo
)
2549 conf.savebmarks
<- not
conf.savebmarks
;
2550 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2556 match state.layout with
2561 conf.interpagespace <- int_of_string
s;
2562 state.maxy <- calcheight ();
2563 let y = getpagey pageno in
2566 state.text <- Printf.sprintf
"bad integer `%s': %s"
2567 s (Printexc.to_string exc
)
2569 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2572 reqlayout conf.angle
(not
conf.proportional
);
2573 TEdone
("proportional display " ^
btos conf.proportional
)
2576 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2577 TEdone
("trim margins " ^
btos conf.trimmargins
)
2580 conf.invert
<- not
conf.invert
;
2581 TEdone
("invert colors " ^
btos conf.invert
)
2585 cbput state.hists
.sel
s;
2588 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2592 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2598 class type lvsource
= object
2599 method getitemcount
: int
2600 method getitem
: int -> (string * int)
2601 method hasaction
: int -> bool
2610 method getactive
: int
2611 method getfirst
: int
2612 method getqsearch
: string
2613 method setqsearch
: string -> unit
2617 class virtual lvsourcebase
= object
2618 val mutable m_active
= 0
2619 val mutable m_first
= 0
2620 val mutable m_qsearch
= ""
2621 val mutable m_pan
= 0
2622 method getactive
= m_active
2623 method getfirst
= m_first
2624 method getqsearch
= m_qsearch
2625 method getpan
= m_pan
2626 method setqsearch
s = m_qsearch
<- s
2629 let withoutlastutf8 s =
2630 let len = String.length
s in
2638 let b = Char.code
s.[pos
] in
2639 if b land 0b110000 = 0b11000000
2644 if Char.code
s.[len-1] land 0x80 = 0
2648 String.sub
s 0 first;
2651 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2653 state.mode
<- Textentry
(te
, onleave
);
2656 G.postRedisplay "textentrykeyboard enttext";
2658 let histaction cmd
=
2661 | Some
(action, _
) ->
2662 state.mode
<- Textentry
(
2663 (c, action cmd
, opthist
, onkey
, ondone), onleave
2665 G.postRedisplay "textentry histaction"
2668 | 0xff08 -> (* backspace *)
2669 let s = withoutlastutf8 text in
2670 let len = String.length
s in
2674 G.postRedisplay "textentrykeyboard after cancel";
2677 enttext (c, s, opthist
, onkey
, ondone)
2683 G.postRedisplay "textentrykeyboard after confirm"
2685 | 0xff52 -> histaction HCprev
2686 | 0xff54 -> histaction HCnext
2687 | 0xff50 -> histaction HCfirst
2688 | 0xff57 -> histaction HClast
2690 | 0xff1b -> (* escape*)
2691 if String.length
text = 0
2693 begin match opthist
with
2695 | Some
(_
, onhistcancel
) -> onhistcancel
()
2699 G.postRedisplay "textentrykeyboard after cancel2"
2702 enttext (c, "", opthist
, onkey
, ondone)
2705 | 0xff9f | 0xffff -> () (* delete *)
2707 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2708 begin match onkey
text key with
2712 G.postRedisplay "textentrykeyboard after confirm2";
2715 enttext (c, text, opthist
, onkey
, ondone);
2719 G.postRedisplay "textentrykeyboard after cancel3"
2722 state.mode
<- Textentry
(te
, onleave
);
2723 G.postRedisplay "textentrykeyboard switch";
2727 vlog "unhandled key %s" (Wsi.keyname
key)
2730 let firstof first active
=
2731 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2732 then max
0 (active
- (fstate.maxrows
/2))
2736 let calcfirst first active
=
2739 let rows = active
- first in
2740 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2744 let scrollph y maxy =
2745 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2746 let sh = float conf.winh
/. sh in
2747 let sh = max
sh (float conf.scrollh
) in
2752 else float y /. float maxy
2754 let position = (float conf.winh
-. sh) *. percent in
2757 if position +. sh > float conf.winh
2758 then float conf.winh
-. sh
2764 let coe s = (s :> uioh
);;
2766 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2768 val m_pan
= source#getpan
2769 val m_first
= source#getfirst
2770 val m_active
= source#getactive
2771 val m_qsearch
= source#getqsearch
2772 val m_prev_uioh
= state.uioh
2774 method private elemunder
y =
2775 let n = y / (fstate.fontsize
+1) in
2776 if m_first
+ n < source#getitemcount
2778 if source#hasaction
(m_first
+ n)
2779 then Some
(m_first
+ n)
2786 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2787 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2788 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2789 GlDraw.color
(1., 1., 1.);
2790 Gl.enable `texture_2d
;
2791 let fs = fstate.fontsize
in
2793 let ww = fstate.wwidth
in
2794 let tabw = 30.0*.ww in
2795 let itemcount = source#getitemcount
in
2797 if (row - m_first
) * nfs > conf.winh
2800 if row >= 0 && row < itemcount
2802 let (s, level
) = source#getitem
row in
2803 let y = (row - m_first
) * nfs in
2804 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2807 Gl.disable `texture_2d
;
2808 GlDraw.polygon_mode `both `line
;
2809 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2810 GlDraw.rect (1., float (y + 1))
2811 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2812 GlDraw.polygon_mode `both `fill
;
2813 GlDraw.color
(1., 1., 1.);
2814 Gl.enable `texture_2d
;
2817 let drawtabularstring s =
2818 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2821 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2824 let len = String.length
s - tabpos - 1 in
2825 let s1 = String.sub
s 0 tabpos
2826 and s2
= String.sub
s (tabpos + 1) len in
2827 let nx = drawstr x s1 in
2829 let x = x +. (max
tabw sw) in
2836 let _ = drawtabularstring s in
2843 Gl.disable `texture_2d
;
2845 method updownlevel incr
=
2846 let len = source#getitemcount
in
2848 if m_active
>= 0 && m_active
< len
2849 then snd
(source#getitem m_active
)
2853 if i
= len then i
-1 else if i
= -1 then 0 else
2854 let _, l = source#getitem i
in
2855 if l != curlevel then i
else flow (i
+incr
)
2857 let active = flow m_active
in
2858 let first = calcfirst m_first
active in
2859 G.postRedisplay "outline updownlevel";
2860 {< m_active
= active; m_first
= first >}
2862 method private key1
key mask
=
2863 let set1 active first qsearch
=
2864 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2866 let search active pattern incr
=
2869 if n >= 0 && n < source#getitemcount
2871 let s, _ = source#getitem
n in
2873 (try ignore
(Str.search_forward
re s 0); true
2874 with Not_found
-> false)
2876 else loop (n + incr
)
2883 let re = Str.regexp_case_fold pattern
in
2889 let itemcount = source#getitemcount
in
2890 let find start incr
=
2892 if i
= -1 || i
= itemcount
2895 if source#hasaction i
2897 else find (i
+ incr
)
2902 let set active first =
2903 let first = bound first 0 (itemcount - fstate.maxrows
) in
2905 coe {< m_active
= active; m_first
= first >}
2908 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2910 let incr1 = if incr
> 0 then 1 else -1 in
2911 if isvisible m_first m_active
2914 let next = m_active
+ incr
in
2916 if next < 0 || next >= itemcount
2918 else find next incr1
2920 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2926 let first = m_first
+ incr
in
2927 let first = bound first 0 (itemcount - 1) in
2929 let next = m_active
+ incr
in
2930 let next = bound next 0 (itemcount - 1) in
2933 let active = if next = -1 then m_active
else next in
2936 let first = min
next m_first
in
2938 if abs
(next - first) > fstate.maxrows
2944 let first = m_first
+ incr
in
2945 let first = bound first 0 (itemcount - 1) in
2947 let next = m_active
+ incr
in
2948 let next = bound next 0 (itemcount - 1) in
2949 let next = find next incr1 in
2951 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2953 let active = if m_active
= -1 then next else m_active
in
2958 if isvisible first active
2964 G.postRedisplay "listview navigate";
2968 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2969 let incr = if key = 0x72 then -1 else 1 in
2971 match search (m_active
+ incr) m_qsearch
incr with
2973 state.text <- m_qsearch ^
" [not found]";
2976 state.text <- m_qsearch
;
2977 active, firstof m_first
active
2979 G.postRedisplay "listview ctrl-r/s";
2980 set1 active first m_qsearch
;
2982 | 0xff08 -> (* backspace *)
2983 if String.length m_qsearch
= 0
2986 let qsearch = withoutlastutf8 m_qsearch
in
2987 let len = String.length
qsearch in
2991 G.postRedisplay "listview empty qsearch";
2992 set1 m_active m_first
"";
2996 match search m_active
qsearch ~
-1 with
2998 state.text <- qsearch ^
" [not found]";
3001 state.text <- qsearch;
3002 active, firstof m_first
active
3004 G.postRedisplay "listview backspace qsearch";
3005 set1 active first qsearch
3008 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3009 let pattern = m_qsearch ^
Wsi.toutf8
key in
3011 match search m_active
pattern 1 with
3013 state.text <- pattern ^
" [not found]";
3016 state.text <- pattern;
3017 active, firstof m_first
active
3019 G.postRedisplay "listview qsearch add";
3020 set1 active first pattern;
3022 | 0xff1b -> (* escape *)
3024 if String.length m_qsearch
= 0
3026 G.postRedisplay "list view escape";
3029 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3031 | None
-> m_prev_uioh
3036 G.postRedisplay "list view kill qsearch";
3037 source#setqsearch
"";
3038 coe {< m_qsearch
= "" >}
3041 | 0xff0d -> (* return *)
3043 let self = {< m_qsearch
= "" >} in
3044 source#setqsearch
"";
3046 G.postRedisplay "listview enter";
3047 if m_active
>= 0 && m_active
< source#getitemcount
3049 source#exit
(coe self) false m_active m_first m_pan
"";
3052 source#exit
(coe self) true m_active m_first m_pan
"";
3055 begin match opt with
3056 | None
-> m_prev_uioh
3060 | 0xff9f | 0xffff -> (* delete *)
3063 | 0xff52 -> navigate ~
-1 (* up *)
3064 | 0xff54 -> navigate 1 (* down *)
3065 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3066 | 0xff56 -> navigate fstate.maxrows
(* next *)
3068 | 0xff53 -> (* right *)
3070 G.postRedisplay "listview right";
3071 coe {< m_pan
= m_pan
- 1 >}
3073 | 0xff51 -> (* left *)
3075 G.postRedisplay "listview left";
3076 coe {< m_pan
= m_pan
+ 1 >}
3078 | 0xff50 -> (* home *)
3079 let active = find 0 1 in
3080 G.postRedisplay "listview home";
3083 | 0xff57 -> (* end *)
3084 let first = max
0 (itemcount - fstate.maxrows
) in
3085 let active = find (itemcount - 1) ~
-1 in
3086 G.postRedisplay "listview end";
3089 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3093 dolog "listview unknown key %#x" key; coe self
3095 method key key mask
=
3096 match state.mode
with
3097 | Textentry te
-> textentrykeyboard key mask te
; coe self
3098 | _ -> self#key1
key mask
3100 method button button down
x y _ =
3103 | 1 when x > conf.winw
- conf.scrollbw
->
3104 G.postRedisplay "listview scroll";
3107 let _, position, sh = self#
scrollph in
3108 if y > truncate
position && y < truncate
(position +. sh)
3110 state.mstate
<- Mscrolly
;
3114 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3115 let first = truncate
(s *. float source#getitemcount
) in
3116 let first = min source#getitemcount
first in
3117 Some
(coe {< m_first
= first; m_active
= first >})
3119 state.mstate
<- Mnone
;
3122 | 1 when not down
->
3123 begin match self#elemunder
y with
3125 G.postRedisplay "listview click";
3127 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3131 | n when (n == 4 || n == 5) && not down
->
3132 let len = source#getitemcount
in
3134 if n = 5 && m_first
+ fstate.maxrows
>= len
3138 let first = m_first
+ (if n == 4 then -1 else 1) in
3139 bound first 0 (len - 1)
3141 G.postRedisplay "listview wheel";
3142 Some
(coe {< m_first
= first >})
3147 | None
-> m_prev_uioh
3151 match state.mstate
with
3153 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3154 let first = truncate
(s *. float source#getitemcount
) in
3155 let first = min source#getitemcount
first in
3156 G.postRedisplay "listview motion";
3157 coe {< m_first
= first; m_active
= first >}
3160 method pmotion
x y =
3161 if x < conf.winw
- conf.scrollbw
3164 match self#elemunder
y with
3165 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3166 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3170 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3175 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3179 method infochanged
_ = ()
3181 method scrollpw
= (0, 0.0, 0.0)
3183 let nfs = fstate.fontsize
+ 1 in
3184 let y = m_first
* nfs in
3185 let itemcount = source#getitemcount
in
3186 let maxi = max
0 (itemcount - fstate.maxrows
) in
3187 let maxy = maxi * nfs in
3188 let p, h = scrollph y maxy in
3191 method modehash
= modehash
3194 class outlinelistview ~source
=
3197 ~source
:(source
:> lvsource
)
3199 ~modehash
:(findkeyhash conf "outline")
3202 method key key mask
=
3203 let calcfirst first active =
3206 let rows = active - first in
3207 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3211 let active = m_active
+ incr in
3212 let active = bound active 0 (source#getitemcount
- 1) in
3213 let first = calcfirst m_first
active in
3214 G.postRedisplay "outline navigate";
3215 coe {< m_active
= active; m_first
= first >}
3217 let ctrl = Wsi.withctrl mask
in
3219 | 110 when ctrl -> (* ctrl-n *)
3220 source#narrow m_qsearch
;
3221 G.postRedisplay "outline ctrl-n";
3222 coe {< m_first
= 0; m_active
= 0 >}
3224 | 117 when ctrl -> (* ctrl-u *)
3226 G.postRedisplay "outline ctrl-u";
3228 coe {< m_first
= 0; m_active
= 0 >}
3230 | 108 when ctrl -> (* ctrl-l *)
3231 let first = m_active
- (fstate.maxrows
/ 2) in
3232 G.postRedisplay "outline ctrl-l";
3233 coe {< m_first
= first >}
3235 | 0xff9f | 0xffff -> (* delete *)
3236 source#remove m_active
;
3237 G.postRedisplay "outline delete";
3238 let active = max
0 (m_active
-1) in
3239 coe {< m_first
= firstof m_first
active;
3240 m_active
= active >}
3242 | 0xff52 -> navigate ~
-1 (* up *)
3243 | 0xff54 -> navigate 1 (* down *)
3244 | 0xff55 -> (* prior *)
3245 navigate ~
-(fstate.maxrows
)
3246 | 0xff56 -> (* next *)
3247 navigate fstate.maxrows
3249 | 0xff53 -> (* [ctrl-]right *)
3253 G.postRedisplay "outline ctrl right";
3254 {< m_pan
= m_pan
+ 1 >}
3256 else self#updownlevel
1
3260 | 0xff51 -> (* [ctrl-]left *)
3264 G.postRedisplay "outline ctrl left";
3265 {< m_pan
= m_pan
- 1 >}
3267 else self#updownlevel ~
-1
3271 | 0xff50 -> (* home *)
3272 G.postRedisplay "outline home";
3273 coe {< m_first
= 0; m_active
= 0 >}
3275 | 0xff57 -> (* end *)
3276 let active = source#getitemcount
- 1 in
3277 let first = max
0 (active - fstate.maxrows
) in
3278 G.postRedisplay "outline end";
3279 coe {< m_active
= active; m_first
= first >}
3281 | _ -> super#
key key mask
3284 let outlinesource usebookmarks
=
3287 inherit lvsourcebase
3288 val mutable m_items
= empty
3289 val mutable m_orig_items
= empty
3290 val mutable m_prev_items
= empty
3291 val mutable m_narrow_pattern
= ""
3292 val mutable m_hadremovals
= false
3294 method getitemcount
=
3295 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3298 if n == Array.length m_items
&& m_hadremovals
3300 ("[Confirm removal]", 0)
3302 let s, n, _ = m_items
.(n) in
3305 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3306 ignore
(uioh
, first, qsearch);
3307 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3309 if String.length m_narrow_pattern
= 0
3315 if not
confrimremoval
3317 let _, _, anchor = m_items
.(active) in
3322 state.bookmarks
<- Array.to_list m_items
;
3323 m_orig_items
<- m_items
;
3326 else m_items
<- items;
3330 method hasaction
_ = true
3333 if Array.length m_items
!= Array.length m_orig_items
3334 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3337 method narrow
pattern =
3338 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3342 let rec loop accu n =
3345 m_narrow_pattern
<- pattern;
3346 m_items
<- Array.of_list
accu
3349 let (s, _, _) as o = m_items
.(n) in
3351 if (try ignore
(Str.search_forward
re s 0); true
3352 with Not_found
-> false)
3358 loop [] (Array.length m_items
- 1)
3363 then Array.of_list
state.bookmarks
3366 m_items
<- m_orig_items
3371 if m
>= 0 && m
< Array.length m_items
3373 m_hadremovals
<- true;
3374 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3375 let n = if n >= m
then n+1 else n in
3380 method reset
anchor items =
3381 m_hadremovals
<- false;
3382 if m_orig_items
== empty || m_prev_items
!= items
3384 m_orig_items
<- items;
3385 if String.length m_narrow_pattern
= 0
3386 then m_items
<- items;
3388 m_prev_items
<- items;
3389 let rely = getanchory anchor in
3391 let rec loop n best bestd
=
3392 if n = Array.length m_items
3395 let (_, _, anchor) = m_items
.(n) in
3396 let orely = getanchory anchor in
3397 let d = abs
(orely - rely) in
3400 else loop (n+1) best bestd
3405 m_first
<- firstof m_first
active
3409 let enterselector usebookmarks
=
3410 let source = outlinesource usebookmarks
in
3414 then Array.of_list
state.bookmarks
3417 if Array.length
outlines = 0
3419 showtext ' ' errmsg
;
3422 state.text <- source#greetmsg
;
3423 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3424 let anchor = getanchor () in
3425 source#reset
anchor outlines;
3426 state.uioh
<- coe (new outlinelistview ~
source);
3427 G.postRedisplay "enter selector";
3431 let enteroutlinemode =
3432 let f = enterselector false in
3433 fun ()-> f "Document has no outline";
3436 let enterbookmarkmode =
3437 let f = enterselector true in
3438 fun () -> f "Document has no bookmarks (yet)";
3441 let color_of_string s =
3442 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3443 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3447 let color_to_string (r
, g
, b) =
3448 let r = truncate
(r *. 256.0)
3449 and g
= truncate
(g
*. 256.0)
3450 and b = truncate
(b *. 256.0) in
3451 Printf.sprintf
"%d/%d/%d" r g
b
3454 let irect_of_string s =
3455 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3458 let irect_to_string (x0,y0,x1,y1) =
3459 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3462 let makecheckers () =
3463 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3465 converted by Issac Trotts. July 25, 2002 *)
3466 let image_height = 64
3467 and image_width
= 64 in
3471 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3473 for i
= 0 to image_width
- 1 do
3474 for j
= 0 to image_height - 1 do
3475 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3476 (if (i
land 8 ) lxor (j
land 8) = 0
3477 then [|255;255;255|] else [|200;200;200|])
3482 let image = make_image () in
3483 let id = GlTex.gen_texture
() in
3484 GlTex.bind_texture `texture_2d
id;
3485 GlPix.store
(`unpack_alignment
1);
3486 GlTex.image2d
image;
3487 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3490 `mag_filter `nearest
;
3491 `min_filter `nearest
];
3495 let setcheckers enabled
=
3496 match state.texid
with
3498 if enabled
then state.texid
<- Some
(makecheckers ())
3503 GlTex.delete_texture texid
;
3504 state.texid
<- None
;
3508 let int_of_string_with_suffix s =
3509 let l = String.length
s in
3513 let suffix = Char.lowercase
s.[l-1] in
3515 | 'k'
-> String.sub
s 0 (l-1), 10
3516 | 'm'
-> String.sub
s 0 (l-1), 20
3517 | 'g'
-> String.sub
s 0 (l-1), 30
3521 let n = int_of_string
s1 in
3522 let m = n lsl shift
in
3524 then raise
(Failure
"value too large")
3528 let string_with_suffix_of_int n =
3536 if n land ((1 lsl 20) - 1) = 0
3539 if n land ((1 lsl 10) - 1) = 0
3546 let h = n mod 1000 in
3549 then string_of_int
h ^
s
3551 let s = Printf.sprintf
"_%03d%s" h s in
3558 let defghyllscroll = (40, 8, 32);;
3559 let ghyllscroll_of_string s =
3560 let (n, a, b) as nab
=
3563 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3565 if n <= a || n <= b || a >= b
3566 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3570 let ghyllscroll_to_string ((n, a, b) as nab
) =
3571 if nab
= defghyllscroll
3573 else Printf.sprintf
"%d,%d,%d" n a b;
3576 let describe_location () =
3578 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3580 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3581 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3585 else (100. *. (float state.y /. float maxy))
3589 Printf.sprintf
"page %d of %d [%.2f%%]"
3590 (fn+1) state.pagecount
percent
3593 "pages %d-%d of %d [%.2f%%]"
3594 (fn+1) (ln
+1) state.pagecount
percent
3598 let btos b = if b then "\xe2\x88\x9a" else "" in
3599 let showextended = ref false in
3600 let leave mode
= function
3601 | Confirm
-> state.mode
<- mode
3602 | Cancel
-> state.mode
<- mode
in
3605 val mutable m_first_time
= true
3606 val mutable m_l
= []
3607 val mutable m_a
= [||]
3608 val mutable m_prev_uioh
= nouioh
3609 val mutable m_prev_mode
= View
3611 inherit lvsourcebase
3613 method reset prev_mode prev_uioh
=
3614 m_a
<- Array.of_list
(List.rev m_l
);
3616 m_prev_mode
<- prev_mode
;
3617 m_prev_uioh
<- prev_uioh
;
3621 if n >= Array.length m_a
3625 | _, _, _, Action
_ -> m_active
<- n
3629 m_first_time
<- false;
3632 method int name get
set =
3634 (name
, `
int get
, 1, Action
(
3637 try set (int_of_string
s)
3639 state.text <- Printf.sprintf
"bad integer `%s': %s"
3640 s (Printexc.to_string exn
)
3643 let te = name ^
": ", "", None
, intentry, ondone in
3644 state.mode
<- Textentry
(te, leave m_prev_mode
);
3648 method int_with_suffix name get
set =
3650 (name
, `intws get
, 1, Action
(
3653 try set (int_of_string_with_suffix s)
3655 state.text <- Printf.sprintf
"bad integer `%s': %s"
3656 s (Printexc.to_string exn
)
3660 name ^
": ", "", None
, intentry_with_suffix, ondone
3662 state.mode
<- Textentry
(te, leave m_prev_mode
);
3666 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3668 (name
, `
bool (btos, get
), offset
, Action
(
3675 method color name get
set =
3677 (name
, `color get
, 1, Action
(
3679 let invalid = (nan
, nan
, nan
) in
3682 try color_of_string s
3684 state.text <- Printf.sprintf
"bad color `%s': %s"
3685 s (Printexc.to_string exn
);
3691 let te = name ^
": ", "", None
, textentry, ondone in
3692 state.text <- color_to_string (get
());
3693 state.mode
<- Textentry
(te, leave m_prev_mode
);
3697 method string name get
set =
3699 (name
, `
string get
, 1, Action
(
3701 let ondone s = set s in
3702 let te = name ^
": ", "", None
, textentry, ondone in
3703 state.mode
<- Textentry
(te, leave m_prev_mode
);
3707 method colorspace name get
set =
3709 (name
, `
string get
, 1, Action
(
3712 let vals = [| "rgb"; "bgr"; "gray" |] in
3714 inherit lvsourcebase
3717 m_active
<- int_of_colorspace conf.colorspace
;
3720 method getitemcount
= Array.length
vals
3721 method getitem
n = (vals.(n), 0)
3722 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3723 ignore
(uioh
, first, pan
, qsearch);
3724 if not cancel
then set active;
3726 method hasaction
_ = true
3730 let modehash = findkeyhash conf "info" in
3731 coe (new listview ~
source ~trusted
:true ~
modehash)
3734 method caption
s offset
=
3735 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3737 method caption2
s f offset
=
3738 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3740 method getitemcount
= Array.length m_a
3743 let tostr = function
3744 | `
int f -> string_of_int
(f ())
3745 | `intws
f -> string_with_suffix_of_int (f ())
3747 | `color
f -> color_to_string (f ())
3748 | `
bool (btos, f) -> btos (f ())
3751 let name, t
, offset
, _ = m_a
.(n) in
3752 ((let s = tostr t
in
3753 if String.length
s > 0
3754 then Printf.sprintf
"%s\t%s" name s
3758 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3762 m_qsearch
<- qsearch;
3764 match m_a
.(active) with
3765 | _, _, _, Action
f -> f uioh
3777 method hasaction
n =
3779 | _, _, _, Action
_ -> true
3783 let rec fillsrc prevmode prevuioh
=
3784 let sep () = src#caption
"" 0 in
3785 let colorp name get
set =
3787 (fun () -> color_to_string (get
()))
3790 let c = color_of_string v in
3793 state.text <- Printf.sprintf
"bad color `%s': %s"
3794 v (Printexc.to_string exn
);
3797 let oldmode = state.mode
in
3798 let birdseye = isbirdseye state.mode
in
3800 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3802 src#
bool "presentation mode"
3803 (fun () -> conf.presentation)
3805 conf.presentation <- v;
3806 state.anchor <- getanchor ();
3809 src#
bool "ignore case in searches"
3810 (fun () -> conf.icase
)
3811 (fun v -> conf.icase
<- v);
3814 (fun () -> conf.preload)
3815 (fun v -> conf.preload <- v);
3817 src#
bool "highlight links"
3818 (fun () -> conf.hlinks
)
3819 (fun v -> conf.hlinks
<- v);
3821 src#
bool "under info"
3822 (fun () -> conf.underinfo
)
3823 (fun v -> conf.underinfo
<- v);
3825 src#
bool "persistent bookmarks"
3826 (fun () -> conf.savebmarks
)
3827 (fun v -> conf.savebmarks
<- v);
3829 src#
bool "proportional display"
3830 (fun () -> conf.proportional
)
3831 (fun v -> reqlayout conf.angle
v);
3833 src#
bool "trim margins"
3834 (fun () -> conf.trimmargins
)
3835 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3837 src#
bool "persistent location"
3838 (fun () -> conf.jumpback
)
3839 (fun v -> conf.jumpback
<- v);
3842 src#
int "inter-page space"
3843 (fun () -> conf.interpagespace)
3845 conf.interpagespace <- n;
3847 match state.layout with
3852 state.maxy <- calcheight ();
3853 let y = getpagey pageno in
3858 (fun () -> conf.pagebias
)
3859 (fun v -> conf.pagebias
<- v);
3861 src#
int "scroll step"
3862 (fun () -> conf.scrollstep
)
3863 (fun n -> conf.scrollstep
<- n);
3865 src#
int "auto scroll step"
3867 match state.autoscroll
with
3869 | _ -> conf.autoscrollstep
)
3871 if state.autoscroll
<> None
3872 then state.autoscroll
<- Some
n;
3873 conf.autoscrollstep
<- n);
3876 (fun () -> truncate
(conf.zoom *. 100.))
3877 (fun v -> setzoom ((float v) /. 100.));
3880 (fun () -> conf.angle
)
3881 (fun v -> reqlayout v conf.proportional
);
3883 src#
int "scroll bar width"
3884 (fun () -> state.scrollw
)
3888 reshape conf.winw
conf.winh
;
3891 src#
int "scroll handle height"
3892 (fun () -> conf.scrollh
)
3893 (fun v -> conf.scrollh
<- v;);
3895 src#
int "thumbnail width"
3896 (fun () -> conf.thumbw
)
3898 conf.thumbw
<- min
4096 v;
3901 leavebirdseye beye
false;
3906 src#
string "columns"
3908 match conf.columns
with
3910 | Some
(multicol
, _) -> columns_to_string multicol
)
3912 let n, a, b = columns_of_string v in
3916 src#caption
"Presentation mode" 0;
3917 src#
bool "scrollbar visible"
3918 (fun () -> conf.scrollbarinpm
)
3920 if v != conf.scrollbarinpm
3922 conf.scrollbarinpm
<- v;
3923 if conf.presentation
3925 state.scrollw
<- if v then conf.scrollbw
else 0;
3926 reshape conf.winw
conf.winh
;
3932 src#caption
"Pixmap cache" 0;
3933 src#int_with_suffix
"size (advisory)"
3934 (fun () -> conf.memlimit
)
3935 (fun v -> conf.memlimit
<- v);
3938 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3939 (string_with_suffix_of_int state.memused
)
3940 (Hashtbl.length
state.tilemap
)) 1;
3943 src#caption
"Layout" 0;
3944 src#caption2
"Dimension"
3946 Printf.sprintf
"%dx%d (virtual %dx%d)"
3952 src#caption2
"Position" (fun () ->
3953 Printf.sprintf
"%dx%d" state.x state.y
3956 src#caption2
"Visible" (fun () -> describe_location ()) 1
3960 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3961 "Save these parameters as global defaults at exit"
3962 (fun () -> conf.bedefault
)
3963 (fun v -> conf.bedefault
<- v)
3967 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3968 src#
bool ~offset
:0 ~
btos "Extended parameters"
3969 (fun () -> !showextended)
3970 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3974 (fun () -> conf.checkers
)
3975 (fun v -> conf.checkers
<- v; setcheckers v);
3976 src#
bool "update cursor"
3977 (fun () -> conf.updatecurs
)
3978 (fun v -> conf.updatecurs
<- v);
3980 (fun () -> conf.verbose
)
3981 (fun v -> conf.verbose
<- v);
3982 src#
bool "invert colors"
3983 (fun () -> conf.invert
)
3984 (fun v -> conf.invert
<- v);
3986 (fun () -> conf.maxhfit
)
3987 (fun v -> conf.maxhfit
<- v);
3988 src#
bool "redirect stderr"
3989 (fun () -> conf.redirectstderr)
3990 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3991 src#
string "uri launcher"
3992 (fun () -> conf.urilauncher
)
3993 (fun v -> conf.urilauncher
<- v);
3994 src#
string "path launcher"
3995 (fun () -> conf.pathlauncher
)
3996 (fun v -> conf.pathlauncher
<- v);
3997 src#
string "tile size"
3998 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4001 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4002 conf.tileh
<- max
64 w;
4003 conf.tilew
<- max
64 h;
4006 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4007 v (Printexc.to_string exn
));
4008 src#
int "texture count"
4009 (fun () -> conf.texcount
)
4012 then conf.texcount
<- v
4013 else showtext '
!'
" Failed to set texture count please retry later"
4015 src#
int "slice height"
4016 (fun () -> conf.sliceheight
)
4018 conf.sliceheight
<- v;
4019 wcmd "sliceh %d" conf.sliceheight
;
4021 src#
int "anti-aliasing level"
4022 (fun () -> conf.aalevel
)
4024 conf.aalevel
<- bound v 0 8;
4025 state.anchor <- getanchor ();
4026 opendoc state.path
state.password
;
4028 src#
int "ui font size"
4029 (fun () -> fstate.fontsize
)
4030 (fun v -> setfontsize (bound v 5 100));
4031 colorp "background color"
4032 (fun () -> conf.bgcolor
)
4033 (fun v -> conf.bgcolor
<- v);
4034 src#
bool "crop hack"
4035 (fun () -> conf.crophack
)
4036 (fun v -> conf.crophack
<- v);
4037 src#
string "trim fuzz"
4038 (fun () -> irect_to_string conf.trimfuzz
)
4041 conf.trimfuzz
<- irect_of_string v;
4043 then settrim true conf.trimfuzz
;
4045 state.text <- Printf.sprintf
"bad irect `%s': %s"
4046 v (Printexc.to_string exn
)
4048 src#
string "throttle"
4050 match conf.maxwait
with
4051 | None
-> "show place holder if page is not ready"
4054 then "wait for page to fully render"
4056 "wait " ^ string_of_float
time
4057 ^
" seconds before showing placeholder"
4061 let f = float_of_string
v in
4063 then conf.maxwait
<- None
4064 else conf.maxwait
<- Some
f
4066 state.text <- Printf.sprintf
"bad time `%s': %s"
4067 v (Printexc.to_string exn
)
4069 src#
string "ghyll scroll"
4071 match conf.ghyllscroll
with
4073 | Some nab
-> ghyllscroll_to_string nab
4078 if String.length
v = 0
4080 else Some
(ghyllscroll_of_string v)
4082 conf.ghyllscroll
<- gs
4084 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4085 v (Printexc.to_string exn
)
4087 src#
string "selection command"
4088 (fun () -> conf.selcmd
)
4089 (fun v -> conf.selcmd
<- v);
4090 src#colorspace
"color space"
4091 (fun () -> colorspace_to_string conf.colorspace
)
4093 conf.colorspace
<- colorspace_of_int v;
4100 src#caption
"Document" 0;
4101 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4102 src#caption2
"Pages"
4103 (fun () -> string_of_int
state.pagecount
) 1;
4104 src#caption2
"Dimensions"
4105 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4109 src#caption
"Trimmed margins" 0;
4110 src#caption2
"Dimensions"
4111 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4114 src#reset prevmode prevuioh
;
4118 let prevmode = state.mode
4119 and prevuioh
= state.uioh in
4120 fillsrc prevmode prevuioh
;
4121 let source = (src :> lvsource
) in
4122 let modehash = findkeyhash conf "info" in
4123 state.uioh <- coe (object (self)
4124 inherit listview ~
source ~trusted
:true ~
modehash as super
4125 val mutable m_prevmemused
= 0
4126 method infochanged
= function
4128 if m_prevmemused
!= state.memused
4130 m_prevmemused
<- state.memused
;
4131 G.postRedisplay "memusedchanged";
4133 | Pdim
-> G.postRedisplay "pdimchanged"
4134 | Docinfo
-> fillsrc prevmode prevuioh
4136 method key key mask
=
4137 if not
(Wsi.withctrl mask
)
4140 | 0xff51 -> coe (self#updownlevel ~
-1)
4141 | 0xff53 -> coe (self#updownlevel
1)
4142 | _ -> super#
key key mask
4143 else super#
key key mask
4145 G.postRedisplay "info";
4151 inherit lvsourcebase
4152 method getitemcount
= Array.length
state.help
4154 let s, n, _ = state.help
.(n) in
4157 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4161 m_qsearch
<- qsearch;
4162 match state.help
.(active) with
4163 | _, _, Action
f -> Some
(f uioh)
4173 method hasaction
n =
4174 match state.help
.(n) with
4175 | _, _, Action
_ -> true
4182 let modehash = findkeyhash conf "help" in
4183 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4184 G.postRedisplay "help";
4189 let re = Str.regexp
"[\r\n]" in
4191 inherit lvsourcebase
4192 val mutable m_items
= [||]
4194 method getitemcount
= 1 + Array.length m_items
4199 else m_items
.(n-1), 0
4201 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4206 then Buffer.clear
state.errmsgs
;
4207 m_qsearch
<- qsearch;
4214 method hasaction
n =
4218 state.newerrmsgs
<- false;
4219 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4220 m_items
<- Array.of_list
l
4228 let source = (msgsource :> lvsource
) in
4229 let modehash = findkeyhash conf "listview" in
4230 state.uioh <- coe (object
4231 inherit listview ~
source ~trusted
:false ~
modehash as super
4234 then msgsource#reset
;
4237 G.postRedisplay "msgs";
4240 let quickbookmark ?title
() =
4241 match state.layout with
4247 let sec = Unix.gettimeofday
() in
4248 let tm = Unix.localtime
sec in
4249 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4253 (tm.Unix.tm_year
+ 1900)
4256 | Some
title -> title
4259 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4264 state.fullscreen
<- None
;
4268 let setautoscrollspeed step goingdown
=
4269 let incr = max
1 ((abs step
) / 2) in
4270 let incr = if goingdown
then incr else -incr in
4271 let astep = step
+ incr in
4272 state.autoscroll
<- Some
astep;
4275 let viewkeyboard key mask
=
4277 let mode = state.mode in
4278 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4281 G.postRedisplay "view:enttext"
4283 let ctrl = Wsi.withctrl mask
in
4288 | 0xff63 -> (* insert *)
4289 if conf.angle
mod 360 = 0
4291 state.mode <- LinkNav
(Ltgendir
0);
4294 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4296 | 0xff1b | 113 -> (* escape / q *)
4297 begin match state.mstate
with
4299 state.mstate
<- Mnone
;
4300 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4301 G.postRedisplay "kill zoom rect";
4303 match state.ranchors
with
4305 | (path
, password
, anchor) :: rest
->
4306 state.ranchors
<- rest
;
4307 state.anchor <- anchor;
4308 opendoc path password
4311 | 0xff08 -> (* backspace *)
4312 let y = getnav ~
-1 in
4313 gotoy_and_clear_text y
4321 G.postRedisplay "dehighlight";
4323 | 47 | 63 -> (* / ? *)
4324 let ondone isforw
s =
4325 cbput state.hists
.pat
s;
4326 state.searchpattern
<- s;
4329 let s = String.create
1 in
4330 s.[0] <- Char.chr
key;
4331 enttext (s, "", Some
(onhist state.hists
.pat
),
4332 textentry, ondone (key = 47))
4334 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4335 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4336 setzoom (conf.zoom +. incr)
4338 | 43 | 0xffab -> (* + *)
4341 try int_of_string
s with exc
->
4342 state.text <- Printf.sprintf
"bad integer `%s': %s"
4343 s (Printexc.to_string exc
);
4349 state.text <- "page bias is now " ^ string_of_int
n;
4352 enttext ("page bias: ", "", None
, intentry, ondone)
4354 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4355 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4356 setzoom (max
0.01 (conf.zoom -. decr))
4358 | 45 | 0xffad -> (* - *)
4359 let ondone msg
= state.text <- msg
in
4361 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4362 optentry state.mode, ondone
4365 | 48 when ctrl -> (* ctrl-0 *)
4368 | 49 when ctrl -> (* 1 *)
4369 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4373 | 0xffc6 -> (* f9 *)
4376 | 57 when ctrl -> (* ctrl-9 *)
4379 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4380 when not
ctrl -> (* 0..9 *)
4383 try int_of_string
s with exc
->
4384 state.text <- Printf.sprintf
"bad integer `%s': %s"
4385 s (Printexc.to_string exc
);
4391 cbput state.hists
.pag
(string_of_int
n);
4392 gotopage1 (n + conf.pagebias
- 1) 0;
4395 let pageentry text key =
4396 match Char.unsafe_chr
key with
4397 | 'g'
-> TEdone
text
4398 | _ -> intentry text key
4400 let text = "x" in text.[0] <- Char.chr
key;
4401 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4404 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4405 reshape conf.winw
conf.winh
;
4408 conf.hlinks
<- not
conf.hlinks
;
4409 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4410 G.postRedisplay "toggle highlightlinks";
4413 begin match state.autoscroll
with
4415 conf.autoscrollstep
<- step
;
4416 state.autoscroll
<- None
4418 if conf.autoscrollstep
= 0
4419 then state.autoscroll
<- Some
1
4420 else state.autoscroll
<- Some
conf.autoscrollstep
4424 conf.presentation <- not
conf.presentation;
4425 if conf.presentation
4427 if not
conf.scrollbarinpm
4428 then state.scrollw
<- 0;
4431 state.scrollw
<- conf.scrollbw
;
4433 showtext ' '
("presentation mode " ^
4434 if conf.presentation then "on" else "off");
4435 state.anchor <- getanchor ();
4439 begin match state.fullscreen
with
4441 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4444 state.fullscreen
<- None
;
4449 gotoy_and_clear_text 0
4452 gotopage1 (state.pagecount
- 1) 0
4454 | 112 | 78 -> (* p|N *)
4455 search state.searchpattern
false
4457 | 110 | 0xffc0 -> (* n|F3 *)
4458 search state.searchpattern
true
4461 begin match state.layout with
4464 gotoy_and_clear_text (getpagey l.pageno)
4468 begin match List.rev
state.layout with
4471 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4472 gotoy_and_clear_text (getpagey pageno)
4475 | 0xff9f | 0xffff -> (* delete *)
4476 begin match state.layout with
4479 let pageno = max
0 (l.pageno-1) in
4480 gotoy_and_clear_text (getpagey pageno)
4484 showtext ' '
(describe_location ());
4487 begin match state.layout with
4490 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4495 enterbookmarkmode ()
4497 | 104 | 0xffbe -> (* h|F1 *)
4503 | 101 when conf.redirectstderr -> (* e *)
4508 match state.layout with
4511 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4515 enttext ("bookmark: ", "", None
, textentry, ondone)
4519 showtext ' '
"Quick bookmark added";
4522 begin match state.layout with
4524 let rect = getpdimrect
l.pagedimno
in
4528 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4529 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4531 (truncate
(rect.(1) -. rect.(0)),
4532 truncate
(rect.(3) -. rect.(0)))
4534 let w = truncate
((float w)*.conf.zoom)
4535 and h = truncate
((float h)*.conf.zoom) in
4538 state.anchor <- getanchor ();
4539 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4541 G.postRedisplay "z";
4546 | 50 when ctrl -> (* ctrl-2 *)
4547 let maxw = getmaxw
() in
4549 then setzoom (maxw /. float conf.winw
)
4551 | 60 | 62 -> (* < > *)
4552 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4554 | 91 | 93 -> (* [ ] *)
4556 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4558 G.postRedisplay "brightness";
4560 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4561 setzoom state.prevzoom
4563 | 107 | 0xff52 -> (* k up *)
4564 begin match state.autoscroll
with
4566 begin match state.mode with
4567 | Birdseye beye
-> upbirdseye 1 beye
4570 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4571 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4574 setautoscrollspeed n false
4577 | 106 | 0xff54 -> (* j down *)
4578 begin match state.autoscroll
with
4580 begin match state.mode with
4581 | Birdseye beye
-> downbirdseye 1 beye
4584 then gotoy_and_clear_text (clamp (conf.winh
/2))
4585 else gotoy_and_clear_text (clamp conf.scrollstep
)
4588 setautoscrollspeed n true
4591 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4599 let dx = if key = 0xff51 then dx else -dx in
4600 state.x <- state.x + dx;
4601 gotoy_and_clear_text state.y
4604 G.postRedisplay "lef/right"
4607 | 0xff55 -> (* prior *)
4611 match state.layout with
4613 | l :: _ -> state.y - l.pagey
4619 | 0xff56 -> (* next *)
4623 match List.rev
state.layout with
4625 | l :: _ -> getpagey l.pageno
4631 | 0xff50 -> gotoghyll 0
4632 | 0xff57 -> gotoghyll (clamp state.maxy)
4633 | 0xff53 when Wsi.withalt mask
->
4634 gotoghyll (getnav ~
-1)
4635 | 0xff51 when Wsi.withalt mask
->
4636 gotoghyll (getnav 1)
4639 state.anchor <- getanchor ();
4640 opendoc state.path
state.password
4645 | 118 when conf.debug
-> (* v *)
4648 match getopaque l.pageno with
4651 let x0, y0, x1, y1 = pagebbox opaque
in
4652 let a,b = float x0, float y0 in
4653 let c,d = float x1, float y0 in
4654 let e,f = float x1, float y1 in
4655 let h,j
= float x0, float y1 in
4656 let rect = (a,b,c,d,e,f,h,j
) in
4658 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4660 G.postRedisplay "v";
4663 vlog "huh? %s" (Wsi.keyname
key)
4666 let gotounder = function
4667 | Ulinkgoto
(pageno, top) ->
4671 gotopage1 pageno top;
4677 | Uremote
(filename
, pageno) ->
4679 if Sys.file_exists filename
4682 let dir = Filename.dirname
state.path in
4683 let path = Filename.concat
dir filename
in
4684 if Sys.file_exists
path
4688 if String.length
path > 0
4690 let anchor = getanchor () in
4691 let ranchor = state.path, state.password
, anchor in
4692 state.anchor <- (pageno, 0.0);
4693 state.ranchors
<- ranchor :: state.ranchors
;
4696 else showtext '
!'
("Could not find " ^ filename
)
4698 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4701 let linknavkeyboard key mask
linknav =
4702 let getpage pageno =
4703 let rec loop = function
4705 | l :: _ when l.pageno = pageno -> Some
l
4706 | _ :: rest
-> loop rest
4707 in loop state.layout
4709 let doexact (pageno, n) =
4710 match getopaque pageno, getpage pageno with
4711 | Some opaque
, Some
l ->
4714 let under = getlink opaque
n in
4715 G.postRedisplay "link gotounder";
4721 | 0xff50 -> (* home *)
4722 Some
(findlink opaque LDfirst
), -1
4724 | 0xff57 -> (* end *)
4725 Some
(findlink opaque LDlast
), 1
4727 | 0xff51 -> (* left *)
4728 Some
(findlink opaque
(LDleft
n)), -1
4730 | 0xff53 -> (* right *)
4731 Some
(findlink opaque
(LDright
n)), 1
4733 | 0xff52 -> (* up *)
4734 Some
(findlink opaque
(LDup
n)), -1
4736 | 0xff54 -> (* down *)
4737 Some
(findlink opaque
(LDdown
n)), 1
4742 begin match findpwl
l.pageno dir with
4746 state.mode <- LinkNav
(Ltgendir
dir);
4747 let y, h = getpageyh pageno in
4750 then y + h - conf.winh
4755 begin match getopaque pageno, getpage pageno with
4756 | Some opaque
, Some
_ ->
4758 let ld = if dir > 0 then LDfirst
else LDlast
in
4761 begin match link with
4762 | Lfound
(m, x0, y0, x1, y1) ->
4763 let r = x0, y0, x1, y1 in
4764 state.mode <- LinkNav
(Ltexact
((pageno, m), r));
4765 G.postRedisplay "linknav jpage";
4772 begin match opt with
4773 | Some Lnotfound
-> pwl l dir;
4774 | Some
(Lfound
(m, x0, y0, x1, y1)) ->
4779 then gotopage1 l.pageno y0
4781 if y1 - l.pagey > l.pagevh
4782 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh)
4783 else G.postRedisplay "linknav";
4785 let r = x0, y0, x1, y1 in
4786 state.mode <- LinkNav
(Ltexact
((l.pageno, m), r));
4790 state.mode <- LinkNav
(Ltgendir
0);
4791 viewkeyboard key mask
4793 | _ -> viewkeyboard key mask
4798 G.postRedisplay "leave linknav"
4802 | Ltgendir
_ -> viewkeyboard key mask
4803 | Ltexact
(exact
, _) -> doexact exact
4806 let keyboard key mask
=
4807 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4808 then wcmd "interrupt"
4809 else state.uioh <- state.uioh#
key key mask
4812 let birdseyekeyboard key mask
4813 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4815 match conf.columns
with
4817 | Some
((c, _, _), _) -> c
4820 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4821 let y, h = getpageyh pageno in
4822 let top = (conf.winh
- h) / 2 in
4823 gotoy (max
0 (y - top))
4824 | 0xff0d -> leavebirdseye beye
false
4825 | 0xff1b -> leavebirdseye beye
true (* escape *)
4826 | 0xff52 -> upbirdseye incr beye
(* prior *)
4827 | 0xff54 -> downbirdseye incr beye
(* next *)
4828 | 0xff51 -> upbirdseye 1 beye
(* up *)
4829 | 0xff53 -> downbirdseye 1 beye
(* down *)
4832 begin match state.layout with
4836 state.mode <- Birdseye
(
4837 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4839 gotopage1 l.pageno 0;
4842 let layout = layout (state.y-conf.winh
) conf.winh
in
4844 | [] -> gotoy (clamp (-conf.winh
))
4846 state.mode <- Birdseye
(
4847 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4849 gotopage1 l.pageno 0
4852 | [] -> gotoy (clamp (-conf.winh
))
4856 begin match List.rev
state.layout with
4858 let layout = layout (state.y + conf.winh
) conf.winh
in
4859 begin match layout with
4861 let incr = l.pageh
- l.pagevh in
4866 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4868 G.postRedisplay "birdseye pagedown";
4870 else gotoy (clamp (incr + conf.interpagespace*2));
4874 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4875 gotopage1 l.pageno 0;
4878 | [] -> gotoy (clamp conf.winh
)
4882 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4886 let pageno = state.pagecount
- 1 in
4887 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4888 if not
(pagevisible state.layout pageno)
4891 match List.rev
state.pdims
with
4893 | (_, _, h, _) :: _ -> h
4895 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4896 else G.postRedisplay "birdseye end";
4897 | _ -> viewkeyboard key mask
4902 match state.mode with
4903 | Textentry
_ -> scalecolor 0.4
4905 | View
-> scalecolor 1.0
4906 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4907 if l.pageno = hooverpageno
4910 if l.pageno = pageno
4916 begin match getopaque l.pageno with
4918 if tileready l l.pagex l.pagey
4920 let x = l.pagedispx - l.pagex
4921 and y = l.pagedispy - l.pagey in
4922 postprocess opaque
conf.hlinks
x y;
4928 let scrollindicator () =
4929 let sbw, ph
, sh = state.uioh#
scrollph in
4930 let sbh, pw
, sw = state.uioh#scrollpw
in
4932 GlDraw.color (0.64, 0.64, 0.64);
4934 (float (conf.winw
- sbw), 0.)
4935 (float conf.winw
, float conf.winh
)
4938 (0., float (conf.winh
- sbh))
4939 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4941 GlDraw.color (0.0, 0.0, 0.0);
4944 (float (conf.winw
- sbw), ph
)
4945 (float conf.winw
, ph
+. sh)
4948 (pw
, float (conf.winh
- sbh))
4949 (pw
+. sw, float conf.winh
)
4954 match state.mstate
with
4955 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4958 | Msel
((x0, y0), (x1, y1)) ->
4959 let rec loop = function
4961 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4962 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4963 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4964 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4966 match getopaque l.pageno with
4968 let x0, y0 = pagetranslatepoint l x0 y0 in
4969 let x1, y1 = pagetranslatepoint l x1 y1 in
4970 seltext opaque
(x0, y0, x1, y1);
4978 let showrects rects
=
4980 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4981 GlDraw.polygon_mode `both `fill
;
4982 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4984 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4986 if l.pageno = pageno
4988 let dx = float (l.pagedispx - l.pagex) in
4989 let dy = float (l.pagedispy - l.pagey) in
4990 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4991 GlDraw.begins `quads
;
4993 GlDraw.vertex2
(x0+.dx, y0+.dy);
4994 GlDraw.vertex2
(x1+.dx, y1+.dy);
4995 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4996 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5007 GlClear.color (scalecolor2 conf.bgcolor
);
5008 GlClear.clear
[`
color];
5009 List.iter
drawpage state.layout;
5011 match state.mode with
5012 | LinkNav
(Ltexact
((pageno, _), (x0, y0, x1, y1))) ->
5024 begin match state.mstate
with
5025 | Mzoomrect
((x0, y0), (x1, y1)) ->
5027 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5028 GlDraw.polygon_mode `both `fill
;
5029 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5030 GlDraw.rect (float x0, float y0)
5031 (float x1, float y1);
5039 let mx, my
= state.mpos
in
5046 if nogeomcmds state.geomcmds
5049 GlFunc.draw_buffer `front
;
5050 GlClear.color (scalecolor2 conf.bgcolor
);
5051 GlClear.clear
[`
color];
5052 GlFunc.draw_buffer `back
;
5056 let zoomrect x y x1 y1 =
5059 and y0 = min
y y1 in
5060 gotoy (state.y + y0);
5061 state.anchor <- getanchor ();
5062 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5064 if state.w < conf.winw
- state.scrollw
5065 then (conf.winw
- state.scrollw
- state.w) / 2
5068 state.x <- (state.x + margin) - x0;
5070 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5071 state.mstate
<- Mnone
;
5075 let winw = conf.winw - state.scrollw
- 1 in
5076 let s = float x /. float winw in
5077 let destx = truncate
(float (state.w + winw) *. s) in
5078 state.x <- winw - destx;
5079 gotoy_and_clear_text state.y;
5080 state.mstate
<- Mscrollx
;
5084 let s = float y /. float conf.winh
in
5085 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5086 gotoy_and_clear_text desty;
5087 state.mstate
<- Mscrolly
;
5090 let viewmouse button down
x y mask
=
5092 | n when (n == 4 || n == 5) && not down
->
5093 if Wsi.withctrl mask
5095 match state.mstate
with
5096 | Mzoom
(oldn
, i
) ->
5104 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5106 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5108 let zoom = conf.zoom -. incr in
5110 state.mstate
<- Mzoom
(n, 0);
5112 state.mstate
<- Mzoom
(n, i
+1);
5114 else state.mstate
<- Mzoom
(n, 0)
5116 | _ -> state.mstate
<- Mzoom
(n, 0)
5119 match state.autoscroll
with
5120 | Some step
-> setautoscrollspeed step
(n=4)
5124 then -conf.scrollstep
5125 else conf.scrollstep
5127 let incr = incr * 2 in
5128 let y = clamp incr in
5129 gotoy_and_clear_text y
5132 | 1 when Wsi.withctrl mask
->
5135 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5136 state.mstate
<- Mpan
(x, y)
5139 state.mstate
<- Mnone
5144 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5146 state.mstate
<- Mzoomrect
(p, p)
5149 match state.mstate
with
5150 | Mzoomrect
((x0, y0), _) ->
5151 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5152 then zoomrect x0 y0 x y
5154 state.mstate
<- Mnone
;
5155 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5156 G.postRedisplay "kill accidental zoom rect";
5159 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5160 state.mstate
<- Mnone
5163 | 1 when x > conf.winw - state.scrollw
->
5166 let _, position, sh = state.uioh#
scrollph in
5167 if y > truncate
position && y < truncate
(position +. sh)
5168 then state.mstate
<- Mscrolly
5171 state.mstate
<- Mnone
5173 | 1 when y > conf.winh
- state.hscrollh ->
5176 let _, position, sw = state.uioh#scrollpw
in
5177 if x > truncate
position && x < truncate
(position +. sw)
5178 then state.mstate
<- Mscrollx
5181 state.mstate
<- Mnone
5184 let dest = if down
then getunder x y else Unone
in
5185 begin match dest with
5186 | Ulinkgoto
(pageno, top) ->
5190 gotopage1 pageno top;
5196 | Uremote
(filename
, pageno) ->
5198 if Sys.file_exists filename
5201 let dir = Filename.dirname
state.path in
5202 let path = Filename.concat
dir filename
in
5203 if Sys.file_exists
path
5207 if String.length
path > 0
5209 let anchor = getanchor () in
5210 let ranchor = state.path, state.password
, anchor in
5211 state.anchor <- (pageno, 0.0);
5212 state.ranchors
<- ranchor :: state.ranchors
;
5215 else showtext '
!'
("Could not find " ^ filename
)
5217 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5219 | Unone
when down
->
5220 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5221 state.mstate
<- Mpan
(x, y);
5223 | Unone
| Utext
_ ->
5226 if conf.angle
mod 360 = 0
5228 state.mstate
<- Msel
((x, y), (x, y));
5229 G.postRedisplay "mouse select";
5233 match state.mstate
with
5236 | Mzoom
_ | Mscrollx
| Mscrolly
->
5237 state.mstate
<- Mnone
5239 | Mzoomrect
((x0, y0), _) ->
5243 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5244 state.mstate
<- Mnone
5246 | Msel
((_, y0), (_, y1)) ->
5247 let rec loop = function
5250 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5251 || ((y1 >= l.pagedispy
5252 && y1 <= (l.pagedispy + l.pagevh)))
5254 match getopaque l.pageno with
5256 copysel
conf.selcmd opaque
;
5257 G.postRedisplay "copysel"
5262 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5263 state.mstate
<- Mnone
;
5270 let birdseyemouse button down
x y mask
5271 (conf, leftx
, _, hooverpageno
, anchor) =
5274 let rec loop = function
5277 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5278 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5280 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5286 | _ -> viewmouse button down
x y mask
5289 let mouse button down
x y mask
=
5290 state.uioh <- state.uioh#button button down
x y mask
;
5294 state.uioh <- state.uioh#
motion x y
5298 state.uioh <- state.uioh#
pmotion x y;
5304 method key key mask
=
5305 begin match state.mode with
5306 | Textentry
textentry -> textentrykeyboard key mask
textentry
5307 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5308 | View
-> viewkeyboard key mask
5309 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5313 method button button bstate
x y mask
=
5314 begin match state.mode with
5316 | View
-> viewmouse button bstate
x y mask
5317 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5323 begin match state.mode with
5325 | View
| Birdseye
_ | LinkNav
_ ->
5326 match state.mstate
with
5327 | Mzoom
_ | Mnone
-> ()
5332 state.mstate
<- Mpan
(x, y);
5333 if conf.zoom > 1.0 then state.x <- state.x + dx;
5335 gotoy_and_clear_text y
5338 state.mstate
<- Msel
(a, (x, y));
5339 G.postRedisplay "motion select";
5342 let y = min
conf.winh
(max
0 y) in
5346 let x = min
conf.winw (max
0 x) in
5349 | Mzoomrect
(p0
, _) ->
5350 state.mstate
<- Mzoomrect
(p0
, (x, y));
5351 G.postRedisplay "motion zoomrect";
5355 method pmotion x y =
5356 begin match state.mode with
5357 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5358 let rec loop = function
5360 if hooverpageno
!= -1
5362 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5363 G.postRedisplay "pmotion birdseye no hoover";
5366 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5367 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5369 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5370 G.postRedisplay "pmotion birdseye hoover";
5380 match state.mstate
with
5381 | Mnone
-> updateunder x y
5382 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5387 method infochanged
_ = ()
5390 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5391 let p, h = scrollph state.y maxy in
5395 let winw = conf.winw - state.scrollw
- 1 in
5396 let fwinw = float winw in
5398 let sw = fwinw /. float state.w in
5399 let sw = fwinw *. sw in
5400 max
sw (float conf.scrollh
)
5403 let f = state.w+winw in
5404 let r = float (winw-state.x) /. float f in
5405 let p = fwinw *. r in
5409 if position +. sw > fwinw
5410 then fwinw -. position
5413 state.hscrollh, position, sw
5417 match state.mode with
5418 | LinkNav
_ -> "links"
5419 | Textentry
_ -> "textentry"
5420 | Birdseye
_ -> "birdseye"
5423 findkeyhash conf modename
5430 let fontpath = ref "";;
5433 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5436 let l = String.length
s in
5437 let b = Buffer.create
l in
5443 try Sys.getenv
"HOME"
5446 ("Can not determine home directory location: " ^
5447 Printexc.to_string exn
);
5451 let modifier_of_string = function
5452 | "alt" -> Wsi.altmask
5453 | "shift" -> Wsi.shiftmask
5454 | "ctrl" | "control" -> Wsi.ctrlmask
5455 | "meta" -> Wsi.metamask
5460 let r = Str.regexp
"-" in
5462 let elems = Str.full_split
r s in
5465 let m1 = modifier_of_string s in
5467 then (Wsi.namekey
s, m)
5470 | Str.Delim
s when n land 1 = 0 -> g s
5472 | Str.Delim
_ -> (k
, m)
5474 let rec loop n k
m = function
5477 let k, m = f n k m x in
5483 let keys_of_string =
5484 let r = Str.regexp
"[ \t]" in
5486 let elems = Str.split
r s in
5487 List.map
key_of_string elems
5490 let copykeyhashes c =
5491 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5494 let config_of c attrs
=
5498 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5499 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5500 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5501 | "preload" -> { c with preload = bool_of_string
v }
5502 | "page-bias" -> { c with pagebias
= int_of_string
v }
5503 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5504 | "auto-scroll-step" ->
5505 { c with autoscrollstep
= max
0 (int_of_string
v) }
5506 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5507 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5510 match String.lowercase
v with
5511 | "true" -> Some infinity
5513 | f -> Some
(float_of_string
f)
5515 { c with maxwait
= mw}
5516 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5517 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5518 | "vertical-margin" ->
5519 { c with interpagespace = max
0 (int_of_string
v) }
5521 let zoom = float_of_string
v /. 100. in
5522 let zoom = max
zoom 0.0 in
5523 { c with zoom = zoom }
5524 | "presentation" -> { c with presentation = bool_of_string
v }
5525 | "rotation-angle" -> { c with angle
= int_of_string
v }
5526 | "width" -> { c with winw = max
20 (int_of_string
v) }
5527 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5528 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5529 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5530 | "pixmap-cache-size" ->
5531 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5532 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5533 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5534 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5535 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5536 | "background-color" -> { c with bgcolor
= color_of_string v }
5537 | "scrollbar-in-presentation" ->
5538 { c with scrollbarinpm
= bool_of_string
v }
5539 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5540 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5541 | "mupdf-store-size" ->
5542 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5543 | "checkers" -> { c with checkers
= bool_of_string
v }
5544 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5545 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5546 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5547 | "uri-launcher" -> { c with urilauncher
= unent v }
5548 | "path-launcher" -> { c with pathlauncher
= unent v }
5549 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5550 | "invert-colors" -> { c with invert
= bool_of_string
v }
5551 | "brightness" -> { c with colorscale
= float_of_string
v }
5552 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5554 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5556 let nab = columns_of_string v in
5557 { c with columns
= Some
(nab, [||]) }
5558 | "birds-eye-columns" ->
5559 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5560 | "selection-command" -> { c with selcmd
= unent v }
5561 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5564 prerr_endline
("Error processing attribute (`" ^
5565 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5568 let rec fold c = function
5571 let c = apply c k v in
5574 fold { c with keyhashes
= copykeyhashes c } attrs
;
5577 let fromstring f pos
n v d =
5580 dolog "Error processing attribute (%S=%S) at %d\n%s"
5581 n v pos
(Printexc.to_string exn
)
5586 let bookmark_of attrs
=
5587 let rec fold title page
rely = function
5588 | ("title", v) :: rest
-> fold v page
rely rest
5589 | ("page", v) :: rest
-> fold title v rely rest
5590 | ("rely", v) :: rest
-> fold title page
v rest
5591 | _ :: rest
-> fold title page
rely rest
5592 | [] -> title, page
, rely
5594 fold "invalid" "0" "0" attrs
5598 let rec fold path page
rely pan
= function
5599 | ("path", v) :: rest
-> fold v page
rely pan rest
5600 | ("page", v) :: rest
-> fold path v rely pan rest
5601 | ("rely", v) :: rest
-> fold path page
v pan rest
5602 | ("pan", v) :: rest
-> fold path page
rely v rest
5603 | _ :: rest
-> fold path page
rely pan rest
5604 | [] -> path, page
, rely, pan
5606 fold "" "0" "0" "0" attrs
5610 let rec fold rs ls
= function
5611 | ("out", v) :: rest
-> fold v ls rest
5612 | ("in", v) :: rest
-> fold rs
v rest
5613 | _ :: rest
-> fold ls rs rest
5619 let setconf dst
src =
5620 dst
.scrollbw
<- src.scrollbw
;
5621 dst
.scrollh
<- src.scrollh
;
5622 dst
.icase
<- src.icase
;
5623 dst
.preload <- src.preload;
5624 dst
.pagebias
<- src.pagebias
;
5625 dst
.verbose
<- src.verbose
;
5626 dst
.scrollstep
<- src.scrollstep
;
5627 dst
.maxhfit
<- src.maxhfit
;
5628 dst
.crophack
<- src.crophack
;
5629 dst
.autoscrollstep
<- src.autoscrollstep
;
5630 dst
.maxwait
<- src.maxwait
;
5631 dst
.hlinks
<- src.hlinks
;
5632 dst
.underinfo
<- src.underinfo
;
5633 dst
.interpagespace <- src.interpagespace;
5634 dst
.zoom <- src.zoom;
5635 dst
.presentation <- src.presentation;
5636 dst
.angle
<- src.angle
;
5637 dst
.winw <- src.winw;
5638 dst
.winh
<- src.winh
;
5639 dst
.savebmarks
<- src.savebmarks
;
5640 dst
.memlimit
<- src.memlimit
;
5641 dst
.proportional
<- src.proportional
;
5642 dst
.texcount
<- src.texcount
;
5643 dst
.sliceheight
<- src.sliceheight
;
5644 dst
.thumbw
<- src.thumbw
;
5645 dst
.jumpback
<- src.jumpback
;
5646 dst
.bgcolor
<- src.bgcolor
;
5647 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5648 dst
.tilew
<- src.tilew
;
5649 dst
.tileh
<- src.tileh
;
5650 dst
.mustoresize
<- src.mustoresize
;
5651 dst
.checkers
<- src.checkers
;
5652 dst
.aalevel
<- src.aalevel
;
5653 dst
.trimmargins
<- src.trimmargins
;
5654 dst
.trimfuzz
<- src.trimfuzz
;
5655 dst
.urilauncher
<- src.urilauncher
;
5656 dst
.colorspace
<- src.colorspace
;
5657 dst
.invert
<- src.invert
;
5658 dst
.colorscale
<- src.colorscale
;
5659 dst
.redirectstderr <- src.redirectstderr;
5660 dst
.ghyllscroll
<- src.ghyllscroll
;
5661 dst
.columns
<- src.columns
;
5662 dst
.beyecolumns
<- src.beyecolumns
;
5663 dst
.selcmd
<- src.selcmd
;
5664 dst
.updatecurs
<- src.updatecurs
;
5665 dst
.pathlauncher
<- src.pathlauncher
;
5666 dst
.keyhashes
<- copykeyhashes src;
5670 let h = Hashtbl.create
10 in
5671 let dc = { defconf with angle
= defconf.angle
} in
5672 let rec toplevel v t spos
_ =
5674 | Vdata
| Vcdata
| Vend
-> v
5675 | Vopen
("llppconfig", _, closed
) ->
5678 else { v with f = llppconfig
}
5680 error
"unexpected subelement at top level" s spos
5681 | Vclose
_ -> error
"unexpected close at top level" s spos
5683 and llppconfig
v t spos
_ =
5685 | Vdata
| Vcdata
-> v
5686 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5687 | Vopen
("defaults", attrs
, closed
) ->
5688 let c = config_of dc attrs
in
5692 else { v with f = defaults
}
5694 | Vopen
("ui-font", attrs
, closed
) ->
5695 let rec getsize size
= function
5697 | ("size", v) :: rest
->
5699 fromstring int_of_string spos
"size" v fstate.fontsize
in
5701 | l -> getsize size l
5703 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5706 else { v with f = uifont
(Buffer.create
10) }
5708 | Vopen
("doc", attrs
, closed
) ->
5709 let pathent, spage
, srely
, span
= doc_of attrs
in
5710 let path = unent pathent
5711 and pageno = fromstring int_of_string spos
"page" spage
0
5712 and rely = fromstring float_of_string spos
"rely" srely
0.0
5713 and pan
= fromstring int_of_string spos
"pan" span
0 in
5714 let c = config_of dc attrs
in
5715 let anchor = (pageno, rely) in
5717 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5718 else { v with f = doc
path pan
anchor c [] }
5721 error
"unexpected subelement in llppconfig" s spos
5723 | Vclose
"llppconfig" -> { v with f = toplevel }
5724 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5726 and defaults
v t spos
_ =
5728 | Vdata
| Vcdata
-> v
5729 | Vend
-> error
"unexpected end of input in defaults" s spos
5730 | Vopen
("keymap", attrs
, closed
) ->
5732 try List.assoc
"mode" attrs
5733 with Not_found
-> "global" in
5738 let h = findkeyhash dc modename in
5739 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5742 { v with f = pkeymap
ret KeyMap.empty }
5744 | Vopen
(_, _, _) ->
5745 error
"unexpected subelement in defaults" s spos
5747 | Vclose
"defaults" ->
5748 { v with f = llppconfig
}
5750 | Vclose
_ -> error
"unexpected close in defaults" s spos
5752 and uifont
b v t spos
epos =
5755 Buffer.add_substring
b s spos
(epos - spos
);
5757 | Vopen
(_, _, _) ->
5758 error
"unexpected subelement in ui-font" s spos
5759 | Vclose
"ui-font" ->
5760 if String.length
!fontpath = 0
5761 then fontpath := Buffer.contents
b;
5762 { v with f = llppconfig
}
5763 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5764 | Vend
-> error
"unexpected end of input in ui-font" s spos
5766 and doc
path pan
anchor c bookmarks
v t spos
_ =
5768 | Vdata
| Vcdata
-> v
5769 | Vend
-> error
"unexpected end of input in doc" s spos
5770 | Vopen
("bookmarks", _, closed
) ->
5773 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5775 | Vopen
("keymap", attrs
, closed
) ->
5777 try List.assoc
"mode" attrs
5778 with Not_found
-> "global"
5784 let h = findkeyhash c modename in
5785 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5786 doc
path pan
anchor c bookmarks
5788 { v with f = pkeymap
ret KeyMap.empty }
5790 | Vopen
(_, _, _) ->
5791 error
"unexpected subelement in doc" s spos
5794 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5795 { v with f = llppconfig
}
5797 | Vclose
_ -> error
"unexpected close in doc" s spos
5799 and pkeymap
ret keymap
v t spos
_ =
5801 | Vdata
| Vcdata
-> v
5802 | Vend
-> error
"unexpected end of input in keymap" s spos
5803 | Vopen
("map", attrs
, closed
) ->
5804 let r, l = map_of attrs
in
5805 let kss = fromstring keys_of_string spos
"in" r [] in
5806 let lss = fromstring keys_of_string spos
"out" l [] in
5810 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5811 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5814 then { v with f = pkeymap
ret keymap }
5817 { v with f = skip
"map" f }
5820 error
"unexpected subelement in keymap" s spos
5822 | Vclose
"keymap" ->
5823 { v with f = ret keymap }
5825 | Vclose
_ -> error
"unexpected close in keymap" s spos
5827 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5829 | Vdata
| Vcdata
-> v
5830 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5831 | Vopen
("item", attrs
, closed
) ->
5832 let titleent, spage
, srely
= bookmark_of attrs
in
5833 let page = fromstring int_of_string spos
"page" spage
0
5834 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5835 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5837 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5840 { v with f = skip
"item" f }
5843 error
"unexpected subelement in bookmarks" s spos
5845 | Vclose
"bookmarks" ->
5846 { v with f = doc
path pan
anchor c bookmarks }
5848 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5850 and skip tag
f v t spos
_ =
5852 | Vdata
| Vcdata
-> v
5854 error
("unexpected end of input in skipped " ^ tag
) s spos
5855 | Vopen
(tag'
, _, closed
) ->
5859 let f'
() = { v with f = skip tag
f } in
5860 { v with f = skip tag'
f'
}
5864 else error
("unexpected close in skipped " ^ tag
) s spos
5867 parse
{ f = toplevel; accu = () } s;
5873 let len = in_channel_length ic
in
5874 let s = String.create
len in
5875 really_input ic
s 0 len;
5878 | Parse_error
(msg
, s, pos
) ->
5879 let subs = subs s pos
in
5880 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5881 failwith
("parse error: " ^
s)
5884 failwith
("config load error: " ^
Printexc.to_string exn
)
5890 let dir = Filename.concat
home ".config" in
5891 if Sys.is_directory
dir then dir else home
5894 Filename.concat
dir "llpp.conf"
5897 let confpath = ref defconfpath;;
5900 if Sys.file_exists
!confpath
5903 (try Some
(open_in_bin
!confpath)
5906 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5907 Printexc.to_string exn
);
5916 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5917 Printexc.to_string exn
);
5923 f (Hashtbl.create
0, defconf)
5928 let pc, pb
, px, pa
=
5930 Hashtbl.find h (Filename.basename
state.path)
5931 with Not_found
-> dc, [], 0, (0, 0.0)
5935 state.bookmarks <- pb
;
5937 state.scrollw
<- conf.scrollbw
;
5939 then state.anchor <- pa
;
5940 cbput state.hists
.nav pa
;
5945 let add_attrs bb always
dc c =
5948 then Printf.bprintf bb
"\n %s='%b'" s a
5951 then Printf.bprintf bb
"\n %s='%d'" s a
5954 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5957 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5960 then Printf.bprintf bb
"\n %s='%f'" s a
5964 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5968 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5972 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5976 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5982 | Some
(_N
, _A
, _B
) ->
5983 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5993 else string_of_float
f
5995 Printf.bprintf bb
"\n %s='%s'" s v
6000 | Some
((n, a, b), _) when n > 1 ->
6001 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6007 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6012 then dc.winw, dc.winh
6014 match state.fullscreen
with
6016 | None
-> c.winw, c.winh
6018 let zoom, presentation, interpagespace, maxwait
=
6020 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6022 match state.mode with
6023 | Birdseye
(bc
, _, _, _, _) ->
6024 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6025 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6027 oi
"width" w dc.winw;
6028 oi
"height" h dc.winh
;
6029 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6030 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6031 ob "case-insensitive-search" c.icase
dc.icase
;
6032 ob "preload" c.preload dc.preload;
6033 oi
"page-bias" c.pagebias
dc.pagebias
;
6034 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6035 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6036 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6037 ob "crop-hack" c.crophack
dc.crophack
;
6038 oW
"throttle" maxwait
dc.maxwait
;
6039 ob "highlight-links" c.hlinks
dc.hlinks
;
6040 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6041 oi
"vertical-margin" interpagespace dc.interpagespace;
6042 oz
"zoom" zoom dc.zoom;
6043 ob "presentation" presentation dc.presentation;
6044 oi
"rotation-angle" c.angle
dc.angle
;
6045 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6046 ob "proportional-display" c.proportional
dc.proportional
;
6047 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6048 oi
"tex-count" c.texcount
dc.texcount
;
6049 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6050 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6051 ob "persistent-location" c.jumpback
dc.jumpback
;
6052 oc
"background-color" c.bgcolor
dc.bgcolor
;
6053 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6054 oi
"tile-width" c.tilew
dc.tilew
;
6055 oi
"tile-height" c.tileh
dc.tileh
;
6056 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6057 ob "checkers" c.checkers
dc.checkers
;
6058 oi
"aalevel" c.aalevel
dc.aalevel
;
6059 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6060 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6061 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6062 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6063 oC
"color-space" c.colorspace
dc.colorspace
;
6064 ob "invert-colors" c.invert
dc.invert
;
6065 oF
"brightness" c.colorscale
dc.colorscale
;
6066 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6067 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6068 oco
"columns" c.columns
dc.columns
;
6069 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6070 os
"selection-command" c.selcmd
dc.selcmd
;
6071 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6074 let keymapsbuf always
dc c =
6075 let bb = Buffer.create
16 in
6076 let rec loop = function
6078 | (modename, h) :: rest
->
6079 let dh = findkeyhash dc modename in
6080 if always
|| h <> dh
6082 if Hashtbl.length
h > 0
6084 if Buffer.length
bb > 0
6085 then Buffer.add_char
bb '
\n'
;
6086 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6087 Hashtbl.iter
(fun i
o ->
6088 let isdifferent = always
||
6090 let dO = Hashtbl.find dh i
in
6092 with Not_found
-> true
6097 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6098 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6099 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6100 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6101 Buffer.add_string
bb (Wsi.keyname
k);
6104 let rec loop = function
6106 | km
:: [] -> addkm km
6107 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6111 Buffer.add_string
bb "<map in='";
6115 Buffer.add_string
bb "' out='";
6117 Buffer.add_string
bb "'/>\n"
6120 Buffer.add_string
bb "' out='";
6122 Buffer.add_string
bb "'/>\n"
6124 | KMmulti
(ins, kms
) ->
6125 Buffer.add_char
bb ' '
;
6127 Buffer.add_string
bb "' out='";
6129 Buffer.add_string
bb "'/>\n"
6131 Buffer.add_string
bb "</keymap>";
6141 let uifontsize = fstate.fontsize
in
6142 let bb = Buffer.create
32768 in
6144 let dc = if conf.bedefault
then conf else dc in
6145 Buffer.add_string
bb "<llppconfig>\n";
6147 if String.length
!fontpath > 0
6149 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6155 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6158 Buffer.add_string
bb "<defaults ";
6159 add_attrs bb true dc dc;
6160 let kb = keymapsbuf true dc dc in
6161 if Buffer.length
kb > 0
6163 Buffer.add_string
bb ">\n";
6164 Buffer.add_buffer
bb kb;
6165 Buffer.add_string
bb "\n</defaults>\n";
6167 else Buffer.add_string
bb "/>\n";
6169 let adddoc path pan
anchor c bookmarks =
6170 if bookmarks == [] && c = dc && anchor = emptyanchor
6173 Printf.bprintf
bb "<doc path='%s'"
6174 (enent
path 0 (String.length
path));
6176 if anchor <> emptyanchor
6178 let n, y = anchor in
6179 Printf.bprintf
bb " page='%d'" n;
6182 Printf.bprintf
bb " rely='%f'" y
6187 then Printf.bprintf
bb " pan='%d'" pan
;
6189 add_attrs bb false dc c;
6190 let kb = keymapsbuf false dc c in
6192 begin match bookmarks with
6194 if Buffer.length
kb > 0
6196 Buffer.add_string
bb ">\n";
6197 Buffer.add_buffer
bb kb;
6198 Buffer.add_string
bb "</doc>\n";
6200 else Buffer.add_string
bb "/>\n"
6202 Buffer.add_string
bb ">\n<bookmarks>\n";
6203 List.iter
(fun (title, _level
, (page, rely)) ->
6205 "<item title='%s' page='%d'"
6206 (enent
title 0 (String.length
title))
6211 Printf.bprintf
bb " rely='%f'" rely
6213 Buffer.add_string
bb "/>\n";
6215 Buffer.add_string
bb "</bookmarks>";
6216 if Buffer.length
kb > 0
6218 Buffer.add_string
bb "\n";
6219 Buffer.add_buffer
bb kb;
6221 Buffer.add_string
bb "\n</doc>\n";
6227 match state.mode with
6228 | Birdseye
(c, pan, _, _, _) ->
6230 match conf.columns
with
6231 | Some
((c, _, _), _) -> Some
c
6234 match c.columns
with
6235 | Some
(c, _) -> Some
(c, [||])
6238 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6239 | _ -> state.x, conf
6241 let basename = Filename.basename state.path in
6242 adddoc basename pan (getanchor ())
6245 match state.autoscroll
with
6247 | None
-> conf.autoscrollstep
}
6248 (if conf.savebmarks
then state.bookmarks else []);
6250 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6252 then adddoc path x y c bookmarks
6254 Buffer.add_string
bb "</llppconfig>";
6257 if Buffer.length
bb > 0
6260 let tmp = !confpath ^
".tmp" in
6261 let oc = open_out_bin
tmp in
6262 Buffer.output_buffer
oc bb;
6264 Unix.rename
tmp !confpath;
6267 ("error while saving configuration: " ^
Printexc.to_string exn
)
6274 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6275 "<password> Set password");
6277 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6278 "<path> Set path to the user interface font");
6280 ("-c", Arg.String
(fun s -> Config.confpath := s),
6281 "<path> Set path to the configuration file");
6283 ("-v", Arg.Unit
(fun () ->
6285 "%s\nconfiguration path: %s\n"
6289 exit
0), " Print version and exit");
6292 (fun s -> state.path <- s)
6293 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6295 if String.length
state.path = 0
6296 then (prerr_endline
"file name missing"; exit
1);
6300 let globalkeyhash = findkeyhash conf "global" in
6301 state.wsfd
<- Wsi.init
(object
6302 method display = display ()
6303 method reshape w h = reshape w h
6304 method mouse b d x y m = mouse b d x y m
6305 method motion x y = state.mpos
<- (x, y); motion x y
6306 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6308 match state.keystate
with
6313 try Hashtbl.find globalkeyhash km
6315 let modehash = state.uioh#
modehash in
6316 try Hashtbl.find modehash km
6317 with Not_found
-> KMinsrt
(k, m)
6319 | KMinsrt
(k, m) -> keyboard k m
6320 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6321 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6323 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land m = m'
->
6324 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6325 state.keystate
<- KSnone
6326 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land m = m'
->
6327 state.keystate
<- KSinto
(keys
, insrt
)
6329 state.keystate
<- KSnone
6331 method enter
x y = state.mpos
<- (x, y); pmotion x y
6332 method leave = state.mpos
<- (-1, -1)
6333 method quit
= raise Quit
6334 end) conf.winw conf.winh
;
6337 List.exists
GlMisc.check_extension
6338 [ "GL_ARB_texture_rectangle"
6339 ; "GL_EXT_texture_recangle"
6340 ; "GL_NV_texture_rectangle" ]
6342 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6344 let cr, sw = Unix.pipe
()
6345 and sr
, cw
= Unix.pipe
() in
6352 setcheckers conf.checkers
;
6356 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6357 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6362 state.text <- "Opening " ^
state.path;
6363 opendoc state.path state.password
;
6365 setfontsize fstate.fontsize
;
6366 doreshape conf.winw conf.winh
;
6368 let rec loop deadline
=
6370 match state.errfd
with
6371 | None
-> [state.sr
; state.wsfd
]
6372 | Some fd
-> [state.sr
; state.wsfd
; fd
]
6376 state.redisplay
<- false;
6383 if deadline
= infinity
6385 else max
0.0 (deadline
-. now)
6390 try Unix.select
r [] [] timeout
6391 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6397 if state.ghyll
== noghyll
6399 match state.autoscroll
with
6400 | Some step
when step
!= 0 ->
6401 let y = state.y + step
in
6405 else if y >= state.maxy then 0 else y
6408 if state.mode = View
6409 then state.text <- "";
6412 else deadline
+. 0.01
6417 let rec checkfds = function
6419 | fd
:: rest
when fd
= state.sr
->
6420 let cmd = readcmd state.sr
in
6424 | fd
:: rest
when fd
= state.wsfd
->
6429 let s = String.create
80 in
6430 let n = Unix.read fd
s 0 80 in
6431 if conf.redirectstderr
6433 Buffer.add_substring
state.errmsgs
s 0 n;
6434 state.newerrmsgs
<- true;
6435 state.redisplay
<- true;
6438 prerr_string
(String.sub
s 0 n);
6446 if deadline
= infinity
6450 match state.autoscroll
with
6451 | Some step
when step
!= 0 -> deadline1
6452 | _ -> if state.ghyll
== noghyll then infinity
else deadline1