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
: Unix.file_descr
-> 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 * string) -> 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 getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
115 if platform = Pcygwin
117 let sh = "/bin/sh" in
118 let args = [|sh; "-c"; cmd
|] in
119 let rec std si so se
= function
121 | (fd
, 0) :: rest
-> std fd so se rest
122 | (fd
, -1) :: rest
->
123 Unix.set_close_on_exec fd
;
126 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
128 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
129 ignore
(Unix.create_process
sh args si so se
)
138 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
141 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
143 type mpos
= int * int
145 | Msel
of (mpos
* mpos
)
147 | Mscrolly
| Mscrollx
148 | Mzoom
of (int * int)
149 | Mzoomrect
of (mpos
* mpos
)
153 type textentry
= string * string * onhist
option * onkey
* ondone
154 and onkey
= string -> int -> te
155 and ondone
= string -> unit
156 and histcancel
= unit -> unit
157 and onhist
= ((histcmd
-> string) * histcancel
)
158 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
163 | TEswitch
of textentry
174 let bound v minv maxv
=
175 max minv
(min maxv v
);
179 { store
= Array.create n v
186 let drawstring size x y s
=
188 Gl.enable `texture_2d
;
189 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
190 ignore
(drawstr size x y s
);
192 Gl.disable `texture_2d
;
195 let drawstring1 size x y s
=
199 let drawstring2 size x y fmt
=
200 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
203 let cbcap b
= Array.length b
.store
;;
208 b
.wc
<- (b
.wc
+ 1) mod cap;
210 b
.len
<- min
(b
.len
+ 1) cap;
213 let cbempty b
= b
.len
= 0;;
215 let cbgetg b circular dir
=
219 let rc = b
.rc + dir
in
231 else max
0 (min
rc (b
.len
-1))
237 let cbget b
= cbgetg b
false;;
238 let cbgetc b
= cbgetg b
true;;
255 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
256 dolog " WxH %dx%d" l
.pagew l
.pageh
;
257 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
258 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
259 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
263 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
265 dolog " x0,y0=(% f, % f)" x0 y0
;
266 dolog " x1,y1=(% f, % f)" x1 y1
;
267 dolog " x2,y2=(% f, % f)" x2 y2
;
268 dolog " x3,y3=(% f, % f)" x3 y3
;
272 type multicolumns
= multicol
* pagegeom
273 and splitcolumns
= columncount
* pagegeom
274 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
275 and multicol
= columncount
* covercount
* covercount
277 and columncount
= int
278 and covercount
= int;;
281 { mutable scrollbw
: int
282 ; mutable scrollh
: int
283 ; mutable icase
: bool
284 ; mutable preload
: bool
285 ; mutable pagebias
: int
286 ; mutable verbose
: bool
287 ; mutable debug
: bool
288 ; mutable scrollstep
: int
289 ; mutable maxhfit
: bool
290 ; mutable crophack
: bool
291 ; mutable autoscrollstep
: int
292 ; mutable maxwait
: float option
293 ; mutable hlinks
: bool
294 ; mutable underinfo
: bool
295 ; mutable interpagespace
: interpagespace
296 ; mutable zoom
: float
297 ; mutable presentation
: bool
298 ; mutable angle
: angle
301 ; mutable savebmarks
: bool
302 ; mutable proportional
: proportional
303 ; mutable trimmargins
: trimmargins
304 ; mutable trimfuzz
: irect
305 ; mutable memlimit
: memsize
306 ; mutable texcount
: texcount
307 ; mutable sliceheight
: sliceheight
308 ; mutable thumbw
: width
309 ; mutable jumpback
: bool
310 ; mutable bgcolor
: float * float * float
311 ; mutable bedefault
: bool
312 ; mutable scrollbarinpm
: bool
313 ; mutable tilew
: int
314 ; mutable tileh
: int
315 ; mutable mustoresize
: memsize
316 ; mutable checkers
: bool
317 ; mutable aalevel
: int
318 ; mutable urilauncher
: string
319 ; mutable pathlauncher
: string
320 ; mutable colorspace
: colorspace
321 ; mutable invert
: bool
322 ; mutable colorscale
: float
323 ; mutable redirectstderr
: bool
324 ; mutable ghyllscroll
: (int * int * int) option
325 ; mutable columns
: columns
326 ; mutable beyecolumns
: columncount
option
327 ; mutable selcmd
: string
328 ; mutable updatecurs
: bool
329 ; mutable keyhashes
: (string * keyhash
) list
333 | Cmulti
of multicolumns
334 | Csplit
of splitcolumns
337 type anchor
= pageno
* top
;;
339 type outline
= string * int * anchor
;;
341 type rect
= float * float * float * float * float * float * float * float;;
343 type tile
= opaque
* pixmapsize
* elapsed
344 and elapsed
= float;;
345 type pagemapkey
= pageno
* gen
;;
346 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
350 let emptyanchor = (0, 0.0);;
352 type infochange
= | Memused
| Docinfo
| Pdim
;;
354 class type uioh
= object
355 method display
: unit
356 method key
: int -> int -> uioh
357 method button
: int -> bool -> int -> int -> int -> uioh
358 method motion
: int -> int -> uioh
359 method pmotion
: int -> int -> uioh
360 method infochanged
: infochange
-> unit
361 method scrollpw
: (int * float * float)
362 method scrollph
: (int * float * float)
363 method modehash
: keyhash
367 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
368 | Textentry
of (textentry
* onleave
)
370 | LinkNav
of linktarget
371 and onleave
= leavetextentrystatus
-> unit
372 and leavetextentrystatus
= | Cancel
| Confirm
373 and helpitem
= string * int * action
376 | Action
of (uioh
-> uioh
)
378 | Ltexact
of (pageno
* int)
382 let isbirdseye = function Birdseye _
-> true | _
-> false;;
383 let istextentry = function Textentry _
-> true | _
-> false;;
387 | Loading
of (page
* gen
)
389 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
391 | Outlining
of outline list
394 let emptykeyhash = Hashtbl.create
0;;
395 let nouioh : uioh
= object (self
)
397 method key _ _
= self
398 method button _ _ _ _ _
= self
399 method motion _ _
= self
400 method pmotion _ _
= self
401 method infochanged _
= ()
402 method scrollpw
= (0, nan
, nan
)
403 method scrollph
= (0, nan
, nan
)
404 method modehash
= emptykeyhash
408 { mutable sr
: Unix.file_descr
409 ; mutable sw
: Unix.file_descr
410 ; mutable wsfd
: Unix.file_descr
411 ; mutable errfd
: Unix.file_descr
option
412 ; mutable stderr
: Unix.file_descr
413 ; mutable errmsgs
: Buffer.t
414 ; mutable newerrmsgs
: bool
418 ; mutable scrollw
: int
419 ; mutable hscrollh
: int
420 ; mutable anchor
: anchor
421 ; mutable ranchors
: (string * string * anchor
) list
423 ; mutable layout
: page list
424 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
425 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
426 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
427 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
428 ; mutable pagecount
: int
429 ; mutable currently
: currently
430 ; mutable mstate
: mstate
431 ; mutable searchpattern
: string
432 ; mutable rects
: (pageno
* recttype
* rect
) list
433 ; mutable rects1
: (pageno
* recttype
* rect
) list
434 ; mutable text
: string
435 ; mutable fullscreen
: (width
* height
) option
436 ; mutable mode
: mode
437 ; mutable uioh
: uioh
438 ; mutable outlines
: outline array
439 ; mutable bookmarks
: outline list
440 ; mutable path
: string
441 ; mutable password
: string
442 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
443 ; mutable memused
: memsize
445 ; mutable throttle
: (page list
* int * float) option
446 ; mutable autoscroll
: int option
447 ; mutable ghyll
: (int option -> unit)
448 ; mutable help
: helpitem array
449 ; mutable docinfo
: (int * string) list
450 ; mutable texid
: GlTex.texture_id
option
452 ; mutable prevzoom
: float
453 ; mutable progress
: float
454 ; mutable redisplay
: bool
455 ; mutable mpos
: mpos
456 ; mutable keystate
: keystate
457 ; mutable glinks
: bool
460 { pat
: string circbuf
461 ; pag
: string circbuf
462 ; nav
: anchor circbuf
463 ; sel
: string circbuf
484 ; presentation
= false
489 ; proportional
= true
490 ; trimmargins
= false
491 ; trimfuzz
= (0,0,0,0)
492 ; memlimit
= 32 lsl 20
497 ; bgcolor
= (0.5, 0.5, 0.5)
499 ; scrollbarinpm
= true
502 ; mustoresize
= 256 lsl 20
507 | Plinux
| Pfreebsd
| Pdragonflybsd
508 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
509 | Posx
-> "open \"%s\""
510 | Pcygwin
-> "cygstart \"%s\""
511 | Punknown
-> "echo %s")
512 ; pathlauncher
= "lp \"%s\""
515 | Plinux
| Pfreebsd
| Pdragonflybsd
516 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
523 ; redirectstderr
= false
529 let mk n
= (n
, Hashtbl.create
1) in
542 let findkeyhash c name
=
543 try List.assoc name c
.keyhashes
544 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
547 let conf = { defconf with angle
= defconf.angle
};;
550 { mutable fontsize
: int
551 ; mutable wwidth
: float
552 ; mutable maxrows
: int
564 fstate.fontsize
<- n
;
565 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
566 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
570 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
571 let len = String.length s
in
572 if colonpos >= 0 && colonpos + 3 < len
574 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
577 try String.rindex_from s
colonpos ' '
581 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
584 | "http" | "ftp" | "mailto" ->
586 try String.index_from s
colonpos ' '
587 with Not_found
-> len
589 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
597 if String.length
conf.urilauncher
= 0
598 then print_endline uri
600 let url = geturl uri
in
601 if String.length
url = 0
602 then print_endline uri
604 let re = Str.regexp
"%s" in
605 let command = Str.global_replace
re url conf.urilauncher
in
609 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
615 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
616 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
620 let strings = version () :: "" :: Help.keys
in
623 let url = geturl s
in
624 if String.length
url > 0
625 then (s
, 0, Action
(fun u
-> gotouri url; u
))
626 else (s
, 0, Noaction
)
631 let firstgeomcmds = "", [];;
638 ; stderr
= Unix.stderr
639 ; errmsgs
= Buffer.create
0
646 ; anchor
= emptyanchor
650 ; tilelru
= Queue.create
()
651 ; pagemap
= Hashtbl.create
10
652 ; tilemap
= Hashtbl.create
10
667 ; geomcmds
= firstgeomcmds
669 { nav
= cbnew 10 (0, 0.0)
695 Printf.kprintf prerr_endline fmt
697 Printf.kprintf ignore fmt
701 if String.length
conf.pathlauncher
= 0
702 then print_endline
state.path
704 let re = Str.regexp
"%s" in
705 let command = Str.global_replace
re state.path
conf.pathlauncher
in
709 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
714 let redirectstderr () =
715 if conf.redirectstderr
717 let rfd, wfd
= Unix.pipe
() in
718 state.stderr
<- Unix.dup
Unix.stderr
;
719 state.errfd
<- Some
rfd;
720 Unix.dup2 wfd
Unix.stderr
;
722 state.newerrmsgs
<- false;
723 begin match state.errfd
with
726 Unix.dup2
state.stderr
Unix.stderr
;
730 prerr_string
(Buffer.contents
state.errmsgs
);
732 Buffer.clear
state.errmsgs
;
738 let postRedisplay who
=
740 then prerr_endline
("redisplay for " ^ who
);
741 state.redisplay
<- true;
745 let getopaque pageno
=
746 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
747 with Not_found
-> None
750 let putopaque pageno opaque
=
751 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
754 let pagetranslatepoint l x y
=
755 let dy = y
- l
.pagedispy
in
756 let y = dy + l
.pagey
in
757 let dx = x
- l
.pagedispx
in
758 let x = dx + l
.pagex
in
765 begin match getopaque l
.pageno
with
767 let x0 = l
.pagedispx
in
768 let x1 = x0 + l
.pagevw
in
769 let y0 = l
.pagedispy
in
770 let y1 = y0 + l
.pagevh
in
771 if y >= y0 && y <= y1 && x >= x0 && x <= x1
773 let px, py
= pagetranslatepoint l
x y in
774 match whatsunder opaque
px py
with
787 state.text
<- Printf.sprintf
"%c%s" c s
;
788 G.postRedisplay "showtext";
791 let updateunder x y =
792 match getunder x y with
793 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
795 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
796 Wsi.setcursor
Wsi.CURSOR_INFO
797 | Ulinkgoto
(page
, _
) ->
799 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
800 Wsi.setcursor
Wsi.CURSOR_INFO
802 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
803 Wsi.setcursor
Wsi.CURSOR_TEXT
805 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
806 Wsi.setcursor
Wsi.CURSOR_INHERIT
808 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
809 Wsi.setcursor
Wsi.CURSOR_INHERIT
811 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
812 Wsi.setcursor
Wsi.CURSOR_INHERIT
813 | Uremote
(filename
, pageno
) ->
814 if conf.underinfo
then showtext 'r'
815 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
816 Wsi.setcursor
Wsi.CURSOR_INFO
819 let showlinktype under
=
825 showtext 'u'
("ri: " ^ uri
)
826 | Ulinkgoto
(page
, _
) ->
827 showtext 'p'
("age: " ^ string_of_int
(page
+1));
829 showtext '
f'
("ont: " ^ s
);
831 showtext 'u'
("nexpected: " ^ s
);
833 showtext 'l'
("aunch: " ^ s
);
835 showtext 'n'
("amed: " ^ s
);
836 | Uremote
(filename
, pageno
) ->
837 showtext 'r'
(Printf.sprintf
"emote: %s (%d)" filename pageno
);
841 let b = Buffer.create
(String.length s
+ 1) in
842 Buffer.add_string
b s
;
847 let colorspace_of_string s
=
848 match String.lowercase s
with
852 | _
-> failwith
"invalid colorspace"
855 let int_of_colorspace = function
861 let colorspace_of_int = function
865 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
868 let colorspace_to_string = function
874 let intentry_with_suffix text key
=
876 if key
>= 32 && key
< 127
880 match Char.lowercase
c with
882 let text = addchar text c in
886 let text = addchar text c in
890 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
894 let multicolumns_to_string (n
, a
, b) =
896 then Printf.sprintf
"%d" n
897 else Printf.sprintf
"%d,%d,%d" n a
b;
900 let multicolumns_of_string s
=
902 (int_of_string s
, 0, 0)
904 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
909 let n = Unix.read fd
s 0 4 in
910 if n != 4 then failwith
"incomplete read(len)";
912 lor (Char.code
s.[0] lsl 24)
913 lor (Char.code
s.[1] lsl 16)
914 lor (Char.code
s.[2] lsl 8)
915 lor (Char.code
s.[3] lsl 0)
917 let s = String.create
len in
918 let n = Unix.read fd
s 0 len in
919 if n != len then failwith
"incomplete read(data)";
923 let btod b = if b then 1 else 0;;
926 let b = Buffer.create
16 in
927 Buffer.add_string
b "llll";
930 let s = Buffer.contents
b in
931 let n = String.length
s in
933 (* dolog "wcmd %S" (String.sub s 4 len); *)
934 s.[0] <- Char.chr
((len lsr 24) land 0xff);
935 s.[1] <- Char.chr
((len lsr 16) land 0xff);
936 s.[2] <- Char.chr
((len lsr 8) land 0xff);
937 s.[3] <- Char.chr
(len land 0xff);
938 let n'
= Unix.write
state.sw
s 0 n in
939 if n'
!= n then failwith
"write failed";
946 let d = conf.winh
- h
in
953 let rec f pn ph pi fh l
=
955 | (n, _
, h
, _
) :: rest
->
956 let ips = calcips h
in
961 if isbirdseye state.mode
&& pn
= 0
966 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
971 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
975 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
978 let fh = f 0 0 0 0 state.pdims
in
983 match conf.columns
with
984 | Csingle
-> calcheight ()
985 | Cmulti
((c, _
, _
), b) ->
990 if n = Array.length
b
993 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
999 loop max_int
0 (((Array.length
b - 1) / c) * c)
1001 if Array.length
b > 0
1003 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1008 let getpageyh pageno
=
1009 let rec f pn ph pi
y l
=
1011 | (n, _
, h
, _
) :: rest
->
1012 let ips = calcips h
in
1015 let h = if n = pageno
then h else ph
in
1016 if conf.presentation
&& n = pageno
1018 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1020 y + (pageno
- pn
) * (ph
+ pi
), h
1022 let y = y + (if conf.presentation
then pi
else 0) in
1023 let y = y + (n - pn
) * (ph
+ pi
) in
1027 y + (pageno
- pn
) * (ph
+ pi
), ph
1029 f 0 0 0 0 state.pdims
1032 let getpageyh pageno
=
1033 match conf.columns
with
1034 | Csingle
-> getpageyh pageno
1036 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1040 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1044 let getpagedim pageno
=
1047 | (n, _
, _
, _
) as pdim
:: rest
->
1049 then (if n = pageno
then pdim
else ppdim
)
1054 f (-1, -1, -1, -1) state.pdims
1057 let getpagey pageno
= fst
(getpageyh pageno
);;
1059 let nogeomcmds cmds
=
1061 | s, [] -> String.length
s = 0
1066 let sh = sh - state.hscrollh
in
1067 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1068 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1070 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1071 let ips = calcips h in
1073 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1077 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1079 prev
, pdims
, pdimno
, 0
1081 let dy = dy + yinc in
1082 let py = py + yinc in
1083 if pageno
= state.pagecount
|| dy >= sh
1088 if py + h <= vy - yinc
1090 let py = py + h + ips in
1091 let dy = max
0 (py - y) in
1092 f ~pageno
:(pageno
+1)
1100 let pagey = vy - py in
1101 let pagevh = h - pagey in
1102 let pagevh = min
(sh - dy) pagevh in
1103 let off = if yinc > 0 then py - vy else 0 in
1104 let py = py + h + ips in
1107 if state.w
< conf.winw
- state.scrollw
1108 then (conf.winw
- state.scrollw
- state.w
) / 2
1111 let dispx = xoff + state.x in
1117 let lw = w
- pagex in
1118 min
lw (conf.winw
- state.scrollw
)
1122 ; pagedimno
= pdimno
1126 ; pagey = pagey + off
1128 ; pagevh = pagevh - off
1130 ; pagedispy
= dy + off
1133 let accu = e :: accu in
1134 f ~pageno
:(pageno
+1)
1155 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1156 let sh = sh - state.hscrollh
in
1157 let rec fold accu n =
1158 if n = Array.length
b
1161 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1164 || n = state.pagecount
- coverB
1165 || (n - coverA
) mod columns
= columns
- 1)
1171 let pagey = max
0 (y - vy) in
1172 let pagedispy = if pagey > 0 then 0 else vy - y in
1173 let pagedispx, pagex =
1175 if n = coverA
- 1 || n = state.pagecount
- coverB
1176 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1177 else dx + xoff + state.x
1184 let vw = conf.winw
- state.scrollw
- pagedispx in
1185 let pw = w
- pagex in
1188 let pagevh = min
(h - pagey) (sh - pagedispy) in
1189 if pagevw > 0 && pagevh > 0
1193 ; pagedimno
= pdimno
1200 ; pagedispx = pagedispx
1201 ; pagedispy = pagedispy
1212 List.rev
(fold [] 0)
1215 let layoutS (columns
, b) y sh =
1216 let sh = sh - state.hscrollh
in
1217 let rec fold accu n =
1218 if n = Array.length
b
1221 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1228 let x = xoff + state.x in
1229 let pagey = max
0 (y - vy) in
1230 let pagedispy = if pagey > 0 then 0 else vy - y in
1231 let pagedispx, pagex =
1246 let vw = conf.winw
- pagedispx - state.scrollw
in
1247 let pw = pagew
- pagex in
1250 let pagevw = min
pagevw (pagew
/columns
) in
1251 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1252 if pagevw > 0 && pagevh > 0
1255 { pageno
= n/columns
1256 ; pagedimno
= pdimno
1263 ; pagedispx = pagedispx
1264 ; pagedispy = pagedispy
1275 List.rev
(fold [] 0)
1279 if nogeomcmds state.geomcmds
1281 match conf.columns
with
1282 | Csingle
-> layout1 y sh
1283 | Cmulti
c -> layoutN c y sh
1284 | Csplit
s -> layoutS s y sh
1289 let y = state.y + incr
in
1291 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1296 let tilex = l
.pagex mod conf.tilew
in
1297 let tiley = l
.pagey mod conf.tileh
in
1299 let col = l
.pagex / conf.tilew
in
1300 let row = l
.pagey / conf.tileh
in
1302 let rec rowloop row y0 dispy
h =
1306 let dh = conf.tileh
- y0 in
1307 let dh = min
h dh in
1308 let rec colloop col x0 dispx w
=
1312 let dw = conf.tilew
- x0 in
1313 let dw = min w
dw in
1315 f col row dispx dispy
x0 y0 dw dh;
1316 colloop (col+1) 0 (dispx+dw) (w
-dw)
1319 colloop col tilex l
.pagedispx l
.pagevw;
1320 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1323 if l
.pagevw > 0 && l
.pagevh > 0
1324 then rowloop row tiley l
.pagedispy l
.pagevh;
1327 let gettileopaque l
col row =
1329 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1331 try Some
(Hashtbl.find
state.tilemap
key)
1332 with Not_found
-> None
1335 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1336 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1337 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1340 let drawtiles l color
=
1342 let f col row x y tilex tiley w
h =
1343 match gettileopaque l
col row with
1344 | Some
(opaque
, _
, t
) ->
1345 let params = x, y, w
, h, tilex, tiley in
1349 GlFunc.blend_func `zero `one_minus_src_color
;
1351 drawtile
params opaque
;
1353 then Gl.disable `blend
;
1356 let s = Printf.sprintf
1360 let w = measurestr
fstate.fontsize
s in
1361 GlMisc.push_attrib
[`current
];
1362 GlDraw.color
(0.0, 0.0, 0.0);
1364 (float (x-2), float (y-2))
1365 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1366 GlDraw.color
(1.0, 1.0, 1.0);
1367 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1368 GlMisc.pop_attrib
();
1373 let lw = conf.winw
- state.scrollw
- x in
1376 let lh = conf.winh
- y in
1379 Gl.enable `texture_2d
;
1380 begin match state.texid
with
1382 GlTex.bind_texture `texture_2d id
;
1385 and x1 = float (x+w)
1386 and y1 = float (y+h) in
1388 let tw = float w /. 64.0
1389 and th
= float h /. 64.0 in
1390 let tx0 = float tilex /. 64.0
1391 and ty0
= float tiley /. 64.0 in
1393 and ty1
= ty0
+. th
in
1394 GlDraw.begins `quads
;
1395 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1396 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1397 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1398 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1401 Gl.disable `texture_2d
;
1403 GlDraw.color
(1.0, 1.0, 1.0);
1406 (float (x+w), float (y+h));
1408 if w > 128 && h > fstate.fontsize
+ 10
1410 GlDraw.color
(0.0, 0.0, 0.0);
1413 then (col*conf.tilew
, row*conf.tileh
)
1416 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1423 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1425 let tilevisible1 l
x y =
1427 and ax1
= l
.pagex + l
.pagevw
1429 and ay1
= l
.pagey + l
.pagevh in
1433 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1434 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1436 let rx0 = max
ax0 bx0
1437 and ry0
= max ay0 by0
1438 and rx1
= min ax1
bx1
1439 and ry1
= min ay1 by1
in
1441 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1442 nonemptyintersection
1445 let tilevisible layout n x y =
1446 let rec findpageinlayout m
= function
1447 | l
:: rest
when l
.pageno
= n ->
1448 tilevisible1 l
x y || (
1449 match conf.columns
with
1450 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1453 | _
:: rest
-> findpageinlayout 0 rest
1456 findpageinlayout 0 layout;
1459 let tileready l
x y =
1460 tilevisible1 l
x y &&
1461 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1464 let tilepage n p
layout =
1465 let rec loop = function
1469 let f col row _ _ _ _ _ _
=
1470 if state.currently
= Idle
1472 match gettileopaque l
col row with
1475 let x = col*conf.tilew
1476 and y = row*conf.tileh
in
1478 let w = l
.pagew
- x in
1482 let h = l
.pageh
- y in
1485 wcmd "tile %s %d %d %d %d" p
x y w h;
1488 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1489 conf.tilew
, conf.tileh
1498 if nogeomcmds state.geomcmds
1502 let preloadlayout visiblepages
=
1503 let presentation = conf.presentation in
1504 let interpagespace = conf.interpagespace in
1505 let maxy = state.maxy in
1506 conf.presentation <- false;
1507 conf.interpagespace <- 0;
1508 state.maxy <- calcheight ();
1510 match visiblepages
with
1512 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1514 let y = if y < conf.winh
then 0 else y - conf.winh
in
1515 let h = state.y - y + conf.winh
*3 in
1516 let pages = layout y h in
1517 conf.presentation <- presentation;
1518 conf.interpagespace <- interpagespace;
1524 let rec loop pages =
1525 if state.currently
!= Idle
1530 begin match getopaque l
.pageno
with
1532 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1533 state.currently
<- Loading
(l
, state.gen
);
1535 tilepage l
.pageno opaque
pages;
1540 if nogeomcmds state.geomcmds
1546 if conf.preload && state.currently
= Idle
1547 then load (preloadlayout pages);
1550 let layoutready layout =
1551 let rec fold all ls
=
1552 all
&& match ls
with
1554 let seen = ref false in
1555 let allvisible = ref true in
1556 let foo col row _ _ _ _ _ _
=
1558 allvisible := !allvisible &&
1559 begin match gettileopaque l
col row with
1565 fold (!seen && !allvisible) rest
1568 let alltilesvisible = fold true layout in
1573 let y = bound y 0 state.maxy in
1574 let y, layout, proceed
=
1575 match conf.maxwait
with
1576 | Some time
when state.ghyll
== noghyll ->
1577 begin match state.throttle
with
1579 let layout = layout y conf.winh
in
1580 let ready = layoutready layout in
1584 state.throttle
<- Some
(layout, y, now ());
1586 else G.postRedisplay "gotoy showall (None)";
1588 | Some
(_
, _
, started
) ->
1589 let dt = now () -. started
in
1592 state.throttle
<- None
;
1593 let layout = layout y conf.winh
in
1595 G.postRedisplay "maxwait";
1602 let layout = layout y conf.winh
in
1603 if true || layoutready layout
1604 then G.postRedisplay "gotoy ready";
1610 state.layout <- layout;
1611 begin match state.mode
with
1612 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1613 let rec loop = function
1615 state.mode
<- LinkNav
(Ltgendir
0)
1616 | l
:: _
when l
.pageno
= pageno
->
1617 begin match getopaque pageno
with
1619 state.mode
<- LinkNav
(Ltgendir
0)
1621 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1622 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1623 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1624 then state.mode
<- LinkNav
(Ltgendir
0)
1626 | _
:: rest
-> loop rest
1631 begin match state.mode
with
1632 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1633 if not
(pagevisible layout pageno
)
1635 match state.layout with
1638 state.mode
<- Birdseye
(
1639 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1642 | LinkNav
(Ltgendir dir
as lt
) ->
1644 let rec loop = function
1647 match getopaque l
.pageno
with
1653 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1655 if dir
> 0 then LDfirst
else LDlast
1661 | Lnotfound
-> loop rest
1663 showlinktype (getlink opaque
n);
1664 Ltexact
(l
.pageno
, n)
1668 state.mode
<- LinkNav
linknav
1673 state.ghyll
<- noghyll;
1676 let mx, my
= state.mpos
in
1681 let conttiling pageno opaque
=
1682 tilepage pageno opaque
1683 (if conf.preload then preloadlayout state.layout else state.layout)
1686 let gotoy_and_clear_text y =
1687 if not
conf.verbose
then state.text <- "";
1692 match state.layout with
1694 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1697 let getanchory (n, top
) =
1698 let y, h = getpageyh n in
1699 y + (truncate
(top
*. float h));
1702 let gotoanchor anchor
=
1703 gotoy (getanchory anchor
);
1707 cbput state.hists
.nav
(getanchor ());
1711 let anchor = cbgetc state.hists
.nav dir
in
1716 let rec scroll f n a
b =
1717 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1719 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1721 then s (float f /. float a
)
1724 then 1.0 -. s ((float (f-b) /. float (n-b)))
1731 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1732 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1734 let ins = float a
*. iv1
1735 and outs
= float (n-b) *. iv1 in
1737 ins +. outs
+. float ones
1739 let rec set (_N
, _A
, _B
) y sy
=
1740 let sum = summa
1.0 _N _A _B
in
1741 let dy = float (y - sy
) in
1745 then state.ghyll
<- noghyll
1748 let s = scroll n _N _A _B
in
1749 let y1 = y1 +. ((s *. dy) /. sum) in
1750 gotoy_and_clear_text (truncate
y1);
1751 state.ghyll
<- gf (n+1) y1;
1755 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1757 gf 0 (float state.y)
1760 match conf.ghyllscroll
with
1762 gotoy_and_clear_text y
1764 if state.ghyll
== noghyll
1765 then set nab
y state.y
1766 else state.ghyll
(Some
y)
1769 let gotopage n top
=
1770 let y, h = getpageyh n in
1771 let y = y + (truncate
(top
*. float h)) in
1775 let gotopage1 n top
=
1776 let y = getpagey n in
1781 let invalidate s f =
1786 match state.geomcmds
with
1787 | ps
, [] when String.length ps
= 0 ->
1789 state.geomcmds
<- s, [];
1792 state.geomcmds
<- ps
, [s, f];
1794 | ps
, (s'
, _
) :: rest
when s'
= s ->
1795 state.geomcmds
<- ps
, ((s, f) :: rest
);
1798 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1801 let opendoc path password
=
1803 state.password
<- password
;
1804 state.gen
<- state.gen
+ 1;
1805 state.docinfo
<- [];
1807 setaalevel
conf.aalevel
;
1808 Wsi.settitle
("llpp " ^
Filename.basename path
);
1809 wcmd "open %s\000%s\000" path password
;
1810 invalidate "reqlayout"
1812 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1816 let c = c *. conf.colorscale
in
1820 let scalecolor2 (r
, g
, b) =
1821 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1825 let docolumns = function
1828 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1829 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1830 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1831 let rec fixrow m
= if m
= pageno
then () else
1832 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1835 let y = y + (rowh
- h) / 2 in
1836 a.(m
) <- (pdimno, x, y, pdim
);
1840 if pageno
= state.pagecount
1841 then fixrow (((pageno
- 1) / columns
) * columns
)
1843 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1845 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1846 pdimno+1, pdim
, rest
1851 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1853 (conf.winw
- state.scrollw
- w) / 2,
1854 y + rowh
+ conf.interpagespace, h
1857 if (pageno
- coverA
) mod columns
= 0
1858 then 0, y + rowh
+ conf.interpagespace, h
1859 else x, y, max rowh
h
1862 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1863 then fixrow (pageno
- columns
);
1864 a.(pageno
) <- (pdimno, x, y, pdim
);
1865 let x = x + w + xoff*2 + conf.interpagespace in
1866 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1868 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1869 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1872 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1873 let rec loop pageno
pdimno pdim
y pdims
=
1874 if pageno
= state.pagecount
1877 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1879 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1880 pdimno+1, pdim
, rest
1885 let rec loop1 n x y =
1886 if n = c then y else (
1887 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1888 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1891 let y = loop1 0 0 y in
1892 loop (pageno
+1) pdimno pdim
y pdims
1894 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1895 conf.columns
<- Csplit
(c, a);
1897 docolumns conf.columns
;
1898 state.maxy <- calcheight ();
1900 if state.w <= conf.winw
- state.scrollw
1904 match state.mode
with
1905 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1906 let y, h = getpageyh pageno
in
1907 let top = (conf.winh
- h) / 2 in
1908 gotoy (max
0 (y - top))
1909 | _
-> gotoanchor state.anchor
1913 GlDraw.viewport
0 0 w h;
1914 let firsttime = state.geomcmds
== firstgeomcmds in
1915 if not
firsttime && nogeomcmds state.geomcmds
1916 then state.anchor <- getanchor ();
1919 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1922 setfontsize fstate.fontsize
;
1923 GlMat.mode `modelview
;
1924 GlMat.load_identity
();
1926 GlMat.mode `projection
;
1927 GlMat.load_identity
();
1928 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1929 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1930 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1935 else float state.x /. float state.w
1937 invalidate "geometry"
1941 then state.x <- truncate
(relx *. float w);
1943 match conf.columns
with
1945 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1946 | Csplit
(c, _
) -> w * c
1948 wcmd "geometry %d %d" w h);
1952 let len = String.length
state.text in
1955 match state.mode
with
1957 | View
-> state.hscrollh
1962 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1963 (x+.w, float (conf.winh
- hscrollh))
1966 let w = float (conf.winw
- state.scrollw
- 1) in
1967 if state.progress
>= 0.0 && state.progress
< 1.0
1969 GlDraw.color
(0.3, 0.3, 0.3);
1970 let w1 = w *. state.progress
in
1972 GlDraw.color
(0.0, 0.0, 0.0);
1976 GlDraw.color
(0.0, 0.0, 0.0);
1980 GlDraw.color
(1.0, 1.0, 1.0);
1981 drawstring fstate.fontsize
1982 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1985 match state.mode
with
1986 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1990 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1992 Printf.sprintf
"%s%s_" prefix
text
2001 if not
(istextentry state.mode
)
2003 let s1 = "(press 'e' to review error messasges)" in
2004 if String.length
s > 0 then s ^
" " ^
s1 else s1
2009 if String.length
s > 0
2014 let len = Queue.length
state.tilelru
in
2016 if state.memused
<= conf.memlimit
2021 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2022 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2023 let (_
, pw, ph
, _
) = getpagedim n in
2026 && colorspace
= conf.colorspace
2027 && angle
= conf.angle
2032 match state.throttle
with
2035 then preloadlayout state.layout
2037 | Some
(layout, _
, _
) ->
2040 let x = col*conf.tilew
2041 and y = row*conf.tileh
in
2042 tilevisible layout n x y
2044 then Queue.push lruitem
state.tilelru
2046 wcmd "freetile %s" p
;
2047 state.memused
<- state.memused
- s;
2048 state.uioh#infochanged Memused
;
2049 Hashtbl.remove
state.tilemap k
;
2058 Queue.iter
(fun (k
, p
, s) ->
2059 wcmd "freetile %s" p
;
2060 state.memused
<- state.memused
- s;
2061 state.uioh#infochanged Memused
;
2062 Hashtbl.remove
state.tilemap k
;
2064 Queue.clear
state.tilelru
;
2068 let logcurrently = function
2069 | Idle
-> dolog "Idle"
2070 | Loading
(l
, gen
) ->
2071 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2072 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2074 "Tiling %d[%d,%d] page=%s cs=%s angle"
2075 l
.pageno
col row pageopaque
2076 (colorspace_to_string colorspace
)
2078 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2079 angle gen
conf.angle
state.gen
2081 conf.tilew
conf.tileh
2088 (* dolog "%S" cmds; *)
2091 try String.index cmds ' '
2092 with Not_found
-> -1
2097 let l = String.length cmds
in
2098 let op = String.sub cmds
0 spacepos in
2100 if l - spacepos < 2 then ""
2101 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2106 state.uioh#infochanged Pdim
;
2110 state.rects
<- state.rects1
;
2111 G.postRedisplay "clearrects";
2115 try Scanf.sscanf
args "%u" (fun n -> n)
2117 dolog "error processing 'continue' %S: %s"
2118 cmds
(Printexc.to_string exn
);
2121 state.pagecount
<- n;
2122 begin match state.currently
with
2124 state.currently
<- Idle
;
2125 state.outlines
<- Array.of_list
(List.rev
l)
2129 let cur, cmds
= state.geomcmds
in
2130 if String.length
cur = 0
2131 then failwith
"umpossible";
2133 begin match List.rev cmds
with
2135 state.geomcmds
<- "", [];
2139 state.geomcmds
<- s, List.rev rest
;
2141 if conf.maxwait
= None
2142 then G.postRedisplay "continue";
2152 then showtext ' '
args
2155 let progress, text =
2157 Scanf.sscanf
args "%f %n"
2159 f, String.sub
args pos
(String.length
args - pos
))
2161 dolog "error processing 'progress' %S: %s"
2162 cmds
(Printexc.to_string exn
);
2166 state.progress <- progress;
2167 G.postRedisplay "progress"
2170 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2172 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2173 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2174 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2176 dolog "error processing 'firstmatch' %S: %s"
2177 cmds
(Printexc.to_string exn
);
2180 let y = (getpagey pageno) + truncate
y0 in
2183 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2186 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2188 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2189 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2190 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2192 dolog "error processing 'match' %S: %s"
2193 cmds
(Printexc.to_string exn
);
2197 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2202 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2204 dolog "error processing 'page' %S: %s"
2205 cmds
(Printexc.to_string exn
);
2208 begin match state.currently
with
2209 | Loading
(l, gen
) ->
2210 vlog "page %d took %f sec" l.pageno t
;
2211 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2212 begin match state.throttle
with
2214 let preloadedpages =
2216 then preloadlayout state.layout
2221 Set.Make
(struct type t
= int let compare = (-) end) in
2223 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2224 IntSet.empty
preloadedpages
2227 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2228 if not
(IntSet.mem
pageno set)
2230 wcmd "freepage %s" opaque
;
2236 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2239 state.currently
<- Idle
;
2242 tilepage l.pageno pageopaque state.layout;
2244 load preloadedpages;
2245 if pagevisible state.layout l.pageno
2246 && layoutready state.layout
2247 then G.postRedisplay "page";
2250 | Some
(layout, _
, _
) ->
2251 state.currently
<- Idle
;
2252 tilepage l.pageno pageopaque layout;
2257 dolog "Inconsistent loading state";
2258 logcurrently state.currently
;
2263 let (x, y, opaque
, size
, t
) =
2265 Scanf.sscanf
args "%u %u %s %u %f"
2266 (fun x y p size t
-> (x, y, p
, size
, t
))
2268 dolog "error processing 'tile' %S: %s"
2269 cmds
(Printexc.to_string exn
);
2272 begin match state.currently
with
2273 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2274 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2276 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2278 wcmd "freetile %s" opaque
;
2279 state.currently
<- Idle
;
2283 puttileopaque l col row gen cs angle opaque size t
;
2284 state.memused
<- state.memused
+ size
;
2285 state.uioh#infochanged Memused
;
2287 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2288 opaque
, size
) state.tilelru
;
2291 match state.throttle
with
2292 | None
-> state.layout
2293 | Some
(layout, _
, _
) -> layout
2296 state.currently
<- Idle
;
2298 && conf.colorspace
= cs
2299 && conf.angle
= angle
2300 && tilevisible layout l.pageno x y
2301 then conttiling l.pageno pageopaque;
2303 begin match state.throttle
with
2305 preload state.layout;
2307 && conf.colorspace
= cs
2308 && conf.angle
= angle
2309 && tilevisible state.layout l.pageno x y
2310 then G.postRedisplay "tile nothrottle";
2312 | Some
(layout, y, _
) ->
2313 let ready = layoutready layout in
2317 state.layout <- layout;
2318 state.throttle
<- None
;
2319 G.postRedisplay "throttle";
2326 dolog "Inconsistent tiling state";
2327 logcurrently state.currently
;
2334 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2336 dolog "error processing 'pdim' %S: %s"
2337 cmds
(Printexc.to_string exn
);
2340 state.uioh#infochanged Pdim
;
2341 state.pdims
<- pdim :: state.pdims
2344 let (l, n, t
, h, pos
) =
2346 Scanf.sscanf
args "%u %u %d %u %n"
2347 (fun l n t
h pos
-> l, n, t
, h, pos
)
2349 dolog "error processing 'o' %S: %s"
2350 cmds
(Printexc.to_string exn
);
2353 let s = String.sub
args pos
(String.length
args - pos
) in
2354 let outline = (s, l, (n, float t
/. float h)) in
2355 begin match state.currently
with
2356 | Outlining outlines
->
2357 state.currently
<- Outlining
(outline :: outlines
)
2359 state.currently
<- Outlining
[outline]
2361 dolog "invalid outlining state";
2362 logcurrently currently
2366 state.docinfo
<- (1, args) :: state.docinfo
2369 state.uioh#infochanged Docinfo
;
2370 state.docinfo
<- List.rev
state.docinfo
2373 dolog "unknown cmd `%S'" cmds
2378 let action = function
2379 | HCprev
-> cbget cb ~
-1
2380 | HCnext
-> cbget cb
1
2381 | HCfirst
-> cbget cb ~
-(cb
.rc)
2382 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2383 and cancel
() = cb
.rc <- rc
2387 let search pattern forward
=
2388 if String.length pattern
> 0
2391 match state.layout with
2394 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2396 wcmd "search %d %d %d %d,%s\000"
2397 (btod conf.icase
) pn py (btod forward
) pattern
;
2400 let intentry text key =
2402 if key >= 32 && key < 127
2408 let text = addchar text c in
2412 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2416 let textentry text key =
2417 if key land 0xff00 = 0xff00
2419 else TEcont
(text ^
Wsi.toutf8
key)
2422 let reqlayout angle proportional
=
2423 match state.throttle
with
2425 if nogeomcmds state.geomcmds
2426 then state.anchor <- getanchor ();
2427 conf.angle
<- angle
mod 360;
2430 match state.mode
with
2431 | LinkNav _
-> state.mode
<- View
2434 conf.proportional
<- proportional
;
2435 invalidate "reqlayout"
2436 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2440 let settrim trimmargins trimfuzz
=
2441 if nogeomcmds state.geomcmds
2442 then state.anchor <- getanchor ();
2443 conf.trimmargins
<- trimmargins
;
2444 conf.trimfuzz
<- trimfuzz
;
2445 let x0, y0, x1, y1 = trimfuzz
in
2446 invalidate "settrim"
2448 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2449 Hashtbl.iter
(fun _ opaque
->
2450 wcmd "freepage %s" opaque
;
2452 Hashtbl.clear
state.pagemap
;
2456 match state.throttle
with
2458 let zoom = max
0.01 zoom in
2459 if zoom <> conf.zoom
2461 state.prevzoom
<- conf.zoom;
2463 reshape conf.winw
conf.winh
;
2464 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2467 | Some
(layout, y, started
) ->
2469 match conf.maxwait
with
2473 let dt = now () -. started
in
2481 let setcolumns mode columns coverA coverB
=
2485 then showtext '
!'
"split mode doesn't work in bird's eye"
2487 conf.columns
<- Csplit
(-columns
, [||]);
2495 conf.columns
<- Csingle
;
2500 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2504 reshape conf.winw
conf.winh
;
2507 let enterbirdseye () =
2508 let zoom = float conf.thumbw
/. float conf.winw
in
2509 let birdseyepageno =
2510 let cy = conf.winh
/ 2 in
2514 let rec fold best
= function
2517 let d = cy - (l.pagedispy + l.pagevh/2)
2518 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2519 if abs
d < abs dbest
2526 state.mode
<- Birdseye
(
2527 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2530 conf.presentation <- false;
2531 conf.interpagespace <- 10;
2532 conf.hlinks
<- false;
2534 state.mstate
<- Mnone
;
2535 conf.maxwait
<- None
;
2537 match conf.beyecolumns
with
2540 Cmulti
((c, 0, 0), [||])
2543 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2546 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2551 reshape conf.winw
conf.winh
;
2554 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2556 conf.zoom <- c.zoom;
2557 conf.presentation <- c.presentation;
2558 conf.interpagespace <- c.interpagespace;
2559 conf.maxwait
<- c.maxwait
;
2560 conf.hlinks
<- c.hlinks
;
2561 conf.beyecolumns
<- (
2562 match conf.columns
with
2563 | Cmulti
((c, _
, _
), _
) -> Some
c
2565 | Csplit _
-> assert false
2568 match c.columns
with
2569 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2570 | Csingle
-> Csingle
2571 | Csplit _
-> failwith
"leaving bird's eye split mode"
2576 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2579 reshape conf.winw
conf.winh
;
2580 state.anchor <- if goback
then anchor else (pageno, 0.0);
2583 let togglebirdseye () =
2584 match state.mode
with
2585 | Birdseye vals
-> leavebirdseye vals
true
2586 | View
-> enterbirdseye ()
2590 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2591 let pageno = max
0 (pageno - incr
) in
2592 let rec loop = function
2593 | [] -> gotopage1 pageno 0
2594 | l :: _
when l.pageno = pageno ->
2595 if l.pagedispy >= 0 && l.pagey = 0
2596 then G.postRedisplay "upbirdseye"
2597 else gotopage1 pageno 0
2598 | _
:: rest
-> loop rest
2601 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2604 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2605 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2606 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2607 let rec loop = function
2609 let y, h = getpageyh pageno in
2610 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2612 | l :: _
when l.pageno = pageno ->
2613 if l.pagevh != l.pageh
2614 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2615 else G.postRedisplay "downbirdseye"
2616 | _
:: rest
-> loop rest
2621 let optentry mode _
key =
2622 let btos b = if b then "on" else "off" in
2623 if key >= 32 && key < 127
2625 let c = Char.chr
key in
2629 try conf.scrollstep
<- int_of_string
s with exc
->
2630 state.text <- Printf.sprintf
"bad integer `%s': %s"
2631 s (Printexc.to_string exc
)
2633 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2638 conf.autoscrollstep
<- int_of_string
s;
2639 if state.autoscroll
<> None
2640 then state.autoscroll
<- Some
conf.autoscrollstep
2642 state.text <- Printf.sprintf
"bad integer `%s': %s"
2643 s (Printexc.to_string exc
)
2645 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2648 let mode = state.mode in
2651 let n, a, b = multicolumns_of_string s in
2652 setcolumns mode n a b;
2654 state.text <- Printf.sprintf
"bad columns `%s': %s"
2655 s (Printexc.to_string exc
)
2657 TEswitch
("columns: ", "", None
, textentry, ondone)
2662 let zoom = float (int_of_string
s) /. 100.0 in
2665 state.text <- Printf.sprintf
"bad integer `%s': %s"
2666 s (Printexc.to_string exc
)
2668 TEswitch
("zoom: ", "", None
, intentry, ondone)
2673 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2675 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2676 begin match mode with
2678 leavebirdseye beye
false;
2683 state.text <- Printf.sprintf
"bad integer `%s': %s"
2684 s (Printexc.to_string exc
)
2686 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2691 Some
(int_of_string
s)
2693 state.text <- Printf.sprintf
"bad integer `%s': %s"
2694 s (Printexc.to_string exc
);
2697 | Some angle
-> reqlayout angle
conf.proportional
2700 TEswitch
("rotation: ", "", None
, intentry, ondone)
2703 conf.icase
<- not
conf.icase
;
2704 TEdone
("case insensitive search " ^
(btos conf.icase
))
2707 conf.preload <- not
conf.preload;
2709 TEdone
("preload " ^
(btos conf.preload))
2712 conf.verbose
<- not
conf.verbose
;
2713 TEdone
("verbose " ^
(btos conf.verbose
))
2716 conf.debug
<- not
conf.debug
;
2717 TEdone
("debug " ^
(btos conf.debug
))
2720 conf.maxhfit
<- not
conf.maxhfit
;
2722 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2723 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2726 conf.crophack
<- not
conf.crophack
;
2727 TEdone
("crophack " ^
btos conf.crophack
)
2731 match conf.maxwait
with
2733 conf.maxwait
<- Some infinity
;
2734 "always wait for page to complete"
2736 conf.maxwait
<- None
;
2737 "show placeholder if page is not ready"
2742 conf.underinfo
<- not
conf.underinfo
;
2743 TEdone
("underinfo " ^
btos conf.underinfo
)
2746 conf.savebmarks
<- not
conf.savebmarks
;
2747 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2753 match state.layout with
2758 conf.interpagespace <- int_of_string
s;
2759 state.maxy <- calcheight ();
2760 let y = getpagey pageno in
2763 state.text <- Printf.sprintf
"bad integer `%s': %s"
2764 s (Printexc.to_string exc
)
2766 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2769 reqlayout conf.angle
(not
conf.proportional
);
2770 TEdone
("proportional display " ^
btos conf.proportional
)
2773 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2774 TEdone
("trim margins " ^
btos conf.trimmargins
)
2777 conf.invert
<- not
conf.invert
;
2778 TEdone
("invert colors " ^
btos conf.invert
)
2782 cbput state.hists
.sel
s;
2785 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2789 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2795 class type lvsource
= object
2796 method getitemcount
: int
2797 method getitem
: int -> (string * int)
2798 method hasaction
: int -> bool
2807 method getactive
: int
2808 method getfirst
: int
2809 method getqsearch
: string
2810 method setqsearch
: string -> unit
2814 class virtual lvsourcebase
= object
2815 val mutable m_active
= 0
2816 val mutable m_first
= 0
2817 val mutable m_qsearch
= ""
2818 val mutable m_pan
= 0
2819 method getactive
= m_active
2820 method getfirst
= m_first
2821 method getqsearch
= m_qsearch
2822 method getpan
= m_pan
2823 method setqsearch
s = m_qsearch
<- s
2826 let withoutlastutf8 s =
2827 let len = String.length
s in
2835 let b = Char.code
s.[pos
] in
2836 if b land 0b110000 = 0b11000000
2841 if Char.code
s.[len-1] land 0x80 = 0
2845 String.sub
s 0 first;
2848 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2850 state.mode <- Textentry
(te
, onleave
);
2853 G.postRedisplay "textentrykeyboard enttext";
2855 let histaction cmd
=
2858 | Some
(action, _
) ->
2859 state.mode <- Textentry
(
2860 (c, action cmd
, opthist
, onkey
, ondone), onleave
2862 G.postRedisplay "textentry histaction"
2865 | 0xff08 -> (* backspace *)
2866 let s = withoutlastutf8 text in
2867 let len = String.length
s in
2871 G.postRedisplay "textentrykeyboard after cancel";
2874 enttext (c, s, opthist
, onkey
, ondone)
2880 G.postRedisplay "textentrykeyboard after confirm"
2882 | 0xff52 -> histaction HCprev
2883 | 0xff54 -> histaction HCnext
2884 | 0xff50 -> histaction HCfirst
2885 | 0xff57 -> histaction HClast
2887 | 0xff1b -> (* escape*)
2888 if String.length
text = 0
2890 begin match opthist
with
2892 | Some
(_
, onhistcancel
) -> onhistcancel
()
2896 G.postRedisplay "textentrykeyboard after cancel2"
2899 enttext (c, "", opthist
, onkey
, ondone)
2902 | 0xff9f | 0xffff -> () (* delete *)
2904 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2905 begin match onkey
text key with
2909 G.postRedisplay "textentrykeyboard after confirm2";
2912 enttext (c, text, opthist
, onkey
, ondone);
2916 G.postRedisplay "textentrykeyboard after cancel3"
2919 state.mode <- Textentry
(te
, onleave
);
2920 G.postRedisplay "textentrykeyboard switch";
2924 vlog "unhandled key %s" (Wsi.keyname
key)
2927 let firstof first active
=
2928 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2929 then max
0 (active
- (fstate.maxrows
/2))
2933 let calcfirst first active
=
2936 let rows = active
- first in
2937 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2941 let scrollph y maxy =
2942 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2943 let sh = float conf.winh
/. sh in
2944 let sh = max
sh (float conf.scrollh
) in
2949 else float y /. float maxy
2951 let position = (float conf.winh
-. sh) *. percent in
2954 if position +. sh > float conf.winh
2955 then float conf.winh
-. sh
2961 let coe s = (s :> uioh
);;
2963 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2965 val m_pan
= source#getpan
2966 val m_first
= source#getfirst
2967 val m_active
= source#getactive
2968 val m_qsearch
= source#getqsearch
2969 val m_prev_uioh
= state.uioh
2971 method private elemunder
y =
2972 let n = y / (fstate.fontsize
+1) in
2973 if m_first
+ n < source#getitemcount
2975 if source#hasaction
(m_first
+ n)
2976 then Some
(m_first
+ n)
2983 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2984 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2985 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2986 GlDraw.color
(1., 1., 1.);
2987 Gl.enable `texture_2d
;
2988 let fs = fstate.fontsize
in
2990 let ww = fstate.wwidth
in
2991 let tabw = 30.0*.ww in
2992 let itemcount = source#getitemcount
in
2994 if (row - m_first
) * nfs > conf.winh
2997 if row >= 0 && row < itemcount
2999 let (s, level
) = source#getitem
row in
3000 let y = (row - m_first
) * nfs in
3001 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3004 Gl.disable `texture_2d
;
3005 GlDraw.polygon_mode `both `line
;
3006 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3007 GlDraw.rect (1., float (y + 1))
3008 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3009 GlDraw.polygon_mode `both `fill
;
3010 GlDraw.color
(1., 1., 1.);
3011 Gl.enable `texture_2d
;
3014 let drawtabularstring s =
3015 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3018 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3021 let len = String.length
s - tabpos - 1 in
3022 let s1 = String.sub
s 0 tabpos
3023 and s2
= String.sub
s (tabpos + 1) len in
3024 let nx = drawstr x s1 in
3026 let x = x +. (max
tabw sw) in
3033 let _ = drawtabularstring s in
3040 Gl.disable `texture_2d
;
3042 method updownlevel incr
=
3043 let len = source#getitemcount
in
3045 if m_active
>= 0 && m_active
< len
3046 then snd
(source#getitem m_active
)
3050 if i
= len then i
-1 else if i
= -1 then 0 else
3051 let _, l = source#getitem i
in
3052 if l != curlevel then i
else flow (i
+incr
)
3054 let active = flow m_active
in
3055 let first = calcfirst m_first
active in
3056 G.postRedisplay "outline updownlevel";
3057 {< m_active
= active; m_first
= first >}
3059 method private key1
key mask
=
3060 let set1 active first qsearch
=
3061 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3063 let search active pattern incr
=
3066 if n >= 0 && n < source#getitemcount
3068 let s, _ = source#getitem
n in
3070 (try ignore
(Str.search_forward
re s 0); true
3071 with Not_found
-> false)
3073 else loop (n + incr
)
3080 let re = Str.regexp_case_fold pattern
in
3086 let itemcount = source#getitemcount
in
3087 let find start incr
=
3089 if i
= -1 || i
= itemcount
3092 if source#hasaction i
3094 else find (i
+ incr
)
3099 let set active first =
3100 let first = bound first 0 (itemcount - fstate.maxrows
) in
3102 coe {< m_active
= active; m_first
= first >}
3105 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3107 let incr1 = if incr
> 0 then 1 else -1 in
3108 if isvisible m_first m_active
3111 let next = m_active
+ incr
in
3113 if next < 0 || next >= itemcount
3115 else find next incr1
3117 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3123 let first = m_first
+ incr
in
3124 let first = bound first 0 (itemcount - 1) in
3126 let next = m_active
+ incr
in
3127 let next = bound next 0 (itemcount - 1) in
3130 let active = if next = -1 then m_active
else next in
3133 let first = min
next m_first
in
3135 if abs
(next - first) > fstate.maxrows
3141 let first = m_first
+ incr
in
3142 let first = bound first 0 (itemcount - 1) in
3144 let next = m_active
+ incr
in
3145 let next = bound next 0 (itemcount - 1) in
3146 let next = find next incr1 in
3148 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3150 let active = if m_active
= -1 then next else m_active
in
3155 if isvisible first active
3161 G.postRedisplay "listview navigate";
3165 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3166 let incr = if key = 0x72 then -1 else 1 in
3168 match search (m_active
+ incr) m_qsearch
incr with
3170 state.text <- m_qsearch ^
" [not found]";
3173 state.text <- m_qsearch
;
3174 active, firstof m_first
active
3176 G.postRedisplay "listview ctrl-r/s";
3177 set1 active first m_qsearch
;
3179 | 0xff08 -> (* backspace *)
3180 if String.length m_qsearch
= 0
3183 let qsearch = withoutlastutf8 m_qsearch
in
3184 let len = String.length
qsearch in
3188 G.postRedisplay "listview empty qsearch";
3189 set1 m_active m_first
"";
3193 match search m_active
qsearch ~
-1 with
3195 state.text <- qsearch ^
" [not found]";
3198 state.text <- qsearch;
3199 active, firstof m_first
active
3201 G.postRedisplay "listview backspace qsearch";
3202 set1 active first qsearch
3205 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3206 let pattern = m_qsearch ^
Wsi.toutf8
key in
3208 match search m_active
pattern 1 with
3210 state.text <- pattern ^
" [not found]";
3213 state.text <- pattern;
3214 active, firstof m_first
active
3216 G.postRedisplay "listview qsearch add";
3217 set1 active first pattern;
3219 | 0xff1b -> (* escape *)
3221 if String.length m_qsearch
= 0
3223 G.postRedisplay "list view escape";
3226 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3228 | None
-> m_prev_uioh
3233 G.postRedisplay "list view kill qsearch";
3234 source#setqsearch
"";
3235 coe {< m_qsearch
= "" >}
3238 | 0xff0d -> (* return *)
3240 let self = {< m_qsearch
= "" >} in
3241 source#setqsearch
"";
3243 G.postRedisplay "listview enter";
3244 if m_active
>= 0 && m_active
< source#getitemcount
3246 source#exit
(coe self) false m_active m_first m_pan
"";
3249 source#exit
(coe self) true m_active m_first m_pan
"";
3252 begin match opt with
3253 | None
-> m_prev_uioh
3257 | 0xff9f | 0xffff -> (* delete *)
3260 | 0xff52 -> navigate ~
-1 (* up *)
3261 | 0xff54 -> navigate 1 (* down *)
3262 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3263 | 0xff56 -> navigate fstate.maxrows
(* next *)
3265 | 0xff53 -> (* right *)
3267 G.postRedisplay "listview right";
3268 coe {< m_pan
= m_pan
- 1 >}
3270 | 0xff51 -> (* left *)
3272 G.postRedisplay "listview left";
3273 coe {< m_pan
= m_pan
+ 1 >}
3275 | 0xff50 -> (* home *)
3276 let active = find 0 1 in
3277 G.postRedisplay "listview home";
3280 | 0xff57 -> (* end *)
3281 let first = max
0 (itemcount - fstate.maxrows
) in
3282 let active = find (itemcount - 1) ~
-1 in
3283 G.postRedisplay "listview end";
3286 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3290 dolog "listview unknown key %#x" key; coe self
3292 method key key mask
=
3293 match state.mode with
3294 | Textentry te
-> textentrykeyboard key mask te
; coe self
3295 | _ -> self#key1
key mask
3297 method button button down
x y _ =
3300 | 1 when x > conf.winw
- conf.scrollbw
->
3301 G.postRedisplay "listview scroll";
3304 let _, position, sh = self#
scrollph in
3305 if y > truncate
position && y < truncate
(position +. sh)
3307 state.mstate
<- Mscrolly
;
3311 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3312 let first = truncate
(s *. float source#getitemcount
) in
3313 let first = min source#getitemcount
first in
3314 Some
(coe {< m_first
= first; m_active
= first >})
3316 state.mstate
<- Mnone
;
3319 | 1 when not down
->
3320 begin match self#elemunder
y with
3322 G.postRedisplay "listview click";
3324 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3328 | n when (n == 4 || n == 5) && not down
->
3329 let len = source#getitemcount
in
3331 if n = 5 && m_first
+ fstate.maxrows
>= len
3335 let first = m_first
+ (if n == 4 then -1 else 1) in
3336 bound first 0 (len - 1)
3338 G.postRedisplay "listview wheel";
3339 Some
(coe {< m_first
= first >})
3344 | None
-> m_prev_uioh
3348 match state.mstate
with
3350 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3351 let first = truncate
(s *. float source#getitemcount
) in
3352 let first = min source#getitemcount
first in
3353 G.postRedisplay "listview motion";
3354 coe {< m_first
= first; m_active
= first >}
3357 method pmotion
x y =
3358 if x < conf.winw
- conf.scrollbw
3361 match self#elemunder
y with
3362 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3363 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3367 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3372 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3376 method infochanged
_ = ()
3378 method scrollpw
= (0, 0.0, 0.0)
3380 let nfs = fstate.fontsize
+ 1 in
3381 let y = m_first
* nfs in
3382 let itemcount = source#getitemcount
in
3383 let maxi = max
0 (itemcount - fstate.maxrows
) in
3384 let maxy = maxi * nfs in
3385 let p, h = scrollph y maxy in
3388 method modehash
= modehash
3391 class outlinelistview ~source
=
3394 ~source
:(source
:> lvsource
)
3396 ~modehash
:(findkeyhash conf "outline")
3399 method key key mask
=
3400 let calcfirst first active =
3403 let rows = active - first in
3404 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3408 let active = m_active
+ incr in
3409 let active = bound active 0 (source#getitemcount
- 1) in
3410 let first = calcfirst m_first
active in
3411 G.postRedisplay "outline navigate";
3412 coe {< m_active
= active; m_first
= first >}
3414 let ctrl = Wsi.withctrl mask
in
3416 | 110 when ctrl -> (* ctrl-n *)
3417 source#narrow m_qsearch
;
3418 G.postRedisplay "outline ctrl-n";
3419 coe {< m_first
= 0; m_active
= 0 >}
3421 | 117 when ctrl -> (* ctrl-u *)
3423 G.postRedisplay "outline ctrl-u";
3425 coe {< m_first
= 0; m_active
= 0 >}
3427 | 108 when ctrl -> (* ctrl-l *)
3428 let first = m_active
- (fstate.maxrows
/ 2) in
3429 G.postRedisplay "outline ctrl-l";
3430 coe {< m_first
= first >}
3432 | 0xff9f | 0xffff -> (* delete *)
3433 source#remove m_active
;
3434 G.postRedisplay "outline delete";
3435 let active = max
0 (m_active
-1) in
3436 coe {< m_first
= firstof m_first
active;
3437 m_active
= active >}
3439 | 0xff52 -> navigate ~
-1 (* up *)
3440 | 0xff54 -> navigate 1 (* down *)
3441 | 0xff55 -> (* prior *)
3442 navigate ~
-(fstate.maxrows
)
3443 | 0xff56 -> (* next *)
3444 navigate fstate.maxrows
3446 | 0xff53 -> (* [ctrl-]right *)
3450 G.postRedisplay "outline ctrl right";
3451 {< m_pan
= m_pan
+ 1 >}
3453 else self#updownlevel
1
3457 | 0xff51 -> (* [ctrl-]left *)
3461 G.postRedisplay "outline ctrl left";
3462 {< m_pan
= m_pan
- 1 >}
3464 else self#updownlevel ~
-1
3468 | 0xff50 -> (* home *)
3469 G.postRedisplay "outline home";
3470 coe {< m_first
= 0; m_active
= 0 >}
3472 | 0xff57 -> (* end *)
3473 let active = source#getitemcount
- 1 in
3474 let first = max
0 (active - fstate.maxrows
) in
3475 G.postRedisplay "outline end";
3476 coe {< m_active
= active; m_first
= first >}
3478 | _ -> super#
key key mask
3481 let outlinesource usebookmarks
=
3484 inherit lvsourcebase
3485 val mutable m_items
= empty
3486 val mutable m_orig_items
= empty
3487 val mutable m_prev_items
= empty
3488 val mutable m_narrow_pattern
= ""
3489 val mutable m_hadremovals
= false
3491 method getitemcount
=
3492 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3495 if n == Array.length m_items
&& m_hadremovals
3497 ("[Confirm removal]", 0)
3499 let s, n, _ = m_items
.(n) in
3502 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3503 ignore
(uioh
, first, qsearch);
3504 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3506 if String.length m_narrow_pattern
= 0
3512 if not
confrimremoval
3514 let _, _, anchor = m_items
.(active) in
3519 state.bookmarks
<- Array.to_list m_items
;
3520 m_orig_items
<- m_items
;
3523 else m_items
<- items;
3527 method hasaction
_ = true
3530 if Array.length m_items
!= Array.length m_orig_items
3531 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3534 method narrow
pattern =
3535 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3539 let rec loop accu n =
3542 m_narrow_pattern
<- pattern;
3543 m_items
<- Array.of_list
accu
3546 let (s, _, _) as o = m_items
.(n) in
3548 if (try ignore
(Str.search_forward
re s 0); true
3549 with Not_found
-> false)
3555 loop [] (Array.length m_items
- 1)
3560 then Array.of_list
state.bookmarks
3563 m_items
<- m_orig_items
3568 if m
>= 0 && m
< Array.length m_items
3570 m_hadremovals
<- true;
3571 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3572 let n = if n >= m
then n+1 else n in
3577 method reset
anchor items =
3578 m_hadremovals
<- false;
3579 if m_orig_items
== empty || m_prev_items
!= items
3581 m_orig_items
<- items;
3582 if String.length m_narrow_pattern
= 0
3583 then m_items
<- items;
3585 m_prev_items
<- items;
3586 let rely = getanchory anchor in
3588 let rec loop n best bestd
=
3589 if n = Array.length m_items
3592 let (_, _, anchor) = m_items
.(n) in
3593 let orely = getanchory anchor in
3594 let d = abs
(orely - rely) in
3597 else loop (n+1) best bestd
3602 m_first
<- firstof m_first
active
3606 let enterselector usebookmarks
=
3607 let source = outlinesource usebookmarks
in
3611 then Array.of_list
state.bookmarks
3614 if Array.length
outlines = 0
3616 showtext ' ' errmsg
;
3619 state.text <- source#greetmsg
;
3620 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3621 let anchor = getanchor () in
3622 source#reset
anchor outlines;
3623 state.uioh
<- coe (new outlinelistview ~
source);
3624 G.postRedisplay "enter selector";
3628 let enteroutlinemode =
3629 let f = enterselector false in
3630 fun ()-> f "Document has no outline";
3633 let enterbookmarkmode =
3634 let f = enterselector true in
3635 fun () -> f "Document has no bookmarks (yet)";
3638 let color_of_string s =
3639 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3640 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3644 let color_to_string (r
, g
, b) =
3645 let r = truncate
(r *. 256.0)
3646 and g
= truncate
(g
*. 256.0)
3647 and b = truncate
(b *. 256.0) in
3648 Printf.sprintf
"%d/%d/%d" r g
b
3651 let irect_of_string s =
3652 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3655 let irect_to_string (x0,y0,x1,y1) =
3656 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3659 let makecheckers () =
3660 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3662 converted by Issac Trotts. July 25, 2002 *)
3663 let image_height = 64
3664 and image_width
= 64 in
3668 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3670 for i
= 0 to image_width
- 1 do
3671 for j
= 0 to image_height - 1 do
3672 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3673 (if (i
land 8 ) lxor (j
land 8) = 0
3674 then [|255;255;255|] else [|200;200;200|])
3679 let image = make_image () in
3680 let id = GlTex.gen_texture
() in
3681 GlTex.bind_texture `texture_2d
id;
3682 GlPix.store
(`unpack_alignment
1);
3683 GlTex.image2d
image;
3684 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3687 `mag_filter `nearest
;
3688 `min_filter `nearest
];
3692 let setcheckers enabled
=
3693 match state.texid
with
3695 if enabled
then state.texid
<- Some
(makecheckers ())
3700 GlTex.delete_texture texid
;
3701 state.texid
<- None
;
3705 let int_of_string_with_suffix s =
3706 let l = String.length
s in
3710 let suffix = Char.lowercase
s.[l-1] in
3712 | 'k'
-> String.sub
s 0 (l-1), 10
3713 | 'm'
-> String.sub
s 0 (l-1), 20
3714 | 'g'
-> String.sub
s 0 (l-1), 30
3718 let n = int_of_string
s1 in
3719 let m = n lsl shift
in
3721 then raise
(Failure
"value too large")
3725 let string_with_suffix_of_int n =
3733 if n land ((1 lsl 20) - 1) = 0
3736 if n land ((1 lsl 10) - 1) = 0
3743 let h = n mod 1000 in
3746 then string_of_int
h ^
s
3748 let s = Printf.sprintf
"_%03d%s" h s in
3755 let defghyllscroll = (40, 8, 32);;
3756 let ghyllscroll_of_string s =
3757 let (n, a, b) as nab
=
3760 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3762 if n <= a || n <= b || a >= b
3763 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3767 let ghyllscroll_to_string ((n, a, b) as nab
) =
3768 if nab
= defghyllscroll
3770 else Printf.sprintf
"%d,%d,%d" n a b;
3773 let describe_location () =
3775 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3777 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3778 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3782 else (100. *. (float state.y /. float maxy))
3786 Printf.sprintf
"page %d of %d [%.2f%%]"
3787 (fn+1) state.pagecount
percent
3790 "pages %d-%d of %d [%.2f%%]"
3791 (fn+1) (ln
+1) state.pagecount
percent
3795 let btos b = if b then "\xe2\x88\x9a" else "" in
3796 let showextended = ref false in
3797 let leave mode = function
3798 | Confirm
-> state.mode <- mode
3799 | Cancel
-> state.mode <- mode in
3802 val mutable m_first_time
= true
3803 val mutable m_l
= []
3804 val mutable m_a
= [||]
3805 val mutable m_prev_uioh
= nouioh
3806 val mutable m_prev_mode
= View
3808 inherit lvsourcebase
3810 method reset prev_mode prev_uioh
=
3811 m_a
<- Array.of_list
(List.rev m_l
);
3813 m_prev_mode
<- prev_mode
;
3814 m_prev_uioh
<- prev_uioh
;
3818 if n >= Array.length m_a
3822 | _, _, _, Action
_ -> m_active
<- n
3826 m_first_time
<- false;
3829 method int name get
set =
3831 (name
, `
int get
, 1, Action
(
3834 try set (int_of_string
s)
3836 state.text <- Printf.sprintf
"bad integer `%s': %s"
3837 s (Printexc.to_string exn
)
3840 let te = name ^
": ", "", None
, intentry, ondone in
3841 state.mode <- Textentry
(te, leave m_prev_mode
);
3845 method int_with_suffix name get
set =
3847 (name
, `intws get
, 1, Action
(
3850 try set (int_of_string_with_suffix s)
3852 state.text <- Printf.sprintf
"bad integer `%s': %s"
3853 s (Printexc.to_string exn
)
3857 name ^
": ", "", None
, intentry_with_suffix, ondone
3859 state.mode <- Textentry
(te, leave m_prev_mode
);
3863 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3865 (name
, `
bool (btos, get
), offset
, Action
(
3872 method color name get
set =
3874 (name
, `color get
, 1, Action
(
3876 let invalid = (nan
, nan
, nan
) in
3879 try color_of_string s
3881 state.text <- Printf.sprintf
"bad color `%s': %s"
3882 s (Printexc.to_string exn
);
3888 let te = name ^
": ", "", None
, textentry, ondone in
3889 state.text <- color_to_string (get
());
3890 state.mode <- Textentry
(te, leave m_prev_mode
);
3894 method string name get
set =
3896 (name
, `
string get
, 1, Action
(
3898 let ondone s = set s in
3899 let te = name ^
": ", "", None
, textentry, ondone in
3900 state.mode <- Textentry
(te, leave m_prev_mode
);
3904 method colorspace name get
set =
3906 (name
, `
string get
, 1, Action
(
3909 let vals = [| "rgb"; "bgr"; "gray" |] in
3911 inherit lvsourcebase
3914 m_active
<- int_of_colorspace conf.colorspace
;
3917 method getitemcount
= Array.length
vals
3918 method getitem
n = (vals.(n), 0)
3919 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3920 ignore
(uioh
, first, pan
, qsearch);
3921 if not cancel
then set active;
3923 method hasaction
_ = true
3927 let modehash = findkeyhash conf "info" in
3928 coe (new listview ~
source ~trusted
:true ~
modehash)
3931 method caption
s offset
=
3932 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3934 method caption2
s f offset
=
3935 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3937 method getitemcount
= Array.length m_a
3940 let tostr = function
3941 | `
int f -> string_of_int
(f ())
3942 | `intws
f -> string_with_suffix_of_int (f ())
3944 | `color
f -> color_to_string (f ())
3945 | `
bool (btos, f) -> btos (f ())
3948 let name, t
, offset
, _ = m_a
.(n) in
3949 ((let s = tostr t
in
3950 if String.length
s > 0
3951 then Printf.sprintf
"%s\t%s" name s
3955 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3959 m_qsearch
<- qsearch;
3961 match m_a
.(active) with
3962 | _, _, _, Action
f -> f uioh
3974 method hasaction
n =
3976 | _, _, _, Action
_ -> true
3980 let rec fillsrc prevmode prevuioh
=
3981 let sep () = src#caption
"" 0 in
3982 let colorp name get
set =
3984 (fun () -> color_to_string (get
()))
3987 let c = color_of_string v in
3990 state.text <- Printf.sprintf
"bad color `%s': %s"
3991 v (Printexc.to_string exn
);
3994 let oldmode = state.mode in
3995 let birdseye = isbirdseye state.mode in
3997 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3999 src#
bool "presentation mode"
4000 (fun () -> conf.presentation)
4002 conf.presentation <- v;
4003 state.anchor <- getanchor ();
4006 src#
bool "ignore case in searches"
4007 (fun () -> conf.icase
)
4008 (fun v -> conf.icase
<- v);
4011 (fun () -> conf.preload)
4012 (fun v -> conf.preload <- v);
4014 src#
bool "highlight links"
4015 (fun () -> conf.hlinks
)
4016 (fun v -> conf.hlinks
<- v);
4018 src#
bool "under info"
4019 (fun () -> conf.underinfo
)
4020 (fun v -> conf.underinfo
<- v);
4022 src#
bool "persistent bookmarks"
4023 (fun () -> conf.savebmarks
)
4024 (fun v -> conf.savebmarks
<- v);
4026 src#
bool "proportional display"
4027 (fun () -> conf.proportional
)
4028 (fun v -> reqlayout conf.angle
v);
4030 src#
bool "trim margins"
4031 (fun () -> conf.trimmargins
)
4032 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4034 src#
bool "persistent location"
4035 (fun () -> conf.jumpback
)
4036 (fun v -> conf.jumpback
<- v);
4039 src#
int "inter-page space"
4040 (fun () -> conf.interpagespace)
4042 conf.interpagespace <- n;
4044 match state.layout with
4049 state.maxy <- calcheight ();
4050 let y = getpagey pageno in
4055 (fun () -> conf.pagebias
)
4056 (fun v -> conf.pagebias
<- v);
4058 src#
int "scroll step"
4059 (fun () -> conf.scrollstep
)
4060 (fun n -> conf.scrollstep
<- n);
4062 src#
int "auto scroll step"
4064 match state.autoscroll
with
4066 | _ -> conf.autoscrollstep
)
4068 if state.autoscroll
<> None
4069 then state.autoscroll
<- Some
n;
4070 conf.autoscrollstep
<- n);
4073 (fun () -> truncate
(conf.zoom *. 100.))
4074 (fun v -> setzoom ((float v) /. 100.));
4077 (fun () -> conf.angle
)
4078 (fun v -> reqlayout v conf.proportional
);
4080 src#
int "scroll bar width"
4081 (fun () -> state.scrollw
)
4085 reshape conf.winw
conf.winh
;
4088 src#
int "scroll handle height"
4089 (fun () -> conf.scrollh
)
4090 (fun v -> conf.scrollh
<- v;);
4092 src#
int "thumbnail width"
4093 (fun () -> conf.thumbw
)
4095 conf.thumbw
<- min
4096 v;
4098 leavebirdseye beye
false;
4103 let mode = state.mode in
4104 src#
string "columns"
4106 match conf.columns
with
4108 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4109 | Csplit
(count
, _) -> "-" ^ string_of_int count
4112 let n, a, b = multicolumns_of_string v in
4113 setcolumns mode n a b);
4116 src#caption
"Presentation mode" 0;
4117 src#
bool "scrollbar visible"
4118 (fun () -> conf.scrollbarinpm
)
4120 if v != conf.scrollbarinpm
4122 conf.scrollbarinpm
<- v;
4123 if conf.presentation
4125 state.scrollw
<- if v then conf.scrollbw
else 0;
4126 reshape conf.winw
conf.winh
;
4132 src#caption
"Pixmap cache" 0;
4133 src#int_with_suffix
"size (advisory)"
4134 (fun () -> conf.memlimit
)
4135 (fun v -> conf.memlimit
<- v);
4138 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4139 (string_with_suffix_of_int state.memused
)
4140 (Hashtbl.length
state.tilemap
)) 1;
4143 src#caption
"Layout" 0;
4144 src#caption2
"Dimension"
4146 Printf.sprintf
"%dx%d (virtual %dx%d)"
4152 src#caption2
"Position" (fun () ->
4153 Printf.sprintf
"%dx%d" state.x state.y
4156 src#caption2
"Visible" (fun () -> describe_location ()) 1
4160 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4161 "Save these parameters as global defaults at exit"
4162 (fun () -> conf.bedefault
)
4163 (fun v -> conf.bedefault
<- v)
4167 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4168 src#
bool ~offset
:0 ~
btos "Extended parameters"
4169 (fun () -> !showextended)
4170 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4174 (fun () -> conf.checkers
)
4175 (fun v -> conf.checkers
<- v; setcheckers v);
4176 src#
bool "update cursor"
4177 (fun () -> conf.updatecurs
)
4178 (fun v -> conf.updatecurs
<- v);
4180 (fun () -> conf.verbose
)
4181 (fun v -> conf.verbose
<- v);
4182 src#
bool "invert colors"
4183 (fun () -> conf.invert
)
4184 (fun v -> conf.invert
<- v);
4186 (fun () -> conf.maxhfit
)
4187 (fun v -> conf.maxhfit
<- v);
4188 src#
bool "redirect stderr"
4189 (fun () -> conf.redirectstderr)
4190 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4191 src#
string "uri launcher"
4192 (fun () -> conf.urilauncher
)
4193 (fun v -> conf.urilauncher
<- v);
4194 src#
string "path launcher"
4195 (fun () -> conf.pathlauncher
)
4196 (fun v -> conf.pathlauncher
<- v);
4197 src#
string "tile size"
4198 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4201 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4202 conf.tileh
<- max
64 w;
4203 conf.tilew
<- max
64 h;
4206 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4207 v (Printexc.to_string exn
));
4208 src#
int "texture count"
4209 (fun () -> conf.texcount
)
4212 then conf.texcount
<- v
4213 else showtext '
!'
" Failed to set texture count please retry later"
4215 src#
int "slice height"
4216 (fun () -> conf.sliceheight
)
4218 conf.sliceheight
<- v;
4219 wcmd "sliceh %d" conf.sliceheight
;
4221 src#
int "anti-aliasing level"
4222 (fun () -> conf.aalevel
)
4224 conf.aalevel
<- bound v 0 8;
4225 state.anchor <- getanchor ();
4226 opendoc state.path
state.password
;
4228 src#
int "ui font size"
4229 (fun () -> fstate.fontsize
)
4230 (fun v -> setfontsize (bound v 5 100));
4231 colorp "background color"
4232 (fun () -> conf.bgcolor
)
4233 (fun v -> conf.bgcolor
<- v);
4234 src#
bool "crop hack"
4235 (fun () -> conf.crophack
)
4236 (fun v -> conf.crophack
<- v);
4237 src#
string "trim fuzz"
4238 (fun () -> irect_to_string conf.trimfuzz
)
4241 conf.trimfuzz
<- irect_of_string v;
4243 then settrim true conf.trimfuzz
;
4245 state.text <- Printf.sprintf
"bad irect `%s': %s"
4246 v (Printexc.to_string exn
)
4248 src#
string "throttle"
4250 match conf.maxwait
with
4251 | None
-> "show place holder if page is not ready"
4254 then "wait for page to fully render"
4256 "wait " ^ string_of_float
time
4257 ^
" seconds before showing placeholder"
4261 let f = float_of_string
v in
4263 then conf.maxwait
<- None
4264 else conf.maxwait
<- Some
f
4266 state.text <- Printf.sprintf
"bad time `%s': %s"
4267 v (Printexc.to_string exn
)
4269 src#
string "ghyll scroll"
4271 match conf.ghyllscroll
with
4273 | Some nab
-> ghyllscroll_to_string nab
4278 if String.length
v = 0
4280 else Some
(ghyllscroll_of_string v)
4282 conf.ghyllscroll
<- gs
4284 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4285 v (Printexc.to_string exn
)
4287 src#
string "selection command"
4288 (fun () -> conf.selcmd
)
4289 (fun v -> conf.selcmd
<- v);
4290 src#colorspace
"color space"
4291 (fun () -> colorspace_to_string conf.colorspace
)
4293 conf.colorspace
<- colorspace_of_int v;
4300 src#caption
"Document" 0;
4301 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4302 src#caption2
"Pages"
4303 (fun () -> string_of_int
state.pagecount
) 1;
4304 src#caption2
"Dimensions"
4305 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4309 src#caption
"Trimmed margins" 0;
4310 src#caption2
"Dimensions"
4311 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4314 src#reset prevmode prevuioh
;
4318 let prevmode = state.mode
4319 and prevuioh
= state.uioh in
4320 fillsrc prevmode prevuioh
;
4321 let source = (src :> lvsource
) in
4322 let modehash = findkeyhash conf "info" in
4323 state.uioh <- coe (object (self)
4324 inherit listview ~
source ~trusted
:true ~
modehash as super
4325 val mutable m_prevmemused
= 0
4326 method infochanged
= function
4328 if m_prevmemused
!= state.memused
4330 m_prevmemused
<- state.memused
;
4331 G.postRedisplay "memusedchanged";
4333 | Pdim
-> G.postRedisplay "pdimchanged"
4334 | Docinfo
-> fillsrc prevmode prevuioh
4336 method key key mask
=
4337 if not
(Wsi.withctrl mask
)
4340 | 0xff51 -> coe (self#updownlevel ~
-1)
4341 | 0xff53 -> coe (self#updownlevel
1)
4342 | _ -> super#
key key mask
4343 else super#
key key mask
4345 G.postRedisplay "info";
4351 inherit lvsourcebase
4352 method getitemcount
= Array.length
state.help
4354 let s, n, _ = state.help
.(n) in
4357 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4361 m_qsearch
<- qsearch;
4362 match state.help
.(active) with
4363 | _, _, Action
f -> Some
(f uioh)
4373 method hasaction
n =
4374 match state.help
.(n) with
4375 | _, _, Action
_ -> true
4382 let modehash = findkeyhash conf "help" in
4383 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4384 G.postRedisplay "help";
4389 let re = Str.regexp
"[\r\n]" in
4391 inherit lvsourcebase
4392 val mutable m_items
= [||]
4394 method getitemcount
= 1 + Array.length m_items
4399 else m_items
.(n-1), 0
4401 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4406 then Buffer.clear
state.errmsgs
;
4407 m_qsearch
<- qsearch;
4414 method hasaction
n =
4418 state.newerrmsgs
<- false;
4419 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4420 m_items
<- Array.of_list
l
4428 let source = (msgsource :> lvsource
) in
4429 let modehash = findkeyhash conf "listview" in
4430 state.uioh <- coe (object
4431 inherit listview ~
source ~trusted
:false ~
modehash as super
4434 then msgsource#reset
;
4437 G.postRedisplay "msgs";
4440 let quickbookmark ?title
() =
4441 match state.layout with
4447 let sec = Unix.gettimeofday
() in
4448 let tm = Unix.localtime
sec in
4449 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4453 (tm.Unix.tm_year
+ 1900)
4456 | Some
title -> title
4459 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4464 state.fullscreen
<- None
;
4468 let setautoscrollspeed step goingdown
=
4469 let incr = max
1 ((abs step
) / 2) in
4470 let incr = if goingdown
then incr else -incr in
4471 let astep = step
+ incr in
4472 state.autoscroll
<- Some
astep;
4475 let gotounder = function
4476 | Ulinkgoto
(pageno, top) ->
4480 gotopage1 pageno top;
4486 | Uremote
(filename
, pageno) ->
4488 if Sys.file_exists filename
4491 let dir = Filename.dirname
state.path in
4492 let path = Filename.concat
dir filename
in
4493 if Sys.file_exists
path
4497 if String.length
path > 0
4499 let anchor = getanchor () in
4500 let ranchor = state.path, state.password
, anchor in
4501 state.anchor <- (pageno, 0.0);
4502 state.ranchors
<- ranchor :: state.ranchors
;
4505 else showtext '
!'
("Could not find " ^ filename
)
4507 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4511 match conf.columns
with
4513 | _ -> conf.zoom > 1.0
4516 let viewkeyboard key mask
=
4518 let mode = state.mode in
4519 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4522 G.postRedisplay "view:enttext"
4524 let ctrl = Wsi.withctrl mask
in
4529 | 0xff63 -> (* insert *)
4530 if conf.angle
mod 360 = 0
4532 state.mode <- LinkNav
(Ltgendir
0);
4535 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4537 | 0xff1b | 113 -> (* escape / q *)
4538 begin match state.mstate
with
4540 state.mstate
<- Mnone
;
4541 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4542 G.postRedisplay "kill zoom rect";
4544 match state.ranchors
with
4546 | (path, password
, anchor) :: rest
->
4547 state.ranchors
<- rest
;
4548 state.anchor <- anchor;
4549 opendoc path password
4552 | 0xff08 -> (* backspace *)
4553 let y = getnav ~
-1 in
4554 gotoy_and_clear_text y
4562 G.postRedisplay "dehighlight";
4564 | 47 | 63 -> (* / ? *)
4565 let ondone isforw
s =
4566 cbput state.hists
.pat
s;
4567 state.searchpattern
<- s;
4570 let s = String.create
1 in
4571 s.[0] <- Char.chr
key;
4572 enttext (s, "", Some
(onhist state.hists
.pat
),
4573 textentry, ondone (key = 47))
4575 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4576 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4577 setzoom (conf.zoom +. incr)
4579 | 43 | 0xffab -> (* + *)
4582 try int_of_string
s with exc
->
4583 state.text <- Printf.sprintf
"bad integer `%s': %s"
4584 s (Printexc.to_string exc
);
4590 state.text <- "page bias is now " ^ string_of_int
n;
4593 enttext ("page bias: ", "", None
, intentry, ondone)
4595 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4596 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4597 setzoom (max
0.01 (conf.zoom -. decr))
4599 | 45 | 0xffad -> (* - *)
4600 let ondone msg
= state.text <- msg
in
4602 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4603 optentry state.mode, ondone
4606 | 48 when ctrl -> (* ctrl-0 *)
4609 | 49 when ctrl -> (* 1 *)
4610 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4614 | 0xffc6 -> (* f9 *)
4617 | 57 when ctrl -> (* ctrl-9 *)
4620 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4621 when not
ctrl -> (* 0..9 *)
4624 try int_of_string
s with exc
->
4625 state.text <- Printf.sprintf
"bad integer `%s': %s"
4626 s (Printexc.to_string exc
);
4632 cbput state.hists
.pag
(string_of_int
n);
4633 gotopage1 (n + conf.pagebias
- 1) 0;
4636 let pageentry text key =
4637 match Char.unsafe_chr
key with
4638 | 'g'
-> TEdone
text
4639 | _ -> intentry text key
4641 let text = "x" in text.[0] <- Char.chr
key;
4642 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4645 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4646 reshape conf.winw
conf.winh
;
4649 conf.hlinks
<- not
conf.hlinks
;
4650 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4651 G.postRedisplay "toggle highlightlinks";
4654 state.glinks
<- true;
4655 let a = Char.code '
a'
and z
= Char.code 'z'
in
4658 let rec loop pos
n = if pos
= String.length
s then n else
4659 let m = Char.code
s.[pos
] - a in
4660 loop (pos
+1) (n*(z
-a+1) + m)
4665 let rec loop n = function
4668 match getopaque l.pageno with
4669 | None
-> loop n rest
4671 let m = getlinkcount opaque
in
4674 let under = getlink opaque
n in
4678 else loop (n-m) rest
4680 loop n state.layout;
4683 let onkey text key =
4684 if (key >= a && key <= z
)
4686 let c = Char.unsafe_chr
key in
4687 let text = addchar text c in
4692 let mode = state.mode in
4693 state.mode <- Textentry
(
4694 (":", "", Some
(onhist state.hists
.pag
), onkey, ondone),
4696 state.glinks
<- false;
4700 G.postRedisplay "view:enttext"
4703 begin match state.autoscroll
with
4705 conf.autoscrollstep
<- step
;
4706 state.autoscroll
<- None
4708 if conf.autoscrollstep
= 0
4709 then state.autoscroll
<- Some
1
4710 else state.autoscroll
<- Some
conf.autoscrollstep
4713 | 112 when ctrl -> (* ctrl-p *)
4717 conf.presentation <- not
conf.presentation;
4718 if conf.presentation
4720 if not
conf.scrollbarinpm
4721 then state.scrollw
<- 0;
4724 state.scrollw
<- conf.scrollbw
;
4726 showtext ' '
("presentation mode " ^
4727 if conf.presentation then "on" else "off");
4728 state.anchor <- getanchor ();
4732 begin match state.fullscreen
with
4734 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4737 state.fullscreen
<- None
;
4742 gotoy_and_clear_text 0
4745 gotopage1 (state.pagecount
- 1) 0
4747 | 112 | 78 -> (* p|N *)
4748 search state.searchpattern
false
4750 | 110 | 0xffc0 -> (* n|F3 *)
4751 search state.searchpattern
true
4754 begin match state.layout with
4757 gotoy_and_clear_text (getpagey l.pageno)
4761 begin match List.rev
state.layout with
4764 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4765 gotoy_and_clear_text (getpagey pageno)
4768 | 0xff9f | 0xffff -> (* delete *)
4769 begin match state.layout with
4772 let pageno = max
0 (l.pageno-1) in
4773 gotoy_and_clear_text (getpagey pageno)
4777 showtext ' '
(describe_location ());
4780 begin match state.layout with
4783 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4788 enterbookmarkmode ()
4790 | 104 | 0xffbe -> (* h|F1 *)
4796 | 101 when conf.redirectstderr -> (* e *)
4801 match state.layout with
4804 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4808 enttext ("bookmark: ", "", None
, textentry, ondone)
4812 showtext ' '
"Quick bookmark added";
4815 begin match state.layout with
4817 let rect = getpdimrect
l.pagedimno
in
4821 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4822 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4824 (truncate
(rect.(1) -. rect.(0)),
4825 truncate
(rect.(3) -. rect.(0)))
4827 let w = truncate
((float w)*.conf.zoom)
4828 and h = truncate
((float h)*.conf.zoom) in
4831 state.anchor <- getanchor ();
4832 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4834 G.postRedisplay "z";
4839 | 50 when ctrl -> (* ctrl-2 *)
4840 let maxw = getmaxw
() in
4842 then setzoom (maxw /. float conf.winw
)
4844 | 60 | 62 -> (* < > *)
4845 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4847 | 91 | 93 -> (* [ ] *)
4849 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4851 G.postRedisplay "brightness";
4853 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4854 setzoom state.prevzoom
4856 | 107 | 0xff52 -> (* k up *)
4857 begin match state.autoscroll
with
4859 begin match state.mode with
4860 | Birdseye beye
-> upbirdseye 1 beye
4863 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4864 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4867 setautoscrollspeed n false
4870 | 106 | 0xff54 -> (* j down *)
4871 begin match state.autoscroll
with
4873 begin match state.mode with
4874 | Birdseye beye
-> downbirdseye 1 beye
4877 then gotoy_and_clear_text (clamp (conf.winh
/2))
4878 else gotoy_and_clear_text (clamp conf.scrollstep
)
4881 setautoscrollspeed n true
4884 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4892 let dx = if key = 0xff51 then dx else -dx in
4893 state.x <- state.x + dx;
4894 gotoy_and_clear_text state.y
4897 G.postRedisplay "lef/right"
4900 | 0xff55 -> (* prior *)
4904 match state.layout with
4906 | l :: _ -> state.y - l.pagey
4912 | 0xff56 -> (* next *)
4916 match List.rev
state.layout with
4918 | l :: _ -> getpagey l.pageno
4924 | 0xff50 -> gotoghyll 0
4925 | 0xff57 -> gotoghyll (clamp state.maxy)
4926 | 0xff53 when Wsi.withalt mask
->
4927 gotoghyll (getnav ~
-1)
4928 | 0xff51 when Wsi.withalt mask
->
4929 gotoghyll (getnav 1)
4932 state.anchor <- getanchor ();
4933 opendoc state.path state.password
4935 | 118 when conf.debug
-> (* v *)
4938 match getopaque l.pageno with
4941 let x0, y0, x1, y1 = pagebbox opaque
in
4942 let a,b = float x0, float y0 in
4943 let c,d = float x1, float y0 in
4944 let e,f = float x1, float y1 in
4945 let h,j
= float x0, float y1 in
4946 let rect = (a,b,c,d,e,f,h,j
) in
4948 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4950 G.postRedisplay "v";
4953 vlog "huh? %s" (Wsi.keyname
key)
4956 let linknavkeyboard key mask
linknav =
4957 let getpage pageno =
4958 let rec loop = function
4960 | l :: _ when l.pageno = pageno -> Some
l
4961 | _ :: rest
-> loop rest
4962 in loop state.layout
4964 let doexact (pageno, n) =
4965 match getopaque pageno, getpage pageno with
4966 | Some opaque
, Some
l ->
4969 let under = getlink opaque
n in
4970 G.postRedisplay "link gotounder";
4976 | 0xff50 -> (* home *)
4977 Some
(findlink opaque LDfirst
), -1
4979 | 0xff57 -> (* end *)
4980 Some
(findlink opaque LDlast
), 1
4982 | 0xff51 -> (* left *)
4983 Some
(findlink opaque
(LDleft
n)), -1
4985 | 0xff53 -> (* right *)
4986 Some
(findlink opaque
(LDright
n)), 1
4988 | 0xff52 -> (* up *)
4989 Some
(findlink opaque
(LDup
n)), -1
4991 | 0xff54 -> (* down *)
4992 Some
(findlink opaque
(LDdown
n)), 1
4997 begin match findpwl
l.pageno dir with
5001 state.mode <- LinkNav
(Ltgendir
dir);
5002 let y, h = getpageyh pageno in
5005 then y + h - conf.winh
5010 begin match getopaque pageno, getpage pageno with
5011 | Some opaque
, Some
_ ->
5013 let ld = if dir > 0 then LDfirst
else LDlast
in
5016 begin match link with
5018 showlinktype (getlink opaque
m);
5019 state.mode <- LinkNav
(Ltexact
(pageno, m));
5020 G.postRedisplay "linknav jpage";
5027 begin match opt with
5028 | Some Lnotfound
-> pwl l dir;
5029 | Some
(Lfound
m) ->
5033 let _, y0, _, y1 = getlinkrect opaque
m in
5035 then gotopage1 l.pageno y0
5037 let d = fstate.fontsize
+ 1 in
5038 if y1 - l.pagey > l.pagevh - d
5039 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5040 else G.postRedisplay "linknav";
5042 showlinktype (getlink opaque
m);
5043 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5046 | None
-> viewkeyboard key mask
5048 | _ -> viewkeyboard key mask
5053 G.postRedisplay "leave linknav"
5057 | Ltgendir
_ -> viewkeyboard key mask
5058 | Ltexact exact
-> doexact exact
5061 let keyboard key mask
=
5062 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5063 then wcmd "interrupt"
5064 else state.uioh <- state.uioh#
key key mask
5067 let birdseyekeyboard key mask
5068 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5070 match conf.columns
with
5072 | Cmulti
((c, _, _), _) -> c
5073 | Csplit
_ -> failwith
"bird's eye split mode"
5076 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5077 let y, h = getpageyh pageno in
5078 let top = (conf.winh
- h) / 2 in
5079 gotoy (max
0 (y - top))
5080 | 0xff0d -> leavebirdseye beye
false
5081 | 0xff1b -> leavebirdseye beye
true (* escape *)
5082 | 0xff52 -> upbirdseye incr beye
(* prior *)
5083 | 0xff54 -> downbirdseye incr beye
(* next *)
5084 | 0xff51 -> upbirdseye 1 beye
(* up *)
5085 | 0xff53 -> downbirdseye 1 beye
(* down *)
5088 begin match state.layout with
5092 state.mode <- Birdseye
(
5093 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5095 gotopage1 l.pageno 0;
5098 let layout = layout (state.y-conf.winh
) conf.winh
in
5100 | [] -> gotoy (clamp (-conf.winh
))
5102 state.mode <- Birdseye
(
5103 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5105 gotopage1 l.pageno 0
5108 | [] -> gotoy (clamp (-conf.winh
))
5112 begin match List.rev
state.layout with
5114 let layout = layout (state.y + conf.winh
) conf.winh
in
5115 begin match layout with
5117 let incr = l.pageh
- l.pagevh in
5122 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5124 G.postRedisplay "birdseye pagedown";
5126 else gotoy (clamp (incr + conf.interpagespace*2));
5130 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5131 gotopage1 l.pageno 0;
5134 | [] -> gotoy (clamp conf.winh
)
5138 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5142 let pageno = state.pagecount
- 1 in
5143 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5144 if not
(pagevisible state.layout pageno)
5147 match List.rev
state.pdims
with
5149 | (_, _, h, _) :: _ -> h
5151 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5152 else G.postRedisplay "birdseye end";
5153 | _ -> viewkeyboard key mask
5156 let drawpage l linkindexbase
=
5158 match state.mode with
5159 | Textentry
_ -> scalecolor 0.4
5161 | View
-> scalecolor 1.0
5162 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5163 if l.pageno = hooverpageno
5166 if l.pageno = pageno
5172 begin match getopaque l.pageno with
5174 if tileready l l.pagex l.pagey
5176 let x = l.pagedispx - l.pagex
5177 and y = l.pagedispy - l.pagey in
5178 let hlmask = (if conf.hlinks
then 1 else 0)
5179 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5182 match state.mode with
5183 | Textentry
((_, s, _, _, _), _) when state.glinks
-> s
5186 postprocess opaque
hlmask x y (linkindexbase
, s);
5193 let scrollindicator () =
5194 let sbw, ph
, sh = state.uioh#
scrollph in
5195 let sbh, pw, sw = state.uioh#scrollpw
in
5197 GlDraw.color (0.64, 0.64, 0.64);
5199 (float (conf.winw
- sbw), 0.)
5200 (float conf.winw
, float conf.winh
)
5203 (0., float (conf.winh
- sbh))
5204 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5206 GlDraw.color (0.0, 0.0, 0.0);
5209 (float (conf.winw
- sbw), ph
)
5210 (float conf.winw
, ph
+. sh)
5213 (pw, float (conf.winh
- sbh))
5214 (pw +. sw, float conf.winh
)
5219 match state.mstate
with
5220 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5223 | Msel
((x0, y0), (x1, y1)) ->
5224 let rec loop = function
5226 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5227 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5228 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5229 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5231 match getopaque l.pageno with
5233 let x0, y0 = pagetranslatepoint l x0 y0 in
5234 let x1, y1 = pagetranslatepoint l x1 y1 in
5235 seltext opaque
(x0, y0, x1, y1);
5243 let showrects rects
=
5245 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5246 GlDraw.polygon_mode `both `fill
;
5247 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5249 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5251 if l.pageno = pageno
5253 let dx = float (l.pagedispx - l.pagex) in
5254 let dy = float (l.pagedispy - l.pagey) in
5255 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5256 GlDraw.begins `quads
;
5258 GlDraw.vertex2
(x0+.dx, y0+.dy);
5259 GlDraw.vertex2
(x1+.dx, y1+.dy);
5260 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5261 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5272 GlClear.color (scalecolor2 conf.bgcolor
);
5273 GlClear.clear
[`
color];
5274 let rec loop linkindexbase
= function
5276 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5277 loop linkindexbase rest
5280 loop 0 state.layout;
5282 match state.mode with
5283 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5284 begin match getopaque pageno with
5286 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5293 | None
-> state.rects
5300 begin match state.mstate
with
5301 | Mzoomrect
((x0, y0), (x1, y1)) ->
5303 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5304 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5305 GlDraw.rect (float x0, float y0)
5306 (float x1, float y1);
5315 let zoomrect x y x1 y1 =
5318 and y0 = min
y y1 in
5319 gotoy (state.y + y0);
5320 state.anchor <- getanchor ();
5321 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5323 if state.w < conf.winw
- state.scrollw
5324 then (conf.winw
- state.scrollw
- state.w) / 2
5327 state.x <- (state.x + margin) - x0;
5329 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5330 state.mstate
<- Mnone
;
5334 let winw = conf.winw - state.scrollw
- 1 in
5335 let s = float x /. float winw in
5336 let destx = truncate
(float (state.w + winw) *. s) in
5337 state.x <- winw - destx;
5338 gotoy_and_clear_text state.y;
5339 state.mstate
<- Mscrollx
;
5343 let s = float y /. float conf.winh
in
5344 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5345 gotoy_and_clear_text desty;
5346 state.mstate
<- Mscrolly
;
5349 let viewmouse button down
x y mask
=
5351 | n when (n == 4 || n == 5) && not down
->
5352 if Wsi.withctrl mask
5354 match state.mstate
with
5355 | Mzoom
(oldn
, i
) ->
5363 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5365 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5367 let zoom = conf.zoom -. incr in
5369 state.mstate
<- Mzoom
(n, 0);
5371 state.mstate
<- Mzoom
(n, i
+1);
5373 else state.mstate
<- Mzoom
(n, 0)
5375 | _ -> state.mstate
<- Mzoom
(n, 0)
5378 match state.autoscroll
with
5379 | Some step
-> setautoscrollspeed step
(n=4)
5383 then -conf.scrollstep
5384 else conf.scrollstep
5386 let incr = incr * 2 in
5387 let y = clamp incr in
5388 gotoy_and_clear_text y
5391 | 1 when Wsi.withctrl mask
->
5394 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5395 state.mstate
<- Mpan
(x, y)
5398 state.mstate
<- Mnone
5403 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5405 state.mstate
<- Mzoomrect
(p, p)
5408 match state.mstate
with
5409 | Mzoomrect
((x0, y0), _) ->
5410 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5411 then zoomrect x0 y0 x y
5413 state.mstate
<- Mnone
;
5414 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5415 G.postRedisplay "kill accidental zoom rect";
5418 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5419 state.mstate
<- Mnone
5422 | 1 when x > conf.winw - state.scrollw
->
5425 let _, position, sh = state.uioh#
scrollph in
5426 if y > truncate
position && y < truncate
(position +. sh)
5427 then state.mstate
<- Mscrolly
5430 state.mstate
<- Mnone
5432 | 1 when y > conf.winh
- state.hscrollh ->
5435 let _, position, sw = state.uioh#scrollpw
in
5436 if x > truncate
position && x < truncate
(position +. sw)
5437 then state.mstate
<- Mscrollx
5440 state.mstate
<- Mnone
5443 let dest = if down
then getunder x y else Unone
in
5444 begin match dest with
5448 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5451 | Unone
when down
->
5452 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5453 state.mstate
<- Mpan
(x, y);
5455 | Unone
| Utext
_ ->
5458 if conf.angle
mod 360 = 0
5460 state.mstate
<- Msel
((x, y), (x, y));
5461 G.postRedisplay "mouse select";
5465 match state.mstate
with
5468 | Mzoom
_ | Mscrollx
| Mscrolly
->
5469 state.mstate
<- Mnone
5471 | Mzoomrect
((x0, y0), _) ->
5475 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5476 state.mstate
<- Mnone
5478 | Msel
((_, y0), (_, y1)) ->
5479 let rec loop = function
5482 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5483 || ((y1 >= l.pagedispy
5484 && y1 <= (l.pagedispy + l.pagevh)))
5486 match getopaque l.pageno with
5490 try Some
(Unix.pipe
())
5492 dolog "can not create sel pipe: %s"
5493 (Printexc.to_string exn
);
5498 let doclose what fd
=
5501 dolog "%s close failed: %s"
5502 what
(Printexc.to_string exn
)
5507 G.postRedisplay "copysel"
5510 popen conf.selcmd
[r, 0; w, -1];
5513 dolog "can not exectute %S: %s"
5514 conf.selcmd
(Printexc.to_string exn
);
5522 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5523 state.mstate
<- Mnone
;
5530 let birdseyemouse button down
x y mask
5531 (conf, leftx
, _, hooverpageno
, anchor) =
5534 let rec loop = function
5537 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5538 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5540 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5546 | _ -> viewmouse button down
x y mask
5549 let mouse button down
x y mask
=
5550 state.uioh <- state.uioh#button button down
x y mask
;
5554 state.uioh <- state.uioh#
motion x y
5558 state.uioh <- state.uioh#
pmotion x y;
5564 method key key mask
=
5565 begin match state.mode with
5566 | Textentry
textentry -> textentrykeyboard key mask
textentry
5567 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5568 | View
-> viewkeyboard key mask
5569 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5573 method button button bstate
x y mask
=
5574 begin match state.mode with
5576 | View
-> viewmouse button bstate
x y mask
5577 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5583 begin match state.mode with
5585 | View
| Birdseye
_ | LinkNav
_ ->
5586 match state.mstate
with
5587 | Mzoom
_ | Mnone
-> ()
5592 state.mstate
<- Mpan
(x, y);
5594 then state.x <- state.x + dx;
5596 gotoy_and_clear_text y
5599 state.mstate
<- Msel
(a, (x, y));
5600 G.postRedisplay "motion select";
5603 let y = min
conf.winh
(max
0 y) in
5607 let x = min
conf.winw (max
0 x) in
5610 | Mzoomrect
(p0
, _) ->
5611 state.mstate
<- Mzoomrect
(p0
, (x, y));
5612 G.postRedisplay "motion zoomrect";
5616 method pmotion x y =
5617 begin match state.mode with
5618 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5619 let rec loop = function
5621 if hooverpageno
!= -1
5623 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5624 G.postRedisplay "pmotion birdseye no hoover";
5627 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5628 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5630 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5631 G.postRedisplay "pmotion birdseye hoover";
5641 match state.mstate
with
5642 | Mnone
-> updateunder x y
5643 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5648 method infochanged
_ = ()
5651 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5652 let p, h = scrollph state.y maxy in
5656 let winw = conf.winw - state.scrollw
- 1 in
5657 let fwinw = float winw in
5659 let sw = fwinw /. float state.w in
5660 let sw = fwinw *. sw in
5661 max
sw (float conf.scrollh
)
5664 let f = state.w+winw in
5665 let r = float (winw-state.x) /. float f in
5666 let p = fwinw *. r in
5670 if position +. sw > fwinw
5671 then fwinw -. position
5674 state.hscrollh, position, sw
5678 match state.mode with
5679 | LinkNav
_ -> "links"
5680 | Textentry
_ -> "textentry"
5681 | Birdseye
_ -> "birdseye"
5684 findkeyhash conf modename
5691 let fontpath = ref "";;
5694 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5697 let l = String.length
s in
5698 let b = Buffer.create
l in
5704 try Sys.getenv
"HOME"
5707 ("Can not determine home directory location: " ^
5708 Printexc.to_string exn
);
5712 let modifier_of_string = function
5713 | "alt" -> Wsi.altmask
5714 | "shift" -> Wsi.shiftmask
5715 | "ctrl" | "control" -> Wsi.ctrlmask
5716 | "meta" -> Wsi.metamask
5721 let r = Str.regexp
"-" in
5723 let elems = Str.full_split
r s in
5726 let m1 = modifier_of_string s in
5728 then (Wsi.namekey
s, m)
5731 | Str.Delim
s when n land 1 = 0 -> g s
5733 | Str.Delim
_ -> (k
, m)
5735 let rec loop n k
m = function
5738 let k, m = f n k m x in
5744 let keys_of_string =
5745 let r = Str.regexp
"[ \t]" in
5747 let elems = Str.split
r s in
5748 List.map
key_of_string elems
5751 let copykeyhashes c =
5752 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5755 let config_of c attrs
=
5759 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5760 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5761 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5762 | "preload" -> { c with preload = bool_of_string
v }
5763 | "page-bias" -> { c with pagebias
= int_of_string
v }
5764 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5765 | "auto-scroll-step" ->
5766 { c with autoscrollstep
= max
0 (int_of_string
v) }
5767 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5768 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5771 match String.lowercase
v with
5772 | "true" -> Some infinity
5774 | f -> Some
(float_of_string
f)
5776 { c with maxwait
= mw}
5777 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5778 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5779 | "vertical-margin" ->
5780 { c with interpagespace = max
0 (int_of_string
v) }
5782 let zoom = float_of_string
v /. 100. in
5783 let zoom = max
zoom 0.0 in
5784 { c with zoom = zoom }
5785 | "presentation" -> { c with presentation = bool_of_string
v }
5786 | "rotation-angle" -> { c with angle
= int_of_string
v }
5787 | "width" -> { c with winw = max
20 (int_of_string
v) }
5788 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5789 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5790 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5791 | "pixmap-cache-size" ->
5792 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5793 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5794 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5795 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5796 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5797 | "background-color" -> { c with bgcolor
= color_of_string v }
5798 | "scrollbar-in-presentation" ->
5799 { c with scrollbarinpm
= bool_of_string
v }
5800 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5801 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5802 | "mupdf-store-size" ->
5803 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5804 | "checkers" -> { c with checkers
= bool_of_string
v }
5805 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5806 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5807 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5808 | "uri-launcher" -> { c with urilauncher
= unent v }
5809 | "path-launcher" -> { c with pathlauncher
= unent v }
5810 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5811 | "invert-colors" -> { c with invert
= bool_of_string
v }
5812 | "brightness" -> { c with colorscale
= float_of_string
v }
5813 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5815 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5817 let (n, _, _) as nab
= multicolumns_of_string v in
5819 then { c with columns
= Csplit
(-n, [||]) }
5820 else { c with columns
= Cmulti
(nab
, [||]) }
5821 | "birds-eye-columns" ->
5822 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5823 | "selection-command" -> { c with selcmd
= unent v }
5824 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5827 prerr_endline
("Error processing attribute (`" ^
5828 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5831 let rec fold c = function
5834 let c = apply c k v in
5837 fold { c with keyhashes
= copykeyhashes c } attrs
;
5840 let fromstring f pos
n v d =
5843 dolog "Error processing attribute (%S=%S) at %d\n%s"
5844 n v pos
(Printexc.to_string exn
)
5849 let bookmark_of attrs
=
5850 let rec fold title page
rely = function
5851 | ("title", v) :: rest
-> fold v page
rely rest
5852 | ("page", v) :: rest
-> fold title v rely rest
5853 | ("rely", v) :: rest
-> fold title page
v rest
5854 | _ :: rest
-> fold title page
rely rest
5855 | [] -> title, page
, rely
5857 fold "invalid" "0" "0" attrs
5861 let rec fold path page
rely pan
= function
5862 | ("path", v) :: rest
-> fold v page
rely pan rest
5863 | ("page", v) :: rest
-> fold path v rely pan rest
5864 | ("rely", v) :: rest
-> fold path page
v pan rest
5865 | ("pan", v) :: rest
-> fold path page
rely v rest
5866 | _ :: rest
-> fold path page
rely pan rest
5867 | [] -> path, page
, rely, pan
5869 fold "" "0" "0" "0" attrs
5873 let rec fold rs ls
= function
5874 | ("out", v) :: rest
-> fold v ls rest
5875 | ("in", v) :: rest
-> fold rs
v rest
5876 | _ :: rest
-> fold ls rs rest
5882 let setconf dst
src =
5883 dst
.scrollbw
<- src.scrollbw
;
5884 dst
.scrollh
<- src.scrollh
;
5885 dst
.icase
<- src.icase
;
5886 dst
.preload <- src.preload;
5887 dst
.pagebias
<- src.pagebias
;
5888 dst
.verbose
<- src.verbose
;
5889 dst
.scrollstep
<- src.scrollstep
;
5890 dst
.maxhfit
<- src.maxhfit
;
5891 dst
.crophack
<- src.crophack
;
5892 dst
.autoscrollstep
<- src.autoscrollstep
;
5893 dst
.maxwait
<- src.maxwait
;
5894 dst
.hlinks
<- src.hlinks
;
5895 dst
.underinfo
<- src.underinfo
;
5896 dst
.interpagespace <- src.interpagespace;
5897 dst
.zoom <- src.zoom;
5898 dst
.presentation <- src.presentation;
5899 dst
.angle
<- src.angle
;
5900 dst
.winw <- src.winw;
5901 dst
.winh
<- src.winh
;
5902 dst
.savebmarks
<- src.savebmarks
;
5903 dst
.memlimit
<- src.memlimit
;
5904 dst
.proportional
<- src.proportional
;
5905 dst
.texcount
<- src.texcount
;
5906 dst
.sliceheight
<- src.sliceheight
;
5907 dst
.thumbw
<- src.thumbw
;
5908 dst
.jumpback
<- src.jumpback
;
5909 dst
.bgcolor
<- src.bgcolor
;
5910 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5911 dst
.tilew
<- src.tilew
;
5912 dst
.tileh
<- src.tileh
;
5913 dst
.mustoresize
<- src.mustoresize
;
5914 dst
.checkers
<- src.checkers
;
5915 dst
.aalevel
<- src.aalevel
;
5916 dst
.trimmargins
<- src.trimmargins
;
5917 dst
.trimfuzz
<- src.trimfuzz
;
5918 dst
.urilauncher
<- src.urilauncher
;
5919 dst
.colorspace
<- src.colorspace
;
5920 dst
.invert
<- src.invert
;
5921 dst
.colorscale
<- src.colorscale
;
5922 dst
.redirectstderr <- src.redirectstderr;
5923 dst
.ghyllscroll
<- src.ghyllscroll
;
5924 dst
.columns
<- src.columns
;
5925 dst
.beyecolumns
<- src.beyecolumns
;
5926 dst
.selcmd
<- src.selcmd
;
5927 dst
.updatecurs
<- src.updatecurs
;
5928 dst
.pathlauncher
<- src.pathlauncher
;
5929 dst
.keyhashes
<- copykeyhashes src;
5933 let h = Hashtbl.create
10 in
5934 let dc = { defconf with angle
= defconf.angle
} in
5935 let rec toplevel v t spos
_ =
5937 | Vdata
| Vcdata
| Vend
-> v
5938 | Vopen
("llppconfig", _, closed
) ->
5941 else { v with f = llppconfig
}
5943 error
"unexpected subelement at top level" s spos
5944 | Vclose
_ -> error
"unexpected close at top level" s spos
5946 and llppconfig
v t spos
_ =
5948 | Vdata
| Vcdata
-> v
5949 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5950 | Vopen
("defaults", attrs
, closed
) ->
5951 let c = config_of dc attrs
in
5955 else { v with f = defaults
}
5957 | Vopen
("ui-font", attrs
, closed
) ->
5958 let rec getsize size
= function
5960 | ("size", v) :: rest
->
5962 fromstring int_of_string spos
"size" v fstate.fontsize
in
5964 | l -> getsize size l
5966 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5969 else { v with f = uifont
(Buffer.create
10) }
5971 | Vopen
("doc", attrs
, closed
) ->
5972 let pathent, spage
, srely
, span
= doc_of attrs
in
5973 let path = unent pathent
5974 and pageno = fromstring int_of_string spos
"page" spage
0
5975 and rely = fromstring float_of_string spos
"rely" srely
0.0
5976 and pan
= fromstring int_of_string spos
"pan" span
0 in
5977 let c = config_of dc attrs
in
5978 let anchor = (pageno, rely) in
5980 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5981 else { v with f = doc
path pan
anchor c [] }
5984 error
"unexpected subelement in llppconfig" s spos
5986 | Vclose
"llppconfig" -> { v with f = toplevel }
5987 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5989 and defaults
v t spos
_ =
5991 | Vdata
| Vcdata
-> v
5992 | Vend
-> error
"unexpected end of input in defaults" s spos
5993 | Vopen
("keymap", attrs
, closed
) ->
5995 try List.assoc
"mode" attrs
5996 with Not_found
-> "global" in
6001 let h = findkeyhash dc modename in
6002 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6005 { v with f = pkeymap
ret KeyMap.empty }
6007 | Vopen
(_, _, _) ->
6008 error
"unexpected subelement in defaults" s spos
6010 | Vclose
"defaults" ->
6011 { v with f = llppconfig
}
6013 | Vclose
_ -> error
"unexpected close in defaults" s spos
6015 and uifont
b v t spos
epos =
6018 Buffer.add_substring
b s spos
(epos - spos
);
6020 | Vopen
(_, _, _) ->
6021 error
"unexpected subelement in ui-font" s spos
6022 | Vclose
"ui-font" ->
6023 if String.length
!fontpath = 0
6024 then fontpath := Buffer.contents
b;
6025 { v with f = llppconfig
}
6026 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6027 | Vend
-> error
"unexpected end of input in ui-font" s spos
6029 and doc
path pan
anchor c bookmarks
v t spos
_ =
6031 | Vdata
| Vcdata
-> v
6032 | Vend
-> error
"unexpected end of input in doc" s spos
6033 | Vopen
("bookmarks", _, closed
) ->
6036 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6038 | Vopen
("keymap", attrs
, closed
) ->
6040 try List.assoc
"mode" attrs
6041 with Not_found
-> "global"
6047 let h = findkeyhash c modename in
6048 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6049 doc
path pan
anchor c bookmarks
6051 { v with f = pkeymap
ret KeyMap.empty }
6053 | Vopen
(_, _, _) ->
6054 error
"unexpected subelement in doc" s spos
6057 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6058 { v with f = llppconfig
}
6060 | Vclose
_ -> error
"unexpected close in doc" s spos
6062 and pkeymap
ret keymap
v t spos
_ =
6064 | Vdata
| Vcdata
-> v
6065 | Vend
-> error
"unexpected end of input in keymap" s spos
6066 | Vopen
("map", attrs
, closed
) ->
6067 let r, l = map_of attrs
in
6068 let kss = fromstring keys_of_string spos
"in" r [] in
6069 let lss = fromstring keys_of_string spos
"out" l [] in
6073 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6074 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6077 then { v with f = pkeymap
ret keymap }
6080 { v with f = skip
"map" f }
6083 error
"unexpected subelement in keymap" s spos
6085 | Vclose
"keymap" ->
6086 { v with f = ret keymap }
6088 | Vclose
_ -> error
"unexpected close in keymap" s spos
6090 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6092 | Vdata
| Vcdata
-> v
6093 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6094 | Vopen
("item", attrs
, closed
) ->
6095 let titleent, spage
, srely
= bookmark_of attrs
in
6096 let page = fromstring int_of_string spos
"page" spage
0
6097 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6098 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6100 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6103 { v with f = skip
"item" f }
6106 error
"unexpected subelement in bookmarks" s spos
6108 | Vclose
"bookmarks" ->
6109 { v with f = doc
path pan
anchor c bookmarks }
6111 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6113 and skip tag
f v t spos
_ =
6115 | Vdata
| Vcdata
-> v
6117 error
("unexpected end of input in skipped " ^ tag
) s spos
6118 | Vopen
(tag'
, _, closed
) ->
6122 let f'
() = { v with f = skip tag
f } in
6123 { v with f = skip tag'
f'
}
6127 else error
("unexpected close in skipped " ^ tag
) s spos
6130 parse
{ f = toplevel; accu = () } s;
6136 let len = in_channel_length ic
in
6137 let s = String.create
len in
6138 really_input ic
s 0 len;
6141 | Parse_error
(msg
, s, pos
) ->
6142 let subs = subs s pos
in
6143 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6144 failwith
("parse error: " ^
s)
6147 failwith
("config load error: " ^
Printexc.to_string exn
)
6153 let dir = Filename.concat
home ".config" in
6154 if Sys.is_directory
dir then dir else home
6157 Filename.concat
dir "llpp.conf"
6160 let confpath = ref defconfpath;;
6163 if Sys.file_exists
!confpath
6166 (try Some
(open_in_bin
!confpath)
6169 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6170 Printexc.to_string exn
);
6179 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6180 Printexc.to_string exn
);
6186 f (Hashtbl.create
0, defconf)
6191 let pc, pb
, px, pa
=
6193 Hashtbl.find h (Filename.basename
state.path)
6194 with Not_found
-> dc, [], 0, (0, 0.0)
6198 state.bookmarks <- pb
;
6200 state.scrollw
<- conf.scrollbw
;
6202 then state.anchor <- pa
;
6203 cbput state.hists
.nav pa
;
6208 let add_attrs bb always
dc c =
6211 then Printf.bprintf bb
"\n %s='%b'" s a
6214 then Printf.bprintf bb
"\n %s='%d'" s a
6217 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6220 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6223 then Printf.bprintf bb
"\n %s='%f'" s a
6227 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6231 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6235 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6239 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6245 | Some
(_N
, _A
, _B
) ->
6246 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6256 else string_of_float
f
6258 Printf.bprintf bb
"\n %s='%s'" s v
6263 | Cmulti
((n, a, b), _) when n > 1 ->
6264 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6265 | Csplit
(n, _) when n > 1 ->
6266 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6272 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6277 then dc.winw, dc.winh
6279 match state.fullscreen
with
6281 | None
-> c.winw, c.winh
6283 let zoom, presentation, interpagespace, maxwait
=
6285 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6287 match state.mode with
6288 | Birdseye
(bc
, _, _, _, _) ->
6289 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6290 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6292 oi
"width" w dc.winw;
6293 oi
"height" h dc.winh
;
6294 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6295 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6296 ob "case-insensitive-search" c.icase
dc.icase
;
6297 ob "preload" c.preload dc.preload;
6298 oi
"page-bias" c.pagebias
dc.pagebias
;
6299 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6300 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6301 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6302 ob "crop-hack" c.crophack
dc.crophack
;
6303 oW
"throttle" maxwait
dc.maxwait
;
6304 ob "highlight-links" c.hlinks
dc.hlinks
;
6305 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6306 oi
"vertical-margin" interpagespace dc.interpagespace;
6307 oz
"zoom" zoom dc.zoom;
6308 ob "presentation" presentation dc.presentation;
6309 oi
"rotation-angle" c.angle
dc.angle
;
6310 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6311 ob "proportional-display" c.proportional
dc.proportional
;
6312 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6313 oi
"tex-count" c.texcount
dc.texcount
;
6314 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6315 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6316 ob "persistent-location" c.jumpback
dc.jumpback
;
6317 oc
"background-color" c.bgcolor
dc.bgcolor
;
6318 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6319 oi
"tile-width" c.tilew
dc.tilew
;
6320 oi
"tile-height" c.tileh
dc.tileh
;
6321 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6322 ob "checkers" c.checkers
dc.checkers
;
6323 oi
"aalevel" c.aalevel
dc.aalevel
;
6324 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6325 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6326 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6327 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6328 oC
"color-space" c.colorspace
dc.colorspace
;
6329 ob "invert-colors" c.invert
dc.invert
;
6330 oF
"brightness" c.colorscale
dc.colorscale
;
6331 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6332 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6333 oco
"columns" c.columns
dc.columns
;
6334 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6335 os
"selection-command" c.selcmd
dc.selcmd
;
6336 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6339 let keymapsbuf always
dc c =
6340 let bb = Buffer.create
16 in
6341 let rec loop = function
6343 | (modename, h) :: rest
->
6344 let dh = findkeyhash dc modename in
6345 if always
|| h <> dh
6347 if Hashtbl.length
h > 0
6349 if Buffer.length
bb > 0
6350 then Buffer.add_char
bb '
\n'
;
6351 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6352 Hashtbl.iter
(fun i
o ->
6353 let isdifferent = always
||
6355 let dO = Hashtbl.find dh i
in
6357 with Not_found
-> true
6362 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6363 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6364 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6365 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6366 Buffer.add_string
bb (Wsi.keyname
k);
6369 let rec loop = function
6371 | km
:: [] -> addkm km
6372 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6376 Buffer.add_string
bb "<map in='";
6380 Buffer.add_string
bb "' out='";
6382 Buffer.add_string
bb "'/>\n"
6385 Buffer.add_string
bb "' out='";
6387 Buffer.add_string
bb "'/>\n"
6389 | KMmulti
(ins, kms
) ->
6390 Buffer.add_char
bb ' '
;
6392 Buffer.add_string
bb "' out='";
6394 Buffer.add_string
bb "'/>\n"
6396 Buffer.add_string
bb "</keymap>";
6406 let uifontsize = fstate.fontsize
in
6407 let bb = Buffer.create
32768 in
6409 let dc = if conf.bedefault
then conf else dc in
6410 Buffer.add_string
bb "<llppconfig>\n";
6412 if String.length
!fontpath > 0
6414 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6420 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6423 Buffer.add_string
bb "<defaults ";
6424 add_attrs bb true dc dc;
6425 let kb = keymapsbuf true dc dc in
6426 if Buffer.length
kb > 0
6428 Buffer.add_string
bb ">\n";
6429 Buffer.add_buffer
bb kb;
6430 Buffer.add_string
bb "\n</defaults>\n";
6432 else Buffer.add_string
bb "/>\n";
6434 let adddoc path pan
anchor c bookmarks =
6435 if bookmarks == [] && c = dc && anchor = emptyanchor
6438 Printf.bprintf
bb "<doc path='%s'"
6439 (enent
path 0 (String.length
path));
6441 if anchor <> emptyanchor
6443 let n, y = anchor in
6444 Printf.bprintf
bb " page='%d'" n;
6447 Printf.bprintf
bb " rely='%f'" y
6452 then Printf.bprintf
bb " pan='%d'" pan
;
6454 add_attrs bb false dc c;
6455 let kb = keymapsbuf false dc c in
6457 begin match bookmarks with
6459 if Buffer.length
kb > 0
6461 Buffer.add_string
bb ">\n";
6462 Buffer.add_buffer
bb kb;
6463 Buffer.add_string
bb "</doc>\n";
6465 else Buffer.add_string
bb "/>\n"
6467 Buffer.add_string
bb ">\n<bookmarks>\n";
6468 List.iter
(fun (title, _level
, (page, rely)) ->
6470 "<item title='%s' page='%d'"
6471 (enent
title 0 (String.length
title))
6476 Printf.bprintf
bb " rely='%f'" rely
6478 Buffer.add_string
bb "/>\n";
6480 Buffer.add_string
bb "</bookmarks>";
6481 if Buffer.length
kb > 0
6483 Buffer.add_string
bb "\n";
6484 Buffer.add_buffer
bb kb;
6486 Buffer.add_string
bb "\n</doc>\n";
6492 match state.mode with
6493 | Birdseye
(c, pan, _, _, _) ->
6495 match conf.columns
with
6496 | Cmulti
((c, _, _), _) -> Some
c
6500 match c.columns
with
6501 | Cmulti
(c, _) -> Cmulti
(c, [||])
6502 | Csingle
-> Csingle
6503 | Csplit
_ -> failwith
"quit from bird's eye while split"
6505 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6506 | _ -> state.x, conf
6508 let basename = Filename.basename state.path in
6509 adddoc basename pan (getanchor ())
6512 match state.autoscroll
with
6514 | None
-> conf.autoscrollstep
}
6515 (if conf.savebmarks
then state.bookmarks else []);
6517 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6519 then adddoc path x y c bookmarks
6521 Buffer.add_string
bb "</llppconfig>";
6524 if Buffer.length
bb > 0
6527 let tmp = !confpath ^
".tmp" in
6528 let oc = open_out_bin
tmp in
6529 Buffer.output_buffer
oc bb;
6531 Unix.rename
tmp !confpath;
6534 ("error while saving configuration: " ^
Printexc.to_string exn
)
6541 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6542 "<password> Set password");
6544 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6545 "<path> Set path to the user interface font");
6547 ("-c", Arg.String
(fun s -> Config.confpath := s),
6548 "<path> Set path to the configuration file");
6550 ("-v", Arg.Unit
(fun () ->
6552 "%s\nconfiguration path: %s\n"
6556 exit
0), " Print version and exit");
6559 (fun s -> state.path <- s)
6560 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6562 if String.length
state.path = 0
6563 then (prerr_endline
"file name missing"; exit
1);
6567 let globalkeyhash = findkeyhash conf "global" in
6568 let wsfd, winw, winh
= Wsi.init
(object
6570 if nogeomcmds state.geomcmds
6573 GlFunc.draw_buffer `front
;
6574 GlClear.color (scalecolor2 conf.bgcolor
);
6575 GlClear.clear
[`
color];
6576 GlFunc.draw_buffer `back
;
6578 method display = display ()
6579 method reshape w h = reshape w h
6580 method mouse b d x y m = mouse b d x y m
6581 method motion x y = state.mpos
<- (x, y); motion x y
6582 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6584 let mascm = m land (
6585 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6587 match state.keystate
with
6589 let km = k, mascm in
6592 try Hashtbl.find globalkeyhash km
6594 let modehash = state.uioh#
modehash in
6595 try Hashtbl.find modehash km
6596 with Not_found
-> KMinsrt
(k, m)
6598 | KMinsrt
(k, m) -> keyboard k m
6599 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6600 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6602 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6603 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6604 state.keystate
<- KSnone
6605 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6606 state.keystate
<- KSinto
(keys
, insrt
)
6608 state.keystate
<- KSnone
6610 method enter
x y = state.mpos
<- (x, y); pmotion x y
6611 method leave = state.mpos
<- (-1, -1)
6612 method quit
= raise Quit
6613 end) conf.winw conf.winh
(platform = Posx
) in
6618 List.exists
GlMisc.check_extension
6619 [ "GL_ARB_texture_rectangle"
6620 ; "GL_EXT_texture_recangle"
6621 ; "GL_NV_texture_rectangle" ]
6623 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6625 let cr, sw = Unix.pipe
()
6626 and sr
, cw = Unix.pipe
() in
6633 setcheckers conf.checkers
;
6637 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6638 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6643 state.text <- "Opening " ^
state.path;
6645 opendoc state.path state.password
;
6648 let rec loop deadline
=
6650 match state.errfd
with
6651 | None
-> [state.sr
; state.wsfd]
6652 | Some fd
-> [state.sr
; state.wsfd; fd
]
6656 state.redisplay
<- false;
6663 if deadline
= infinity
6665 else max
0.0 (deadline
-. now)
6670 try Unix.select
r [] [] timeout
6671 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6677 if state.ghyll
== noghyll
6679 match state.autoscroll
with
6680 | Some step
when step
!= 0 ->
6681 let y = state.y + step
in
6685 else if y >= state.maxy then 0 else y
6688 if state.mode = View
6689 then state.text <- "";
6692 else deadline
+. 0.01
6697 let rec checkfds = function
6699 | fd
:: rest
when fd
= state.sr
->
6700 let cmd = readcmd state.sr
in
6704 | fd
:: rest
when fd
= state.wsfd ->
6709 let s = String.create
80 in
6710 let n = Unix.read fd
s 0 80 in
6711 if conf.redirectstderr
6713 Buffer.add_substring
state.errmsgs
s 0 n;
6714 state.newerrmsgs
<- true;
6715 state.redisplay
<- true;
6718 prerr_string
(String.sub
s 0 n);
6726 if deadline
= infinity
6730 match state.autoscroll
with
6731 | Some step
when step
!= 0 -> deadline1
6732 | _ -> if state.ghyll
== noghyll then infinity
else deadline1