6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: string -> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> int -> int -> int -> int -> int =
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlink2
: opaque
-> int -> under
= "ml_getlink2";;
96 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
99 let platform_to_string = function
100 | Punknown
-> "unknown"
104 | Pfreebsd
-> "FreeBSD"
105 | Pdragonflybsd
-> "DragonflyBSD"
106 | Popenbsd
-> "OpenBSD"
107 | Pnetbsd
-> "NetBSD"
108 | Pcygwin
-> "Cygwin"
111 let platform = platform ();;
117 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
120 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
122 type mpos
= int * int
124 | Msel
of (mpos
* mpos
)
126 | Mscrolly
| Mscrollx
127 | Mzoom
of (int * int)
128 | Mzoomrect
of (mpos
* mpos
)
132 type textentry
= string * string * onhist
option * onkey
* ondone
133 and onkey
= string -> int -> te
134 and ondone
= string -> unit
135 and histcancel
= unit -> unit
136 and onhist
= ((histcmd
-> string) * histcancel
)
137 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
142 | TEswitch
of textentry
153 let bound v minv maxv
=
154 max minv
(min maxv v
);
158 { store
= Array.create n v
165 let drawstring size x y s
=
167 Gl.enable `texture_2d
;
168 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
169 ignore
(drawstr size x y s
);
171 Gl.disable `texture_2d
;
174 let drawstring1 size x y s
=
178 let drawstring2 size x y fmt
=
179 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
182 let cbcap b
= Array.length b
.store
;;
187 b
.wc
<- (b
.wc
+ 1) mod cap;
189 b
.len
<- min
(b
.len
+ 1) cap;
192 let cbempty b
= b
.len
= 0;;
194 let cbgetg b circular dir
=
198 let rc = b
.rc + dir
in
210 else max
0 (min
rc (b
.len
-1))
216 let cbget b
= cbgetg b
false;;
217 let cbgetc b
= cbgetg b
true;;
234 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
235 dolog " WxH %dx%d" l
.pagew l
.pageh
;
236 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
237 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
238 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
242 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
244 dolog " x0,y0=(% f, % f)" x0 y0
;
245 dolog " x1,y1=(% f, % f)" x1 y1
;
246 dolog " x2,y2=(% f, % f)" x2 y2
;
247 dolog " x3,y3=(% f, % f)" x3 y3
;
252 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
253 and multicol
= columncount
* covercount
* covercount
255 and columncount
= int
256 and covercount
= int;;
259 { mutable scrollbw
: int
260 ; mutable scrollh
: int
261 ; mutable icase
: bool
262 ; mutable preload
: bool
263 ; mutable pagebias
: int
264 ; mutable verbose
: bool
265 ; mutable debug
: bool
266 ; mutable scrollstep
: int
267 ; mutable maxhfit
: bool
268 ; mutable crophack
: bool
269 ; mutable autoscrollstep
: int
270 ; mutable maxwait
: float option
271 ; mutable hlinks
: bool
272 ; mutable underinfo
: bool
273 ; mutable interpagespace
: interpagespace
274 ; mutable zoom
: float
275 ; mutable presentation
: bool
276 ; mutable angle
: angle
279 ; mutable savebmarks
: bool
280 ; mutable proportional
: proportional
281 ; mutable trimmargins
: trimmargins
282 ; mutable trimfuzz
: irect
283 ; mutable memlimit
: memsize
284 ; mutable texcount
: texcount
285 ; mutable sliceheight
: sliceheight
286 ; mutable thumbw
: width
287 ; mutable jumpback
: bool
288 ; mutable bgcolor
: float * float * float
289 ; mutable bedefault
: bool
290 ; mutable scrollbarinpm
: bool
291 ; mutable tilew
: int
292 ; mutable tileh
: int
293 ; mutable mustoresize
: memsize
294 ; mutable checkers
: bool
295 ; mutable aalevel
: int
296 ; mutable urilauncher
: string
297 ; mutable pathlauncher
: string
298 ; mutable colorspace
: colorspace
299 ; mutable invert
: bool
300 ; mutable colorscale
: float
301 ; mutable redirectstderr
: bool
302 ; mutable ghyllscroll
: (int * int * int) option
303 ; mutable columns
: columns
option
304 ; mutable beyecolumns
: columncount
option
305 ; mutable selcmd
: string
306 ; mutable updatecurs
: bool
307 ; mutable keyhashes
: (string * keyhash
) list
311 type anchor
= pageno
* top
;;
313 type outline
= string * int * anchor
;;
315 type rect
= float * float * float * float * float * float * float * float;;
317 type tile
= opaque
* pixmapsize
* elapsed
318 and elapsed
= float;;
319 type pagemapkey
= pageno
* gen
;;
320 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
324 let emptyanchor = (0, 0.0);;
326 type infochange
= | Memused
| Docinfo
| Pdim
;;
328 class type uioh
= object
329 method display
: unit
330 method key
: int -> int -> uioh
331 method button
: int -> bool -> int -> int -> int -> uioh
332 method motion
: int -> int -> uioh
333 method pmotion
: int -> int -> uioh
334 method infochanged
: infochange
-> unit
335 method scrollpw
: (int * float * float)
336 method scrollph
: (int * float * float)
337 method modehash
: keyhash
341 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
342 | Textentry
of (textentry
* onleave
)
344 | LinkNav
of linktarget
345 and onleave
= leavetextentrystatus
-> unit
346 and leavetextentrystatus
= | Cancel
| Confirm
347 and helpitem
= string * int * action
350 | Action
of (uioh
-> uioh
)
352 | Ltexact
of (pageno
* int)
356 let isbirdseye = function Birdseye _
-> true | _
-> false;;
357 let istextentry = function Textentry _
-> true | _
-> false;;
361 | Loading
of (page
* gen
)
363 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
365 | Outlining
of outline list
368 let emptykeyhash = Hashtbl.create
0;;
369 let nouioh : uioh
= object (self
)
371 method key _ _
= self
372 method button _ _ _ _ _
= self
373 method motion _ _
= self
374 method pmotion _ _
= self
375 method infochanged _
= ()
376 method scrollpw
= (0, nan
, nan
)
377 method scrollph
= (0, nan
, nan
)
378 method modehash
= emptykeyhash
382 { mutable sr
: Unix.file_descr
383 ; mutable sw
: Unix.file_descr
384 ; mutable wsfd
: Unix.file_descr
385 ; mutable errfd
: Unix.file_descr
option
386 ; mutable stderr
: Unix.file_descr
387 ; mutable errmsgs
: Buffer.t
388 ; mutable newerrmsgs
: bool
392 ; mutable scrollw
: int
393 ; mutable hscrollh
: int
394 ; mutable anchor
: anchor
395 ; mutable ranchors
: (string * string * anchor
) list
397 ; mutable layout
: page list
398 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
399 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
400 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
401 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
402 ; mutable pagecount
: int
403 ; mutable currently
: currently
404 ; mutable mstate
: mstate
405 ; mutable searchpattern
: string
406 ; mutable rects
: (pageno
* recttype
* rect
) list
407 ; mutable rects1
: (pageno
* recttype
* rect
) list
408 ; mutable text
: string
409 ; mutable fullscreen
: (width
* height
) option
410 ; mutable mode
: mode
411 ; mutable uioh
: uioh
412 ; mutable outlines
: outline array
413 ; mutable bookmarks
: outline list
414 ; mutable path
: string
415 ; mutable password
: string
416 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
417 ; mutable memused
: memsize
419 ; mutable throttle
: (page list
* int * float) option
420 ; mutable autoscroll
: int option
421 ; mutable ghyll
: (int option -> unit)
422 ; mutable help
: helpitem array
423 ; mutable docinfo
: (int * string) list
424 ; mutable texid
: GlTex.texture_id
option
426 ; mutable prevzoom
: float
427 ; mutable progress
: float
428 ; mutable redisplay
: bool
429 ; mutable mpos
: mpos
430 ; mutable keystate
: keystate
431 ; mutable glinks
: bool
434 { pat
: string circbuf
435 ; pag
: string circbuf
436 ; nav
: anchor circbuf
437 ; sel
: string circbuf
458 ; presentation
= false
463 ; proportional
= true
464 ; trimmargins
= false
465 ; trimfuzz
= (0,0,0,0)
466 ; memlimit
= 32 lsl 20
471 ; bgcolor
= (0.5, 0.5, 0.5)
473 ; scrollbarinpm
= true
476 ; mustoresize
= 128 lsl 20
481 | Plinux
| Pfreebsd
| Pdragonflybsd
482 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
483 | Posx
-> "open \"%s\""
484 | Pcygwin
-> "cygstart %s"
485 | Punknown
-> "echo %s")
486 ; pathlauncher
= "lp \"%s\""
489 | Plinux
| Pfreebsd
| Pdragonflybsd
490 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
497 ; redirectstderr
= false
503 let mk n
= (n
, Hashtbl.create
1) in
516 let findkeyhash c name
=
517 try List.assoc name c
.keyhashes
518 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
521 let conf = { defconf with angle
= defconf.angle
};;
524 { mutable fontsize
: int
525 ; mutable wwidth
: float
526 ; mutable maxrows
: int
538 fstate.fontsize
<- n
;
539 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
540 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
544 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
545 let len = String.length s
in
546 if colonpos >= 0 && colonpos + 3 < len
548 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
551 try String.rindex_from s
colonpos ' '
555 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
558 | "http" | "ftp" | "mailto" ->
560 try String.index_from s
colonpos ' '
561 with Not_found
-> len
563 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
571 let shell, farg
= "/bin/sh", "-c" in
573 let args = [|shell; farg
; s
|] in
574 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
578 if String.length
conf.urilauncher
= 0
579 then print_endline uri
581 let url = geturl uri
in
582 if String.length
url = 0
583 then print_endline uri
585 let re = Str.regexp
"%s" in
586 let command = Str.global_replace
re url conf.urilauncher
in
590 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
596 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
597 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
601 let strings = version () :: "" :: Help.keys
in
604 let url = geturl s
in
605 if String.length
url > 0
606 then (s
, 0, Action
(fun u
-> gotouri url; u
))
607 else (s
, 0, Noaction
)
612 let firstgeomcmds = "", [];;
619 ; stderr
= Unix.stderr
620 ; errmsgs
= Buffer.create
0
627 ; anchor
= emptyanchor
631 ; tilelru
= Queue.create
()
632 ; pagemap
= Hashtbl.create
10
633 ; tilemap
= Hashtbl.create
10
648 ; geomcmds
= firstgeomcmds
650 { nav
= cbnew 10 (0, 0.0)
676 Printf.kprintf prerr_endline fmt
678 Printf.kprintf ignore fmt
682 if String.length
conf.pathlauncher
= 0
683 then print_endline
state.path
685 let re = Str.regexp
"%s" in
686 let command = Str.global_replace
re state.path
conf.pathlauncher
in
690 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
695 let redirectstderr () =
696 if conf.redirectstderr
698 let rfd, wfd
= Unix.pipe
() in
699 state.stderr
<- Unix.dup
Unix.stderr
;
700 state.errfd
<- Some
rfd;
701 Unix.dup2 wfd
Unix.stderr
;
703 state.newerrmsgs
<- false;
704 begin match state.errfd
with
707 Unix.dup2
state.stderr
Unix.stderr
;
711 prerr_string
(Buffer.contents
state.errmsgs
);
713 Buffer.clear
state.errmsgs
;
719 let postRedisplay who
=
721 then prerr_endline
("redisplay for " ^ who
);
722 state.redisplay
<- true;
726 let getopaque pageno
=
727 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
728 with Not_found
-> None
731 let putopaque pageno opaque
=
732 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
735 let pagetranslatepoint l x y
=
736 let dy = y
- l
.pagedispy
in
737 let y = dy + l
.pagey
in
738 let dx = x
- l
.pagedispx
in
739 let x = dx + l
.pagex
in
746 begin match getopaque l
.pageno
with
748 let x0 = l
.pagedispx
in
749 let x1 = x0 + l
.pagevw
in
750 let y0 = l
.pagedispy
in
751 let y1 = y0 + l
.pagevh
in
752 if y >= y0 && y <= y1 && x >= x0 && x <= x1
754 let px, py
= pagetranslatepoint l
x y in
755 match whatsunder opaque
px py
with
768 state.text
<- Printf.sprintf
"%c%s" c s
;
769 G.postRedisplay "showtext";
772 let updateunder x y =
773 match getunder x y with
774 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
776 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
777 Wsi.setcursor
Wsi.CURSOR_INFO
778 | Ulinkgoto
(page
, _
) ->
780 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
781 Wsi.setcursor
Wsi.CURSOR_INFO
783 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
784 Wsi.setcursor
Wsi.CURSOR_TEXT
786 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
787 Wsi.setcursor
Wsi.CURSOR_INHERIT
789 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
790 Wsi.setcursor
Wsi.CURSOR_INHERIT
792 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
793 Wsi.setcursor
Wsi.CURSOR_INHERIT
794 | Uremote
(filename
, pageno
) ->
795 if conf.underinfo
then showtext 'r'
796 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
797 Wsi.setcursor
Wsi.CURSOR_INFO
800 let showlinktype under
=
806 showtext 'u'
("ri: " ^ uri
)
807 | Ulinkgoto
(page
, _
) ->
808 showtext 'p'
("age: " ^ string_of_int
(page
+1));
810 showtext '
f'
("ont: " ^ s
);
812 showtext 'u'
("nexpected: " ^ s
);
814 showtext 'l'
("aunch: " ^ s
);
816 showtext 'n'
("amed: " ^ s
);
817 | Uremote
(filename
, pageno
) ->
818 showtext 'r'
(Printf.sprintf
"emote: %s (%d)" filename pageno
);
822 let b = Buffer.create
(String.length s
+ 1) in
823 Buffer.add_string
b s
;
828 let colorspace_of_string s
=
829 match String.lowercase s
with
833 | _
-> failwith
"invalid colorspace"
836 let int_of_colorspace = function
842 let colorspace_of_int = function
846 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
849 let colorspace_to_string = function
855 let intentry_with_suffix text key
=
857 if key
>= 32 && key
< 127
861 match Char.lowercase
c with
863 let text = addchar text c in
867 let text = addchar text c in
871 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
875 let columns_to_string (n
, a
, b) =
877 then Printf.sprintf
"%d" n
878 else Printf.sprintf
"%d,%d,%d" n a
b;
881 let columns_of_string s
=
883 (int_of_string s
, 0, 0)
885 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
890 let n = Unix.read fd
s 0 4 in
891 if n != 4 then failwith
"incomplete read(len)";
893 lor (Char.code
s.[0] lsl 24)
894 lor (Char.code
s.[1] lsl 16)
895 lor (Char.code
s.[2] lsl 8)
896 lor (Char.code
s.[3] lsl 0)
898 let s = String.create
len in
899 let n = Unix.read fd
s 0 len in
900 if n != len then failwith
"incomplete read(data)";
904 let btod b = if b then 1 else 0;;
907 let b = Buffer.create
16 in
908 Buffer.add_string
b "llll";
911 let s = Buffer.contents
b in
912 let n = String.length
s in
914 (* dolog "wcmd %S" (String.sub s 4 len); *)
915 s.[0] <- Char.chr
((len lsr 24) land 0xff);
916 s.[1] <- Char.chr
((len lsr 16) land 0xff);
917 s.[2] <- Char.chr
((len lsr 8) land 0xff);
918 s.[3] <- Char.chr
(len land 0xff);
919 let n'
= Unix.write
state.sw
s 0 n in
920 if n'
!= n then failwith
"write failed";
927 let d = conf.winh
- h
in
934 let rec f pn ph pi fh l
=
936 | (n, _
, h
, _
) :: rest
->
937 let ips = calcips h
in
942 if isbirdseye state.mode
&& pn
= 0
947 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
952 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
956 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
959 let fh = f 0 0 0 0 state.pdims
in
964 match conf.columns
with
965 | None
-> calcheight ()
967 if Array.length
b > 0
969 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
974 let getpageyh pageno
=
975 let rec f pn ph pi
y l
=
977 | (n, _
, h
, _
) :: rest
->
978 let ips = calcips h
in
981 let h = if n = pageno
then h else ph
in
982 if conf.presentation
&& n = pageno
984 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
986 y + (pageno
- pn
) * (ph
+ pi
), h
988 let y = y + (if conf.presentation
then pi
else 0) in
989 let y = y + (n - pn
) * (ph
+ pi
) in
993 y + (pageno
- pn
) * (ph
+ pi
), ph
995 f 0 0 0 0 state.pdims
998 let getpageyh pageno
=
999 match conf.columns
with
1000 | None
-> getpageyh pageno
1002 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1006 let getpagedim pageno
=
1009 | (n, _
, _
, _
) as pdim
:: rest
->
1011 then (if n = pageno
then pdim
else ppdim
)
1016 f (-1, -1, -1, -1) state.pdims
1019 let getpagey pageno
= fst
(getpageyh pageno
);;
1021 let nogeomcmds cmds
=
1023 | s, [] -> String.length
s = 0
1028 let sh = sh - state.hscrollh
in
1029 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1030 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1032 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1033 let ips = calcips h in
1035 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1039 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1041 prev
, pdims
, pdimno
, 0
1043 let dy = dy + yinc in
1044 let py = py + yinc in
1045 if pageno
= state.pagecount
|| dy >= sh
1050 if py + h <= vy - yinc
1052 let py = py + h + ips in
1053 let dy = max
0 (py - y) in
1054 f ~pageno
:(pageno
+1)
1062 let pagey = vy - py in
1063 let pagevh = h - pagey in
1064 let pagevh = min
(sh - dy) pagevh in
1065 let off = if yinc > 0 then py - vy else 0 in
1066 let py = py + h + ips in
1069 if state.w
< conf.winw
- state.scrollw
1070 then (conf.winw
- state.scrollw
- state.w
) / 2
1073 let dispx = xoff + state.x in
1079 let lw = w
- pagex in
1080 min
lw (conf.winw
- state.scrollw
)
1084 ; pagedimno
= pdimno
1088 ; pagey = pagey + off
1090 ; pagevh = pagevh - off
1092 ; pagedispy
= dy + off
1095 let accu = e :: accu in
1096 f ~pageno
:(pageno
+1)
1104 if nogeomcmds state.geomcmds
1122 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1123 let sh = sh - state.hscrollh
in
1124 let rec fold accu n =
1125 if n = Array.length
b
1128 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1131 || n = state.pagecount
- coverB
1132 || (n - coverA
) mod columns
= columns
- 1)
1138 let pagey = max
0 (y - vy) in
1139 let pagedispy = if pagey > 0 then 0 else vy - y in
1140 let pagedispx, pagex, pagevw =
1142 if n = coverA
- 1 || n = state.pagecount
- coverB
1143 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1144 else dx + xoff + state.x
1147 then 0, -pdx, w
+ pdx
1148 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1150 let pagevh = min
(h - pagey) (sh - pagedispy) in
1151 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1155 ; pagedimno
= pdimno
1162 ; pagedispx = pagedispx
1163 ; pagedispy = pagedispy
1174 if nogeomcmds state.geomcmds
1175 then List.rev
(fold [] 0)
1180 match conf.columns
with
1181 | None
-> layout1 y sh
1182 | Some
c -> layoutN c y sh
1186 let y = state.y + incr
in
1188 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1193 let tilex = l
.pagex mod conf.tilew
in
1194 let tiley = l
.pagey mod conf.tileh
in
1196 let col = l
.pagex / conf.tilew
in
1197 let row = l
.pagey / conf.tileh
in
1200 let a = l
.pagew
- l
.pagex in
1201 let b = conf.winw
- state.scrollw
in
1203 and vh
= l
.pagevh in
1205 let rec rowloop row y0 dispy
h =
1209 let dh = conf.tileh
- y0 in
1210 let dh = min
h dh in
1211 let rec colloop col x0 dispx w
=
1215 let dw = conf.tilew
- x0 in
1216 let dw = min w
dw in
1218 f col row dispx dispy
x0 y0 dw dh;
1219 colloop (col+1) 0 (dispx+dw) (w
-dw)
1222 colloop col tilex l
.pagedispx vw;
1223 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1227 then rowloop row tiley l
.pagedispy vh
;
1230 let gettileopaque l
col row =
1232 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1234 try Some
(Hashtbl.find
state.tilemap
key)
1235 with Not_found
-> None
1238 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1239 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1240 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1243 let drawtiles l color
=
1245 let f col row x y tilex tiley w
h =
1246 match gettileopaque l
col row with
1247 | Some
(opaque
, _
, t
) ->
1248 let params = x, y, w
, h, tilex, tiley in
1252 GlFunc.blend_func `zero `one_minus_src_color
;
1254 drawtile
params opaque
;
1256 then Gl.disable `blend
;
1259 let s = Printf.sprintf
1263 let w = measurestr
fstate.fontsize
s in
1264 GlMisc.push_attrib
[`current
];
1265 GlDraw.color
(0.0, 0.0, 0.0);
1267 (float (x-2), float (y-2))
1268 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1269 GlDraw.color
(1.0, 1.0, 1.0);
1270 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1271 GlMisc.pop_attrib
();
1276 let lw = conf.winw
- state.scrollw
- x in
1279 let lh = conf.winh
- y in
1282 Gl.enable `texture_2d
;
1283 begin match state.texid
with
1285 GlTex.bind_texture `texture_2d id
;
1288 and x1 = float (x+w)
1289 and y1 = float (y+h) in
1291 let tw = float w /. 64.0
1292 and th
= float h /. 64.0 in
1293 let tx0 = float tilex /. 64.0
1294 and ty0
= float tiley /. 64.0 in
1296 and ty1
= ty0
+. th
in
1297 GlDraw.begins `quads
;
1298 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1299 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1300 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1301 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1304 Gl.disable `texture_2d
;
1306 GlDraw.color
(1.0, 1.0, 1.0);
1309 (float (x+w), float (y+h));
1311 if w > 128 && h > fstate.fontsize
+ 10
1313 GlDraw.color
(0.0, 0.0, 0.0);
1316 then (col*conf.tilew
, row*conf.tileh
)
1319 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1326 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1328 let tilevisible1 l
x y =
1330 and ax1
= l
.pagex + l
.pagevw
1332 and ay1
= l
.pagey + l
.pagevh in
1336 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1337 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1339 let rx0 = max
ax0 bx0
1340 and ry0
= max ay0 by0
1341 and rx1
= min ax1
bx1
1342 and ry1
= min ay1 by1
in
1344 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1345 nonemptyintersection
1348 let tilevisible layout n x y =
1349 let rec findpageinlayout = function
1350 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1351 | _
:: rest
-> findpageinlayout rest
1354 findpageinlayout layout
1357 let tileready l
x y =
1358 tilevisible1 l
x y &&
1359 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1362 let tilepage n p
layout =
1363 let rec loop = function
1367 let f col row _ _ _ _ _ _
=
1368 if state.currently
= Idle
1370 match gettileopaque l
col row with
1373 let x = col*conf.tilew
1374 and y = row*conf.tileh
in
1376 let w = l
.pagew
- x in
1380 let h = l
.pageh
- y in
1383 wcmd "tile %s %d %d %d %d" p
x y w h;
1386 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1387 conf.tilew
, conf.tileh
1396 if nogeomcmds state.geomcmds
1400 let preloadlayout visiblepages
=
1401 let presentation = conf.presentation in
1402 let interpagespace = conf.interpagespace in
1403 let maxy = state.maxy in
1404 conf.presentation <- false;
1405 conf.interpagespace <- 0;
1406 state.maxy <- calcheight ();
1408 match visiblepages
with
1410 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1412 let y = if y < conf.winh
then 0 else y - conf.winh
in
1413 let h = state.y - y + conf.winh
*3 in
1414 let pages = layout y h in
1415 conf.presentation <- presentation;
1416 conf.interpagespace <- interpagespace;
1422 let rec loop pages =
1423 if state.currently
!= Idle
1428 begin match getopaque l
.pageno
with
1430 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1431 state.currently
<- Loading
(l
, state.gen
);
1433 tilepage l
.pageno opaque
pages;
1438 if nogeomcmds state.geomcmds
1444 if conf.preload && state.currently
= Idle
1445 then load (preloadlayout pages);
1448 let layoutready layout =
1449 let rec fold all ls
=
1450 all
&& match ls
with
1452 let seen = ref false in
1453 let allvisible = ref true in
1454 let foo col row _ _ _ _ _ _
=
1456 allvisible := !allvisible &&
1457 begin match gettileopaque l
col row with
1463 fold (!seen && !allvisible) rest
1466 let alltilesvisible = fold true layout in
1471 let y = bound y 0 state.maxy in
1472 let y, layout, proceed
=
1473 match conf.maxwait
with
1474 | Some time
when state.ghyll
== noghyll ->
1475 begin match state.throttle
with
1477 let layout = layout y conf.winh
in
1478 let ready = layoutready layout in
1482 state.throttle
<- Some
(layout, y, now ());
1484 else G.postRedisplay "gotoy showall (None)";
1486 | Some
(_
, _
, started
) ->
1487 let dt = now () -. started
in
1490 state.throttle
<- None
;
1491 let layout = layout y conf.winh
in
1493 G.postRedisplay "maxwait";
1500 let layout = layout y conf.winh
in
1501 if true || layoutready layout
1502 then G.postRedisplay "gotoy ready";
1508 state.layout <- layout;
1509 begin match state.mode
with
1510 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1511 let rec loop = function
1513 state.mode
<- LinkNav
(Ltgendir
0)
1514 | l
:: _
when l
.pageno
= pageno
->
1515 begin match getopaque pageno
with
1517 state.mode
<- LinkNav
(Ltgendir
0)
1519 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1520 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1521 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1522 then state.mode
<- LinkNav
(Ltgendir
0)
1524 | _
:: rest
-> loop rest
1529 begin match state.mode
with
1530 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1531 if not
(pagevisible layout pageno
)
1533 match state.layout with
1536 state.mode
<- Birdseye
(
1537 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1540 | LinkNav
(Ltgendir dir
as lt
) ->
1542 let rec loop = function
1545 match getopaque l
.pageno
with
1551 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1553 if dir
> 0 then LDfirst
else LDlast
1559 | Lnotfound
-> loop rest
1561 showlinktype (getlink opaque
n);
1562 Ltexact
(l
.pageno
, n)
1566 state.mode
<- LinkNav
linknav
1571 state.ghyll
<- noghyll;
1574 let mx, my
= state.mpos
in
1579 let conttiling pageno opaque
=
1580 tilepage pageno opaque
1581 (if conf.preload then preloadlayout state.layout else state.layout)
1584 let gotoy_and_clear_text y =
1585 if not
conf.verbose
then state.text <- "";
1590 match state.layout with
1592 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1595 let getanchory (n, top
) =
1596 let y, h = getpageyh n in
1597 y + (truncate
(top
*. float h));
1600 let gotoanchor anchor
=
1601 gotoy (getanchory anchor
);
1605 cbput state.hists
.nav
(getanchor ());
1609 let anchor = cbgetc state.hists
.nav dir
in
1614 let rec scroll f n a b =
1615 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1617 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1619 then s (float f /. float a)
1622 then 1.0 -. s ((float (f-b) /. float (n-b)))
1629 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1630 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1632 let ins = float a *. iv1
1633 and outs
= float (n-b) *. iv1 in
1635 ins +. outs
+. float ones
1637 let rec set (_N
, _A
, _B
) y sy
=
1638 let sum = summa
1.0 _N _A _B
in
1639 let dy = float (y - sy
) in
1643 then state.ghyll
<- noghyll
1646 let s = scroll n _N _A _B
in
1647 let y1 = y1 +. ((s *. dy) /. sum) in
1648 gotoy_and_clear_text (truncate
y1);
1649 state.ghyll
<- gf (n+1) y1;
1653 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1655 gf 0 (float state.y)
1658 match conf.ghyllscroll
with
1660 gotoy_and_clear_text y
1662 if state.ghyll
== noghyll
1663 then set nab
y state.y
1664 else state.ghyll
(Some
y)
1667 let gotopage n top
=
1668 let y, h = getpageyh n in
1669 let y = y + (truncate
(top
*. float h)) in
1673 let gotopage1 n top
=
1674 let y = getpagey n in
1679 let invalidate s f =
1684 match state.geomcmds
with
1685 | ps
, [] when String.length ps
= 0 ->
1687 state.geomcmds
<- s, [];
1690 state.geomcmds
<- ps
, [s, f];
1692 | ps
, (s'
, _
) :: rest
when s'
= s ->
1693 state.geomcmds
<- ps
, ((s, f) :: rest
);
1696 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1699 let opendoc path password
=
1701 state.password
<- password
;
1702 state.gen
<- state.gen
+ 1;
1703 state.docinfo
<- [];
1705 setaalevel
conf.aalevel
;
1706 Wsi.settitle
("llpp " ^
Filename.basename path
);
1707 wcmd "open %s\000%s\000" path password
;
1708 invalidate "reqlayout"
1710 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1714 let c = c *. conf.colorscale
in
1718 let scalecolor2 (r
, g
, b) =
1719 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1723 let docolumns = function
1725 | Some
((columns
, coverA
, coverB
), _
) ->
1726 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1727 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1728 if pageno
= state.pagecount
1731 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1733 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1734 pdimno+1, pdim
, rest
1739 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1741 (conf.winw
- state.scrollw
- w) / 2,
1742 y + rowh
+ conf.interpagespace, h
1745 if (pageno
- coverA
) mod columns
= 0
1746 then 0, y + rowh
+ conf.interpagespace, h
1747 else x, y, max rowh
h
1750 let rec fixrow m
= if m
= pageno
then () else
1751 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1754 let y = y + (rowh
- h) / 2 in
1755 a.(m
) <- (pdimno, x, y, pdim
);
1759 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1760 then fixrow (pageno
- columns
);
1761 a.(pageno
) <- (pdimno, x, y, pdim
);
1762 let x = x + w + xoff*2 + conf.interpagespace in
1763 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1765 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1766 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1768 docolumns conf.columns
;
1769 state.maxy <- calcheight ();
1771 if state.w <= conf.winw
- state.scrollw
1775 match state.mode
with
1776 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1777 let y, h = getpageyh pageno
in
1778 let top = (conf.winh
- h) / 2 in
1779 gotoy (max
0 (y - top))
1780 | _
-> gotoanchor state.anchor
1784 GlDraw.viewport
0 0 w h;
1785 if state.geomcmds
!= firstgeomcmds && nogeomcmds state.geomcmds
1786 then state.anchor <- getanchor ();
1789 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1792 setfontsize fstate.fontsize
;
1793 GlMat.mode `modelview
;
1794 GlMat.load_identity
();
1796 GlMat.mode `projection
;
1797 GlMat.load_identity
();
1798 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1799 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1800 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1805 else float state.x /. float state.w
1807 invalidate "geometry"
1810 state.x <- truncate
(relx *. float w);
1812 match conf.columns
with
1814 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1816 wcmd "geometry %d %d" w h);
1820 let len = String.length
state.text in
1823 match state.mode
with
1825 | View
-> state.hscrollh
1830 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1831 (x+.w, float (conf.winh
- hscrollh))
1834 let w = float (conf.winw
- state.scrollw
- 1) in
1835 if state.progress
>= 0.0 && state.progress
< 1.0
1837 GlDraw.color
(0.3, 0.3, 0.3);
1838 let w1 = w *. state.progress
in
1840 GlDraw.color
(0.0, 0.0, 0.0);
1844 GlDraw.color
(0.0, 0.0, 0.0);
1848 GlDraw.color
(1.0, 1.0, 1.0);
1849 drawstring fstate.fontsize
1850 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1853 match state.mode
with
1854 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1858 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1860 Printf.sprintf
"%s%s_" prefix
text
1869 if not
(istextentry state.mode
)
1871 let s1 = "(press 'e' to review error messasges)" in
1872 if String.length
s > 0 then s ^
" " ^
s1 else s1
1877 if String.length
s > 0
1882 let len = Queue.length
state.tilelru
in
1884 if state.memused
<= conf.memlimit
1889 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1890 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1891 let (_
, pw
, ph
, _
) = getpagedim n in
1894 && colorspace
= conf.colorspace
1895 && angle
= conf.angle
1900 match state.throttle
with
1903 then preloadlayout state.layout
1905 | Some
(layout, _
, _
) ->
1908 let x = col*conf.tilew
1909 and y = row*conf.tileh
in
1910 tilevisible layout n x y
1912 then Queue.push lruitem
state.tilelru
1914 wcmd "freetile %s" p
;
1915 state.memused
<- state.memused
- s;
1916 state.uioh#infochanged Memused
;
1917 Hashtbl.remove
state.tilemap k
;
1926 Queue.iter
(fun (k
, p
, s) ->
1927 wcmd "freetile %s" p
;
1928 state.memused
<- state.memused
- s;
1929 state.uioh#infochanged Memused
;
1930 Hashtbl.remove
state.tilemap k
;
1932 Queue.clear
state.tilelru
;
1936 let logcurrently = function
1937 | Idle
-> dolog "Idle"
1938 | Loading
(l
, gen
) ->
1939 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1940 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1942 "Tiling %d[%d,%d] page=%s cs=%s angle"
1943 l
.pageno
col row pageopaque
1944 (colorspace_to_string colorspace
)
1946 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1947 angle gen
conf.angle
state.gen
1949 conf.tilew
conf.tileh
1956 (* dolog "%S" cmds; *)
1959 try String.index cmds ' '
1960 with Not_found
-> -1
1965 let l = String.length cmds
in
1966 let op = String.sub cmds
0 spacepos in
1968 if l - spacepos < 2 then ""
1969 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1974 state.uioh#infochanged Pdim
;
1978 state.rects
<- state.rects1
;
1979 G.postRedisplay "clearrects";
1983 try Scanf.sscanf
args "%u" (fun n -> n)
1985 dolog "error processing 'continue' %S: %s"
1986 cmds
(Printexc.to_string exn
);
1989 state.pagecount
<- n;
1990 begin match state.currently
with
1992 state.currently
<- Idle
;
1993 state.outlines
<- Array.of_list
(List.rev
l)
1997 let cur, cmds
= state.geomcmds
in
1998 if String.length
cur = 0
1999 then failwith
"umpossible";
2001 begin match List.rev cmds
with
2003 state.geomcmds
<- "", [];
2007 state.geomcmds
<- s, List.rev rest
;
2009 if conf.maxwait
= None
2010 then G.postRedisplay "continue";
2020 then showtext ' '
args
2023 let progress, text =
2025 Scanf.sscanf
args "%f %n"
2027 f, String.sub
args pos
(String.length
args - pos
))
2029 dolog "error processing 'progress' %S: %s"
2030 cmds
(Printexc.to_string exn
);
2034 state.progress <- progress;
2035 G.postRedisplay "progress"
2038 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2040 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2041 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2042 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2044 dolog "error processing 'firstmatch' %S: %s"
2045 cmds
(Printexc.to_string exn
);
2048 let y = (getpagey pageno) + truncate
y0 in
2051 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2054 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2056 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2057 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2058 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2060 dolog "error processing 'match' %S: %s"
2061 cmds
(Printexc.to_string exn
);
2065 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2070 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2072 dolog "error processing 'page' %S: %s"
2073 cmds
(Printexc.to_string exn
);
2076 begin match state.currently
with
2077 | Loading
(l, gen
) ->
2078 vlog "page %d took %f sec" l.pageno t
;
2079 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2080 begin match state.throttle
with
2082 let preloadedpages =
2084 then preloadlayout state.layout
2089 Set.Make
(struct type t
= int let compare = (-) end) in
2091 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2092 IntSet.empty
preloadedpages
2095 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2096 if not
(IntSet.mem
pageno set)
2098 wcmd "freepage %s" opaque
;
2104 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2107 state.currently
<- Idle
;
2110 tilepage l.pageno pageopaque state.layout;
2112 load preloadedpages;
2113 if pagevisible state.layout l.pageno
2114 && layoutready state.layout
2115 then G.postRedisplay "page";
2118 | Some
(layout, _
, _
) ->
2119 state.currently
<- Idle
;
2120 tilepage l.pageno pageopaque layout;
2125 dolog "Inconsistent loading state";
2126 logcurrently state.currently
;
2131 let (x, y, opaque
, size
, t
) =
2133 Scanf.sscanf
args "%u %u %s %u %f"
2134 (fun x y p size t
-> (x, y, p
, size
, t
))
2136 dolog "error processing 'tile' %S: %s"
2137 cmds
(Printexc.to_string exn
);
2140 begin match state.currently
with
2141 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2142 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2144 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2146 wcmd "freetile %s" opaque
;
2147 state.currently
<- Idle
;
2151 puttileopaque l col row gen cs angle opaque size t
;
2152 state.memused
<- state.memused
+ size
;
2153 state.uioh#infochanged Memused
;
2155 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2156 opaque
, size
) state.tilelru
;
2159 match state.throttle
with
2160 | None
-> state.layout
2161 | Some
(layout, _
, _
) -> layout
2164 state.currently
<- Idle
;
2166 && conf.colorspace
= cs
2167 && conf.angle
= angle
2168 && tilevisible layout l.pageno x y
2169 then conttiling l.pageno pageopaque;
2171 begin match state.throttle
with
2173 preload state.layout;
2175 && conf.colorspace
= cs
2176 && conf.angle
= angle
2177 && tilevisible state.layout l.pageno x y
2178 then G.postRedisplay "tile nothrottle";
2180 | Some
(layout, y, _
) ->
2181 let ready = layoutready layout in
2185 state.layout <- layout;
2186 state.throttle
<- None
;
2187 G.postRedisplay "throttle";
2194 dolog "Inconsistent tiling state";
2195 logcurrently state.currently
;
2202 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2204 dolog "error processing 'pdim' %S: %s"
2205 cmds
(Printexc.to_string exn
);
2208 state.uioh#infochanged Pdim
;
2209 state.pdims
<- pdim :: state.pdims
2212 let (l, n, t
, h, pos
) =
2214 Scanf.sscanf
args "%u %u %d %u %n"
2215 (fun l n t
h pos
-> l, n, t
, h, pos
)
2217 dolog "error processing 'o' %S: %s"
2218 cmds
(Printexc.to_string exn
);
2221 let s = String.sub
args pos
(String.length
args - pos
) in
2222 let outline = (s, l, (n, float t
/. float h)) in
2223 begin match state.currently
with
2224 | Outlining outlines
->
2225 state.currently
<- Outlining
(outline :: outlines
)
2227 state.currently
<- Outlining
[outline]
2229 dolog "invalid outlining state";
2230 logcurrently currently
2234 state.docinfo
<- (1, args) :: state.docinfo
2237 state.uioh#infochanged Docinfo
;
2238 state.docinfo
<- List.rev
state.docinfo
2241 dolog "unknown cmd `%S'" cmds
2246 let action = function
2247 | HCprev
-> cbget cb ~
-1
2248 | HCnext
-> cbget cb
1
2249 | HCfirst
-> cbget cb ~
-(cb
.rc)
2250 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2251 and cancel
() = cb
.rc <- rc
2255 let search pattern forward
=
2256 if String.length pattern
> 0
2259 match state.layout with
2262 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2264 wcmd "search %d %d %d %d,%s\000"
2265 (btod conf.icase
) pn py (btod forward
) pattern
;
2268 let intentry text key =
2270 if key >= 32 && key < 127
2276 let text = addchar text c in
2280 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2284 let textentry text key =
2285 if key land 0xff00 = 0xff00
2287 else TEcont
(text ^
Wsi.toutf8
key)
2290 let reqlayout angle proportional
=
2291 match state.throttle
with
2293 if nogeomcmds state.geomcmds
2294 then state.anchor <- getanchor ();
2295 conf.angle
<- angle
mod 360;
2298 match state.mode
with
2299 | LinkNav _
-> state.mode
<- View
2302 conf.proportional
<- proportional
;
2303 invalidate "reqlayout"
2304 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2308 let settrim trimmargins trimfuzz
=
2309 if nogeomcmds state.geomcmds
2310 then state.anchor <- getanchor ();
2311 conf.trimmargins
<- trimmargins
;
2312 conf.trimfuzz
<- trimfuzz
;
2313 let x0, y0, x1, y1 = trimfuzz
in
2314 invalidate "settrim"
2316 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2317 Hashtbl.iter
(fun _ opaque
->
2318 wcmd "freepage %s" opaque
;
2320 Hashtbl.clear
state.pagemap
;
2324 match state.throttle
with
2326 let zoom = max
0.01 zoom in
2327 if zoom <> conf.zoom
2329 state.prevzoom
<- conf.zoom;
2331 reshape conf.winw
conf.winh
;
2332 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2335 | Some
(layout, y, started
) ->
2337 match conf.maxwait
with
2341 let dt = now () -. started
in
2349 let setcolumns columns coverA coverB
=
2352 conf.columns
<- None
;
2357 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2360 reshape conf.winw
conf.winh
;
2363 let enterbirdseye () =
2364 let zoom = float conf.thumbw
/. float conf.winw
in
2365 let birdseyepageno =
2366 let cy = conf.winh
/ 2 in
2370 let rec fold best
= function
2373 let d = cy - (l.pagedispy + l.pagevh/2)
2374 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2375 if abs
d < abs dbest
2382 state.mode
<- Birdseye
(
2383 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2386 conf.presentation <- false;
2387 conf.interpagespace <- 10;
2388 conf.hlinks
<- false;
2390 state.mstate
<- Mnone
;
2391 conf.maxwait
<- None
;
2393 match conf.beyecolumns
with
2396 Some
((c, 0, 0), [||])
2399 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2402 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2407 reshape conf.winw
conf.winh
;
2410 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2412 conf.zoom <- c.zoom;
2413 conf.presentation <- c.presentation;
2414 conf.interpagespace <- c.interpagespace;
2415 conf.maxwait
<- c.maxwait
;
2416 conf.hlinks
<- c.hlinks
;
2417 conf.beyecolumns
<- (
2418 match conf.columns
with
2419 | Some
((c, _
, _
), _
) -> Some
c
2423 match c.columns
with
2424 | Some
(c, _
) -> Some
(c, [||])
2430 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2433 reshape conf.winw
conf.winh
;
2434 state.anchor <- if goback
then anchor else (pageno, 0.0);
2437 let togglebirdseye () =
2438 match state.mode
with
2439 | Birdseye vals
-> leavebirdseye vals
true
2440 | View
-> enterbirdseye ()
2444 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2445 let pageno = max
0 (pageno - incr
) in
2446 let rec loop = function
2447 | [] -> gotopage1 pageno 0
2448 | l :: _
when l.pageno = pageno ->
2449 if l.pagedispy >= 0 && l.pagey = 0
2450 then G.postRedisplay "upbirdseye"
2451 else gotopage1 pageno 0
2452 | _
:: rest
-> loop rest
2455 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2458 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2459 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2460 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2461 let rec loop = function
2463 let y, h = getpageyh pageno in
2464 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2466 | l :: _
when l.pageno = pageno ->
2467 if l.pagevh != l.pageh
2468 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2469 else G.postRedisplay "downbirdseye"
2470 | _
:: rest
-> loop rest
2475 let optentry mode _
key =
2476 let btos b = if b then "on" else "off" in
2477 if key >= 32 && key < 127
2479 let c = Char.chr
key in
2483 try conf.scrollstep
<- int_of_string
s with exc
->
2484 state.text <- Printf.sprintf
"bad integer `%s': %s"
2485 s (Printexc.to_string exc
)
2487 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2492 conf.autoscrollstep
<- int_of_string
s;
2493 if state.autoscroll
<> None
2494 then state.autoscroll
<- Some
conf.autoscrollstep
2496 state.text <- Printf.sprintf
"bad integer `%s': %s"
2497 s (Printexc.to_string exc
)
2499 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2504 let n, a, b = columns_of_string s in
2507 state.text <- Printf.sprintf
"bad columns `%s': %s"
2508 s (Printexc.to_string exc
)
2510 TEswitch
("columns: ", "", None
, textentry, ondone)
2515 let zoom = float (int_of_string
s) /. 100.0 in
2518 state.text <- Printf.sprintf
"bad integer `%s': %s"
2519 s (Printexc.to_string exc
)
2521 TEswitch
("zoom: ", "", None
, intentry, ondone)
2526 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2528 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2529 begin match mode
with
2531 leavebirdseye beye
false;
2536 state.text <- Printf.sprintf
"bad integer `%s': %s"
2537 s (Printexc.to_string exc
)
2539 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2544 Some
(int_of_string
s)
2546 state.text <- Printf.sprintf
"bad integer `%s': %s"
2547 s (Printexc.to_string exc
);
2550 | Some angle
-> reqlayout angle
conf.proportional
2553 TEswitch
("rotation: ", "", None
, intentry, ondone)
2556 conf.icase
<- not
conf.icase
;
2557 TEdone
("case insensitive search " ^
(btos conf.icase
))
2560 conf.preload <- not
conf.preload;
2562 TEdone
("preload " ^
(btos conf.preload))
2565 conf.verbose
<- not
conf.verbose
;
2566 TEdone
("verbose " ^
(btos conf.verbose
))
2569 conf.debug
<- not
conf.debug
;
2570 TEdone
("debug " ^
(btos conf.debug
))
2573 conf.maxhfit
<- not
conf.maxhfit
;
2575 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2576 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2579 conf.crophack
<- not
conf.crophack
;
2580 TEdone
("crophack " ^
btos conf.crophack
)
2584 match conf.maxwait
with
2586 conf.maxwait
<- Some infinity
;
2587 "always wait for page to complete"
2589 conf.maxwait
<- None
;
2590 "show placeholder if page is not ready"
2595 conf.underinfo
<- not
conf.underinfo
;
2596 TEdone
("underinfo " ^
btos conf.underinfo
)
2599 conf.savebmarks
<- not
conf.savebmarks
;
2600 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2606 match state.layout with
2611 conf.interpagespace <- int_of_string
s;
2612 state.maxy <- calcheight ();
2613 let y = getpagey pageno in
2616 state.text <- Printf.sprintf
"bad integer `%s': %s"
2617 s (Printexc.to_string exc
)
2619 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2622 reqlayout conf.angle
(not
conf.proportional
);
2623 TEdone
("proportional display " ^
btos conf.proportional
)
2626 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2627 TEdone
("trim margins " ^
btos conf.trimmargins
)
2630 conf.invert
<- not
conf.invert
;
2631 TEdone
("invert colors " ^
btos conf.invert
)
2635 cbput state.hists
.sel
s;
2638 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2642 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2648 class type lvsource
= object
2649 method getitemcount
: int
2650 method getitem
: int -> (string * int)
2651 method hasaction
: int -> bool
2660 method getactive
: int
2661 method getfirst
: int
2662 method getqsearch
: string
2663 method setqsearch
: string -> unit
2667 class virtual lvsourcebase
= object
2668 val mutable m_active
= 0
2669 val mutable m_first
= 0
2670 val mutable m_qsearch
= ""
2671 val mutable m_pan
= 0
2672 method getactive
= m_active
2673 method getfirst
= m_first
2674 method getqsearch
= m_qsearch
2675 method getpan
= m_pan
2676 method setqsearch
s = m_qsearch
<- s
2679 let withoutlastutf8 s =
2680 let len = String.length
s in
2688 let b = Char.code
s.[pos
] in
2689 if b land 0b110000 = 0b11000000
2694 if Char.code
s.[len-1] land 0x80 = 0
2698 String.sub
s 0 first;
2701 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2703 state.mode
<- Textentry
(te
, onleave
);
2706 G.postRedisplay "textentrykeyboard enttext";
2708 let histaction cmd
=
2711 | Some
(action, _
) ->
2712 state.mode
<- Textentry
(
2713 (c, action cmd
, opthist
, onkey
, ondone), onleave
2715 G.postRedisplay "textentry histaction"
2718 | 0xff08 -> (* backspace *)
2719 let s = withoutlastutf8 text in
2720 let len = String.length
s in
2724 G.postRedisplay "textentrykeyboard after cancel";
2727 enttext (c, s, opthist
, onkey
, ondone)
2733 G.postRedisplay "textentrykeyboard after confirm"
2735 | 0xff52 -> histaction HCprev
2736 | 0xff54 -> histaction HCnext
2737 | 0xff50 -> histaction HCfirst
2738 | 0xff57 -> histaction HClast
2740 | 0xff1b -> (* escape*)
2741 if String.length
text = 0
2743 begin match opthist
with
2745 | Some
(_
, onhistcancel
) -> onhistcancel
()
2749 G.postRedisplay "textentrykeyboard after cancel2"
2752 enttext (c, "", opthist
, onkey
, ondone)
2755 | 0xff9f | 0xffff -> () (* delete *)
2757 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2758 begin match onkey
text key with
2762 G.postRedisplay "textentrykeyboard after confirm2";
2765 enttext (c, text, opthist
, onkey
, ondone);
2769 G.postRedisplay "textentrykeyboard after cancel3"
2772 state.mode
<- Textentry
(te
, onleave
);
2773 G.postRedisplay "textentrykeyboard switch";
2777 vlog "unhandled key %s" (Wsi.keyname
key)
2780 let firstof first active
=
2781 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2782 then max
0 (active
- (fstate.maxrows
/2))
2786 let calcfirst first active
=
2789 let rows = active
- first in
2790 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2794 let scrollph y maxy =
2795 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2796 let sh = float conf.winh
/. sh in
2797 let sh = max
sh (float conf.scrollh
) in
2802 else float y /. float maxy
2804 let position = (float conf.winh
-. sh) *. percent in
2807 if position +. sh > float conf.winh
2808 then float conf.winh
-. sh
2814 let coe s = (s :> uioh
);;
2816 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2818 val m_pan
= source#getpan
2819 val m_first
= source#getfirst
2820 val m_active
= source#getactive
2821 val m_qsearch
= source#getqsearch
2822 val m_prev_uioh
= state.uioh
2824 method private elemunder
y =
2825 let n = y / (fstate.fontsize
+1) in
2826 if m_first
+ n < source#getitemcount
2828 if source#hasaction
(m_first
+ n)
2829 then Some
(m_first
+ n)
2836 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2837 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2838 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2839 GlDraw.color
(1., 1., 1.);
2840 Gl.enable `texture_2d
;
2841 let fs = fstate.fontsize
in
2843 let ww = fstate.wwidth
in
2844 let tabw = 30.0*.ww in
2845 let itemcount = source#getitemcount
in
2847 if (row - m_first
) * nfs > conf.winh
2850 if row >= 0 && row < itemcount
2852 let (s, level
) = source#getitem
row in
2853 let y = (row - m_first
) * nfs in
2854 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2857 Gl.disable `texture_2d
;
2858 GlDraw.polygon_mode `both `line
;
2859 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2860 GlDraw.rect (1., float (y + 1))
2861 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2862 GlDraw.polygon_mode `both `fill
;
2863 GlDraw.color
(1., 1., 1.);
2864 Gl.enable `texture_2d
;
2867 let drawtabularstring s =
2868 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2871 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2874 let len = String.length
s - tabpos - 1 in
2875 let s1 = String.sub
s 0 tabpos
2876 and s2
= String.sub
s (tabpos + 1) len in
2877 let nx = drawstr x s1 in
2879 let x = x +. (max
tabw sw) in
2886 let _ = drawtabularstring s in
2893 Gl.disable `texture_2d
;
2895 method updownlevel incr
=
2896 let len = source#getitemcount
in
2898 if m_active
>= 0 && m_active
< len
2899 then snd
(source#getitem m_active
)
2903 if i
= len then i
-1 else if i
= -1 then 0 else
2904 let _, l = source#getitem i
in
2905 if l != curlevel then i
else flow (i
+incr
)
2907 let active = flow m_active
in
2908 let first = calcfirst m_first
active in
2909 G.postRedisplay "outline updownlevel";
2910 {< m_active
= active; m_first
= first >}
2912 method private key1
key mask
=
2913 let set1 active first qsearch
=
2914 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2916 let search active pattern incr
=
2919 if n >= 0 && n < source#getitemcount
2921 let s, _ = source#getitem
n in
2923 (try ignore
(Str.search_forward
re s 0); true
2924 with Not_found
-> false)
2926 else loop (n + incr
)
2933 let re = Str.regexp_case_fold pattern
in
2939 let itemcount = source#getitemcount
in
2940 let find start incr
=
2942 if i
= -1 || i
= itemcount
2945 if source#hasaction i
2947 else find (i
+ incr
)
2952 let set active first =
2953 let first = bound first 0 (itemcount - fstate.maxrows
) in
2955 coe {< m_active
= active; m_first
= first >}
2958 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2960 let incr1 = if incr
> 0 then 1 else -1 in
2961 if isvisible m_first m_active
2964 let next = m_active
+ incr
in
2966 if next < 0 || next >= itemcount
2968 else find next incr1
2970 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2976 let first = m_first
+ incr
in
2977 let first = bound first 0 (itemcount - 1) in
2979 let next = m_active
+ incr
in
2980 let next = bound next 0 (itemcount - 1) in
2983 let active = if next = -1 then m_active
else next in
2986 let first = min
next m_first
in
2988 if abs
(next - first) > fstate.maxrows
2994 let first = m_first
+ incr
in
2995 let first = bound first 0 (itemcount - 1) in
2997 let next = m_active
+ incr
in
2998 let next = bound next 0 (itemcount - 1) in
2999 let next = find next incr1 in
3001 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3003 let active = if m_active
= -1 then next else m_active
in
3008 if isvisible first active
3014 G.postRedisplay "listview navigate";
3018 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3019 let incr = if key = 0x72 then -1 else 1 in
3021 match search (m_active
+ incr) m_qsearch
incr with
3023 state.text <- m_qsearch ^
" [not found]";
3026 state.text <- m_qsearch
;
3027 active, firstof m_first
active
3029 G.postRedisplay "listview ctrl-r/s";
3030 set1 active first m_qsearch
;
3032 | 0xff08 -> (* backspace *)
3033 if String.length m_qsearch
= 0
3036 let qsearch = withoutlastutf8 m_qsearch
in
3037 let len = String.length
qsearch in
3041 G.postRedisplay "listview empty qsearch";
3042 set1 m_active m_first
"";
3046 match search m_active
qsearch ~
-1 with
3048 state.text <- qsearch ^
" [not found]";
3051 state.text <- qsearch;
3052 active, firstof m_first
active
3054 G.postRedisplay "listview backspace qsearch";
3055 set1 active first qsearch
3058 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3059 let pattern = m_qsearch ^
Wsi.toutf8
key in
3061 match search m_active
pattern 1 with
3063 state.text <- pattern ^
" [not found]";
3066 state.text <- pattern;
3067 active, firstof m_first
active
3069 G.postRedisplay "listview qsearch add";
3070 set1 active first pattern;
3072 | 0xff1b -> (* escape *)
3074 if String.length m_qsearch
= 0
3076 G.postRedisplay "list view escape";
3079 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3081 | None
-> m_prev_uioh
3086 G.postRedisplay "list view kill qsearch";
3087 source#setqsearch
"";
3088 coe {< m_qsearch
= "" >}
3091 | 0xff0d -> (* return *)
3093 let self = {< m_qsearch
= "" >} in
3094 source#setqsearch
"";
3096 G.postRedisplay "listview enter";
3097 if m_active
>= 0 && m_active
< source#getitemcount
3099 source#exit
(coe self) false m_active m_first m_pan
"";
3102 source#exit
(coe self) true m_active m_first m_pan
"";
3105 begin match opt with
3106 | None
-> m_prev_uioh
3110 | 0xff9f | 0xffff -> (* delete *)
3113 | 0xff52 -> navigate ~
-1 (* up *)
3114 | 0xff54 -> navigate 1 (* down *)
3115 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3116 | 0xff56 -> navigate fstate.maxrows
(* next *)
3118 | 0xff53 -> (* right *)
3120 G.postRedisplay "listview right";
3121 coe {< m_pan
= m_pan
- 1 >}
3123 | 0xff51 -> (* left *)
3125 G.postRedisplay "listview left";
3126 coe {< m_pan
= m_pan
+ 1 >}
3128 | 0xff50 -> (* home *)
3129 let active = find 0 1 in
3130 G.postRedisplay "listview home";
3133 | 0xff57 -> (* end *)
3134 let first = max
0 (itemcount - fstate.maxrows
) in
3135 let active = find (itemcount - 1) ~
-1 in
3136 G.postRedisplay "listview end";
3139 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3143 dolog "listview unknown key %#x" key; coe self
3145 method key key mask
=
3146 match state.mode
with
3147 | Textentry te
-> textentrykeyboard key mask te
; coe self
3148 | _ -> self#key1
key mask
3150 method button button down
x y _ =
3153 | 1 when x > conf.winw
- conf.scrollbw
->
3154 G.postRedisplay "listview scroll";
3157 let _, position, sh = self#
scrollph in
3158 if y > truncate
position && y < truncate
(position +. sh)
3160 state.mstate
<- Mscrolly
;
3164 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3165 let first = truncate
(s *. float source#getitemcount
) in
3166 let first = min source#getitemcount
first in
3167 Some
(coe {< m_first
= first; m_active
= first >})
3169 state.mstate
<- Mnone
;
3172 | 1 when not down
->
3173 begin match self#elemunder
y with
3175 G.postRedisplay "listview click";
3177 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3181 | n when (n == 4 || n == 5) && not down
->
3182 let len = source#getitemcount
in
3184 if n = 5 && m_first
+ fstate.maxrows
>= len
3188 let first = m_first
+ (if n == 4 then -1 else 1) in
3189 bound first 0 (len - 1)
3191 G.postRedisplay "listview wheel";
3192 Some
(coe {< m_first
= first >})
3197 | None
-> m_prev_uioh
3201 match state.mstate
with
3203 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3204 let first = truncate
(s *. float source#getitemcount
) in
3205 let first = min source#getitemcount
first in
3206 G.postRedisplay "listview motion";
3207 coe {< m_first
= first; m_active
= first >}
3210 method pmotion
x y =
3211 if x < conf.winw
- conf.scrollbw
3214 match self#elemunder
y with
3215 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3216 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3220 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3225 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3229 method infochanged
_ = ()
3231 method scrollpw
= (0, 0.0, 0.0)
3233 let nfs = fstate.fontsize
+ 1 in
3234 let y = m_first
* nfs in
3235 let itemcount = source#getitemcount
in
3236 let maxi = max
0 (itemcount - fstate.maxrows
) in
3237 let maxy = maxi * nfs in
3238 let p, h = scrollph y maxy in
3241 method modehash
= modehash
3244 class outlinelistview ~source
=
3247 ~source
:(source
:> lvsource
)
3249 ~modehash
:(findkeyhash conf "outline")
3252 method key key mask
=
3253 let calcfirst first active =
3256 let rows = active - first in
3257 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3261 let active = m_active
+ incr in
3262 let active = bound active 0 (source#getitemcount
- 1) in
3263 let first = calcfirst m_first
active in
3264 G.postRedisplay "outline navigate";
3265 coe {< m_active
= active; m_first
= first >}
3267 let ctrl = Wsi.withctrl mask
in
3269 | 110 when ctrl -> (* ctrl-n *)
3270 source#narrow m_qsearch
;
3271 G.postRedisplay "outline ctrl-n";
3272 coe {< m_first
= 0; m_active
= 0 >}
3274 | 117 when ctrl -> (* ctrl-u *)
3276 G.postRedisplay "outline ctrl-u";
3278 coe {< m_first
= 0; m_active
= 0 >}
3280 | 108 when ctrl -> (* ctrl-l *)
3281 let first = m_active
- (fstate.maxrows
/ 2) in
3282 G.postRedisplay "outline ctrl-l";
3283 coe {< m_first
= first >}
3285 | 0xff9f | 0xffff -> (* delete *)
3286 source#remove m_active
;
3287 G.postRedisplay "outline delete";
3288 let active = max
0 (m_active
-1) in
3289 coe {< m_first
= firstof m_first
active;
3290 m_active
= active >}
3292 | 0xff52 -> navigate ~
-1 (* up *)
3293 | 0xff54 -> navigate 1 (* down *)
3294 | 0xff55 -> (* prior *)
3295 navigate ~
-(fstate.maxrows
)
3296 | 0xff56 -> (* next *)
3297 navigate fstate.maxrows
3299 | 0xff53 -> (* [ctrl-]right *)
3303 G.postRedisplay "outline ctrl right";
3304 {< m_pan
= m_pan
+ 1 >}
3306 else self#updownlevel
1
3310 | 0xff51 -> (* [ctrl-]left *)
3314 G.postRedisplay "outline ctrl left";
3315 {< m_pan
= m_pan
- 1 >}
3317 else self#updownlevel ~
-1
3321 | 0xff50 -> (* home *)
3322 G.postRedisplay "outline home";
3323 coe {< m_first
= 0; m_active
= 0 >}
3325 | 0xff57 -> (* end *)
3326 let active = source#getitemcount
- 1 in
3327 let first = max
0 (active - fstate.maxrows
) in
3328 G.postRedisplay "outline end";
3329 coe {< m_active
= active; m_first
= first >}
3331 | _ -> super#
key key mask
3334 let outlinesource usebookmarks
=
3337 inherit lvsourcebase
3338 val mutable m_items
= empty
3339 val mutable m_orig_items
= empty
3340 val mutable m_prev_items
= empty
3341 val mutable m_narrow_pattern
= ""
3342 val mutable m_hadremovals
= false
3344 method getitemcount
=
3345 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3348 if n == Array.length m_items
&& m_hadremovals
3350 ("[Confirm removal]", 0)
3352 let s, n, _ = m_items
.(n) in
3355 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3356 ignore
(uioh
, first, qsearch);
3357 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3359 if String.length m_narrow_pattern
= 0
3365 if not
confrimremoval
3367 let _, _, anchor = m_items
.(active) in
3372 state.bookmarks
<- Array.to_list m_items
;
3373 m_orig_items
<- m_items
;
3376 else m_items
<- items;
3380 method hasaction
_ = true
3383 if Array.length m_items
!= Array.length m_orig_items
3384 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3387 method narrow
pattern =
3388 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3392 let rec loop accu n =
3395 m_narrow_pattern
<- pattern;
3396 m_items
<- Array.of_list
accu
3399 let (s, _, _) as o = m_items
.(n) in
3401 if (try ignore
(Str.search_forward
re s 0); true
3402 with Not_found
-> false)
3408 loop [] (Array.length m_items
- 1)
3413 then Array.of_list
state.bookmarks
3416 m_items
<- m_orig_items
3421 if m
>= 0 && m
< Array.length m_items
3423 m_hadremovals
<- true;
3424 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3425 let n = if n >= m
then n+1 else n in
3430 method reset
anchor items =
3431 m_hadremovals
<- false;
3432 if m_orig_items
== empty || m_prev_items
!= items
3434 m_orig_items
<- items;
3435 if String.length m_narrow_pattern
= 0
3436 then m_items
<- items;
3438 m_prev_items
<- items;
3439 let rely = getanchory anchor in
3441 let rec loop n best bestd
=
3442 if n = Array.length m_items
3445 let (_, _, anchor) = m_items
.(n) in
3446 let orely = getanchory anchor in
3447 let d = abs
(orely - rely) in
3450 else loop (n+1) best bestd
3455 m_first
<- firstof m_first
active
3459 let enterselector usebookmarks
=
3460 let source = outlinesource usebookmarks
in
3464 then Array.of_list
state.bookmarks
3467 if Array.length
outlines = 0
3469 showtext ' ' errmsg
;
3472 state.text <- source#greetmsg
;
3473 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3474 let anchor = getanchor () in
3475 source#reset
anchor outlines;
3476 state.uioh
<- coe (new outlinelistview ~
source);
3477 G.postRedisplay "enter selector";
3481 let enteroutlinemode =
3482 let f = enterselector false in
3483 fun ()-> f "Document has no outline";
3486 let enterbookmarkmode =
3487 let f = enterselector true in
3488 fun () -> f "Document has no bookmarks (yet)";
3491 let color_of_string s =
3492 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3493 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3497 let color_to_string (r
, g
, b) =
3498 let r = truncate
(r *. 256.0)
3499 and g
= truncate
(g
*. 256.0)
3500 and b = truncate
(b *. 256.0) in
3501 Printf.sprintf
"%d/%d/%d" r g
b
3504 let irect_of_string s =
3505 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3508 let irect_to_string (x0,y0,x1,y1) =
3509 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3512 let makecheckers () =
3513 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3515 converted by Issac Trotts. July 25, 2002 *)
3516 let image_height = 64
3517 and image_width
= 64 in
3521 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3523 for i
= 0 to image_width
- 1 do
3524 for j
= 0 to image_height - 1 do
3525 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3526 (if (i
land 8 ) lxor (j
land 8) = 0
3527 then [|255;255;255|] else [|200;200;200|])
3532 let image = make_image () in
3533 let id = GlTex.gen_texture
() in
3534 GlTex.bind_texture `texture_2d
id;
3535 GlPix.store
(`unpack_alignment
1);
3536 GlTex.image2d
image;
3537 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3540 `mag_filter `nearest
;
3541 `min_filter `nearest
];
3545 let setcheckers enabled
=
3546 match state.texid
with
3548 if enabled
then state.texid
<- Some
(makecheckers ())
3553 GlTex.delete_texture texid
;
3554 state.texid
<- None
;
3558 let int_of_string_with_suffix s =
3559 let l = String.length
s in
3563 let suffix = Char.lowercase
s.[l-1] in
3565 | 'k'
-> String.sub
s 0 (l-1), 10
3566 | 'm'
-> String.sub
s 0 (l-1), 20
3567 | 'g'
-> String.sub
s 0 (l-1), 30
3571 let n = int_of_string
s1 in
3572 let m = n lsl shift
in
3574 then raise
(Failure
"value too large")
3578 let string_with_suffix_of_int n =
3586 if n land ((1 lsl 20) - 1) = 0
3589 if n land ((1 lsl 10) - 1) = 0
3596 let h = n mod 1000 in
3599 then string_of_int
h ^
s
3601 let s = Printf.sprintf
"_%03d%s" h s in
3608 let defghyllscroll = (40, 8, 32);;
3609 let ghyllscroll_of_string s =
3610 let (n, a, b) as nab
=
3613 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3615 if n <= a || n <= b || a >= b
3616 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3620 let ghyllscroll_to_string ((n, a, b) as nab
) =
3621 if nab
= defghyllscroll
3623 else Printf.sprintf
"%d,%d,%d" n a b;
3626 let describe_location () =
3628 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3630 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3631 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3635 else (100. *. (float state.y /. float maxy))
3639 Printf.sprintf
"page %d of %d [%.2f%%]"
3640 (fn+1) state.pagecount
percent
3643 "pages %d-%d of %d [%.2f%%]"
3644 (fn+1) (ln
+1) state.pagecount
percent
3648 let btos b = if b then "\xe2\x88\x9a" else "" in
3649 let showextended = ref false in
3650 let leave mode
= function
3651 | Confirm
-> state.mode
<- mode
3652 | Cancel
-> state.mode
<- mode
in
3655 val mutable m_first_time
= true
3656 val mutable m_l
= []
3657 val mutable m_a
= [||]
3658 val mutable m_prev_uioh
= nouioh
3659 val mutable m_prev_mode
= View
3661 inherit lvsourcebase
3663 method reset prev_mode prev_uioh
=
3664 m_a
<- Array.of_list
(List.rev m_l
);
3666 m_prev_mode
<- prev_mode
;
3667 m_prev_uioh
<- prev_uioh
;
3671 if n >= Array.length m_a
3675 | _, _, _, Action
_ -> m_active
<- n
3679 m_first_time
<- false;
3682 method int name get
set =
3684 (name
, `
int get
, 1, Action
(
3687 try set (int_of_string
s)
3689 state.text <- Printf.sprintf
"bad integer `%s': %s"
3690 s (Printexc.to_string exn
)
3693 let te = name ^
": ", "", None
, intentry, ondone in
3694 state.mode
<- Textentry
(te, leave m_prev_mode
);
3698 method int_with_suffix name get
set =
3700 (name
, `intws get
, 1, Action
(
3703 try set (int_of_string_with_suffix s)
3705 state.text <- Printf.sprintf
"bad integer `%s': %s"
3706 s (Printexc.to_string exn
)
3710 name ^
": ", "", None
, intentry_with_suffix, ondone
3712 state.mode
<- Textentry
(te, leave m_prev_mode
);
3716 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3718 (name
, `
bool (btos, get
), offset
, Action
(
3725 method color name get
set =
3727 (name
, `color get
, 1, Action
(
3729 let invalid = (nan
, nan
, nan
) in
3732 try color_of_string s
3734 state.text <- Printf.sprintf
"bad color `%s': %s"
3735 s (Printexc.to_string exn
);
3741 let te = name ^
": ", "", None
, textentry, ondone in
3742 state.text <- color_to_string (get
());
3743 state.mode
<- Textentry
(te, leave m_prev_mode
);
3747 method string name get
set =
3749 (name
, `
string get
, 1, Action
(
3751 let ondone s = set s in
3752 let te = name ^
": ", "", None
, textentry, ondone in
3753 state.mode
<- Textentry
(te, leave m_prev_mode
);
3757 method colorspace name get
set =
3759 (name
, `
string get
, 1, Action
(
3762 let vals = [| "rgb"; "bgr"; "gray" |] in
3764 inherit lvsourcebase
3767 m_active
<- int_of_colorspace conf.colorspace
;
3770 method getitemcount
= Array.length
vals
3771 method getitem
n = (vals.(n), 0)
3772 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3773 ignore
(uioh
, first, pan
, qsearch);
3774 if not cancel
then set active;
3776 method hasaction
_ = true
3780 let modehash = findkeyhash conf "info" in
3781 coe (new listview ~
source ~trusted
:true ~
modehash)
3784 method caption
s offset
=
3785 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3787 method caption2
s f offset
=
3788 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3790 method getitemcount
= Array.length m_a
3793 let tostr = function
3794 | `
int f -> string_of_int
(f ())
3795 | `intws
f -> string_with_suffix_of_int (f ())
3797 | `color
f -> color_to_string (f ())
3798 | `
bool (btos, f) -> btos (f ())
3801 let name, t
, offset
, _ = m_a
.(n) in
3802 ((let s = tostr t
in
3803 if String.length
s > 0
3804 then Printf.sprintf
"%s\t%s" name s
3808 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3812 m_qsearch
<- qsearch;
3814 match m_a
.(active) with
3815 | _, _, _, Action
f -> f uioh
3827 method hasaction
n =
3829 | _, _, _, Action
_ -> true
3833 let rec fillsrc prevmode prevuioh
=
3834 let sep () = src#caption
"" 0 in
3835 let colorp name get
set =
3837 (fun () -> color_to_string (get
()))
3840 let c = color_of_string v in
3843 state.text <- Printf.sprintf
"bad color `%s': %s"
3844 v (Printexc.to_string exn
);
3847 let oldmode = state.mode
in
3848 let birdseye = isbirdseye state.mode
in
3850 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3852 src#
bool "presentation mode"
3853 (fun () -> conf.presentation)
3855 conf.presentation <- v;
3856 state.anchor <- getanchor ();
3859 src#
bool "ignore case in searches"
3860 (fun () -> conf.icase
)
3861 (fun v -> conf.icase
<- v);
3864 (fun () -> conf.preload)
3865 (fun v -> conf.preload <- v);
3867 src#
bool "highlight links"
3868 (fun () -> conf.hlinks
)
3869 (fun v -> conf.hlinks
<- v);
3871 src#
bool "under info"
3872 (fun () -> conf.underinfo
)
3873 (fun v -> conf.underinfo
<- v);
3875 src#
bool "persistent bookmarks"
3876 (fun () -> conf.savebmarks
)
3877 (fun v -> conf.savebmarks
<- v);
3879 src#
bool "proportional display"
3880 (fun () -> conf.proportional
)
3881 (fun v -> reqlayout conf.angle
v);
3883 src#
bool "trim margins"
3884 (fun () -> conf.trimmargins
)
3885 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3887 src#
bool "persistent location"
3888 (fun () -> conf.jumpback
)
3889 (fun v -> conf.jumpback
<- v);
3892 src#
int "inter-page space"
3893 (fun () -> conf.interpagespace)
3895 conf.interpagespace <- n;
3897 match state.layout with
3902 state.maxy <- calcheight ();
3903 let y = getpagey pageno in
3908 (fun () -> conf.pagebias
)
3909 (fun v -> conf.pagebias
<- v);
3911 src#
int "scroll step"
3912 (fun () -> conf.scrollstep
)
3913 (fun n -> conf.scrollstep
<- n);
3915 src#
int "auto scroll step"
3917 match state.autoscroll
with
3919 | _ -> conf.autoscrollstep
)
3921 if state.autoscroll
<> None
3922 then state.autoscroll
<- Some
n;
3923 conf.autoscrollstep
<- n);
3926 (fun () -> truncate
(conf.zoom *. 100.))
3927 (fun v -> setzoom ((float v) /. 100.));
3930 (fun () -> conf.angle
)
3931 (fun v -> reqlayout v conf.proportional
);
3933 src#
int "scroll bar width"
3934 (fun () -> state.scrollw
)
3938 reshape conf.winw
conf.winh
;
3941 src#
int "scroll handle height"
3942 (fun () -> conf.scrollh
)
3943 (fun v -> conf.scrollh
<- v;);
3945 src#
int "thumbnail width"
3946 (fun () -> conf.thumbw
)
3948 conf.thumbw
<- min
4096 v;
3951 leavebirdseye beye
false;
3956 src#
string "columns"
3958 match conf.columns
with
3960 | Some
(multicol
, _) -> columns_to_string multicol
)
3962 let n, a, b = columns_of_string v in
3966 src#caption
"Presentation mode" 0;
3967 src#
bool "scrollbar visible"
3968 (fun () -> conf.scrollbarinpm
)
3970 if v != conf.scrollbarinpm
3972 conf.scrollbarinpm
<- v;
3973 if conf.presentation
3975 state.scrollw
<- if v then conf.scrollbw
else 0;
3976 reshape conf.winw
conf.winh
;
3982 src#caption
"Pixmap cache" 0;
3983 src#int_with_suffix
"size (advisory)"
3984 (fun () -> conf.memlimit
)
3985 (fun v -> conf.memlimit
<- v);
3988 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3989 (string_with_suffix_of_int state.memused
)
3990 (Hashtbl.length
state.tilemap
)) 1;
3993 src#caption
"Layout" 0;
3994 src#caption2
"Dimension"
3996 Printf.sprintf
"%dx%d (virtual %dx%d)"
4002 src#caption2
"Position" (fun () ->
4003 Printf.sprintf
"%dx%d" state.x state.y
4006 src#caption2
"Visible" (fun () -> describe_location ()) 1
4010 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4011 "Save these parameters as global defaults at exit"
4012 (fun () -> conf.bedefault
)
4013 (fun v -> conf.bedefault
<- v)
4017 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4018 src#
bool ~offset
:0 ~
btos "Extended parameters"
4019 (fun () -> !showextended)
4020 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4024 (fun () -> conf.checkers
)
4025 (fun v -> conf.checkers
<- v; setcheckers v);
4026 src#
bool "update cursor"
4027 (fun () -> conf.updatecurs
)
4028 (fun v -> conf.updatecurs
<- v);
4030 (fun () -> conf.verbose
)
4031 (fun v -> conf.verbose
<- v);
4032 src#
bool "invert colors"
4033 (fun () -> conf.invert
)
4034 (fun v -> conf.invert
<- v);
4036 (fun () -> conf.maxhfit
)
4037 (fun v -> conf.maxhfit
<- v);
4038 src#
bool "redirect stderr"
4039 (fun () -> conf.redirectstderr)
4040 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4041 src#
string "uri launcher"
4042 (fun () -> conf.urilauncher
)
4043 (fun v -> conf.urilauncher
<- v);
4044 src#
string "path launcher"
4045 (fun () -> conf.pathlauncher
)
4046 (fun v -> conf.pathlauncher
<- v);
4047 src#
string "tile size"
4048 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4051 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4052 conf.tileh
<- max
64 w;
4053 conf.tilew
<- max
64 h;
4056 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4057 v (Printexc.to_string exn
));
4058 src#
int "texture count"
4059 (fun () -> conf.texcount
)
4062 then conf.texcount
<- v
4063 else showtext '
!'
" Failed to set texture count please retry later"
4065 src#
int "slice height"
4066 (fun () -> conf.sliceheight
)
4068 conf.sliceheight
<- v;
4069 wcmd "sliceh %d" conf.sliceheight
;
4071 src#
int "anti-aliasing level"
4072 (fun () -> conf.aalevel
)
4074 conf.aalevel
<- bound v 0 8;
4075 state.anchor <- getanchor ();
4076 opendoc state.path
state.password
;
4078 src#
int "ui font size"
4079 (fun () -> fstate.fontsize
)
4080 (fun v -> setfontsize (bound v 5 100));
4081 colorp "background color"
4082 (fun () -> conf.bgcolor
)
4083 (fun v -> conf.bgcolor
<- v);
4084 src#
bool "crop hack"
4085 (fun () -> conf.crophack
)
4086 (fun v -> conf.crophack
<- v);
4087 src#
string "trim fuzz"
4088 (fun () -> irect_to_string conf.trimfuzz
)
4091 conf.trimfuzz
<- irect_of_string v;
4093 then settrim true conf.trimfuzz
;
4095 state.text <- Printf.sprintf
"bad irect `%s': %s"
4096 v (Printexc.to_string exn
)
4098 src#
string "throttle"
4100 match conf.maxwait
with
4101 | None
-> "show place holder if page is not ready"
4104 then "wait for page to fully render"
4106 "wait " ^ string_of_float
time
4107 ^
" seconds before showing placeholder"
4111 let f = float_of_string
v in
4113 then conf.maxwait
<- None
4114 else conf.maxwait
<- Some
f
4116 state.text <- Printf.sprintf
"bad time `%s': %s"
4117 v (Printexc.to_string exn
)
4119 src#
string "ghyll scroll"
4121 match conf.ghyllscroll
with
4123 | Some nab
-> ghyllscroll_to_string nab
4128 if String.length
v = 0
4130 else Some
(ghyllscroll_of_string v)
4132 conf.ghyllscroll
<- gs
4134 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4135 v (Printexc.to_string exn
)
4137 src#
string "selection command"
4138 (fun () -> conf.selcmd
)
4139 (fun v -> conf.selcmd
<- v);
4140 src#colorspace
"color space"
4141 (fun () -> colorspace_to_string conf.colorspace
)
4143 conf.colorspace
<- colorspace_of_int v;
4150 src#caption
"Document" 0;
4151 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4152 src#caption2
"Pages"
4153 (fun () -> string_of_int
state.pagecount
) 1;
4154 src#caption2
"Dimensions"
4155 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4159 src#caption
"Trimmed margins" 0;
4160 src#caption2
"Dimensions"
4161 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4164 src#reset prevmode prevuioh
;
4168 let prevmode = state.mode
4169 and prevuioh
= state.uioh in
4170 fillsrc prevmode prevuioh
;
4171 let source = (src :> lvsource
) in
4172 let modehash = findkeyhash conf "info" in
4173 state.uioh <- coe (object (self)
4174 inherit listview ~
source ~trusted
:true ~
modehash as super
4175 val mutable m_prevmemused
= 0
4176 method infochanged
= function
4178 if m_prevmemused
!= state.memused
4180 m_prevmemused
<- state.memused
;
4181 G.postRedisplay "memusedchanged";
4183 | Pdim
-> G.postRedisplay "pdimchanged"
4184 | Docinfo
-> fillsrc prevmode prevuioh
4186 method key key mask
=
4187 if not
(Wsi.withctrl mask
)
4190 | 0xff51 -> coe (self#updownlevel ~
-1)
4191 | 0xff53 -> coe (self#updownlevel
1)
4192 | _ -> super#
key key mask
4193 else super#
key key mask
4195 G.postRedisplay "info";
4201 inherit lvsourcebase
4202 method getitemcount
= Array.length
state.help
4204 let s, n, _ = state.help
.(n) in
4207 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4211 m_qsearch
<- qsearch;
4212 match state.help
.(active) with
4213 | _, _, Action
f -> Some
(f uioh)
4223 method hasaction
n =
4224 match state.help
.(n) with
4225 | _, _, Action
_ -> true
4232 let modehash = findkeyhash conf "help" in
4233 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4234 G.postRedisplay "help";
4239 let re = Str.regexp
"[\r\n]" in
4241 inherit lvsourcebase
4242 val mutable m_items
= [||]
4244 method getitemcount
= 1 + Array.length m_items
4249 else m_items
.(n-1), 0
4251 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4256 then Buffer.clear
state.errmsgs
;
4257 m_qsearch
<- qsearch;
4264 method hasaction
n =
4268 state.newerrmsgs
<- false;
4269 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4270 m_items
<- Array.of_list
l
4278 let source = (msgsource :> lvsource
) in
4279 let modehash = findkeyhash conf "listview" in
4280 state.uioh <- coe (object
4281 inherit listview ~
source ~trusted
:false ~
modehash as super
4284 then msgsource#reset
;
4287 G.postRedisplay "msgs";
4290 let quickbookmark ?title
() =
4291 match state.layout with
4297 let sec = Unix.gettimeofday
() in
4298 let tm = Unix.localtime
sec in
4299 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4303 (tm.Unix.tm_year
+ 1900)
4306 | Some
title -> title
4309 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4314 state.fullscreen
<- None
;
4318 let setautoscrollspeed step goingdown
=
4319 let incr = max
1 ((abs step
) / 2) in
4320 let incr = if goingdown
then incr else -incr in
4321 let astep = step
+ incr in
4322 state.autoscroll
<- Some
astep;
4325 let gotounder = function
4326 | Ulinkgoto
(pageno, top) ->
4330 gotopage1 pageno top;
4336 | Uremote
(filename
, pageno) ->
4338 if Sys.file_exists filename
4341 let dir = Filename.dirname
state.path in
4342 let path = Filename.concat
dir filename
in
4343 if Sys.file_exists
path
4347 if String.length
path > 0
4349 let anchor = getanchor () in
4350 let ranchor = state.path, state.password
, anchor in
4351 state.anchor <- (pageno, 0.0);
4352 state.ranchors
<- ranchor :: state.ranchors
;
4355 else showtext '
!'
("Could not find " ^ filename
)
4357 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4360 let viewkeyboard key mask
=
4362 let mode = state.mode in
4363 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4366 G.postRedisplay "view:enttext"
4368 let ctrl = Wsi.withctrl mask
in
4373 | 0xff63 -> (* insert *)
4374 if conf.angle
mod 360 = 0
4376 state.mode <- LinkNav
(Ltgendir
0);
4379 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4381 | 0xff1b | 113 -> (* escape / q *)
4382 begin match state.mstate
with
4384 state.mstate
<- Mnone
;
4385 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4386 G.postRedisplay "kill zoom rect";
4388 match state.ranchors
with
4390 | (path, password
, anchor) :: rest
->
4391 state.ranchors
<- rest
;
4392 state.anchor <- anchor;
4393 opendoc path password
4396 | 0xff08 -> (* backspace *)
4397 let y = getnav ~
-1 in
4398 gotoy_and_clear_text y
4406 G.postRedisplay "dehighlight";
4408 | 47 | 63 -> (* / ? *)
4409 let ondone isforw
s =
4410 cbput state.hists
.pat
s;
4411 state.searchpattern
<- s;
4414 let s = String.create
1 in
4415 s.[0] <- Char.chr
key;
4416 enttext (s, "", Some
(onhist state.hists
.pat
),
4417 textentry, ondone (key = 47))
4419 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4420 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4421 setzoom (conf.zoom +. incr)
4423 | 43 | 0xffab -> (* + *)
4426 try int_of_string
s with exc
->
4427 state.text <- Printf.sprintf
"bad integer `%s': %s"
4428 s (Printexc.to_string exc
);
4434 state.text <- "page bias is now " ^ string_of_int
n;
4437 enttext ("page bias: ", "", None
, intentry, ondone)
4439 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4440 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4441 setzoom (max
0.01 (conf.zoom -. decr))
4443 | 45 | 0xffad -> (* - *)
4444 let ondone msg
= state.text <- msg
in
4446 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4447 optentry state.mode, ondone
4450 | 48 when ctrl -> (* ctrl-0 *)
4453 | 49 when ctrl -> (* 1 *)
4454 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4458 | 0xffc6 -> (* f9 *)
4461 | 57 when ctrl -> (* ctrl-9 *)
4464 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4465 when not
ctrl -> (* 0..9 *)
4468 try int_of_string
s with exc
->
4469 state.text <- Printf.sprintf
"bad integer `%s': %s"
4470 s (Printexc.to_string exc
);
4476 cbput state.hists
.pag
(string_of_int
n);
4477 gotopage1 (n + conf.pagebias
- 1) 0;
4480 let pageentry text key =
4481 match Char.unsafe_chr
key with
4482 | 'g'
-> TEdone
text
4483 | _ -> intentry text key
4485 let text = "x" in text.[0] <- Char.chr
key;
4486 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4489 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4490 reshape conf.winw
conf.winh
;
4493 conf.hlinks
<- not
conf.hlinks
;
4494 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4495 G.postRedisplay "toggle highlightlinks";
4498 state.glinks
<- true;
4501 try int_of_string
s with exc
->
4502 state.text <- Printf.sprintf
"bad integer `%s': %s"
4503 s (Printexc.to_string exc
);
4508 let rec loop = function
4511 match getopaque l.pageno with
4514 match getlink2 opaque
n with
4515 | Unone
-> loop rest
4518 cbput state.hists
.pag
s;
4524 let onkey text key =
4525 match Char.unsafe_chr
key with
4526 | 'g'
-> TEdone
text
4527 | _ -> intentry text key
4529 let mode = state.mode in
4530 state.mode <- Textentry
(
4531 (":", "", Some
(onhist state.hists
.pag
), onkey, ondone),
4533 state.glinks
<- false;
4537 G.postRedisplay "view:enttext"
4540 begin match state.autoscroll
with
4542 conf.autoscrollstep
<- step
;
4543 state.autoscroll
<- None
4545 if conf.autoscrollstep
= 0
4546 then state.autoscroll
<- Some
1
4547 else state.autoscroll
<- Some
conf.autoscrollstep
4551 conf.presentation <- not
conf.presentation;
4552 if conf.presentation
4554 if not
conf.scrollbarinpm
4555 then state.scrollw
<- 0;
4558 state.scrollw
<- conf.scrollbw
;
4560 showtext ' '
("presentation mode " ^
4561 if conf.presentation then "on" else "off");
4562 state.anchor <- getanchor ();
4566 begin match state.fullscreen
with
4568 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4571 state.fullscreen
<- None
;
4576 gotoy_and_clear_text 0
4579 gotopage1 (state.pagecount
- 1) 0
4581 | 112 | 78 -> (* p|N *)
4582 search state.searchpattern
false
4584 | 110 | 0xffc0 -> (* n|F3 *)
4585 search state.searchpattern
true
4588 begin match state.layout with
4591 gotoy_and_clear_text (getpagey l.pageno)
4595 begin match List.rev
state.layout with
4598 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4599 gotoy_and_clear_text (getpagey pageno)
4602 | 0xff9f | 0xffff -> (* delete *)
4603 begin match state.layout with
4606 let pageno = max
0 (l.pageno-1) in
4607 gotoy_and_clear_text (getpagey pageno)
4611 showtext ' '
(describe_location ());
4614 begin match state.layout with
4617 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4622 enterbookmarkmode ()
4624 | 104 | 0xffbe -> (* h|F1 *)
4630 | 101 when conf.redirectstderr -> (* e *)
4635 match state.layout with
4638 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4642 enttext ("bookmark: ", "", None
, textentry, ondone)
4646 showtext ' '
"Quick bookmark added";
4649 begin match state.layout with
4651 let rect = getpdimrect
l.pagedimno
in
4655 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4656 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4658 (truncate
(rect.(1) -. rect.(0)),
4659 truncate
(rect.(3) -. rect.(0)))
4661 let w = truncate
((float w)*.conf.zoom)
4662 and h = truncate
((float h)*.conf.zoom) in
4665 state.anchor <- getanchor ();
4666 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4668 G.postRedisplay "z";
4673 | 50 when ctrl -> (* ctrl-2 *)
4674 let maxw = getmaxw
() in
4676 then setzoom (maxw /. float conf.winw
)
4678 | 60 | 62 -> (* < > *)
4679 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4681 | 91 | 93 -> (* [ ] *)
4683 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4685 G.postRedisplay "brightness";
4687 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4688 setzoom state.prevzoom
4690 | 107 | 0xff52 -> (* k up *)
4691 begin match state.autoscroll
with
4693 begin match state.mode with
4694 | Birdseye beye
-> upbirdseye 1 beye
4697 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4698 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4701 setautoscrollspeed n false
4704 | 106 | 0xff54 -> (* j down *)
4705 begin match state.autoscroll
with
4707 begin match state.mode with
4708 | Birdseye beye
-> downbirdseye 1 beye
4711 then gotoy_and_clear_text (clamp (conf.winh
/2))
4712 else gotoy_and_clear_text (clamp conf.scrollstep
)
4715 setautoscrollspeed n true
4718 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4726 let dx = if key = 0xff51 then dx else -dx in
4727 state.x <- state.x + dx;
4728 gotoy_and_clear_text state.y
4731 G.postRedisplay "lef/right"
4734 | 0xff55 -> (* prior *)
4738 match state.layout with
4740 | l :: _ -> state.y - l.pagey
4746 | 0xff56 -> (* next *)
4750 match List.rev
state.layout with
4752 | l :: _ -> getpagey l.pageno
4758 | 0xff50 -> gotoghyll 0
4759 | 0xff57 -> gotoghyll (clamp state.maxy)
4760 | 0xff53 when Wsi.withalt mask
->
4761 gotoghyll (getnav ~
-1)
4762 | 0xff51 when Wsi.withalt mask
->
4763 gotoghyll (getnav 1)
4766 state.anchor <- getanchor ();
4767 opendoc state.path state.password
4772 | 118 when conf.debug
-> (* v *)
4775 match getopaque l.pageno with
4778 let x0, y0, x1, y1 = pagebbox opaque
in
4779 let a,b = float x0, float y0 in
4780 let c,d = float x1, float y0 in
4781 let e,f = float x1, float y1 in
4782 let h,j
= float x0, float y1 in
4783 let rect = (a,b,c,d,e,f,h,j
) in
4785 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4787 G.postRedisplay "v";
4790 vlog "huh? %s" (Wsi.keyname
key)
4793 let linknavkeyboard key mask
linknav =
4794 let getpage pageno =
4795 let rec loop = function
4797 | l :: _ when l.pageno = pageno -> Some
l
4798 | _ :: rest
-> loop rest
4799 in loop state.layout
4801 let doexact (pageno, n) =
4802 match getopaque pageno, getpage pageno with
4803 | Some opaque
, Some
l ->
4806 let under = getlink opaque
n in
4807 G.postRedisplay "link gotounder";
4813 | 0xff50 -> (* home *)
4814 Some
(findlink opaque LDfirst
), -1
4816 | 0xff57 -> (* end *)
4817 Some
(findlink opaque LDlast
), 1
4819 | 0xff51 -> (* left *)
4820 Some
(findlink opaque
(LDleft
n)), -1
4822 | 0xff53 -> (* right *)
4823 Some
(findlink opaque
(LDright
n)), 1
4825 | 0xff52 -> (* up *)
4826 Some
(findlink opaque
(LDup
n)), -1
4828 | 0xff54 -> (* down *)
4829 Some
(findlink opaque
(LDdown
n)), 1
4834 begin match findpwl
l.pageno dir with
4838 state.mode <- LinkNav
(Ltgendir
dir);
4839 let y, h = getpageyh pageno in
4842 then y + h - conf.winh
4847 begin match getopaque pageno, getpage pageno with
4848 | Some opaque
, Some
_ ->
4850 let ld = if dir > 0 then LDfirst
else LDlast
in
4853 begin match link with
4855 showlinktype (getlink opaque
m);
4856 state.mode <- LinkNav
(Ltexact
(pageno, m));
4857 G.postRedisplay "linknav jpage";
4864 begin match opt with
4865 | Some Lnotfound
-> pwl l dir;
4866 | Some
(Lfound
m) ->
4870 let _, y0, _, y1 = getlinkrect opaque
m in
4872 then gotopage1 l.pageno y0
4874 let d = fstate.fontsize
+ 1 in
4875 if y1 - l.pagey > l.pagevh - d
4876 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
4877 else G.postRedisplay "linknav";
4879 showlinktype (getlink opaque
m);
4880 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
4883 | None
-> viewkeyboard key mask
4885 | _ -> viewkeyboard key mask
4890 G.postRedisplay "leave linknav"
4894 | Ltgendir
_ -> viewkeyboard key mask
4895 | Ltexact exact
-> doexact exact
4898 let keyboard key mask
=
4899 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4900 then wcmd "interrupt"
4901 else state.uioh <- state.uioh#
key key mask
4904 let birdseyekeyboard key mask
4905 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4907 match conf.columns
with
4909 | Some
((c, _, _), _) -> c
4912 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4913 let y, h = getpageyh pageno in
4914 let top = (conf.winh
- h) / 2 in
4915 gotoy (max
0 (y - top))
4916 | 0xff0d -> leavebirdseye beye
false
4917 | 0xff1b -> leavebirdseye beye
true (* escape *)
4918 | 0xff52 -> upbirdseye incr beye
(* prior *)
4919 | 0xff54 -> downbirdseye incr beye
(* next *)
4920 | 0xff51 -> upbirdseye 1 beye
(* up *)
4921 | 0xff53 -> downbirdseye 1 beye
(* down *)
4924 begin match state.layout with
4928 state.mode <- Birdseye
(
4929 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4931 gotopage1 l.pageno 0;
4934 let layout = layout (state.y-conf.winh
) conf.winh
in
4936 | [] -> gotoy (clamp (-conf.winh
))
4938 state.mode <- Birdseye
(
4939 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4941 gotopage1 l.pageno 0
4944 | [] -> gotoy (clamp (-conf.winh
))
4948 begin match List.rev
state.layout with
4950 let layout = layout (state.y + conf.winh
) conf.winh
in
4951 begin match layout with
4953 let incr = l.pageh
- l.pagevh in
4958 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4960 G.postRedisplay "birdseye pagedown";
4962 else gotoy (clamp (incr + conf.interpagespace*2));
4966 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4967 gotopage1 l.pageno 0;
4970 | [] -> gotoy (clamp conf.winh
)
4974 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4978 let pageno = state.pagecount
- 1 in
4979 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4980 if not
(pagevisible state.layout pageno)
4983 match List.rev
state.pdims
with
4985 | (_, _, h, _) :: _ -> h
4987 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4988 else G.postRedisplay "birdseye end";
4989 | _ -> viewkeyboard key mask
4992 let drawpage l linkindexbase
=
4994 match state.mode with
4995 | Textentry
_ -> scalecolor 0.4
4997 | View
-> scalecolor 1.0
4998 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4999 if l.pageno = hooverpageno
5002 if l.pageno = pageno
5008 begin match getopaque l.pageno with
5010 if tileready l l.pagex l.pagey
5012 let x = l.pagedispx - l.pagex
5013 and y = l.pagedispy - l.pagey in
5014 let hlmask = (if conf.hlinks
then 1 else 0)
5015 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5017 postprocess opaque
hlmask x y linkindexbase
;
5024 let scrollindicator () =
5025 let sbw, ph
, sh = state.uioh#
scrollph in
5026 let sbh, pw
, sw = state.uioh#scrollpw
in
5028 GlDraw.color (0.64, 0.64, 0.64);
5030 (float (conf.winw
- sbw), 0.)
5031 (float conf.winw
, float conf.winh
)
5034 (0., float (conf.winh
- sbh))
5035 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5037 GlDraw.color (0.0, 0.0, 0.0);
5040 (float (conf.winw
- sbw), ph
)
5041 (float conf.winw
, ph
+. sh)
5044 (pw
, float (conf.winh
- sbh))
5045 (pw
+. sw, float conf.winh
)
5050 match state.mstate
with
5051 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5054 | Msel
((x0, y0), (x1, y1)) ->
5055 let rec loop = function
5057 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5058 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5059 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5060 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5062 match getopaque l.pageno with
5064 let x0, y0 = pagetranslatepoint l x0 y0 in
5065 let x1, y1 = pagetranslatepoint l x1 y1 in
5066 seltext opaque
(x0, y0, x1, y1);
5074 let showrects rects
=
5076 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5077 GlDraw.polygon_mode `both `fill
;
5078 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5080 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5082 if l.pageno = pageno
5084 let dx = float (l.pagedispx - l.pagex) in
5085 let dy = float (l.pagedispy - l.pagey) in
5086 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5087 GlDraw.begins `quads
;
5089 GlDraw.vertex2
(x0+.dx, y0+.dy);
5090 GlDraw.vertex2
(x1+.dx, y1+.dy);
5091 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5092 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5103 GlClear.color (scalecolor2 conf.bgcolor
);
5104 GlClear.clear
[`
color];
5105 let rec loop linkindexbase
= function
5107 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5108 loop linkindexbase rest
5111 loop 0 state.layout;
5113 match state.mode with
5114 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5115 begin match getopaque pageno with
5117 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5124 | None
-> state.rects
5131 begin match state.mstate
with
5132 | Mzoomrect
((x0, y0), (x1, y1)) ->
5134 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5135 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5136 GlDraw.rect (float x0, float y0)
5137 (float x1, float y1);
5146 let zoomrect x y x1 y1 =
5149 and y0 = min
y y1 in
5150 gotoy (state.y + y0);
5151 state.anchor <- getanchor ();
5152 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5154 if state.w < conf.winw
- state.scrollw
5155 then (conf.winw
- state.scrollw
- state.w) / 2
5158 state.x <- (state.x + margin) - x0;
5160 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5161 state.mstate
<- Mnone
;
5165 let winw = conf.winw - state.scrollw
- 1 in
5166 let s = float x /. float winw in
5167 let destx = truncate
(float (state.w + winw) *. s) in
5168 state.x <- winw - destx;
5169 gotoy_and_clear_text state.y;
5170 state.mstate
<- Mscrollx
;
5174 let s = float y /. float conf.winh
in
5175 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5176 gotoy_and_clear_text desty;
5177 state.mstate
<- Mscrolly
;
5180 let viewmouse button down
x y mask
=
5182 | n when (n == 4 || n == 5) && not down
->
5183 if Wsi.withctrl mask
5185 match state.mstate
with
5186 | Mzoom
(oldn
, i
) ->
5194 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5196 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5198 let zoom = conf.zoom -. incr in
5200 state.mstate
<- Mzoom
(n, 0);
5202 state.mstate
<- Mzoom
(n, i
+1);
5204 else state.mstate
<- Mzoom
(n, 0)
5206 | _ -> state.mstate
<- Mzoom
(n, 0)
5209 match state.autoscroll
with
5210 | Some step
-> setautoscrollspeed step
(n=4)
5214 then -conf.scrollstep
5215 else conf.scrollstep
5217 let incr = incr * 2 in
5218 let y = clamp incr in
5219 gotoy_and_clear_text y
5222 | 1 when Wsi.withctrl mask
->
5225 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5226 state.mstate
<- Mpan
(x, y)
5229 state.mstate
<- Mnone
5234 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5236 state.mstate
<- Mzoomrect
(p, p)
5239 match state.mstate
with
5240 | Mzoomrect
((x0, y0), _) ->
5241 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5242 then zoomrect x0 y0 x y
5244 state.mstate
<- Mnone
;
5245 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5246 G.postRedisplay "kill accidental zoom rect";
5249 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5250 state.mstate
<- Mnone
5253 | 1 when x > conf.winw - state.scrollw
->
5256 let _, position, sh = state.uioh#
scrollph in
5257 if y > truncate
position && y < truncate
(position +. sh)
5258 then state.mstate
<- Mscrolly
5261 state.mstate
<- Mnone
5263 | 1 when y > conf.winh
- state.hscrollh ->
5266 let _, position, sw = state.uioh#scrollpw
in
5267 if x > truncate
position && x < truncate
(position +. sw)
5268 then state.mstate
<- Mscrollx
5271 state.mstate
<- Mnone
5274 let dest = if down
then getunder x y else Unone
in
5275 begin match dest with
5276 | Ulinkgoto
(pageno, top) ->
5280 gotopage1 pageno top;
5286 | Uremote
(filename
, pageno) ->
5288 if Sys.file_exists filename
5291 let dir = Filename.dirname
state.path in
5292 let path = Filename.concat
dir filename
in
5293 if Sys.file_exists
path
5297 if String.length
path > 0
5299 let anchor = getanchor () in
5300 let ranchor = state.path, state.password
, anchor in
5301 state.anchor <- (pageno, 0.0);
5302 state.ranchors
<- ranchor :: state.ranchors
;
5305 else showtext '
!'
("Could not find " ^ filename
)
5307 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5309 | Unone
when down
->
5310 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5311 state.mstate
<- Mpan
(x, y);
5313 | Unone
| Utext
_ ->
5316 if conf.angle
mod 360 = 0
5318 state.mstate
<- Msel
((x, y), (x, y));
5319 G.postRedisplay "mouse select";
5323 match state.mstate
with
5326 | Mzoom
_ | Mscrollx
| Mscrolly
->
5327 state.mstate
<- Mnone
5329 | Mzoomrect
((x0, y0), _) ->
5333 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5334 state.mstate
<- Mnone
5336 | Msel
((_, y0), (_, y1)) ->
5337 let rec loop = function
5340 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5341 || ((y1 >= l.pagedispy
5342 && y1 <= (l.pagedispy + l.pagevh)))
5344 match getopaque l.pageno with
5346 copysel
conf.selcmd opaque
;
5347 G.postRedisplay "copysel"
5352 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5353 state.mstate
<- Mnone
;
5360 let birdseyemouse button down
x y mask
5361 (conf, leftx
, _, hooverpageno
, anchor) =
5364 let rec loop = function
5367 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5368 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5370 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5376 | _ -> viewmouse button down
x y mask
5379 let mouse button down
x y mask
=
5380 state.uioh <- state.uioh#button button down
x y mask
;
5384 state.uioh <- state.uioh#
motion x y
5388 state.uioh <- state.uioh#
pmotion x y;
5394 method key key mask
=
5395 begin match state.mode with
5396 | Textentry
textentry -> textentrykeyboard key mask
textentry
5397 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5398 | View
-> viewkeyboard key mask
5399 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5403 method button button bstate
x y mask
=
5404 begin match state.mode with
5406 | View
-> viewmouse button bstate
x y mask
5407 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5413 begin match state.mode with
5415 | View
| Birdseye
_ | LinkNav
_ ->
5416 match state.mstate
with
5417 | Mzoom
_ | Mnone
-> ()
5422 state.mstate
<- Mpan
(x, y);
5423 if conf.zoom > 1.0 then state.x <- state.x + dx;
5425 gotoy_and_clear_text y
5428 state.mstate
<- Msel
(a, (x, y));
5429 G.postRedisplay "motion select";
5432 let y = min
conf.winh
(max
0 y) in
5436 let x = min
conf.winw (max
0 x) in
5439 | Mzoomrect
(p0
, _) ->
5440 state.mstate
<- Mzoomrect
(p0
, (x, y));
5441 G.postRedisplay "motion zoomrect";
5445 method pmotion x y =
5446 begin match state.mode with
5447 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5448 let rec loop = function
5450 if hooverpageno
!= -1
5452 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5453 G.postRedisplay "pmotion birdseye no hoover";
5456 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5457 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5459 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5460 G.postRedisplay "pmotion birdseye hoover";
5470 match state.mstate
with
5471 | Mnone
-> updateunder x y
5472 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5477 method infochanged
_ = ()
5480 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5481 let p, h = scrollph state.y maxy in
5485 let winw = conf.winw - state.scrollw
- 1 in
5486 let fwinw = float winw in
5488 let sw = fwinw /. float state.w in
5489 let sw = fwinw *. sw in
5490 max
sw (float conf.scrollh
)
5493 let f = state.w+winw in
5494 let r = float (winw-state.x) /. float f in
5495 let p = fwinw *. r in
5499 if position +. sw > fwinw
5500 then fwinw -. position
5503 state.hscrollh, position, sw
5507 match state.mode with
5508 | LinkNav
_ -> "links"
5509 | Textentry
_ -> "textentry"
5510 | Birdseye
_ -> "birdseye"
5513 findkeyhash conf modename
5520 let fontpath = ref "";;
5523 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5526 let l = String.length
s in
5527 let b = Buffer.create
l in
5533 try Sys.getenv
"HOME"
5536 ("Can not determine home directory location: " ^
5537 Printexc.to_string exn
);
5541 let modifier_of_string = function
5542 | "alt" -> Wsi.altmask
5543 | "shift" -> Wsi.shiftmask
5544 | "ctrl" | "control" -> Wsi.ctrlmask
5545 | "meta" -> Wsi.metamask
5550 let r = Str.regexp
"-" in
5552 let elems = Str.full_split
r s in
5555 let m1 = modifier_of_string s in
5557 then (Wsi.namekey
s, m)
5560 | Str.Delim
s when n land 1 = 0 -> g s
5562 | Str.Delim
_ -> (k
, m)
5564 let rec loop n k
m = function
5567 let k, m = f n k m x in
5573 let keys_of_string =
5574 let r = Str.regexp
"[ \t]" in
5576 let elems = Str.split
r s in
5577 List.map
key_of_string elems
5580 let copykeyhashes c =
5581 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5584 let config_of c attrs
=
5588 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5589 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5590 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5591 | "preload" -> { c with preload = bool_of_string
v }
5592 | "page-bias" -> { c with pagebias
= int_of_string
v }
5593 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5594 | "auto-scroll-step" ->
5595 { c with autoscrollstep
= max
0 (int_of_string
v) }
5596 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5597 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5600 match String.lowercase
v with
5601 | "true" -> Some infinity
5603 | f -> Some
(float_of_string
f)
5605 { c with maxwait
= mw}
5606 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5607 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5608 | "vertical-margin" ->
5609 { c with interpagespace = max
0 (int_of_string
v) }
5611 let zoom = float_of_string
v /. 100. in
5612 let zoom = max
zoom 0.0 in
5613 { c with zoom = zoom }
5614 | "presentation" -> { c with presentation = bool_of_string
v }
5615 | "rotation-angle" -> { c with angle
= int_of_string
v }
5616 | "width" -> { c with winw = max
20 (int_of_string
v) }
5617 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5618 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5619 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5620 | "pixmap-cache-size" ->
5621 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5622 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5623 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5624 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5625 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5626 | "background-color" -> { c with bgcolor
= color_of_string v }
5627 | "scrollbar-in-presentation" ->
5628 { c with scrollbarinpm
= bool_of_string
v }
5629 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5630 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5631 | "mupdf-store-size" ->
5632 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5633 | "checkers" -> { c with checkers
= bool_of_string
v }
5634 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5635 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5636 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5637 | "uri-launcher" -> { c with urilauncher
= unent v }
5638 | "path-launcher" -> { c with pathlauncher
= unent v }
5639 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5640 | "invert-colors" -> { c with invert
= bool_of_string
v }
5641 | "brightness" -> { c with colorscale
= float_of_string
v }
5642 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5644 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5646 let nab = columns_of_string v in
5647 { c with columns
= Some
(nab, [||]) }
5648 | "birds-eye-columns" ->
5649 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5650 | "selection-command" -> { c with selcmd
= unent v }
5651 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5654 prerr_endline
("Error processing attribute (`" ^
5655 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5658 let rec fold c = function
5661 let c = apply c k v in
5664 fold { c with keyhashes
= copykeyhashes c } attrs
;
5667 let fromstring f pos
n v d =
5670 dolog "Error processing attribute (%S=%S) at %d\n%s"
5671 n v pos
(Printexc.to_string exn
)
5676 let bookmark_of attrs
=
5677 let rec fold title page
rely = function
5678 | ("title", v) :: rest
-> fold v page
rely rest
5679 | ("page", v) :: rest
-> fold title v rely rest
5680 | ("rely", v) :: rest
-> fold title page
v rest
5681 | _ :: rest
-> fold title page
rely rest
5682 | [] -> title, page
, rely
5684 fold "invalid" "0" "0" attrs
5688 let rec fold path page
rely pan
= function
5689 | ("path", v) :: rest
-> fold v page
rely pan rest
5690 | ("page", v) :: rest
-> fold path v rely pan rest
5691 | ("rely", v) :: rest
-> fold path page
v pan rest
5692 | ("pan", v) :: rest
-> fold path page
rely v rest
5693 | _ :: rest
-> fold path page
rely pan rest
5694 | [] -> path, page
, rely, pan
5696 fold "" "0" "0" "0" attrs
5700 let rec fold rs ls
= function
5701 | ("out", v) :: rest
-> fold v ls rest
5702 | ("in", v) :: rest
-> fold rs
v rest
5703 | _ :: rest
-> fold ls rs rest
5709 let setconf dst
src =
5710 dst
.scrollbw
<- src.scrollbw
;
5711 dst
.scrollh
<- src.scrollh
;
5712 dst
.icase
<- src.icase
;
5713 dst
.preload <- src.preload;
5714 dst
.pagebias
<- src.pagebias
;
5715 dst
.verbose
<- src.verbose
;
5716 dst
.scrollstep
<- src.scrollstep
;
5717 dst
.maxhfit
<- src.maxhfit
;
5718 dst
.crophack
<- src.crophack
;
5719 dst
.autoscrollstep
<- src.autoscrollstep
;
5720 dst
.maxwait
<- src.maxwait
;
5721 dst
.hlinks
<- src.hlinks
;
5722 dst
.underinfo
<- src.underinfo
;
5723 dst
.interpagespace <- src.interpagespace;
5724 dst
.zoom <- src.zoom;
5725 dst
.presentation <- src.presentation;
5726 dst
.angle
<- src.angle
;
5727 dst
.winw <- src.winw;
5728 dst
.winh
<- src.winh
;
5729 dst
.savebmarks
<- src.savebmarks
;
5730 dst
.memlimit
<- src.memlimit
;
5731 dst
.proportional
<- src.proportional
;
5732 dst
.texcount
<- src.texcount
;
5733 dst
.sliceheight
<- src.sliceheight
;
5734 dst
.thumbw
<- src.thumbw
;
5735 dst
.jumpback
<- src.jumpback
;
5736 dst
.bgcolor
<- src.bgcolor
;
5737 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5738 dst
.tilew
<- src.tilew
;
5739 dst
.tileh
<- src.tileh
;
5740 dst
.mustoresize
<- src.mustoresize
;
5741 dst
.checkers
<- src.checkers
;
5742 dst
.aalevel
<- src.aalevel
;
5743 dst
.trimmargins
<- src.trimmargins
;
5744 dst
.trimfuzz
<- src.trimfuzz
;
5745 dst
.urilauncher
<- src.urilauncher
;
5746 dst
.colorspace
<- src.colorspace
;
5747 dst
.invert
<- src.invert
;
5748 dst
.colorscale
<- src.colorscale
;
5749 dst
.redirectstderr <- src.redirectstderr;
5750 dst
.ghyllscroll
<- src.ghyllscroll
;
5751 dst
.columns
<- src.columns
;
5752 dst
.beyecolumns
<- src.beyecolumns
;
5753 dst
.selcmd
<- src.selcmd
;
5754 dst
.updatecurs
<- src.updatecurs
;
5755 dst
.pathlauncher
<- src.pathlauncher
;
5756 dst
.keyhashes
<- copykeyhashes src;
5760 let h = Hashtbl.create
10 in
5761 let dc = { defconf with angle
= defconf.angle
} in
5762 let rec toplevel v t spos
_ =
5764 | Vdata
| Vcdata
| Vend
-> v
5765 | Vopen
("llppconfig", _, closed
) ->
5768 else { v with f = llppconfig
}
5770 error
"unexpected subelement at top level" s spos
5771 | Vclose
_ -> error
"unexpected close at top level" s spos
5773 and llppconfig
v t spos
_ =
5775 | Vdata
| Vcdata
-> v
5776 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5777 | Vopen
("defaults", attrs
, closed
) ->
5778 let c = config_of dc attrs
in
5782 else { v with f = defaults
}
5784 | Vopen
("ui-font", attrs
, closed
) ->
5785 let rec getsize size
= function
5787 | ("size", v) :: rest
->
5789 fromstring int_of_string spos
"size" v fstate.fontsize
in
5791 | l -> getsize size l
5793 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5796 else { v with f = uifont
(Buffer.create
10) }
5798 | Vopen
("doc", attrs
, closed
) ->
5799 let pathent, spage
, srely
, span
= doc_of attrs
in
5800 let path = unent pathent
5801 and pageno = fromstring int_of_string spos
"page" spage
0
5802 and rely = fromstring float_of_string spos
"rely" srely
0.0
5803 and pan
= fromstring int_of_string spos
"pan" span
0 in
5804 let c = config_of dc attrs
in
5805 let anchor = (pageno, rely) in
5807 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5808 else { v with f = doc
path pan
anchor c [] }
5811 error
"unexpected subelement in llppconfig" s spos
5813 | Vclose
"llppconfig" -> { v with f = toplevel }
5814 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5816 and defaults
v t spos
_ =
5818 | Vdata
| Vcdata
-> v
5819 | Vend
-> error
"unexpected end of input in defaults" s spos
5820 | Vopen
("keymap", attrs
, closed
) ->
5822 try List.assoc
"mode" attrs
5823 with Not_found
-> "global" in
5828 let h = findkeyhash dc modename in
5829 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5832 { v with f = pkeymap
ret KeyMap.empty }
5834 | Vopen
(_, _, _) ->
5835 error
"unexpected subelement in defaults" s spos
5837 | Vclose
"defaults" ->
5838 { v with f = llppconfig
}
5840 | Vclose
_ -> error
"unexpected close in defaults" s spos
5842 and uifont
b v t spos
epos =
5845 Buffer.add_substring
b s spos
(epos - spos
);
5847 | Vopen
(_, _, _) ->
5848 error
"unexpected subelement in ui-font" s spos
5849 | Vclose
"ui-font" ->
5850 if String.length
!fontpath = 0
5851 then fontpath := Buffer.contents
b;
5852 { v with f = llppconfig
}
5853 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5854 | Vend
-> error
"unexpected end of input in ui-font" s spos
5856 and doc
path pan
anchor c bookmarks
v t spos
_ =
5858 | Vdata
| Vcdata
-> v
5859 | Vend
-> error
"unexpected end of input in doc" s spos
5860 | Vopen
("bookmarks", _, closed
) ->
5863 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5865 | Vopen
("keymap", attrs
, closed
) ->
5867 try List.assoc
"mode" attrs
5868 with Not_found
-> "global"
5874 let h = findkeyhash c modename in
5875 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5876 doc
path pan
anchor c bookmarks
5878 { v with f = pkeymap
ret KeyMap.empty }
5880 | Vopen
(_, _, _) ->
5881 error
"unexpected subelement in doc" s spos
5884 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5885 { v with f = llppconfig
}
5887 | Vclose
_ -> error
"unexpected close in doc" s spos
5889 and pkeymap
ret keymap
v t spos
_ =
5891 | Vdata
| Vcdata
-> v
5892 | Vend
-> error
"unexpected end of input in keymap" s spos
5893 | Vopen
("map", attrs
, closed
) ->
5894 let r, l = map_of attrs
in
5895 let kss = fromstring keys_of_string spos
"in" r [] in
5896 let lss = fromstring keys_of_string spos
"out" l [] in
5900 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5901 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5904 then { v with f = pkeymap
ret keymap }
5907 { v with f = skip
"map" f }
5910 error
"unexpected subelement in keymap" s spos
5912 | Vclose
"keymap" ->
5913 { v with f = ret keymap }
5915 | Vclose
_ -> error
"unexpected close in keymap" s spos
5917 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5919 | Vdata
| Vcdata
-> v
5920 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5921 | Vopen
("item", attrs
, closed
) ->
5922 let titleent, spage
, srely
= bookmark_of attrs
in
5923 let page = fromstring int_of_string spos
"page" spage
0
5924 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5925 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5927 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5930 { v with f = skip
"item" f }
5933 error
"unexpected subelement in bookmarks" s spos
5935 | Vclose
"bookmarks" ->
5936 { v with f = doc
path pan
anchor c bookmarks }
5938 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5940 and skip tag
f v t spos
_ =
5942 | Vdata
| Vcdata
-> v
5944 error
("unexpected end of input in skipped " ^ tag
) s spos
5945 | Vopen
(tag'
, _, closed
) ->
5949 let f'
() = { v with f = skip tag
f } in
5950 { v with f = skip tag'
f'
}
5954 else error
("unexpected close in skipped " ^ tag
) s spos
5957 parse
{ f = toplevel; accu = () } s;
5963 let len = in_channel_length ic
in
5964 let s = String.create
len in
5965 really_input ic
s 0 len;
5968 | Parse_error
(msg
, s, pos
) ->
5969 let subs = subs s pos
in
5970 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5971 failwith
("parse error: " ^
s)
5974 failwith
("config load error: " ^
Printexc.to_string exn
)
5980 let dir = Filename.concat
home ".config" in
5981 if Sys.is_directory
dir then dir else home
5984 Filename.concat
dir "llpp.conf"
5987 let confpath = ref defconfpath;;
5990 if Sys.file_exists
!confpath
5993 (try Some
(open_in_bin
!confpath)
5996 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5997 Printexc.to_string exn
);
6006 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6007 Printexc.to_string exn
);
6013 f (Hashtbl.create
0, defconf)
6018 let pc, pb
, px, pa
=
6020 Hashtbl.find h (Filename.basename
state.path)
6021 with Not_found
-> dc, [], 0, (0, 0.0)
6025 state.bookmarks <- pb
;
6027 state.scrollw
<- conf.scrollbw
;
6029 then state.anchor <- pa
;
6030 cbput state.hists
.nav pa
;
6035 let add_attrs bb always
dc c =
6038 then Printf.bprintf bb
"\n %s='%b'" s a
6041 then Printf.bprintf bb
"\n %s='%d'" s a
6044 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6047 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6050 then Printf.bprintf bb
"\n %s='%f'" s a
6054 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6058 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6062 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6066 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6072 | Some
(_N
, _A
, _B
) ->
6073 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6083 else string_of_float
f
6085 Printf.bprintf bb
"\n %s='%s'" s v
6090 | Some
((n, a, b), _) when n > 1 ->
6091 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6097 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6102 then dc.winw, dc.winh
6104 match state.fullscreen
with
6106 | None
-> c.winw, c.winh
6108 let zoom, presentation, interpagespace, maxwait
=
6110 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6112 match state.mode with
6113 | Birdseye
(bc
, _, _, _, _) ->
6114 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6115 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6117 oi
"width" w dc.winw;
6118 oi
"height" h dc.winh
;
6119 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6120 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6121 ob "case-insensitive-search" c.icase
dc.icase
;
6122 ob "preload" c.preload dc.preload;
6123 oi
"page-bias" c.pagebias
dc.pagebias
;
6124 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6125 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6126 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6127 ob "crop-hack" c.crophack
dc.crophack
;
6128 oW
"throttle" maxwait
dc.maxwait
;
6129 ob "highlight-links" c.hlinks
dc.hlinks
;
6130 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6131 oi
"vertical-margin" interpagespace dc.interpagespace;
6132 oz
"zoom" zoom dc.zoom;
6133 ob "presentation" presentation dc.presentation;
6134 oi
"rotation-angle" c.angle
dc.angle
;
6135 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6136 ob "proportional-display" c.proportional
dc.proportional
;
6137 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6138 oi
"tex-count" c.texcount
dc.texcount
;
6139 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6140 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6141 ob "persistent-location" c.jumpback
dc.jumpback
;
6142 oc
"background-color" c.bgcolor
dc.bgcolor
;
6143 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6144 oi
"tile-width" c.tilew
dc.tilew
;
6145 oi
"tile-height" c.tileh
dc.tileh
;
6146 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6147 ob "checkers" c.checkers
dc.checkers
;
6148 oi
"aalevel" c.aalevel
dc.aalevel
;
6149 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6150 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6151 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6152 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6153 oC
"color-space" c.colorspace
dc.colorspace
;
6154 ob "invert-colors" c.invert
dc.invert
;
6155 oF
"brightness" c.colorscale
dc.colorscale
;
6156 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6157 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6158 oco
"columns" c.columns
dc.columns
;
6159 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6160 os
"selection-command" c.selcmd
dc.selcmd
;
6161 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6164 let keymapsbuf always
dc c =
6165 let bb = Buffer.create
16 in
6166 let rec loop = function
6168 | (modename, h) :: rest
->
6169 let dh = findkeyhash dc modename in
6170 if always
|| h <> dh
6172 if Hashtbl.length
h > 0
6174 if Buffer.length
bb > 0
6175 then Buffer.add_char
bb '
\n'
;
6176 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6177 Hashtbl.iter
(fun i
o ->
6178 let isdifferent = always
||
6180 let dO = Hashtbl.find dh i
in
6182 with Not_found
-> true
6187 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6188 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6189 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6190 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6191 Buffer.add_string
bb (Wsi.keyname
k);
6194 let rec loop = function
6196 | km
:: [] -> addkm km
6197 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6201 Buffer.add_string
bb "<map in='";
6205 Buffer.add_string
bb "' out='";
6207 Buffer.add_string
bb "'/>\n"
6210 Buffer.add_string
bb "' out='";
6212 Buffer.add_string
bb "'/>\n"
6214 | KMmulti
(ins, kms
) ->
6215 Buffer.add_char
bb ' '
;
6217 Buffer.add_string
bb "' out='";
6219 Buffer.add_string
bb "'/>\n"
6221 Buffer.add_string
bb "</keymap>";
6231 let uifontsize = fstate.fontsize
in
6232 let bb = Buffer.create
32768 in
6234 let dc = if conf.bedefault
then conf else dc in
6235 Buffer.add_string
bb "<llppconfig>\n";
6237 if String.length
!fontpath > 0
6239 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6245 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6248 Buffer.add_string
bb "<defaults ";
6249 add_attrs bb true dc dc;
6250 let kb = keymapsbuf true dc dc in
6251 if Buffer.length
kb > 0
6253 Buffer.add_string
bb ">\n";
6254 Buffer.add_buffer
bb kb;
6255 Buffer.add_string
bb "\n</defaults>\n";
6257 else Buffer.add_string
bb "/>\n";
6259 let adddoc path pan
anchor c bookmarks =
6260 if bookmarks == [] && c = dc && anchor = emptyanchor
6263 Printf.bprintf
bb "<doc path='%s'"
6264 (enent
path 0 (String.length
path));
6266 if anchor <> emptyanchor
6268 let n, y = anchor in
6269 Printf.bprintf
bb " page='%d'" n;
6272 Printf.bprintf
bb " rely='%f'" y
6277 then Printf.bprintf
bb " pan='%d'" pan
;
6279 add_attrs bb false dc c;
6280 let kb = keymapsbuf false dc c in
6282 begin match bookmarks with
6284 if Buffer.length
kb > 0
6286 Buffer.add_string
bb ">\n";
6287 Buffer.add_buffer
bb kb;
6288 Buffer.add_string
bb "</doc>\n";
6290 else Buffer.add_string
bb "/>\n"
6292 Buffer.add_string
bb ">\n<bookmarks>\n";
6293 List.iter
(fun (title, _level
, (page, rely)) ->
6295 "<item title='%s' page='%d'"
6296 (enent
title 0 (String.length
title))
6301 Printf.bprintf
bb " rely='%f'" rely
6303 Buffer.add_string
bb "/>\n";
6305 Buffer.add_string
bb "</bookmarks>";
6306 if Buffer.length
kb > 0
6308 Buffer.add_string
bb "\n";
6309 Buffer.add_buffer
bb kb;
6311 Buffer.add_string
bb "\n</doc>\n";
6317 match state.mode with
6318 | Birdseye
(c, pan, _, _, _) ->
6320 match conf.columns
with
6321 | Some
((c, _, _), _) -> Some
c
6324 match c.columns
with
6325 | Some
(c, _) -> Some
(c, [||])
6328 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6329 | _ -> state.x, conf
6331 let basename = Filename.basename state.path in
6332 adddoc basename pan (getanchor ())
6335 match state.autoscroll
with
6337 | None
-> conf.autoscrollstep
}
6338 (if conf.savebmarks
then state.bookmarks else []);
6340 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6342 then adddoc path x y c bookmarks
6344 Buffer.add_string
bb "</llppconfig>";
6347 if Buffer.length
bb > 0
6350 let tmp = !confpath ^
".tmp" in
6351 let oc = open_out_bin
tmp in
6352 Buffer.output_buffer
oc bb;
6354 Unix.rename
tmp !confpath;
6357 ("error while saving configuration: " ^
Printexc.to_string exn
)
6364 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6365 "<password> Set password");
6367 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6368 "<path> Set path to the user interface font");
6370 ("-c", Arg.String
(fun s -> Config.confpath := s),
6371 "<path> Set path to the configuration file");
6373 ("-v", Arg.Unit
(fun () ->
6375 "%s\nconfiguration path: %s\n"
6379 exit
0), " Print version and exit");
6382 (fun s -> state.path <- s)
6383 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6385 if String.length
state.path = 0
6386 then (prerr_endline
"file name missing"; exit
1);
6390 let globalkeyhash = findkeyhash conf "global" in
6391 let wsfd, winw, winh
= Wsi.init
(object
6393 if nogeomcmds state.geomcmds
6395 method display = display ()
6396 method reshape w h = reshape w h
6397 method mouse b d x y m = mouse b d x y m
6398 method motion x y = state.mpos
<- (x, y); motion x y
6399 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6401 let mascm = m land (
6402 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6404 match state.keystate
with
6406 let km = k, mascm in
6409 try Hashtbl.find globalkeyhash km
6411 let modehash = state.uioh#
modehash in
6412 try Hashtbl.find modehash km
6413 with Not_found
-> KMinsrt
(k, m)
6415 | KMinsrt
(k, m) -> keyboard k m
6416 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6417 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6419 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6420 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6421 state.keystate
<- KSnone
6422 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6423 state.keystate
<- KSinto
(keys
, insrt
)
6425 state.keystate
<- KSnone
6427 method enter
x y = state.mpos
<- (x, y); pmotion x y
6428 method leave = state.mpos
<- (-1, -1)
6429 method quit
= raise Quit
6430 end) conf.winw conf.winh
(platform = Posx
) in
6435 List.exists
GlMisc.check_extension
6436 [ "GL_ARB_texture_rectangle"
6437 ; "GL_EXT_texture_recangle"
6438 ; "GL_NV_texture_rectangle" ]
6440 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6442 let cr, sw = Unix.pipe
()
6443 and sr
, cw
= Unix.pipe
() in
6450 setcheckers conf.checkers
;
6454 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6455 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6460 state.text <- "Opening " ^
state.path;
6461 opendoc state.path state.password
;
6463 setfontsize fstate.fontsize
;
6466 let rec loop deadline
=
6468 match state.errfd
with
6469 | None
-> [state.sr
; state.wsfd]
6470 | Some fd
-> [state.sr
; state.wsfd; fd
]
6474 state.redisplay
<- false;
6481 if deadline
= infinity
6483 else max
0.0 (deadline
-. now)
6488 try Unix.select
r [] [] timeout
6489 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6495 if state.ghyll
== noghyll
6497 match state.autoscroll
with
6498 | Some step
when step
!= 0 ->
6499 let y = state.y + step
in
6503 else if y >= state.maxy then 0 else y
6506 if state.mode = View
6507 then state.text <- "";
6510 else deadline
+. 0.01
6515 let rec checkfds = function
6517 | fd
:: rest
when fd
= state.sr
->
6518 let cmd = readcmd state.sr
in
6522 | fd
:: rest
when fd
= state.wsfd ->
6527 let s = String.create
80 in
6528 let n = Unix.read fd
s 0 80 in
6529 if conf.redirectstderr
6531 Buffer.add_substring
state.errmsgs
s 0 n;
6532 state.newerrmsgs
<- true;
6533 state.redisplay
<- true;
6536 prerr_string
(String.sub
s 0 n);
6544 if deadline
= infinity
6548 match state.autoscroll
with
6549 | Some step
when step
!= 0 -> deadline1
6550 | _ -> if state.ghyll
== noghyll then infinity
else deadline1