6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> int -> int -> int -> (int * string) -> int =
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
115 if platform = Pcygwin
117 let sh = "/bin/sh" in
118 let args = [|sh; "-c"; cmd
|] in
119 let rec std si so se
= function
121 | (fd
, 0) :: rest
-> std fd so se rest
122 | (fd
, -1) :: rest
->
123 Unix.set_close_on_exec fd
;
126 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
128 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
129 ignore
(Unix.create_process
sh args si so se
)
138 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
141 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
143 type mpos
= int * int
145 | Msel
of (mpos
* mpos
)
147 | Mscrolly
| Mscrollx
148 | Mzoom
of (int * int)
149 | Mzoomrect
of (mpos
* mpos
)
153 type textentry
= string * string * onhist
option * onkey
* ondone
154 and onkey
= string -> int -> te
155 and ondone
= string -> unit
156 and histcancel
= unit -> unit
157 and onhist
= ((histcmd
-> string) * histcancel
)
158 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
163 | TEswitch
of textentry
174 let bound v minv maxv
=
175 max minv
(min maxv v
);
179 { store
= Array.create n v
186 let drawstring size x y s
=
188 Gl.enable `texture_2d
;
189 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
190 ignore
(drawstr size x y s
);
192 Gl.disable `texture_2d
;
195 let drawstring1 size x y s
=
199 let drawstring2 size x y fmt
=
200 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
203 let cbcap b
= Array.length b
.store
;;
208 b
.wc
<- (b
.wc
+ 1) mod cap;
210 b
.len
<- min
(b
.len
+ 1) cap;
213 let cbempty b
= b
.len
= 0;;
215 let cbgetg b circular dir
=
219 let rc = b
.rc + dir
in
231 else max
0 (min
rc (b
.len
-1))
237 let cbget b
= cbgetg b
false;;
238 let cbgetc b
= cbgetg b
true;;
255 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
256 dolog " WxH %dx%d" l
.pagew l
.pageh
;
257 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
258 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
259 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
263 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
265 dolog " x0,y0=(% f, % f)" x0 y0
;
266 dolog " x1,y1=(% f, % f)" x1 y1
;
267 dolog " x2,y2=(% f, % f)" x2 y2
;
268 dolog " x3,y3=(% f, % f)" x3 y3
;
272 type multicolumns
= multicol
* pagegeom
273 and splitcolumns
= columncount
* pagegeom
274 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
275 and multicol
= columncount
* covercount
* covercount
277 and columncount
= int
278 and covercount
= int;;
281 { mutable scrollbw
: int
282 ; mutable scrollh
: int
283 ; mutable icase
: bool
284 ; mutable preload
: bool
285 ; mutable pagebias
: int
286 ; mutable verbose
: bool
287 ; mutable debug
: bool
288 ; mutable scrollstep
: int
289 ; mutable maxhfit
: bool
290 ; mutable crophack
: bool
291 ; mutable autoscrollstep
: int
292 ; mutable maxwait
: float option
293 ; mutable hlinks
: bool
294 ; mutable underinfo
: bool
295 ; mutable interpagespace
: interpagespace
296 ; mutable zoom
: float
297 ; mutable presentation
: bool
298 ; mutable angle
: angle
301 ; mutable savebmarks
: bool
302 ; mutable proportional
: proportional
303 ; mutable trimmargins
: trimmargins
304 ; mutable trimfuzz
: irect
305 ; mutable memlimit
: memsize
306 ; mutable texcount
: texcount
307 ; mutable sliceheight
: sliceheight
308 ; mutable thumbw
: width
309 ; mutable jumpback
: bool
310 ; mutable bgcolor
: float * float * float
311 ; mutable bedefault
: bool
312 ; mutable scrollbarinpm
: bool
313 ; mutable tilew
: int
314 ; mutable tileh
: int
315 ; mutable mustoresize
: memsize
316 ; mutable checkers
: bool
317 ; mutable aalevel
: int
318 ; mutable urilauncher
: string
319 ; mutable pathlauncher
: string
320 ; mutable colorspace
: colorspace
321 ; mutable invert
: bool
322 ; mutable colorscale
: float
323 ; mutable redirectstderr
: bool
324 ; mutable ghyllscroll
: (int * int * int) option
325 ; mutable columns
: columns
326 ; mutable beyecolumns
: columncount
option
327 ; mutable selcmd
: string
328 ; mutable updatecurs
: bool
329 ; mutable keyhashes
: (string * keyhash
) list
333 | Cmulti
of multicolumns
334 | Csplit
of splitcolumns
337 type anchor
= pageno
* top
;;
339 type outline
= string * int * anchor
;;
341 type rect
= float * float * float * float * float * float * float * float;;
343 type tile
= opaque
* pixmapsize
* elapsed
344 and elapsed
= float;;
345 type pagemapkey
= pageno
* gen
;;
346 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
350 let emptyanchor = (0, 0.0);;
352 type infochange
= | Memused
| Docinfo
| Pdim
;;
354 class type uioh
= object
355 method display
: unit
356 method key
: int -> int -> uioh
357 method button
: int -> bool -> int -> int -> int -> uioh
358 method motion
: int -> int -> uioh
359 method pmotion
: int -> int -> uioh
360 method infochanged
: infochange
-> unit
361 method scrollpw
: (int * float * float)
362 method scrollph
: (int * float * float)
363 method modehash
: keyhash
367 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
368 | Textentry
of (textentry
* onleave
)
370 | LinkNav
of linktarget
371 and onleave
= leavetextentrystatus
-> unit
372 and leavetextentrystatus
= | Cancel
| Confirm
373 and helpitem
= string * int * action
376 | Action
of (uioh
-> uioh
)
378 | Ltexact
of (pageno
* int)
382 let isbirdseye = function Birdseye _
-> true | _
-> false;;
383 let istextentry = function Textentry _
-> true | _
-> false;;
387 | Loading
of (page
* gen
)
389 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
391 | Outlining
of outline list
394 let emptykeyhash = Hashtbl.create
0;;
395 let nouioh : uioh
= object (self
)
397 method key _ _
= self
398 method button _ _ _ _ _
= self
399 method motion _ _
= self
400 method pmotion _ _
= self
401 method infochanged _
= ()
402 method scrollpw
= (0, nan
, nan
)
403 method scrollph
= (0, nan
, nan
)
404 method modehash
= emptykeyhash
408 { mutable sr
: Unix.file_descr
409 ; mutable sw
: Unix.file_descr
410 ; mutable wsfd
: Unix.file_descr
411 ; mutable errfd
: Unix.file_descr
option
412 ; mutable stderr
: Unix.file_descr
413 ; mutable errmsgs
: Buffer.t
414 ; mutable newerrmsgs
: bool
418 ; mutable scrollw
: int
419 ; mutable hscrollh
: int
420 ; mutable anchor
: anchor
421 ; mutable ranchors
: (string * string * anchor
) list
423 ; mutable layout
: page list
424 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
425 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
426 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
427 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
428 ; mutable pagecount
: int
429 ; mutable currently
: currently
430 ; mutable mstate
: mstate
431 ; mutable searchpattern
: string
432 ; mutable rects
: (pageno
* recttype
* rect
) list
433 ; mutable rects1
: (pageno
* recttype
* rect
) list
434 ; mutable text
: string
435 ; mutable fullscreen
: (width
* height
) option
436 ; mutable mode
: mode
437 ; mutable uioh
: uioh
438 ; mutable outlines
: outline array
439 ; mutable bookmarks
: outline list
440 ; mutable path
: string
441 ; mutable password
: string
442 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
443 ; mutable memused
: memsize
445 ; mutable throttle
: (page list
* int * float) option
446 ; mutable autoscroll
: int option
447 ; mutable ghyll
: (int option -> unit)
448 ; mutable help
: helpitem array
449 ; mutable docinfo
: (int * string) list
450 ; mutable texid
: GlTex.texture_id
option
452 ; mutable prevzoom
: float
453 ; mutable progress
: float
454 ; mutable redisplay
: bool
455 ; mutable mpos
: mpos
456 ; mutable keystate
: keystate
457 ; mutable glinks
: bool
460 { pat
: string circbuf
461 ; pag
: string circbuf
462 ; nav
: anchor circbuf
463 ; sel
: string circbuf
484 ; presentation
= false
489 ; proportional
= true
490 ; trimmargins
= false
491 ; trimfuzz
= (0,0,0,0)
492 ; memlimit
= 32 lsl 20
497 ; bgcolor
= (0.5, 0.5, 0.5)
499 ; scrollbarinpm
= true
502 ; mustoresize
= 256 lsl 20
507 | Plinux
| Pfreebsd
| Pdragonflybsd
508 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
509 | Posx
-> "open \"%s\""
510 | Pcygwin
-> "cygstart \"%s\""
511 | Punknown
-> "echo %s")
512 ; pathlauncher
= "lp \"%s\""
515 | Plinux
| Pfreebsd
| Pdragonflybsd
516 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
523 ; redirectstderr
= false
529 let mk n
= (n
, Hashtbl.create
1) in
542 let findkeyhash c name
=
543 try List.assoc name c
.keyhashes
544 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
547 let conf = { defconf with angle
= defconf.angle
};;
550 { mutable fontsize
: int
551 ; mutable wwidth
: float
552 ; mutable maxrows
: int
564 fstate.fontsize
<- n
;
565 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
566 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
570 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
571 let len = String.length s
in
572 if colonpos >= 0 && colonpos + 3 < len
574 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
577 try String.rindex_from s
colonpos ' '
581 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
584 | "http" | "ftp" | "mailto" ->
586 try String.index_from s
colonpos ' '
587 with Not_found
-> len
589 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
597 if String.length
conf.urilauncher
= 0
598 then print_endline uri
600 let url = geturl uri
in
601 if String.length
url = 0
602 then print_endline uri
604 let re = Str.regexp
"%s" in
605 let command = Str.global_replace
re url conf.urilauncher
in
609 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
615 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
616 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
620 let strings = version () :: "" :: Help.keys
in
623 let url = geturl s
in
624 if String.length
url > 0
625 then (s
, 0, Action
(fun u
-> gotouri url; u
))
626 else (s
, 0, Noaction
)
631 let firstgeomcmds = "", [];;
638 ; stderr
= Unix.stderr
639 ; errmsgs
= Buffer.create
0
646 ; anchor
= emptyanchor
650 ; tilelru
= Queue.create
()
651 ; pagemap
= Hashtbl.create
10
652 ; tilemap
= Hashtbl.create
10
667 ; geomcmds
= firstgeomcmds
669 { nav
= cbnew 10 (0, 0.0)
695 Printf.kprintf prerr_endline fmt
697 Printf.kprintf ignore fmt
701 if String.length
conf.pathlauncher
= 0
702 then print_endline
state.path
704 let re = Str.regexp
"%s" in
705 let command = Str.global_replace
re state.path
conf.pathlauncher
in
709 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
714 let redirectstderr () =
715 if conf.redirectstderr
717 let rfd, wfd
= Unix.pipe
() in
718 state.stderr
<- Unix.dup
Unix.stderr
;
719 state.errfd
<- Some
rfd;
720 Unix.dup2 wfd
Unix.stderr
;
722 state.newerrmsgs
<- false;
723 begin match state.errfd
with
726 Unix.dup2
state.stderr
Unix.stderr
;
730 prerr_string
(Buffer.contents
state.errmsgs
);
732 Buffer.clear
state.errmsgs
;
738 let postRedisplay who
=
740 then prerr_endline
("redisplay for " ^ who
);
741 state.redisplay
<- true;
745 let getopaque pageno
=
746 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
747 with Not_found
-> None
750 let putopaque pageno opaque
=
751 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
754 let pagetranslatepoint l x y
=
755 let dy = y
- l
.pagedispy
in
756 let y = dy + l
.pagey
in
757 let dx = x
- l
.pagedispx
in
758 let x = dx + l
.pagex
in
765 begin match getopaque l
.pageno
with
767 let x0 = l
.pagedispx
in
768 let x1 = x0 + l
.pagevw
in
769 let y0 = l
.pagedispy
in
770 let y1 = y0 + l
.pagevh
in
771 if y >= y0 && y <= y1 && x >= x0 && x <= x1
773 let px, py
= pagetranslatepoint l
x y in
774 match whatsunder opaque
px py
with
787 state.text
<- Printf.sprintf
"%c%s" c s
;
788 G.postRedisplay "showtext";
791 let undertext = function
794 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
795 | Utext s
-> "font: " ^ s
796 | Uunexpected s
-> "unexpected: " ^ s
797 | Ulaunch s
-> "launch: " ^ s
798 | Unamed s
-> "named: " ^ s
799 | Uremote
(filename
, pageno
) ->
800 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
803 let updateunder x y =
804 match getunder x y with
805 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
807 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
808 Wsi.setcursor
Wsi.CURSOR_INFO
809 | Ulinkgoto
(pageno
, _
) ->
811 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
812 Wsi.setcursor
Wsi.CURSOR_INFO
814 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
815 Wsi.setcursor
Wsi.CURSOR_TEXT
817 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
818 Wsi.setcursor
Wsi.CURSOR_INHERIT
820 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
821 Wsi.setcursor
Wsi.CURSOR_INHERIT
823 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
824 Wsi.setcursor
Wsi.CURSOR_INHERIT
825 | Uremote
(filename
, pageno
) ->
826 if conf.underinfo
then showtext 'r'
827 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
828 Wsi.setcursor
Wsi.CURSOR_INFO
831 let showlinktype under
=
837 let s = undertext under
in
842 let b = Buffer.create
(String.length
s + 1) in
843 Buffer.add_string
b s;
848 let colorspace_of_string s =
849 match String.lowercase
s with
853 | _
-> failwith
"invalid colorspace"
856 let int_of_colorspace = function
862 let colorspace_of_int = function
866 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
869 let colorspace_to_string = function
875 let intentry_with_suffix text key
=
877 if key
>= 32 && key
< 127
881 match Char.lowercase
c with
883 let text = addchar text c in
887 let text = addchar text c in
891 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
895 let multicolumns_to_string (n
, a
, b) =
897 then Printf.sprintf
"%d" n
898 else Printf.sprintf
"%d,%d,%d" n a
b;
901 let multicolumns_of_string s =
903 (int_of_string
s, 0, 0)
905 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
910 let n = Unix.read fd
s 0 4 in
911 if n != 4 then failwith
"incomplete read(len)";
913 lor (Char.code
s.[0] lsl 24)
914 lor (Char.code
s.[1] lsl 16)
915 lor (Char.code
s.[2] lsl 8)
916 lor (Char.code
s.[3] lsl 0)
918 let s = String.create
len in
919 let n = Unix.read fd
s 0 len in
920 if n != len then failwith
"incomplete read(data)";
924 let btod b = if b then 1 else 0;;
927 let b = Buffer.create
16 in
928 Buffer.add_string
b "llll";
931 let s = Buffer.contents
b in
932 let n = String.length
s in
934 (* dolog "wcmd %S" (String.sub s 4 len); *)
935 s.[0] <- Char.chr
((len lsr 24) land 0xff);
936 s.[1] <- Char.chr
((len lsr 16) land 0xff);
937 s.[2] <- Char.chr
((len lsr 8) land 0xff);
938 s.[3] <- Char.chr
(len land 0xff);
939 let n'
= Unix.write
state.sw
s 0 n in
940 if n'
!= n then failwith
"write failed";
947 let d = conf.winh
- h
in
954 let rec f pn ph pi fh l
=
956 | (n, _
, h
, _
) :: rest
->
957 let ips = calcips h
in
962 if isbirdseye state.mode
&& pn
= 0
967 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
972 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
976 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
979 let fh = f 0 0 0 0 state.pdims
in
984 match conf.columns
with
985 | Csingle
-> calcheight ()
986 | Cmulti
((c, _
, _
), b) ->
991 if n = Array.length
b
994 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1000 loop max_int
0 (((Array.length
b - 1) / c) * c)
1002 if Array.length
b > 0
1004 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1009 let getpageyh pageno
=
1010 let rec f pn ph pi
y l
=
1012 | (n, _
, h
, _
) :: rest
->
1013 let ips = calcips h
in
1016 let h = if n = pageno
then h else ph
in
1017 if conf.presentation
&& n = pageno
1019 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1021 y + (pageno
- pn
) * (ph
+ pi
), h
1023 let y = y + (if conf.presentation
then pi
else 0) in
1024 let y = y + (n - pn
) * (ph
+ pi
) in
1028 y + (pageno
- pn
) * (ph
+ pi
), ph
1030 f 0 0 0 0 state.pdims
1033 let getpageyh pageno
=
1034 match conf.columns
with
1035 | Csingle
-> getpageyh pageno
1037 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1041 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1045 let getpagedim pageno
=
1048 | (n, _
, _
, _
) as pdim
:: rest
->
1050 then (if n = pageno
then pdim
else ppdim
)
1055 f (-1, -1, -1, -1) state.pdims
1058 let getpagey pageno
= fst
(getpageyh pageno
);;
1060 let nogeomcmds cmds
=
1062 | s, [] -> String.length
s = 0
1067 let sh = sh - state.hscrollh
in
1068 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1069 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1071 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1072 let ips = calcips h in
1074 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1078 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1080 prev
, pdims
, pdimno
, 0
1082 let dy = dy + yinc in
1083 let py = py + yinc in
1084 if pageno
= state.pagecount
|| dy >= sh
1089 if py + h <= vy - yinc
1091 let py = py + h + ips in
1092 let dy = max
0 (py - y) in
1093 f ~pageno
:(pageno
+1)
1101 let pagey = vy - py in
1102 let pagevh = h - pagey in
1103 let pagevh = min
(sh - dy) pagevh in
1104 let off = if yinc > 0 then py - vy else 0 in
1105 let py = py + h + ips in
1108 if state.w
< conf.winw
- state.scrollw
1109 then (conf.winw
- state.scrollw
- state.w
) / 2
1112 let dispx = xoff + state.x in
1118 let lw = w
- pagex in
1119 min
lw (conf.winw
- state.scrollw
)
1123 ; pagedimno
= pdimno
1127 ; pagey = pagey + off
1129 ; pagevh = pagevh - off
1131 ; pagedispy
= dy + off
1134 let accu = e :: accu in
1135 f ~pageno
:(pageno
+1)
1156 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1157 let sh = sh - state.hscrollh
in
1158 let rec fold accu n =
1159 if n = Array.length
b
1162 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1165 || n = state.pagecount
- coverB
1166 || (n - coverA
) mod columns
= columns
- 1)
1172 let pagey = max
0 (y - vy) in
1173 let pagedispy = if pagey > 0 then 0 else vy - y in
1174 let pagedispx, pagex =
1176 if n = coverA
- 1 || n = state.pagecount
- coverB
1177 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1178 else dx + xoff + state.x
1185 let vw = conf.winw
- state.scrollw
- pagedispx in
1186 let pw = w
- pagex in
1189 let pagevh = min
(h - pagey) (sh - pagedispy) in
1190 if pagevw > 0 && pagevh > 0
1194 ; pagedimno
= pdimno
1201 ; pagedispx = pagedispx
1202 ; pagedispy = pagedispy
1213 List.rev
(fold [] 0)
1216 let layoutS (columns
, b) y sh =
1217 let sh = sh - state.hscrollh
in
1218 let rec fold accu n =
1219 if n = Array.length
b
1222 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1229 let x = xoff + state.x in
1230 let pagey = max
0 (y - vy) in
1231 let pagedispy = if pagey > 0 then 0 else vy - y in
1232 let pagedispx, pagex =
1247 let vw = conf.winw
- pagedispx - state.scrollw
in
1248 let pw = pagew
- pagex in
1251 let pagevw = min
pagevw (pagew
/columns
) in
1252 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1253 if pagevw > 0 && pagevh > 0
1256 { pageno
= n/columns
1257 ; pagedimno
= pdimno
1264 ; pagedispx = pagedispx
1265 ; pagedispy = pagedispy
1276 List.rev
(fold [] 0)
1280 if nogeomcmds state.geomcmds
1282 match conf.columns
with
1283 | Csingle
-> layout1 y sh
1284 | Cmulti
c -> layoutN c y sh
1285 | Csplit
s -> layoutS s y sh
1290 let y = state.y + incr
in
1292 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1297 let tilex = l
.pagex mod conf.tilew
in
1298 let tiley = l
.pagey mod conf.tileh
in
1300 let col = l
.pagex / conf.tilew
in
1301 let row = l
.pagey / conf.tileh
in
1303 let rec rowloop row y0 dispy
h =
1307 let dh = conf.tileh
- y0 in
1308 let dh = min
h dh in
1309 let rec colloop col x0 dispx w
=
1313 let dw = conf.tilew
- x0 in
1314 let dw = min w
dw in
1316 f col row dispx dispy
x0 y0 dw dh;
1317 colloop (col+1) 0 (dispx+dw) (w
-dw)
1320 colloop col tilex l
.pagedispx l
.pagevw;
1321 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1324 if l
.pagevw > 0 && l
.pagevh > 0
1325 then rowloop row tiley l
.pagedispy l
.pagevh;
1328 let gettileopaque l
col row =
1330 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1332 try Some
(Hashtbl.find
state.tilemap
key)
1333 with Not_found
-> None
1336 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1337 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1338 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1341 let drawtiles l color
=
1343 let f col row x y tilex tiley w
h =
1344 match gettileopaque l
col row with
1345 | Some
(opaque
, _
, t
) ->
1346 let params = x, y, w
, h, tilex, tiley in
1350 GlFunc.blend_func `zero `one_minus_src_color
;
1352 drawtile
params opaque
;
1354 then Gl.disable `blend
;
1357 let s = Printf.sprintf
1361 let w = measurestr
fstate.fontsize
s in
1362 GlMisc.push_attrib
[`current
];
1363 GlDraw.color
(0.0, 0.0, 0.0);
1365 (float (x-2), float (y-2))
1366 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1367 GlDraw.color
(1.0, 1.0, 1.0);
1368 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1369 GlMisc.pop_attrib
();
1374 let lw = conf.winw
- state.scrollw
- x in
1377 let lh = conf.winh
- y in
1380 Gl.enable `texture_2d
;
1381 begin match state.texid
with
1383 GlTex.bind_texture `texture_2d id
;
1386 and x1 = float (x+w)
1387 and y1 = float (y+h) in
1389 let tw = float w /. 64.0
1390 and th
= float h /. 64.0 in
1391 let tx0 = float tilex /. 64.0
1392 and ty0
= float tiley /. 64.0 in
1394 and ty1
= ty0
+. th
in
1395 GlDraw.begins `quads
;
1396 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1397 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1398 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1399 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1402 Gl.disable `texture_2d
;
1404 GlDraw.color
(1.0, 1.0, 1.0);
1407 (float (x+w), float (y+h));
1409 if w > 128 && h > fstate.fontsize
+ 10
1411 GlDraw.color
(0.0, 0.0, 0.0);
1414 then (col*conf.tilew
, row*conf.tileh
)
1417 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1424 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1426 let tilevisible1 l
x y =
1428 and ax1
= l
.pagex + l
.pagevw
1430 and ay1
= l
.pagey + l
.pagevh in
1434 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1435 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1437 let rx0 = max
ax0 bx0
1438 and ry0
= max ay0 by0
1439 and rx1
= min ax1
bx1
1440 and ry1
= min ay1 by1
in
1442 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1443 nonemptyintersection
1446 let tilevisible layout n x y =
1447 let rec findpageinlayout m
= function
1448 | l
:: rest
when l
.pageno
= n ->
1449 tilevisible1 l
x y || (
1450 match conf.columns
with
1451 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1454 | _
:: rest
-> findpageinlayout 0 rest
1457 findpageinlayout 0 layout;
1460 let tileready l
x y =
1461 tilevisible1 l
x y &&
1462 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1465 let tilepage n p
layout =
1466 let rec loop = function
1470 let f col row _ _ _ _ _ _
=
1471 if state.currently
= Idle
1473 match gettileopaque l
col row with
1476 let x = col*conf.tilew
1477 and y = row*conf.tileh
in
1479 let w = l
.pagew
- x in
1483 let h = l
.pageh
- y in
1486 wcmd "tile %s %d %d %d %d" p
x y w h;
1489 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1490 conf.tilew
, conf.tileh
1499 if nogeomcmds state.geomcmds
1503 let preloadlayout visiblepages
=
1504 let presentation = conf.presentation in
1505 let interpagespace = conf.interpagespace in
1506 let maxy = state.maxy in
1507 conf.presentation <- false;
1508 conf.interpagespace <- 0;
1509 state.maxy <- calcheight ();
1511 match visiblepages
with
1513 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1515 let y = if y < conf.winh
then 0 else y - conf.winh
in
1516 let h = state.y - y + conf.winh
*3 in
1517 let pages = layout y h in
1518 conf.presentation <- presentation;
1519 conf.interpagespace <- interpagespace;
1525 let rec loop pages =
1526 if state.currently
!= Idle
1531 begin match getopaque l
.pageno
with
1533 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1534 state.currently
<- Loading
(l
, state.gen
);
1536 tilepage l
.pageno opaque
pages;
1541 if nogeomcmds state.geomcmds
1547 if conf.preload && state.currently
= Idle
1548 then load (preloadlayout pages);
1551 let layoutready layout =
1552 let rec fold all ls
=
1553 all
&& match ls
with
1555 let seen = ref false in
1556 let allvisible = ref true in
1557 let foo col row _ _ _ _ _ _
=
1559 allvisible := !allvisible &&
1560 begin match gettileopaque l
col row with
1566 fold (!seen && !allvisible) rest
1569 let alltilesvisible = fold true layout in
1574 let y = bound y 0 state.maxy in
1575 let y, layout, proceed
=
1576 match conf.maxwait
with
1577 | Some time
when state.ghyll
== noghyll ->
1578 begin match state.throttle
with
1580 let layout = layout y conf.winh
in
1581 let ready = layoutready layout in
1585 state.throttle
<- Some
(layout, y, now ());
1587 else G.postRedisplay "gotoy showall (None)";
1589 | Some
(_
, _
, started
) ->
1590 let dt = now () -. started
in
1593 state.throttle
<- None
;
1594 let layout = layout y conf.winh
in
1596 G.postRedisplay "maxwait";
1603 let layout = layout y conf.winh
in
1604 if true || layoutready layout
1605 then G.postRedisplay "gotoy ready";
1611 state.layout <- layout;
1612 begin match state.mode
with
1613 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1614 let rec loop = function
1616 state.mode
<- LinkNav
(Ltgendir
0)
1617 | l
:: _
when l
.pageno
= pageno
->
1618 begin match getopaque pageno
with
1620 state.mode
<- LinkNav
(Ltgendir
0)
1622 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1623 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1624 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1625 then state.mode
<- LinkNav
(Ltgendir
0)
1627 | _
:: rest
-> loop rest
1632 begin match state.mode
with
1633 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1634 if not
(pagevisible layout pageno
)
1636 match state.layout with
1639 state.mode
<- Birdseye
(
1640 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1643 | LinkNav
(Ltgendir dir
as lt
) ->
1645 let rec loop = function
1648 match getopaque l
.pageno
with
1654 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1656 if dir
> 0 then LDfirst
else LDlast
1662 | Lnotfound
-> loop rest
1664 showlinktype (getlink opaque
n);
1665 Ltexact
(l
.pageno
, n)
1669 state.mode
<- LinkNav
linknav
1674 state.ghyll
<- noghyll;
1677 let mx, my
= state.mpos
in
1682 let conttiling pageno opaque
=
1683 tilepage pageno opaque
1684 (if conf.preload then preloadlayout state.layout else state.layout)
1687 let gotoy_and_clear_text y =
1688 if not
conf.verbose
then state.text <- "";
1693 match state.layout with
1695 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1698 let getanchory (n, top
) =
1699 let y, h = getpageyh n in
1700 y + (truncate
(top
*. float h));
1703 let gotoanchor anchor
=
1704 gotoy (getanchory anchor
);
1708 cbput state.hists
.nav
(getanchor ());
1712 let anchor = cbgetc state.hists
.nav dir
in
1717 let rec scroll f n a
b =
1718 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1720 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1722 then s (float f /. float a
)
1725 then 1.0 -. s ((float (f-b) /. float (n-b)))
1732 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1733 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1735 let ins = float a
*. iv1
1736 and outs
= float (n-b) *. iv1 in
1738 ins +. outs
+. float ones
1740 let rec set (_N
, _A
, _B
) y sy
=
1741 let sum = summa
1.0 _N _A _B
in
1742 let dy = float (y - sy
) in
1746 then state.ghyll
<- noghyll
1749 let s = scroll n _N _A _B
in
1750 let y1 = y1 +. ((s *. dy) /. sum) in
1751 gotoy_and_clear_text (truncate
y1);
1752 state.ghyll
<- gf (n+1) y1;
1756 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1758 gf 0 (float state.y)
1761 match conf.ghyllscroll
with
1763 gotoy_and_clear_text y
1765 if state.ghyll
== noghyll
1766 then set nab
y state.y
1767 else state.ghyll
(Some
y)
1770 let gotopage n top
=
1771 let y, h = getpageyh n in
1772 let y = y + (truncate
(top
*. float h)) in
1776 let gotopage1 n top
=
1777 let y = getpagey n in
1782 let invalidate s f =
1787 match state.geomcmds
with
1788 | ps
, [] when String.length ps
= 0 ->
1790 state.geomcmds
<- s, [];
1793 state.geomcmds
<- ps
, [s, f];
1795 | ps
, (s'
, _
) :: rest
when s'
= s ->
1796 state.geomcmds
<- ps
, ((s, f) :: rest
);
1799 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1802 let opendoc path password
=
1804 state.password
<- password
;
1805 state.gen
<- state.gen
+ 1;
1806 state.docinfo
<- [];
1808 setaalevel
conf.aalevel
;
1809 Wsi.settitle
("llpp " ^
Filename.basename path
);
1810 wcmd "open %s\000%s\000" path password
;
1811 invalidate "reqlayout"
1813 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1817 let c = c *. conf.colorscale
in
1821 let scalecolor2 (r
, g
, b) =
1822 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1826 let docolumns = function
1829 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1830 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1831 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1832 let rec fixrow m
= if m
= pageno
then () else
1833 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1836 let y = y + (rowh
- h) / 2 in
1837 a.(m
) <- (pdimno, x, y, pdim
);
1841 if pageno
= state.pagecount
1842 then fixrow (((pageno
- 1) / columns
) * columns
)
1844 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1846 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1847 pdimno+1, pdim
, rest
1852 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1854 (conf.winw
- state.scrollw
- w) / 2,
1855 y + rowh
+ conf.interpagespace, h
1858 if (pageno
- coverA
) mod columns
= 0
1859 then 0, y + rowh
+ conf.interpagespace, h
1860 else x, y, max rowh
h
1863 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1864 then fixrow (pageno
- columns
);
1865 a.(pageno
) <- (pdimno, x, y, pdim
);
1866 let x = x + w + xoff*2 + conf.interpagespace in
1867 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1869 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1870 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1873 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1874 let rec loop pageno
pdimno pdim
y pdims
=
1875 if pageno
= state.pagecount
1878 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1880 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1881 pdimno+1, pdim
, rest
1886 let rec loop1 n x y =
1887 if n = c then y else (
1888 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1889 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1892 let y = loop1 0 0 y in
1893 loop (pageno
+1) pdimno pdim
y pdims
1895 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1896 conf.columns
<- Csplit
(c, a);
1898 docolumns conf.columns
;
1899 state.maxy <- calcheight ();
1901 if state.w <= conf.winw
- state.scrollw
1905 match state.mode
with
1906 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1907 let y, h = getpageyh pageno
in
1908 let top = (conf.winh
- h) / 2 in
1909 gotoy (max
0 (y - top))
1910 | _
-> gotoanchor state.anchor
1914 GlDraw.viewport
0 0 w h;
1915 let firsttime = state.geomcmds
== firstgeomcmds in
1916 if not
firsttime && nogeomcmds state.geomcmds
1917 then state.anchor <- getanchor ();
1920 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1923 setfontsize fstate.fontsize
;
1924 GlMat.mode `modelview
;
1925 GlMat.load_identity
();
1927 GlMat.mode `projection
;
1928 GlMat.load_identity
();
1929 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1930 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1931 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1936 else float state.x /. float state.w
1938 invalidate "geometry"
1942 then state.x <- truncate
(relx *. float w);
1944 match conf.columns
with
1946 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1947 | Csplit
(c, _
) -> w * c
1949 wcmd "geometry %d %d" w h);
1953 let len = String.length
state.text in
1956 match state.mode
with
1958 | View
-> state.hscrollh
1963 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1964 (x+.w, float (conf.winh
- hscrollh))
1967 let w = float (conf.winw
- state.scrollw
- 1) in
1968 if state.progress
>= 0.0 && state.progress
< 1.0
1970 GlDraw.color
(0.3, 0.3, 0.3);
1971 let w1 = w *. state.progress
in
1973 GlDraw.color
(0.0, 0.0, 0.0);
1977 GlDraw.color
(0.0, 0.0, 0.0);
1981 GlDraw.color
(1.0, 1.0, 1.0);
1982 drawstring fstate.fontsize
1983 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1986 match state.mode
with
1987 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1991 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1993 Printf.sprintf
"%s%s_" prefix
text
2002 if not
(istextentry state.mode
)
2004 let s1 = "(press 'e' to review error messasges)" in
2005 if String.length
s > 0 then s ^
" " ^
s1 else s1
2010 if String.length
s > 0
2015 let len = Queue.length
state.tilelru
in
2017 if state.memused
<= conf.memlimit
2022 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2023 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2024 let (_
, pw, ph
, _
) = getpagedim n in
2027 && colorspace
= conf.colorspace
2028 && angle
= conf.angle
2033 match state.throttle
with
2036 then preloadlayout state.layout
2038 | Some
(layout, _
, _
) ->
2041 let x = col*conf.tilew
2042 and y = row*conf.tileh
in
2043 tilevisible layout n x y
2045 then Queue.push lruitem
state.tilelru
2047 wcmd "freetile %s" p
;
2048 state.memused
<- state.memused
- s;
2049 state.uioh#infochanged Memused
;
2050 Hashtbl.remove
state.tilemap k
;
2059 Queue.iter
(fun (k
, p
, s) ->
2060 wcmd "freetile %s" p
;
2061 state.memused
<- state.memused
- s;
2062 state.uioh#infochanged Memused
;
2063 Hashtbl.remove
state.tilemap k
;
2065 Queue.clear
state.tilelru
;
2069 let logcurrently = function
2070 | Idle
-> dolog "Idle"
2071 | Loading
(l
, gen
) ->
2072 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2073 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2075 "Tiling %d[%d,%d] page=%s cs=%s angle"
2076 l
.pageno
col row pageopaque
2077 (colorspace_to_string colorspace
)
2079 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2080 angle gen
conf.angle
state.gen
2082 conf.tilew
conf.tileh
2089 (* dolog "%S" cmds; *)
2092 try String.index cmds ' '
2093 with Not_found
-> -1
2098 let l = String.length cmds
in
2099 let op = String.sub cmds
0 spacepos in
2101 if l - spacepos < 2 then ""
2102 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2107 state.uioh#infochanged Pdim
;
2111 state.rects
<- state.rects1
;
2112 G.postRedisplay "clearrects";
2116 try Scanf.sscanf
args "%u" (fun n -> n)
2118 dolog "error processing 'continue' %S: %s"
2119 cmds
(Printexc.to_string exn
);
2122 state.pagecount
<- n;
2123 begin match state.currently
with
2125 state.currently
<- Idle
;
2126 state.outlines
<- Array.of_list
(List.rev
l)
2130 let cur, cmds
= state.geomcmds
in
2131 if String.length
cur = 0
2132 then failwith
"umpossible";
2134 begin match List.rev cmds
with
2136 state.geomcmds
<- "", [];
2140 state.geomcmds
<- s, List.rev rest
;
2142 if conf.maxwait
= None
2143 then G.postRedisplay "continue";
2153 then showtext ' '
args
2156 let progress, text =
2158 Scanf.sscanf
args "%f %n"
2160 f, String.sub
args pos
(String.length
args - pos
))
2162 dolog "error processing 'progress' %S: %s"
2163 cmds
(Printexc.to_string exn
);
2167 state.progress <- progress;
2168 G.postRedisplay "progress"
2171 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2173 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2174 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2175 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2177 dolog "error processing 'firstmatch' %S: %s"
2178 cmds
(Printexc.to_string exn
);
2181 let y = (getpagey pageno) + truncate
y0 in
2184 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2187 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2189 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2190 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2191 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2193 dolog "error processing 'match' %S: %s"
2194 cmds
(Printexc.to_string exn
);
2198 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2203 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2205 dolog "error processing 'page' %S: %s"
2206 cmds
(Printexc.to_string exn
);
2209 begin match state.currently
with
2210 | Loading
(l, gen
) ->
2211 vlog "page %d took %f sec" l.pageno t
;
2212 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2213 begin match state.throttle
with
2215 let preloadedpages =
2217 then preloadlayout state.layout
2222 Set.Make
(struct type t
= int let compare = (-) end) in
2224 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2225 IntSet.empty
preloadedpages
2228 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2229 if not
(IntSet.mem
pageno set)
2231 wcmd "freepage %s" opaque
;
2237 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2240 state.currently
<- Idle
;
2243 tilepage l.pageno pageopaque state.layout;
2245 load preloadedpages;
2246 if pagevisible state.layout l.pageno
2247 && layoutready state.layout
2248 then G.postRedisplay "page";
2251 | Some
(layout, _
, _
) ->
2252 state.currently
<- Idle
;
2253 tilepage l.pageno pageopaque layout;
2258 dolog "Inconsistent loading state";
2259 logcurrently state.currently
;
2264 let (x, y, opaque
, size
, t
) =
2266 Scanf.sscanf
args "%u %u %s %u %f"
2267 (fun x y p size t
-> (x, y, p
, size
, t
))
2269 dolog "error processing 'tile' %S: %s"
2270 cmds
(Printexc.to_string exn
);
2273 begin match state.currently
with
2274 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2275 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2277 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2279 wcmd "freetile %s" opaque
;
2280 state.currently
<- Idle
;
2284 puttileopaque l col row gen cs angle opaque size t
;
2285 state.memused
<- state.memused
+ size
;
2286 state.uioh#infochanged Memused
;
2288 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2289 opaque
, size
) state.tilelru
;
2292 match state.throttle
with
2293 | None
-> state.layout
2294 | Some
(layout, _
, _
) -> layout
2297 state.currently
<- Idle
;
2299 && conf.colorspace
= cs
2300 && conf.angle
= angle
2301 && tilevisible layout l.pageno x y
2302 then conttiling l.pageno pageopaque;
2304 begin match state.throttle
with
2306 preload state.layout;
2308 && conf.colorspace
= cs
2309 && conf.angle
= angle
2310 && tilevisible state.layout l.pageno x y
2311 then G.postRedisplay "tile nothrottle";
2313 | Some
(layout, y, _
) ->
2314 let ready = layoutready layout in
2318 state.layout <- layout;
2319 state.throttle
<- None
;
2320 G.postRedisplay "throttle";
2327 dolog "Inconsistent tiling state";
2328 logcurrently state.currently
;
2335 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2337 dolog "error processing 'pdim' %S: %s"
2338 cmds
(Printexc.to_string exn
);
2341 state.uioh#infochanged Pdim
;
2342 state.pdims
<- pdim :: state.pdims
2345 let (l, n, t
, h, pos
) =
2347 Scanf.sscanf
args "%u %u %d %u %n"
2348 (fun l n t
h pos
-> l, n, t
, h, pos
)
2350 dolog "error processing 'o' %S: %s"
2351 cmds
(Printexc.to_string exn
);
2354 let s = String.sub
args pos
(String.length
args - pos
) in
2355 let outline = (s, l, (n, float t
/. float h)) in
2356 begin match state.currently
with
2357 | Outlining outlines
->
2358 state.currently
<- Outlining
(outline :: outlines
)
2360 state.currently
<- Outlining
[outline]
2362 dolog "invalid outlining state";
2363 logcurrently currently
2367 state.docinfo
<- (1, args) :: state.docinfo
2370 state.uioh#infochanged Docinfo
;
2371 state.docinfo
<- List.rev
state.docinfo
2374 dolog "unknown cmd `%S'" cmds
2379 let action = function
2380 | HCprev
-> cbget cb ~
-1
2381 | HCnext
-> cbget cb
1
2382 | HCfirst
-> cbget cb ~
-(cb
.rc)
2383 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2384 and cancel
() = cb
.rc <- rc
2388 let search pattern forward
=
2389 if String.length pattern
> 0
2392 match state.layout with
2395 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2397 wcmd "search %d %d %d %d,%s\000"
2398 (btod conf.icase
) pn py (btod forward
) pattern
;
2401 let intentry text key =
2403 if key >= 32 && key < 127
2409 let text = addchar text c in
2413 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2417 let linknentry text key =
2419 if key >= 32 && key < 127
2425 let text = addchar text c in
2429 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2434 if String.length
s > 0
2437 let rec loop pos
n = if pos
= String.length
s then n else
2438 let m = Char.code
s.[pos
] - 97 in
2439 loop (pos
+1) (n*26 + m)
2442 let rec loop n = function
2445 match getopaque l.pageno with
2446 | None
-> loop n rest
2448 let m = getlinkcount opaque
in
2451 let under = getlink opaque
n in
2454 else loop (n-m) rest
2456 loop n state.layout;
2460 let textentry text key =
2461 if key land 0xff00 = 0xff00
2463 else TEcont
(text ^
Wsi.toutf8
key)
2466 let reqlayout angle proportional
=
2467 match state.throttle
with
2469 if nogeomcmds state.geomcmds
2470 then state.anchor <- getanchor ();
2471 conf.angle
<- angle
mod 360;
2474 match state.mode
with
2475 | LinkNav _
-> state.mode
<- View
2478 conf.proportional
<- proportional
;
2479 invalidate "reqlayout"
2480 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2484 let settrim trimmargins trimfuzz
=
2485 if nogeomcmds state.geomcmds
2486 then state.anchor <- getanchor ();
2487 conf.trimmargins
<- trimmargins
;
2488 conf.trimfuzz
<- trimfuzz
;
2489 let x0, y0, x1, y1 = trimfuzz
in
2490 invalidate "settrim"
2492 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2493 Hashtbl.iter
(fun _ opaque
->
2494 wcmd "freepage %s" opaque
;
2496 Hashtbl.clear
state.pagemap
;
2500 match state.throttle
with
2502 let zoom = max
0.01 zoom in
2503 if zoom <> conf.zoom
2505 state.prevzoom
<- conf.zoom;
2507 reshape conf.winw
conf.winh
;
2508 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2511 | Some
(layout, y, started
) ->
2513 match conf.maxwait
with
2517 let dt = now () -. started
in
2525 let setcolumns mode columns coverA coverB
=
2529 then showtext '
!'
"split mode doesn't work in bird's eye"
2531 conf.columns
<- Csplit
(-columns
, [||]);
2539 conf.columns
<- Csingle
;
2544 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2548 reshape conf.winw
conf.winh
;
2551 let enterbirdseye () =
2552 let zoom = float conf.thumbw
/. float conf.winw
in
2553 let birdseyepageno =
2554 let cy = conf.winh
/ 2 in
2558 let rec fold best
= function
2561 let d = cy - (l.pagedispy + l.pagevh/2)
2562 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2563 if abs
d < abs dbest
2570 state.mode
<- Birdseye
(
2571 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2574 conf.presentation <- false;
2575 conf.interpagespace <- 10;
2576 conf.hlinks
<- false;
2578 state.mstate
<- Mnone
;
2579 conf.maxwait
<- None
;
2581 match conf.beyecolumns
with
2584 Cmulti
((c, 0, 0), [||])
2587 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2590 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2595 reshape conf.winw
conf.winh
;
2598 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2600 conf.zoom <- c.zoom;
2601 conf.presentation <- c.presentation;
2602 conf.interpagespace <- c.interpagespace;
2603 conf.maxwait
<- c.maxwait
;
2604 conf.hlinks
<- c.hlinks
;
2605 conf.beyecolumns
<- (
2606 match conf.columns
with
2607 | Cmulti
((c, _
, _
), _
) -> Some
c
2609 | Csplit _
-> assert false
2612 match c.columns
with
2613 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2614 | Csingle
-> Csingle
2615 | Csplit _
-> failwith
"leaving bird's eye split mode"
2620 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2623 reshape conf.winw
conf.winh
;
2624 state.anchor <- if goback
then anchor else (pageno, 0.0);
2627 let togglebirdseye () =
2628 match state.mode
with
2629 | Birdseye vals
-> leavebirdseye vals
true
2630 | View
-> enterbirdseye ()
2634 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2635 let pageno = max
0 (pageno - incr
) in
2636 let rec loop = function
2637 | [] -> gotopage1 pageno 0
2638 | l :: _
when l.pageno = pageno ->
2639 if l.pagedispy >= 0 && l.pagey = 0
2640 then G.postRedisplay "upbirdseye"
2641 else gotopage1 pageno 0
2642 | _
:: rest
-> loop rest
2645 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2648 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2649 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2650 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2651 let rec loop = function
2653 let y, h = getpageyh pageno in
2654 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2656 | l :: _
when l.pageno = pageno ->
2657 if l.pagevh != l.pageh
2658 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2659 else G.postRedisplay "downbirdseye"
2660 | _
:: rest
-> loop rest
2665 let optentry mode _
key =
2666 let btos b = if b then "on" else "off" in
2667 if key >= 32 && key < 127
2669 let c = Char.chr
key in
2673 try conf.scrollstep
<- int_of_string
s with exc
->
2674 state.text <- Printf.sprintf
"bad integer `%s': %s"
2675 s (Printexc.to_string exc
)
2677 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2682 conf.autoscrollstep
<- int_of_string
s;
2683 if state.autoscroll
<> None
2684 then state.autoscroll
<- Some
conf.autoscrollstep
2686 state.text <- Printf.sprintf
"bad integer `%s': %s"
2687 s (Printexc.to_string exc
)
2689 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2692 let mode = state.mode in
2695 let n, a, b = multicolumns_of_string s in
2696 setcolumns mode n a b;
2698 state.text <- Printf.sprintf
"bad columns `%s': %s"
2699 s (Printexc.to_string exc
)
2701 TEswitch
("columns: ", "", None
, textentry, ondone)
2706 let zoom = float (int_of_string
s) /. 100.0 in
2709 state.text <- Printf.sprintf
"bad integer `%s': %s"
2710 s (Printexc.to_string exc
)
2712 TEswitch
("zoom: ", "", None
, intentry, ondone)
2717 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2719 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2720 begin match mode with
2722 leavebirdseye beye
false;
2727 state.text <- Printf.sprintf
"bad integer `%s': %s"
2728 s (Printexc.to_string exc
)
2730 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2735 Some
(int_of_string
s)
2737 state.text <- Printf.sprintf
"bad integer `%s': %s"
2738 s (Printexc.to_string exc
);
2741 | Some angle
-> reqlayout angle
conf.proportional
2744 TEswitch
("rotation: ", "", None
, intentry, ondone)
2747 conf.icase
<- not
conf.icase
;
2748 TEdone
("case insensitive search " ^
(btos conf.icase
))
2751 conf.preload <- not
conf.preload;
2753 TEdone
("preload " ^
(btos conf.preload))
2756 conf.verbose
<- not
conf.verbose
;
2757 TEdone
("verbose " ^
(btos conf.verbose
))
2760 conf.debug
<- not
conf.debug
;
2761 TEdone
("debug " ^
(btos conf.debug
))
2764 conf.maxhfit
<- not
conf.maxhfit
;
2766 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2767 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2770 conf.crophack
<- not
conf.crophack
;
2771 TEdone
("crophack " ^
btos conf.crophack
)
2775 match conf.maxwait
with
2777 conf.maxwait
<- Some infinity
;
2778 "always wait for page to complete"
2780 conf.maxwait
<- None
;
2781 "show placeholder if page is not ready"
2786 conf.underinfo
<- not
conf.underinfo
;
2787 TEdone
("underinfo " ^
btos conf.underinfo
)
2790 conf.savebmarks
<- not
conf.savebmarks
;
2791 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2797 match state.layout with
2802 conf.interpagespace <- int_of_string
s;
2803 state.maxy <- calcheight ();
2804 let y = getpagey pageno in
2807 state.text <- Printf.sprintf
"bad integer `%s': %s"
2808 s (Printexc.to_string exc
)
2810 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2813 reqlayout conf.angle
(not
conf.proportional
);
2814 TEdone
("proportional display " ^
btos conf.proportional
)
2817 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2818 TEdone
("trim margins " ^
btos conf.trimmargins
)
2821 conf.invert
<- not
conf.invert
;
2822 TEdone
("invert colors " ^
btos conf.invert
)
2826 cbput state.hists
.sel
s;
2829 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2833 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2839 class type lvsource
= object
2840 method getitemcount
: int
2841 method getitem
: int -> (string * int)
2842 method hasaction
: int -> bool
2851 method getactive
: int
2852 method getfirst
: int
2853 method getqsearch
: string
2854 method setqsearch
: string -> unit
2858 class virtual lvsourcebase
= object
2859 val mutable m_active
= 0
2860 val mutable m_first
= 0
2861 val mutable m_qsearch
= ""
2862 val mutable m_pan
= 0
2863 method getactive
= m_active
2864 method getfirst
= m_first
2865 method getqsearch
= m_qsearch
2866 method getpan
= m_pan
2867 method setqsearch
s = m_qsearch
<- s
2870 let withoutlastutf8 s =
2871 let len = String.length
s in
2879 let b = Char.code
s.[pos
] in
2880 if b land 0b110000 = 0b11000000
2885 if Char.code
s.[len-1] land 0x80 = 0
2889 String.sub
s 0 first;
2892 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2894 state.mode <- Textentry
(te
, onleave
);
2897 G.postRedisplay "textentrykeyboard enttext";
2899 let histaction cmd
=
2902 | Some
(action, _
) ->
2903 state.mode <- Textentry
(
2904 (c, action cmd
, opthist
, onkey
, ondone), onleave
2906 G.postRedisplay "textentry histaction"
2909 | 0xff08 -> (* backspace *)
2910 let s = withoutlastutf8 text in
2911 let len = String.length
s in
2915 G.postRedisplay "textentrykeyboard after cancel";
2918 enttext (c, s, opthist
, onkey
, ondone)
2924 G.postRedisplay "textentrykeyboard after confirm"
2926 | 0xff52 -> histaction HCprev
2927 | 0xff54 -> histaction HCnext
2928 | 0xff50 -> histaction HCfirst
2929 | 0xff57 -> histaction HClast
2931 | 0xff1b -> (* escape*)
2932 if String.length
text = 0
2934 begin match opthist
with
2936 | Some
(_
, onhistcancel
) -> onhistcancel
()
2940 G.postRedisplay "textentrykeyboard after cancel2"
2943 enttext (c, "", opthist
, onkey
, ondone)
2946 | 0xff9f | 0xffff -> () (* delete *)
2948 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2949 begin match onkey
text key with
2953 G.postRedisplay "textentrykeyboard after confirm2";
2956 enttext (c, text, opthist
, onkey
, ondone);
2960 G.postRedisplay "textentrykeyboard after cancel3"
2963 state.mode <- Textentry
(te
, onleave
);
2964 G.postRedisplay "textentrykeyboard switch";
2968 vlog "unhandled key %s" (Wsi.keyname
key)
2971 let firstof first active
=
2972 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2973 then max
0 (active
- (fstate.maxrows
/2))
2977 let calcfirst first active
=
2980 let rows = active
- first in
2981 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2985 let scrollph y maxy =
2986 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2987 let sh = float conf.winh
/. sh in
2988 let sh = max
sh (float conf.scrollh
) in
2993 else float y /. float maxy
2995 let position = (float conf.winh
-. sh) *. percent in
2998 if position +. sh > float conf.winh
2999 then float conf.winh
-. sh
3005 let coe s = (s :> uioh
);;
3007 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3009 val m_pan
= source#getpan
3010 val m_first
= source#getfirst
3011 val m_active
= source#getactive
3012 val m_qsearch
= source#getqsearch
3013 val m_prev_uioh
= state.uioh
3015 method private elemunder
y =
3016 let n = y / (fstate.fontsize
+1) in
3017 if m_first
+ n < source#getitemcount
3019 if source#hasaction
(m_first
+ n)
3020 then Some
(m_first
+ n)
3027 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3028 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3029 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3030 GlDraw.color
(1., 1., 1.);
3031 Gl.enable `texture_2d
;
3032 let fs = fstate.fontsize
in
3034 let ww = fstate.wwidth
in
3035 let tabw = 30.0*.ww in
3036 let itemcount = source#getitemcount
in
3038 if (row - m_first
) * nfs > conf.winh
3041 if row >= 0 && row < itemcount
3043 let (s, level
) = source#getitem
row in
3044 let y = (row - m_first
) * nfs in
3045 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3048 Gl.disable `texture_2d
;
3049 GlDraw.polygon_mode `both `line
;
3050 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3051 GlDraw.rect (1., float (y + 1))
3052 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3053 GlDraw.polygon_mode `both `fill
;
3054 GlDraw.color
(1., 1., 1.);
3055 Gl.enable `texture_2d
;
3058 let drawtabularstring s =
3059 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3062 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3065 let len = String.length
s - tabpos - 1 in
3066 let s1 = String.sub
s 0 tabpos
3067 and s2
= String.sub
s (tabpos + 1) len in
3068 let nx = drawstr x s1 in
3070 let x = x +. (max
tabw sw) in
3077 let _ = drawtabularstring s in
3084 Gl.disable `texture_2d
;
3086 method updownlevel incr
=
3087 let len = source#getitemcount
in
3089 if m_active
>= 0 && m_active
< len
3090 then snd
(source#getitem m_active
)
3094 if i
= len then i
-1 else if i
= -1 then 0 else
3095 let _, l = source#getitem i
in
3096 if l != curlevel then i
else flow (i
+incr
)
3098 let active = flow m_active
in
3099 let first = calcfirst m_first
active in
3100 G.postRedisplay "outline updownlevel";
3101 {< m_active
= active; m_first
= first >}
3103 method private key1
key mask
=
3104 let set1 active first qsearch
=
3105 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3107 let search active pattern incr
=
3110 if n >= 0 && n < source#getitemcount
3112 let s, _ = source#getitem
n in
3114 (try ignore
(Str.search_forward
re s 0); true
3115 with Not_found
-> false)
3117 else loop (n + incr
)
3124 let re = Str.regexp_case_fold pattern
in
3130 let itemcount = source#getitemcount
in
3131 let find start incr
=
3133 if i
= -1 || i
= itemcount
3136 if source#hasaction i
3138 else find (i
+ incr
)
3143 let set active first =
3144 let first = bound first 0 (itemcount - fstate.maxrows
) in
3146 coe {< m_active
= active; m_first
= first >}
3149 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3151 let incr1 = if incr
> 0 then 1 else -1 in
3152 if isvisible m_first m_active
3155 let next = m_active
+ incr
in
3157 if next < 0 || next >= itemcount
3159 else find next incr1
3161 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3167 let first = m_first
+ incr
in
3168 let first = bound first 0 (itemcount - 1) in
3170 let next = m_active
+ incr
in
3171 let next = bound next 0 (itemcount - 1) in
3174 let active = if next = -1 then m_active
else next in
3177 let first = min
next m_first
in
3179 if abs
(next - first) > fstate.maxrows
3185 let first = m_first
+ incr
in
3186 let first = bound first 0 (itemcount - 1) in
3188 let next = m_active
+ incr
in
3189 let next = bound next 0 (itemcount - 1) in
3190 let next = find next incr1 in
3192 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3194 let active = if m_active
= -1 then next else m_active
in
3199 if isvisible first active
3205 G.postRedisplay "listview navigate";
3209 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3210 let incr = if key = 0x72 then -1 else 1 in
3212 match search (m_active
+ incr) m_qsearch
incr with
3214 state.text <- m_qsearch ^
" [not found]";
3217 state.text <- m_qsearch
;
3218 active, firstof m_first
active
3220 G.postRedisplay "listview ctrl-r/s";
3221 set1 active first m_qsearch
;
3223 | 0xff08 -> (* backspace *)
3224 if String.length m_qsearch
= 0
3227 let qsearch = withoutlastutf8 m_qsearch
in
3228 let len = String.length
qsearch in
3232 G.postRedisplay "listview empty qsearch";
3233 set1 m_active m_first
"";
3237 match search m_active
qsearch ~
-1 with
3239 state.text <- qsearch ^
" [not found]";
3242 state.text <- qsearch;
3243 active, firstof m_first
active
3245 G.postRedisplay "listview backspace qsearch";
3246 set1 active first qsearch
3249 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3250 let pattern = m_qsearch ^
Wsi.toutf8
key in
3252 match search m_active
pattern 1 with
3254 state.text <- pattern ^
" [not found]";
3257 state.text <- pattern;
3258 active, firstof m_first
active
3260 G.postRedisplay "listview qsearch add";
3261 set1 active first pattern;
3263 | 0xff1b -> (* escape *)
3265 if String.length m_qsearch
= 0
3267 G.postRedisplay "list view escape";
3270 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3272 | None
-> m_prev_uioh
3277 G.postRedisplay "list view kill qsearch";
3278 source#setqsearch
"";
3279 coe {< m_qsearch
= "" >}
3282 | 0xff0d -> (* return *)
3284 let self = {< m_qsearch
= "" >} in
3285 source#setqsearch
"";
3287 G.postRedisplay "listview enter";
3288 if m_active
>= 0 && m_active
< source#getitemcount
3290 source#exit
(coe self) false m_active m_first m_pan
"";
3293 source#exit
(coe self) true m_active m_first m_pan
"";
3296 begin match opt with
3297 | None
-> m_prev_uioh
3301 | 0xff9f | 0xffff -> (* delete *)
3304 | 0xff52 -> navigate ~
-1 (* up *)
3305 | 0xff54 -> navigate 1 (* down *)
3306 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3307 | 0xff56 -> navigate fstate.maxrows
(* next *)
3309 | 0xff53 -> (* right *)
3311 G.postRedisplay "listview right";
3312 coe {< m_pan
= m_pan
- 1 >}
3314 | 0xff51 -> (* left *)
3316 G.postRedisplay "listview left";
3317 coe {< m_pan
= m_pan
+ 1 >}
3319 | 0xff50 -> (* home *)
3320 let active = find 0 1 in
3321 G.postRedisplay "listview home";
3324 | 0xff57 -> (* end *)
3325 let first = max
0 (itemcount - fstate.maxrows
) in
3326 let active = find (itemcount - 1) ~
-1 in
3327 G.postRedisplay "listview end";
3330 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3334 dolog "listview unknown key %#x" key; coe self
3336 method key key mask
=
3337 match state.mode with
3338 | Textentry te
-> textentrykeyboard key mask te
; coe self
3339 | _ -> self#key1
key mask
3341 method button button down
x y _ =
3344 | 1 when x > conf.winw
- conf.scrollbw
->
3345 G.postRedisplay "listview scroll";
3348 let _, position, sh = self#
scrollph in
3349 if y > truncate
position && y < truncate
(position +. sh)
3351 state.mstate
<- Mscrolly
;
3355 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3356 let first = truncate
(s *. float source#getitemcount
) in
3357 let first = min source#getitemcount
first in
3358 Some
(coe {< m_first
= first; m_active
= first >})
3360 state.mstate
<- Mnone
;
3363 | 1 when not down
->
3364 begin match self#elemunder
y with
3366 G.postRedisplay "listview click";
3368 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3372 | n when (n == 4 || n == 5) && not down
->
3373 let len = source#getitemcount
in
3375 if n = 5 && m_first
+ fstate.maxrows
>= len
3379 let first = m_first
+ (if n == 4 then -1 else 1) in
3380 bound first 0 (len - 1)
3382 G.postRedisplay "listview wheel";
3383 Some
(coe {< m_first
= first >})
3388 | None
-> m_prev_uioh
3392 match state.mstate
with
3394 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3395 let first = truncate
(s *. float source#getitemcount
) in
3396 let first = min source#getitemcount
first in
3397 G.postRedisplay "listview motion";
3398 coe {< m_first
= first; m_active
= first >}
3401 method pmotion
x y =
3402 if x < conf.winw
- conf.scrollbw
3405 match self#elemunder
y with
3406 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3407 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3411 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3416 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3420 method infochanged
_ = ()
3422 method scrollpw
= (0, 0.0, 0.0)
3424 let nfs = fstate.fontsize
+ 1 in
3425 let y = m_first
* nfs in
3426 let itemcount = source#getitemcount
in
3427 let maxi = max
0 (itemcount - fstate.maxrows
) in
3428 let maxy = maxi * nfs in
3429 let p, h = scrollph y maxy in
3432 method modehash
= modehash
3435 class outlinelistview ~source
=
3438 ~source
:(source
:> lvsource
)
3440 ~modehash
:(findkeyhash conf "outline")
3443 method key key mask
=
3444 let calcfirst first active =
3447 let rows = active - first in
3448 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3452 let active = m_active
+ incr in
3453 let active = bound active 0 (source#getitemcount
- 1) in
3454 let first = calcfirst m_first
active in
3455 G.postRedisplay "outline navigate";
3456 coe {< m_active
= active; m_first
= first >}
3458 let ctrl = Wsi.withctrl mask
in
3460 | 110 when ctrl -> (* ctrl-n *)
3461 source#narrow m_qsearch
;
3462 G.postRedisplay "outline ctrl-n";
3463 coe {< m_first
= 0; m_active
= 0 >}
3465 | 117 when ctrl -> (* ctrl-u *)
3467 G.postRedisplay "outline ctrl-u";
3469 coe {< m_first
= 0; m_active
= 0 >}
3471 | 108 when ctrl -> (* ctrl-l *)
3472 let first = m_active
- (fstate.maxrows
/ 2) in
3473 G.postRedisplay "outline ctrl-l";
3474 coe {< m_first
= first >}
3476 | 0xff9f | 0xffff -> (* delete *)
3477 source#remove m_active
;
3478 G.postRedisplay "outline delete";
3479 let active = max
0 (m_active
-1) in
3480 coe {< m_first
= firstof m_first
active;
3481 m_active
= active >}
3483 | 0xff52 -> navigate ~
-1 (* up *)
3484 | 0xff54 -> navigate 1 (* down *)
3485 | 0xff55 -> (* prior *)
3486 navigate ~
-(fstate.maxrows
)
3487 | 0xff56 -> (* next *)
3488 navigate fstate.maxrows
3490 | 0xff53 -> (* [ctrl-]right *)
3494 G.postRedisplay "outline ctrl right";
3495 {< m_pan
= m_pan
+ 1 >}
3497 else self#updownlevel
1
3501 | 0xff51 -> (* [ctrl-]left *)
3505 G.postRedisplay "outline ctrl left";
3506 {< m_pan
= m_pan
- 1 >}
3508 else self#updownlevel ~
-1
3512 | 0xff50 -> (* home *)
3513 G.postRedisplay "outline home";
3514 coe {< m_first
= 0; m_active
= 0 >}
3516 | 0xff57 -> (* end *)
3517 let active = source#getitemcount
- 1 in
3518 let first = max
0 (active - fstate.maxrows
) in
3519 G.postRedisplay "outline end";
3520 coe {< m_active
= active; m_first
= first >}
3522 | _ -> super#
key key mask
3525 let outlinesource usebookmarks
=
3528 inherit lvsourcebase
3529 val mutable m_items
= empty
3530 val mutable m_orig_items
= empty
3531 val mutable m_prev_items
= empty
3532 val mutable m_narrow_pattern
= ""
3533 val mutable m_hadremovals
= false
3535 method getitemcount
=
3536 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3539 if n == Array.length m_items
&& m_hadremovals
3541 ("[Confirm removal]", 0)
3543 let s, n, _ = m_items
.(n) in
3546 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3547 ignore
(uioh
, first, qsearch);
3548 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3550 if String.length m_narrow_pattern
= 0
3556 if not
confrimremoval
3558 let _, _, anchor = m_items
.(active) in
3563 state.bookmarks
<- Array.to_list m_items
;
3564 m_orig_items
<- m_items
;
3567 else m_items
<- items;
3571 method hasaction
_ = true
3574 if Array.length m_items
!= Array.length m_orig_items
3575 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3578 method narrow
pattern =
3579 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3583 let rec loop accu n =
3586 m_narrow_pattern
<- pattern;
3587 m_items
<- Array.of_list
accu
3590 let (s, _, _) as o = m_items
.(n) in
3592 if (try ignore
(Str.search_forward
re s 0); true
3593 with Not_found
-> false)
3599 loop [] (Array.length m_items
- 1)
3604 then Array.of_list
state.bookmarks
3607 m_items
<- m_orig_items
3612 if m >= 0 && m < Array.length m_items
3614 m_hadremovals
<- true;
3615 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3616 let n = if n >= m then n+1 else n in
3621 method reset
anchor items =
3622 m_hadremovals
<- false;
3623 if m_orig_items
== empty || m_prev_items
!= items
3625 m_orig_items
<- items;
3626 if String.length m_narrow_pattern
= 0
3627 then m_items
<- items;
3629 m_prev_items
<- items;
3630 let rely = getanchory anchor in
3632 let rec loop n best bestd
=
3633 if n = Array.length m_items
3636 let (_, _, anchor) = m_items
.(n) in
3637 let orely = getanchory anchor in
3638 let d = abs
(orely - rely) in
3641 else loop (n+1) best bestd
3646 m_first
<- firstof m_first
active
3650 let enterselector usebookmarks
=
3651 let source = outlinesource usebookmarks
in
3655 then Array.of_list
state.bookmarks
3658 if Array.length
outlines = 0
3660 showtext ' ' errmsg
;
3663 state.text <- source#greetmsg
;
3664 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3665 let anchor = getanchor () in
3666 source#reset
anchor outlines;
3667 state.uioh
<- coe (new outlinelistview ~
source);
3668 G.postRedisplay "enter selector";
3672 let enteroutlinemode =
3673 let f = enterselector false in
3674 fun ()-> f "Document has no outline";
3677 let enterbookmarkmode =
3678 let f = enterselector true in
3679 fun () -> f "Document has no bookmarks (yet)";
3682 let color_of_string s =
3683 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3684 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3688 let color_to_string (r
, g
, b) =
3689 let r = truncate
(r *. 256.0)
3690 and g
= truncate
(g
*. 256.0)
3691 and b = truncate
(b *. 256.0) in
3692 Printf.sprintf
"%d/%d/%d" r g
b
3695 let irect_of_string s =
3696 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3699 let irect_to_string (x0,y0,x1,y1) =
3700 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3703 let makecheckers () =
3704 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3706 converted by Issac Trotts. July 25, 2002 *)
3707 let image_height = 64
3708 and image_width
= 64 in
3712 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3714 for i
= 0 to image_width
- 1 do
3715 for j
= 0 to image_height - 1 do
3716 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3717 (if (i
land 8 ) lxor (j
land 8) = 0
3718 then [|255;255;255|] else [|200;200;200|])
3723 let image = make_image () in
3724 let id = GlTex.gen_texture
() in
3725 GlTex.bind_texture `texture_2d
id;
3726 GlPix.store
(`unpack_alignment
1);
3727 GlTex.image2d
image;
3728 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3731 `mag_filter `nearest
;
3732 `min_filter `nearest
];
3736 let setcheckers enabled
=
3737 match state.texid
with
3739 if enabled
then state.texid
<- Some
(makecheckers ())
3744 GlTex.delete_texture texid
;
3745 state.texid
<- None
;
3749 let int_of_string_with_suffix s =
3750 let l = String.length
s in
3754 let suffix = Char.lowercase
s.[l-1] in
3756 | 'k'
-> String.sub
s 0 (l-1), 10
3757 | '
m'
-> String.sub
s 0 (l-1), 20
3758 | 'g'
-> String.sub
s 0 (l-1), 30
3762 let n = int_of_string
s1 in
3763 let m = n lsl shift
in
3765 then raise
(Failure
"value too large")
3769 let string_with_suffix_of_int n =
3777 if n land ((1 lsl 20) - 1) = 0
3780 if n land ((1 lsl 10) - 1) = 0
3787 let h = n mod 1000 in
3790 then string_of_int
h ^
s
3792 let s = Printf.sprintf
"_%03d%s" h s in
3799 let defghyllscroll = (40, 8, 32);;
3800 let ghyllscroll_of_string s =
3801 let (n, a, b) as nab
=
3804 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3806 if n <= a || n <= b || a >= b
3807 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3811 let ghyllscroll_to_string ((n, a, b) as nab
) =
3812 if nab
= defghyllscroll
3814 else Printf.sprintf
"%d,%d,%d" n a b;
3817 let describe_location () =
3819 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3821 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3822 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3826 else (100. *. (float state.y /. float maxy))
3830 Printf.sprintf
"page %d of %d [%.2f%%]"
3831 (fn+1) state.pagecount
percent
3834 "pages %d-%d of %d [%.2f%%]"
3835 (fn+1) (ln
+1) state.pagecount
percent
3839 let btos b = if b then "\xe2\x88\x9a" else "" in
3840 let showextended = ref false in
3841 let leave mode = function
3842 | Confirm
-> state.mode <- mode
3843 | Cancel
-> state.mode <- mode in
3846 val mutable m_first_time
= true
3847 val mutable m_l
= []
3848 val mutable m_a
= [||]
3849 val mutable m_prev_uioh
= nouioh
3850 val mutable m_prev_mode
= View
3852 inherit lvsourcebase
3854 method reset prev_mode prev_uioh
=
3855 m_a
<- Array.of_list
(List.rev m_l
);
3857 m_prev_mode
<- prev_mode
;
3858 m_prev_uioh
<- prev_uioh
;
3862 if n >= Array.length m_a
3866 | _, _, _, Action
_ -> m_active
<- n
3870 m_first_time
<- false;
3873 method int name get
set =
3875 (name
, `
int get
, 1, Action
(
3878 try set (int_of_string
s)
3880 state.text <- Printf.sprintf
"bad integer `%s': %s"
3881 s (Printexc.to_string exn
)
3884 let te = name ^
": ", "", None
, intentry, ondone in
3885 state.mode <- Textentry
(te, leave m_prev_mode
);
3889 method int_with_suffix name get
set =
3891 (name
, `intws get
, 1, Action
(
3894 try set (int_of_string_with_suffix s)
3896 state.text <- Printf.sprintf
"bad integer `%s': %s"
3897 s (Printexc.to_string exn
)
3901 name ^
": ", "", None
, intentry_with_suffix, ondone
3903 state.mode <- Textentry
(te, leave m_prev_mode
);
3907 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3909 (name
, `
bool (btos, get
), offset
, Action
(
3916 method color name get
set =
3918 (name
, `color get
, 1, Action
(
3920 let invalid = (nan
, nan
, nan
) in
3923 try color_of_string s
3925 state.text <- Printf.sprintf
"bad color `%s': %s"
3926 s (Printexc.to_string exn
);
3932 let te = name ^
": ", "", None
, textentry, ondone in
3933 state.text <- color_to_string (get
());
3934 state.mode <- Textentry
(te, leave m_prev_mode
);
3938 method string name get
set =
3940 (name
, `
string get
, 1, Action
(
3942 let ondone s = set s in
3943 let te = name ^
": ", "", None
, textentry, ondone in
3944 state.mode <- Textentry
(te, leave m_prev_mode
);
3948 method colorspace name get
set =
3950 (name
, `
string get
, 1, Action
(
3953 let vals = [| "rgb"; "bgr"; "gray" |] in
3955 inherit lvsourcebase
3958 m_active
<- int_of_colorspace conf.colorspace
;
3961 method getitemcount
= Array.length
vals
3962 method getitem
n = (vals.(n), 0)
3963 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3964 ignore
(uioh
, first, pan
, qsearch);
3965 if not cancel
then set active;
3967 method hasaction
_ = true
3971 let modehash = findkeyhash conf "info" in
3972 coe (new listview ~
source ~trusted
:true ~
modehash)
3975 method caption
s offset
=
3976 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3978 method caption2
s f offset
=
3979 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3981 method getitemcount
= Array.length m_a
3984 let tostr = function
3985 | `
int f -> string_of_int
(f ())
3986 | `intws
f -> string_with_suffix_of_int (f ())
3988 | `color
f -> color_to_string (f ())
3989 | `
bool (btos, f) -> btos (f ())
3992 let name, t
, offset
, _ = m_a
.(n) in
3993 ((let s = tostr t
in
3994 if String.length
s > 0
3995 then Printf.sprintf
"%s\t%s" name s
3999 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4003 m_qsearch
<- qsearch;
4005 match m_a
.(active) with
4006 | _, _, _, Action
f -> f uioh
4018 method hasaction
n =
4020 | _, _, _, Action
_ -> true
4024 let rec fillsrc prevmode prevuioh
=
4025 let sep () = src#caption
"" 0 in
4026 let colorp name get
set =
4028 (fun () -> color_to_string (get
()))
4031 let c = color_of_string v in
4034 state.text <- Printf.sprintf
"bad color `%s': %s"
4035 v (Printexc.to_string exn
);
4038 let oldmode = state.mode in
4039 let birdseye = isbirdseye state.mode in
4041 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4043 src#
bool "presentation mode"
4044 (fun () -> conf.presentation)
4046 conf.presentation <- v;
4047 state.anchor <- getanchor ();
4050 src#
bool "ignore case in searches"
4051 (fun () -> conf.icase
)
4052 (fun v -> conf.icase
<- v);
4055 (fun () -> conf.preload)
4056 (fun v -> conf.preload <- v);
4058 src#
bool "highlight links"
4059 (fun () -> conf.hlinks
)
4060 (fun v -> conf.hlinks
<- v);
4062 src#
bool "under info"
4063 (fun () -> conf.underinfo
)
4064 (fun v -> conf.underinfo
<- v);
4066 src#
bool "persistent bookmarks"
4067 (fun () -> conf.savebmarks
)
4068 (fun v -> conf.savebmarks
<- v);
4070 src#
bool "proportional display"
4071 (fun () -> conf.proportional
)
4072 (fun v -> reqlayout conf.angle
v);
4074 src#
bool "trim margins"
4075 (fun () -> conf.trimmargins
)
4076 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4078 src#
bool "persistent location"
4079 (fun () -> conf.jumpback
)
4080 (fun v -> conf.jumpback
<- v);
4083 src#
int "inter-page space"
4084 (fun () -> conf.interpagespace)
4086 conf.interpagespace <- n;
4088 match state.layout with
4093 state.maxy <- calcheight ();
4094 let y = getpagey pageno in
4099 (fun () -> conf.pagebias
)
4100 (fun v -> conf.pagebias
<- v);
4102 src#
int "scroll step"
4103 (fun () -> conf.scrollstep
)
4104 (fun n -> conf.scrollstep
<- n);
4106 src#
int "auto scroll step"
4108 match state.autoscroll
with
4110 | _ -> conf.autoscrollstep
)
4112 if state.autoscroll
<> None
4113 then state.autoscroll
<- Some
n;
4114 conf.autoscrollstep
<- n);
4117 (fun () -> truncate
(conf.zoom *. 100.))
4118 (fun v -> setzoom ((float v) /. 100.));
4121 (fun () -> conf.angle
)
4122 (fun v -> reqlayout v conf.proportional
);
4124 src#
int "scroll bar width"
4125 (fun () -> state.scrollw
)
4129 reshape conf.winw
conf.winh
;
4132 src#
int "scroll handle height"
4133 (fun () -> conf.scrollh
)
4134 (fun v -> conf.scrollh
<- v;);
4136 src#
int "thumbnail width"
4137 (fun () -> conf.thumbw
)
4139 conf.thumbw
<- min
4096 v;
4142 leavebirdseye beye
false;
4147 let mode = state.mode in
4148 src#
string "columns"
4150 match conf.columns
with
4152 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4153 | Csplit
(count
, _) -> "-" ^ string_of_int count
4156 let n, a, b = multicolumns_of_string v in
4157 setcolumns mode n a b);
4160 src#caption
"Presentation mode" 0;
4161 src#
bool "scrollbar visible"
4162 (fun () -> conf.scrollbarinpm
)
4164 if v != conf.scrollbarinpm
4166 conf.scrollbarinpm
<- v;
4167 if conf.presentation
4169 state.scrollw
<- if v then conf.scrollbw
else 0;
4170 reshape conf.winw
conf.winh
;
4176 src#caption
"Pixmap cache" 0;
4177 src#int_with_suffix
"size (advisory)"
4178 (fun () -> conf.memlimit
)
4179 (fun v -> conf.memlimit
<- v);
4182 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4183 (string_with_suffix_of_int state.memused
)
4184 (Hashtbl.length
state.tilemap
)) 1;
4187 src#caption
"Layout" 0;
4188 src#caption2
"Dimension"
4190 Printf.sprintf
"%dx%d (virtual %dx%d)"
4196 src#caption2
"Position" (fun () ->
4197 Printf.sprintf
"%dx%d" state.x state.y
4200 src#caption2
"Visible" (fun () -> describe_location ()) 1
4204 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4205 "Save these parameters as global defaults at exit"
4206 (fun () -> conf.bedefault
)
4207 (fun v -> conf.bedefault
<- v)
4211 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4212 src#
bool ~offset
:0 ~
btos "Extended parameters"
4213 (fun () -> !showextended)
4214 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4218 (fun () -> conf.checkers
)
4219 (fun v -> conf.checkers
<- v; setcheckers v);
4220 src#
bool "update cursor"
4221 (fun () -> conf.updatecurs
)
4222 (fun v -> conf.updatecurs
<- v);
4224 (fun () -> conf.verbose
)
4225 (fun v -> conf.verbose
<- v);
4226 src#
bool "invert colors"
4227 (fun () -> conf.invert
)
4228 (fun v -> conf.invert
<- v);
4230 (fun () -> conf.maxhfit
)
4231 (fun v -> conf.maxhfit
<- v);
4232 src#
bool "redirect stderr"
4233 (fun () -> conf.redirectstderr)
4234 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4235 src#
string "uri launcher"
4236 (fun () -> conf.urilauncher
)
4237 (fun v -> conf.urilauncher
<- v);
4238 src#
string "path launcher"
4239 (fun () -> conf.pathlauncher
)
4240 (fun v -> conf.pathlauncher
<- v);
4241 src#
string "tile size"
4242 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4245 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4246 conf.tilew
<- max
64 w;
4247 conf.tileh
<- max
64 h;
4250 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4251 v (Printexc.to_string exn
));
4252 src#
int "texture count"
4253 (fun () -> conf.texcount
)
4256 then conf.texcount
<- v
4257 else showtext '
!'
" Failed to set texture count please retry later"
4259 src#
int "slice height"
4260 (fun () -> conf.sliceheight
)
4262 conf.sliceheight
<- v;
4263 wcmd "sliceh %d" conf.sliceheight
;
4265 src#
int "anti-aliasing level"
4266 (fun () -> conf.aalevel
)
4268 conf.aalevel
<- bound v 0 8;
4269 state.anchor <- getanchor ();
4270 opendoc state.path
state.password
;
4272 src#
int "ui font size"
4273 (fun () -> fstate.fontsize
)
4274 (fun v -> setfontsize (bound v 5 100));
4275 colorp "background color"
4276 (fun () -> conf.bgcolor
)
4277 (fun v -> conf.bgcolor
<- v);
4278 src#
bool "crop hack"
4279 (fun () -> conf.crophack
)
4280 (fun v -> conf.crophack
<- v);
4281 src#
string "trim fuzz"
4282 (fun () -> irect_to_string conf.trimfuzz
)
4285 conf.trimfuzz
<- irect_of_string v;
4287 then settrim true conf.trimfuzz
;
4289 state.text <- Printf.sprintf
"bad irect `%s': %s"
4290 v (Printexc.to_string exn
)
4292 src#
string "throttle"
4294 match conf.maxwait
with
4295 | None
-> "show place holder if page is not ready"
4298 then "wait for page to fully render"
4300 "wait " ^ string_of_float
time
4301 ^
" seconds before showing placeholder"
4305 let f = float_of_string
v in
4307 then conf.maxwait
<- None
4308 else conf.maxwait
<- Some
f
4310 state.text <- Printf.sprintf
"bad time `%s': %s"
4311 v (Printexc.to_string exn
)
4313 src#
string "ghyll scroll"
4315 match conf.ghyllscroll
with
4317 | Some nab
-> ghyllscroll_to_string nab
4322 if String.length
v = 0
4324 else Some
(ghyllscroll_of_string v)
4326 conf.ghyllscroll
<- gs
4328 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4329 v (Printexc.to_string exn
)
4331 src#
string "selection command"
4332 (fun () -> conf.selcmd
)
4333 (fun v -> conf.selcmd
<- v);
4334 src#colorspace
"color space"
4335 (fun () -> colorspace_to_string conf.colorspace
)
4337 conf.colorspace
<- colorspace_of_int v;
4344 src#caption
"Document" 0;
4345 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4346 src#caption2
"Pages"
4347 (fun () -> string_of_int
state.pagecount
) 1;
4348 src#caption2
"Dimensions"
4349 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4353 src#caption
"Trimmed margins" 0;
4354 src#caption2
"Dimensions"
4355 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4358 src#reset prevmode prevuioh
;
4362 let prevmode = state.mode
4363 and prevuioh
= state.uioh in
4364 fillsrc prevmode prevuioh
;
4365 let source = (src :> lvsource
) in
4366 let modehash = findkeyhash conf "info" in
4367 state.uioh <- coe (object (self)
4368 inherit listview ~
source ~trusted
:true ~
modehash as super
4369 val mutable m_prevmemused
= 0
4370 method infochanged
= function
4372 if m_prevmemused
!= state.memused
4374 m_prevmemused
<- state.memused
;
4375 G.postRedisplay "memusedchanged";
4377 | Pdim
-> G.postRedisplay "pdimchanged"
4378 | Docinfo
-> fillsrc prevmode prevuioh
4380 method key key mask
=
4381 if not
(Wsi.withctrl mask
)
4384 | 0xff51 -> coe (self#updownlevel ~
-1)
4385 | 0xff53 -> coe (self#updownlevel
1)
4386 | _ -> super#
key key mask
4387 else super#
key key mask
4389 G.postRedisplay "info";
4395 inherit lvsourcebase
4396 method getitemcount
= Array.length
state.help
4398 let s, n, _ = state.help
.(n) in
4401 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4405 m_qsearch
<- qsearch;
4406 match state.help
.(active) with
4407 | _, _, Action
f -> Some
(f uioh)
4417 method hasaction
n =
4418 match state.help
.(n) with
4419 | _, _, Action
_ -> true
4426 let modehash = findkeyhash conf "help" in
4427 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4428 G.postRedisplay "help";
4433 let re = Str.regexp
"[\r\n]" in
4435 inherit lvsourcebase
4436 val mutable m_items
= [||]
4438 method getitemcount
= 1 + Array.length m_items
4443 else m_items
.(n-1), 0
4445 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4450 then Buffer.clear
state.errmsgs
;
4451 m_qsearch
<- qsearch;
4458 method hasaction
n =
4462 state.newerrmsgs
<- false;
4463 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4464 m_items
<- Array.of_list
l
4472 let source = (msgsource :> lvsource
) in
4473 let modehash = findkeyhash conf "listview" in
4474 state.uioh <- coe (object
4475 inherit listview ~
source ~trusted
:false ~
modehash as super
4478 then msgsource#reset
;
4481 G.postRedisplay "msgs";
4484 let quickbookmark ?title
() =
4485 match state.layout with
4491 let sec = Unix.gettimeofday
() in
4492 let tm = Unix.localtime
sec in
4493 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4497 (tm.Unix.tm_year
+ 1900)
4500 | Some
title -> title
4503 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4508 state.fullscreen
<- None
;
4512 let setautoscrollspeed step goingdown
=
4513 let incr = max
1 ((abs step
) / 2) in
4514 let incr = if goingdown
then incr else -incr in
4515 let astep = step
+ incr in
4516 state.autoscroll
<- Some
astep;
4519 let gotounder = function
4520 | Ulinkgoto
(pageno, top) ->
4524 gotopage1 pageno top;
4530 | Uremote
(filename
, pageno) ->
4532 if Sys.file_exists filename
4535 let dir = Filename.dirname
state.path in
4536 let path = Filename.concat
dir filename
in
4537 if Sys.file_exists
path
4541 if String.length
path > 0
4543 let anchor = getanchor () in
4544 let ranchor = state.path, state.password
, anchor in
4545 state.anchor <- (pageno, 0.0);
4546 state.ranchors
<- ranchor :: state.ranchors
;
4549 else showtext '
!'
("Could not find " ^ filename
)
4551 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4555 match conf.columns
with
4557 | _ -> conf.zoom > 1.0
4560 let viewkeyboard key mask
=
4562 let mode = state.mode in
4563 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4566 G.postRedisplay "view:enttext"
4568 let ctrl = Wsi.withctrl mask
in
4573 | 0xff63 -> (* insert *)
4574 if conf.angle
mod 360 = 0
4576 state.mode <- LinkNav
(Ltgendir
0);
4579 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4581 | 0xff1b | 113 -> (* escape / q *)
4582 begin match state.mstate
with
4584 state.mstate
<- Mnone
;
4585 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4586 G.postRedisplay "kill zoom rect";
4588 match state.ranchors
with
4590 | (path, password
, anchor) :: rest
->
4591 state.ranchors
<- rest
;
4592 state.anchor <- anchor;
4593 opendoc path password
4596 | 0xff08 -> (* backspace *)
4597 let y = getnav ~
-1 in
4598 gotoy_and_clear_text y
4606 G.postRedisplay "dehighlight";
4608 | 47 | 63 -> (* / ? *)
4609 let ondone isforw
s =
4610 cbput state.hists
.pat
s;
4611 state.searchpattern
<- s;
4614 let s = String.create
1 in
4615 s.[0] <- Char.chr
key;
4616 enttext (s, "", Some
(onhist state.hists
.pat
),
4617 textentry, ondone (key = 47))
4619 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4620 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4621 setzoom (conf.zoom +. incr)
4623 | 43 | 0xffab -> (* + *)
4626 try int_of_string
s with exc
->
4627 state.text <- Printf.sprintf
"bad integer `%s': %s"
4628 s (Printexc.to_string exc
);
4634 state.text <- "page bias is now " ^ string_of_int
n;
4637 enttext ("page bias: ", "", None
, intentry, ondone)
4639 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4640 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4641 setzoom (max
0.01 (conf.zoom -. decr))
4643 | 45 | 0xffad -> (* - *)
4644 let ondone msg
= state.text <- msg
in
4646 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4647 optentry state.mode, ondone
4650 | 48 when ctrl -> (* ctrl-0 *)
4653 | 49 when ctrl -> (* 1 *)
4654 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4658 | 0xffc6 -> (* f9 *)
4661 | 57 when ctrl -> (* ctrl-9 *)
4664 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4665 when not
ctrl -> (* 0..9 *)
4668 try int_of_string
s with exc
->
4669 state.text <- Printf.sprintf
"bad integer `%s': %s"
4670 s (Printexc.to_string exc
);
4676 cbput state.hists
.pag
(string_of_int
n);
4677 gotopage1 (n + conf.pagebias
- 1) 0;
4680 let pageentry text key =
4681 match Char.unsafe_chr
key with
4682 | 'g'
-> TEdone
text
4683 | _ -> intentry text key
4685 let text = "x" in text.[0] <- Char.chr
key;
4686 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4689 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4690 reshape conf.winw
conf.winh
;
4693 conf.hlinks
<- not
conf.hlinks
;
4694 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4695 G.postRedisplay "toggle highlightlinks";
4698 state.glinks
<- true;
4699 let mode = state.mode in
4700 state.mode <- Textentry
(
4701 (":", "", None
, linknentry, linkndone (fun under ->
4706 state.glinks
<- false;
4710 G.postRedisplay "view:linkent(F)"
4713 state.glinks
<- true;
4714 let mode = state.mode in
4715 state.mode <- Textentry
(
4716 (":", "", None
, linknentry, linkndone (fun under ->
4721 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4722 (Printexc.to_string exn
));
4728 popen conf.selcmd
[r, 0; w, -1]
4731 (Printf.sprintf
"failed to execute %s: %s"
4732 conf.selcmd
(Printexc.to_string exn
))
4737 showtext '
!'
(Printf.sprintf
"failed to close %s: %s"
4738 cap (Printexc.to_string exn
))
4740 let s = undertext under in
4742 let l = String.length
s in
4743 let n = Unix.write
w s 0 l in
4748 "failed to write %d characters to sel pipe, wrote %d"
4753 (Printf.sprintf
"failed to write to sel pipe: %s"
4754 (Printexc.to_string exn
)
4763 state.glinks
<- false;
4767 G.postRedisplay "view:linkent"
4770 begin match state.autoscroll
with
4772 conf.autoscrollstep
<- step
;
4773 state.autoscroll
<- None
4775 if conf.autoscrollstep
= 0
4776 then state.autoscroll
<- Some
1
4777 else state.autoscroll
<- Some
conf.autoscrollstep
4780 | 112 when ctrl -> (* ctrl-p *)
4784 conf.presentation <- not
conf.presentation;
4785 if conf.presentation
4787 if not
conf.scrollbarinpm
4788 then state.scrollw
<- 0;
4791 state.scrollw
<- conf.scrollbw
;
4793 showtext ' '
("presentation mode " ^
4794 if conf.presentation then "on" else "off");
4795 state.anchor <- getanchor ();
4799 begin match state.fullscreen
with
4801 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4804 state.fullscreen
<- None
;
4809 gotoy_and_clear_text 0
4812 gotopage1 (state.pagecount
- 1) 0
4814 | 112 | 78 -> (* p|N *)
4815 search state.searchpattern
false
4817 | 110 | 0xffc0 -> (* n|F3 *)
4818 search state.searchpattern
true
4821 begin match state.layout with
4824 gotoy_and_clear_text (getpagey l.pageno)
4828 begin match List.rev
state.layout with
4831 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4832 gotoy_and_clear_text (getpagey pageno)
4835 | 0xff9f | 0xffff -> (* delete *)
4836 begin match state.layout with
4839 let pageno = max
0 (l.pageno-1) in
4840 gotoy_and_clear_text (getpagey pageno)
4844 showtext ' '
(describe_location ());
4847 begin match state.layout with
4850 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4855 enterbookmarkmode ()
4857 | 104 | 0xffbe -> (* h|F1 *)
4863 | 101 when conf.redirectstderr -> (* e *)
4868 match state.layout with
4871 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4875 enttext ("bookmark: ", "", None
, textentry, ondone)
4879 showtext ' '
"Quick bookmark added";
4882 begin match state.layout with
4884 let rect = getpdimrect
l.pagedimno
in
4888 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4889 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4891 (truncate
(rect.(1) -. rect.(0)),
4892 truncate
(rect.(3) -. rect.(0)))
4894 let w = truncate
((float w)*.conf.zoom)
4895 and h = truncate
((float h)*.conf.zoom) in
4898 state.anchor <- getanchor ();
4899 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4901 G.postRedisplay "z";
4906 | 50 when ctrl -> (* ctrl-2 *)
4907 let maxw = getmaxw
() in
4909 then setzoom (maxw /. float conf.winw
)
4911 | 60 | 62 -> (* < > *)
4912 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4914 | 91 | 93 -> (* [ ] *)
4916 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4918 G.postRedisplay "brightness";
4920 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4921 setzoom state.prevzoom
4923 | 107 | 0xff52 -> (* k up *)
4924 begin match state.autoscroll
with
4926 begin match state.mode with
4927 | Birdseye beye
-> upbirdseye 1 beye
4930 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4931 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4934 setautoscrollspeed n false
4937 | 106 | 0xff54 -> (* j down *)
4938 begin match state.autoscroll
with
4940 begin match state.mode with
4941 | Birdseye beye
-> downbirdseye 1 beye
4944 then gotoy_and_clear_text (clamp (conf.winh
/2))
4945 else gotoy_and_clear_text (clamp conf.scrollstep
)
4948 setautoscrollspeed n true
4951 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4959 let dx = if key = 0xff51 then dx else -dx in
4960 state.x <- state.x + dx;
4961 gotoy_and_clear_text state.y
4964 G.postRedisplay "lef/right"
4967 | 0xff55 -> (* prior *)
4971 match state.layout with
4973 | l :: _ -> state.y - l.pagey
4979 | 0xff56 -> (* next *)
4983 match List.rev
state.layout with
4985 | l :: _ -> getpagey l.pageno
4991 | 0xff50 -> gotoghyll 0
4992 | 0xff57 -> gotoghyll (clamp state.maxy)
4993 | 0xff53 when Wsi.withalt mask
->
4994 gotoghyll (getnav ~
-1)
4995 | 0xff51 when Wsi.withalt mask
->
4996 gotoghyll (getnav 1)
4999 state.anchor <- getanchor ();
5000 opendoc state.path state.password
5002 | 118 when conf.debug
-> (* v *)
5005 match getopaque l.pageno with
5008 let x0, y0, x1, y1 = pagebbox opaque
in
5009 let a,b = float x0, float y0 in
5010 let c,d = float x1, float y0 in
5011 let e,f = float x1, float y1 in
5012 let h,j
= float x0, float y1 in
5013 let rect = (a,b,c,d,e,f,h,j
) in
5015 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5017 G.postRedisplay "v";
5020 vlog "huh? %s" (Wsi.keyname
key)
5023 let linknavkeyboard key mask
linknav =
5024 let getpage pageno =
5025 let rec loop = function
5027 | l :: _ when l.pageno = pageno -> Some
l
5028 | _ :: rest
-> loop rest
5029 in loop state.layout
5031 let doexact (pageno, n) =
5032 match getopaque pageno, getpage pageno with
5033 | Some opaque
, Some
l ->
5036 let under = getlink opaque
n in
5037 G.postRedisplay "link gotounder";
5043 | 0xff50 -> (* home *)
5044 Some
(findlink opaque LDfirst
), -1
5046 | 0xff57 -> (* end *)
5047 Some
(findlink opaque LDlast
), 1
5049 | 0xff51 -> (* left *)
5050 Some
(findlink opaque
(LDleft
n)), -1
5052 | 0xff53 -> (* right *)
5053 Some
(findlink opaque
(LDright
n)), 1
5055 | 0xff52 -> (* up *)
5056 Some
(findlink opaque
(LDup
n)), -1
5058 | 0xff54 -> (* down *)
5059 Some
(findlink opaque
(LDdown
n)), 1
5064 begin match findpwl
l.pageno dir with
5068 state.mode <- LinkNav
(Ltgendir
dir);
5069 let y, h = getpageyh pageno in
5072 then y + h - conf.winh
5077 begin match getopaque pageno, getpage pageno with
5078 | Some opaque
, Some
_ ->
5080 let ld = if dir > 0 then LDfirst
else LDlast
in
5083 begin match link with
5085 showlinktype (getlink opaque
m);
5086 state.mode <- LinkNav
(Ltexact
(pageno, m));
5087 G.postRedisplay "linknav jpage";
5094 begin match opt with
5095 | Some Lnotfound
-> pwl l dir;
5096 | Some
(Lfound
m) ->
5100 let _, y0, _, y1 = getlinkrect opaque
m in
5102 then gotopage1 l.pageno y0
5104 let d = fstate.fontsize
+ 1 in
5105 if y1 - l.pagey > l.pagevh - d
5106 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5107 else G.postRedisplay "linknav";
5109 showlinktype (getlink opaque
m);
5110 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5113 | None
-> viewkeyboard key mask
5115 | _ -> viewkeyboard key mask
5120 G.postRedisplay "leave linknav"
5124 | Ltgendir
_ -> viewkeyboard key mask
5125 | Ltexact exact
-> doexact exact
5128 let keyboard key mask
=
5129 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5130 then wcmd "interrupt"
5131 else state.uioh <- state.uioh#
key key mask
5134 let birdseyekeyboard key mask
5135 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5137 match conf.columns
with
5139 | Cmulti
((c, _, _), _) -> c
5140 | Csplit
_ -> failwith
"bird's eye split mode"
5143 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5144 let y, h = getpageyh pageno in
5145 let top = (conf.winh
- h) / 2 in
5146 gotoy (max
0 (y - top))
5147 | 0xff0d -> leavebirdseye beye
false
5148 | 0xff1b -> leavebirdseye beye
true (* escape *)
5149 | 0xff52 -> upbirdseye incr beye
(* prior *)
5150 | 0xff54 -> downbirdseye incr beye
(* next *)
5151 | 0xff51 -> upbirdseye 1 beye
(* up *)
5152 | 0xff53 -> downbirdseye 1 beye
(* down *)
5155 begin match state.layout with
5159 state.mode <- Birdseye
(
5160 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5162 gotopage1 l.pageno 0;
5165 let layout = layout (state.y-conf.winh
) conf.winh
in
5167 | [] -> gotoy (clamp (-conf.winh
))
5169 state.mode <- Birdseye
(
5170 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5172 gotopage1 l.pageno 0
5175 | [] -> gotoy (clamp (-conf.winh
))
5179 begin match List.rev
state.layout with
5181 let layout = layout (state.y + conf.winh
) conf.winh
in
5182 begin match layout with
5184 let incr = l.pageh
- l.pagevh in
5189 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5191 G.postRedisplay "birdseye pagedown";
5193 else gotoy (clamp (incr + conf.interpagespace*2));
5197 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5198 gotopage1 l.pageno 0;
5201 | [] -> gotoy (clamp conf.winh
)
5205 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5209 let pageno = state.pagecount
- 1 in
5210 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5211 if not
(pagevisible state.layout pageno)
5214 match List.rev
state.pdims
with
5216 | (_, _, h, _) :: _ -> h
5218 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5219 else G.postRedisplay "birdseye end";
5220 | _ -> viewkeyboard key mask
5223 let drawpage l linkindexbase
=
5225 match state.mode with
5226 | Textentry
_ -> scalecolor 0.4
5228 | View
-> scalecolor 1.0
5229 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5230 if l.pageno = hooverpageno
5233 if l.pageno = pageno
5239 begin match getopaque l.pageno with
5241 if tileready l l.pagex l.pagey
5243 let x = l.pagedispx - l.pagex
5244 and y = l.pagedispy - l.pagey in
5245 let hlmask = (if conf.hlinks
then 1 else 0)
5246 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5249 match state.mode with
5250 | Textentry
((_, s, _, _, _), _) when state.glinks
-> s
5253 postprocess opaque
hlmask x y (linkindexbase
, s);
5260 let scrollindicator () =
5261 let sbw, ph
, sh = state.uioh#
scrollph in
5262 let sbh, pw, sw = state.uioh#scrollpw
in
5264 GlDraw.color (0.64, 0.64, 0.64);
5266 (float (conf.winw
- sbw), 0.)
5267 (float conf.winw
, float conf.winh
)
5270 (0., float (conf.winh
- sbh))
5271 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5273 GlDraw.color (0.0, 0.0, 0.0);
5276 (float (conf.winw
- sbw), ph
)
5277 (float conf.winw
, ph
+. sh)
5280 (pw, float (conf.winh
- sbh))
5281 (pw +. sw, float conf.winh
)
5286 match state.mstate
with
5287 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5290 | Msel
((x0, y0), (x1, y1)) ->
5291 let rec loop = function
5293 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5294 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5295 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5296 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5298 match getopaque l.pageno with
5300 let x0, y0 = pagetranslatepoint l x0 y0 in
5301 let x1, y1 = pagetranslatepoint l x1 y1 in
5302 seltext opaque
(x0, y0, x1, y1);
5310 let showrects rects
=
5312 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5313 GlDraw.polygon_mode `both `fill
;
5314 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5316 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5318 if l.pageno = pageno
5320 let dx = float (l.pagedispx - l.pagex) in
5321 let dy = float (l.pagedispy - l.pagey) in
5322 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5323 GlDraw.begins `quads
;
5325 GlDraw.vertex2
(x0+.dx, y0+.dy);
5326 GlDraw.vertex2
(x1+.dx, y1+.dy);
5327 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5328 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5339 GlClear.color (scalecolor2 conf.bgcolor
);
5340 GlClear.clear
[`
color];
5341 let rec loop linkindexbase
= function
5343 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5344 loop linkindexbase rest
5347 loop 0 state.layout;
5349 match state.mode with
5350 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5351 begin match getopaque pageno with
5353 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5360 | None
-> state.rects
5367 begin match state.mstate
with
5368 | Mzoomrect
((x0, y0), (x1, y1)) ->
5370 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5371 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5372 GlDraw.rect (float x0, float y0)
5373 (float x1, float y1);
5382 let zoomrect x y x1 y1 =
5385 and y0 = min
y y1 in
5386 gotoy (state.y + y0);
5387 state.anchor <- getanchor ();
5388 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5390 if state.w < conf.winw
- state.scrollw
5391 then (conf.winw
- state.scrollw
- state.w) / 2
5394 state.x <- (state.x + margin) - x0;
5396 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5397 state.mstate
<- Mnone
;
5401 let winw = conf.winw - state.scrollw
- 1 in
5402 let s = float x /. float winw in
5403 let destx = truncate
(float (state.w + winw) *. s) in
5404 state.x <- winw - destx;
5405 gotoy_and_clear_text state.y;
5406 state.mstate
<- Mscrollx
;
5410 let s = float y /. float conf.winh
in
5411 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5412 gotoy_and_clear_text desty;
5413 state.mstate
<- Mscrolly
;
5416 let viewmouse button down
x y mask
=
5418 | n when (n == 4 || n == 5) && not down
->
5419 if Wsi.withctrl mask
5421 match state.mstate
with
5422 | Mzoom
(oldn
, i
) ->
5430 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5432 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5434 let zoom = conf.zoom -. incr in
5436 state.mstate
<- Mzoom
(n, 0);
5438 state.mstate
<- Mzoom
(n, i
+1);
5440 else state.mstate
<- Mzoom
(n, 0)
5442 | _ -> state.mstate
<- Mzoom
(n, 0)
5445 match state.autoscroll
with
5446 | Some step
-> setautoscrollspeed step
(n=4)
5450 then -conf.scrollstep
5451 else conf.scrollstep
5453 let incr = incr * 2 in
5454 let y = clamp incr in
5455 gotoy_and_clear_text y
5458 | 1 when Wsi.withctrl mask
->
5461 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5462 state.mstate
<- Mpan
(x, y)
5465 state.mstate
<- Mnone
5470 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5472 state.mstate
<- Mzoomrect
(p, p)
5475 match state.mstate
with
5476 | Mzoomrect
((x0, y0), _) ->
5477 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5478 then zoomrect x0 y0 x y
5480 state.mstate
<- Mnone
;
5481 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5482 G.postRedisplay "kill accidental zoom rect";
5485 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5486 state.mstate
<- Mnone
5489 | 1 when x > conf.winw - state.scrollw
->
5492 let _, position, sh = state.uioh#
scrollph in
5493 if y > truncate
position && y < truncate
(position +. sh)
5494 then state.mstate
<- Mscrolly
5497 state.mstate
<- Mnone
5499 | 1 when y > conf.winh
- state.hscrollh ->
5502 let _, position, sw = state.uioh#scrollpw
in
5503 if x > truncate
position && x < truncate
(position +. sw)
5504 then state.mstate
<- Mscrollx
5507 state.mstate
<- Mnone
5510 let dest = if down
then getunder x y else Unone
in
5511 begin match dest with
5515 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5518 | Unone
when down
->
5519 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5520 state.mstate
<- Mpan
(x, y);
5522 | Unone
| Utext
_ ->
5525 if conf.angle
mod 360 = 0
5527 state.mstate
<- Msel
((x, y), (x, y));
5528 G.postRedisplay "mouse select";
5532 match state.mstate
with
5535 | Mzoom
_ | Mscrollx
| Mscrolly
->
5536 state.mstate
<- Mnone
5538 | Mzoomrect
((x0, y0), _) ->
5542 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5543 state.mstate
<- Mnone
5545 | Msel
((_, y0), (_, y1)) ->
5546 let rec loop = function
5549 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5550 || ((y1 >= l.pagedispy
5551 && y1 <= (l.pagedispy + l.pagevh)))
5553 match getopaque l.pageno with
5557 try Some
(Unix.pipe
())
5559 dolog "can not create sel pipe: %s"
5560 (Printexc.to_string exn
);
5565 let doclose what fd
=
5568 dolog "%s close failed: %s"
5569 what
(Printexc.to_string exn
)
5574 G.postRedisplay "copysel"
5577 popen conf.selcmd
[r, 0; w, -1];
5580 dolog "can not exectute %S: %s"
5581 conf.selcmd
(Printexc.to_string exn
);
5589 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5590 state.mstate
<- Mnone
;
5597 let birdseyemouse button down
x y mask
5598 (conf, leftx
, _, hooverpageno
, anchor) =
5601 let rec loop = function
5604 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5605 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5607 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5613 | _ -> viewmouse button down
x y mask
5616 let mouse button down
x y mask
=
5617 state.uioh <- state.uioh#button button down
x y mask
;
5621 state.uioh <- state.uioh#
motion x y
5625 state.uioh <- state.uioh#
pmotion x y;
5631 method key key mask
=
5632 begin match state.mode with
5633 | Textentry
textentry -> textentrykeyboard key mask
textentry
5634 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5635 | View
-> viewkeyboard key mask
5636 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5640 method button button bstate
x y mask
=
5641 begin match state.mode with
5643 | View
-> viewmouse button bstate
x y mask
5644 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5650 begin match state.mode with
5652 | View
| Birdseye
_ | LinkNav
_ ->
5653 match state.mstate
with
5654 | Mzoom
_ | Mnone
-> ()
5659 state.mstate
<- Mpan
(x, y);
5661 then state.x <- state.x + dx;
5663 gotoy_and_clear_text y
5666 state.mstate
<- Msel
(a, (x, y));
5667 G.postRedisplay "motion select";
5670 let y = min
conf.winh
(max
0 y) in
5674 let x = min
conf.winw (max
0 x) in
5677 | Mzoomrect
(p0
, _) ->
5678 state.mstate
<- Mzoomrect
(p0
, (x, y));
5679 G.postRedisplay "motion zoomrect";
5683 method pmotion x y =
5684 begin match state.mode with
5685 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5686 let rec loop = function
5688 if hooverpageno
!= -1
5690 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5691 G.postRedisplay "pmotion birdseye no hoover";
5694 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5695 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5697 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5698 G.postRedisplay "pmotion birdseye hoover";
5708 match state.mstate
with
5709 | Mnone
-> updateunder x y
5710 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5715 method infochanged
_ = ()
5718 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5719 let p, h = scrollph state.y maxy in
5723 let winw = conf.winw - state.scrollw
- 1 in
5724 let fwinw = float winw in
5726 let sw = fwinw /. float state.w in
5727 let sw = fwinw *. sw in
5728 max
sw (float conf.scrollh
)
5731 let f = state.w+winw in
5732 let r = float (winw-state.x) /. float f in
5733 let p = fwinw *. r in
5737 if position +. sw > fwinw
5738 then fwinw -. position
5741 state.hscrollh, position, sw
5745 match state.mode with
5746 | LinkNav
_ -> "links"
5747 | Textentry
_ -> "textentry"
5748 | Birdseye
_ -> "birdseye"
5751 findkeyhash conf modename
5758 let fontpath = ref "";;
5761 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5764 let l = String.length
s in
5765 let b = Buffer.create
l in
5771 try Sys.getenv
"HOME"
5774 ("Can not determine home directory location: " ^
5775 Printexc.to_string exn
);
5779 let modifier_of_string = function
5780 | "alt" -> Wsi.altmask
5781 | "shift" -> Wsi.shiftmask
5782 | "ctrl" | "control" -> Wsi.ctrlmask
5783 | "meta" -> Wsi.metamask
5788 let r = Str.regexp
"-" in
5790 let elems = Str.full_split
r s in
5793 let m1 = modifier_of_string s in
5795 then (Wsi.namekey
s, m)
5798 | Str.Delim
s when n land 1 = 0 -> g s
5800 | Str.Delim
_ -> (k
, m)
5802 let rec loop n k
m = function
5805 let k, m = f n k m x in
5811 let keys_of_string =
5812 let r = Str.regexp
"[ \t]" in
5814 let elems = Str.split
r s in
5815 List.map
key_of_string elems
5818 let copykeyhashes c =
5819 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5822 let config_of c attrs
=
5826 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5827 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5828 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5829 | "preload" -> { c with preload = bool_of_string
v }
5830 | "page-bias" -> { c with pagebias
= int_of_string
v }
5831 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5832 | "auto-scroll-step" ->
5833 { c with autoscrollstep
= max
0 (int_of_string
v) }
5834 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5835 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5838 match String.lowercase
v with
5839 | "true" -> Some infinity
5841 | f -> Some
(float_of_string
f)
5843 { c with maxwait
= mw}
5844 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5845 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5846 | "vertical-margin" ->
5847 { c with interpagespace = max
0 (int_of_string
v) }
5849 let zoom = float_of_string
v /. 100. in
5850 let zoom = max
zoom 0.0 in
5851 { c with zoom = zoom }
5852 | "presentation" -> { c with presentation = bool_of_string
v }
5853 | "rotation-angle" -> { c with angle
= int_of_string
v }
5854 | "width" -> { c with winw = max
20 (int_of_string
v) }
5855 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5856 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5857 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5858 | "pixmap-cache-size" ->
5859 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5860 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5861 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5862 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5863 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5864 | "background-color" -> { c with bgcolor
= color_of_string v }
5865 | "scrollbar-in-presentation" ->
5866 { c with scrollbarinpm
= bool_of_string
v }
5867 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5868 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5869 | "mupdf-store-size" ->
5870 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5871 | "checkers" -> { c with checkers
= bool_of_string
v }
5872 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5873 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5874 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5875 | "uri-launcher" -> { c with urilauncher
= unent v }
5876 | "path-launcher" -> { c with pathlauncher
= unent v }
5877 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5878 | "invert-colors" -> { c with invert
= bool_of_string
v }
5879 | "brightness" -> { c with colorscale
= float_of_string
v }
5880 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5882 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5884 let (n, _, _) as nab
= multicolumns_of_string v in
5886 then { c with columns
= Csplit
(-n, [||]) }
5887 else { c with columns
= Cmulti
(nab
, [||]) }
5888 | "birds-eye-columns" ->
5889 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5890 | "selection-command" -> { c with selcmd
= unent v }
5891 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5894 prerr_endline
("Error processing attribute (`" ^
5895 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5898 let rec fold c = function
5901 let c = apply c k v in
5904 fold { c with keyhashes
= copykeyhashes c } attrs
;
5907 let fromstring f pos
n v d =
5910 dolog "Error processing attribute (%S=%S) at %d\n%s"
5911 n v pos
(Printexc.to_string exn
)
5916 let bookmark_of attrs
=
5917 let rec fold title page
rely = function
5918 | ("title", v) :: rest
-> fold v page
rely rest
5919 | ("page", v) :: rest
-> fold title v rely rest
5920 | ("rely", v) :: rest
-> fold title page
v rest
5921 | _ :: rest
-> fold title page
rely rest
5922 | [] -> title, page
, rely
5924 fold "invalid" "0" "0" attrs
5928 let rec fold path page
rely pan
= function
5929 | ("path", v) :: rest
-> fold v page
rely pan rest
5930 | ("page", v) :: rest
-> fold path v rely pan rest
5931 | ("rely", v) :: rest
-> fold path page
v pan rest
5932 | ("pan", v) :: rest
-> fold path page
rely v rest
5933 | _ :: rest
-> fold path page
rely pan rest
5934 | [] -> path, page
, rely, pan
5936 fold "" "0" "0" "0" attrs
5940 let rec fold rs ls
= function
5941 | ("out", v) :: rest
-> fold v ls rest
5942 | ("in", v) :: rest
-> fold rs
v rest
5943 | _ :: rest
-> fold ls rs rest
5949 let setconf dst
src =
5950 dst
.scrollbw
<- src.scrollbw
;
5951 dst
.scrollh
<- src.scrollh
;
5952 dst
.icase
<- src.icase
;
5953 dst
.preload <- src.preload;
5954 dst
.pagebias
<- src.pagebias
;
5955 dst
.verbose
<- src.verbose
;
5956 dst
.scrollstep
<- src.scrollstep
;
5957 dst
.maxhfit
<- src.maxhfit
;
5958 dst
.crophack
<- src.crophack
;
5959 dst
.autoscrollstep
<- src.autoscrollstep
;
5960 dst
.maxwait
<- src.maxwait
;
5961 dst
.hlinks
<- src.hlinks
;
5962 dst
.underinfo
<- src.underinfo
;
5963 dst
.interpagespace <- src.interpagespace;
5964 dst
.zoom <- src.zoom;
5965 dst
.presentation <- src.presentation;
5966 dst
.angle
<- src.angle
;
5967 dst
.winw <- src.winw;
5968 dst
.winh
<- src.winh
;
5969 dst
.savebmarks
<- src.savebmarks
;
5970 dst
.memlimit
<- src.memlimit
;
5971 dst
.proportional
<- src.proportional
;
5972 dst
.texcount
<- src.texcount
;
5973 dst
.sliceheight
<- src.sliceheight
;
5974 dst
.thumbw
<- src.thumbw
;
5975 dst
.jumpback
<- src.jumpback
;
5976 dst
.bgcolor
<- src.bgcolor
;
5977 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5978 dst
.tilew
<- src.tilew
;
5979 dst
.tileh
<- src.tileh
;
5980 dst
.mustoresize
<- src.mustoresize
;
5981 dst
.checkers
<- src.checkers
;
5982 dst
.aalevel
<- src.aalevel
;
5983 dst
.trimmargins
<- src.trimmargins
;
5984 dst
.trimfuzz
<- src.trimfuzz
;
5985 dst
.urilauncher
<- src.urilauncher
;
5986 dst
.colorspace
<- src.colorspace
;
5987 dst
.invert
<- src.invert
;
5988 dst
.colorscale
<- src.colorscale
;
5989 dst
.redirectstderr <- src.redirectstderr;
5990 dst
.ghyllscroll
<- src.ghyllscroll
;
5991 dst
.columns
<- src.columns
;
5992 dst
.beyecolumns
<- src.beyecolumns
;
5993 dst
.selcmd
<- src.selcmd
;
5994 dst
.updatecurs
<- src.updatecurs
;
5995 dst
.pathlauncher
<- src.pathlauncher
;
5996 dst
.keyhashes
<- copykeyhashes src;
6000 let h = Hashtbl.create
10 in
6001 let dc = { defconf with angle
= defconf.angle
} in
6002 let rec toplevel v t spos
_ =
6004 | Vdata
| Vcdata
| Vend
-> v
6005 | Vopen
("llppconfig", _, closed
) ->
6008 else { v with f = llppconfig
}
6010 error
"unexpected subelement at top level" s spos
6011 | Vclose
_ -> error
"unexpected close at top level" s spos
6013 and llppconfig
v t spos
_ =
6015 | Vdata
| Vcdata
-> v
6016 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6017 | Vopen
("defaults", attrs
, closed
) ->
6018 let c = config_of dc attrs
in
6022 else { v with f = defaults
}
6024 | Vopen
("ui-font", attrs
, closed
) ->
6025 let rec getsize size
= function
6027 | ("size", v) :: rest
->
6029 fromstring int_of_string spos
"size" v fstate.fontsize
in
6031 | l -> getsize size l
6033 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6036 else { v with f = uifont
(Buffer.create
10) }
6038 | Vopen
("doc", attrs
, closed
) ->
6039 let pathent, spage
, srely
, span
= doc_of attrs
in
6040 let path = unent pathent
6041 and pageno = fromstring int_of_string spos
"page" spage
0
6042 and rely = fromstring float_of_string spos
"rely" srely
0.0
6043 and pan
= fromstring int_of_string spos
"pan" span
0 in
6044 let c = config_of dc attrs
in
6045 let anchor = (pageno, rely) in
6047 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6048 else { v with f = doc
path pan
anchor c [] }
6051 error
"unexpected subelement in llppconfig" s spos
6053 | Vclose
"llppconfig" -> { v with f = toplevel }
6054 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6056 and defaults
v t spos
_ =
6058 | Vdata
| Vcdata
-> v
6059 | Vend
-> error
"unexpected end of input in defaults" s spos
6060 | Vopen
("keymap", attrs
, closed
) ->
6062 try List.assoc
"mode" attrs
6063 with Not_found
-> "global" in
6068 let h = findkeyhash dc modename in
6069 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6072 { v with f = pkeymap
ret KeyMap.empty }
6074 | Vopen
(_, _, _) ->
6075 error
"unexpected subelement in defaults" s spos
6077 | Vclose
"defaults" ->
6078 { v with f = llppconfig
}
6080 | Vclose
_ -> error
"unexpected close in defaults" s spos
6082 and uifont
b v t spos
epos =
6085 Buffer.add_substring
b s spos
(epos - spos
);
6087 | Vopen
(_, _, _) ->
6088 error
"unexpected subelement in ui-font" s spos
6089 | Vclose
"ui-font" ->
6090 if String.length
!fontpath = 0
6091 then fontpath := Buffer.contents
b;
6092 { v with f = llppconfig
}
6093 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6094 | Vend
-> error
"unexpected end of input in ui-font" s spos
6096 and doc
path pan
anchor c bookmarks
v t spos
_ =
6098 | Vdata
| Vcdata
-> v
6099 | Vend
-> error
"unexpected end of input in doc" s spos
6100 | Vopen
("bookmarks", _, closed
) ->
6103 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6105 | Vopen
("keymap", attrs
, closed
) ->
6107 try List.assoc
"mode" attrs
6108 with Not_found
-> "global"
6114 let h = findkeyhash c modename in
6115 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6116 doc
path pan
anchor c bookmarks
6118 { v with f = pkeymap
ret KeyMap.empty }
6120 | Vopen
(_, _, _) ->
6121 error
"unexpected subelement in doc" s spos
6124 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6125 { v with f = llppconfig
}
6127 | Vclose
_ -> error
"unexpected close in doc" s spos
6129 and pkeymap
ret keymap
v t spos
_ =
6131 | Vdata
| Vcdata
-> v
6132 | Vend
-> error
"unexpected end of input in keymap" s spos
6133 | Vopen
("map", attrs
, closed
) ->
6134 let r, l = map_of attrs
in
6135 let kss = fromstring keys_of_string spos
"in" r [] in
6136 let lss = fromstring keys_of_string spos
"out" l [] in
6140 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6141 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6144 then { v with f = pkeymap
ret keymap }
6147 { v with f = skip
"map" f }
6150 error
"unexpected subelement in keymap" s spos
6152 | Vclose
"keymap" ->
6153 { v with f = ret keymap }
6155 | Vclose
_ -> error
"unexpected close in keymap" s spos
6157 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6159 | Vdata
| Vcdata
-> v
6160 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6161 | Vopen
("item", attrs
, closed
) ->
6162 let titleent, spage
, srely
= bookmark_of attrs
in
6163 let page = fromstring int_of_string spos
"page" spage
0
6164 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6165 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6167 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6170 { v with f = skip
"item" f }
6173 error
"unexpected subelement in bookmarks" s spos
6175 | Vclose
"bookmarks" ->
6176 { v with f = doc
path pan
anchor c bookmarks }
6178 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6180 and skip tag
f v t spos
_ =
6182 | Vdata
| Vcdata
-> v
6184 error
("unexpected end of input in skipped " ^ tag
) s spos
6185 | Vopen
(tag'
, _, closed
) ->
6189 let f'
() = { v with f = skip tag
f } in
6190 { v with f = skip tag'
f'
}
6194 else error
("unexpected close in skipped " ^ tag
) s spos
6197 parse
{ f = toplevel; accu = () } s;
6203 let len = in_channel_length ic
in
6204 let s = String.create
len in
6205 really_input ic
s 0 len;
6208 | Parse_error
(msg
, s, pos
) ->
6209 let subs = subs s pos
in
6210 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6211 failwith
("parse error: " ^
s)
6214 failwith
("config load error: " ^
Printexc.to_string exn
)
6220 let dir = Filename.concat
home ".config" in
6221 if Sys.is_directory
dir then dir else home
6224 Filename.concat
dir "llpp.conf"
6227 let confpath = ref defconfpath;;
6230 if Sys.file_exists
!confpath
6233 (try Some
(open_in_bin
!confpath)
6236 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6237 Printexc.to_string exn
);
6246 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6247 Printexc.to_string exn
);
6253 f (Hashtbl.create
0, defconf)
6258 let pc, pb
, px, pa
=
6260 Hashtbl.find h (Filename.basename
state.path)
6261 with Not_found
-> dc, [], 0, (0, 0.0)
6265 state.bookmarks <- pb
;
6267 state.scrollw
<- conf.scrollbw
;
6269 then state.anchor <- pa
;
6270 cbput state.hists
.nav pa
;
6275 let add_attrs bb always
dc c =
6278 then Printf.bprintf bb
"\n %s='%b'" s a
6281 then Printf.bprintf bb
"\n %s='%d'" s a
6284 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6287 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6290 then Printf.bprintf bb
"\n %s='%f'" s a
6294 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6298 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6302 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6306 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6312 | Some
(_N
, _A
, _B
) ->
6313 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6323 else string_of_float
f
6325 Printf.bprintf bb
"\n %s='%s'" s v
6330 | Cmulti
((n, a, b), _) when n > 1 ->
6331 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6332 | Csplit
(n, _) when n > 1 ->
6333 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6339 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6344 then dc.winw, dc.winh
6346 match state.fullscreen
with
6348 | None
-> c.winw, c.winh
6350 let zoom, presentation, interpagespace, maxwait
=
6352 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6354 match state.mode with
6355 | Birdseye
(bc
, _, _, _, _) ->
6356 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6357 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6359 oi
"width" w dc.winw;
6360 oi
"height" h dc.winh
;
6361 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6362 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6363 ob "case-insensitive-search" c.icase
dc.icase
;
6364 ob "preload" c.preload dc.preload;
6365 oi
"page-bias" c.pagebias
dc.pagebias
;
6366 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6367 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6368 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6369 ob "crop-hack" c.crophack
dc.crophack
;
6370 oW
"throttle" maxwait
dc.maxwait
;
6371 ob "highlight-links" c.hlinks
dc.hlinks
;
6372 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6373 oi
"vertical-margin" interpagespace dc.interpagespace;
6374 oz
"zoom" zoom dc.zoom;
6375 ob "presentation" presentation dc.presentation;
6376 oi
"rotation-angle" c.angle
dc.angle
;
6377 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6378 ob "proportional-display" c.proportional
dc.proportional
;
6379 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6380 oi
"tex-count" c.texcount
dc.texcount
;
6381 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6382 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6383 ob "persistent-location" c.jumpback
dc.jumpback
;
6384 oc
"background-color" c.bgcolor
dc.bgcolor
;
6385 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6386 oi
"tile-width" c.tilew
dc.tilew
;
6387 oi
"tile-height" c.tileh
dc.tileh
;
6388 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6389 ob "checkers" c.checkers
dc.checkers
;
6390 oi
"aalevel" c.aalevel
dc.aalevel
;
6391 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6392 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6393 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6394 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6395 oC
"color-space" c.colorspace
dc.colorspace
;
6396 ob "invert-colors" c.invert
dc.invert
;
6397 oF
"brightness" c.colorscale
dc.colorscale
;
6398 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6399 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6400 oco
"columns" c.columns
dc.columns
;
6401 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6402 os
"selection-command" c.selcmd
dc.selcmd
;
6403 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6406 let keymapsbuf always
dc c =
6407 let bb = Buffer.create
16 in
6408 let rec loop = function
6410 | (modename, h) :: rest
->
6411 let dh = findkeyhash dc modename in
6412 if always
|| h <> dh
6414 if Hashtbl.length
h > 0
6416 if Buffer.length
bb > 0
6417 then Buffer.add_char
bb '
\n'
;
6418 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6419 Hashtbl.iter
(fun i
o ->
6420 let isdifferent = always
||
6422 let dO = Hashtbl.find dh i
in
6424 with Not_found
-> true
6429 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6430 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6431 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6432 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6433 Buffer.add_string
bb (Wsi.keyname
k);
6436 let rec loop = function
6438 | km
:: [] -> addkm km
6439 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6443 Buffer.add_string
bb "<map in='";
6447 Buffer.add_string
bb "' out='";
6449 Buffer.add_string
bb "'/>\n"
6452 Buffer.add_string
bb "' out='";
6454 Buffer.add_string
bb "'/>\n"
6456 | KMmulti
(ins, kms
) ->
6457 Buffer.add_char
bb ' '
;
6459 Buffer.add_string
bb "' out='";
6461 Buffer.add_string
bb "'/>\n"
6463 Buffer.add_string
bb "</keymap>";
6473 let uifontsize = fstate.fontsize
in
6474 let bb = Buffer.create
32768 in
6476 let dc = if conf.bedefault
then conf else dc in
6477 Buffer.add_string
bb "<llppconfig>\n";
6479 if String.length
!fontpath > 0
6481 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6487 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6490 Buffer.add_string
bb "<defaults ";
6491 add_attrs bb true dc dc;
6492 let kb = keymapsbuf true dc dc in
6493 if Buffer.length
kb > 0
6495 Buffer.add_string
bb ">\n";
6496 Buffer.add_buffer
bb kb;
6497 Buffer.add_string
bb "\n</defaults>\n";
6499 else Buffer.add_string
bb "/>\n";
6501 let adddoc path pan
anchor c bookmarks =
6502 if bookmarks == [] && c = dc && anchor = emptyanchor
6505 Printf.bprintf
bb "<doc path='%s'"
6506 (enent
path 0 (String.length
path));
6508 if anchor <> emptyanchor
6510 let n, y = anchor in
6511 Printf.bprintf
bb " page='%d'" n;
6514 Printf.bprintf
bb " rely='%f'" y
6519 then Printf.bprintf
bb " pan='%d'" pan
;
6521 add_attrs bb false dc c;
6522 let kb = keymapsbuf false dc c in
6524 begin match bookmarks with
6526 if Buffer.length
kb > 0
6528 Buffer.add_string
bb ">\n";
6529 Buffer.add_buffer
bb kb;
6530 Buffer.add_string
bb "</doc>\n";
6532 else Buffer.add_string
bb "/>\n"
6534 Buffer.add_string
bb ">\n<bookmarks>\n";
6535 List.iter
(fun (title, _level
, (page, rely)) ->
6537 "<item title='%s' page='%d'"
6538 (enent
title 0 (String.length
title))
6543 Printf.bprintf
bb " rely='%f'" rely
6545 Buffer.add_string
bb "/>\n";
6547 Buffer.add_string
bb "</bookmarks>";
6548 if Buffer.length
kb > 0
6550 Buffer.add_string
bb "\n";
6551 Buffer.add_buffer
bb kb;
6553 Buffer.add_string
bb "\n</doc>\n";
6559 match state.mode with
6560 | Birdseye
(c, pan, _, _, _) ->
6562 match conf.columns
with
6563 | Cmulti
((c, _, _), _) -> Some
c
6567 match c.columns
with
6568 | Cmulti
(c, _) -> Cmulti
(c, [||])
6569 | Csingle
-> Csingle
6570 | Csplit
_ -> failwith
"quit from bird's eye while split"
6572 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6573 | _ -> state.x, conf
6575 let basename = Filename.basename state.path in
6576 adddoc basename pan (getanchor ())
6579 match state.autoscroll
with
6581 | None
-> conf.autoscrollstep
}
6582 (if conf.savebmarks
then state.bookmarks else []);
6584 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6586 then adddoc path x y c bookmarks
6588 Buffer.add_string
bb "</llppconfig>";
6591 if Buffer.length
bb > 0
6594 let tmp = !confpath ^
".tmp" in
6595 let oc = open_out_bin
tmp in
6596 Buffer.output_buffer
oc bb;
6598 Unix.rename
tmp !confpath;
6601 ("error while saving configuration: " ^
Printexc.to_string exn
)
6608 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6609 "<password> Set password");
6611 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6612 "<path> Set path to the user interface font");
6614 ("-c", Arg.String
(fun s -> Config.confpath := s),
6615 "<path> Set path to the configuration file");
6617 ("-v", Arg.Unit
(fun () ->
6619 "%s\nconfiguration path: %s\n"
6623 exit
0), " Print version and exit");
6626 (fun s -> state.path <- s)
6627 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6629 if String.length
state.path = 0
6630 then (prerr_endline
"file name missing"; exit
1);
6634 let globalkeyhash = findkeyhash conf "global" in
6635 let wsfd, winw, winh
= Wsi.init
(object
6637 if nogeomcmds state.geomcmds
|| platform == Posx
6640 GlFunc.draw_buffer `front
;
6641 GlClear.color (scalecolor2 conf.bgcolor
);
6642 GlClear.clear
[`
color];
6643 GlFunc.draw_buffer `back
;
6645 method display = display ()
6646 method reshape w h = reshape w h
6647 method mouse b d x y m = mouse b d x y m
6648 method motion x y = state.mpos
<- (x, y); motion x y
6649 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6651 let mascm = m land (
6652 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6654 match state.keystate
with
6656 let km = k, mascm in
6659 try Hashtbl.find globalkeyhash km
6661 let modehash = state.uioh#
modehash in
6662 try Hashtbl.find modehash km
6663 with Not_found
-> KMinsrt
(k, m)
6665 | KMinsrt
(k, m) -> keyboard k m
6666 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6667 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6669 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6670 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6671 state.keystate
<- KSnone
6672 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6673 state.keystate
<- KSinto
(keys
, insrt
)
6675 state.keystate
<- KSnone
6677 method enter
x y = state.mpos
<- (x, y); pmotion x y
6678 method leave = state.mpos
<- (-1, -1)
6679 method quit
= raise Quit
6680 end) conf.winw conf.winh
(platform = Posx
) in
6685 List.exists
GlMisc.check_extension
6686 [ "GL_ARB_texture_rectangle"
6687 ; "GL_EXT_texture_recangle"
6688 ; "GL_NV_texture_rectangle" ]
6690 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6692 let cr, sw = Unix.pipe
()
6693 and sr
, cw = Unix.pipe
() in
6700 setcheckers conf.checkers
;
6704 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6705 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6710 state.text <- "Opening " ^
state.path;
6712 opendoc state.path state.password
;
6715 let rec loop deadline
=
6717 match state.errfd
with
6718 | None
-> [state.sr
; state.wsfd]
6719 | Some fd
-> [state.sr
; state.wsfd; fd
]
6723 state.redisplay
<- false;
6730 if deadline
= infinity
6732 else max
0.0 (deadline
-. now)
6737 try Unix.select
r [] [] timeout
6738 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6744 if state.ghyll
== noghyll
6746 match state.autoscroll
with
6747 | Some step
when step
!= 0 ->
6748 let y = state.y + step
in
6752 else if y >= state.maxy then 0 else y
6755 if state.mode = View
6756 then state.text <- "";
6759 else deadline
+. 0.01
6764 let rec checkfds = function
6766 | fd
:: rest
when fd
= state.sr
->
6767 let cmd = readcmd state.sr
in
6771 | fd
:: rest
when fd
= state.wsfd ->
6776 let s = String.create
80 in
6777 let n = Unix.read fd
s 0 80 in
6778 if conf.redirectstderr
6780 Buffer.add_substring
state.errmsgs
s 0 n;
6781 state.newerrmsgs
<- true;
6782 state.redisplay
<- true;
6785 prerr_string
(String.sub
s 0 n);
6793 if deadline
= infinity
6797 match state.autoscroll
with
6798 | Some step
when step
!= 0 -> deadline1
6799 | _ -> if state.ghyll
== noghyll then infinity
else deadline1