6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
45 | Lfound
of (int * int * int * int * int)
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: string -> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
87 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
88 external platform
: unit -> platform
= "ml_platform";;
89 external setaalevel
: int -> unit = "ml_setaalevel";;
90 external realloctexts
: int -> bool = "ml_realloctexts";;
91 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
92 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
93 external getlink
: opaque
-> int -> under
= "ml_getlink";;
94 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
96 let platform_to_string = function
97 | Punknown
-> "unknown"
101 | Pfreebsd
-> "FreeBSD"
102 | Pdragonflybsd
-> "DragonflyBSD"
103 | Popenbsd
-> "OpenBSD"
104 | Pnetbsd
-> "NetBSD"
105 | Pcygwin
-> "Cygwin"
108 let platform = platform ();;
114 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
117 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
119 type mpos
= int * int
121 | Msel
of (mpos
* mpos
)
123 | Mscrolly
| Mscrollx
124 | Mzoom
of (int * int)
125 | Mzoomrect
of (mpos
* mpos
)
129 type textentry
= string * string * onhist
option * onkey
* ondone
130 and onkey
= string -> int -> te
131 and ondone
= string -> unit
132 and histcancel
= unit -> unit
133 and onhist
= ((histcmd
-> string) * histcancel
)
134 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
139 | TEswitch
of textentry
150 let bound v minv maxv
=
151 max minv
(min maxv v
);
155 { store
= Array.create n v
162 let drawstring size x y s
=
164 Gl.enable `texture_2d
;
165 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
166 ignore
(drawstr size x y s
);
168 Gl.disable `texture_2d
;
171 let drawstring1 size x y s
=
175 let drawstring2 size x y fmt
=
176 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
179 let cbcap b
= Array.length b
.store
;;
184 b
.wc
<- (b
.wc
+ 1) mod cap;
186 b
.len
<- min
(b
.len
+ 1) cap;
189 let cbempty b
= b
.len
= 0;;
191 let cbgetg b circular dir
=
195 let rc = b
.rc + dir
in
207 else max
0 (min
rc (b
.len
-1))
213 let cbget b
= cbgetg b
false;;
214 let cbgetc b
= cbgetg b
true;;
231 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
232 dolog " WxH %dx%d" l
.pagew l
.pageh
;
233 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
234 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
235 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
239 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
241 dolog " x0,y0=(% f, % f)" x0 y0
;
242 dolog " x1,y1=(% f, % f)" x1 y1
;
243 dolog " x2,y2=(% f, % f)" x2 y2
;
244 dolog " x3,y3=(% f, % f)" x3 y3
;
249 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
250 and multicol
= columncount
* covercount
* covercount
252 and columncount
= int
253 and covercount
= int;;
256 { mutable scrollbw
: int
257 ; mutable scrollh
: int
258 ; mutable icase
: bool
259 ; mutable preload
: bool
260 ; mutable pagebias
: int
261 ; mutable verbose
: bool
262 ; mutable debug
: bool
263 ; mutable scrollstep
: int
264 ; mutable maxhfit
: bool
265 ; mutable crophack
: bool
266 ; mutable autoscrollstep
: int
267 ; mutable maxwait
: float option
268 ; mutable hlinks
: bool
269 ; mutable underinfo
: bool
270 ; mutable interpagespace
: interpagespace
271 ; mutable zoom
: float
272 ; mutable presentation
: bool
273 ; mutable angle
: angle
276 ; mutable savebmarks
: bool
277 ; mutable proportional
: proportional
278 ; mutable trimmargins
: trimmargins
279 ; mutable trimfuzz
: irect
280 ; mutable memlimit
: memsize
281 ; mutable texcount
: texcount
282 ; mutable sliceheight
: sliceheight
283 ; mutable thumbw
: width
284 ; mutable jumpback
: bool
285 ; mutable bgcolor
: float * float * float
286 ; mutable bedefault
: bool
287 ; mutable scrollbarinpm
: bool
288 ; mutable tilew
: int
289 ; mutable tileh
: int
290 ; mutable mustoresize
: memsize
291 ; mutable checkers
: bool
292 ; mutable aalevel
: int
293 ; mutable urilauncher
: string
294 ; mutable pathlauncher
: string
295 ; mutable colorspace
: colorspace
296 ; mutable invert
: bool
297 ; mutable colorscale
: float
298 ; mutable redirectstderr
: bool
299 ; mutable ghyllscroll
: (int * int * int) option
300 ; mutable columns
: columns
option
301 ; mutable beyecolumns
: columncount
option
302 ; mutable selcmd
: string
303 ; mutable updatecurs
: bool
304 ; mutable keyhashes
: (string * keyhash
) list
308 type anchor
= pageno
* top
;;
310 type outline
= string * int * anchor
;;
312 type rect
= float * float * float * float * float * float * float * float;;
314 type tile
= opaque
* pixmapsize
* elapsed
315 and elapsed
= float;;
316 type pagemapkey
= pageno
* gen
;;
317 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
321 let emptyanchor = (0, 0.0);;
323 type infochange
= | Memused
| Docinfo
| Pdim
;;
325 class type uioh
= object
326 method display
: unit
327 method key
: int -> int -> uioh
328 method button
: int -> bool -> int -> int -> int -> uioh
329 method motion
: int -> int -> uioh
330 method pmotion
: int -> int -> uioh
331 method infochanged
: infochange
-> unit
332 method scrollpw
: (int * float * float)
333 method scrollph
: (int * float * float)
334 method modehash
: keyhash
338 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
339 | Textentry
of (textentry
* onleave
)
341 | LinkNav
of linktarget
342 and onleave
= leavetextentrystatus
-> unit
343 and leavetextentrystatus
= | Cancel
| Confirm
344 and helpitem
= string * int * action
347 | Action
of (uioh
-> uioh
)
349 | Ltexact
of ((pageno
* int) * (int * int * int * int))
353 let isbirdseye = function Birdseye _
-> true | _
-> false;;
354 let istextentry = function Textentry _
-> true | _
-> false;;
358 | Loading
of (page
* gen
)
360 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
362 | Outlining
of outline list
365 let emptykeyhash = Hashtbl.create
0;;
366 let nouioh : uioh
= object (self
)
368 method key _ _
= self
369 method button _ _ _ _ _
= self
370 method motion _ _
= self
371 method pmotion _ _
= self
372 method infochanged _
= ()
373 method scrollpw
= (0, nan
, nan
)
374 method scrollph
= (0, nan
, nan
)
375 method modehash
= emptykeyhash
379 { mutable sr
: Unix.file_descr
380 ; mutable sw
: Unix.file_descr
381 ; mutable wsfd
: Unix.file_descr
382 ; mutable errfd
: Unix.file_descr
option
383 ; mutable stderr
: Unix.file_descr
384 ; mutable errmsgs
: Buffer.t
385 ; mutable newerrmsgs
: bool
389 ; mutable scrollw
: int
390 ; mutable hscrollh
: int
391 ; mutable anchor
: anchor
392 ; mutable ranchors
: (string * string * anchor
) list
394 ; mutable layout
: page list
395 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
396 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
397 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
398 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
399 ; mutable pagecount
: int
400 ; mutable currently
: currently
401 ; mutable mstate
: mstate
402 ; mutable searchpattern
: string
403 ; mutable rects
: (pageno
* recttype
* rect
) list
404 ; mutable rects1
: (pageno
* recttype
* rect
) list
405 ; mutable text
: string
406 ; mutable fullscreen
: (width
* height
) option
407 ; mutable mode
: mode
408 ; mutable uioh
: uioh
409 ; mutable outlines
: outline array
410 ; mutable bookmarks
: outline list
411 ; mutable path
: string
412 ; mutable password
: string
413 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
414 ; mutable memused
: memsize
416 ; mutable throttle
: (page list
* int * float) option
417 ; mutable autoscroll
: int option
418 ; mutable ghyll
: (int option -> unit)
419 ; mutable help
: helpitem array
420 ; mutable docinfo
: (int * string) list
421 ; mutable texid
: GlTex.texture_id
option
423 ; mutable prevzoom
: float
424 ; mutable progress
: float
425 ; mutable redisplay
: bool
426 ; mutable mpos
: mpos
427 ; mutable keystate
: keystate
430 { pat
: string circbuf
431 ; pag
: string circbuf
432 ; nav
: anchor circbuf
433 ; sel
: string circbuf
454 ; presentation
= false
459 ; proportional
= true
460 ; trimmargins
= false
461 ; trimfuzz
= (0,0,0,0)
462 ; memlimit
= 32 lsl 20
467 ; bgcolor
= (0.5, 0.5, 0.5)
469 ; scrollbarinpm
= true
472 ; mustoresize
= 128 lsl 20
477 | Plinux
| Pfreebsd
| Pdragonflybsd
478 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
479 | Posx
-> "open \"%s\""
480 | Pcygwin
-> "cygstart %s"
481 | Punknown
-> "echo %s")
482 ; pathlauncher
= "lp \"%s\""
485 | Plinux
| Pfreebsd
| Pdragonflybsd
486 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
493 ; redirectstderr
= false
499 let mk n
= (n
, Hashtbl.create
1) in
512 let findkeyhash c name
=
513 try List.assoc name c
.keyhashes
514 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
517 let conf = { defconf with angle
= defconf.angle
};;
520 { mutable fontsize
: int
521 ; mutable wwidth
: float
522 ; mutable maxrows
: int
534 fstate.fontsize
<- n
;
535 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
536 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
540 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
541 let len = String.length s
in
542 if colonpos >= 0 && colonpos + 3 < len
544 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
547 try String.rindex_from s
colonpos ' '
551 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
554 | "http" | "ftp" | "mailto" ->
556 try String.index_from s
colonpos ' '
557 with Not_found
-> len
559 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
567 let shell, farg
= "/bin/sh", "-c" in
569 let args = [|shell; farg
; s
|] in
570 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
574 if String.length
conf.urilauncher
= 0
575 then print_endline uri
577 let url = geturl uri
in
578 if String.length
url = 0
579 then print_endline uri
581 let re = Str.regexp
"%s" in
582 let command = Str.global_replace
re url conf.urilauncher
in
586 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
592 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
593 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
597 let strings = version () :: "" :: Help.keys
in
600 let url = geturl s
in
601 if String.length
url > 0
602 then (s
, 0, Action
(fun u
-> gotouri url; u
))
603 else (s
, 0, Noaction
)
608 let firstgeomcmds = "", [];;
615 ; stderr
= Unix.stderr
616 ; errmsgs
= Buffer.create
0
623 ; anchor
= emptyanchor
627 ; tilelru
= Queue.create
()
628 ; pagemap
= Hashtbl.create
10
629 ; tilemap
= Hashtbl.create
10
644 ; geomcmds
= firstgeomcmds
646 { nav
= cbnew 10 (0, 0.0)
671 Printf.kprintf prerr_endline fmt
673 Printf.kprintf ignore fmt
677 if String.length
conf.pathlauncher
= 0
678 then print_endline
state.path
680 let re = Str.regexp
"%s" in
681 let command = Str.global_replace
re state.path
conf.pathlauncher
in
685 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
690 let redirectstderr () =
691 if conf.redirectstderr
693 let rfd, wfd
= Unix.pipe
() in
694 state.stderr
<- Unix.dup
Unix.stderr
;
695 state.errfd
<- Some
rfd;
696 Unix.dup2 wfd
Unix.stderr
;
698 state.newerrmsgs
<- false;
699 begin match state.errfd
with
702 Unix.dup2
state.stderr
Unix.stderr
;
706 prerr_string
(Buffer.contents
state.errmsgs
);
708 Buffer.clear
state.errmsgs
;
714 let postRedisplay who
=
716 then prerr_endline
("redisplay for " ^ who
);
717 state.redisplay
<- true;
721 let getopaque pageno
=
722 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
723 with Not_found
-> None
726 let putopaque pageno opaque
=
727 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
730 let pagetranslatepoint l x y
=
731 let dy = y
- l
.pagedispy
in
732 let y = dy + l
.pagey
in
733 let dx = x
- l
.pagedispx
in
734 let x = dx + l
.pagex
in
741 begin match getopaque l
.pageno
with
743 let x0 = l
.pagedispx
in
744 let x1 = x0 + l
.pagevw
in
745 let y0 = l
.pagedispy
in
746 let y1 = y0 + l
.pagevh
in
747 if y >= y0 && y <= y1 && x >= x0 && x <= x1
749 let px, py
= pagetranslatepoint l
x y in
750 match whatsunder opaque
px py
with
763 state.text
<- Printf.sprintf
"%c%s" c s
;
764 G.postRedisplay "showtext";
767 let updateunder x y =
768 match getunder x y with
769 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
771 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
772 Wsi.setcursor
Wsi.CURSOR_INFO
773 | Ulinkgoto
(page
, _
) ->
775 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
776 Wsi.setcursor
Wsi.CURSOR_INFO
778 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
779 Wsi.setcursor
Wsi.CURSOR_TEXT
781 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
782 Wsi.setcursor
Wsi.CURSOR_INHERIT
784 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
785 Wsi.setcursor
Wsi.CURSOR_INHERIT
787 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
788 Wsi.setcursor
Wsi.CURSOR_INHERIT
789 | Uremote
(filename
, pageno
) ->
790 if conf.underinfo
then showtext 'r'
791 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
792 Wsi.setcursor
Wsi.CURSOR_INFO
795 let showlinktype under
=
801 showtext 'u'
("ri: " ^ uri
)
802 | Ulinkgoto
(page
, _
) ->
803 showtext 'p'
("age: " ^ string_of_int
(page
+1));
805 showtext '
f'
("ont: " ^ s
);
807 showtext 'u'
("nexpected: " ^ s
);
809 showtext 'l'
("aunch: " ^ s
);
811 showtext 'n'
("amed: " ^ s
);
812 | Uremote
(filename
, pageno
) ->
813 showtext 'r'
(Printf.sprintf
"emote: %s (%d)" filename pageno
);
817 let b = Buffer.create
(String.length s
+ 1) in
818 Buffer.add_string
b s
;
823 let colorspace_of_string s
=
824 match String.lowercase s
with
828 | _
-> failwith
"invalid colorspace"
831 let int_of_colorspace = function
837 let colorspace_of_int = function
841 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
844 let colorspace_to_string = function
850 let intentry_with_suffix text key
=
852 if key
>= 32 && key
< 127
856 match Char.lowercase
c with
858 let text = addchar text c in
862 let text = addchar text c in
866 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
870 let columns_to_string (n
, a
, b) =
872 then Printf.sprintf
"%d" n
873 else Printf.sprintf
"%d,%d,%d" n a
b;
876 let columns_of_string s
=
878 (int_of_string s
, 0, 0)
880 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
885 let n = Unix.read fd
s 0 4 in
886 if n != 4 then failwith
"incomplete read(len)";
888 lor (Char.code
s.[0] lsl 24)
889 lor (Char.code
s.[1] lsl 16)
890 lor (Char.code
s.[2] lsl 8)
891 lor (Char.code
s.[3] lsl 0)
893 let s = String.create
len in
894 let n = Unix.read fd
s 0 len in
895 if n != len then failwith
"incomplete read(data)";
899 let btod b = if b then 1 else 0;;
902 let b = Buffer.create
16 in
903 Buffer.add_string
b "llll";
906 let s = Buffer.contents
b in
907 let n = String.length
s in
909 (* dolog "wcmd %S" (String.sub s 4 len); *)
910 s.[0] <- Char.chr
((len lsr 24) land 0xff);
911 s.[1] <- Char.chr
((len lsr 16) land 0xff);
912 s.[2] <- Char.chr
((len lsr 8) land 0xff);
913 s.[3] <- Char.chr
(len land 0xff);
914 let n'
= Unix.write
state.sw
s 0 n in
915 if n'
!= n then failwith
"write failed";
922 let d = conf.winh
- h
in
929 let rec f pn ph pi fh l
=
931 | (n, _
, h
, _
) :: rest
->
932 let ips = calcips h
in
937 if isbirdseye state.mode
&& pn
= 0
942 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
947 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
951 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
954 let fh = f 0 0 0 0 state.pdims
in
959 match conf.columns
with
960 | None
-> calcheight ()
962 if Array.length
b > 0
964 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
969 let getpageyh pageno
=
970 let rec f pn ph pi
y l
=
972 | (n, _
, h
, _
) :: rest
->
973 let ips = calcips h
in
976 let h = if n = pageno
then h else ph
in
977 if conf.presentation
&& n = pageno
979 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
981 y + (pageno
- pn
) * (ph
+ pi
), h
983 let y = y + (if conf.presentation
then pi
else 0) in
984 let y = y + (n - pn
) * (ph
+ pi
) in
988 y + (pageno
- pn
) * (ph
+ pi
), ph
990 f 0 0 0 0 state.pdims
993 let getpageyh pageno
=
994 match conf.columns
with
995 | None
-> getpageyh pageno
997 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1001 let getpagedim pageno
=
1004 | (n, _
, _
, _
) as pdim
:: rest
->
1006 then (if n = pageno
then pdim
else ppdim
)
1011 f (-1, -1, -1, -1) state.pdims
1014 let getpagey pageno
= fst
(getpageyh pageno
);;
1016 let nogeomcmds cmds
=
1018 | s, [] -> String.length
s = 0
1023 let sh = sh - state.hscrollh
in
1024 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1025 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1027 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1028 let ips = calcips h in
1030 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1034 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1036 prev
, pdims
, pdimno
, 0
1038 let dy = dy + yinc in
1039 let py = py + yinc in
1040 if pageno
= state.pagecount
|| dy >= sh
1045 if py + h <= vy - yinc
1047 let py = py + h + ips in
1048 let dy = max
0 (py - y) in
1049 f ~pageno
:(pageno
+1)
1057 let pagey = vy - py in
1058 let pagevh = h - pagey in
1059 let pagevh = min
(sh - dy) pagevh in
1060 let off = if yinc > 0 then py - vy else 0 in
1061 let py = py + h + ips in
1064 if state.w
< conf.winw
- state.scrollw
1065 then (conf.winw
- state.scrollw
- state.w
) / 2
1068 let dispx = xoff + state.x in
1074 let lw = w
- pagex in
1075 min
lw (conf.winw
- state.scrollw
)
1079 ; pagedimno
= pdimno
1083 ; pagey = pagey + off
1085 ; pagevh = pagevh - off
1087 ; pagedispy
= dy + off
1090 let accu = e :: accu in
1091 f ~pageno
:(pageno
+1)
1099 if nogeomcmds state.geomcmds
1117 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1118 let sh = sh - state.hscrollh
in
1119 let rec fold accu n =
1120 if n = Array.length
b
1123 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1126 || n = state.pagecount
- coverB
1127 || (n - coverA
) mod columns
= columns
- 1)
1133 let pagey = max
0 (y - vy) in
1134 let pagedispy = if pagey > 0 then 0 else vy - y in
1135 let pagedispx, pagex, pagevw =
1137 if n = coverA
- 1 || n = state.pagecount
- coverB
1138 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1139 else dx + xoff + state.x
1142 then 0, -pdx, w
+ pdx
1143 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1145 let pagevh = min
(h - pagey) (sh - pagedispy) in
1146 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1150 ; pagedimno
= pdimno
1157 ; pagedispx = pagedispx
1158 ; pagedispy = pagedispy
1169 if nogeomcmds state.geomcmds
1170 then List.rev
(fold [] 0)
1175 match conf.columns
with
1176 | None
-> layout1 y sh
1177 | Some
c -> layoutN c y sh
1181 let y = state.y + incr
in
1183 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1188 let tilex = l
.pagex mod conf.tilew
in
1189 let tiley = l
.pagey mod conf.tileh
in
1191 let col = l
.pagex / conf.tilew
in
1192 let row = l
.pagey / conf.tileh
in
1195 let a = l
.pagew
- l
.pagex in
1196 let b = conf.winw
- state.scrollw
in
1198 and vh
= l
.pagevh in
1200 let rec rowloop row y0 dispy
h =
1204 let dh = conf.tileh
- y0 in
1205 let dh = min
h dh in
1206 let rec colloop col x0 dispx w
=
1210 let dw = conf.tilew
- x0 in
1211 let dw = min w
dw in
1213 f col row dispx dispy
x0 y0 dw dh;
1214 colloop (col+1) 0 (dispx+dw) (w
-dw)
1217 colloop col tilex l
.pagedispx vw;
1218 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1222 then rowloop row tiley l
.pagedispy vh
;
1225 let gettileopaque l
col row =
1227 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1229 try Some
(Hashtbl.find
state.tilemap
key)
1230 with Not_found
-> None
1233 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1234 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1235 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1238 let drawtiles l color
=
1240 let f col row x y tilex tiley w
h =
1241 match gettileopaque l
col row with
1242 | Some
(opaque
, _
, t
) ->
1243 let params = x, y, w
, h, tilex, tiley in
1247 GlFunc.blend_func `zero `one_minus_src_color
;
1249 drawtile
params opaque
;
1251 then Gl.disable `blend
;
1254 let s = Printf.sprintf
1258 let w = measurestr
fstate.fontsize
s in
1259 GlMisc.push_attrib
[`current
];
1260 GlDraw.color
(0.0, 0.0, 0.0);
1262 (float (x-2), float (y-2))
1263 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1264 GlDraw.color
(1.0, 1.0, 1.0);
1265 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1266 GlMisc.pop_attrib
();
1271 let lw = conf.winw
- state.scrollw
- x in
1274 let lh = conf.winh
- y in
1277 Gl.enable `texture_2d
;
1278 begin match state.texid
with
1280 GlTex.bind_texture `texture_2d id
;
1283 and x1 = float (x+w)
1284 and y1 = float (y+h) in
1286 let tw = float w /. 64.0
1287 and th
= float h /. 64.0 in
1288 let tx0 = float tilex /. 64.0
1289 and ty0
= float tiley /. 64.0 in
1291 and ty1
= ty0
+. th
in
1292 GlDraw.begins `quads
;
1293 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1294 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1295 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1296 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1299 Gl.disable `texture_2d
;
1301 GlDraw.color
(1.0, 1.0, 1.0);
1304 (float (x+w), float (y+h));
1306 if w > 128 && h > fstate.fontsize
+ 10
1308 GlDraw.color
(0.0, 0.0, 0.0);
1311 then (col*conf.tilew
, row*conf.tileh
)
1314 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1321 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1323 let tilevisible1 l
x y =
1325 and ax1
= l
.pagex + l
.pagevw
1327 and ay1
= l
.pagey + l
.pagevh in
1331 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1332 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1334 let rx0 = max
ax0 bx0
1335 and ry0
= max ay0 by0
1336 and rx1
= min ax1
bx1
1337 and ry1
= min ay1 by1
in
1339 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1340 nonemptyintersection
1343 let tilevisible layout n x y =
1344 let rec findpageinlayout = function
1345 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1346 | _
:: rest
-> findpageinlayout rest
1349 findpageinlayout layout
1352 let tileready l
x y =
1353 tilevisible1 l
x y &&
1354 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1357 let tilepage n p
layout =
1358 let rec loop = function
1362 let f col row _ _ _ _ _ _
=
1363 if state.currently
= Idle
1365 match gettileopaque l
col row with
1368 let x = col*conf.tilew
1369 and y = row*conf.tileh
in
1371 let w = l
.pagew
- x in
1375 let h = l
.pageh
- y in
1378 wcmd "tile %s %d %d %d %d" p
x y w h;
1381 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1382 conf.tilew
, conf.tileh
1391 if nogeomcmds state.geomcmds
1395 let preloadlayout visiblepages
=
1396 let presentation = conf.presentation in
1397 let interpagespace = conf.interpagespace in
1398 let maxy = state.maxy in
1399 conf.presentation <- false;
1400 conf.interpagespace <- 0;
1401 state.maxy <- calcheight ();
1403 match visiblepages
with
1405 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1407 let y = if y < conf.winh
then 0 else y - conf.winh
in
1408 let h = state.y - y + conf.winh
*3 in
1409 let pages = layout y h in
1410 conf.presentation <- presentation;
1411 conf.interpagespace <- interpagespace;
1417 let rec loop pages =
1418 if state.currently
!= Idle
1423 begin match getopaque l
.pageno
with
1425 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1426 state.currently
<- Loading
(l
, state.gen
);
1428 tilepage l
.pageno opaque
pages;
1433 if nogeomcmds state.geomcmds
1439 if conf.preload && state.currently
= Idle
1440 then load (preloadlayout pages);
1443 let layoutready layout =
1444 let rec fold all ls
=
1445 all
&& match ls
with
1447 let seen = ref false in
1448 let allvisible = ref true in
1449 let foo col row _ _ _ _ _ _
=
1451 allvisible := !allvisible &&
1452 begin match gettileopaque l
col row with
1458 fold (!seen && !allvisible) rest
1461 let alltilesvisible = fold true layout in
1466 let y = bound y 0 state.maxy in
1467 let y, layout, proceed
=
1468 match conf.maxwait
with
1469 | Some time
when state.ghyll
== noghyll ->
1470 begin match state.throttle
with
1472 let layout = layout y conf.winh
in
1473 let ready = layoutready layout in
1477 state.throttle
<- Some
(layout, y, now ());
1479 else G.postRedisplay "gotoy showall (None)";
1481 | Some
(_
, _
, started
) ->
1482 let dt = now () -. started
in
1485 state.throttle
<- None
;
1486 let layout = layout y conf.winh
in
1488 G.postRedisplay "maxwait";
1495 let layout = layout y conf.winh
in
1496 if true || layoutready layout
1497 then G.postRedisplay "gotoy ready";
1503 state.layout <- layout;
1504 begin match state.mode
with
1505 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1506 if not
(pagevisible layout pageno
)
1508 match state.layout with
1511 state.mode
<- Birdseye
(
1512 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1515 | LinkNav
(Ltgendir dir
as lt
) ->
1517 let rec loop = function
1520 match getopaque l
.pageno
with
1526 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1528 if dir
> 0 then LDfirst
else LDlast
1534 | Lnotfound
-> loop rest
1535 | Lfound
(n, x0, y0, x1, y1) ->
1536 showlinktype (getlink opaque
n);
1537 Ltexact
((l
.pageno
, n), (x0, y0, x1, y1))
1541 state.mode
<- LinkNav
linknav
1546 state.ghyll
<- noghyll;
1549 let mx, my
= state.mpos
in
1554 let conttiling pageno opaque
=
1555 tilepage pageno opaque
1556 (if conf.preload then preloadlayout state.layout else state.layout)
1559 let gotoy_and_clear_text y =
1560 if not
conf.verbose
then state.text <- "";
1565 match state.layout with
1567 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1570 let getanchory (n, top
) =
1571 let y, h = getpageyh n in
1572 y + (truncate
(top
*. float h));
1575 let gotoanchor anchor
=
1576 gotoy (getanchory anchor
);
1580 cbput state.hists
.nav
(getanchor ());
1584 let anchor = cbgetc state.hists
.nav dir
in
1589 let rec scroll f n a b =
1590 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1592 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1594 then s (float f /. float a)
1597 then 1.0 -. s ((float (f-b) /. float (n-b)))
1604 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1605 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1607 let ins = float a *. iv1
1608 and outs
= float (n-b) *. iv1 in
1610 ins +. outs
+. float ones
1612 let rec set (_N
, _A
, _B
) y sy
=
1613 let sum = summa
1.0 _N _A _B
in
1614 let dy = float (y - sy
) in
1618 then state.ghyll
<- noghyll
1621 let s = scroll n _N _A _B
in
1622 let y1 = y1 +. ((s *. dy) /. sum) in
1623 gotoy_and_clear_text (truncate
y1);
1624 state.ghyll
<- gf (n+1) y1;
1628 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1630 gf 0 (float state.y)
1633 match conf.ghyllscroll
with
1635 gotoy_and_clear_text y
1637 if state.ghyll
== noghyll
1638 then set nab
y state.y
1639 else state.ghyll
(Some
y)
1642 let gotopage n top
=
1643 let y, h = getpageyh n in
1644 let y = y + (truncate
(top
*. float h)) in
1648 let gotopage1 n top
=
1649 let y = getpagey n in
1654 let invalidate s f =
1659 match state.geomcmds
with
1660 | ps
, [] when String.length ps
= 0 ->
1662 state.geomcmds
<- s, [];
1665 state.geomcmds
<- ps
, [s, f];
1667 | ps
, (s'
, _
) :: rest
when s'
= s ->
1668 state.geomcmds
<- ps
, ((s, f) :: rest
);
1671 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1674 let opendoc path password
=
1676 state.password
<- password
;
1677 state.gen
<- state.gen
+ 1;
1678 state.docinfo
<- [];
1680 setaalevel
conf.aalevel
;
1681 Wsi.settitle
("llpp " ^
Filename.basename path
);
1682 wcmd "open %s\000%s\000" path password
;
1683 invalidate "reqlayout"
1685 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1689 let c = c *. conf.colorscale
in
1693 let scalecolor2 (r
, g
, b) =
1694 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1698 let docolumns = function
1700 | Some
((columns
, coverA
, coverB
), _
) ->
1701 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1702 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1703 if pageno
= state.pagecount
1706 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1708 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1709 pdimno+1, pdim
, rest
1714 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1716 (conf.winw
- state.scrollw
- w) / 2,
1717 y + rowh
+ conf.interpagespace, h
1720 if (pageno
- coverA
) mod columns
= 0
1721 then 0, y + rowh
+ conf.interpagespace, h
1722 else x, y, max rowh
h
1725 let rec fixrow m
= if m
= pageno
then () else
1726 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1729 let y = y + (rowh
- h) / 2 in
1730 a.(m
) <- (pdimno, x, y, pdim
);
1734 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1735 then fixrow (pageno
- columns
);
1736 a.(pageno
) <- (pdimno, x, y, pdim
);
1737 let x = x + w + xoff*2 + conf.interpagespace in
1738 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1740 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1741 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1743 docolumns conf.columns
;
1744 state.maxy <- calcheight ();
1746 if state.w <= conf.winw
- state.scrollw
1750 match state.mode
with
1751 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1752 let y, h = getpageyh pageno
in
1753 let top = (conf.winh
- h) / 2 in
1754 gotoy (max
0 (y - top))
1755 | _
-> gotoanchor state.anchor
1759 GlDraw.viewport
0 0 w h;
1760 if state.geomcmds
!= firstgeomcmds && nogeomcmds state.geomcmds
1761 then state.anchor <- getanchor ();
1764 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1767 setfontsize fstate.fontsize
;
1768 GlMat.mode `modelview
;
1769 GlMat.load_identity
();
1771 GlMat.mode `projection
;
1772 GlMat.load_identity
();
1773 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1774 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1775 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1780 else float state.x /. float state.w
1782 invalidate "geometry"
1785 state.x <- truncate
(relx *. float w);
1787 match conf.columns
with
1789 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1791 wcmd "geometry %d %d" w h);
1795 let len = String.length
state.text in
1798 match state.mode
with
1800 | View
-> state.hscrollh
1805 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1806 (x+.w, float (conf.winh
- hscrollh))
1809 let w = float (conf.winw
- state.scrollw
- 1) in
1810 if state.progress
>= 0.0 && state.progress
< 1.0
1812 GlDraw.color
(0.3, 0.3, 0.3);
1813 let w1 = w *. state.progress
in
1815 GlDraw.color
(0.0, 0.0, 0.0);
1819 GlDraw.color
(0.0, 0.0, 0.0);
1823 GlDraw.color
(1.0, 1.0, 1.0);
1824 drawstring fstate.fontsize
1825 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1828 match state.mode
with
1829 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1833 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1835 Printf.sprintf
"%s%s_" prefix
text
1844 if not
(istextentry state.mode
)
1846 let s1 = "(press 'e' to review error messasges)" in
1847 if String.length
s > 0 then s ^
" " ^
s1 else s1
1852 if String.length
s > 0
1857 let len = Queue.length
state.tilelru
in
1859 if state.memused
<= conf.memlimit
1864 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1865 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1866 let (_
, pw
, ph
, _
) = getpagedim n in
1869 && colorspace
= conf.colorspace
1870 && angle
= conf.angle
1875 match state.throttle
with
1878 then preloadlayout state.layout
1880 | Some
(layout, _
, _
) ->
1883 let x = col*conf.tilew
1884 and y = row*conf.tileh
in
1885 tilevisible layout n x y
1887 then Queue.push lruitem
state.tilelru
1889 wcmd "freetile %s" p
;
1890 state.memused
<- state.memused
- s;
1891 state.uioh#infochanged Memused
;
1892 Hashtbl.remove
state.tilemap k
;
1901 Queue.iter
(fun (k
, p
, s) ->
1902 wcmd "freetile %s" p
;
1903 state.memused
<- state.memused
- s;
1904 state.uioh#infochanged Memused
;
1905 Hashtbl.remove
state.tilemap k
;
1907 Queue.clear
state.tilelru
;
1911 let logcurrently = function
1912 | Idle
-> dolog "Idle"
1913 | Loading
(l
, gen
) ->
1914 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1915 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1917 "Tiling %d[%d,%d] page=%s cs=%s angle"
1918 l
.pageno
col row pageopaque
1919 (colorspace_to_string colorspace
)
1921 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1922 angle gen
conf.angle
state.gen
1924 conf.tilew
conf.tileh
1931 (* dolog "%S" cmds; *)
1934 try String.index cmds ' '
1935 with Not_found
-> -1
1940 let l = String.length cmds
in
1941 let op = String.sub cmds
0 spacepos in
1943 if l - spacepos < 2 then ""
1944 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1949 state.uioh#infochanged Pdim
;
1951 begin match state.mode
with
1952 | LinkNav
(Ltexact _
) -> state.mode
<- LinkNav
(Ltgendir
0)
1957 state.rects
<- state.rects1
;
1958 G.postRedisplay "clearrects";
1962 try Scanf.sscanf
args "%u" (fun n -> n)
1964 dolog "error processing 'continue' %S: %s"
1965 cmds
(Printexc.to_string exn
);
1968 state.pagecount
<- n;
1969 begin match state.currently
with
1971 state.currently
<- Idle
;
1972 state.outlines
<- Array.of_list
(List.rev
l)
1976 let cur, cmds
= state.geomcmds
in
1977 if String.length
cur = 0
1978 then failwith
"umpossible";
1980 begin match List.rev cmds
with
1982 state.geomcmds
<- "", [];
1986 state.geomcmds
<- s, List.rev rest
;
1988 if conf.maxwait
= None
1989 then G.postRedisplay "continue";
1999 then showtext ' '
args
2002 let progress, text =
2004 Scanf.sscanf
args "%f %n"
2006 f, String.sub
args pos
(String.length
args - pos
))
2008 dolog "error processing 'progress' %S: %s"
2009 cmds
(Printexc.to_string exn
);
2013 state.progress <- progress;
2014 G.postRedisplay "progress"
2017 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2019 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2020 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2021 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2023 dolog "error processing 'firstmatch' %S: %s"
2024 cmds
(Printexc.to_string exn
);
2027 let y = (getpagey pageno) + truncate
y0 in
2030 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2033 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2035 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2036 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2037 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2039 dolog "error processing 'match' %S: %s"
2040 cmds
(Printexc.to_string exn
);
2044 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2049 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2051 dolog "error processing 'page' %S: %s"
2052 cmds
(Printexc.to_string exn
);
2055 begin match state.currently
with
2056 | Loading
(l, gen
) ->
2057 vlog "page %d took %f sec" l.pageno t
;
2058 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2059 begin match state.throttle
with
2061 let preloadedpages =
2063 then preloadlayout state.layout
2068 Set.Make
(struct type t
= int let compare = (-) end) in
2070 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2071 IntSet.empty
preloadedpages
2074 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2075 if not
(IntSet.mem
pageno set)
2077 wcmd "freepage %s" opaque
;
2083 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2086 state.currently
<- Idle
;
2089 tilepage l.pageno pageopaque state.layout;
2091 load preloadedpages;
2092 if pagevisible state.layout l.pageno
2093 && layoutready state.layout
2094 then G.postRedisplay "page";
2097 | Some
(layout, _
, _
) ->
2098 state.currently
<- Idle
;
2099 tilepage l.pageno pageopaque layout;
2104 dolog "Inconsistent loading state";
2105 logcurrently state.currently
;
2110 let (x, y, opaque
, size
, t
) =
2112 Scanf.sscanf
args "%u %u %s %u %f"
2113 (fun x y p size t
-> (x, y, p
, size
, t
))
2115 dolog "error processing 'tile' %S: %s"
2116 cmds
(Printexc.to_string exn
);
2119 begin match state.currently
with
2120 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2121 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2123 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2125 wcmd "freetile %s" opaque
;
2126 state.currently
<- Idle
;
2130 puttileopaque l col row gen cs angle opaque size t
;
2131 state.memused
<- state.memused
+ size
;
2132 state.uioh#infochanged Memused
;
2134 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2135 opaque
, size
) state.tilelru
;
2138 match state.throttle
with
2139 | None
-> state.layout
2140 | Some
(layout, _
, _
) -> layout
2143 state.currently
<- Idle
;
2145 && conf.colorspace
= cs
2146 && conf.angle
= angle
2147 && tilevisible layout l.pageno x y
2148 then conttiling l.pageno pageopaque;
2150 begin match state.throttle
with
2152 preload state.layout;
2154 && conf.colorspace
= cs
2155 && conf.angle
= angle
2156 && tilevisible state.layout l.pageno x y
2157 then G.postRedisplay "tile nothrottle";
2159 | Some
(layout, y, _
) ->
2160 let ready = layoutready layout in
2164 state.layout <- layout;
2165 state.throttle
<- None
;
2166 G.postRedisplay "throttle";
2173 dolog "Inconsistent tiling state";
2174 logcurrently state.currently
;
2181 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2183 dolog "error processing 'pdim' %S: %s"
2184 cmds
(Printexc.to_string exn
);
2187 state.uioh#infochanged Pdim
;
2188 state.pdims
<- pdim :: state.pdims
2191 let (l, n, t
, h, pos
) =
2193 Scanf.sscanf
args "%u %u %d %u %n"
2194 (fun l n t
h pos
-> l, n, t
, h, pos
)
2196 dolog "error processing 'o' %S: %s"
2197 cmds
(Printexc.to_string exn
);
2200 let s = String.sub
args pos
(String.length
args - pos
) in
2201 let outline = (s, l, (n, float t
/. float h)) in
2202 begin match state.currently
with
2203 | Outlining outlines
->
2204 state.currently
<- Outlining
(outline :: outlines
)
2206 state.currently
<- Outlining
[outline]
2208 dolog "invalid outlining state";
2209 logcurrently currently
2213 state.docinfo
<- (1, args) :: state.docinfo
2216 state.uioh#infochanged Docinfo
;
2217 state.docinfo
<- List.rev
state.docinfo
2220 dolog "unknown cmd `%S'" cmds
2225 let action = function
2226 | HCprev
-> cbget cb ~
-1
2227 | HCnext
-> cbget cb
1
2228 | HCfirst
-> cbget cb ~
-(cb
.rc)
2229 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2230 and cancel
() = cb
.rc <- rc
2234 let search pattern forward
=
2235 if String.length pattern
> 0
2238 match state.layout with
2241 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2243 wcmd "search %d %d %d %d,%s\000"
2244 (btod conf.icase
) pn py (btod forward
) pattern
;
2247 let intentry text key =
2249 if key >= 32 && key < 127
2255 let text = addchar text c in
2259 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2263 let textentry text key =
2264 if key land 0xff00 = 0xff00
2266 else TEcont
(text ^
Wsi.toutf8
key)
2269 let reqlayout angle proportional
=
2270 match state.throttle
with
2272 if nogeomcmds state.geomcmds
2273 then state.anchor <- getanchor ();
2274 conf.angle
<- angle
mod 360;
2277 match state.mode
with
2278 | LinkNav _
-> state.mode
<- View
2281 conf.proportional
<- proportional
;
2282 invalidate "reqlayout"
2283 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2287 let settrim trimmargins trimfuzz
=
2288 if nogeomcmds state.geomcmds
2289 then state.anchor <- getanchor ();
2290 conf.trimmargins
<- trimmargins
;
2291 conf.trimfuzz
<- trimfuzz
;
2292 let x0, y0, x1, y1 = trimfuzz
in
2293 invalidate "settrim"
2295 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2296 Hashtbl.iter
(fun _ opaque
->
2297 wcmd "freepage %s" opaque
;
2299 Hashtbl.clear
state.pagemap
;
2303 match state.throttle
with
2305 let zoom = max
0.01 zoom in
2306 if zoom <> conf.zoom
2308 state.prevzoom
<- conf.zoom;
2310 reshape conf.winw
conf.winh
;
2311 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2314 | Some
(layout, y, started
) ->
2316 match conf.maxwait
with
2320 let dt = now () -. started
in
2328 let setcolumns columns coverA coverB
=
2331 conf.columns
<- None
;
2336 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2339 reshape conf.winw
conf.winh
;
2342 let enterbirdseye () =
2343 let zoom = float conf.thumbw
/. float conf.winw
in
2344 let birdseyepageno =
2345 let cy = conf.winh
/ 2 in
2349 let rec fold best
= function
2352 let d = cy - (l.pagedispy + l.pagevh/2)
2353 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2354 if abs
d < abs dbest
2361 state.mode
<- Birdseye
(
2362 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2365 conf.presentation <- false;
2366 conf.interpagespace <- 10;
2367 conf.hlinks
<- false;
2369 state.mstate
<- Mnone
;
2370 conf.maxwait
<- None
;
2372 match conf.beyecolumns
with
2375 Some
((c, 0, 0), [||])
2378 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2381 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2386 reshape conf.winw
conf.winh
;
2389 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2391 conf.zoom <- c.zoom;
2392 conf.presentation <- c.presentation;
2393 conf.interpagespace <- c.interpagespace;
2394 conf.maxwait
<- c.maxwait
;
2395 conf.hlinks
<- c.hlinks
;
2396 conf.beyecolumns
<- (
2397 match conf.columns
with
2398 | Some
((c, _
, _
), _
) -> Some
c
2402 match c.columns
with
2403 | Some
(c, _
) -> Some
(c, [||])
2409 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2412 reshape conf.winw
conf.winh
;
2413 state.anchor <- if goback
then anchor else (pageno, 0.0);
2416 let togglebirdseye () =
2417 match state.mode
with
2418 | Birdseye vals
-> leavebirdseye vals
true
2419 | View
-> enterbirdseye ()
2423 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2424 let pageno = max
0 (pageno - incr
) in
2425 let rec loop = function
2426 | [] -> gotopage1 pageno 0
2427 | l :: _
when l.pageno = pageno ->
2428 if l.pagedispy >= 0 && l.pagey = 0
2429 then G.postRedisplay "upbirdseye"
2430 else gotopage1 pageno 0
2431 | _
:: rest
-> loop rest
2434 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2437 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2438 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2439 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2440 let rec loop = function
2442 let y, h = getpageyh pageno in
2443 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2445 | l :: _
when l.pageno = pageno ->
2446 if l.pagevh != l.pageh
2447 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2448 else G.postRedisplay "downbirdseye"
2449 | _
:: rest
-> loop rest
2454 let optentry mode _
key =
2455 let btos b = if b then "on" else "off" in
2456 if key >= 32 && key < 127
2458 let c = Char.chr
key in
2462 try conf.scrollstep
<- int_of_string
s with exc
->
2463 state.text <- Printf.sprintf
"bad integer `%s': %s"
2464 s (Printexc.to_string exc
)
2466 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2471 conf.autoscrollstep
<- int_of_string
s;
2472 if state.autoscroll
<> None
2473 then state.autoscroll
<- Some
conf.autoscrollstep
2475 state.text <- Printf.sprintf
"bad integer `%s': %s"
2476 s (Printexc.to_string exc
)
2478 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2483 let n, a, b = columns_of_string s in
2486 state.text <- Printf.sprintf
"bad columns `%s': %s"
2487 s (Printexc.to_string exc
)
2489 TEswitch
("columns: ", "", None
, textentry, ondone)
2494 let zoom = float (int_of_string
s) /. 100.0 in
2497 state.text <- Printf.sprintf
"bad integer `%s': %s"
2498 s (Printexc.to_string exc
)
2500 TEswitch
("zoom: ", "", None
, intentry, ondone)
2505 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2507 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2508 begin match mode
with
2510 leavebirdseye beye
false;
2515 state.text <- Printf.sprintf
"bad integer `%s': %s"
2516 s (Printexc.to_string exc
)
2518 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2523 Some
(int_of_string
s)
2525 state.text <- Printf.sprintf
"bad integer `%s': %s"
2526 s (Printexc.to_string exc
);
2529 | Some angle
-> reqlayout angle
conf.proportional
2532 TEswitch
("rotation: ", "", None
, intentry, ondone)
2535 conf.icase
<- not
conf.icase
;
2536 TEdone
("case insensitive search " ^
(btos conf.icase
))
2539 conf.preload <- not
conf.preload;
2541 TEdone
("preload " ^
(btos conf.preload))
2544 conf.verbose
<- not
conf.verbose
;
2545 TEdone
("verbose " ^
(btos conf.verbose
))
2548 conf.debug
<- not
conf.debug
;
2549 TEdone
("debug " ^
(btos conf.debug
))
2552 conf.maxhfit
<- not
conf.maxhfit
;
2554 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2555 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2558 conf.crophack
<- not
conf.crophack
;
2559 TEdone
("crophack " ^
btos conf.crophack
)
2563 match conf.maxwait
with
2565 conf.maxwait
<- Some infinity
;
2566 "always wait for page to complete"
2568 conf.maxwait
<- None
;
2569 "show placeholder if page is not ready"
2574 conf.underinfo
<- not
conf.underinfo
;
2575 TEdone
("underinfo " ^
btos conf.underinfo
)
2578 conf.savebmarks
<- not
conf.savebmarks
;
2579 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2585 match state.layout with
2590 conf.interpagespace <- int_of_string
s;
2591 state.maxy <- calcheight ();
2592 let y = getpagey pageno in
2595 state.text <- Printf.sprintf
"bad integer `%s': %s"
2596 s (Printexc.to_string exc
)
2598 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2601 reqlayout conf.angle
(not
conf.proportional
);
2602 TEdone
("proportional display " ^
btos conf.proportional
)
2605 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2606 TEdone
("trim margins " ^
btos conf.trimmargins
)
2609 conf.invert
<- not
conf.invert
;
2610 TEdone
("invert colors " ^
btos conf.invert
)
2614 cbput state.hists
.sel
s;
2617 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2621 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2627 class type lvsource
= object
2628 method getitemcount
: int
2629 method getitem
: int -> (string * int)
2630 method hasaction
: int -> bool
2639 method getactive
: int
2640 method getfirst
: int
2641 method getqsearch
: string
2642 method setqsearch
: string -> unit
2646 class virtual lvsourcebase
= object
2647 val mutable m_active
= 0
2648 val mutable m_first
= 0
2649 val mutable m_qsearch
= ""
2650 val mutable m_pan
= 0
2651 method getactive
= m_active
2652 method getfirst
= m_first
2653 method getqsearch
= m_qsearch
2654 method getpan
= m_pan
2655 method setqsearch
s = m_qsearch
<- s
2658 let withoutlastutf8 s =
2659 let len = String.length
s in
2667 let b = Char.code
s.[pos
] in
2668 if b land 0b110000 = 0b11000000
2673 if Char.code
s.[len-1] land 0x80 = 0
2677 String.sub
s 0 first;
2680 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2682 state.mode
<- Textentry
(te
, onleave
);
2685 G.postRedisplay "textentrykeyboard enttext";
2687 let histaction cmd
=
2690 | Some
(action, _
) ->
2691 state.mode
<- Textentry
(
2692 (c, action cmd
, opthist
, onkey
, ondone), onleave
2694 G.postRedisplay "textentry histaction"
2697 | 0xff08 -> (* backspace *)
2698 let s = withoutlastutf8 text in
2699 let len = String.length
s in
2703 G.postRedisplay "textentrykeyboard after cancel";
2706 enttext (c, s, opthist
, onkey
, ondone)
2712 G.postRedisplay "textentrykeyboard after confirm"
2714 | 0xff52 -> histaction HCprev
2715 | 0xff54 -> histaction HCnext
2716 | 0xff50 -> histaction HCfirst
2717 | 0xff57 -> histaction HClast
2719 | 0xff1b -> (* escape*)
2720 if String.length
text = 0
2722 begin match opthist
with
2724 | Some
(_
, onhistcancel
) -> onhistcancel
()
2728 G.postRedisplay "textentrykeyboard after cancel2"
2731 enttext (c, "", opthist
, onkey
, ondone)
2734 | 0xff9f | 0xffff -> () (* delete *)
2736 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2737 begin match onkey
text key with
2741 G.postRedisplay "textentrykeyboard after confirm2";
2744 enttext (c, text, opthist
, onkey
, ondone);
2748 G.postRedisplay "textentrykeyboard after cancel3"
2751 state.mode
<- Textentry
(te
, onleave
);
2752 G.postRedisplay "textentrykeyboard switch";
2756 vlog "unhandled key %s" (Wsi.keyname
key)
2759 let firstof first active
=
2760 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2761 then max
0 (active
- (fstate.maxrows
/2))
2765 let calcfirst first active
=
2768 let rows = active
- first in
2769 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2773 let scrollph y maxy =
2774 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2775 let sh = float conf.winh
/. sh in
2776 let sh = max
sh (float conf.scrollh
) in
2781 else float y /. float maxy
2783 let position = (float conf.winh
-. sh) *. percent in
2786 if position +. sh > float conf.winh
2787 then float conf.winh
-. sh
2793 let coe s = (s :> uioh
);;
2795 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2797 val m_pan
= source#getpan
2798 val m_first
= source#getfirst
2799 val m_active
= source#getactive
2800 val m_qsearch
= source#getqsearch
2801 val m_prev_uioh
= state.uioh
2803 method private elemunder
y =
2804 let n = y / (fstate.fontsize
+1) in
2805 if m_first
+ n < source#getitemcount
2807 if source#hasaction
(m_first
+ n)
2808 then Some
(m_first
+ n)
2815 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2816 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2817 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2818 GlDraw.color
(1., 1., 1.);
2819 Gl.enable `texture_2d
;
2820 let fs = fstate.fontsize
in
2822 let ww = fstate.wwidth
in
2823 let tabw = 30.0*.ww in
2824 let itemcount = source#getitemcount
in
2826 if (row - m_first
) * nfs > conf.winh
2829 if row >= 0 && row < itemcount
2831 let (s, level
) = source#getitem
row in
2832 let y = (row - m_first
) * nfs in
2833 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2836 Gl.disable `texture_2d
;
2837 GlDraw.polygon_mode `both `line
;
2838 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2839 GlDraw.rect (1., float (y + 1))
2840 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2841 GlDraw.polygon_mode `both `fill
;
2842 GlDraw.color
(1., 1., 1.);
2843 Gl.enable `texture_2d
;
2846 let drawtabularstring s =
2847 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2850 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2853 let len = String.length
s - tabpos - 1 in
2854 let s1 = String.sub
s 0 tabpos
2855 and s2
= String.sub
s (tabpos + 1) len in
2856 let nx = drawstr x s1 in
2858 let x = x +. (max
tabw sw) in
2865 let _ = drawtabularstring s in
2872 Gl.disable `texture_2d
;
2874 method updownlevel incr
=
2875 let len = source#getitemcount
in
2877 if m_active
>= 0 && m_active
< len
2878 then snd
(source#getitem m_active
)
2882 if i
= len then i
-1 else if i
= -1 then 0 else
2883 let _, l = source#getitem i
in
2884 if l != curlevel then i
else flow (i
+incr
)
2886 let active = flow m_active
in
2887 let first = calcfirst m_first
active in
2888 G.postRedisplay "outline updownlevel";
2889 {< m_active
= active; m_first
= first >}
2891 method private key1
key mask
=
2892 let set1 active first qsearch
=
2893 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2895 let search active pattern incr
=
2898 if n >= 0 && n < source#getitemcount
2900 let s, _ = source#getitem
n in
2902 (try ignore
(Str.search_forward
re s 0); true
2903 with Not_found
-> false)
2905 else loop (n + incr
)
2912 let re = Str.regexp_case_fold pattern
in
2918 let itemcount = source#getitemcount
in
2919 let find start incr
=
2921 if i
= -1 || i
= itemcount
2924 if source#hasaction i
2926 else find (i
+ incr
)
2931 let set active first =
2932 let first = bound first 0 (itemcount - fstate.maxrows
) in
2934 coe {< m_active
= active; m_first
= first >}
2937 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2939 let incr1 = if incr
> 0 then 1 else -1 in
2940 if isvisible m_first m_active
2943 let next = m_active
+ incr
in
2945 if next < 0 || next >= itemcount
2947 else find next incr1
2949 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2955 let first = m_first
+ incr
in
2956 let first = bound first 0 (itemcount - 1) in
2958 let next = m_active
+ incr
in
2959 let next = bound next 0 (itemcount - 1) in
2962 let active = if next = -1 then m_active
else next in
2965 let first = min
next m_first
in
2967 if abs
(next - first) > fstate.maxrows
2973 let first = m_first
+ incr
in
2974 let first = bound first 0 (itemcount - 1) in
2976 let next = m_active
+ incr
in
2977 let next = bound next 0 (itemcount - 1) in
2978 let next = find next incr1 in
2980 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2982 let active = if m_active
= -1 then next else m_active
in
2987 if isvisible first active
2993 G.postRedisplay "listview navigate";
2997 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2998 let incr = if key = 0x72 then -1 else 1 in
3000 match search (m_active
+ incr) m_qsearch
incr with
3002 state.text <- m_qsearch ^
" [not found]";
3005 state.text <- m_qsearch
;
3006 active, firstof m_first
active
3008 G.postRedisplay "listview ctrl-r/s";
3009 set1 active first m_qsearch
;
3011 | 0xff08 -> (* backspace *)
3012 if String.length m_qsearch
= 0
3015 let qsearch = withoutlastutf8 m_qsearch
in
3016 let len = String.length
qsearch in
3020 G.postRedisplay "listview empty qsearch";
3021 set1 m_active m_first
"";
3025 match search m_active
qsearch ~
-1 with
3027 state.text <- qsearch ^
" [not found]";
3030 state.text <- qsearch;
3031 active, firstof m_first
active
3033 G.postRedisplay "listview backspace qsearch";
3034 set1 active first qsearch
3037 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3038 let pattern = m_qsearch ^
Wsi.toutf8
key in
3040 match search m_active
pattern 1 with
3042 state.text <- pattern ^
" [not found]";
3045 state.text <- pattern;
3046 active, firstof m_first
active
3048 G.postRedisplay "listview qsearch add";
3049 set1 active first pattern;
3051 | 0xff1b -> (* escape *)
3053 if String.length m_qsearch
= 0
3055 G.postRedisplay "list view escape";
3058 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3060 | None
-> m_prev_uioh
3065 G.postRedisplay "list view kill qsearch";
3066 source#setqsearch
"";
3067 coe {< m_qsearch
= "" >}
3070 | 0xff0d -> (* return *)
3072 let self = {< m_qsearch
= "" >} in
3073 source#setqsearch
"";
3075 G.postRedisplay "listview enter";
3076 if m_active
>= 0 && m_active
< source#getitemcount
3078 source#exit
(coe self) false m_active m_first m_pan
"";
3081 source#exit
(coe self) true m_active m_first m_pan
"";
3084 begin match opt with
3085 | None
-> m_prev_uioh
3089 | 0xff9f | 0xffff -> (* delete *)
3092 | 0xff52 -> navigate ~
-1 (* up *)
3093 | 0xff54 -> navigate 1 (* down *)
3094 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3095 | 0xff56 -> navigate fstate.maxrows
(* next *)
3097 | 0xff53 -> (* right *)
3099 G.postRedisplay "listview right";
3100 coe {< m_pan
= m_pan
- 1 >}
3102 | 0xff51 -> (* left *)
3104 G.postRedisplay "listview left";
3105 coe {< m_pan
= m_pan
+ 1 >}
3107 | 0xff50 -> (* home *)
3108 let active = find 0 1 in
3109 G.postRedisplay "listview home";
3112 | 0xff57 -> (* end *)
3113 let first = max
0 (itemcount - fstate.maxrows
) in
3114 let active = find (itemcount - 1) ~
-1 in
3115 G.postRedisplay "listview end";
3118 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3122 dolog "listview unknown key %#x" key; coe self
3124 method key key mask
=
3125 match state.mode
with
3126 | Textentry te
-> textentrykeyboard key mask te
; coe self
3127 | _ -> self#key1
key mask
3129 method button button down
x y _ =
3132 | 1 when x > conf.winw
- conf.scrollbw
->
3133 G.postRedisplay "listview scroll";
3136 let _, position, sh = self#
scrollph in
3137 if y > truncate
position && y < truncate
(position +. sh)
3139 state.mstate
<- Mscrolly
;
3143 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3144 let first = truncate
(s *. float source#getitemcount
) in
3145 let first = min source#getitemcount
first in
3146 Some
(coe {< m_first
= first; m_active
= first >})
3148 state.mstate
<- Mnone
;
3151 | 1 when not down
->
3152 begin match self#elemunder
y with
3154 G.postRedisplay "listview click";
3156 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3160 | n when (n == 4 || n == 5) && not down
->
3161 let len = source#getitemcount
in
3163 if n = 5 && m_first
+ fstate.maxrows
>= len
3167 let first = m_first
+ (if n == 4 then -1 else 1) in
3168 bound first 0 (len - 1)
3170 G.postRedisplay "listview wheel";
3171 Some
(coe {< m_first
= first >})
3176 | None
-> m_prev_uioh
3180 match state.mstate
with
3182 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3183 let first = truncate
(s *. float source#getitemcount
) in
3184 let first = min source#getitemcount
first in
3185 G.postRedisplay "listview motion";
3186 coe {< m_first
= first; m_active
= first >}
3189 method pmotion
x y =
3190 if x < conf.winw
- conf.scrollbw
3193 match self#elemunder
y with
3194 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3195 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3199 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3204 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3208 method infochanged
_ = ()
3210 method scrollpw
= (0, 0.0, 0.0)
3212 let nfs = fstate.fontsize
+ 1 in
3213 let y = m_first
* nfs in
3214 let itemcount = source#getitemcount
in
3215 let maxi = max
0 (itemcount - fstate.maxrows
) in
3216 let maxy = maxi * nfs in
3217 let p, h = scrollph y maxy in
3220 method modehash
= modehash
3223 class outlinelistview ~source
=
3226 ~source
:(source
:> lvsource
)
3228 ~modehash
:(findkeyhash conf "outline")
3231 method key key mask
=
3232 let calcfirst first active =
3235 let rows = active - first in
3236 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3240 let active = m_active
+ incr in
3241 let active = bound active 0 (source#getitemcount
- 1) in
3242 let first = calcfirst m_first
active in
3243 G.postRedisplay "outline navigate";
3244 coe {< m_active
= active; m_first
= first >}
3246 let ctrl = Wsi.withctrl mask
in
3248 | 110 when ctrl -> (* ctrl-n *)
3249 source#narrow m_qsearch
;
3250 G.postRedisplay "outline ctrl-n";
3251 coe {< m_first
= 0; m_active
= 0 >}
3253 | 117 when ctrl -> (* ctrl-u *)
3255 G.postRedisplay "outline ctrl-u";
3257 coe {< m_first
= 0; m_active
= 0 >}
3259 | 108 when ctrl -> (* ctrl-l *)
3260 let first = m_active
- (fstate.maxrows
/ 2) in
3261 G.postRedisplay "outline ctrl-l";
3262 coe {< m_first
= first >}
3264 | 0xff9f | 0xffff -> (* delete *)
3265 source#remove m_active
;
3266 G.postRedisplay "outline delete";
3267 let active = max
0 (m_active
-1) in
3268 coe {< m_first
= firstof m_first
active;
3269 m_active
= active >}
3271 | 0xff52 -> navigate ~
-1 (* up *)
3272 | 0xff54 -> navigate 1 (* down *)
3273 | 0xff55 -> (* prior *)
3274 navigate ~
-(fstate.maxrows
)
3275 | 0xff56 -> (* next *)
3276 navigate fstate.maxrows
3278 | 0xff53 -> (* [ctrl-]right *)
3282 G.postRedisplay "outline ctrl right";
3283 {< m_pan
= m_pan
+ 1 >}
3285 else self#updownlevel
1
3289 | 0xff51 -> (* [ctrl-]left *)
3293 G.postRedisplay "outline ctrl left";
3294 {< m_pan
= m_pan
- 1 >}
3296 else self#updownlevel ~
-1
3300 | 0xff50 -> (* home *)
3301 G.postRedisplay "outline home";
3302 coe {< m_first
= 0; m_active
= 0 >}
3304 | 0xff57 -> (* end *)
3305 let active = source#getitemcount
- 1 in
3306 let first = max
0 (active - fstate.maxrows
) in
3307 G.postRedisplay "outline end";
3308 coe {< m_active
= active; m_first
= first >}
3310 | _ -> super#
key key mask
3313 let outlinesource usebookmarks
=
3316 inherit lvsourcebase
3317 val mutable m_items
= empty
3318 val mutable m_orig_items
= empty
3319 val mutable m_prev_items
= empty
3320 val mutable m_narrow_pattern
= ""
3321 val mutable m_hadremovals
= false
3323 method getitemcount
=
3324 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3327 if n == Array.length m_items
&& m_hadremovals
3329 ("[Confirm removal]", 0)
3331 let s, n, _ = m_items
.(n) in
3334 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3335 ignore
(uioh
, first, qsearch);
3336 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3338 if String.length m_narrow_pattern
= 0
3344 if not
confrimremoval
3346 let _, _, anchor = m_items
.(active) in
3351 state.bookmarks
<- Array.to_list m_items
;
3352 m_orig_items
<- m_items
;
3355 else m_items
<- items;
3359 method hasaction
_ = true
3362 if Array.length m_items
!= Array.length m_orig_items
3363 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3366 method narrow
pattern =
3367 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3371 let rec loop accu n =
3374 m_narrow_pattern
<- pattern;
3375 m_items
<- Array.of_list
accu
3378 let (s, _, _) as o = m_items
.(n) in
3380 if (try ignore
(Str.search_forward
re s 0); true
3381 with Not_found
-> false)
3387 loop [] (Array.length m_items
- 1)
3392 then Array.of_list
state.bookmarks
3395 m_items
<- m_orig_items
3400 if m
>= 0 && m
< Array.length m_items
3402 m_hadremovals
<- true;
3403 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3404 let n = if n >= m
then n+1 else n in
3409 method reset
anchor items =
3410 m_hadremovals
<- false;
3411 if m_orig_items
== empty || m_prev_items
!= items
3413 m_orig_items
<- items;
3414 if String.length m_narrow_pattern
= 0
3415 then m_items
<- items;
3417 m_prev_items
<- items;
3418 let rely = getanchory anchor in
3420 let rec loop n best bestd
=
3421 if n = Array.length m_items
3424 let (_, _, anchor) = m_items
.(n) in
3425 let orely = getanchory anchor in
3426 let d = abs
(orely - rely) in
3429 else loop (n+1) best bestd
3434 m_first
<- firstof m_first
active
3438 let enterselector usebookmarks
=
3439 let source = outlinesource usebookmarks
in
3443 then Array.of_list
state.bookmarks
3446 if Array.length
outlines = 0
3448 showtext ' ' errmsg
;
3451 state.text <- source#greetmsg
;
3452 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3453 let anchor = getanchor () in
3454 source#reset
anchor outlines;
3455 state.uioh
<- coe (new outlinelistview ~
source);
3456 G.postRedisplay "enter selector";
3460 let enteroutlinemode =
3461 let f = enterselector false in
3462 fun ()-> f "Document has no outline";
3465 let enterbookmarkmode =
3466 let f = enterselector true in
3467 fun () -> f "Document has no bookmarks (yet)";
3470 let color_of_string s =
3471 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3472 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3476 let color_to_string (r
, g
, b) =
3477 let r = truncate
(r *. 256.0)
3478 and g
= truncate
(g
*. 256.0)
3479 and b = truncate
(b *. 256.0) in
3480 Printf.sprintf
"%d/%d/%d" r g
b
3483 let irect_of_string s =
3484 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3487 let irect_to_string (x0,y0,x1,y1) =
3488 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3491 let makecheckers () =
3492 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3494 converted by Issac Trotts. July 25, 2002 *)
3495 let image_height = 64
3496 and image_width
= 64 in
3500 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3502 for i
= 0 to image_width
- 1 do
3503 for j
= 0 to image_height - 1 do
3504 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3505 (if (i
land 8 ) lxor (j
land 8) = 0
3506 then [|255;255;255|] else [|200;200;200|])
3511 let image = make_image () in
3512 let id = GlTex.gen_texture
() in
3513 GlTex.bind_texture `texture_2d
id;
3514 GlPix.store
(`unpack_alignment
1);
3515 GlTex.image2d
image;
3516 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3519 `mag_filter `nearest
;
3520 `min_filter `nearest
];
3524 let setcheckers enabled
=
3525 match state.texid
with
3527 if enabled
then state.texid
<- Some
(makecheckers ())
3532 GlTex.delete_texture texid
;
3533 state.texid
<- None
;
3537 let int_of_string_with_suffix s =
3538 let l = String.length
s in
3542 let suffix = Char.lowercase
s.[l-1] in
3544 | 'k'
-> String.sub
s 0 (l-1), 10
3545 | 'm'
-> String.sub
s 0 (l-1), 20
3546 | 'g'
-> String.sub
s 0 (l-1), 30
3550 let n = int_of_string
s1 in
3551 let m = n lsl shift
in
3553 then raise
(Failure
"value too large")
3557 let string_with_suffix_of_int n =
3565 if n land ((1 lsl 20) - 1) = 0
3568 if n land ((1 lsl 10) - 1) = 0
3575 let h = n mod 1000 in
3578 then string_of_int
h ^
s
3580 let s = Printf.sprintf
"_%03d%s" h s in
3587 let defghyllscroll = (40, 8, 32);;
3588 let ghyllscroll_of_string s =
3589 let (n, a, b) as nab
=
3592 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3594 if n <= a || n <= b || a >= b
3595 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3599 let ghyllscroll_to_string ((n, a, b) as nab
) =
3600 if nab
= defghyllscroll
3602 else Printf.sprintf
"%d,%d,%d" n a b;
3605 let describe_location () =
3607 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3609 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3610 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3614 else (100. *. (float state.y /. float maxy))
3618 Printf.sprintf
"page %d of %d [%.2f%%]"
3619 (fn+1) state.pagecount
percent
3622 "pages %d-%d of %d [%.2f%%]"
3623 (fn+1) (ln
+1) state.pagecount
percent
3627 let btos b = if b then "\xe2\x88\x9a" else "" in
3628 let showextended = ref false in
3629 let leave mode
= function
3630 | Confirm
-> state.mode
<- mode
3631 | Cancel
-> state.mode
<- mode
in
3634 val mutable m_first_time
= true
3635 val mutable m_l
= []
3636 val mutable m_a
= [||]
3637 val mutable m_prev_uioh
= nouioh
3638 val mutable m_prev_mode
= View
3640 inherit lvsourcebase
3642 method reset prev_mode prev_uioh
=
3643 m_a
<- Array.of_list
(List.rev m_l
);
3645 m_prev_mode
<- prev_mode
;
3646 m_prev_uioh
<- prev_uioh
;
3650 if n >= Array.length m_a
3654 | _, _, _, Action
_ -> m_active
<- n
3658 m_first_time
<- false;
3661 method int name get
set =
3663 (name
, `
int get
, 1, Action
(
3666 try set (int_of_string
s)
3668 state.text <- Printf.sprintf
"bad integer `%s': %s"
3669 s (Printexc.to_string exn
)
3672 let te = name ^
": ", "", None
, intentry, ondone in
3673 state.mode
<- Textentry
(te, leave m_prev_mode
);
3677 method int_with_suffix name get
set =
3679 (name
, `intws get
, 1, Action
(
3682 try set (int_of_string_with_suffix s)
3684 state.text <- Printf.sprintf
"bad integer `%s': %s"
3685 s (Printexc.to_string exn
)
3689 name ^
": ", "", None
, intentry_with_suffix, ondone
3691 state.mode
<- Textentry
(te, leave m_prev_mode
);
3695 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3697 (name
, `
bool (btos, get
), offset
, Action
(
3704 method color name get
set =
3706 (name
, `color get
, 1, Action
(
3708 let invalid = (nan
, nan
, nan
) in
3711 try color_of_string s
3713 state.text <- Printf.sprintf
"bad color `%s': %s"
3714 s (Printexc.to_string exn
);
3720 let te = name ^
": ", "", None
, textentry, ondone in
3721 state.text <- color_to_string (get
());
3722 state.mode
<- Textentry
(te, leave m_prev_mode
);
3726 method string name get
set =
3728 (name
, `
string get
, 1, Action
(
3730 let ondone s = set s in
3731 let te = name ^
": ", "", None
, textentry, ondone in
3732 state.mode
<- Textentry
(te, leave m_prev_mode
);
3736 method colorspace name get
set =
3738 (name
, `
string get
, 1, Action
(
3741 let vals = [| "rgb"; "bgr"; "gray" |] in
3743 inherit lvsourcebase
3746 m_active
<- int_of_colorspace conf.colorspace
;
3749 method getitemcount
= Array.length
vals
3750 method getitem
n = (vals.(n), 0)
3751 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3752 ignore
(uioh
, first, pan
, qsearch);
3753 if not cancel
then set active;
3755 method hasaction
_ = true
3759 let modehash = findkeyhash conf "info" in
3760 coe (new listview ~
source ~trusted
:true ~
modehash)
3763 method caption
s offset
=
3764 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3766 method caption2
s f offset
=
3767 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3769 method getitemcount
= Array.length m_a
3772 let tostr = function
3773 | `
int f -> string_of_int
(f ())
3774 | `intws
f -> string_with_suffix_of_int (f ())
3776 | `color
f -> color_to_string (f ())
3777 | `
bool (btos, f) -> btos (f ())
3780 let name, t
, offset
, _ = m_a
.(n) in
3781 ((let s = tostr t
in
3782 if String.length
s > 0
3783 then Printf.sprintf
"%s\t%s" name s
3787 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3791 m_qsearch
<- qsearch;
3793 match m_a
.(active) with
3794 | _, _, _, Action
f -> f uioh
3806 method hasaction
n =
3808 | _, _, _, Action
_ -> true
3812 let rec fillsrc prevmode prevuioh
=
3813 let sep () = src#caption
"" 0 in
3814 let colorp name get
set =
3816 (fun () -> color_to_string (get
()))
3819 let c = color_of_string v in
3822 state.text <- Printf.sprintf
"bad color `%s': %s"
3823 v (Printexc.to_string exn
);
3826 let oldmode = state.mode
in
3827 let birdseye = isbirdseye state.mode
in
3829 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3831 src#
bool "presentation mode"
3832 (fun () -> conf.presentation)
3834 conf.presentation <- v;
3835 state.anchor <- getanchor ();
3838 src#
bool "ignore case in searches"
3839 (fun () -> conf.icase
)
3840 (fun v -> conf.icase
<- v);
3843 (fun () -> conf.preload)
3844 (fun v -> conf.preload <- v);
3846 src#
bool "highlight links"
3847 (fun () -> conf.hlinks
)
3848 (fun v -> conf.hlinks
<- v);
3850 src#
bool "under info"
3851 (fun () -> conf.underinfo
)
3852 (fun v -> conf.underinfo
<- v);
3854 src#
bool "persistent bookmarks"
3855 (fun () -> conf.savebmarks
)
3856 (fun v -> conf.savebmarks
<- v);
3858 src#
bool "proportional display"
3859 (fun () -> conf.proportional
)
3860 (fun v -> reqlayout conf.angle
v);
3862 src#
bool "trim margins"
3863 (fun () -> conf.trimmargins
)
3864 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3866 src#
bool "persistent location"
3867 (fun () -> conf.jumpback
)
3868 (fun v -> conf.jumpback
<- v);
3871 src#
int "inter-page space"
3872 (fun () -> conf.interpagespace)
3874 conf.interpagespace <- n;
3876 match state.layout with
3881 state.maxy <- calcheight ();
3882 let y = getpagey pageno in
3887 (fun () -> conf.pagebias
)
3888 (fun v -> conf.pagebias
<- v);
3890 src#
int "scroll step"
3891 (fun () -> conf.scrollstep
)
3892 (fun n -> conf.scrollstep
<- n);
3894 src#
int "auto scroll step"
3896 match state.autoscroll
with
3898 | _ -> conf.autoscrollstep
)
3900 if state.autoscroll
<> None
3901 then state.autoscroll
<- Some
n;
3902 conf.autoscrollstep
<- n);
3905 (fun () -> truncate
(conf.zoom *. 100.))
3906 (fun v -> setzoom ((float v) /. 100.));
3909 (fun () -> conf.angle
)
3910 (fun v -> reqlayout v conf.proportional
);
3912 src#
int "scroll bar width"
3913 (fun () -> state.scrollw
)
3917 reshape conf.winw
conf.winh
;
3920 src#
int "scroll handle height"
3921 (fun () -> conf.scrollh
)
3922 (fun v -> conf.scrollh
<- v;);
3924 src#
int "thumbnail width"
3925 (fun () -> conf.thumbw
)
3927 conf.thumbw
<- min
4096 v;
3930 leavebirdseye beye
false;
3935 src#
string "columns"
3937 match conf.columns
with
3939 | Some
(multicol
, _) -> columns_to_string multicol
)
3941 let n, a, b = columns_of_string v in
3945 src#caption
"Presentation mode" 0;
3946 src#
bool "scrollbar visible"
3947 (fun () -> conf.scrollbarinpm
)
3949 if v != conf.scrollbarinpm
3951 conf.scrollbarinpm
<- v;
3952 if conf.presentation
3954 state.scrollw
<- if v then conf.scrollbw
else 0;
3955 reshape conf.winw
conf.winh
;
3961 src#caption
"Pixmap cache" 0;
3962 src#int_with_suffix
"size (advisory)"
3963 (fun () -> conf.memlimit
)
3964 (fun v -> conf.memlimit
<- v);
3967 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3968 (string_with_suffix_of_int state.memused
)
3969 (Hashtbl.length
state.tilemap
)) 1;
3972 src#caption
"Layout" 0;
3973 src#caption2
"Dimension"
3975 Printf.sprintf
"%dx%d (virtual %dx%d)"
3981 src#caption2
"Position" (fun () ->
3982 Printf.sprintf
"%dx%d" state.x state.y
3985 src#caption2
"Visible" (fun () -> describe_location ()) 1
3989 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3990 "Save these parameters as global defaults at exit"
3991 (fun () -> conf.bedefault
)
3992 (fun v -> conf.bedefault
<- v)
3996 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3997 src#
bool ~offset
:0 ~
btos "Extended parameters"
3998 (fun () -> !showextended)
3999 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4003 (fun () -> conf.checkers
)
4004 (fun v -> conf.checkers
<- v; setcheckers v);
4005 src#
bool "update cursor"
4006 (fun () -> conf.updatecurs
)
4007 (fun v -> conf.updatecurs
<- v);
4009 (fun () -> conf.verbose
)
4010 (fun v -> conf.verbose
<- v);
4011 src#
bool "invert colors"
4012 (fun () -> conf.invert
)
4013 (fun v -> conf.invert
<- v);
4015 (fun () -> conf.maxhfit
)
4016 (fun v -> conf.maxhfit
<- v);
4017 src#
bool "redirect stderr"
4018 (fun () -> conf.redirectstderr)
4019 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4020 src#
string "uri launcher"
4021 (fun () -> conf.urilauncher
)
4022 (fun v -> conf.urilauncher
<- v);
4023 src#
string "path launcher"
4024 (fun () -> conf.pathlauncher
)
4025 (fun v -> conf.pathlauncher
<- v);
4026 src#
string "tile size"
4027 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4030 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4031 conf.tileh
<- max
64 w;
4032 conf.tilew
<- max
64 h;
4035 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4036 v (Printexc.to_string exn
));
4037 src#
int "texture count"
4038 (fun () -> conf.texcount
)
4041 then conf.texcount
<- v
4042 else showtext '
!'
" Failed to set texture count please retry later"
4044 src#
int "slice height"
4045 (fun () -> conf.sliceheight
)
4047 conf.sliceheight
<- v;
4048 wcmd "sliceh %d" conf.sliceheight
;
4050 src#
int "anti-aliasing level"
4051 (fun () -> conf.aalevel
)
4053 conf.aalevel
<- bound v 0 8;
4054 state.anchor <- getanchor ();
4055 opendoc state.path
state.password
;
4057 src#
int "ui font size"
4058 (fun () -> fstate.fontsize
)
4059 (fun v -> setfontsize (bound v 5 100));
4060 colorp "background color"
4061 (fun () -> conf.bgcolor
)
4062 (fun v -> conf.bgcolor
<- v);
4063 src#
bool "crop hack"
4064 (fun () -> conf.crophack
)
4065 (fun v -> conf.crophack
<- v);
4066 src#
string "trim fuzz"
4067 (fun () -> irect_to_string conf.trimfuzz
)
4070 conf.trimfuzz
<- irect_of_string v;
4072 then settrim true conf.trimfuzz
;
4074 state.text <- Printf.sprintf
"bad irect `%s': %s"
4075 v (Printexc.to_string exn
)
4077 src#
string "throttle"
4079 match conf.maxwait
with
4080 | None
-> "show place holder if page is not ready"
4083 then "wait for page to fully render"
4085 "wait " ^ string_of_float
time
4086 ^
" seconds before showing placeholder"
4090 let f = float_of_string
v in
4092 then conf.maxwait
<- None
4093 else conf.maxwait
<- Some
f
4095 state.text <- Printf.sprintf
"bad time `%s': %s"
4096 v (Printexc.to_string exn
)
4098 src#
string "ghyll scroll"
4100 match conf.ghyllscroll
with
4102 | Some nab
-> ghyllscroll_to_string nab
4107 if String.length
v = 0
4109 else Some
(ghyllscroll_of_string v)
4111 conf.ghyllscroll
<- gs
4113 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4114 v (Printexc.to_string exn
)
4116 src#
string "selection command"
4117 (fun () -> conf.selcmd
)
4118 (fun v -> conf.selcmd
<- v);
4119 src#colorspace
"color space"
4120 (fun () -> colorspace_to_string conf.colorspace
)
4122 conf.colorspace
<- colorspace_of_int v;
4129 src#caption
"Document" 0;
4130 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4131 src#caption2
"Pages"
4132 (fun () -> string_of_int
state.pagecount
) 1;
4133 src#caption2
"Dimensions"
4134 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4138 src#caption
"Trimmed margins" 0;
4139 src#caption2
"Dimensions"
4140 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4143 src#reset prevmode prevuioh
;
4147 let prevmode = state.mode
4148 and prevuioh
= state.uioh in
4149 fillsrc prevmode prevuioh
;
4150 let source = (src :> lvsource
) in
4151 let modehash = findkeyhash conf "info" in
4152 state.uioh <- coe (object (self)
4153 inherit listview ~
source ~trusted
:true ~
modehash as super
4154 val mutable m_prevmemused
= 0
4155 method infochanged
= function
4157 if m_prevmemused
!= state.memused
4159 m_prevmemused
<- state.memused
;
4160 G.postRedisplay "memusedchanged";
4162 | Pdim
-> G.postRedisplay "pdimchanged"
4163 | Docinfo
-> fillsrc prevmode prevuioh
4165 method key key mask
=
4166 if not
(Wsi.withctrl mask
)
4169 | 0xff51 -> coe (self#updownlevel ~
-1)
4170 | 0xff53 -> coe (self#updownlevel
1)
4171 | _ -> super#
key key mask
4172 else super#
key key mask
4174 G.postRedisplay "info";
4180 inherit lvsourcebase
4181 method getitemcount
= Array.length
state.help
4183 let s, n, _ = state.help
.(n) in
4186 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4190 m_qsearch
<- qsearch;
4191 match state.help
.(active) with
4192 | _, _, Action
f -> Some
(f uioh)
4202 method hasaction
n =
4203 match state.help
.(n) with
4204 | _, _, Action
_ -> true
4211 let modehash = findkeyhash conf "help" in
4212 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4213 G.postRedisplay "help";
4218 let re = Str.regexp
"[\r\n]" in
4220 inherit lvsourcebase
4221 val mutable m_items
= [||]
4223 method getitemcount
= 1 + Array.length m_items
4228 else m_items
.(n-1), 0
4230 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4235 then Buffer.clear
state.errmsgs
;
4236 m_qsearch
<- qsearch;
4243 method hasaction
n =
4247 state.newerrmsgs
<- false;
4248 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4249 m_items
<- Array.of_list
l
4257 let source = (msgsource :> lvsource
) in
4258 let modehash = findkeyhash conf "listview" in
4259 state.uioh <- coe (object
4260 inherit listview ~
source ~trusted
:false ~
modehash as super
4263 then msgsource#reset
;
4266 G.postRedisplay "msgs";
4269 let quickbookmark ?title
() =
4270 match state.layout with
4276 let sec = Unix.gettimeofday
() in
4277 let tm = Unix.localtime
sec in
4278 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4282 (tm.Unix.tm_year
+ 1900)
4285 | Some
title -> title
4288 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4293 state.fullscreen
<- None
;
4297 let setautoscrollspeed step goingdown
=
4298 let incr = max
1 ((abs step
) / 2) in
4299 let incr = if goingdown
then incr else -incr in
4300 let astep = step
+ incr in
4301 state.autoscroll
<- Some
astep;
4304 let viewkeyboard key mask
=
4306 let mode = state.mode in
4307 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4310 G.postRedisplay "view:enttext"
4312 let ctrl = Wsi.withctrl mask
in
4317 | 0xff63 -> (* insert *)
4318 if conf.angle
mod 360 = 0
4320 state.mode <- LinkNav
(Ltgendir
0);
4323 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4325 | 0xff1b | 113 -> (* escape / q *)
4326 begin match state.mstate
with
4328 state.mstate
<- Mnone
;
4329 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4330 G.postRedisplay "kill zoom rect";
4332 match state.ranchors
with
4334 | (path
, password
, anchor) :: rest
->
4335 state.ranchors
<- rest
;
4336 state.anchor <- anchor;
4337 opendoc path password
4340 | 0xff08 -> (* backspace *)
4341 let y = getnav ~
-1 in
4342 gotoy_and_clear_text y
4350 G.postRedisplay "dehighlight";
4352 | 47 | 63 -> (* / ? *)
4353 let ondone isforw
s =
4354 cbput state.hists
.pat
s;
4355 state.searchpattern
<- s;
4358 let s = String.create
1 in
4359 s.[0] <- Char.chr
key;
4360 enttext (s, "", Some
(onhist state.hists
.pat
),
4361 textentry, ondone (key = 47))
4363 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4364 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4365 setzoom (conf.zoom +. incr)
4367 | 43 | 0xffab -> (* + *)
4370 try int_of_string
s with exc
->
4371 state.text <- Printf.sprintf
"bad integer `%s': %s"
4372 s (Printexc.to_string exc
);
4378 state.text <- "page bias is now " ^ string_of_int
n;
4381 enttext ("page bias: ", "", None
, intentry, ondone)
4383 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4384 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4385 setzoom (max
0.01 (conf.zoom -. decr))
4387 | 45 | 0xffad -> (* - *)
4388 let ondone msg
= state.text <- msg
in
4390 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4391 optentry state.mode, ondone
4394 | 48 when ctrl -> (* ctrl-0 *)
4397 | 49 when ctrl -> (* 1 *)
4398 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4402 | 0xffc6 -> (* f9 *)
4405 | 57 when ctrl -> (* ctrl-9 *)
4408 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4409 when not
ctrl -> (* 0..9 *)
4412 try int_of_string
s with exc
->
4413 state.text <- Printf.sprintf
"bad integer `%s': %s"
4414 s (Printexc.to_string exc
);
4420 cbput state.hists
.pag
(string_of_int
n);
4421 gotopage1 (n + conf.pagebias
- 1) 0;
4424 let pageentry text key =
4425 match Char.unsafe_chr
key with
4426 | 'g'
-> TEdone
text
4427 | _ -> intentry text key
4429 let text = "x" in text.[0] <- Char.chr
key;
4430 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4433 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4434 reshape conf.winw
conf.winh
;
4437 conf.hlinks
<- not
conf.hlinks
;
4438 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4439 G.postRedisplay "toggle highlightlinks";
4442 begin match state.autoscroll
with
4444 conf.autoscrollstep
<- step
;
4445 state.autoscroll
<- None
4447 if conf.autoscrollstep
= 0
4448 then state.autoscroll
<- Some
1
4449 else state.autoscroll
<- Some
conf.autoscrollstep
4453 conf.presentation <- not
conf.presentation;
4454 if conf.presentation
4456 if not
conf.scrollbarinpm
4457 then state.scrollw
<- 0;
4460 state.scrollw
<- conf.scrollbw
;
4462 showtext ' '
("presentation mode " ^
4463 if conf.presentation then "on" else "off");
4464 state.anchor <- getanchor ();
4468 begin match state.fullscreen
with
4470 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4473 state.fullscreen
<- None
;
4478 gotoy_and_clear_text 0
4481 gotopage1 (state.pagecount
- 1) 0
4483 | 112 | 78 -> (* p|N *)
4484 search state.searchpattern
false
4486 | 110 | 0xffc0 -> (* n|F3 *)
4487 search state.searchpattern
true
4490 begin match state.layout with
4493 gotoy_and_clear_text (getpagey l.pageno)
4497 begin match List.rev
state.layout with
4500 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4501 gotoy_and_clear_text (getpagey pageno)
4504 | 0xff9f | 0xffff -> (* delete *)
4505 begin match state.layout with
4508 let pageno = max
0 (l.pageno-1) in
4509 gotoy_and_clear_text (getpagey pageno)
4513 showtext ' '
(describe_location ());
4516 begin match state.layout with
4519 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4524 enterbookmarkmode ()
4526 | 104 | 0xffbe -> (* h|F1 *)
4532 | 101 when conf.redirectstderr -> (* e *)
4537 match state.layout with
4540 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4544 enttext ("bookmark: ", "", None
, textentry, ondone)
4548 showtext ' '
"Quick bookmark added";
4551 begin match state.layout with
4553 let rect = getpdimrect
l.pagedimno
in
4557 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4558 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4560 (truncate
(rect.(1) -. rect.(0)),
4561 truncate
(rect.(3) -. rect.(0)))
4563 let w = truncate
((float w)*.conf.zoom)
4564 and h = truncate
((float h)*.conf.zoom) in
4567 state.anchor <- getanchor ();
4568 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4570 G.postRedisplay "z";
4575 | 50 when ctrl -> (* ctrl-2 *)
4576 let maxw = getmaxw
() in
4578 then setzoom (maxw /. float conf.winw
)
4580 | 60 | 62 -> (* < > *)
4581 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4583 | 91 | 93 -> (* [ ] *)
4585 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4587 G.postRedisplay "brightness";
4589 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4590 setzoom state.prevzoom
4592 | 107 | 0xff52 -> (* k up *)
4593 begin match state.autoscroll
with
4595 begin match state.mode with
4596 | Birdseye beye
-> upbirdseye 1 beye
4599 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4600 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4603 setautoscrollspeed n false
4606 | 106 | 0xff54 -> (* j down *)
4607 begin match state.autoscroll
with
4609 begin match state.mode with
4610 | Birdseye beye
-> downbirdseye 1 beye
4613 then gotoy_and_clear_text (clamp (conf.winh
/2))
4614 else gotoy_and_clear_text (clamp conf.scrollstep
)
4617 setautoscrollspeed n true
4620 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4628 let dx = if key = 0xff51 then dx else -dx in
4629 state.x <- state.x + dx;
4630 gotoy_and_clear_text state.y
4633 G.postRedisplay "lef/right"
4636 | 0xff55 -> (* prior *)
4640 match state.layout with
4642 | l :: _ -> state.y - l.pagey
4648 | 0xff56 -> (* next *)
4652 match List.rev
state.layout with
4654 | l :: _ -> getpagey l.pageno
4660 | 0xff50 -> gotoghyll 0
4661 | 0xff57 -> gotoghyll (clamp state.maxy)
4662 | 0xff53 when Wsi.withalt mask
->
4663 gotoghyll (getnav ~
-1)
4664 | 0xff51 when Wsi.withalt mask
->
4665 gotoghyll (getnav 1)
4668 state.anchor <- getanchor ();
4669 opendoc state.path
state.password
4674 | 118 when conf.debug
-> (* v *)
4677 match getopaque l.pageno with
4680 let x0, y0, x1, y1 = pagebbox opaque
in
4681 let a,b = float x0, float y0 in
4682 let c,d = float x1, float y0 in
4683 let e,f = float x1, float y1 in
4684 let h,j
= float x0, float y1 in
4685 let rect = (a,b,c,d,e,f,h,j
) in
4687 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4689 G.postRedisplay "v";
4692 vlog "huh? %s" (Wsi.keyname
key)
4695 let gotounder = function
4696 | Ulinkgoto
(pageno, top) ->
4700 gotopage1 pageno top;
4706 | Uremote
(filename
, pageno) ->
4708 if Sys.file_exists filename
4711 let dir = Filename.dirname
state.path in
4712 let path = Filename.concat
dir filename
in
4713 if Sys.file_exists
path
4717 if String.length
path > 0
4719 let anchor = getanchor () in
4720 let ranchor = state.path, state.password
, anchor in
4721 state.anchor <- (pageno, 0.0);
4722 state.ranchors
<- ranchor :: state.ranchors
;
4725 else showtext '
!'
("Could not find " ^ filename
)
4727 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4730 let linknavkeyboard key mask
linknav =
4731 let getpage pageno =
4732 let rec loop = function
4734 | l :: _ when l.pageno = pageno -> Some
l
4735 | _ :: rest
-> loop rest
4736 in loop state.layout
4738 let doexact (pageno, n) =
4739 match getopaque pageno, getpage pageno with
4740 | Some opaque
, Some
l ->
4743 let under = getlink opaque
n in
4744 G.postRedisplay "link gotounder";
4750 | 0xff50 -> (* home *)
4751 Some
(findlink opaque LDfirst
), -1
4753 | 0xff57 -> (* end *)
4754 Some
(findlink opaque LDlast
), 1
4756 | 0xff51 -> (* left *)
4757 Some
(findlink opaque
(LDleft
n)), -1
4759 | 0xff53 -> (* right *)
4760 Some
(findlink opaque
(LDright
n)), 1
4762 | 0xff52 -> (* up *)
4763 Some
(findlink opaque
(LDup
n)), -1
4765 | 0xff54 -> (* down *)
4766 Some
(findlink opaque
(LDdown
n)), 1
4771 begin match findpwl
l.pageno dir with
4775 state.mode <- LinkNav
(Ltgendir
dir);
4776 let y, h = getpageyh pageno in
4779 then y + h - conf.winh
4784 begin match getopaque pageno, getpage pageno with
4785 | Some opaque
, Some
_ ->
4787 let ld = if dir > 0 then LDfirst
else LDlast
in
4790 begin match link with
4791 | Lfound
(m, x0, y0, x1, y1) ->
4792 let r = x0, y0, x1, y1 in
4793 showlinktype (getlink opaque
m);
4794 state.mode <- LinkNav
(Ltexact
((pageno, m), r));
4795 G.postRedisplay "linknav jpage";
4802 begin match opt with
4803 | Some Lnotfound
-> pwl l dir;
4804 | Some
(Lfound
(m, x0, y0, x1, y1)) ->
4809 then gotopage1 l.pageno y0
4811 let d = fstate.fontsize
+ 1 in
4812 if y1 - l.pagey > l.pagevh - d
4813 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
4814 else G.postRedisplay "linknav";
4816 let r = x0, y0, x1, y1 in
4817 showlinktype (getlink opaque
m);
4818 state.mode <- LinkNav
(Ltexact
((l.pageno, m), r));
4822 state.mode <- LinkNav
(Ltgendir
0);
4823 viewkeyboard key mask
4825 | _ -> viewkeyboard key mask
4830 G.postRedisplay "leave linknav"
4834 | Ltgendir
_ -> viewkeyboard key mask
4835 | Ltexact
(exact
, _) -> doexact exact
4838 let keyboard key mask
=
4839 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4840 then wcmd "interrupt"
4841 else state.uioh <- state.uioh#
key key mask
4844 let birdseyekeyboard key mask
4845 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4847 match conf.columns
with
4849 | Some
((c, _, _), _) -> c
4852 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4853 let y, h = getpageyh pageno in
4854 let top = (conf.winh
- h) / 2 in
4855 gotoy (max
0 (y - top))
4856 | 0xff0d -> leavebirdseye beye
false
4857 | 0xff1b -> leavebirdseye beye
true (* escape *)
4858 | 0xff52 -> upbirdseye incr beye
(* prior *)
4859 | 0xff54 -> downbirdseye incr beye
(* next *)
4860 | 0xff51 -> upbirdseye 1 beye
(* up *)
4861 | 0xff53 -> downbirdseye 1 beye
(* down *)
4864 begin match state.layout with
4868 state.mode <- Birdseye
(
4869 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4871 gotopage1 l.pageno 0;
4874 let layout = layout (state.y-conf.winh
) conf.winh
in
4876 | [] -> gotoy (clamp (-conf.winh
))
4878 state.mode <- Birdseye
(
4879 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4881 gotopage1 l.pageno 0
4884 | [] -> gotoy (clamp (-conf.winh
))
4888 begin match List.rev
state.layout with
4890 let layout = layout (state.y + conf.winh
) conf.winh
in
4891 begin match layout with
4893 let incr = l.pageh
- l.pagevh in
4898 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4900 G.postRedisplay "birdseye pagedown";
4902 else gotoy (clamp (incr + conf.interpagespace*2));
4906 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4907 gotopage1 l.pageno 0;
4910 | [] -> gotoy (clamp conf.winh
)
4914 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4918 let pageno = state.pagecount
- 1 in
4919 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4920 if not
(pagevisible state.layout pageno)
4923 match List.rev
state.pdims
with
4925 | (_, _, h, _) :: _ -> h
4927 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4928 else G.postRedisplay "birdseye end";
4929 | _ -> viewkeyboard key mask
4934 match state.mode with
4935 | Textentry
_ -> scalecolor 0.4
4937 | View
-> scalecolor 1.0
4938 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4939 if l.pageno = hooverpageno
4942 if l.pageno = pageno
4948 begin match getopaque l.pageno with
4950 if tileready l l.pagex l.pagey
4952 let x = l.pagedispx - l.pagex
4953 and y = l.pagedispy - l.pagey in
4954 postprocess opaque
conf.hlinks
x y;
4960 let scrollindicator () =
4961 let sbw, ph
, sh = state.uioh#
scrollph in
4962 let sbh, pw
, sw = state.uioh#scrollpw
in
4964 GlDraw.color (0.64, 0.64, 0.64);
4966 (float (conf.winw
- sbw), 0.)
4967 (float conf.winw
, float conf.winh
)
4970 (0., float (conf.winh
- sbh))
4971 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4973 GlDraw.color (0.0, 0.0, 0.0);
4976 (float (conf.winw
- sbw), ph
)
4977 (float conf.winw
, ph
+. sh)
4980 (pw
, float (conf.winh
- sbh))
4981 (pw
+. sw, float conf.winh
)
4986 match state.mstate
with
4987 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4990 | Msel
((x0, y0), (x1, y1)) ->
4991 let rec loop = function
4993 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4994 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4995 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4996 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4998 match getopaque l.pageno with
5000 let x0, y0 = pagetranslatepoint l x0 y0 in
5001 let x1, y1 = pagetranslatepoint l x1 y1 in
5002 seltext opaque
(x0, y0, x1, y1);
5010 let showrects rects
=
5012 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5013 GlDraw.polygon_mode `both `fill
;
5014 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5016 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5018 if l.pageno = pageno
5020 let dx = float (l.pagedispx - l.pagex) in
5021 let dy = float (l.pagedispy - l.pagey) in
5022 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5023 GlDraw.begins `quads
;
5025 GlDraw.vertex2
(x0+.dx, y0+.dy);
5026 GlDraw.vertex2
(x1+.dx, y1+.dy);
5027 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5028 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5039 GlClear.color (scalecolor2 conf.bgcolor
);
5040 GlClear.clear
[`
color];
5041 List.iter
drawpage state.layout;
5043 match state.mode with
5044 | LinkNav
(Ltexact
((pageno, _), (x0, y0, x1, y1))) ->
5056 begin match state.mstate
with
5057 | Mzoomrect
((x0, y0), (x1, y1)) ->
5059 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5060 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5061 GlDraw.rect (float x0, float y0)
5062 (float x1, float y1);
5071 let zoomrect x y x1 y1 =
5074 and y0 = min
y y1 in
5075 gotoy (state.y + y0);
5076 state.anchor <- getanchor ();
5077 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5079 if state.w < conf.winw
- state.scrollw
5080 then (conf.winw
- state.scrollw
- state.w) / 2
5083 state.x <- (state.x + margin) - x0;
5085 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5086 state.mstate
<- Mnone
;
5090 let winw = conf.winw - state.scrollw
- 1 in
5091 let s = float x /. float winw in
5092 let destx = truncate
(float (state.w + winw) *. s) in
5093 state.x <- winw - destx;
5094 gotoy_and_clear_text state.y;
5095 state.mstate
<- Mscrollx
;
5099 let s = float y /. float conf.winh
in
5100 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5101 gotoy_and_clear_text desty;
5102 state.mstate
<- Mscrolly
;
5105 let viewmouse button down
x y mask
=
5107 | n when (n == 4 || n == 5) && not down
->
5108 if Wsi.withctrl mask
5110 match state.mstate
with
5111 | Mzoom
(oldn
, i
) ->
5119 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5121 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5123 let zoom = conf.zoom -. incr in
5125 state.mstate
<- Mzoom
(n, 0);
5127 state.mstate
<- Mzoom
(n, i
+1);
5129 else state.mstate
<- Mzoom
(n, 0)
5131 | _ -> state.mstate
<- Mzoom
(n, 0)
5134 match state.autoscroll
with
5135 | Some step
-> setautoscrollspeed step
(n=4)
5139 then -conf.scrollstep
5140 else conf.scrollstep
5142 let incr = incr * 2 in
5143 let y = clamp incr in
5144 gotoy_and_clear_text y
5147 | 1 when Wsi.withctrl mask
->
5150 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5151 state.mstate
<- Mpan
(x, y)
5154 state.mstate
<- Mnone
5159 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5161 state.mstate
<- Mzoomrect
(p, p)
5164 match state.mstate
with
5165 | Mzoomrect
((x0, y0), _) ->
5166 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5167 then zoomrect x0 y0 x y
5169 state.mstate
<- Mnone
;
5170 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5171 G.postRedisplay "kill accidental zoom rect";
5174 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5175 state.mstate
<- Mnone
5178 | 1 when x > conf.winw - state.scrollw
->
5181 let _, position, sh = state.uioh#
scrollph in
5182 if y > truncate
position && y < truncate
(position +. sh)
5183 then state.mstate
<- Mscrolly
5186 state.mstate
<- Mnone
5188 | 1 when y > conf.winh
- state.hscrollh ->
5191 let _, position, sw = state.uioh#scrollpw
in
5192 if x > truncate
position && x < truncate
(position +. sw)
5193 then state.mstate
<- Mscrollx
5196 state.mstate
<- Mnone
5199 let dest = if down
then getunder x y else Unone
in
5200 begin match dest with
5201 | Ulinkgoto
(pageno, top) ->
5205 gotopage1 pageno top;
5211 | Uremote
(filename
, pageno) ->
5213 if Sys.file_exists filename
5216 let dir = Filename.dirname
state.path in
5217 let path = Filename.concat
dir filename
in
5218 if Sys.file_exists
path
5222 if String.length
path > 0
5224 let anchor = getanchor () in
5225 let ranchor = state.path, state.password
, anchor in
5226 state.anchor <- (pageno, 0.0);
5227 state.ranchors
<- ranchor :: state.ranchors
;
5230 else showtext '
!'
("Could not find " ^ filename
)
5232 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5234 | Unone
when down
->
5235 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5236 state.mstate
<- Mpan
(x, y);
5238 | Unone
| Utext
_ ->
5241 if conf.angle
mod 360 = 0
5243 state.mstate
<- Msel
((x, y), (x, y));
5244 G.postRedisplay "mouse select";
5248 match state.mstate
with
5251 | Mzoom
_ | Mscrollx
| Mscrolly
->
5252 state.mstate
<- Mnone
5254 | Mzoomrect
((x0, y0), _) ->
5258 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5259 state.mstate
<- Mnone
5261 | Msel
((_, y0), (_, y1)) ->
5262 let rec loop = function
5265 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5266 || ((y1 >= l.pagedispy
5267 && y1 <= (l.pagedispy + l.pagevh)))
5269 match getopaque l.pageno with
5271 copysel
conf.selcmd opaque
;
5272 G.postRedisplay "copysel"
5277 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5278 state.mstate
<- Mnone
;
5285 let birdseyemouse button down
x y mask
5286 (conf, leftx
, _, hooverpageno
, anchor) =
5289 let rec loop = function
5292 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5293 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5295 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5301 | _ -> viewmouse button down
x y mask
5304 let mouse button down
x y mask
=
5305 state.uioh <- state.uioh#button button down
x y mask
;
5309 state.uioh <- state.uioh#
motion x y
5313 state.uioh <- state.uioh#
pmotion x y;
5319 method key key mask
=
5320 begin match state.mode with
5321 | Textentry
textentry -> textentrykeyboard key mask
textentry
5322 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5323 | View
-> viewkeyboard key mask
5324 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5328 method button button bstate
x y mask
=
5329 begin match state.mode with
5331 | View
-> viewmouse button bstate
x y mask
5332 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5338 begin match state.mode with
5340 | View
| Birdseye
_ | LinkNav
_ ->
5341 match state.mstate
with
5342 | Mzoom
_ | Mnone
-> ()
5347 state.mstate
<- Mpan
(x, y);
5348 if conf.zoom > 1.0 then state.x <- state.x + dx;
5350 gotoy_and_clear_text y
5353 state.mstate
<- Msel
(a, (x, y));
5354 G.postRedisplay "motion select";
5357 let y = min
conf.winh
(max
0 y) in
5361 let x = min
conf.winw (max
0 x) in
5364 | Mzoomrect
(p0
, _) ->
5365 state.mstate
<- Mzoomrect
(p0
, (x, y));
5366 G.postRedisplay "motion zoomrect";
5370 method pmotion x y =
5371 begin match state.mode with
5372 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5373 let rec loop = function
5375 if hooverpageno
!= -1
5377 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5378 G.postRedisplay "pmotion birdseye no hoover";
5381 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5382 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5384 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5385 G.postRedisplay "pmotion birdseye hoover";
5395 match state.mstate
with
5396 | Mnone
-> updateunder x y
5397 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5402 method infochanged
_ = ()
5405 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5406 let p, h = scrollph state.y maxy in
5410 let winw = conf.winw - state.scrollw
- 1 in
5411 let fwinw = float winw in
5413 let sw = fwinw /. float state.w in
5414 let sw = fwinw *. sw in
5415 max
sw (float conf.scrollh
)
5418 let f = state.w+winw in
5419 let r = float (winw-state.x) /. float f in
5420 let p = fwinw *. r in
5424 if position +. sw > fwinw
5425 then fwinw -. position
5428 state.hscrollh, position, sw
5432 match state.mode with
5433 | LinkNav
_ -> "links"
5434 | Textentry
_ -> "textentry"
5435 | Birdseye
_ -> "birdseye"
5438 findkeyhash conf modename
5445 let fontpath = ref "";;
5448 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5451 let l = String.length
s in
5452 let b = Buffer.create
l in
5458 try Sys.getenv
"HOME"
5461 ("Can not determine home directory location: " ^
5462 Printexc.to_string exn
);
5466 let modifier_of_string = function
5467 | "alt" -> Wsi.altmask
5468 | "shift" -> Wsi.shiftmask
5469 | "ctrl" | "control" -> Wsi.ctrlmask
5470 | "meta" -> Wsi.metamask
5475 let r = Str.regexp
"-" in
5477 let elems = Str.full_split
r s in
5480 let m1 = modifier_of_string s in
5482 then (Wsi.namekey
s, m)
5485 | Str.Delim
s when n land 1 = 0 -> g s
5487 | Str.Delim
_ -> (k
, m)
5489 let rec loop n k
m = function
5492 let k, m = f n k m x in
5498 let keys_of_string =
5499 let r = Str.regexp
"[ \t]" in
5501 let elems = Str.split
r s in
5502 List.map
key_of_string elems
5505 let copykeyhashes c =
5506 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5509 let config_of c attrs
=
5513 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5514 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5515 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5516 | "preload" -> { c with preload = bool_of_string
v }
5517 | "page-bias" -> { c with pagebias
= int_of_string
v }
5518 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5519 | "auto-scroll-step" ->
5520 { c with autoscrollstep
= max
0 (int_of_string
v) }
5521 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5522 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5525 match String.lowercase
v with
5526 | "true" -> Some infinity
5528 | f -> Some
(float_of_string
f)
5530 { c with maxwait
= mw}
5531 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5532 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5533 | "vertical-margin" ->
5534 { c with interpagespace = max
0 (int_of_string
v) }
5536 let zoom = float_of_string
v /. 100. in
5537 let zoom = max
zoom 0.0 in
5538 { c with zoom = zoom }
5539 | "presentation" -> { c with presentation = bool_of_string
v }
5540 | "rotation-angle" -> { c with angle
= int_of_string
v }
5541 | "width" -> { c with winw = max
20 (int_of_string
v) }
5542 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5543 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5544 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5545 | "pixmap-cache-size" ->
5546 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5547 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5548 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5549 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5550 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5551 | "background-color" -> { c with bgcolor
= color_of_string v }
5552 | "scrollbar-in-presentation" ->
5553 { c with scrollbarinpm
= bool_of_string
v }
5554 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5555 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5556 | "mupdf-store-size" ->
5557 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5558 | "checkers" -> { c with checkers
= bool_of_string
v }
5559 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5560 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5561 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5562 | "uri-launcher" -> { c with urilauncher
= unent v }
5563 | "path-launcher" -> { c with pathlauncher
= unent v }
5564 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5565 | "invert-colors" -> { c with invert
= bool_of_string
v }
5566 | "brightness" -> { c with colorscale
= float_of_string
v }
5567 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5569 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5571 let nab = columns_of_string v in
5572 { c with columns
= Some
(nab, [||]) }
5573 | "birds-eye-columns" ->
5574 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5575 | "selection-command" -> { c with selcmd
= unent v }
5576 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5579 prerr_endline
("Error processing attribute (`" ^
5580 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5583 let rec fold c = function
5586 let c = apply c k v in
5589 fold { c with keyhashes
= copykeyhashes c } attrs
;
5592 let fromstring f pos
n v d =
5595 dolog "Error processing attribute (%S=%S) at %d\n%s"
5596 n v pos
(Printexc.to_string exn
)
5601 let bookmark_of attrs
=
5602 let rec fold title page
rely = function
5603 | ("title", v) :: rest
-> fold v page
rely rest
5604 | ("page", v) :: rest
-> fold title v rely rest
5605 | ("rely", v) :: rest
-> fold title page
v rest
5606 | _ :: rest
-> fold title page
rely rest
5607 | [] -> title, page
, rely
5609 fold "invalid" "0" "0" attrs
5613 let rec fold path page
rely pan
= function
5614 | ("path", v) :: rest
-> fold v page
rely pan rest
5615 | ("page", v) :: rest
-> fold path v rely pan rest
5616 | ("rely", v) :: rest
-> fold path page
v pan rest
5617 | ("pan", v) :: rest
-> fold path page
rely v rest
5618 | _ :: rest
-> fold path page
rely pan rest
5619 | [] -> path, page
, rely, pan
5621 fold "" "0" "0" "0" attrs
5625 let rec fold rs ls
= function
5626 | ("out", v) :: rest
-> fold v ls rest
5627 | ("in", v) :: rest
-> fold rs
v rest
5628 | _ :: rest
-> fold ls rs rest
5634 let setconf dst
src =
5635 dst
.scrollbw
<- src.scrollbw
;
5636 dst
.scrollh
<- src.scrollh
;
5637 dst
.icase
<- src.icase
;
5638 dst
.preload <- src.preload;
5639 dst
.pagebias
<- src.pagebias
;
5640 dst
.verbose
<- src.verbose
;
5641 dst
.scrollstep
<- src.scrollstep
;
5642 dst
.maxhfit
<- src.maxhfit
;
5643 dst
.crophack
<- src.crophack
;
5644 dst
.autoscrollstep
<- src.autoscrollstep
;
5645 dst
.maxwait
<- src.maxwait
;
5646 dst
.hlinks
<- src.hlinks
;
5647 dst
.underinfo
<- src.underinfo
;
5648 dst
.interpagespace <- src.interpagespace;
5649 dst
.zoom <- src.zoom;
5650 dst
.presentation <- src.presentation;
5651 dst
.angle
<- src.angle
;
5652 dst
.winw <- src.winw;
5653 dst
.winh
<- src.winh
;
5654 dst
.savebmarks
<- src.savebmarks
;
5655 dst
.memlimit
<- src.memlimit
;
5656 dst
.proportional
<- src.proportional
;
5657 dst
.texcount
<- src.texcount
;
5658 dst
.sliceheight
<- src.sliceheight
;
5659 dst
.thumbw
<- src.thumbw
;
5660 dst
.jumpback
<- src.jumpback
;
5661 dst
.bgcolor
<- src.bgcolor
;
5662 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5663 dst
.tilew
<- src.tilew
;
5664 dst
.tileh
<- src.tileh
;
5665 dst
.mustoresize
<- src.mustoresize
;
5666 dst
.checkers
<- src.checkers
;
5667 dst
.aalevel
<- src.aalevel
;
5668 dst
.trimmargins
<- src.trimmargins
;
5669 dst
.trimfuzz
<- src.trimfuzz
;
5670 dst
.urilauncher
<- src.urilauncher
;
5671 dst
.colorspace
<- src.colorspace
;
5672 dst
.invert
<- src.invert
;
5673 dst
.colorscale
<- src.colorscale
;
5674 dst
.redirectstderr <- src.redirectstderr;
5675 dst
.ghyllscroll
<- src.ghyllscroll
;
5676 dst
.columns
<- src.columns
;
5677 dst
.beyecolumns
<- src.beyecolumns
;
5678 dst
.selcmd
<- src.selcmd
;
5679 dst
.updatecurs
<- src.updatecurs
;
5680 dst
.pathlauncher
<- src.pathlauncher
;
5681 dst
.keyhashes
<- copykeyhashes src;
5685 let h = Hashtbl.create
10 in
5686 let dc = { defconf with angle
= defconf.angle
} in
5687 let rec toplevel v t spos
_ =
5689 | Vdata
| Vcdata
| Vend
-> v
5690 | Vopen
("llppconfig", _, closed
) ->
5693 else { v with f = llppconfig
}
5695 error
"unexpected subelement at top level" s spos
5696 | Vclose
_ -> error
"unexpected close at top level" s spos
5698 and llppconfig
v t spos
_ =
5700 | Vdata
| Vcdata
-> v
5701 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5702 | Vopen
("defaults", attrs
, closed
) ->
5703 let c = config_of dc attrs
in
5707 else { v with f = defaults
}
5709 | Vopen
("ui-font", attrs
, closed
) ->
5710 let rec getsize size
= function
5712 | ("size", v) :: rest
->
5714 fromstring int_of_string spos
"size" v fstate.fontsize
in
5716 | l -> getsize size l
5718 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5721 else { v with f = uifont
(Buffer.create
10) }
5723 | Vopen
("doc", attrs
, closed
) ->
5724 let pathent, spage
, srely
, span
= doc_of attrs
in
5725 let path = unent pathent
5726 and pageno = fromstring int_of_string spos
"page" spage
0
5727 and rely = fromstring float_of_string spos
"rely" srely
0.0
5728 and pan
= fromstring int_of_string spos
"pan" span
0 in
5729 let c = config_of dc attrs
in
5730 let anchor = (pageno, rely) in
5732 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5733 else { v with f = doc
path pan
anchor c [] }
5736 error
"unexpected subelement in llppconfig" s spos
5738 | Vclose
"llppconfig" -> { v with f = toplevel }
5739 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5741 and defaults
v t spos
_ =
5743 | Vdata
| Vcdata
-> v
5744 | Vend
-> error
"unexpected end of input in defaults" s spos
5745 | Vopen
("keymap", attrs
, closed
) ->
5747 try List.assoc
"mode" attrs
5748 with Not_found
-> "global" in
5753 let h = findkeyhash dc modename in
5754 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5757 { v with f = pkeymap
ret KeyMap.empty }
5759 | Vopen
(_, _, _) ->
5760 error
"unexpected subelement in defaults" s spos
5762 | Vclose
"defaults" ->
5763 { v with f = llppconfig
}
5765 | Vclose
_ -> error
"unexpected close in defaults" s spos
5767 and uifont
b v t spos
epos =
5770 Buffer.add_substring
b s spos
(epos - spos
);
5772 | Vopen
(_, _, _) ->
5773 error
"unexpected subelement in ui-font" s spos
5774 | Vclose
"ui-font" ->
5775 if String.length
!fontpath = 0
5776 then fontpath := Buffer.contents
b;
5777 { v with f = llppconfig
}
5778 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5779 | Vend
-> error
"unexpected end of input in ui-font" s spos
5781 and doc
path pan
anchor c bookmarks
v t spos
_ =
5783 | Vdata
| Vcdata
-> v
5784 | Vend
-> error
"unexpected end of input in doc" s spos
5785 | Vopen
("bookmarks", _, closed
) ->
5788 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5790 | Vopen
("keymap", attrs
, closed
) ->
5792 try List.assoc
"mode" attrs
5793 with Not_found
-> "global"
5799 let h = findkeyhash c modename in
5800 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5801 doc
path pan
anchor c bookmarks
5803 { v with f = pkeymap
ret KeyMap.empty }
5805 | Vopen
(_, _, _) ->
5806 error
"unexpected subelement in doc" s spos
5809 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5810 { v with f = llppconfig
}
5812 | Vclose
_ -> error
"unexpected close in doc" s spos
5814 and pkeymap
ret keymap
v t spos
_ =
5816 | Vdata
| Vcdata
-> v
5817 | Vend
-> error
"unexpected end of input in keymap" s spos
5818 | Vopen
("map", attrs
, closed
) ->
5819 let r, l = map_of attrs
in
5820 let kss = fromstring keys_of_string spos
"in" r [] in
5821 let lss = fromstring keys_of_string spos
"out" l [] in
5825 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5826 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5829 then { v with f = pkeymap
ret keymap }
5832 { v with f = skip
"map" f }
5835 error
"unexpected subelement in keymap" s spos
5837 | Vclose
"keymap" ->
5838 { v with f = ret keymap }
5840 | Vclose
_ -> error
"unexpected close in keymap" s spos
5842 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5844 | Vdata
| Vcdata
-> v
5845 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5846 | Vopen
("item", attrs
, closed
) ->
5847 let titleent, spage
, srely
= bookmark_of attrs
in
5848 let page = fromstring int_of_string spos
"page" spage
0
5849 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5850 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5852 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5855 { v with f = skip
"item" f }
5858 error
"unexpected subelement in bookmarks" s spos
5860 | Vclose
"bookmarks" ->
5861 { v with f = doc
path pan
anchor c bookmarks }
5863 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5865 and skip tag
f v t spos
_ =
5867 | Vdata
| Vcdata
-> v
5869 error
("unexpected end of input in skipped " ^ tag
) s spos
5870 | Vopen
(tag'
, _, closed
) ->
5874 let f'
() = { v with f = skip tag
f } in
5875 { v with f = skip tag'
f'
}
5879 else error
("unexpected close in skipped " ^ tag
) s spos
5882 parse
{ f = toplevel; accu = () } s;
5888 let len = in_channel_length ic
in
5889 let s = String.create
len in
5890 really_input ic
s 0 len;
5893 | Parse_error
(msg
, s, pos
) ->
5894 let subs = subs s pos
in
5895 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5896 failwith
("parse error: " ^
s)
5899 failwith
("config load error: " ^
Printexc.to_string exn
)
5905 let dir = Filename.concat
home ".config" in
5906 if Sys.is_directory
dir then dir else home
5909 Filename.concat
dir "llpp.conf"
5912 let confpath = ref defconfpath;;
5915 if Sys.file_exists
!confpath
5918 (try Some
(open_in_bin
!confpath)
5921 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5922 Printexc.to_string exn
);
5931 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5932 Printexc.to_string exn
);
5938 f (Hashtbl.create
0, defconf)
5943 let pc, pb
, px, pa
=
5945 Hashtbl.find h (Filename.basename
state.path)
5946 with Not_found
-> dc, [], 0, (0, 0.0)
5950 state.bookmarks <- pb
;
5952 state.scrollw
<- conf.scrollbw
;
5954 then state.anchor <- pa
;
5955 cbput state.hists
.nav pa
;
5960 let add_attrs bb always
dc c =
5963 then Printf.bprintf bb
"\n %s='%b'" s a
5966 then Printf.bprintf bb
"\n %s='%d'" s a
5969 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5972 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5975 then Printf.bprintf bb
"\n %s='%f'" s a
5979 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5983 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5987 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5991 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5997 | Some
(_N
, _A
, _B
) ->
5998 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6008 else string_of_float
f
6010 Printf.bprintf bb
"\n %s='%s'" s v
6015 | Some
((n, a, b), _) when n > 1 ->
6016 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6022 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6027 then dc.winw, dc.winh
6029 match state.fullscreen
with
6031 | None
-> c.winw, c.winh
6033 let zoom, presentation, interpagespace, maxwait
=
6035 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6037 match state.mode with
6038 | Birdseye
(bc
, _, _, _, _) ->
6039 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6040 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6042 oi
"width" w dc.winw;
6043 oi
"height" h dc.winh
;
6044 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6045 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6046 ob "case-insensitive-search" c.icase
dc.icase
;
6047 ob "preload" c.preload dc.preload;
6048 oi
"page-bias" c.pagebias
dc.pagebias
;
6049 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6050 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6051 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6052 ob "crop-hack" c.crophack
dc.crophack
;
6053 oW
"throttle" maxwait
dc.maxwait
;
6054 ob "highlight-links" c.hlinks
dc.hlinks
;
6055 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6056 oi
"vertical-margin" interpagespace dc.interpagespace;
6057 oz
"zoom" zoom dc.zoom;
6058 ob "presentation" presentation dc.presentation;
6059 oi
"rotation-angle" c.angle
dc.angle
;
6060 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6061 ob "proportional-display" c.proportional
dc.proportional
;
6062 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6063 oi
"tex-count" c.texcount
dc.texcount
;
6064 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6065 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6066 ob "persistent-location" c.jumpback
dc.jumpback
;
6067 oc
"background-color" c.bgcolor
dc.bgcolor
;
6068 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6069 oi
"tile-width" c.tilew
dc.tilew
;
6070 oi
"tile-height" c.tileh
dc.tileh
;
6071 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6072 ob "checkers" c.checkers
dc.checkers
;
6073 oi
"aalevel" c.aalevel
dc.aalevel
;
6074 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6075 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6076 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6077 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6078 oC
"color-space" c.colorspace
dc.colorspace
;
6079 ob "invert-colors" c.invert
dc.invert
;
6080 oF
"brightness" c.colorscale
dc.colorscale
;
6081 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6082 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6083 oco
"columns" c.columns
dc.columns
;
6084 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6085 os
"selection-command" c.selcmd
dc.selcmd
;
6086 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6089 let keymapsbuf always
dc c =
6090 let bb = Buffer.create
16 in
6091 let rec loop = function
6093 | (modename, h) :: rest
->
6094 let dh = findkeyhash dc modename in
6095 if always
|| h <> dh
6097 if Hashtbl.length
h > 0
6099 if Buffer.length
bb > 0
6100 then Buffer.add_char
bb '
\n'
;
6101 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6102 Hashtbl.iter
(fun i
o ->
6103 let isdifferent = always
||
6105 let dO = Hashtbl.find dh i
in
6107 with Not_found
-> true
6112 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6113 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6114 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6115 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6116 Buffer.add_string
bb (Wsi.keyname
k);
6119 let rec loop = function
6121 | km
:: [] -> addkm km
6122 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6126 Buffer.add_string
bb "<map in='";
6130 Buffer.add_string
bb "' out='";
6132 Buffer.add_string
bb "'/>\n"
6135 Buffer.add_string
bb "' out='";
6137 Buffer.add_string
bb "'/>\n"
6139 | KMmulti
(ins, kms
) ->
6140 Buffer.add_char
bb ' '
;
6142 Buffer.add_string
bb "' out='";
6144 Buffer.add_string
bb "'/>\n"
6146 Buffer.add_string
bb "</keymap>";
6156 let uifontsize = fstate.fontsize
in
6157 let bb = Buffer.create
32768 in
6159 let dc = if conf.bedefault
then conf else dc in
6160 Buffer.add_string
bb "<llppconfig>\n";
6162 if String.length
!fontpath > 0
6164 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6170 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6173 Buffer.add_string
bb "<defaults ";
6174 add_attrs bb true dc dc;
6175 let kb = keymapsbuf true dc dc in
6176 if Buffer.length
kb > 0
6178 Buffer.add_string
bb ">\n";
6179 Buffer.add_buffer
bb kb;
6180 Buffer.add_string
bb "\n</defaults>\n";
6182 else Buffer.add_string
bb "/>\n";
6184 let adddoc path pan
anchor c bookmarks =
6185 if bookmarks == [] && c = dc && anchor = emptyanchor
6188 Printf.bprintf
bb "<doc path='%s'"
6189 (enent
path 0 (String.length
path));
6191 if anchor <> emptyanchor
6193 let n, y = anchor in
6194 Printf.bprintf
bb " page='%d'" n;
6197 Printf.bprintf
bb " rely='%f'" y
6202 then Printf.bprintf
bb " pan='%d'" pan
;
6204 add_attrs bb false dc c;
6205 let kb = keymapsbuf false dc c in
6207 begin match bookmarks with
6209 if Buffer.length
kb > 0
6211 Buffer.add_string
bb ">\n";
6212 Buffer.add_buffer
bb kb;
6213 Buffer.add_string
bb "</doc>\n";
6215 else Buffer.add_string
bb "/>\n"
6217 Buffer.add_string
bb ">\n<bookmarks>\n";
6218 List.iter
(fun (title, _level
, (page, rely)) ->
6220 "<item title='%s' page='%d'"
6221 (enent
title 0 (String.length
title))
6226 Printf.bprintf
bb " rely='%f'" rely
6228 Buffer.add_string
bb "/>\n";
6230 Buffer.add_string
bb "</bookmarks>";
6231 if Buffer.length
kb > 0
6233 Buffer.add_string
bb "\n";
6234 Buffer.add_buffer
bb kb;
6236 Buffer.add_string
bb "\n</doc>\n";
6242 match state.mode with
6243 | Birdseye
(c, pan, _, _, _) ->
6245 match conf.columns
with
6246 | Some
((c, _, _), _) -> Some
c
6249 match c.columns
with
6250 | Some
(c, _) -> Some
(c, [||])
6253 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6254 | _ -> state.x, conf
6256 let basename = Filename.basename state.path in
6257 adddoc basename pan (getanchor ())
6260 match state.autoscroll
with
6262 | None
-> conf.autoscrollstep
}
6263 (if conf.savebmarks
then state.bookmarks else []);
6265 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6267 then adddoc path x y c bookmarks
6269 Buffer.add_string
bb "</llppconfig>";
6272 if Buffer.length
bb > 0
6275 let tmp = !confpath ^
".tmp" in
6276 let oc = open_out_bin
tmp in
6277 Buffer.output_buffer
oc bb;
6279 Unix.rename
tmp !confpath;
6282 ("error while saving configuration: " ^
Printexc.to_string exn
)
6289 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6290 "<password> Set password");
6292 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6293 "<path> Set path to the user interface font");
6295 ("-c", Arg.String
(fun s -> Config.confpath := s),
6296 "<path> Set path to the configuration file");
6298 ("-v", Arg.Unit
(fun () ->
6300 "%s\nconfiguration path: %s\n"
6304 exit
0), " Print version and exit");
6307 (fun s -> state.path <- s)
6308 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6310 if String.length
state.path = 0
6311 then (prerr_endline
"file name missing"; exit
1);
6315 let globalkeyhash = findkeyhash conf "global" in
6316 let wsfd, winw, winh
= Wsi.init
(object
6318 if nogeomcmds state.geomcmds
6320 method display = display ()
6321 method reshape w h = reshape w h
6322 method mouse b d x y m = mouse b d x y m
6323 method motion x y = state.mpos
<- (x, y); motion x y
6324 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6326 let mascm = m land (
6327 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6329 match state.keystate
with
6331 let km = k, mascm in
6334 try Hashtbl.find globalkeyhash km
6336 let modehash = state.uioh#
modehash in
6337 try Hashtbl.find modehash km
6338 with Not_found
-> KMinsrt
(k, m)
6340 | KMinsrt
(k, m) -> keyboard k m
6341 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6342 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6344 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6345 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6346 state.keystate
<- KSnone
6347 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6348 state.keystate
<- KSinto
(keys
, insrt
)
6350 state.keystate
<- KSnone
6352 method enter
x y = state.mpos
<- (x, y); pmotion x y
6353 method leave = state.mpos
<- (-1, -1)
6354 method quit
= raise Quit
6355 end) conf.winw conf.winh
in
6360 List.exists
GlMisc.check_extension
6361 [ "GL_ARB_texture_rectangle"
6362 ; "GL_EXT_texture_recangle"
6363 ; "GL_NV_texture_rectangle" ]
6365 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6367 let cr, sw = Unix.pipe
()
6368 and sr
, cw
= Unix.pipe
() in
6375 setcheckers conf.checkers
;
6379 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6380 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6385 state.text <- "Opening " ^
state.path;
6386 opendoc state.path state.password
;
6388 setfontsize fstate.fontsize
;
6391 let rec loop deadline
=
6393 match state.errfd
with
6394 | None
-> [state.sr
; state.wsfd]
6395 | Some fd
-> [state.sr
; state.wsfd; fd
]
6399 state.redisplay
<- false;
6406 if deadline
= infinity
6408 else max
0.0 (deadline
-. now)
6413 try Unix.select
r [] [] timeout
6414 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6420 if state.ghyll
== noghyll
6422 match state.autoscroll
with
6423 | Some step
when step
!= 0 ->
6424 let y = state.y + step
in
6428 else if y >= state.maxy then 0 else y
6431 if state.mode = View
6432 then state.text <- "";
6435 else deadline
+. 0.01
6440 let rec checkfds = function
6442 | fd
:: rest
when fd
= state.sr
->
6443 let cmd = readcmd state.sr
in
6447 | fd
:: rest
when fd
= state.wsfd ->
6452 let s = String.create
80 in
6453 let n = Unix.read fd
s 0 80 in
6454 if conf.redirectstderr
6456 Buffer.add_substring
state.errmsgs
s 0 n;
6457 state.newerrmsgs
<- true;
6458 state.redisplay
<- true;
6461 prerr_string
(String.sub
s 0 n);
6469 if deadline
= infinity
6473 match state.autoscroll
with
6474 | Some step
when step
!= 0 -> deadline1
6475 | _ -> if state.ghyll
== noghyll then infinity
else deadline1