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 -> 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 ()
986 if Array.length
b > 0
988 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
992 if Array.length
b > 0
994 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
999 let getpageyh pageno
=
1000 let rec f pn ph pi
y l
=
1002 | (n, _
, h
, _
) :: rest
->
1003 let ips = calcips h
in
1006 let h = if n = pageno
then h else ph
in
1007 if conf.presentation
&& n = pageno
1009 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1011 y + (pageno
- pn
) * (ph
+ pi
), h
1013 let y = y + (if conf.presentation
then pi
else 0) in
1014 let y = y + (n - pn
) * (ph
+ pi
) in
1018 y + (pageno
- pn
) * (ph
+ pi
), ph
1020 f 0 0 0 0 state.pdims
1023 let getpageyh pageno
=
1024 match conf.columns
with
1025 | Csingle
-> getpageyh pageno
1027 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1031 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1035 let getpagedim pageno
=
1038 | (n, _
, _
, _
) as pdim
:: rest
->
1040 then (if n = pageno
then pdim
else ppdim
)
1045 f (-1, -1, -1, -1) state.pdims
1048 let getpagey pageno
= fst
(getpageyh pageno
);;
1050 let nogeomcmds cmds
=
1052 | s, [] -> String.length
s = 0
1057 let sh = sh - state.hscrollh
in
1058 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1059 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1061 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1062 let ips = calcips h in
1064 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1068 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1070 prev
, pdims
, pdimno
, 0
1072 let dy = dy + yinc in
1073 let py = py + yinc in
1074 if pageno
= state.pagecount
|| dy >= sh
1079 if py + h <= vy - yinc
1081 let py = py + h + ips in
1082 let dy = max
0 (py - y) in
1083 f ~pageno
:(pageno
+1)
1091 let pagey = vy - py in
1092 let pagevh = h - pagey in
1093 let pagevh = min
(sh - dy) pagevh in
1094 let off = if yinc > 0 then py - vy else 0 in
1095 let py = py + h + ips in
1098 if state.w
< conf.winw
- state.scrollw
1099 then (conf.winw
- state.scrollw
- state.w
) / 2
1102 let dispx = xoff + state.x in
1108 let lw = w
- pagex in
1109 min
lw (conf.winw
- state.scrollw
)
1113 ; pagedimno
= pdimno
1117 ; pagey = pagey + off
1119 ; pagevh = pagevh - off
1121 ; pagedispy
= dy + off
1124 let accu = e :: accu in
1125 f ~pageno
:(pageno
+1)
1146 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1147 let sh = sh - state.hscrollh
in
1148 let rec fold accu n =
1149 if n = Array.length
b
1152 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1155 || n = state.pagecount
- coverB
1156 || (n - coverA
) mod columns
= columns
- 1)
1162 let pagey = max
0 (y - vy) in
1163 let pagedispy = if pagey > 0 then 0 else vy - y in
1164 let pagedispx, pagex =
1166 if n = coverA
- 1 || n = state.pagecount
- coverB
1167 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1168 else dx + xoff + state.x
1175 let vw = conf.winw
- state.scrollw
- pagedispx in
1176 let pw = w
- pagex in
1179 let pagevh = min
(h - pagey) (sh - pagedispy) in
1180 if pagevw > 0 && pagevh > 0
1184 ; pagedimno
= pdimno
1191 ; pagedispx = pagedispx
1192 ; pagedispy = pagedispy
1203 List.rev
(fold [] 0)
1206 let layoutS (columns
, b) y sh =
1207 let sh = sh - state.hscrollh
in
1208 let rec fold accu n =
1209 if n = Array.length
b
1212 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1219 let x = xoff + state.x in
1220 let pagey = max
0 (y - vy) in
1221 let pagedispy = if pagey > 0 then 0 else vy - y in
1222 let pagedispx, pagex =
1237 let vw = conf.winw
- pagedispx - state.scrollw
in
1238 let pw = pagew
- pagex in
1241 let pagevw = min
pagevw (pagew
/columns
) in
1242 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1243 if pagevw > 0 && pagevh > 0
1246 { pageno
= n/columns
1247 ; pagedimno
= pdimno
1254 ; pagedispx = pagedispx
1255 ; pagedispy = pagedispy
1266 List.rev
(fold [] 0)
1270 if nogeomcmds state.geomcmds
1272 match conf.columns
with
1273 | Csingle
-> layout1 y sh
1274 | Cmulti
c -> layoutN c y sh
1275 | Csplit
s -> layoutS s y sh
1280 let y = state.y + incr
in
1282 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1287 let tilex = l
.pagex mod conf.tilew
in
1288 let tiley = l
.pagey mod conf.tileh
in
1290 let col = l
.pagex / conf.tilew
in
1291 let row = l
.pagey / conf.tileh
in
1293 let rec rowloop row y0 dispy
h =
1297 let dh = conf.tileh
- y0 in
1298 let dh = min
h dh in
1299 let rec colloop col x0 dispx w
=
1303 let dw = conf.tilew
- x0 in
1304 let dw = min w
dw in
1306 f col row dispx dispy
x0 y0 dw dh;
1307 colloop (col+1) 0 (dispx+dw) (w
-dw)
1310 colloop col tilex l
.pagedispx l
.pagevw;
1311 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1314 if l
.pagevw > 0 && l
.pagevh > 0
1315 then rowloop row tiley l
.pagedispy l
.pagevh;
1318 let gettileopaque l
col row =
1320 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1322 try Some
(Hashtbl.find
state.tilemap
key)
1323 with Not_found
-> None
1326 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1327 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1328 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1331 let drawtiles l color
=
1333 let f col row x y tilex tiley w
h =
1334 match gettileopaque l
col row with
1335 | Some
(opaque
, _
, t
) ->
1336 let params = x, y, w
, h, tilex, tiley in
1340 GlFunc.blend_func `zero `one_minus_src_color
;
1342 drawtile
params opaque
;
1344 then Gl.disable `blend
;
1347 let s = Printf.sprintf
1351 let w = measurestr
fstate.fontsize
s in
1352 GlMisc.push_attrib
[`current
];
1353 GlDraw.color
(0.0, 0.0, 0.0);
1355 (float (x-2), float (y-2))
1356 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1357 GlDraw.color
(1.0, 1.0, 1.0);
1358 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1359 GlMisc.pop_attrib
();
1364 let lw = conf.winw
- state.scrollw
- x in
1367 let lh = conf.winh
- y in
1370 Gl.enable `texture_2d
;
1371 begin match state.texid
with
1373 GlTex.bind_texture `texture_2d id
;
1376 and x1 = float (x+w)
1377 and y1 = float (y+h) in
1379 let tw = float w /. 64.0
1380 and th
= float h /. 64.0 in
1381 let tx0 = float tilex /. 64.0
1382 and ty0
= float tiley /. 64.0 in
1384 and ty1
= ty0
+. th
in
1385 GlDraw.begins `quads
;
1386 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1387 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1388 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1389 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1392 Gl.disable `texture_2d
;
1394 GlDraw.color
(1.0, 1.0, 1.0);
1397 (float (x+w), float (y+h));
1399 if w > 128 && h > fstate.fontsize
+ 10
1401 GlDraw.color
(0.0, 0.0, 0.0);
1404 then (col*conf.tilew
, row*conf.tileh
)
1407 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1414 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1416 let tilevisible1 l
x y =
1418 and ax1
= l
.pagex + l
.pagevw
1420 and ay1
= l
.pagey + l
.pagevh in
1424 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1425 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1427 let rx0 = max
ax0 bx0
1428 and ry0
= max ay0 by0
1429 and rx1
= min ax1
bx1
1430 and ry1
= min ay1 by1
in
1432 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1433 nonemptyintersection
1436 let tilevisible layout n x y =
1437 let rec findpageinlayout m
= function
1438 | l
:: rest
when l
.pageno
= n ->
1439 tilevisible1 l
x y || (
1440 match conf.columns
with
1441 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1444 | _
:: rest
-> findpageinlayout 0 rest
1447 findpageinlayout 0 layout;
1450 let tileready l
x y =
1451 tilevisible1 l
x y &&
1452 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1455 let tilepage n p
layout =
1456 let rec loop = function
1460 let f col row _ _ _ _ _ _
=
1461 if state.currently
= Idle
1463 match gettileopaque l
col row with
1466 let x = col*conf.tilew
1467 and y = row*conf.tileh
in
1469 let w = l
.pagew
- x in
1473 let h = l
.pageh
- y in
1476 wcmd "tile %s %d %d %d %d" p
x y w h;
1479 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1480 conf.tilew
, conf.tileh
1489 if nogeomcmds state.geomcmds
1493 let preloadlayout visiblepages
=
1494 let presentation = conf.presentation in
1495 let interpagespace = conf.interpagespace in
1496 let maxy = state.maxy in
1497 conf.presentation <- false;
1498 conf.interpagespace <- 0;
1499 state.maxy <- calcheight ();
1501 match visiblepages
with
1503 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1505 let y = if y < conf.winh
then 0 else y - conf.winh
in
1506 let h = state.y - y + conf.winh
*3 in
1507 let pages = layout y h in
1508 conf.presentation <- presentation;
1509 conf.interpagespace <- interpagespace;
1515 let rec loop pages =
1516 if state.currently
!= Idle
1521 begin match getopaque l
.pageno
with
1523 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1524 state.currently
<- Loading
(l
, state.gen
);
1526 tilepage l
.pageno opaque
pages;
1531 if nogeomcmds state.geomcmds
1537 if conf.preload && state.currently
= Idle
1538 then load (preloadlayout pages);
1541 let layoutready layout =
1542 let rec fold all ls
=
1543 all
&& match ls
with
1545 let seen = ref false in
1546 let allvisible = ref true in
1547 let foo col row _ _ _ _ _ _
=
1549 allvisible := !allvisible &&
1550 begin match gettileopaque l
col row with
1556 fold (!seen && !allvisible) rest
1559 let alltilesvisible = fold true layout in
1564 let y = bound y 0 state.maxy in
1565 let y, layout, proceed
=
1566 match conf.maxwait
with
1567 | Some time
when state.ghyll
== noghyll ->
1568 begin match state.throttle
with
1570 let layout = layout y conf.winh
in
1571 let ready = layoutready layout in
1575 state.throttle
<- Some
(layout, y, now ());
1577 else G.postRedisplay "gotoy showall (None)";
1579 | Some
(_
, _
, started
) ->
1580 let dt = now () -. started
in
1583 state.throttle
<- None
;
1584 let layout = layout y conf.winh
in
1586 G.postRedisplay "maxwait";
1593 let layout = layout y conf.winh
in
1594 if true || layoutready layout
1595 then G.postRedisplay "gotoy ready";
1601 state.layout <- layout;
1602 begin match state.mode
with
1603 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1604 let rec loop = function
1606 state.mode
<- LinkNav
(Ltgendir
0)
1607 | l
:: _
when l
.pageno
= pageno
->
1608 begin match getopaque pageno
with
1610 state.mode
<- LinkNav
(Ltgendir
0)
1612 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1613 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1614 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1615 then state.mode
<- LinkNav
(Ltgendir
0)
1617 | _
:: rest
-> loop rest
1622 begin match state.mode
with
1623 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1624 if not
(pagevisible layout pageno
)
1626 match state.layout with
1629 state.mode
<- Birdseye
(
1630 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1633 | LinkNav
(Ltgendir dir
as lt
) ->
1635 let rec loop = function
1638 match getopaque l
.pageno
with
1644 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1646 if dir
> 0 then LDfirst
else LDlast
1652 | Lnotfound
-> loop rest
1654 showlinktype (getlink opaque
n);
1655 Ltexact
(l
.pageno
, n)
1659 state.mode
<- LinkNav
linknav
1664 state.ghyll
<- noghyll;
1667 let mx, my
= state.mpos
in
1672 let conttiling pageno opaque
=
1673 tilepage pageno opaque
1674 (if conf.preload then preloadlayout state.layout else state.layout)
1677 let gotoy_and_clear_text y =
1678 if not
conf.verbose
then state.text <- "";
1683 match state.layout with
1685 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1688 let getanchory (n, top
) =
1689 let y, h = getpageyh n in
1690 y + (truncate
(top
*. float h));
1693 let gotoanchor anchor
=
1694 gotoy (getanchory anchor
);
1698 cbput state.hists
.nav
(getanchor ());
1702 let anchor = cbgetc state.hists
.nav dir
in
1707 let rec scroll f n a
b =
1708 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1710 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1712 then s (float f /. float a
)
1715 then 1.0 -. s ((float (f-b) /. float (n-b)))
1722 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1723 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1725 let ins = float a
*. iv1
1726 and outs
= float (n-b) *. iv1 in
1728 ins +. outs
+. float ones
1730 let rec set (_N
, _A
, _B
) y sy
=
1731 let sum = summa
1.0 _N _A _B
in
1732 let dy = float (y - sy
) in
1736 then state.ghyll
<- noghyll
1739 let s = scroll n _N _A _B
in
1740 let y1 = y1 +. ((s *. dy) /. sum) in
1741 gotoy_and_clear_text (truncate
y1);
1742 state.ghyll
<- gf (n+1) y1;
1746 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1748 gf 0 (float state.y)
1751 match conf.ghyllscroll
with
1753 gotoy_and_clear_text y
1755 if state.ghyll
== noghyll
1756 then set nab
y state.y
1757 else state.ghyll
(Some
y)
1760 let gotopage n top
=
1761 let y, h = getpageyh n in
1762 let y = y + (truncate
(top
*. float h)) in
1766 let gotopage1 n top
=
1767 let y = getpagey n in
1772 let invalidate s f =
1777 match state.geomcmds
with
1778 | ps
, [] when String.length ps
= 0 ->
1780 state.geomcmds
<- s, [];
1783 state.geomcmds
<- ps
, [s, f];
1785 | ps
, (s'
, _
) :: rest
when s'
= s ->
1786 state.geomcmds
<- ps
, ((s, f) :: rest
);
1789 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1792 let opendoc path password
=
1794 state.password
<- password
;
1795 state.gen
<- state.gen
+ 1;
1796 state.docinfo
<- [];
1798 setaalevel
conf.aalevel
;
1799 Wsi.settitle
("llpp " ^
Filename.basename path
);
1800 wcmd "open %s\000%s\000" path password
;
1801 invalidate "reqlayout"
1803 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1807 let c = c *. conf.colorscale
in
1811 let scalecolor2 (r
, g
, b) =
1812 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1816 let docolumns = function
1819 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1820 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1821 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1822 if pageno
= state.pagecount
1825 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1827 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1828 pdimno+1, pdim
, rest
1833 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1835 (conf.winw
- state.scrollw
- w) / 2,
1836 y + rowh
+ conf.interpagespace, h
1839 if (pageno
- coverA
) mod columns
= 0
1840 then 0, y + rowh
+ conf.interpagespace, h
1841 else x, y, max rowh
h
1844 let rec fixrow m
= if m
= pageno
then () else
1845 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1848 let y = y + (rowh
- h) / 2 in
1849 a.(m
) <- (pdimno, x, y, pdim
);
1853 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1854 then fixrow (pageno
- columns
);
1855 a.(pageno
) <- (pdimno, x, y, pdim
);
1856 let x = x + w + xoff*2 + conf.interpagespace in
1857 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1859 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1860 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1863 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1864 let rec loop pageno
pdimno pdim
y pdims
=
1865 if pageno
= state.pagecount
1868 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1870 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1871 pdimno+1, pdim
, rest
1876 let rec loop1 n x y =
1877 if n = c then y else (
1878 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1879 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1882 let y = loop1 0 0 y in
1883 loop (pageno
+1) pdimno pdim
y pdims
1885 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1886 conf.columns
<- Csplit
(c, a);
1888 docolumns conf.columns
;
1889 state.maxy <- calcheight ();
1891 if state.w <= conf.winw
- state.scrollw
1895 match state.mode
with
1896 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1897 let y, h = getpageyh pageno
in
1898 let top = (conf.winh
- h) / 2 in
1899 gotoy (max
0 (y - top))
1900 | _
-> gotoanchor state.anchor
1904 GlDraw.viewport
0 0 w h;
1905 let firsttime = state.geomcmds
== firstgeomcmds in
1906 if not
firsttime && nogeomcmds state.geomcmds
1907 then state.anchor <- getanchor ();
1910 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1913 setfontsize fstate.fontsize
;
1914 GlMat.mode `modelview
;
1915 GlMat.load_identity
();
1917 GlMat.mode `projection
;
1918 GlMat.load_identity
();
1919 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1920 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1921 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1926 else float state.x /. float state.w
1928 invalidate "geometry"
1932 then state.x <- truncate
(relx *. float w);
1934 match conf.columns
with
1936 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1937 | Csplit
(c, _
) -> w * c
1939 wcmd "geometry %d %d" w h);
1943 let len = String.length
state.text in
1946 match state.mode
with
1948 | View
-> state.hscrollh
1953 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1954 (x+.w, float (conf.winh
- hscrollh))
1957 let w = float (conf.winw
- state.scrollw
- 1) in
1958 if state.progress
>= 0.0 && state.progress
< 1.0
1960 GlDraw.color
(0.3, 0.3, 0.3);
1961 let w1 = w *. state.progress
in
1963 GlDraw.color
(0.0, 0.0, 0.0);
1967 GlDraw.color
(0.0, 0.0, 0.0);
1971 GlDraw.color
(1.0, 1.0, 1.0);
1972 drawstring fstate.fontsize
1973 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1976 match state.mode
with
1977 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1981 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1983 Printf.sprintf
"%s%s_" prefix
text
1992 if not
(istextentry state.mode
)
1994 let s1 = "(press 'e' to review error messasges)" in
1995 if String.length
s > 0 then s ^
" " ^
s1 else s1
2000 if String.length
s > 0
2005 let len = Queue.length
state.tilelru
in
2007 if state.memused
<= conf.memlimit
2012 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2013 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2014 let (_
, pw, ph
, _
) = getpagedim n in
2017 && colorspace
= conf.colorspace
2018 && angle
= conf.angle
2023 match state.throttle
with
2026 then preloadlayout state.layout
2028 | Some
(layout, _
, _
) ->
2031 let x = col*conf.tilew
2032 and y = row*conf.tileh
in
2033 tilevisible layout n x y
2035 then Queue.push lruitem
state.tilelru
2037 wcmd "freetile %s" p
;
2038 state.memused
<- state.memused
- s;
2039 state.uioh#infochanged Memused
;
2040 Hashtbl.remove
state.tilemap k
;
2049 Queue.iter
(fun (k
, p
, s) ->
2050 wcmd "freetile %s" p
;
2051 state.memused
<- state.memused
- s;
2052 state.uioh#infochanged Memused
;
2053 Hashtbl.remove
state.tilemap k
;
2055 Queue.clear
state.tilelru
;
2059 let logcurrently = function
2060 | Idle
-> dolog "Idle"
2061 | Loading
(l
, gen
) ->
2062 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2063 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2065 "Tiling %d[%d,%d] page=%s cs=%s angle"
2066 l
.pageno
col row pageopaque
2067 (colorspace_to_string colorspace
)
2069 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2070 angle gen
conf.angle
state.gen
2072 conf.tilew
conf.tileh
2079 (* dolog "%S" cmds; *)
2082 try String.index cmds ' '
2083 with Not_found
-> -1
2088 let l = String.length cmds
in
2089 let op = String.sub cmds
0 spacepos in
2091 if l - spacepos < 2 then ""
2092 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2097 state.uioh#infochanged Pdim
;
2101 state.rects
<- state.rects1
;
2102 G.postRedisplay "clearrects";
2106 try Scanf.sscanf
args "%u" (fun n -> n)
2108 dolog "error processing 'continue' %S: %s"
2109 cmds
(Printexc.to_string exn
);
2112 state.pagecount
<- n;
2113 begin match state.currently
with
2115 state.currently
<- Idle
;
2116 state.outlines
<- Array.of_list
(List.rev
l)
2120 let cur, cmds
= state.geomcmds
in
2121 if String.length
cur = 0
2122 then failwith
"umpossible";
2124 begin match List.rev cmds
with
2126 state.geomcmds
<- "", [];
2130 state.geomcmds
<- s, List.rev rest
;
2132 if conf.maxwait
= None
2133 then G.postRedisplay "continue";
2143 then showtext ' '
args
2146 let progress, text =
2148 Scanf.sscanf
args "%f %n"
2150 f, String.sub
args pos
(String.length
args - pos
))
2152 dolog "error processing 'progress' %S: %s"
2153 cmds
(Printexc.to_string exn
);
2157 state.progress <- progress;
2158 G.postRedisplay "progress"
2161 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2163 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2164 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2165 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2167 dolog "error processing 'firstmatch' %S: %s"
2168 cmds
(Printexc.to_string exn
);
2171 let y = (getpagey pageno) + truncate
y0 in
2174 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2177 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2179 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2180 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2181 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2183 dolog "error processing 'match' %S: %s"
2184 cmds
(Printexc.to_string exn
);
2188 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2193 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2195 dolog "error processing 'page' %S: %s"
2196 cmds
(Printexc.to_string exn
);
2199 begin match state.currently
with
2200 | Loading
(l, gen
) ->
2201 vlog "page %d took %f sec" l.pageno t
;
2202 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2203 begin match state.throttle
with
2205 let preloadedpages =
2207 then preloadlayout state.layout
2212 Set.Make
(struct type t
= int let compare = (-) end) in
2214 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2215 IntSet.empty
preloadedpages
2218 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2219 if not
(IntSet.mem
pageno set)
2221 wcmd "freepage %s" opaque
;
2227 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2230 state.currently
<- Idle
;
2233 tilepage l.pageno pageopaque state.layout;
2235 load preloadedpages;
2236 if pagevisible state.layout l.pageno
2237 && layoutready state.layout
2238 then G.postRedisplay "page";
2241 | Some
(layout, _
, _
) ->
2242 state.currently
<- Idle
;
2243 tilepage l.pageno pageopaque layout;
2248 dolog "Inconsistent loading state";
2249 logcurrently state.currently
;
2254 let (x, y, opaque
, size
, t
) =
2256 Scanf.sscanf
args "%u %u %s %u %f"
2257 (fun x y p size t
-> (x, y, p
, size
, t
))
2259 dolog "error processing 'tile' %S: %s"
2260 cmds
(Printexc.to_string exn
);
2263 begin match state.currently
with
2264 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2265 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2267 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2269 wcmd "freetile %s" opaque
;
2270 state.currently
<- Idle
;
2274 puttileopaque l col row gen cs angle opaque size t
;
2275 state.memused
<- state.memused
+ size
;
2276 state.uioh#infochanged Memused
;
2278 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2279 opaque
, size
) state.tilelru
;
2282 match state.throttle
with
2283 | None
-> state.layout
2284 | Some
(layout, _
, _
) -> layout
2287 state.currently
<- Idle
;
2289 && conf.colorspace
= cs
2290 && conf.angle
= angle
2291 && tilevisible layout l.pageno x y
2292 then conttiling l.pageno pageopaque;
2294 begin match state.throttle
with
2296 preload state.layout;
2298 && conf.colorspace
= cs
2299 && conf.angle
= angle
2300 && tilevisible state.layout l.pageno x y
2301 then G.postRedisplay "tile nothrottle";
2303 | Some
(layout, y, _
) ->
2304 let ready = layoutready layout in
2308 state.layout <- layout;
2309 state.throttle
<- None
;
2310 G.postRedisplay "throttle";
2317 dolog "Inconsistent tiling state";
2318 logcurrently state.currently
;
2325 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2327 dolog "error processing 'pdim' %S: %s"
2328 cmds
(Printexc.to_string exn
);
2331 state.uioh#infochanged Pdim
;
2332 state.pdims
<- pdim :: state.pdims
2335 let (l, n, t
, h, pos
) =
2337 Scanf.sscanf
args "%u %u %d %u %n"
2338 (fun l n t
h pos
-> l, n, t
, h, pos
)
2340 dolog "error processing 'o' %S: %s"
2341 cmds
(Printexc.to_string exn
);
2344 let s = String.sub
args pos
(String.length
args - pos
) in
2345 let outline = (s, l, (n, float t
/. float h)) in
2346 begin match state.currently
with
2347 | Outlining outlines
->
2348 state.currently
<- Outlining
(outline :: outlines
)
2350 state.currently
<- Outlining
[outline]
2352 dolog "invalid outlining state";
2353 logcurrently currently
2357 state.docinfo
<- (1, args) :: state.docinfo
2360 state.uioh#infochanged Docinfo
;
2361 state.docinfo
<- List.rev
state.docinfo
2364 dolog "unknown cmd `%S'" cmds
2369 let action = function
2370 | HCprev
-> cbget cb ~
-1
2371 | HCnext
-> cbget cb
1
2372 | HCfirst
-> cbget cb ~
-(cb
.rc)
2373 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2374 and cancel
() = cb
.rc <- rc
2378 let search pattern forward
=
2379 if String.length pattern
> 0
2382 match state.layout with
2385 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2387 wcmd "search %d %d %d %d,%s\000"
2388 (btod conf.icase
) pn py (btod forward
) pattern
;
2391 let intentry text key =
2393 if key >= 32 && key < 127
2399 let text = addchar text c in
2403 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2407 let textentry text key =
2408 if key land 0xff00 = 0xff00
2410 else TEcont
(text ^
Wsi.toutf8
key)
2413 let reqlayout angle proportional
=
2414 match state.throttle
with
2416 if nogeomcmds state.geomcmds
2417 then state.anchor <- getanchor ();
2418 conf.angle
<- angle
mod 360;
2421 match state.mode
with
2422 | LinkNav _
-> state.mode
<- View
2425 conf.proportional
<- proportional
;
2426 invalidate "reqlayout"
2427 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2431 let settrim trimmargins trimfuzz
=
2432 if nogeomcmds state.geomcmds
2433 then state.anchor <- getanchor ();
2434 conf.trimmargins
<- trimmargins
;
2435 conf.trimfuzz
<- trimfuzz
;
2436 let x0, y0, x1, y1 = trimfuzz
in
2437 invalidate "settrim"
2439 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2440 Hashtbl.iter
(fun _ opaque
->
2441 wcmd "freepage %s" opaque
;
2443 Hashtbl.clear
state.pagemap
;
2447 match state.throttle
with
2449 let zoom = max
0.01 zoom in
2450 if zoom <> conf.zoom
2452 state.prevzoom
<- conf.zoom;
2454 reshape conf.winw
conf.winh
;
2455 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2458 | Some
(layout, y, started
) ->
2460 match conf.maxwait
with
2464 let dt = now () -. started
in
2472 let setcolumns mode columns coverA coverB
=
2476 then showtext '
!'
"split mode doesn't work in bird's eye"
2478 conf.columns
<- Csplit
(-columns
, [||]);
2486 conf.columns
<- Csingle
;
2491 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2495 reshape conf.winw
conf.winh
;
2498 let enterbirdseye () =
2499 let zoom = float conf.thumbw
/. float conf.winw
in
2500 let birdseyepageno =
2501 let cy = conf.winh
/ 2 in
2505 let rec fold best
= function
2508 let d = cy - (l.pagedispy + l.pagevh/2)
2509 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2510 if abs
d < abs dbest
2517 state.mode
<- Birdseye
(
2518 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2521 conf.presentation <- false;
2522 conf.interpagespace <- 10;
2523 conf.hlinks
<- false;
2525 state.mstate
<- Mnone
;
2526 conf.maxwait
<- None
;
2528 match conf.beyecolumns
with
2531 Cmulti
((c, 0, 0), [||])
2534 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2537 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2542 reshape conf.winw
conf.winh
;
2545 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2547 conf.zoom <- c.zoom;
2548 conf.presentation <- c.presentation;
2549 conf.interpagespace <- c.interpagespace;
2550 conf.maxwait
<- c.maxwait
;
2551 conf.hlinks
<- c.hlinks
;
2552 conf.beyecolumns
<- (
2553 match conf.columns
with
2554 | Cmulti
((c, _
, _
), _
) -> Some
c
2556 | Csplit _
-> assert false
2559 match c.columns
with
2560 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2561 | Csingle
-> Csingle
2562 | Csplit _
-> failwith
"leaving bird's eye split mode"
2567 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2570 reshape conf.winw
conf.winh
;
2571 state.anchor <- if goback
then anchor else (pageno, 0.0);
2574 let togglebirdseye () =
2575 match state.mode
with
2576 | Birdseye vals
-> leavebirdseye vals
true
2577 | View
-> enterbirdseye ()
2581 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2582 let pageno = max
0 (pageno - incr
) in
2583 let rec loop = function
2584 | [] -> gotopage1 pageno 0
2585 | l :: _
when l.pageno = pageno ->
2586 if l.pagedispy >= 0 && l.pagey = 0
2587 then G.postRedisplay "upbirdseye"
2588 else gotopage1 pageno 0
2589 | _
:: rest
-> loop rest
2592 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2595 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2596 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2597 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2598 let rec loop = function
2600 let y, h = getpageyh pageno in
2601 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2603 | l :: _
when l.pageno = pageno ->
2604 if l.pagevh != l.pageh
2605 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2606 else G.postRedisplay "downbirdseye"
2607 | _
:: rest
-> loop rest
2612 let optentry mode _
key =
2613 let btos b = if b then "on" else "off" in
2614 if key >= 32 && key < 127
2616 let c = Char.chr
key in
2620 try conf.scrollstep
<- int_of_string
s with exc
->
2621 state.text <- Printf.sprintf
"bad integer `%s': %s"
2622 s (Printexc.to_string exc
)
2624 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2629 conf.autoscrollstep
<- int_of_string
s;
2630 if state.autoscroll
<> None
2631 then state.autoscroll
<- Some
conf.autoscrollstep
2633 state.text <- Printf.sprintf
"bad integer `%s': %s"
2634 s (Printexc.to_string exc
)
2636 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2639 let mode = state.mode in
2642 let n, a, b = multicolumns_of_string s in
2643 setcolumns mode n a b;
2645 state.text <- Printf.sprintf
"bad columns `%s': %s"
2646 s (Printexc.to_string exc
)
2648 TEswitch
("columns: ", "", None
, textentry, ondone)
2653 let zoom = float (int_of_string
s) /. 100.0 in
2656 state.text <- Printf.sprintf
"bad integer `%s': %s"
2657 s (Printexc.to_string exc
)
2659 TEswitch
("zoom: ", "", None
, intentry, ondone)
2664 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2666 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2667 begin match mode with
2669 leavebirdseye beye
false;
2674 state.text <- Printf.sprintf
"bad integer `%s': %s"
2675 s (Printexc.to_string exc
)
2677 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2682 Some
(int_of_string
s)
2684 state.text <- Printf.sprintf
"bad integer `%s': %s"
2685 s (Printexc.to_string exc
);
2688 | Some angle
-> reqlayout angle
conf.proportional
2691 TEswitch
("rotation: ", "", None
, intentry, ondone)
2694 conf.icase
<- not
conf.icase
;
2695 TEdone
("case insensitive search " ^
(btos conf.icase
))
2698 conf.preload <- not
conf.preload;
2700 TEdone
("preload " ^
(btos conf.preload))
2703 conf.verbose
<- not
conf.verbose
;
2704 TEdone
("verbose " ^
(btos conf.verbose
))
2707 conf.debug
<- not
conf.debug
;
2708 TEdone
("debug " ^
(btos conf.debug
))
2711 conf.maxhfit
<- not
conf.maxhfit
;
2713 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2714 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2717 conf.crophack
<- not
conf.crophack
;
2718 TEdone
("crophack " ^
btos conf.crophack
)
2722 match conf.maxwait
with
2724 conf.maxwait
<- Some infinity
;
2725 "always wait for page to complete"
2727 conf.maxwait
<- None
;
2728 "show placeholder if page is not ready"
2733 conf.underinfo
<- not
conf.underinfo
;
2734 TEdone
("underinfo " ^
btos conf.underinfo
)
2737 conf.savebmarks
<- not
conf.savebmarks
;
2738 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2744 match state.layout with
2749 conf.interpagespace <- int_of_string
s;
2750 state.maxy <- calcheight ();
2751 let y = getpagey pageno in
2754 state.text <- Printf.sprintf
"bad integer `%s': %s"
2755 s (Printexc.to_string exc
)
2757 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2760 reqlayout conf.angle
(not
conf.proportional
);
2761 TEdone
("proportional display " ^
btos conf.proportional
)
2764 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2765 TEdone
("trim margins " ^
btos conf.trimmargins
)
2768 conf.invert
<- not
conf.invert
;
2769 TEdone
("invert colors " ^
btos conf.invert
)
2773 cbput state.hists
.sel
s;
2776 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2780 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2786 class type lvsource
= object
2787 method getitemcount
: int
2788 method getitem
: int -> (string * int)
2789 method hasaction
: int -> bool
2798 method getactive
: int
2799 method getfirst
: int
2800 method getqsearch
: string
2801 method setqsearch
: string -> unit
2805 class virtual lvsourcebase
= object
2806 val mutable m_active
= 0
2807 val mutable m_first
= 0
2808 val mutable m_qsearch
= ""
2809 val mutable m_pan
= 0
2810 method getactive
= m_active
2811 method getfirst
= m_first
2812 method getqsearch
= m_qsearch
2813 method getpan
= m_pan
2814 method setqsearch
s = m_qsearch
<- s
2817 let withoutlastutf8 s =
2818 let len = String.length
s in
2826 let b = Char.code
s.[pos
] in
2827 if b land 0b110000 = 0b11000000
2832 if Char.code
s.[len-1] land 0x80 = 0
2836 String.sub
s 0 first;
2839 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2841 state.mode <- Textentry
(te
, onleave
);
2844 G.postRedisplay "textentrykeyboard enttext";
2846 let histaction cmd
=
2849 | Some
(action, _
) ->
2850 state.mode <- Textentry
(
2851 (c, action cmd
, opthist
, onkey
, ondone), onleave
2853 G.postRedisplay "textentry histaction"
2856 | 0xff08 -> (* backspace *)
2857 let s = withoutlastutf8 text in
2858 let len = String.length
s in
2862 G.postRedisplay "textentrykeyboard after cancel";
2865 enttext (c, s, opthist
, onkey
, ondone)
2871 G.postRedisplay "textentrykeyboard after confirm"
2873 | 0xff52 -> histaction HCprev
2874 | 0xff54 -> histaction HCnext
2875 | 0xff50 -> histaction HCfirst
2876 | 0xff57 -> histaction HClast
2878 | 0xff1b -> (* escape*)
2879 if String.length
text = 0
2881 begin match opthist
with
2883 | Some
(_
, onhistcancel
) -> onhistcancel
()
2887 G.postRedisplay "textentrykeyboard after cancel2"
2890 enttext (c, "", opthist
, onkey
, ondone)
2893 | 0xff9f | 0xffff -> () (* delete *)
2895 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2896 begin match onkey
text key with
2900 G.postRedisplay "textentrykeyboard after confirm2";
2903 enttext (c, text, opthist
, onkey
, ondone);
2907 G.postRedisplay "textentrykeyboard after cancel3"
2910 state.mode <- Textentry
(te
, onleave
);
2911 G.postRedisplay "textentrykeyboard switch";
2915 vlog "unhandled key %s" (Wsi.keyname
key)
2918 let firstof first active
=
2919 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2920 then max
0 (active
- (fstate.maxrows
/2))
2924 let calcfirst first active
=
2927 let rows = active
- first in
2928 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2932 let scrollph y maxy =
2933 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2934 let sh = float conf.winh
/. sh in
2935 let sh = max
sh (float conf.scrollh
) in
2940 else float y /. float maxy
2942 let position = (float conf.winh
-. sh) *. percent in
2945 if position +. sh > float conf.winh
2946 then float conf.winh
-. sh
2952 let coe s = (s :> uioh
);;
2954 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2956 val m_pan
= source#getpan
2957 val m_first
= source#getfirst
2958 val m_active
= source#getactive
2959 val m_qsearch
= source#getqsearch
2960 val m_prev_uioh
= state.uioh
2962 method private elemunder
y =
2963 let n = y / (fstate.fontsize
+1) in
2964 if m_first
+ n < source#getitemcount
2966 if source#hasaction
(m_first
+ n)
2967 then Some
(m_first
+ n)
2974 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2975 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2976 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2977 GlDraw.color
(1., 1., 1.);
2978 Gl.enable `texture_2d
;
2979 let fs = fstate.fontsize
in
2981 let ww = fstate.wwidth
in
2982 let tabw = 30.0*.ww in
2983 let itemcount = source#getitemcount
in
2985 if (row - m_first
) * nfs > conf.winh
2988 if row >= 0 && row < itemcount
2990 let (s, level
) = source#getitem
row in
2991 let y = (row - m_first
) * nfs in
2992 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2995 Gl.disable `texture_2d
;
2996 GlDraw.polygon_mode `both `line
;
2997 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2998 GlDraw.rect (1., float (y + 1))
2999 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3000 GlDraw.polygon_mode `both `fill
;
3001 GlDraw.color
(1., 1., 1.);
3002 Gl.enable `texture_2d
;
3005 let drawtabularstring s =
3006 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3009 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3012 let len = String.length
s - tabpos - 1 in
3013 let s1 = String.sub
s 0 tabpos
3014 and s2
= String.sub
s (tabpos + 1) len in
3015 let nx = drawstr x s1 in
3017 let x = x +. (max
tabw sw) in
3024 let _ = drawtabularstring s in
3031 Gl.disable `texture_2d
;
3033 method updownlevel incr
=
3034 let len = source#getitemcount
in
3036 if m_active
>= 0 && m_active
< len
3037 then snd
(source#getitem m_active
)
3041 if i
= len then i
-1 else if i
= -1 then 0 else
3042 let _, l = source#getitem i
in
3043 if l != curlevel then i
else flow (i
+incr
)
3045 let active = flow m_active
in
3046 let first = calcfirst m_first
active in
3047 G.postRedisplay "outline updownlevel";
3048 {< m_active
= active; m_first
= first >}
3050 method private key1
key mask
=
3051 let set1 active first qsearch
=
3052 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3054 let search active pattern incr
=
3057 if n >= 0 && n < source#getitemcount
3059 let s, _ = source#getitem
n in
3061 (try ignore
(Str.search_forward
re s 0); true
3062 with Not_found
-> false)
3064 else loop (n + incr
)
3071 let re = Str.regexp_case_fold pattern
in
3077 let itemcount = source#getitemcount
in
3078 let find start incr
=
3080 if i
= -1 || i
= itemcount
3083 if source#hasaction i
3085 else find (i
+ incr
)
3090 let set active first =
3091 let first = bound first 0 (itemcount - fstate.maxrows
) in
3093 coe {< m_active
= active; m_first
= first >}
3096 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3098 let incr1 = if incr
> 0 then 1 else -1 in
3099 if isvisible m_first m_active
3102 let next = m_active
+ incr
in
3104 if next < 0 || next >= itemcount
3106 else find next incr1
3108 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3114 let first = m_first
+ incr
in
3115 let first = bound first 0 (itemcount - 1) in
3117 let next = m_active
+ incr
in
3118 let next = bound next 0 (itemcount - 1) in
3121 let active = if next = -1 then m_active
else next in
3124 let first = min
next m_first
in
3126 if abs
(next - first) > fstate.maxrows
3132 let first = m_first
+ incr
in
3133 let first = bound first 0 (itemcount - 1) in
3135 let next = m_active
+ incr
in
3136 let next = bound next 0 (itemcount - 1) in
3137 let next = find next incr1 in
3139 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3141 let active = if m_active
= -1 then next else m_active
in
3146 if isvisible first active
3152 G.postRedisplay "listview navigate";
3156 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3157 let incr = if key = 0x72 then -1 else 1 in
3159 match search (m_active
+ incr) m_qsearch
incr with
3161 state.text <- m_qsearch ^
" [not found]";
3164 state.text <- m_qsearch
;
3165 active, firstof m_first
active
3167 G.postRedisplay "listview ctrl-r/s";
3168 set1 active first m_qsearch
;
3170 | 0xff08 -> (* backspace *)
3171 if String.length m_qsearch
= 0
3174 let qsearch = withoutlastutf8 m_qsearch
in
3175 let len = String.length
qsearch in
3179 G.postRedisplay "listview empty qsearch";
3180 set1 m_active m_first
"";
3184 match search m_active
qsearch ~
-1 with
3186 state.text <- qsearch ^
" [not found]";
3189 state.text <- qsearch;
3190 active, firstof m_first
active
3192 G.postRedisplay "listview backspace qsearch";
3193 set1 active first qsearch
3196 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3197 let pattern = m_qsearch ^
Wsi.toutf8
key in
3199 match search m_active
pattern 1 with
3201 state.text <- pattern ^
" [not found]";
3204 state.text <- pattern;
3205 active, firstof m_first
active
3207 G.postRedisplay "listview qsearch add";
3208 set1 active first pattern;
3210 | 0xff1b -> (* escape *)
3212 if String.length m_qsearch
= 0
3214 G.postRedisplay "list view escape";
3217 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3219 | None
-> m_prev_uioh
3224 G.postRedisplay "list view kill qsearch";
3225 source#setqsearch
"";
3226 coe {< m_qsearch
= "" >}
3229 | 0xff0d -> (* return *)
3231 let self = {< m_qsearch
= "" >} in
3232 source#setqsearch
"";
3234 G.postRedisplay "listview enter";
3235 if m_active
>= 0 && m_active
< source#getitemcount
3237 source#exit
(coe self) false m_active m_first m_pan
"";
3240 source#exit
(coe self) true m_active m_first m_pan
"";
3243 begin match opt with
3244 | None
-> m_prev_uioh
3248 | 0xff9f | 0xffff -> (* delete *)
3251 | 0xff52 -> navigate ~
-1 (* up *)
3252 | 0xff54 -> navigate 1 (* down *)
3253 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3254 | 0xff56 -> navigate fstate.maxrows
(* next *)
3256 | 0xff53 -> (* right *)
3258 G.postRedisplay "listview right";
3259 coe {< m_pan
= m_pan
- 1 >}
3261 | 0xff51 -> (* left *)
3263 G.postRedisplay "listview left";
3264 coe {< m_pan
= m_pan
+ 1 >}
3266 | 0xff50 -> (* home *)
3267 let active = find 0 1 in
3268 G.postRedisplay "listview home";
3271 | 0xff57 -> (* end *)
3272 let first = max
0 (itemcount - fstate.maxrows
) in
3273 let active = find (itemcount - 1) ~
-1 in
3274 G.postRedisplay "listview end";
3277 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3281 dolog "listview unknown key %#x" key; coe self
3283 method key key mask
=
3284 match state.mode with
3285 | Textentry te
-> textentrykeyboard key mask te
; coe self
3286 | _ -> self#key1
key mask
3288 method button button down
x y _ =
3291 | 1 when x > conf.winw
- conf.scrollbw
->
3292 G.postRedisplay "listview scroll";
3295 let _, position, sh = self#
scrollph in
3296 if y > truncate
position && y < truncate
(position +. sh)
3298 state.mstate
<- Mscrolly
;
3302 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3303 let first = truncate
(s *. float source#getitemcount
) in
3304 let first = min source#getitemcount
first in
3305 Some
(coe {< m_first
= first; m_active
= first >})
3307 state.mstate
<- Mnone
;
3310 | 1 when not down
->
3311 begin match self#elemunder
y with
3313 G.postRedisplay "listview click";
3315 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3319 | n when (n == 4 || n == 5) && not down
->
3320 let len = source#getitemcount
in
3322 if n = 5 && m_first
+ fstate.maxrows
>= len
3326 let first = m_first
+ (if n == 4 then -1 else 1) in
3327 bound first 0 (len - 1)
3329 G.postRedisplay "listview wheel";
3330 Some
(coe {< m_first
= first >})
3335 | None
-> m_prev_uioh
3339 match state.mstate
with
3341 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3342 let first = truncate
(s *. float source#getitemcount
) in
3343 let first = min source#getitemcount
first in
3344 G.postRedisplay "listview motion";
3345 coe {< m_first
= first; m_active
= first >}
3348 method pmotion
x y =
3349 if x < conf.winw
- conf.scrollbw
3352 match self#elemunder
y with
3353 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3354 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3358 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3363 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3367 method infochanged
_ = ()
3369 method scrollpw
= (0, 0.0, 0.0)
3371 let nfs = fstate.fontsize
+ 1 in
3372 let y = m_first
* nfs in
3373 let itemcount = source#getitemcount
in
3374 let maxi = max
0 (itemcount - fstate.maxrows
) in
3375 let maxy = maxi * nfs in
3376 let p, h = scrollph y maxy in
3379 method modehash
= modehash
3382 class outlinelistview ~source
=
3385 ~source
:(source
:> lvsource
)
3387 ~modehash
:(findkeyhash conf "outline")
3390 method key key mask
=
3391 let calcfirst first active =
3394 let rows = active - first in
3395 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3399 let active = m_active
+ incr in
3400 let active = bound active 0 (source#getitemcount
- 1) in
3401 let first = calcfirst m_first
active in
3402 G.postRedisplay "outline navigate";
3403 coe {< m_active
= active; m_first
= first >}
3405 let ctrl = Wsi.withctrl mask
in
3407 | 110 when ctrl -> (* ctrl-n *)
3408 source#narrow m_qsearch
;
3409 G.postRedisplay "outline ctrl-n";
3410 coe {< m_first
= 0; m_active
= 0 >}
3412 | 117 when ctrl -> (* ctrl-u *)
3414 G.postRedisplay "outline ctrl-u";
3416 coe {< m_first
= 0; m_active
= 0 >}
3418 | 108 when ctrl -> (* ctrl-l *)
3419 let first = m_active
- (fstate.maxrows
/ 2) in
3420 G.postRedisplay "outline ctrl-l";
3421 coe {< m_first
= first >}
3423 | 0xff9f | 0xffff -> (* delete *)
3424 source#remove m_active
;
3425 G.postRedisplay "outline delete";
3426 let active = max
0 (m_active
-1) in
3427 coe {< m_first
= firstof m_first
active;
3428 m_active
= active >}
3430 | 0xff52 -> navigate ~
-1 (* up *)
3431 | 0xff54 -> navigate 1 (* down *)
3432 | 0xff55 -> (* prior *)
3433 navigate ~
-(fstate.maxrows
)
3434 | 0xff56 -> (* next *)
3435 navigate fstate.maxrows
3437 | 0xff53 -> (* [ctrl-]right *)
3441 G.postRedisplay "outline ctrl right";
3442 {< m_pan
= m_pan
+ 1 >}
3444 else self#updownlevel
1
3448 | 0xff51 -> (* [ctrl-]left *)
3452 G.postRedisplay "outline ctrl left";
3453 {< m_pan
= m_pan
- 1 >}
3455 else self#updownlevel ~
-1
3459 | 0xff50 -> (* home *)
3460 G.postRedisplay "outline home";
3461 coe {< m_first
= 0; m_active
= 0 >}
3463 | 0xff57 -> (* end *)
3464 let active = source#getitemcount
- 1 in
3465 let first = max
0 (active - fstate.maxrows
) in
3466 G.postRedisplay "outline end";
3467 coe {< m_active
= active; m_first
= first >}
3469 | _ -> super#
key key mask
3472 let outlinesource usebookmarks
=
3475 inherit lvsourcebase
3476 val mutable m_items
= empty
3477 val mutable m_orig_items
= empty
3478 val mutable m_prev_items
= empty
3479 val mutable m_narrow_pattern
= ""
3480 val mutable m_hadremovals
= false
3482 method getitemcount
=
3483 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3486 if n == Array.length m_items
&& m_hadremovals
3488 ("[Confirm removal]", 0)
3490 let s, n, _ = m_items
.(n) in
3493 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3494 ignore
(uioh
, first, qsearch);
3495 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3497 if String.length m_narrow_pattern
= 0
3503 if not
confrimremoval
3505 let _, _, anchor = m_items
.(active) in
3510 state.bookmarks
<- Array.to_list m_items
;
3511 m_orig_items
<- m_items
;
3514 else m_items
<- items;
3518 method hasaction
_ = true
3521 if Array.length m_items
!= Array.length m_orig_items
3522 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3525 method narrow
pattern =
3526 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3530 let rec loop accu n =
3533 m_narrow_pattern
<- pattern;
3534 m_items
<- Array.of_list
accu
3537 let (s, _, _) as o = m_items
.(n) in
3539 if (try ignore
(Str.search_forward
re s 0); true
3540 with Not_found
-> false)
3546 loop [] (Array.length m_items
- 1)
3551 then Array.of_list
state.bookmarks
3554 m_items
<- m_orig_items
3559 if m
>= 0 && m
< Array.length m_items
3561 m_hadremovals
<- true;
3562 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3563 let n = if n >= m
then n+1 else n in
3568 method reset
anchor items =
3569 m_hadremovals
<- false;
3570 if m_orig_items
== empty || m_prev_items
!= items
3572 m_orig_items
<- items;
3573 if String.length m_narrow_pattern
= 0
3574 then m_items
<- items;
3576 m_prev_items
<- items;
3577 let rely = getanchory anchor in
3579 let rec loop n best bestd
=
3580 if n = Array.length m_items
3583 let (_, _, anchor) = m_items
.(n) in
3584 let orely = getanchory anchor in
3585 let d = abs
(orely - rely) in
3588 else loop (n+1) best bestd
3593 m_first
<- firstof m_first
active
3597 let enterselector usebookmarks
=
3598 let source = outlinesource usebookmarks
in
3602 then Array.of_list
state.bookmarks
3605 if Array.length
outlines = 0
3607 showtext ' ' errmsg
;
3610 state.text <- source#greetmsg
;
3611 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3612 let anchor = getanchor () in
3613 source#reset
anchor outlines;
3614 state.uioh
<- coe (new outlinelistview ~
source);
3615 G.postRedisplay "enter selector";
3619 let enteroutlinemode =
3620 let f = enterselector false in
3621 fun ()-> f "Document has no outline";
3624 let enterbookmarkmode =
3625 let f = enterselector true in
3626 fun () -> f "Document has no bookmarks (yet)";
3629 let color_of_string s =
3630 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3631 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3635 let color_to_string (r
, g
, b) =
3636 let r = truncate
(r *. 256.0)
3637 and g
= truncate
(g
*. 256.0)
3638 and b = truncate
(b *. 256.0) in
3639 Printf.sprintf
"%d/%d/%d" r g
b
3642 let irect_of_string s =
3643 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3646 let irect_to_string (x0,y0,x1,y1) =
3647 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3650 let makecheckers () =
3651 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3653 converted by Issac Trotts. July 25, 2002 *)
3654 let image_height = 64
3655 and image_width
= 64 in
3659 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3661 for i
= 0 to image_width
- 1 do
3662 for j
= 0 to image_height - 1 do
3663 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3664 (if (i
land 8 ) lxor (j
land 8) = 0
3665 then [|255;255;255|] else [|200;200;200|])
3670 let image = make_image () in
3671 let id = GlTex.gen_texture
() in
3672 GlTex.bind_texture `texture_2d
id;
3673 GlPix.store
(`unpack_alignment
1);
3674 GlTex.image2d
image;
3675 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3678 `mag_filter `nearest
;
3679 `min_filter `nearest
];
3683 let setcheckers enabled
=
3684 match state.texid
with
3686 if enabled
then state.texid
<- Some
(makecheckers ())
3691 GlTex.delete_texture texid
;
3692 state.texid
<- None
;
3696 let int_of_string_with_suffix s =
3697 let l = String.length
s in
3701 let suffix = Char.lowercase
s.[l-1] in
3703 | 'k'
-> String.sub
s 0 (l-1), 10
3704 | 'm'
-> String.sub
s 0 (l-1), 20
3705 | 'g'
-> String.sub
s 0 (l-1), 30
3709 let n = int_of_string
s1 in
3710 let m = n lsl shift
in
3712 then raise
(Failure
"value too large")
3716 let string_with_suffix_of_int n =
3724 if n land ((1 lsl 20) - 1) = 0
3727 if n land ((1 lsl 10) - 1) = 0
3734 let h = n mod 1000 in
3737 then string_of_int
h ^
s
3739 let s = Printf.sprintf
"_%03d%s" h s in
3746 let defghyllscroll = (40, 8, 32);;
3747 let ghyllscroll_of_string s =
3748 let (n, a, b) as nab
=
3751 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3753 if n <= a || n <= b || a >= b
3754 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3758 let ghyllscroll_to_string ((n, a, b) as nab
) =
3759 if nab
= defghyllscroll
3761 else Printf.sprintf
"%d,%d,%d" n a b;
3764 let describe_location () =
3766 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3768 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3769 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3773 else (100. *. (float state.y /. float maxy))
3777 Printf.sprintf
"page %d of %d [%.2f%%]"
3778 (fn+1) state.pagecount
percent
3781 "pages %d-%d of %d [%.2f%%]"
3782 (fn+1) (ln
+1) state.pagecount
percent
3786 let btos b = if b then "\xe2\x88\x9a" else "" in
3787 let showextended = ref false in
3788 let leave mode = function
3789 | Confirm
-> state.mode <- mode
3790 | Cancel
-> state.mode <- mode in
3793 val mutable m_first_time
= true
3794 val mutable m_l
= []
3795 val mutable m_a
= [||]
3796 val mutable m_prev_uioh
= nouioh
3797 val mutable m_prev_mode
= View
3799 inherit lvsourcebase
3801 method reset prev_mode prev_uioh
=
3802 m_a
<- Array.of_list
(List.rev m_l
);
3804 m_prev_mode
<- prev_mode
;
3805 m_prev_uioh
<- prev_uioh
;
3809 if n >= Array.length m_a
3813 | _, _, _, Action
_ -> m_active
<- n
3817 m_first_time
<- false;
3820 method int name get
set =
3822 (name
, `
int get
, 1, Action
(
3825 try set (int_of_string
s)
3827 state.text <- Printf.sprintf
"bad integer `%s': %s"
3828 s (Printexc.to_string exn
)
3831 let te = name ^
": ", "", None
, intentry, ondone in
3832 state.mode <- Textentry
(te, leave m_prev_mode
);
3836 method int_with_suffix name get
set =
3838 (name
, `intws get
, 1, Action
(
3841 try set (int_of_string_with_suffix s)
3843 state.text <- Printf.sprintf
"bad integer `%s': %s"
3844 s (Printexc.to_string exn
)
3848 name ^
": ", "", None
, intentry_with_suffix, ondone
3850 state.mode <- Textentry
(te, leave m_prev_mode
);
3854 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3856 (name
, `
bool (btos, get
), offset
, Action
(
3863 method color name get
set =
3865 (name
, `color get
, 1, Action
(
3867 let invalid = (nan
, nan
, nan
) in
3870 try color_of_string s
3872 state.text <- Printf.sprintf
"bad color `%s': %s"
3873 s (Printexc.to_string exn
);
3879 let te = name ^
": ", "", None
, textentry, ondone in
3880 state.text <- color_to_string (get
());
3881 state.mode <- Textentry
(te, leave m_prev_mode
);
3885 method string name get
set =
3887 (name
, `
string get
, 1, Action
(
3889 let ondone s = set s in
3890 let te = name ^
": ", "", None
, textentry, ondone in
3891 state.mode <- Textentry
(te, leave m_prev_mode
);
3895 method colorspace name get
set =
3897 (name
, `
string get
, 1, Action
(
3900 let vals = [| "rgb"; "bgr"; "gray" |] in
3902 inherit lvsourcebase
3905 m_active
<- int_of_colorspace conf.colorspace
;
3908 method getitemcount
= Array.length
vals
3909 method getitem
n = (vals.(n), 0)
3910 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3911 ignore
(uioh
, first, pan
, qsearch);
3912 if not cancel
then set active;
3914 method hasaction
_ = true
3918 let modehash = findkeyhash conf "info" in
3919 coe (new listview ~
source ~trusted
:true ~
modehash)
3922 method caption
s offset
=
3923 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3925 method caption2
s f offset
=
3926 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3928 method getitemcount
= Array.length m_a
3931 let tostr = function
3932 | `
int f -> string_of_int
(f ())
3933 | `intws
f -> string_with_suffix_of_int (f ())
3935 | `color
f -> color_to_string (f ())
3936 | `
bool (btos, f) -> btos (f ())
3939 let name, t
, offset
, _ = m_a
.(n) in
3940 ((let s = tostr t
in
3941 if String.length
s > 0
3942 then Printf.sprintf
"%s\t%s" name s
3946 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3950 m_qsearch
<- qsearch;
3952 match m_a
.(active) with
3953 | _, _, _, Action
f -> f uioh
3965 method hasaction
n =
3967 | _, _, _, Action
_ -> true
3971 let rec fillsrc prevmode prevuioh
=
3972 let sep () = src#caption
"" 0 in
3973 let colorp name get
set =
3975 (fun () -> color_to_string (get
()))
3978 let c = color_of_string v in
3981 state.text <- Printf.sprintf
"bad color `%s': %s"
3982 v (Printexc.to_string exn
);
3985 let oldmode = state.mode in
3986 let birdseye = isbirdseye state.mode in
3988 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3990 src#
bool "presentation mode"
3991 (fun () -> conf.presentation)
3993 conf.presentation <- v;
3994 state.anchor <- getanchor ();
3997 src#
bool "ignore case in searches"
3998 (fun () -> conf.icase
)
3999 (fun v -> conf.icase
<- v);
4002 (fun () -> conf.preload)
4003 (fun v -> conf.preload <- v);
4005 src#
bool "highlight links"
4006 (fun () -> conf.hlinks
)
4007 (fun v -> conf.hlinks
<- v);
4009 src#
bool "under info"
4010 (fun () -> conf.underinfo
)
4011 (fun v -> conf.underinfo
<- v);
4013 src#
bool "persistent bookmarks"
4014 (fun () -> conf.savebmarks
)
4015 (fun v -> conf.savebmarks
<- v);
4017 src#
bool "proportional display"
4018 (fun () -> conf.proportional
)
4019 (fun v -> reqlayout conf.angle
v);
4021 src#
bool "trim margins"
4022 (fun () -> conf.trimmargins
)
4023 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4025 src#
bool "persistent location"
4026 (fun () -> conf.jumpback
)
4027 (fun v -> conf.jumpback
<- v);
4030 src#
int "inter-page space"
4031 (fun () -> conf.interpagespace)
4033 conf.interpagespace <- n;
4035 match state.layout with
4040 state.maxy <- calcheight ();
4041 let y = getpagey pageno in
4046 (fun () -> conf.pagebias
)
4047 (fun v -> conf.pagebias
<- v);
4049 src#
int "scroll step"
4050 (fun () -> conf.scrollstep
)
4051 (fun n -> conf.scrollstep
<- n);
4053 src#
int "auto scroll step"
4055 match state.autoscroll
with
4057 | _ -> conf.autoscrollstep
)
4059 if state.autoscroll
<> None
4060 then state.autoscroll
<- Some
n;
4061 conf.autoscrollstep
<- n);
4064 (fun () -> truncate
(conf.zoom *. 100.))
4065 (fun v -> setzoom ((float v) /. 100.));
4068 (fun () -> conf.angle
)
4069 (fun v -> reqlayout v conf.proportional
);
4071 src#
int "scroll bar width"
4072 (fun () -> state.scrollw
)
4076 reshape conf.winw
conf.winh
;
4079 src#
int "scroll handle height"
4080 (fun () -> conf.scrollh
)
4081 (fun v -> conf.scrollh
<- v;);
4083 src#
int "thumbnail width"
4084 (fun () -> conf.thumbw
)
4086 conf.thumbw
<- min
4096 v;
4089 leavebirdseye beye
false;
4094 let mode = state.mode in
4095 src#
string "columns"
4097 match conf.columns
with
4099 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4100 | Csplit
(count
, _) -> "-" ^ string_of_int count
4103 let n, a, b = multicolumns_of_string v in
4104 setcolumns mode n a b);
4107 src#caption
"Presentation mode" 0;
4108 src#
bool "scrollbar visible"
4109 (fun () -> conf.scrollbarinpm
)
4111 if v != conf.scrollbarinpm
4113 conf.scrollbarinpm
<- v;
4114 if conf.presentation
4116 state.scrollw
<- if v then conf.scrollbw
else 0;
4117 reshape conf.winw
conf.winh
;
4123 src#caption
"Pixmap cache" 0;
4124 src#int_with_suffix
"size (advisory)"
4125 (fun () -> conf.memlimit
)
4126 (fun v -> conf.memlimit
<- v);
4129 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4130 (string_with_suffix_of_int state.memused
)
4131 (Hashtbl.length
state.tilemap
)) 1;
4134 src#caption
"Layout" 0;
4135 src#caption2
"Dimension"
4137 Printf.sprintf
"%dx%d (virtual %dx%d)"
4143 src#caption2
"Position" (fun () ->
4144 Printf.sprintf
"%dx%d" state.x state.y
4147 src#caption2
"Visible" (fun () -> describe_location ()) 1
4151 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4152 "Save these parameters as global defaults at exit"
4153 (fun () -> conf.bedefault
)
4154 (fun v -> conf.bedefault
<- v)
4158 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4159 src#
bool ~offset
:0 ~
btos "Extended parameters"
4160 (fun () -> !showextended)
4161 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4165 (fun () -> conf.checkers
)
4166 (fun v -> conf.checkers
<- v; setcheckers v);
4167 src#
bool "update cursor"
4168 (fun () -> conf.updatecurs
)
4169 (fun v -> conf.updatecurs
<- v);
4171 (fun () -> conf.verbose
)
4172 (fun v -> conf.verbose
<- v);
4173 src#
bool "invert colors"
4174 (fun () -> conf.invert
)
4175 (fun v -> conf.invert
<- v);
4177 (fun () -> conf.maxhfit
)
4178 (fun v -> conf.maxhfit
<- v);
4179 src#
bool "redirect stderr"
4180 (fun () -> conf.redirectstderr)
4181 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4182 src#
string "uri launcher"
4183 (fun () -> conf.urilauncher
)
4184 (fun v -> conf.urilauncher
<- v);
4185 src#
string "path launcher"
4186 (fun () -> conf.pathlauncher
)
4187 (fun v -> conf.pathlauncher
<- v);
4188 src#
string "tile size"
4189 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4192 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4193 conf.tileh
<- max
64 w;
4194 conf.tilew
<- max
64 h;
4197 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4198 v (Printexc.to_string exn
));
4199 src#
int "texture count"
4200 (fun () -> conf.texcount
)
4203 then conf.texcount
<- v
4204 else showtext '
!'
" Failed to set texture count please retry later"
4206 src#
int "slice height"
4207 (fun () -> conf.sliceheight
)
4209 conf.sliceheight
<- v;
4210 wcmd "sliceh %d" conf.sliceheight
;
4212 src#
int "anti-aliasing level"
4213 (fun () -> conf.aalevel
)
4215 conf.aalevel
<- bound v 0 8;
4216 state.anchor <- getanchor ();
4217 opendoc state.path
state.password
;
4219 src#
int "ui font size"
4220 (fun () -> fstate.fontsize
)
4221 (fun v -> setfontsize (bound v 5 100));
4222 colorp "background color"
4223 (fun () -> conf.bgcolor
)
4224 (fun v -> conf.bgcolor
<- v);
4225 src#
bool "crop hack"
4226 (fun () -> conf.crophack
)
4227 (fun v -> conf.crophack
<- v);
4228 src#
string "trim fuzz"
4229 (fun () -> irect_to_string conf.trimfuzz
)
4232 conf.trimfuzz
<- irect_of_string v;
4234 then settrim true conf.trimfuzz
;
4236 state.text <- Printf.sprintf
"bad irect `%s': %s"
4237 v (Printexc.to_string exn
)
4239 src#
string "throttle"
4241 match conf.maxwait
with
4242 | None
-> "show place holder if page is not ready"
4245 then "wait for page to fully render"
4247 "wait " ^ string_of_float
time
4248 ^
" seconds before showing placeholder"
4252 let f = float_of_string
v in
4254 then conf.maxwait
<- None
4255 else conf.maxwait
<- Some
f
4257 state.text <- Printf.sprintf
"bad time `%s': %s"
4258 v (Printexc.to_string exn
)
4260 src#
string "ghyll scroll"
4262 match conf.ghyllscroll
with
4264 | Some nab
-> ghyllscroll_to_string nab
4269 if String.length
v = 0
4271 else Some
(ghyllscroll_of_string v)
4273 conf.ghyllscroll
<- gs
4275 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4276 v (Printexc.to_string exn
)
4278 src#
string "selection command"
4279 (fun () -> conf.selcmd
)
4280 (fun v -> conf.selcmd
<- v);
4281 src#colorspace
"color space"
4282 (fun () -> colorspace_to_string conf.colorspace
)
4284 conf.colorspace
<- colorspace_of_int v;
4291 src#caption
"Document" 0;
4292 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4293 src#caption2
"Pages"
4294 (fun () -> string_of_int
state.pagecount
) 1;
4295 src#caption2
"Dimensions"
4296 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4300 src#caption
"Trimmed margins" 0;
4301 src#caption2
"Dimensions"
4302 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4305 src#reset prevmode prevuioh
;
4309 let prevmode = state.mode
4310 and prevuioh
= state.uioh in
4311 fillsrc prevmode prevuioh
;
4312 let source = (src :> lvsource
) in
4313 let modehash = findkeyhash conf "info" in
4314 state.uioh <- coe (object (self)
4315 inherit listview ~
source ~trusted
:true ~
modehash as super
4316 val mutable m_prevmemused
= 0
4317 method infochanged
= function
4319 if m_prevmemused
!= state.memused
4321 m_prevmemused
<- state.memused
;
4322 G.postRedisplay "memusedchanged";
4324 | Pdim
-> G.postRedisplay "pdimchanged"
4325 | Docinfo
-> fillsrc prevmode prevuioh
4327 method key key mask
=
4328 if not
(Wsi.withctrl mask
)
4331 | 0xff51 -> coe (self#updownlevel ~
-1)
4332 | 0xff53 -> coe (self#updownlevel
1)
4333 | _ -> super#
key key mask
4334 else super#
key key mask
4336 G.postRedisplay "info";
4342 inherit lvsourcebase
4343 method getitemcount
= Array.length
state.help
4345 let s, n, _ = state.help
.(n) in
4348 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4352 m_qsearch
<- qsearch;
4353 match state.help
.(active) with
4354 | _, _, Action
f -> Some
(f uioh)
4364 method hasaction
n =
4365 match state.help
.(n) with
4366 | _, _, Action
_ -> true
4373 let modehash = findkeyhash conf "help" in
4374 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4375 G.postRedisplay "help";
4380 let re = Str.regexp
"[\r\n]" in
4382 inherit lvsourcebase
4383 val mutable m_items
= [||]
4385 method getitemcount
= 1 + Array.length m_items
4390 else m_items
.(n-1), 0
4392 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4397 then Buffer.clear
state.errmsgs
;
4398 m_qsearch
<- qsearch;
4405 method hasaction
n =
4409 state.newerrmsgs
<- false;
4410 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4411 m_items
<- Array.of_list
l
4419 let source = (msgsource :> lvsource
) in
4420 let modehash = findkeyhash conf "listview" in
4421 state.uioh <- coe (object
4422 inherit listview ~
source ~trusted
:false ~
modehash as super
4425 then msgsource#reset
;
4428 G.postRedisplay "msgs";
4431 let quickbookmark ?title
() =
4432 match state.layout with
4438 let sec = Unix.gettimeofday
() in
4439 let tm = Unix.localtime
sec in
4440 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4444 (tm.Unix.tm_year
+ 1900)
4447 | Some
title -> title
4450 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4455 state.fullscreen
<- None
;
4459 let setautoscrollspeed step goingdown
=
4460 let incr = max
1 ((abs step
) / 2) in
4461 let incr = if goingdown
then incr else -incr in
4462 let astep = step
+ incr in
4463 state.autoscroll
<- Some
astep;
4466 let gotounder = function
4467 | Ulinkgoto
(pageno, top) ->
4471 gotopage1 pageno top;
4477 | Uremote
(filename
, pageno) ->
4479 if Sys.file_exists filename
4482 let dir = Filename.dirname
state.path in
4483 let path = Filename.concat
dir filename
in
4484 if Sys.file_exists
path
4488 if String.length
path > 0
4490 let anchor = getanchor () in
4491 let ranchor = state.path, state.password
, anchor in
4492 state.anchor <- (pageno, 0.0);
4493 state.ranchors
<- ranchor :: state.ranchors
;
4496 else showtext '
!'
("Could not find " ^ filename
)
4498 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4502 match conf.columns
with
4504 | _ -> conf.zoom > 1.0
4507 let viewkeyboard key mask
=
4509 let mode = state.mode in
4510 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4513 G.postRedisplay "view:enttext"
4515 let ctrl = Wsi.withctrl mask
in
4520 | 0xff63 -> (* insert *)
4521 if conf.angle
mod 360 = 0
4523 state.mode <- LinkNav
(Ltgendir
0);
4526 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4528 | 0xff1b | 113 -> (* escape / q *)
4529 begin match state.mstate
with
4531 state.mstate
<- Mnone
;
4532 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4533 G.postRedisplay "kill zoom rect";
4535 match state.ranchors
with
4537 | (path, password
, anchor) :: rest
->
4538 state.ranchors
<- rest
;
4539 state.anchor <- anchor;
4540 opendoc path password
4543 | 0xff08 -> (* backspace *)
4544 let y = getnav ~
-1 in
4545 gotoy_and_clear_text y
4553 G.postRedisplay "dehighlight";
4555 | 47 | 63 -> (* / ? *)
4556 let ondone isforw
s =
4557 cbput state.hists
.pat
s;
4558 state.searchpattern
<- s;
4561 let s = String.create
1 in
4562 s.[0] <- Char.chr
key;
4563 enttext (s, "", Some
(onhist state.hists
.pat
),
4564 textentry, ondone (key = 47))
4566 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4567 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4568 setzoom (conf.zoom +. incr)
4570 | 43 | 0xffab -> (* + *)
4573 try int_of_string
s with exc
->
4574 state.text <- Printf.sprintf
"bad integer `%s': %s"
4575 s (Printexc.to_string exc
);
4581 state.text <- "page bias is now " ^ string_of_int
n;
4584 enttext ("page bias: ", "", None
, intentry, ondone)
4586 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4587 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4588 setzoom (max
0.01 (conf.zoom -. decr))
4590 | 45 | 0xffad -> (* - *)
4591 let ondone msg
= state.text <- msg
in
4593 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4594 optentry state.mode, ondone
4597 | 48 when ctrl -> (* ctrl-0 *)
4600 | 49 when ctrl -> (* 1 *)
4601 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4605 | 0xffc6 -> (* f9 *)
4608 | 57 when ctrl -> (* ctrl-9 *)
4611 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4612 when not
ctrl -> (* 0..9 *)
4615 try int_of_string
s with exc
->
4616 state.text <- Printf.sprintf
"bad integer `%s': %s"
4617 s (Printexc.to_string exc
);
4623 cbput state.hists
.pag
(string_of_int
n);
4624 gotopage1 (n + conf.pagebias
- 1) 0;
4627 let pageentry text key =
4628 match Char.unsafe_chr
key with
4629 | 'g'
-> TEdone
text
4630 | _ -> intentry text key
4632 let text = "x" in text.[0] <- Char.chr
key;
4633 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4636 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4637 reshape conf.winw
conf.winh
;
4640 conf.hlinks
<- not
conf.hlinks
;
4641 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4642 G.postRedisplay "toggle highlightlinks";
4645 state.glinks
<- true;
4646 let a = Char.code '
a'
and z
= Char.code 'z'
in
4649 let rec loop pos
n = if pos
= String.length
s then n else
4650 let m = Char.code
s.[pos
] - a in
4651 loop (pos
+1) (n*(z
-a+1) + m)
4656 let rec loop n = function
4659 match getopaque l.pageno with
4660 | None
-> loop n rest
4662 let m = getlinkcount opaque
in
4665 let under = getlink opaque
n in
4669 else loop (n-m) rest
4671 loop n state.layout;
4674 let onkey text key =
4675 if (key >= a && key <= z
)
4677 let c = Char.unsafe_chr
key in
4678 let text = addchar text c in
4683 let mode = state.mode in
4684 state.mode <- Textentry
(
4685 (":", "", Some
(onhist state.hists
.pag
), onkey, ondone),
4687 state.glinks
<- false;
4691 G.postRedisplay "view:enttext"
4694 begin match state.autoscroll
with
4696 conf.autoscrollstep
<- step
;
4697 state.autoscroll
<- None
4699 if conf.autoscrollstep
= 0
4700 then state.autoscroll
<- Some
1
4701 else state.autoscroll
<- Some
conf.autoscrollstep
4704 | 112 when ctrl -> (* ctrl-p *)
4708 conf.presentation <- not
conf.presentation;
4709 if conf.presentation
4711 if not
conf.scrollbarinpm
4712 then state.scrollw
<- 0;
4715 state.scrollw
<- conf.scrollbw
;
4717 showtext ' '
("presentation mode " ^
4718 if conf.presentation then "on" else "off");
4719 state.anchor <- getanchor ();
4723 begin match state.fullscreen
with
4725 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4728 state.fullscreen
<- None
;
4733 gotoy_and_clear_text 0
4736 gotopage1 (state.pagecount
- 1) 0
4738 | 112 | 78 -> (* p|N *)
4739 search state.searchpattern
false
4741 | 110 | 0xffc0 -> (* n|F3 *)
4742 search state.searchpattern
true
4745 begin match state.layout with
4748 gotoy_and_clear_text (getpagey l.pageno)
4752 begin match List.rev
state.layout with
4755 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4756 gotoy_and_clear_text (getpagey pageno)
4759 | 0xff9f | 0xffff -> (* delete *)
4760 begin match state.layout with
4763 let pageno = max
0 (l.pageno-1) in
4764 gotoy_and_clear_text (getpagey pageno)
4768 showtext ' '
(describe_location ());
4771 begin match state.layout with
4774 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4779 enterbookmarkmode ()
4781 | 104 | 0xffbe -> (* h|F1 *)
4787 | 101 when conf.redirectstderr -> (* e *)
4792 match state.layout with
4795 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4799 enttext ("bookmark: ", "", None
, textentry, ondone)
4803 showtext ' '
"Quick bookmark added";
4806 begin match state.layout with
4808 let rect = getpdimrect
l.pagedimno
in
4812 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4813 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4815 (truncate
(rect.(1) -. rect.(0)),
4816 truncate
(rect.(3) -. rect.(0)))
4818 let w = truncate
((float w)*.conf.zoom)
4819 and h = truncate
((float h)*.conf.zoom) in
4822 state.anchor <- getanchor ();
4823 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4825 G.postRedisplay "z";
4830 | 50 when ctrl -> (* ctrl-2 *)
4831 let maxw = getmaxw
() in
4833 then setzoom (maxw /. float conf.winw
)
4835 | 60 | 62 -> (* < > *)
4836 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4838 | 91 | 93 -> (* [ ] *)
4840 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4842 G.postRedisplay "brightness";
4844 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4845 setzoom state.prevzoom
4847 | 107 | 0xff52 -> (* k up *)
4848 begin match state.autoscroll
with
4850 begin match state.mode with
4851 | Birdseye beye
-> upbirdseye 1 beye
4854 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4855 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4858 setautoscrollspeed n false
4861 | 106 | 0xff54 -> (* j down *)
4862 begin match state.autoscroll
with
4864 begin match state.mode with
4865 | Birdseye beye
-> downbirdseye 1 beye
4868 then gotoy_and_clear_text (clamp (conf.winh
/2))
4869 else gotoy_and_clear_text (clamp conf.scrollstep
)
4872 setautoscrollspeed n true
4875 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4883 let dx = if key = 0xff51 then dx else -dx in
4884 state.x <- state.x + dx;
4885 gotoy_and_clear_text state.y
4888 G.postRedisplay "lef/right"
4891 | 0xff55 -> (* prior *)
4895 match state.layout with
4897 | l :: _ -> state.y - l.pagey
4903 | 0xff56 -> (* next *)
4907 match List.rev
state.layout with
4909 | l :: _ -> getpagey l.pageno
4915 | 0xff50 -> gotoghyll 0
4916 | 0xff57 -> gotoghyll (clamp state.maxy)
4917 | 0xff53 when Wsi.withalt mask
->
4918 gotoghyll (getnav ~
-1)
4919 | 0xff51 when Wsi.withalt mask
->
4920 gotoghyll (getnav 1)
4923 state.anchor <- getanchor ();
4924 opendoc state.path state.password
4926 | 118 when conf.debug
-> (* v *)
4929 match getopaque l.pageno with
4932 let x0, y0, x1, y1 = pagebbox opaque
in
4933 let a,b = float x0, float y0 in
4934 let c,d = float x1, float y0 in
4935 let e,f = float x1, float y1 in
4936 let h,j
= float x0, float y1 in
4937 let rect = (a,b,c,d,e,f,h,j
) in
4939 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4941 G.postRedisplay "v";
4944 vlog "huh? %s" (Wsi.keyname
key)
4947 let linknavkeyboard key mask
linknav =
4948 let getpage pageno =
4949 let rec loop = function
4951 | l :: _ when l.pageno = pageno -> Some
l
4952 | _ :: rest
-> loop rest
4953 in loop state.layout
4955 let doexact (pageno, n) =
4956 match getopaque pageno, getpage pageno with
4957 | Some opaque
, Some
l ->
4960 let under = getlink opaque
n in
4961 G.postRedisplay "link gotounder";
4967 | 0xff50 -> (* home *)
4968 Some
(findlink opaque LDfirst
), -1
4970 | 0xff57 -> (* end *)
4971 Some
(findlink opaque LDlast
), 1
4973 | 0xff51 -> (* left *)
4974 Some
(findlink opaque
(LDleft
n)), -1
4976 | 0xff53 -> (* right *)
4977 Some
(findlink opaque
(LDright
n)), 1
4979 | 0xff52 -> (* up *)
4980 Some
(findlink opaque
(LDup
n)), -1
4982 | 0xff54 -> (* down *)
4983 Some
(findlink opaque
(LDdown
n)), 1
4988 begin match findpwl
l.pageno dir with
4992 state.mode <- LinkNav
(Ltgendir
dir);
4993 let y, h = getpageyh pageno in
4996 then y + h - conf.winh
5001 begin match getopaque pageno, getpage pageno with
5002 | Some opaque
, Some
_ ->
5004 let ld = if dir > 0 then LDfirst
else LDlast
in
5007 begin match link with
5009 showlinktype (getlink opaque
m);
5010 state.mode <- LinkNav
(Ltexact
(pageno, m));
5011 G.postRedisplay "linknav jpage";
5018 begin match opt with
5019 | Some Lnotfound
-> pwl l dir;
5020 | Some
(Lfound
m) ->
5024 let _, y0, _, y1 = getlinkrect opaque
m in
5026 then gotopage1 l.pageno y0
5028 let d = fstate.fontsize
+ 1 in
5029 if y1 - l.pagey > l.pagevh - d
5030 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5031 else G.postRedisplay "linknav";
5033 showlinktype (getlink opaque
m);
5034 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5037 | None
-> viewkeyboard key mask
5039 | _ -> viewkeyboard key mask
5044 G.postRedisplay "leave linknav"
5048 | Ltgendir
_ -> viewkeyboard key mask
5049 | Ltexact exact
-> doexact exact
5052 let keyboard key mask
=
5053 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5054 then wcmd "interrupt"
5055 else state.uioh <- state.uioh#
key key mask
5058 let birdseyekeyboard key mask
5059 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5061 match conf.columns
with
5063 | Cmulti
((c, _, _), _) -> c
5064 | Csplit
_ -> failwith
"bird's eye split mode"
5067 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5068 let y, h = getpageyh pageno in
5069 let top = (conf.winh
- h) / 2 in
5070 gotoy (max
0 (y - top))
5071 | 0xff0d -> leavebirdseye beye
false
5072 | 0xff1b -> leavebirdseye beye
true (* escape *)
5073 | 0xff52 -> upbirdseye incr beye
(* prior *)
5074 | 0xff54 -> downbirdseye incr beye
(* next *)
5075 | 0xff51 -> upbirdseye 1 beye
(* up *)
5076 | 0xff53 -> downbirdseye 1 beye
(* down *)
5079 begin match state.layout with
5083 state.mode <- Birdseye
(
5084 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5086 gotopage1 l.pageno 0;
5089 let layout = layout (state.y-conf.winh
) conf.winh
in
5091 | [] -> gotoy (clamp (-conf.winh
))
5093 state.mode <- Birdseye
(
5094 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5096 gotopage1 l.pageno 0
5099 | [] -> gotoy (clamp (-conf.winh
))
5103 begin match List.rev
state.layout with
5105 let layout = layout (state.y + conf.winh
) conf.winh
in
5106 begin match layout with
5108 let incr = l.pageh
- l.pagevh in
5113 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5115 G.postRedisplay "birdseye pagedown";
5117 else gotoy (clamp (incr + conf.interpagespace*2));
5121 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5122 gotopage1 l.pageno 0;
5125 | [] -> gotoy (clamp conf.winh
)
5129 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5133 let pageno = state.pagecount
- 1 in
5134 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5135 if not
(pagevisible state.layout pageno)
5138 match List.rev
state.pdims
with
5140 | (_, _, h, _) :: _ -> h
5142 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5143 else G.postRedisplay "birdseye end";
5144 | _ -> viewkeyboard key mask
5147 let drawpage l linkindexbase
=
5149 match state.mode with
5150 | Textentry
_ -> scalecolor 0.4
5152 | View
-> scalecolor 1.0
5153 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5154 if l.pageno = hooverpageno
5157 if l.pageno = pageno
5163 begin match getopaque l.pageno with
5165 if tileready l l.pagex l.pagey
5167 let x = l.pagedispx - l.pagex
5168 and y = l.pagedispy - l.pagey in
5169 let hlmask = (if conf.hlinks
then 1 else 0)
5170 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5172 postprocess opaque
hlmask x y linkindexbase
;
5179 let scrollindicator () =
5180 let sbw, ph
, sh = state.uioh#
scrollph in
5181 let sbh, pw, sw = state.uioh#scrollpw
in
5183 GlDraw.color (0.64, 0.64, 0.64);
5185 (float (conf.winw
- sbw), 0.)
5186 (float conf.winw
, float conf.winh
)
5189 (0., float (conf.winh
- sbh))
5190 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5192 GlDraw.color (0.0, 0.0, 0.0);
5195 (float (conf.winw
- sbw), ph
)
5196 (float conf.winw
, ph
+. sh)
5199 (pw, float (conf.winh
- sbh))
5200 (pw +. sw, float conf.winh
)
5205 match state.mstate
with
5206 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5209 | Msel
((x0, y0), (x1, y1)) ->
5210 let rec loop = function
5212 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5213 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5214 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5215 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5217 match getopaque l.pageno with
5219 let x0, y0 = pagetranslatepoint l x0 y0 in
5220 let x1, y1 = pagetranslatepoint l x1 y1 in
5221 seltext opaque
(x0, y0, x1, y1);
5229 let showrects rects
=
5231 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5232 GlDraw.polygon_mode `both `fill
;
5233 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5235 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5237 if l.pageno = pageno
5239 let dx = float (l.pagedispx - l.pagex) in
5240 let dy = float (l.pagedispy - l.pagey) in
5241 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5242 GlDraw.begins `quads
;
5244 GlDraw.vertex2
(x0+.dx, y0+.dy);
5245 GlDraw.vertex2
(x1+.dx, y1+.dy);
5246 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5247 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5258 GlClear.color (scalecolor2 conf.bgcolor
);
5259 GlClear.clear
[`
color];
5260 let rec loop linkindexbase
= function
5262 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5263 loop linkindexbase rest
5266 loop 0 state.layout;
5268 match state.mode with
5269 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5270 begin match getopaque pageno with
5272 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5279 | None
-> state.rects
5286 begin match state.mstate
with
5287 | Mzoomrect
((x0, y0), (x1, y1)) ->
5289 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5290 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5291 GlDraw.rect (float x0, float y0)
5292 (float x1, float y1);
5301 let zoomrect x y x1 y1 =
5304 and y0 = min
y y1 in
5305 gotoy (state.y + y0);
5306 state.anchor <- getanchor ();
5307 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5309 if state.w < conf.winw
- state.scrollw
5310 then (conf.winw
- state.scrollw
- state.w) / 2
5313 state.x <- (state.x + margin) - x0;
5315 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5316 state.mstate
<- Mnone
;
5320 let winw = conf.winw - state.scrollw
- 1 in
5321 let s = float x /. float winw in
5322 let destx = truncate
(float (state.w + winw) *. s) in
5323 state.x <- winw - destx;
5324 gotoy_and_clear_text state.y;
5325 state.mstate
<- Mscrollx
;
5329 let s = float y /. float conf.winh
in
5330 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5331 gotoy_and_clear_text desty;
5332 state.mstate
<- Mscrolly
;
5335 let viewmouse button down
x y mask
=
5337 | n when (n == 4 || n == 5) && not down
->
5338 if Wsi.withctrl mask
5340 match state.mstate
with
5341 | Mzoom
(oldn
, i
) ->
5349 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5351 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5353 let zoom = conf.zoom -. incr in
5355 state.mstate
<- Mzoom
(n, 0);
5357 state.mstate
<- Mzoom
(n, i
+1);
5359 else state.mstate
<- Mzoom
(n, 0)
5361 | _ -> state.mstate
<- Mzoom
(n, 0)
5364 match state.autoscroll
with
5365 | Some step
-> setautoscrollspeed step
(n=4)
5369 then -conf.scrollstep
5370 else conf.scrollstep
5372 let incr = incr * 2 in
5373 let y = clamp incr in
5374 gotoy_and_clear_text y
5377 | 1 when Wsi.withctrl mask
->
5380 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5381 state.mstate
<- Mpan
(x, y)
5384 state.mstate
<- Mnone
5389 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5391 state.mstate
<- Mzoomrect
(p, p)
5394 match state.mstate
with
5395 | Mzoomrect
((x0, y0), _) ->
5396 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5397 then zoomrect x0 y0 x y
5399 state.mstate
<- Mnone
;
5400 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5401 G.postRedisplay "kill accidental zoom rect";
5404 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5405 state.mstate
<- Mnone
5408 | 1 when x > conf.winw - state.scrollw
->
5411 let _, position, sh = state.uioh#
scrollph in
5412 if y > truncate
position && y < truncate
(position +. sh)
5413 then state.mstate
<- Mscrolly
5416 state.mstate
<- Mnone
5418 | 1 when y > conf.winh
- state.hscrollh ->
5421 let _, position, sw = state.uioh#scrollpw
in
5422 if x > truncate
position && x < truncate
(position +. sw)
5423 then state.mstate
<- Mscrollx
5426 state.mstate
<- Mnone
5429 let dest = if down
then getunder x y else Unone
in
5430 begin match dest with
5434 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5437 | Unone
when down
->
5438 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5439 state.mstate
<- Mpan
(x, y);
5441 | Unone
| Utext
_ ->
5444 if conf.angle
mod 360 = 0
5446 state.mstate
<- Msel
((x, y), (x, y));
5447 G.postRedisplay "mouse select";
5451 match state.mstate
with
5454 | Mzoom
_ | Mscrollx
| Mscrolly
->
5455 state.mstate
<- Mnone
5457 | Mzoomrect
((x0, y0), _) ->
5461 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5462 state.mstate
<- Mnone
5464 | Msel
((_, y0), (_, y1)) ->
5465 let rec loop = function
5468 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5469 || ((y1 >= l.pagedispy
5470 && y1 <= (l.pagedispy + l.pagevh)))
5472 match getopaque l.pageno with
5476 try Some
(Unix.pipe
())
5478 dolog "can not create sel pipe: %s"
5479 (Printexc.to_string exn
);
5484 let doclose what fd
=
5487 dolog "%s close failed: %s"
5488 what
(Printexc.to_string exn
)
5493 G.postRedisplay "copysel"
5496 popen conf.selcmd
[r, 0; w, -1];
5499 dolog "can not exectute %S: %s"
5500 conf.selcmd
(Printexc.to_string exn
);
5508 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5509 state.mstate
<- Mnone
;
5516 let birdseyemouse button down
x y mask
5517 (conf, leftx
, _, hooverpageno
, anchor) =
5520 let rec loop = function
5523 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5524 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5526 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5532 | _ -> viewmouse button down
x y mask
5535 let mouse button down
x y mask
=
5536 state.uioh <- state.uioh#button button down
x y mask
;
5540 state.uioh <- state.uioh#
motion x y
5544 state.uioh <- state.uioh#
pmotion x y;
5550 method key key mask
=
5551 begin match state.mode with
5552 | Textentry
textentry -> textentrykeyboard key mask
textentry
5553 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5554 | View
-> viewkeyboard key mask
5555 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5559 method button button bstate
x y mask
=
5560 begin match state.mode with
5562 | View
-> viewmouse button bstate
x y mask
5563 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5569 begin match state.mode with
5571 | View
| Birdseye
_ | LinkNav
_ ->
5572 match state.mstate
with
5573 | Mzoom
_ | Mnone
-> ()
5578 state.mstate
<- Mpan
(x, y);
5580 then state.x <- state.x + dx;
5582 gotoy_and_clear_text y
5585 state.mstate
<- Msel
(a, (x, y));
5586 G.postRedisplay "motion select";
5589 let y = min
conf.winh
(max
0 y) in
5593 let x = min
conf.winw (max
0 x) in
5596 | Mzoomrect
(p0
, _) ->
5597 state.mstate
<- Mzoomrect
(p0
, (x, y));
5598 G.postRedisplay "motion zoomrect";
5602 method pmotion x y =
5603 begin match state.mode with
5604 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5605 let rec loop = function
5607 if hooverpageno
!= -1
5609 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5610 G.postRedisplay "pmotion birdseye no hoover";
5613 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5614 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5616 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5617 G.postRedisplay "pmotion birdseye hoover";
5627 match state.mstate
with
5628 | Mnone
-> updateunder x y
5629 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5634 method infochanged
_ = ()
5637 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5638 let p, h = scrollph state.y maxy in
5642 let winw = conf.winw - state.scrollw
- 1 in
5643 let fwinw = float winw in
5645 let sw = fwinw /. float state.w in
5646 let sw = fwinw *. sw in
5647 max
sw (float conf.scrollh
)
5650 let f = state.w+winw in
5651 let r = float (winw-state.x) /. float f in
5652 let p = fwinw *. r in
5656 if position +. sw > fwinw
5657 then fwinw -. position
5660 state.hscrollh, position, sw
5664 match state.mode with
5665 | LinkNav
_ -> "links"
5666 | Textentry
_ -> "textentry"
5667 | Birdseye
_ -> "birdseye"
5670 findkeyhash conf modename
5677 let fontpath = ref "";;
5680 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5683 let l = String.length
s in
5684 let b = Buffer.create
l in
5690 try Sys.getenv
"HOME"
5693 ("Can not determine home directory location: " ^
5694 Printexc.to_string exn
);
5698 let modifier_of_string = function
5699 | "alt" -> Wsi.altmask
5700 | "shift" -> Wsi.shiftmask
5701 | "ctrl" | "control" -> Wsi.ctrlmask
5702 | "meta" -> Wsi.metamask
5707 let r = Str.regexp
"-" in
5709 let elems = Str.full_split
r s in
5712 let m1 = modifier_of_string s in
5714 then (Wsi.namekey
s, m)
5717 | Str.Delim
s when n land 1 = 0 -> g s
5719 | Str.Delim
_ -> (k
, m)
5721 let rec loop n k
m = function
5724 let k, m = f n k m x in
5730 let keys_of_string =
5731 let r = Str.regexp
"[ \t]" in
5733 let elems = Str.split
r s in
5734 List.map
key_of_string elems
5737 let copykeyhashes c =
5738 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5741 let config_of c attrs
=
5745 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5746 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5747 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5748 | "preload" -> { c with preload = bool_of_string
v }
5749 | "page-bias" -> { c with pagebias
= int_of_string
v }
5750 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5751 | "auto-scroll-step" ->
5752 { c with autoscrollstep
= max
0 (int_of_string
v) }
5753 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5754 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5757 match String.lowercase
v with
5758 | "true" -> Some infinity
5760 | f -> Some
(float_of_string
f)
5762 { c with maxwait
= mw}
5763 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5764 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5765 | "vertical-margin" ->
5766 { c with interpagespace = max
0 (int_of_string
v) }
5768 let zoom = float_of_string
v /. 100. in
5769 let zoom = max
zoom 0.0 in
5770 { c with zoom = zoom }
5771 | "presentation" -> { c with presentation = bool_of_string
v }
5772 | "rotation-angle" -> { c with angle
= int_of_string
v }
5773 | "width" -> { c with winw = max
20 (int_of_string
v) }
5774 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5775 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5776 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5777 | "pixmap-cache-size" ->
5778 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5779 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5780 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5781 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5782 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5783 | "background-color" -> { c with bgcolor
= color_of_string v }
5784 | "scrollbar-in-presentation" ->
5785 { c with scrollbarinpm
= bool_of_string
v }
5786 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5787 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5788 | "mupdf-store-size" ->
5789 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5790 | "checkers" -> { c with checkers
= bool_of_string
v }
5791 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5792 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5793 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5794 | "uri-launcher" -> { c with urilauncher
= unent v }
5795 | "path-launcher" -> { c with pathlauncher
= unent v }
5796 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5797 | "invert-colors" -> { c with invert
= bool_of_string
v }
5798 | "brightness" -> { c with colorscale
= float_of_string
v }
5799 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5801 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5803 let (n, _, _) as nab
= multicolumns_of_string v in
5805 then { c with columns
= Csplit
(-n, [||]) }
5806 else { c with columns
= Cmulti
(nab
, [||]) }
5807 | "birds-eye-columns" ->
5808 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5809 | "selection-command" -> { c with selcmd
= unent v }
5810 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5813 prerr_endline
("Error processing attribute (`" ^
5814 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5817 let rec fold c = function
5820 let c = apply c k v in
5823 fold { c with keyhashes
= copykeyhashes c } attrs
;
5826 let fromstring f pos
n v d =
5829 dolog "Error processing attribute (%S=%S) at %d\n%s"
5830 n v pos
(Printexc.to_string exn
)
5835 let bookmark_of attrs
=
5836 let rec fold title page
rely = function
5837 | ("title", v) :: rest
-> fold v page
rely rest
5838 | ("page", v) :: rest
-> fold title v rely rest
5839 | ("rely", v) :: rest
-> fold title page
v rest
5840 | _ :: rest
-> fold title page
rely rest
5841 | [] -> title, page
, rely
5843 fold "invalid" "0" "0" attrs
5847 let rec fold path page
rely pan
= function
5848 | ("path", v) :: rest
-> fold v page
rely pan rest
5849 | ("page", v) :: rest
-> fold path v rely pan rest
5850 | ("rely", v) :: rest
-> fold path page
v pan rest
5851 | ("pan", v) :: rest
-> fold path page
rely v rest
5852 | _ :: rest
-> fold path page
rely pan rest
5853 | [] -> path, page
, rely, pan
5855 fold "" "0" "0" "0" attrs
5859 let rec fold rs ls
= function
5860 | ("out", v) :: rest
-> fold v ls rest
5861 | ("in", v) :: rest
-> fold rs
v rest
5862 | _ :: rest
-> fold ls rs rest
5868 let setconf dst
src =
5869 dst
.scrollbw
<- src.scrollbw
;
5870 dst
.scrollh
<- src.scrollh
;
5871 dst
.icase
<- src.icase
;
5872 dst
.preload <- src.preload;
5873 dst
.pagebias
<- src.pagebias
;
5874 dst
.verbose
<- src.verbose
;
5875 dst
.scrollstep
<- src.scrollstep
;
5876 dst
.maxhfit
<- src.maxhfit
;
5877 dst
.crophack
<- src.crophack
;
5878 dst
.autoscrollstep
<- src.autoscrollstep
;
5879 dst
.maxwait
<- src.maxwait
;
5880 dst
.hlinks
<- src.hlinks
;
5881 dst
.underinfo
<- src.underinfo
;
5882 dst
.interpagespace <- src.interpagespace;
5883 dst
.zoom <- src.zoom;
5884 dst
.presentation <- src.presentation;
5885 dst
.angle
<- src.angle
;
5886 dst
.winw <- src.winw;
5887 dst
.winh
<- src.winh
;
5888 dst
.savebmarks
<- src.savebmarks
;
5889 dst
.memlimit
<- src.memlimit
;
5890 dst
.proportional
<- src.proportional
;
5891 dst
.texcount
<- src.texcount
;
5892 dst
.sliceheight
<- src.sliceheight
;
5893 dst
.thumbw
<- src.thumbw
;
5894 dst
.jumpback
<- src.jumpback
;
5895 dst
.bgcolor
<- src.bgcolor
;
5896 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5897 dst
.tilew
<- src.tilew
;
5898 dst
.tileh
<- src.tileh
;
5899 dst
.mustoresize
<- src.mustoresize
;
5900 dst
.checkers
<- src.checkers
;
5901 dst
.aalevel
<- src.aalevel
;
5902 dst
.trimmargins
<- src.trimmargins
;
5903 dst
.trimfuzz
<- src.trimfuzz
;
5904 dst
.urilauncher
<- src.urilauncher
;
5905 dst
.colorspace
<- src.colorspace
;
5906 dst
.invert
<- src.invert
;
5907 dst
.colorscale
<- src.colorscale
;
5908 dst
.redirectstderr <- src.redirectstderr;
5909 dst
.ghyllscroll
<- src.ghyllscroll
;
5910 dst
.columns
<- src.columns
;
5911 dst
.beyecolumns
<- src.beyecolumns
;
5912 dst
.selcmd
<- src.selcmd
;
5913 dst
.updatecurs
<- src.updatecurs
;
5914 dst
.pathlauncher
<- src.pathlauncher
;
5915 dst
.keyhashes
<- copykeyhashes src;
5919 let h = Hashtbl.create
10 in
5920 let dc = { defconf with angle
= defconf.angle
} in
5921 let rec toplevel v t spos
_ =
5923 | Vdata
| Vcdata
| Vend
-> v
5924 | Vopen
("llppconfig", _, closed
) ->
5927 else { v with f = llppconfig
}
5929 error
"unexpected subelement at top level" s spos
5930 | Vclose
_ -> error
"unexpected close at top level" s spos
5932 and llppconfig
v t spos
_ =
5934 | Vdata
| Vcdata
-> v
5935 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5936 | Vopen
("defaults", attrs
, closed
) ->
5937 let c = config_of dc attrs
in
5941 else { v with f = defaults
}
5943 | Vopen
("ui-font", attrs
, closed
) ->
5944 let rec getsize size
= function
5946 | ("size", v) :: rest
->
5948 fromstring int_of_string spos
"size" v fstate.fontsize
in
5950 | l -> getsize size l
5952 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5955 else { v with f = uifont
(Buffer.create
10) }
5957 | Vopen
("doc", attrs
, closed
) ->
5958 let pathent, spage
, srely
, span
= doc_of attrs
in
5959 let path = unent pathent
5960 and pageno = fromstring int_of_string spos
"page" spage
0
5961 and rely = fromstring float_of_string spos
"rely" srely
0.0
5962 and pan
= fromstring int_of_string spos
"pan" span
0 in
5963 let c = config_of dc attrs
in
5964 let anchor = (pageno, rely) in
5966 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5967 else { v with f = doc
path pan
anchor c [] }
5970 error
"unexpected subelement in llppconfig" s spos
5972 | Vclose
"llppconfig" -> { v with f = toplevel }
5973 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5975 and defaults
v t spos
_ =
5977 | Vdata
| Vcdata
-> v
5978 | Vend
-> error
"unexpected end of input in defaults" s spos
5979 | Vopen
("keymap", attrs
, closed
) ->
5981 try List.assoc
"mode" attrs
5982 with Not_found
-> "global" in
5987 let h = findkeyhash dc modename in
5988 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5991 { v with f = pkeymap
ret KeyMap.empty }
5993 | Vopen
(_, _, _) ->
5994 error
"unexpected subelement in defaults" s spos
5996 | Vclose
"defaults" ->
5997 { v with f = llppconfig
}
5999 | Vclose
_ -> error
"unexpected close in defaults" s spos
6001 and uifont
b v t spos
epos =
6004 Buffer.add_substring
b s spos
(epos - spos
);
6006 | Vopen
(_, _, _) ->
6007 error
"unexpected subelement in ui-font" s spos
6008 | Vclose
"ui-font" ->
6009 if String.length
!fontpath = 0
6010 then fontpath := Buffer.contents
b;
6011 { v with f = llppconfig
}
6012 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6013 | Vend
-> error
"unexpected end of input in ui-font" s spos
6015 and doc
path pan
anchor c bookmarks
v t spos
_ =
6017 | Vdata
| Vcdata
-> v
6018 | Vend
-> error
"unexpected end of input in doc" s spos
6019 | Vopen
("bookmarks", _, closed
) ->
6022 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6024 | Vopen
("keymap", attrs
, closed
) ->
6026 try List.assoc
"mode" attrs
6027 with Not_found
-> "global"
6033 let h = findkeyhash c modename in
6034 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6035 doc
path pan
anchor c bookmarks
6037 { v with f = pkeymap
ret KeyMap.empty }
6039 | Vopen
(_, _, _) ->
6040 error
"unexpected subelement in doc" s spos
6043 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6044 { v with f = llppconfig
}
6046 | Vclose
_ -> error
"unexpected close in doc" s spos
6048 and pkeymap
ret keymap
v t spos
_ =
6050 | Vdata
| Vcdata
-> v
6051 | Vend
-> error
"unexpected end of input in keymap" s spos
6052 | Vopen
("map", attrs
, closed
) ->
6053 let r, l = map_of attrs
in
6054 let kss = fromstring keys_of_string spos
"in" r [] in
6055 let lss = fromstring keys_of_string spos
"out" l [] in
6059 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6060 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6063 then { v with f = pkeymap
ret keymap }
6066 { v with f = skip
"map" f }
6069 error
"unexpected subelement in keymap" s spos
6071 | Vclose
"keymap" ->
6072 { v with f = ret keymap }
6074 | Vclose
_ -> error
"unexpected close in keymap" s spos
6076 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6078 | Vdata
| Vcdata
-> v
6079 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6080 | Vopen
("item", attrs
, closed
) ->
6081 let titleent, spage
, srely
= bookmark_of attrs
in
6082 let page = fromstring int_of_string spos
"page" spage
0
6083 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6084 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6086 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6089 { v with f = skip
"item" f }
6092 error
"unexpected subelement in bookmarks" s spos
6094 | Vclose
"bookmarks" ->
6095 { v with f = doc
path pan
anchor c bookmarks }
6097 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6099 and skip tag
f v t spos
_ =
6101 | Vdata
| Vcdata
-> v
6103 error
("unexpected end of input in skipped " ^ tag
) s spos
6104 | Vopen
(tag'
, _, closed
) ->
6108 let f'
() = { v with f = skip tag
f } in
6109 { v with f = skip tag'
f'
}
6113 else error
("unexpected close in skipped " ^ tag
) s spos
6116 parse
{ f = toplevel; accu = () } s;
6122 let len = in_channel_length ic
in
6123 let s = String.create
len in
6124 really_input ic
s 0 len;
6127 | Parse_error
(msg
, s, pos
) ->
6128 let subs = subs s pos
in
6129 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6130 failwith
("parse error: " ^
s)
6133 failwith
("config load error: " ^
Printexc.to_string exn
)
6139 let dir = Filename.concat
home ".config" in
6140 if Sys.is_directory
dir then dir else home
6143 Filename.concat
dir "llpp.conf"
6146 let confpath = ref defconfpath;;
6149 if Sys.file_exists
!confpath
6152 (try Some
(open_in_bin
!confpath)
6155 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6156 Printexc.to_string exn
);
6165 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6166 Printexc.to_string exn
);
6172 f (Hashtbl.create
0, defconf)
6177 let pc, pb
, px, pa
=
6179 Hashtbl.find h (Filename.basename
state.path)
6180 with Not_found
-> dc, [], 0, (0, 0.0)
6184 state.bookmarks <- pb
;
6186 state.scrollw
<- conf.scrollbw
;
6188 then state.anchor <- pa
;
6189 cbput state.hists
.nav pa
;
6194 let add_attrs bb always
dc c =
6197 then Printf.bprintf bb
"\n %s='%b'" s a
6200 then Printf.bprintf bb
"\n %s='%d'" s a
6203 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6206 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6209 then Printf.bprintf bb
"\n %s='%f'" s a
6213 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6217 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6221 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6225 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6231 | Some
(_N
, _A
, _B
) ->
6232 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6242 else string_of_float
f
6244 Printf.bprintf bb
"\n %s='%s'" s v
6249 | Cmulti
((n, a, b), _) when n > 1 ->
6250 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6251 | Csplit
(n, _) when n > 1 ->
6252 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6258 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6263 then dc.winw, dc.winh
6265 match state.fullscreen
with
6267 | None
-> c.winw, c.winh
6269 let zoom, presentation, interpagespace, maxwait
=
6271 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6273 match state.mode with
6274 | Birdseye
(bc
, _, _, _, _) ->
6275 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6276 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6278 oi
"width" w dc.winw;
6279 oi
"height" h dc.winh
;
6280 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6281 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6282 ob "case-insensitive-search" c.icase
dc.icase
;
6283 ob "preload" c.preload dc.preload;
6284 oi
"page-bias" c.pagebias
dc.pagebias
;
6285 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6286 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6287 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6288 ob "crop-hack" c.crophack
dc.crophack
;
6289 oW
"throttle" maxwait
dc.maxwait
;
6290 ob "highlight-links" c.hlinks
dc.hlinks
;
6291 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6292 oi
"vertical-margin" interpagespace dc.interpagespace;
6293 oz
"zoom" zoom dc.zoom;
6294 ob "presentation" presentation dc.presentation;
6295 oi
"rotation-angle" c.angle
dc.angle
;
6296 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6297 ob "proportional-display" c.proportional
dc.proportional
;
6298 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6299 oi
"tex-count" c.texcount
dc.texcount
;
6300 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6301 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6302 ob "persistent-location" c.jumpback
dc.jumpback
;
6303 oc
"background-color" c.bgcolor
dc.bgcolor
;
6304 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6305 oi
"tile-width" c.tilew
dc.tilew
;
6306 oi
"tile-height" c.tileh
dc.tileh
;
6307 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6308 ob "checkers" c.checkers
dc.checkers
;
6309 oi
"aalevel" c.aalevel
dc.aalevel
;
6310 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6311 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6312 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6313 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6314 oC
"color-space" c.colorspace
dc.colorspace
;
6315 ob "invert-colors" c.invert
dc.invert
;
6316 oF
"brightness" c.colorscale
dc.colorscale
;
6317 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6318 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6319 oco
"columns" c.columns
dc.columns
;
6320 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6321 os
"selection-command" c.selcmd
dc.selcmd
;
6322 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6325 let keymapsbuf always
dc c =
6326 let bb = Buffer.create
16 in
6327 let rec loop = function
6329 | (modename, h) :: rest
->
6330 let dh = findkeyhash dc modename in
6331 if always
|| h <> dh
6333 if Hashtbl.length
h > 0
6335 if Buffer.length
bb > 0
6336 then Buffer.add_char
bb '
\n'
;
6337 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6338 Hashtbl.iter
(fun i
o ->
6339 let isdifferent = always
||
6341 let dO = Hashtbl.find dh i
in
6343 with Not_found
-> true
6348 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6349 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6350 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6351 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6352 Buffer.add_string
bb (Wsi.keyname
k);
6355 let rec loop = function
6357 | km
:: [] -> addkm km
6358 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6362 Buffer.add_string
bb "<map in='";
6366 Buffer.add_string
bb "' out='";
6368 Buffer.add_string
bb "'/>\n"
6371 Buffer.add_string
bb "' out='";
6373 Buffer.add_string
bb "'/>\n"
6375 | KMmulti
(ins, kms
) ->
6376 Buffer.add_char
bb ' '
;
6378 Buffer.add_string
bb "' out='";
6380 Buffer.add_string
bb "'/>\n"
6382 Buffer.add_string
bb "</keymap>";
6392 let uifontsize = fstate.fontsize
in
6393 let bb = Buffer.create
32768 in
6395 let dc = if conf.bedefault
then conf else dc in
6396 Buffer.add_string
bb "<llppconfig>\n";
6398 if String.length
!fontpath > 0
6400 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6406 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6409 Buffer.add_string
bb "<defaults ";
6410 add_attrs bb true dc dc;
6411 let kb = keymapsbuf true dc dc in
6412 if Buffer.length
kb > 0
6414 Buffer.add_string
bb ">\n";
6415 Buffer.add_buffer
bb kb;
6416 Buffer.add_string
bb "\n</defaults>\n";
6418 else Buffer.add_string
bb "/>\n";
6420 let adddoc path pan
anchor c bookmarks =
6421 if bookmarks == [] && c = dc && anchor = emptyanchor
6424 Printf.bprintf
bb "<doc path='%s'"
6425 (enent
path 0 (String.length
path));
6427 if anchor <> emptyanchor
6429 let n, y = anchor in
6430 Printf.bprintf
bb " page='%d'" n;
6433 Printf.bprintf
bb " rely='%f'" y
6438 then Printf.bprintf
bb " pan='%d'" pan
;
6440 add_attrs bb false dc c;
6441 let kb = keymapsbuf false dc c in
6443 begin match bookmarks with
6445 if Buffer.length
kb > 0
6447 Buffer.add_string
bb ">\n";
6448 Buffer.add_buffer
bb kb;
6449 Buffer.add_string
bb "</doc>\n";
6451 else Buffer.add_string
bb "/>\n"
6453 Buffer.add_string
bb ">\n<bookmarks>\n";
6454 List.iter
(fun (title, _level
, (page, rely)) ->
6456 "<item title='%s' page='%d'"
6457 (enent
title 0 (String.length
title))
6462 Printf.bprintf
bb " rely='%f'" rely
6464 Buffer.add_string
bb "/>\n";
6466 Buffer.add_string
bb "</bookmarks>";
6467 if Buffer.length
kb > 0
6469 Buffer.add_string
bb "\n";
6470 Buffer.add_buffer
bb kb;
6472 Buffer.add_string
bb "\n</doc>\n";
6478 match state.mode with
6479 | Birdseye
(c, pan, _, _, _) ->
6481 match conf.columns
with
6482 | Cmulti
((c, _, _), _) -> Some
c
6486 match c.columns
with
6487 | Cmulti
(c, _) -> Cmulti
(c, [||])
6488 | Csingle
-> Csingle
6489 | Csplit
_ -> failwith
"quit from bird's eye while split"
6491 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6492 | _ -> state.x, conf
6494 let basename = Filename.basename state.path in
6495 adddoc basename pan (getanchor ())
6498 match state.autoscroll
with
6500 | None
-> conf.autoscrollstep
}
6501 (if conf.savebmarks
then state.bookmarks else []);
6503 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6505 then adddoc path x y c bookmarks
6507 Buffer.add_string
bb "</llppconfig>";
6510 if Buffer.length
bb > 0
6513 let tmp = !confpath ^
".tmp" in
6514 let oc = open_out_bin
tmp in
6515 Buffer.output_buffer
oc bb;
6517 Unix.rename
tmp !confpath;
6520 ("error while saving configuration: " ^
Printexc.to_string exn
)
6527 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6528 "<password> Set password");
6530 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6531 "<path> Set path to the user interface font");
6533 ("-c", Arg.String
(fun s -> Config.confpath := s),
6534 "<path> Set path to the configuration file");
6536 ("-v", Arg.Unit
(fun () ->
6538 "%s\nconfiguration path: %s\n"
6542 exit
0), " Print version and exit");
6545 (fun s -> state.path <- s)
6546 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6548 if String.length
state.path = 0
6549 then (prerr_endline
"file name missing"; exit
1);
6553 let globalkeyhash = findkeyhash conf "global" in
6554 let wsfd, winw, winh
= Wsi.init
(object
6556 if nogeomcmds state.geomcmds
6558 method display = display ()
6559 method reshape w h = reshape w h
6560 method mouse b d x y m = mouse b d x y m
6561 method motion x y = state.mpos
<- (x, y); motion x y
6562 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6564 let mascm = m land (
6565 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6567 match state.keystate
with
6569 let km = k, mascm in
6572 try Hashtbl.find globalkeyhash km
6574 let modehash = state.uioh#
modehash in
6575 try Hashtbl.find modehash km
6576 with Not_found
-> KMinsrt
(k, m)
6578 | KMinsrt
(k, m) -> keyboard k m
6579 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6580 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6582 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6583 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6584 state.keystate
<- KSnone
6585 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6586 state.keystate
<- KSinto
(keys
, insrt
)
6588 state.keystate
<- KSnone
6590 method enter
x y = state.mpos
<- (x, y); pmotion x y
6591 method leave = state.mpos
<- (-1, -1)
6592 method quit
= raise Quit
6593 end) conf.winw conf.winh
(platform = Posx
) in
6598 List.exists
GlMisc.check_extension
6599 [ "GL_ARB_texture_rectangle"
6600 ; "GL_EXT_texture_recangle"
6601 ; "GL_NV_texture_rectangle" ]
6603 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6605 let cr, sw = Unix.pipe
()
6606 and sr
, cw = Unix.pipe
() in
6613 setcheckers conf.checkers
;
6617 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6618 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6623 state.text <- "Opening " ^
state.path;
6625 opendoc state.path state.password
;
6628 let rec loop deadline
=
6630 match state.errfd
with
6631 | None
-> [state.sr
; state.wsfd]
6632 | Some fd
-> [state.sr
; state.wsfd; fd
]
6636 state.redisplay
<- false;
6643 if deadline
= infinity
6645 else max
0.0 (deadline
-. now)
6650 try Unix.select
r [] [] timeout
6651 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6657 if state.ghyll
== noghyll
6659 match state.autoscroll
with
6660 | Some step
when step
!= 0 ->
6661 let y = state.y + step
in
6665 else if y >= state.maxy then 0 else y
6668 if state.mode = View
6669 then state.text <- "";
6672 else deadline
+. 0.01
6677 let rec checkfds = function
6679 | fd
:: rest
when fd
= state.sr
->
6680 let cmd = readcmd state.sr
in
6684 | fd
:: rest
when fd
= state.wsfd ->
6689 let s = String.create
80 in
6690 let n = Unix.read fd
s 0 80 in
6691 if conf.redirectstderr
6693 Buffer.add_substring
state.errmsgs
s 0 n;
6694 state.newerrmsgs
<- true;
6695 state.redisplay
<- true;
6698 prerr_string
(String.sub
s 0 n);
6706 if deadline
= infinity
6710 match state.autoscroll
with
6711 | Some step
when step
!= 0 -> deadline1
6712 | _ -> if state.ghyll
== noghyll then infinity
else deadline1