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'
("launch: " ^ s
);
785 Wsi.setcursor
Wsi.CURSOR_INHERIT
787 if conf.underinfo
then showtext 'n'
("named: " ^ 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'
("launch: " ^ s
);
811 showtext 'n'
("named: " ^ 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 =
1561 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);
1777 invalidate "geometry"
1781 match conf.columns
with
1783 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1785 wcmd "geometry %d %d" w h);
1789 let len = String.length
state.text in
1792 match state.mode
with
1793 | View
-> state.hscrollh
1798 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1799 (x+.w, float (conf.winh
- hscrollh))
1802 let w = float (conf.winw
- state.scrollw
- 1) in
1803 if state.progress
>= 0.0 && state.progress
< 1.0
1805 GlDraw.color
(0.3, 0.3, 0.3);
1806 let w1 = w *. state.progress
in
1808 GlDraw.color
(0.0, 0.0, 0.0);
1812 GlDraw.color
(0.0, 0.0, 0.0);
1816 GlDraw.color
(1.0, 1.0, 1.0);
1817 drawstring fstate.fontsize
1818 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1821 match state.mode
with
1822 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1826 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1828 Printf.sprintf
"%s%s_" prefix
text
1837 if not
(istextentry state.mode
)
1839 let s1 = "(press 'e' to review error messasges)" in
1840 if String.length
s > 0 then s ^
" " ^
s1 else s1
1845 if String.length
s > 0
1850 let len = Queue.length
state.tilelru
in
1852 if state.memused
<= conf.memlimit
1857 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1858 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1859 let (_
, pw
, ph
, _
) = getpagedim n in
1862 && colorspace
= conf.colorspace
1863 && angle
= conf.angle
1868 match state.throttle
with
1871 then preloadlayout state.layout
1873 | Some
(layout, _
, _
) ->
1876 let x = col*conf.tilew
1877 and y = row*conf.tileh
in
1878 tilevisible layout n x y
1880 then Queue.push lruitem
state.tilelru
1882 wcmd "freetile %s" p
;
1883 state.memused
<- state.memused
- s;
1884 state.uioh#infochanged Memused
;
1885 Hashtbl.remove
state.tilemap k
;
1894 Queue.iter
(fun (k
, p
, s) ->
1895 wcmd "freetile %s" p
;
1896 state.memused
<- state.memused
- s;
1897 state.uioh#infochanged Memused
;
1898 Hashtbl.remove
state.tilemap k
;
1900 Queue.clear
state.tilelru
;
1904 let logcurrently = function
1905 | Idle
-> dolog "Idle"
1906 | Loading
(l
, gen
) ->
1907 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1908 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1910 "Tiling %d[%d,%d] page=%s cs=%s angle"
1911 l
.pageno
col row pageopaque
1912 (colorspace_to_string colorspace
)
1914 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1915 angle gen
conf.angle
state.gen
1917 conf.tilew
conf.tileh
1924 (* dolog "%S" cmds; *)
1927 try String.index cmds ' '
1928 with Not_found
-> -1
1933 let l = String.length cmds
in
1934 let op = String.sub cmds
0 spacepos in
1936 if l - spacepos < 2 then ""
1937 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1942 state.uioh#infochanged Pdim
;
1946 state.rects
<- state.rects1
;
1947 G.postRedisplay "clearrects";
1951 try Scanf.sscanf
args "%u" (fun n -> n)
1953 dolog "error processing 'continue' %S: %s"
1954 cmds
(Printexc.to_string exn
);
1957 state.pagecount
<- n;
1958 begin match state.currently
with
1960 state.currently
<- Idle
;
1961 state.outlines
<- Array.of_list
(List.rev
l)
1965 let cur, cmds
= state.geomcmds
in
1966 if String.length
cur = 0
1967 then failwith
"umpossible";
1969 begin match List.rev cmds
with
1971 state.geomcmds
<- "", [];
1975 state.geomcmds
<- s, List.rev rest
;
1977 if conf.maxwait
= None
1978 then G.postRedisplay "continue";
1988 then showtext ' '
args
1991 let progress, text =
1993 Scanf.sscanf
args "%f %n"
1995 f, String.sub
args pos
(String.length
args - pos
))
1997 dolog "error processing 'progress' %S: %s"
1998 cmds
(Printexc.to_string exn
);
2002 state.progress <- progress;
2003 G.postRedisplay "progress"
2006 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2008 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2009 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2010 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2012 dolog "error processing 'firstmatch' %S: %s"
2013 cmds
(Printexc.to_string exn
);
2016 let y = (getpagey pageno) + truncate
y0 in
2019 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2022 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2024 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2025 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2026 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2028 dolog "error processing 'match' %S: %s"
2029 cmds
(Printexc.to_string exn
);
2033 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2038 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2040 dolog "error processing 'page' %S: %s"
2041 cmds
(Printexc.to_string exn
);
2044 begin match state.currently
with
2045 | Loading
(l, gen
) ->
2046 vlog "page %d took %f sec" l.pageno t
;
2047 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2048 begin match state.throttle
with
2050 let preloadedpages =
2052 then preloadlayout state.layout
2057 Set.Make
(struct type t
= int let compare = (-) end) in
2059 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2060 IntSet.empty
preloadedpages
2063 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2064 if not
(IntSet.mem
pageno set)
2066 wcmd "freepage %s" opaque
;
2072 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2075 state.currently
<- Idle
;
2078 tilepage l.pageno pageopaque state.layout;
2080 load preloadedpages;
2081 if pagevisible state.layout l.pageno
2082 && layoutready state.layout
2083 then G.postRedisplay "page";
2086 | Some
(layout, _
, _
) ->
2087 state.currently
<- Idle
;
2088 tilepage l.pageno pageopaque layout;
2093 dolog "Inconsistent loading state";
2094 logcurrently state.currently
;
2099 let (x, y, opaque
, size
, t
) =
2101 Scanf.sscanf
args "%u %u %s %u %f"
2102 (fun x y p size t
-> (x, y, p
, size
, t
))
2104 dolog "error processing 'tile' %S: %s"
2105 cmds
(Printexc.to_string exn
);
2108 begin match state.currently
with
2109 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2110 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2112 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2114 wcmd "freetile %s" opaque
;
2115 state.currently
<- Idle
;
2119 puttileopaque l col row gen cs angle opaque size t
;
2120 state.memused
<- state.memused
+ size
;
2121 state.uioh#infochanged Memused
;
2123 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2124 opaque
, size
) state.tilelru
;
2127 match state.throttle
with
2128 | None
-> state.layout
2129 | Some
(layout, _
, _
) -> layout
2132 state.currently
<- Idle
;
2134 && conf.colorspace
= cs
2135 && conf.angle
= angle
2136 && tilevisible layout l.pageno x y
2137 then conttiling l.pageno pageopaque;
2139 begin match state.throttle
with
2141 preload state.layout;
2143 && conf.colorspace
= cs
2144 && conf.angle
= angle
2145 && tilevisible state.layout l.pageno x y
2146 then G.postRedisplay "tile nothrottle";
2148 | Some
(layout, y, _
) ->
2149 let ready = layoutready layout in
2153 state.layout <- layout;
2154 state.throttle
<- None
;
2155 G.postRedisplay "throttle";
2162 dolog "Inconsistent tiling state";
2163 logcurrently state.currently
;
2170 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2172 dolog "error processing 'pdim' %S: %s"
2173 cmds
(Printexc.to_string exn
);
2176 state.uioh#infochanged Pdim
;
2177 state.pdims
<- pdim :: state.pdims
2180 let (l, n, t
, h, pos
) =
2182 Scanf.sscanf
args "%u %u %d %u %n"
2183 (fun l n t
h pos
-> l, n, t
, h, pos
)
2185 dolog "error processing 'o' %S: %s"
2186 cmds
(Printexc.to_string exn
);
2189 let s = String.sub
args pos
(String.length
args - pos
) in
2190 let outline = (s, l, (n, float t
/. float h)) in
2191 begin match state.currently
with
2192 | Outlining outlines
->
2193 state.currently
<- Outlining
(outline :: outlines
)
2195 state.currently
<- Outlining
[outline]
2197 dolog "invalid outlining state";
2198 logcurrently currently
2202 state.docinfo
<- (1, args) :: state.docinfo
2205 state.uioh#infochanged Docinfo
;
2206 state.docinfo
<- List.rev
state.docinfo
2209 dolog "unknown cmd `%S'" cmds
2214 let action = function
2215 | HCprev
-> cbget cb ~
-1
2216 | HCnext
-> cbget cb
1
2217 | HCfirst
-> cbget cb ~
-(cb
.rc)
2218 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2219 and cancel
() = cb
.rc <- rc
2223 let search pattern forward
=
2224 if String.length pattern
> 0
2227 match state.layout with
2230 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2232 wcmd "search %d %d %d %d,%s\000"
2233 (btod conf.icase
) pn py (btod forward
) pattern
;
2236 let intentry text key =
2238 if key >= 32 && key < 127
2244 let text = addchar text c in
2248 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2252 let textentry text key =
2253 if key land 0xff00 = 0xff00
2255 else TEcont
(text ^
Wsi.toutf8
key)
2258 let reqlayout angle proportional
=
2259 match state.throttle
with
2261 if nogeomcmds state.geomcmds
2262 then state.anchor <- getanchor ();
2263 conf.angle
<- angle
mod 360;
2266 match state.mode
with
2267 | LinkNav _
-> state.mode
<- View
2270 conf.proportional
<- proportional
;
2271 invalidate "reqlayout"
2272 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2276 let settrim trimmargins trimfuzz
=
2277 if nogeomcmds state.geomcmds
2278 then state.anchor <- getanchor ();
2279 conf.trimmargins
<- trimmargins
;
2280 conf.trimfuzz
<- trimfuzz
;
2281 let x0, y0, x1, y1 = trimfuzz
in
2282 invalidate "settrim"
2284 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2285 Hashtbl.iter
(fun _ opaque
->
2286 wcmd "freepage %s" opaque
;
2288 Hashtbl.clear
state.pagemap
;
2292 match state.throttle
with
2294 let zoom = max
0.01 zoom in
2295 if zoom <> conf.zoom
2297 state.prevzoom
<- conf.zoom;
2300 then (state.x <- 0; 0.0)
2301 else float state.x /. float state.w
2304 reshape conf.winw
conf.winh
;
2307 let x = relx *. float state.w in
2308 state.x <- truncate
x;
2310 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2313 | Some
(layout, y, started
) ->
2315 match conf.maxwait
with
2319 let dt = now () -. started
in
2327 let setcolumns columns coverA coverB
=
2330 conf.columns
<- None
;
2335 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2338 reshape conf.winw
conf.winh
;
2341 let enterbirdseye () =
2342 let zoom = float conf.thumbw
/. float conf.winw
in
2343 let birdseyepageno =
2344 let cy = conf.winh
/ 2 in
2348 let rec fold best
= function
2351 let d = cy - (l.pagedispy + l.pagevh/2)
2352 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2353 if abs
d < abs dbest
2360 state.mode
<- Birdseye
(
2361 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2364 conf.presentation <- false;
2365 conf.interpagespace <- 10;
2366 conf.hlinks
<- false;
2368 state.mstate
<- Mnone
;
2369 conf.maxwait
<- None
;
2371 match conf.beyecolumns
with
2374 Some
((c, 0, 0), [||])
2377 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2380 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2385 reshape conf.winw
conf.winh
;
2388 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2390 conf.zoom <- c.zoom;
2391 conf.presentation <- c.presentation;
2392 conf.interpagespace <- c.interpagespace;
2393 conf.maxwait
<- c.maxwait
;
2394 conf.hlinks
<- c.hlinks
;
2395 conf.beyecolumns
<- (
2396 match conf.columns
with
2397 | Some
((c, _
, _
), _
) -> Some
c
2401 match c.columns
with
2402 | Some
(c, _
) -> Some
(c, [||])
2408 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2411 reshape conf.winw
conf.winh
;
2412 state.anchor <- if goback
then anchor else (pageno, 0.0);
2415 let togglebirdseye () =
2416 match state.mode
with
2417 | Birdseye vals
-> leavebirdseye vals
true
2418 | View
-> enterbirdseye ()
2422 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2423 let pageno = max
0 (pageno - incr
) in
2424 let rec loop = function
2425 | [] -> gotopage1 pageno 0
2426 | l :: _
when l.pageno = pageno ->
2427 if l.pagedispy >= 0 && l.pagey = 0
2428 then G.postRedisplay "upbirdseye"
2429 else gotopage1 pageno 0
2430 | _
:: rest
-> loop rest
2433 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2436 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2437 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2438 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2439 let rec loop = function
2441 let y, h = getpageyh pageno in
2442 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2444 | l :: _
when l.pageno = pageno ->
2445 if l.pagevh != l.pageh
2446 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2447 else G.postRedisplay "downbirdseye"
2448 | _
:: rest
-> loop rest
2453 let optentry mode _
key =
2454 let btos b = if b then "on" else "off" in
2455 if key >= 32 && key < 127
2457 let c = Char.chr
key in
2461 try conf.scrollstep
<- int_of_string
s with exc
->
2462 state.text <- Printf.sprintf
"bad integer `%s': %s"
2463 s (Printexc.to_string exc
)
2465 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2470 conf.autoscrollstep
<- int_of_string
s;
2471 if state.autoscroll
<> None
2472 then state.autoscroll
<- Some
conf.autoscrollstep
2474 state.text <- Printf.sprintf
"bad integer `%s': %s"
2475 s (Printexc.to_string exc
)
2477 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2482 let n, a, b = columns_of_string s in
2485 state.text <- Printf.sprintf
"bad columns `%s': %s"
2486 s (Printexc.to_string exc
)
2488 TEswitch
("columns: ", "", None
, textentry, ondone)
2493 let zoom = float (int_of_string
s) /. 100.0 in
2496 state.text <- Printf.sprintf
"bad integer `%s': %s"
2497 s (Printexc.to_string exc
)
2499 TEswitch
("zoom: ", "", None
, intentry, ondone)
2504 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2506 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2507 begin match mode
with
2509 leavebirdseye beye
false;
2514 state.text <- Printf.sprintf
"bad integer `%s': %s"
2515 s (Printexc.to_string exc
)
2517 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2522 Some
(int_of_string
s)
2524 state.text <- Printf.sprintf
"bad integer `%s': %s"
2525 s (Printexc.to_string exc
);
2528 | Some angle
-> reqlayout angle
conf.proportional
2531 TEswitch
("rotation: ", "", None
, intentry, ondone)
2534 conf.icase
<- not
conf.icase
;
2535 TEdone
("case insensitive search " ^
(btos conf.icase
))
2538 conf.preload <- not
conf.preload;
2540 TEdone
("preload " ^
(btos conf.preload))
2543 conf.verbose
<- not
conf.verbose
;
2544 TEdone
("verbose " ^
(btos conf.verbose
))
2547 conf.debug
<- not
conf.debug
;
2548 TEdone
("debug " ^
(btos conf.debug
))
2551 conf.maxhfit
<- not
conf.maxhfit
;
2553 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2554 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2557 conf.crophack
<- not
conf.crophack
;
2558 TEdone
("crophack " ^
btos conf.crophack
)
2562 match conf.maxwait
with
2564 conf.maxwait
<- Some infinity
;
2565 "always wait for page to complete"
2567 conf.maxwait
<- None
;
2568 "show placeholder if page is not ready"
2573 conf.underinfo
<- not
conf.underinfo
;
2574 TEdone
("underinfo " ^
btos conf.underinfo
)
2577 conf.savebmarks
<- not
conf.savebmarks
;
2578 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2584 match state.layout with
2589 conf.interpagespace <- int_of_string
s;
2590 state.maxy <- calcheight ();
2591 let y = getpagey pageno in
2594 state.text <- Printf.sprintf
"bad integer `%s': %s"
2595 s (Printexc.to_string exc
)
2597 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2600 reqlayout conf.angle
(not
conf.proportional
);
2601 TEdone
("proportional display " ^
btos conf.proportional
)
2604 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2605 TEdone
("trim margins " ^
btos conf.trimmargins
)
2608 conf.invert
<- not
conf.invert
;
2609 TEdone
("invert colors " ^
btos conf.invert
)
2613 cbput state.hists
.sel
s;
2616 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2620 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2626 class type lvsource
= object
2627 method getitemcount
: int
2628 method getitem
: int -> (string * int)
2629 method hasaction
: int -> bool
2638 method getactive
: int
2639 method getfirst
: int
2640 method getqsearch
: string
2641 method setqsearch
: string -> unit
2645 class virtual lvsourcebase
= object
2646 val mutable m_active
= 0
2647 val mutable m_first
= 0
2648 val mutable m_qsearch
= ""
2649 val mutable m_pan
= 0
2650 method getactive
= m_active
2651 method getfirst
= m_first
2652 method getqsearch
= m_qsearch
2653 method getpan
= m_pan
2654 method setqsearch
s = m_qsearch
<- s
2657 let withoutlastutf8 s =
2658 let len = String.length
s in
2666 let b = Char.code
s.[pos
] in
2667 if b land 0b110000 = 0b11000000
2672 if Char.code
s.[len-1] land 0x80 = 0
2676 String.sub
s 0 first;
2679 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2681 state.mode
<- Textentry
(te
, onleave
);
2684 G.postRedisplay "textentrykeyboard enttext";
2686 let histaction cmd
=
2689 | Some
(action, _
) ->
2690 state.mode
<- Textentry
(
2691 (c, action cmd
, opthist
, onkey
, ondone), onleave
2693 G.postRedisplay "textentry histaction"
2696 | 0xff08 -> (* backspace *)
2697 let s = withoutlastutf8 text in
2698 let len = String.length
s in
2702 G.postRedisplay "textentrykeyboard after cancel";
2705 enttext (c, s, opthist
, onkey
, ondone)
2711 G.postRedisplay "textentrykeyboard after confirm"
2713 | 0xff52 -> histaction HCprev
2714 | 0xff54 -> histaction HCnext
2715 | 0xff50 -> histaction HCfirst
2716 | 0xff57 -> histaction HClast
2718 | 0xff1b -> (* escape*)
2719 if String.length
text = 0
2721 begin match opthist
with
2723 | Some
(_
, onhistcancel
) -> onhistcancel
()
2727 G.postRedisplay "textentrykeyboard after cancel2"
2730 enttext (c, "", opthist
, onkey
, ondone)
2733 | 0xff9f | 0xffff -> () (* delete *)
2735 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2736 begin match onkey
text key with
2740 G.postRedisplay "textentrykeyboard after confirm2";
2743 enttext (c, text, opthist
, onkey
, ondone);
2747 G.postRedisplay "textentrykeyboard after cancel3"
2750 state.mode
<- Textentry
(te
, onleave
);
2751 G.postRedisplay "textentrykeyboard switch";
2755 vlog "unhandled key %s" (Wsi.keyname
key)
2758 let firstof first active
=
2759 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2760 then max
0 (active
- (fstate.maxrows
/2))
2764 let calcfirst first active
=
2767 let rows = active
- first in
2768 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2772 let scrollph y maxy =
2773 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2774 let sh = float conf.winh
/. sh in
2775 let sh = max
sh (float conf.scrollh
) in
2780 else float y /. float maxy
2782 let position = (float conf.winh
-. sh) *. percent in
2785 if position +. sh > float conf.winh
2786 then float conf.winh
-. sh
2792 let coe s = (s :> uioh
);;
2794 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2796 val m_pan
= source#getpan
2797 val m_first
= source#getfirst
2798 val m_active
= source#getactive
2799 val m_qsearch
= source#getqsearch
2800 val m_prev_uioh
= state.uioh
2802 method private elemunder
y =
2803 let n = y / (fstate.fontsize
+1) in
2804 if m_first
+ n < source#getitemcount
2806 if source#hasaction
(m_first
+ n)
2807 then Some
(m_first
+ n)
2814 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2815 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2816 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2817 GlDraw.color
(1., 1., 1.);
2818 Gl.enable `texture_2d
;
2819 let fs = fstate.fontsize
in
2821 let ww = fstate.wwidth
in
2822 let tabw = 30.0*.ww in
2823 let itemcount = source#getitemcount
in
2825 if (row - m_first
) * nfs > conf.winh
2828 if row >= 0 && row < itemcount
2830 let (s, level
) = source#getitem
row in
2831 let y = (row - m_first
) * nfs in
2832 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2835 Gl.disable `texture_2d
;
2836 GlDraw.polygon_mode `both `line
;
2837 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2838 GlDraw.rect (1., float (y + 1))
2839 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2840 GlDraw.polygon_mode `both `fill
;
2841 GlDraw.color
(1., 1., 1.);
2842 Gl.enable `texture_2d
;
2845 let drawtabularstring s =
2846 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2849 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2852 let len = String.length
s - tabpos - 1 in
2853 let s1 = String.sub
s 0 tabpos
2854 and s2
= String.sub
s (tabpos + 1) len in
2855 let nx = drawstr x s1 in
2857 let x = x +. (max
tabw sw) in
2864 let _ = drawtabularstring s in
2871 Gl.disable `texture_2d
;
2873 method updownlevel incr
=
2874 let len = source#getitemcount
in
2876 if m_active
>= 0 && m_active
< len
2877 then snd
(source#getitem m_active
)
2881 if i
= len then i
-1 else if i
= -1 then 0 else
2882 let _, l = source#getitem i
in
2883 if l != curlevel then i
else flow (i
+incr
)
2885 let active = flow m_active
in
2886 let first = calcfirst m_first
active in
2887 G.postRedisplay "outline updownlevel";
2888 {< m_active
= active; m_first
= first >}
2890 method private key1
key mask
=
2891 let set1 active first qsearch
=
2892 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2894 let search active pattern incr
=
2897 if n >= 0 && n < source#getitemcount
2899 let s, _ = source#getitem
n in
2901 (try ignore
(Str.search_forward
re s 0); true
2902 with Not_found
-> false)
2904 else loop (n + incr
)
2911 let re = Str.regexp_case_fold pattern
in
2917 let itemcount = source#getitemcount
in
2918 let find start incr
=
2920 if i
= -1 || i
= itemcount
2923 if source#hasaction i
2925 else find (i
+ incr
)
2930 let set active first =
2931 let first = bound first 0 (itemcount - fstate.maxrows
) in
2933 coe {< m_active
= active; m_first
= first >}
2936 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2938 let incr1 = if incr
> 0 then 1 else -1 in
2939 if isvisible m_first m_active
2942 let next = m_active
+ incr
in
2944 if next < 0 || next >= itemcount
2946 else find next incr1
2948 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2954 let first = m_first
+ incr
in
2955 let first = bound first 0 (itemcount - 1) in
2957 let next = m_active
+ incr
in
2958 let next = bound next 0 (itemcount - 1) in
2961 let active = if next = -1 then m_active
else next in
2964 let first = min
next m_first
in
2966 if abs
(next - first) > fstate.maxrows
2972 let first = m_first
+ incr
in
2973 let first = bound first 0 (itemcount - 1) in
2975 let next = m_active
+ incr
in
2976 let next = bound next 0 (itemcount - 1) in
2977 let next = find next incr1 in
2979 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2981 let active = if m_active
= -1 then next else m_active
in
2986 if isvisible first active
2992 G.postRedisplay "listview navigate";
2996 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2997 let incr = if key = 0x72 then -1 else 1 in
2999 match search (m_active
+ incr) m_qsearch
incr with
3001 state.text <- m_qsearch ^
" [not found]";
3004 state.text <- m_qsearch
;
3005 active, firstof m_first
active
3007 G.postRedisplay "listview ctrl-r/s";
3008 set1 active first m_qsearch
;
3010 | 0xff08 -> (* backspace *)
3011 if String.length m_qsearch
= 0
3014 let qsearch = withoutlastutf8 m_qsearch
in
3015 let len = String.length
qsearch in
3019 G.postRedisplay "listview empty qsearch";
3020 set1 m_active m_first
"";
3024 match search m_active
qsearch ~
-1 with
3026 state.text <- qsearch ^
" [not found]";
3029 state.text <- qsearch;
3030 active, firstof m_first
active
3032 G.postRedisplay "listview backspace qsearch";
3033 set1 active first qsearch
3036 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3037 let pattern = m_qsearch ^
Wsi.toutf8
key in
3039 match search m_active
pattern 1 with
3041 state.text <- pattern ^
" [not found]";
3044 state.text <- pattern;
3045 active, firstof m_first
active
3047 G.postRedisplay "listview qsearch add";
3048 set1 active first pattern;
3050 | 0xff1b -> (* escape *)
3052 if String.length m_qsearch
= 0
3054 G.postRedisplay "list view escape";
3057 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3059 | None
-> m_prev_uioh
3064 G.postRedisplay "list view kill qsearch";
3065 source#setqsearch
"";
3066 coe {< m_qsearch
= "" >}
3069 | 0xff0d -> (* return *)
3071 let self = {< m_qsearch
= "" >} in
3072 source#setqsearch
"";
3074 G.postRedisplay "listview enter";
3075 if m_active
>= 0 && m_active
< source#getitemcount
3077 source#exit
(coe self) false m_active m_first m_pan
"";
3080 source#exit
(coe self) true m_active m_first m_pan
"";
3083 begin match opt with
3084 | None
-> m_prev_uioh
3088 | 0xff9f | 0xffff -> (* delete *)
3091 | 0xff52 -> navigate ~
-1 (* up *)
3092 | 0xff54 -> navigate 1 (* down *)
3093 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3094 | 0xff56 -> navigate fstate.maxrows
(* next *)
3096 | 0xff53 -> (* right *)
3098 G.postRedisplay "listview right";
3099 coe {< m_pan
= m_pan
- 1 >}
3101 | 0xff51 -> (* left *)
3103 G.postRedisplay "listview left";
3104 coe {< m_pan
= m_pan
+ 1 >}
3106 | 0xff50 -> (* home *)
3107 let active = find 0 1 in
3108 G.postRedisplay "listview home";
3111 | 0xff57 -> (* end *)
3112 let first = max
0 (itemcount - fstate.maxrows
) in
3113 let active = find (itemcount - 1) ~
-1 in
3114 G.postRedisplay "listview end";
3117 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3121 dolog "listview unknown key %#x" key; coe self
3123 method key key mask
=
3124 match state.mode
with
3125 | Textentry te
-> textentrykeyboard key mask te
; coe self
3126 | _ -> self#key1
key mask
3128 method button button down
x y _ =
3131 | 1 when x > conf.winw
- conf.scrollbw
->
3132 G.postRedisplay "listview scroll";
3135 let _, position, sh = self#
scrollph in
3136 if y > truncate
position && y < truncate
(position +. sh)
3138 state.mstate
<- Mscrolly
;
3142 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3143 let first = truncate
(s *. float source#getitemcount
) in
3144 let first = min source#getitemcount
first in
3145 Some
(coe {< m_first
= first; m_active
= first >})
3147 state.mstate
<- Mnone
;
3150 | 1 when not down
->
3151 begin match self#elemunder
y with
3153 G.postRedisplay "listview click";
3155 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3159 | n when (n == 4 || n == 5) && not down
->
3160 let len = source#getitemcount
in
3162 if n = 5 && m_first
+ fstate.maxrows
>= len
3166 let first = m_first
+ (if n == 4 then -1 else 1) in
3167 bound first 0 (len - 1)
3169 G.postRedisplay "listview wheel";
3170 Some
(coe {< m_first
= first >})
3175 | None
-> m_prev_uioh
3179 match state.mstate
with
3181 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3182 let first = truncate
(s *. float source#getitemcount
) in
3183 let first = min source#getitemcount
first in
3184 G.postRedisplay "listview motion";
3185 coe {< m_first
= first; m_active
= first >}
3188 method pmotion
x y =
3189 if x < conf.winw
- conf.scrollbw
3192 match self#elemunder
y with
3193 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3194 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3198 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3203 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3207 method infochanged
_ = ()
3209 method scrollpw
= (0, 0.0, 0.0)
3211 let nfs = fstate.fontsize
+ 1 in
3212 let y = m_first
* nfs in
3213 let itemcount = source#getitemcount
in
3214 let maxi = max
0 (itemcount - fstate.maxrows
) in
3215 let maxy = maxi * nfs in
3216 let p, h = scrollph y maxy in
3219 method modehash
= modehash
3222 class outlinelistview ~source
=
3225 ~source
:(source
:> lvsource
)
3227 ~modehash
:(findkeyhash conf "outline")
3230 method key key mask
=
3231 let calcfirst first active =
3234 let rows = active - first in
3235 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3239 let active = m_active
+ incr in
3240 let active = bound active 0 (source#getitemcount
- 1) in
3241 let first = calcfirst m_first
active in
3242 G.postRedisplay "outline navigate";
3243 coe {< m_active
= active; m_first
= first >}
3245 let ctrl = Wsi.withctrl mask
in
3247 | 110 when ctrl -> (* ctrl-n *)
3248 source#narrow m_qsearch
;
3249 G.postRedisplay "outline ctrl-n";
3250 coe {< m_first
= 0; m_active
= 0 >}
3252 | 117 when ctrl -> (* ctrl-u *)
3254 G.postRedisplay "outline ctrl-u";
3256 coe {< m_first
= 0; m_active
= 0 >}
3258 | 108 when ctrl -> (* ctrl-l *)
3259 let first = m_active
- (fstate.maxrows
/ 2) in
3260 G.postRedisplay "outline ctrl-l";
3261 coe {< m_first
= first >}
3263 | 0xff9f | 0xffff -> (* delete *)
3264 source#remove m_active
;
3265 G.postRedisplay "outline delete";
3266 let active = max
0 (m_active
-1) in
3267 coe {< m_first
= firstof m_first
active;
3268 m_active
= active >}
3270 | 0xff52 -> navigate ~
-1 (* up *)
3271 | 0xff54 -> navigate 1 (* down *)
3272 | 0xff55 -> (* prior *)
3273 navigate ~
-(fstate.maxrows
)
3274 | 0xff56 -> (* next *)
3275 navigate fstate.maxrows
3277 | 0xff53 -> (* [ctrl-]right *)
3281 G.postRedisplay "outline ctrl right";
3282 {< m_pan
= m_pan
+ 1 >}
3284 else self#updownlevel
1
3288 | 0xff51 -> (* [ctrl-]left *)
3292 G.postRedisplay "outline ctrl left";
3293 {< m_pan
= m_pan
- 1 >}
3295 else self#updownlevel ~
-1
3299 | 0xff50 -> (* home *)
3300 G.postRedisplay "outline home";
3301 coe {< m_first
= 0; m_active
= 0 >}
3303 | 0xff57 -> (* end *)
3304 let active = source#getitemcount
- 1 in
3305 let first = max
0 (active - fstate.maxrows
) in
3306 G.postRedisplay "outline end";
3307 coe {< m_active
= active; m_first
= first >}
3309 | _ -> super#
key key mask
3312 let outlinesource usebookmarks
=
3315 inherit lvsourcebase
3316 val mutable m_items
= empty
3317 val mutable m_orig_items
= empty
3318 val mutable m_prev_items
= empty
3319 val mutable m_narrow_pattern
= ""
3320 val mutable m_hadremovals
= false
3322 method getitemcount
=
3323 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3326 if n == Array.length m_items
&& m_hadremovals
3328 ("[Confirm removal]", 0)
3330 let s, n, _ = m_items
.(n) in
3333 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3334 ignore
(uioh
, first, qsearch);
3335 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3337 if String.length m_narrow_pattern
= 0
3343 if not
confrimremoval
3345 let _, _, anchor = m_items
.(active) in
3350 state.bookmarks
<- Array.to_list m_items
;
3351 m_orig_items
<- m_items
;
3354 else m_items
<- items;
3358 method hasaction
_ = true
3361 if Array.length m_items
!= Array.length m_orig_items
3362 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3365 method narrow
pattern =
3366 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3370 let rec loop accu n =
3373 m_narrow_pattern
<- pattern;
3374 m_items
<- Array.of_list
accu
3377 let (s, _, _) as o = m_items
.(n) in
3379 if (try ignore
(Str.search_forward
re s 0); true
3380 with Not_found
-> false)
3386 loop [] (Array.length m_items
- 1)
3391 then Array.of_list
state.bookmarks
3394 m_items
<- m_orig_items
3399 if m
>= 0 && m
< Array.length m_items
3401 m_hadremovals
<- true;
3402 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3403 let n = if n >= m
then n+1 else n in
3408 method reset
anchor items =
3409 m_hadremovals
<- false;
3410 if m_orig_items
== empty || m_prev_items
!= items
3412 m_orig_items
<- items;
3413 if String.length m_narrow_pattern
= 0
3414 then m_items
<- items;
3416 m_prev_items
<- items;
3417 let rely = getanchory anchor in
3419 let rec loop n best bestd
=
3420 if n = Array.length m_items
3423 let (_, _, anchor) = m_items
.(n) in
3424 let orely = getanchory anchor in
3425 let d = abs
(orely - rely) in
3428 else loop (n+1) best bestd
3433 m_first
<- firstof m_first
active
3437 let enterselector usebookmarks
=
3438 let source = outlinesource usebookmarks
in
3442 then Array.of_list
state.bookmarks
3445 if Array.length
outlines = 0
3447 showtext ' ' errmsg
;
3450 state.text <- source#greetmsg
;
3451 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3452 let anchor = getanchor () in
3453 source#reset
anchor outlines;
3454 state.uioh
<- coe (new outlinelistview ~
source);
3455 G.postRedisplay "enter selector";
3459 let enteroutlinemode =
3460 let f = enterselector false in
3461 fun ()-> f "Document has no outline";
3464 let enterbookmarkmode =
3465 let f = enterselector true in
3466 fun () -> f "Document has no bookmarks (yet)";
3469 let color_of_string s =
3470 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3471 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3475 let color_to_string (r
, g
, b) =
3476 let r = truncate
(r *. 256.0)
3477 and g
= truncate
(g
*. 256.0)
3478 and b = truncate
(b *. 256.0) in
3479 Printf.sprintf
"%d/%d/%d" r g
b
3482 let irect_of_string s =
3483 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3486 let irect_to_string (x0,y0,x1,y1) =
3487 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3490 let makecheckers () =
3491 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3493 converted by Issac Trotts. July 25, 2002 *)
3494 let image_height = 64
3495 and image_width
= 64 in
3499 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3501 for i
= 0 to image_width
- 1 do
3502 for j
= 0 to image_height - 1 do
3503 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3504 (if (i
land 8 ) lxor (j
land 8) = 0
3505 then [|255;255;255|] else [|200;200;200|])
3510 let image = make_image () in
3511 let id = GlTex.gen_texture
() in
3512 GlTex.bind_texture `texture_2d
id;
3513 GlPix.store
(`unpack_alignment
1);
3514 GlTex.image2d
image;
3515 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3518 `mag_filter `nearest
;
3519 `min_filter `nearest
];
3523 let setcheckers enabled
=
3524 match state.texid
with
3526 if enabled
then state.texid
<- Some
(makecheckers ())
3531 GlTex.delete_texture texid
;
3532 state.texid
<- None
;
3536 let int_of_string_with_suffix s =
3537 let l = String.length
s in
3541 let suffix = Char.lowercase
s.[l-1] in
3543 | 'k'
-> String.sub
s 0 (l-1), 10
3544 | 'm'
-> String.sub
s 0 (l-1), 20
3545 | 'g'
-> String.sub
s 0 (l-1), 30
3549 let n = int_of_string
s1 in
3550 let m = n lsl shift
in
3552 then raise
(Failure
"value too large")
3556 let string_with_suffix_of_int n =
3564 if n land ((1 lsl 20) - 1) = 0
3567 if n land ((1 lsl 10) - 1) = 0
3574 let h = n mod 1000 in
3577 then string_of_int
h ^
s
3579 let s = Printf.sprintf
"_%03d%s" h s in
3586 let defghyllscroll = (40, 8, 32);;
3587 let ghyllscroll_of_string s =
3588 let (n, a, b) as nab
=
3591 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3593 if n <= a || n <= b || a >= b
3594 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3598 let ghyllscroll_to_string ((n, a, b) as nab
) =
3599 if nab
= defghyllscroll
3601 else Printf.sprintf
"%d,%d,%d" n a b;
3604 let describe_location () =
3606 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3608 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3609 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3613 else (100. *. (float state.y /. float maxy))
3617 Printf.sprintf
"page %d of %d [%.2f%%]"
3618 (fn+1) state.pagecount
percent
3621 "pages %d-%d of %d [%.2f%%]"
3622 (fn+1) (ln
+1) state.pagecount
percent
3626 let btos b = if b then "\xe2\x88\x9a" else "" in
3627 let showextended = ref false in
3628 let leave mode
= function
3629 | Confirm
-> state.mode
<- mode
3630 | Cancel
-> state.mode
<- mode
in
3633 val mutable m_first_time
= true
3634 val mutable m_l
= []
3635 val mutable m_a
= [||]
3636 val mutable m_prev_uioh
= nouioh
3637 val mutable m_prev_mode
= View
3639 inherit lvsourcebase
3641 method reset prev_mode prev_uioh
=
3642 m_a
<- Array.of_list
(List.rev m_l
);
3644 m_prev_mode
<- prev_mode
;
3645 m_prev_uioh
<- prev_uioh
;
3649 if n >= Array.length m_a
3653 | _, _, _, Action
_ -> m_active
<- n
3657 m_first_time
<- false;
3660 method int name get
set =
3662 (name
, `
int get
, 1, Action
(
3665 try set (int_of_string
s)
3667 state.text <- Printf.sprintf
"bad integer `%s': %s"
3668 s (Printexc.to_string exn
)
3671 let te = name ^
": ", "", None
, intentry, ondone in
3672 state.mode
<- Textentry
(te, leave m_prev_mode
);
3676 method int_with_suffix name get
set =
3678 (name
, `intws get
, 1, Action
(
3681 try set (int_of_string_with_suffix s)
3683 state.text <- Printf.sprintf
"bad integer `%s': %s"
3684 s (Printexc.to_string exn
)
3688 name ^
": ", "", None
, intentry_with_suffix, ondone
3690 state.mode
<- Textentry
(te, leave m_prev_mode
);
3694 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3696 (name
, `
bool (btos, get
), offset
, Action
(
3703 method color name get
set =
3705 (name
, `color get
, 1, Action
(
3707 let invalid = (nan
, nan
, nan
) in
3710 try color_of_string s
3712 state.text <- Printf.sprintf
"bad color `%s': %s"
3713 s (Printexc.to_string exn
);
3719 let te = name ^
": ", "", None
, textentry, ondone in
3720 state.text <- color_to_string (get
());
3721 state.mode
<- Textentry
(te, leave m_prev_mode
);
3725 method string name get
set =
3727 (name
, `
string get
, 1, Action
(
3729 let ondone s = set s in
3730 let te = name ^
": ", "", None
, textentry, ondone in
3731 state.mode
<- Textentry
(te, leave m_prev_mode
);
3735 method colorspace name get
set =
3737 (name
, `
string get
, 1, Action
(
3740 let vals = [| "rgb"; "bgr"; "gray" |] in
3742 inherit lvsourcebase
3745 m_active
<- int_of_colorspace conf.colorspace
;
3748 method getitemcount
= Array.length
vals
3749 method getitem
n = (vals.(n), 0)
3750 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3751 ignore
(uioh
, first, pan
, qsearch);
3752 if not cancel
then set active;
3754 method hasaction
_ = true
3758 let modehash = findkeyhash conf "info" in
3759 coe (new listview ~
source ~trusted
:true ~
modehash)
3762 method caption
s offset
=
3763 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3765 method caption2
s f offset
=
3766 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3768 method getitemcount
= Array.length m_a
3771 let tostr = function
3772 | `
int f -> string_of_int
(f ())
3773 | `intws
f -> string_with_suffix_of_int (f ())
3775 | `color
f -> color_to_string (f ())
3776 | `
bool (btos, f) -> btos (f ())
3779 let name, t
, offset
, _ = m_a
.(n) in
3780 ((let s = tostr t
in
3781 if String.length
s > 0
3782 then Printf.sprintf
"%s\t%s" name s
3786 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3790 m_qsearch
<- qsearch;
3792 match m_a
.(active) with
3793 | _, _, _, Action
f -> f uioh
3805 method hasaction
n =
3807 | _, _, _, Action
_ -> true
3811 let rec fillsrc prevmode prevuioh
=
3812 let sep () = src#caption
"" 0 in
3813 let colorp name get
set =
3815 (fun () -> color_to_string (get
()))
3818 let c = color_of_string v in
3821 state.text <- Printf.sprintf
"bad color `%s': %s"
3822 v (Printexc.to_string exn
);
3825 let oldmode = state.mode
in
3826 let birdseye = isbirdseye state.mode
in
3828 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3830 src#
bool "presentation mode"
3831 (fun () -> conf.presentation)
3833 conf.presentation <- v;
3834 state.anchor <- getanchor ();
3837 src#
bool "ignore case in searches"
3838 (fun () -> conf.icase
)
3839 (fun v -> conf.icase
<- v);
3842 (fun () -> conf.preload)
3843 (fun v -> conf.preload <- v);
3845 src#
bool "highlight links"
3846 (fun () -> conf.hlinks
)
3847 (fun v -> conf.hlinks
<- v);
3849 src#
bool "under info"
3850 (fun () -> conf.underinfo
)
3851 (fun v -> conf.underinfo
<- v);
3853 src#
bool "persistent bookmarks"
3854 (fun () -> conf.savebmarks
)
3855 (fun v -> conf.savebmarks
<- v);
3857 src#
bool "proportional display"
3858 (fun () -> conf.proportional
)
3859 (fun v -> reqlayout conf.angle
v);
3861 src#
bool "trim margins"
3862 (fun () -> conf.trimmargins
)
3863 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3865 src#
bool "persistent location"
3866 (fun () -> conf.jumpback
)
3867 (fun v -> conf.jumpback
<- v);
3870 src#
int "inter-page space"
3871 (fun () -> conf.interpagespace)
3873 conf.interpagespace <- n;
3875 match state.layout with
3880 state.maxy <- calcheight ();
3881 let y = getpagey pageno in
3886 (fun () -> conf.pagebias
)
3887 (fun v -> conf.pagebias
<- v);
3889 src#
int "scroll step"
3890 (fun () -> conf.scrollstep
)
3891 (fun n -> conf.scrollstep
<- n);
3893 src#
int "auto scroll step"
3895 match state.autoscroll
with
3897 | _ -> conf.autoscrollstep
)
3899 if state.autoscroll
<> None
3900 then state.autoscroll
<- Some
n;
3901 conf.autoscrollstep
<- n);
3904 (fun () -> truncate
(conf.zoom *. 100.))
3905 (fun v -> setzoom ((float v) /. 100.));
3908 (fun () -> conf.angle
)
3909 (fun v -> reqlayout v conf.proportional
);
3911 src#
int "scroll bar width"
3912 (fun () -> state.scrollw
)
3916 reshape conf.winw
conf.winh
;
3919 src#
int "scroll handle height"
3920 (fun () -> conf.scrollh
)
3921 (fun v -> conf.scrollh
<- v;);
3923 src#
int "thumbnail width"
3924 (fun () -> conf.thumbw
)
3926 conf.thumbw
<- min
4096 v;
3929 leavebirdseye beye
false;
3934 src#
string "columns"
3936 match conf.columns
with
3938 | Some
(multicol
, _) -> columns_to_string multicol
)
3940 let n, a, b = columns_of_string v in
3944 src#caption
"Presentation mode" 0;
3945 src#
bool "scrollbar visible"
3946 (fun () -> conf.scrollbarinpm
)
3948 if v != conf.scrollbarinpm
3950 conf.scrollbarinpm
<- v;
3951 if conf.presentation
3953 state.scrollw
<- if v then conf.scrollbw
else 0;
3954 reshape conf.winw
conf.winh
;
3960 src#caption
"Pixmap cache" 0;
3961 src#int_with_suffix
"size (advisory)"
3962 (fun () -> conf.memlimit
)
3963 (fun v -> conf.memlimit
<- v);
3966 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3967 (string_with_suffix_of_int state.memused
)
3968 (Hashtbl.length
state.tilemap
)) 1;
3971 src#caption
"Layout" 0;
3972 src#caption2
"Dimension"
3974 Printf.sprintf
"%dx%d (virtual %dx%d)"
3980 src#caption2
"Position" (fun () ->
3981 Printf.sprintf
"%dx%d" state.x state.y
3984 src#caption2
"Visible" (fun () -> describe_location ()) 1
3988 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3989 "Save these parameters as global defaults at exit"
3990 (fun () -> conf.bedefault
)
3991 (fun v -> conf.bedefault
<- v)
3995 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3996 src#
bool ~offset
:0 ~
btos "Extended parameters"
3997 (fun () -> !showextended)
3998 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4002 (fun () -> conf.checkers
)
4003 (fun v -> conf.checkers
<- v; setcheckers v);
4004 src#
bool "update cursor"
4005 (fun () -> conf.updatecurs
)
4006 (fun v -> conf.updatecurs
<- v);
4008 (fun () -> conf.verbose
)
4009 (fun v -> conf.verbose
<- v);
4010 src#
bool "invert colors"
4011 (fun () -> conf.invert
)
4012 (fun v -> conf.invert
<- v);
4014 (fun () -> conf.maxhfit
)
4015 (fun v -> conf.maxhfit
<- v);
4016 src#
bool "redirect stderr"
4017 (fun () -> conf.redirectstderr)
4018 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4019 src#
string "uri launcher"
4020 (fun () -> conf.urilauncher
)
4021 (fun v -> conf.urilauncher
<- v);
4022 src#
string "path launcher"
4023 (fun () -> conf.pathlauncher
)
4024 (fun v -> conf.pathlauncher
<- v);
4025 src#
string "tile size"
4026 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4029 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4030 conf.tileh
<- max
64 w;
4031 conf.tilew
<- max
64 h;
4034 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4035 v (Printexc.to_string exn
));
4036 src#
int "texture count"
4037 (fun () -> conf.texcount
)
4040 then conf.texcount
<- v
4041 else showtext '
!'
" Failed to set texture count please retry later"
4043 src#
int "slice height"
4044 (fun () -> conf.sliceheight
)
4046 conf.sliceheight
<- v;
4047 wcmd "sliceh %d" conf.sliceheight
;
4049 src#
int "anti-aliasing level"
4050 (fun () -> conf.aalevel
)
4052 conf.aalevel
<- bound v 0 8;
4053 state.anchor <- getanchor ();
4054 opendoc state.path
state.password
;
4056 src#
int "ui font size"
4057 (fun () -> fstate.fontsize
)
4058 (fun v -> setfontsize (bound v 5 100));
4059 colorp "background color"
4060 (fun () -> conf.bgcolor
)
4061 (fun v -> conf.bgcolor
<- v);
4062 src#
bool "crop hack"
4063 (fun () -> conf.crophack
)
4064 (fun v -> conf.crophack
<- v);
4065 src#
string "trim fuzz"
4066 (fun () -> irect_to_string conf.trimfuzz
)
4069 conf.trimfuzz
<- irect_of_string v;
4071 then settrim true conf.trimfuzz
;
4073 state.text <- Printf.sprintf
"bad irect `%s': %s"
4074 v (Printexc.to_string exn
)
4076 src#
string "throttle"
4078 match conf.maxwait
with
4079 | None
-> "show place holder if page is not ready"
4082 then "wait for page to fully render"
4084 "wait " ^ string_of_float
time
4085 ^
" seconds before showing placeholder"
4089 let f = float_of_string
v in
4091 then conf.maxwait
<- None
4092 else conf.maxwait
<- Some
f
4094 state.text <- Printf.sprintf
"bad time `%s': %s"
4095 v (Printexc.to_string exn
)
4097 src#
string "ghyll scroll"
4099 match conf.ghyllscroll
with
4101 | Some nab
-> ghyllscroll_to_string nab
4106 if String.length
v = 0
4108 else Some
(ghyllscroll_of_string v)
4110 conf.ghyllscroll
<- gs
4112 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4113 v (Printexc.to_string exn
)
4115 src#
string "selection command"
4116 (fun () -> conf.selcmd
)
4117 (fun v -> conf.selcmd
<- v);
4118 src#colorspace
"color space"
4119 (fun () -> colorspace_to_string conf.colorspace
)
4121 conf.colorspace
<- colorspace_of_int v;
4128 src#caption
"Document" 0;
4129 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4130 src#caption2
"Pages"
4131 (fun () -> string_of_int
state.pagecount
) 1;
4132 src#caption2
"Dimensions"
4133 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4137 src#caption
"Trimmed margins" 0;
4138 src#caption2
"Dimensions"
4139 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4142 src#reset prevmode prevuioh
;
4146 let prevmode = state.mode
4147 and prevuioh
= state.uioh in
4148 fillsrc prevmode prevuioh
;
4149 let source = (src :> lvsource
) in
4150 let modehash = findkeyhash conf "info" in
4151 state.uioh <- coe (object (self)
4152 inherit listview ~
source ~trusted
:true ~
modehash as super
4153 val mutable m_prevmemused
= 0
4154 method infochanged
= function
4156 if m_prevmemused
!= state.memused
4158 m_prevmemused
<- state.memused
;
4159 G.postRedisplay "memusedchanged";
4161 | Pdim
-> G.postRedisplay "pdimchanged"
4162 | Docinfo
-> fillsrc prevmode prevuioh
4164 method key key mask
=
4165 if not
(Wsi.withctrl mask
)
4168 | 0xff51 -> coe (self#updownlevel ~
-1)
4169 | 0xff53 -> coe (self#updownlevel
1)
4170 | _ -> super#
key key mask
4171 else super#
key key mask
4173 G.postRedisplay "info";
4179 inherit lvsourcebase
4180 method getitemcount
= Array.length
state.help
4182 let s, n, _ = state.help
.(n) in
4185 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4189 m_qsearch
<- qsearch;
4190 match state.help
.(active) with
4191 | _, _, Action
f -> Some
(f uioh)
4201 method hasaction
n =
4202 match state.help
.(n) with
4203 | _, _, Action
_ -> true
4210 let modehash = findkeyhash conf "help" in
4211 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4212 G.postRedisplay "help";
4217 let re = Str.regexp
"[\r\n]" in
4219 inherit lvsourcebase
4220 val mutable m_items
= [||]
4222 method getitemcount
= 1 + Array.length m_items
4227 else m_items
.(n-1), 0
4229 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4234 then Buffer.clear
state.errmsgs
;
4235 m_qsearch
<- qsearch;
4242 method hasaction
n =
4246 state.newerrmsgs
<- false;
4247 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4248 m_items
<- Array.of_list
l
4256 let source = (msgsource :> lvsource
) in
4257 let modehash = findkeyhash conf "listview" in
4258 state.uioh <- coe (object
4259 inherit listview ~
source ~trusted
:false ~
modehash as super
4262 then msgsource#reset
;
4265 G.postRedisplay "msgs";
4268 let quickbookmark ?title
() =
4269 match state.layout with
4275 let sec = Unix.gettimeofday
() in
4276 let tm = Unix.localtime
sec in
4277 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4281 (tm.Unix.tm_year
+ 1900)
4284 | Some
title -> title
4287 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4292 state.fullscreen
<- None
;
4296 let setautoscrollspeed step goingdown
=
4297 let incr = max
1 ((abs step
) / 2) in
4298 let incr = if goingdown
then incr else -incr in
4299 let astep = step
+ incr in
4300 state.autoscroll
<- Some
astep;
4303 let viewkeyboard key mask
=
4305 let mode = state.mode in
4306 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4309 G.postRedisplay "view:enttext"
4311 let ctrl = Wsi.withctrl mask
in
4316 | 0xff63 -> (* insert *)
4317 if conf.angle
mod 360 = 0
4319 state.mode <- LinkNav
(Ltgendir
0);
4322 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4324 | 0xff1b | 113 -> (* escape / q *)
4325 begin match state.mstate
with
4327 state.mstate
<- Mnone
;
4328 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4329 G.postRedisplay "kill zoom rect";
4331 match state.ranchors
with
4333 | (path
, password
, anchor) :: rest
->
4334 state.ranchors
<- rest
;
4335 state.anchor <- anchor;
4336 opendoc path password
4339 | 0xff08 -> (* backspace *)
4340 let y = getnav ~
-1 in
4341 gotoy_and_clear_text y
4349 G.postRedisplay "dehighlight";
4351 | 47 | 63 -> (* / ? *)
4352 let ondone isforw
s =
4353 cbput state.hists
.pat
s;
4354 state.searchpattern
<- s;
4357 let s = String.create
1 in
4358 s.[0] <- Char.chr
key;
4359 enttext (s, "", Some
(onhist state.hists
.pat
),
4360 textentry, ondone (key = 47))
4362 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4363 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4364 setzoom (conf.zoom +. incr)
4366 | 43 | 0xffab -> (* + *)
4369 try int_of_string
s with exc
->
4370 state.text <- Printf.sprintf
"bad integer `%s': %s"
4371 s (Printexc.to_string exc
);
4377 state.text <- "page bias is now " ^ string_of_int
n;
4380 enttext ("page bias: ", "", None
, intentry, ondone)
4382 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4383 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4384 setzoom (max
0.01 (conf.zoom -. decr))
4386 | 45 | 0xffad -> (* - *)
4387 let ondone msg
= state.text <- msg
in
4389 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4390 optentry state.mode, ondone
4393 | 48 when ctrl -> (* ctrl-0 *)
4396 | 49 when ctrl -> (* 1 *)
4397 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4401 | 0xffc6 -> (* f9 *)
4404 | 57 when ctrl -> (* ctrl-9 *)
4407 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4408 when not
ctrl -> (* 0..9 *)
4411 try int_of_string
s with exc
->
4412 state.text <- Printf.sprintf
"bad integer `%s': %s"
4413 s (Printexc.to_string exc
);
4419 cbput state.hists
.pag
(string_of_int
n);
4420 gotopage1 (n + conf.pagebias
- 1) 0;
4423 let pageentry text key =
4424 match Char.unsafe_chr
key with
4425 | 'g'
-> TEdone
text
4426 | _ -> intentry text key
4428 let text = "x" in text.[0] <- Char.chr
key;
4429 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4432 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4433 reshape conf.winw
conf.winh
;
4436 conf.hlinks
<- not
conf.hlinks
;
4437 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4438 G.postRedisplay "toggle highlightlinks";
4441 begin match state.autoscroll
with
4443 conf.autoscrollstep
<- step
;
4444 state.autoscroll
<- None
4446 if conf.autoscrollstep
= 0
4447 then state.autoscroll
<- Some
1
4448 else state.autoscroll
<- Some
conf.autoscrollstep
4452 conf.presentation <- not
conf.presentation;
4453 if conf.presentation
4455 if not
conf.scrollbarinpm
4456 then state.scrollw
<- 0;
4459 state.scrollw
<- conf.scrollbw
;
4461 showtext ' '
("presentation mode " ^
4462 if conf.presentation then "on" else "off");
4463 state.anchor <- getanchor ();
4467 begin match state.fullscreen
with
4469 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4472 state.fullscreen
<- None
;
4477 gotoy_and_clear_text 0
4480 gotopage1 (state.pagecount
- 1) 0
4482 | 112 | 78 -> (* p|N *)
4483 search state.searchpattern
false
4485 | 110 | 0xffc0 -> (* n|F3 *)
4486 search state.searchpattern
true
4489 begin match state.layout with
4492 gotoy_and_clear_text (getpagey l.pageno)
4496 begin match List.rev
state.layout with
4499 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4500 gotoy_and_clear_text (getpagey pageno)
4503 | 0xff9f | 0xffff -> (* delete *)
4504 begin match state.layout with
4507 let pageno = max
0 (l.pageno-1) in
4508 gotoy_and_clear_text (getpagey pageno)
4512 showtext ' '
(describe_location ());
4515 begin match state.layout with
4518 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4523 enterbookmarkmode ()
4525 | 104 | 0xffbe -> (* h|F1 *)
4531 | 101 when conf.redirectstderr -> (* e *)
4536 match state.layout with
4539 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4543 enttext ("bookmark: ", "", None
, textentry, ondone)
4547 showtext ' '
"Quick bookmark added";
4550 begin match state.layout with
4552 let rect = getpdimrect
l.pagedimno
in
4556 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4557 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4559 (truncate
(rect.(1) -. rect.(0)),
4560 truncate
(rect.(3) -. rect.(0)))
4562 let w = truncate
((float w)*.conf.zoom)
4563 and h = truncate
((float h)*.conf.zoom) in
4566 state.anchor <- getanchor ();
4567 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4569 G.postRedisplay "z";
4574 | 50 when ctrl -> (* ctrl-2 *)
4575 let maxw = getmaxw
() in
4577 then setzoom (maxw /. float conf.winw
)
4579 | 60 | 62 -> (* < > *)
4580 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4582 | 91 | 93 -> (* [ ] *)
4584 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4586 G.postRedisplay "brightness";
4588 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4589 setzoom state.prevzoom
4591 | 107 | 0xff52 -> (* k up *)
4592 begin match state.autoscroll
with
4594 begin match state.mode with
4595 | Birdseye beye
-> upbirdseye 1 beye
4598 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4599 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4602 setautoscrollspeed n false
4605 | 106 | 0xff54 -> (* j down *)
4606 begin match state.autoscroll
with
4608 begin match state.mode with
4609 | Birdseye beye
-> downbirdseye 1 beye
4612 then gotoy_and_clear_text (clamp (conf.winh
/2))
4613 else gotoy_and_clear_text (clamp conf.scrollstep
)
4616 setautoscrollspeed n true
4619 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4627 let dx = if key = 0xff51 then dx else -dx in
4628 state.x <- state.x + dx;
4629 gotoy_and_clear_text state.y
4632 G.postRedisplay "lef/right"
4635 | 0xff55 -> (* prior *)
4639 match state.layout with
4641 | l :: _ -> state.y - l.pagey
4647 | 0xff56 -> (* next *)
4651 match List.rev
state.layout with
4653 | l :: _ -> getpagey l.pageno
4659 | 0xff50 -> gotoghyll 0
4660 | 0xff57 -> gotoghyll (clamp state.maxy)
4661 | 0xff53 when Wsi.withalt mask
->
4662 gotoghyll (getnav ~
-1)
4663 | 0xff51 when Wsi.withalt mask
->
4664 gotoghyll (getnav 1)
4667 state.anchor <- getanchor ();
4668 opendoc state.path
state.password
4673 | 118 when conf.debug
-> (* v *)
4676 match getopaque l.pageno with
4679 let x0, y0, x1, y1 = pagebbox opaque
in
4680 let a,b = float x0, float y0 in
4681 let c,d = float x1, float y0 in
4682 let e,f = float x1, float y1 in
4683 let h,j
= float x0, float y1 in
4684 let rect = (a,b,c,d,e,f,h,j
) in
4686 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4688 G.postRedisplay "v";
4691 vlog "huh? %s" (Wsi.keyname
key)
4694 let gotounder = function
4695 | Ulinkgoto
(pageno, top) ->
4699 gotopage1 pageno top;
4705 | Uremote
(filename
, pageno) ->
4707 if Sys.file_exists filename
4710 let dir = Filename.dirname
state.path in
4711 let path = Filename.concat
dir filename
in
4712 if Sys.file_exists
path
4716 if String.length
path > 0
4718 let anchor = getanchor () in
4719 let ranchor = state.path, state.password
, anchor in
4720 state.anchor <- (pageno, 0.0);
4721 state.ranchors
<- ranchor :: state.ranchors
;
4724 else showtext '
!'
("Could not find " ^ filename
)
4726 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4729 let linknavkeyboard key mask
linknav =
4730 let getpage pageno =
4731 let rec loop = function
4733 | l :: _ when l.pageno = pageno -> Some
l
4734 | _ :: rest
-> loop rest
4735 in loop state.layout
4737 let doexact (pageno, n) =
4738 match getopaque pageno, getpage pageno with
4739 | Some opaque
, Some
l ->
4742 let under = getlink opaque
n in
4743 G.postRedisplay "link gotounder";
4749 | 0xff50 -> (* home *)
4750 Some
(findlink opaque LDfirst
), -1
4752 | 0xff57 -> (* end *)
4753 Some
(findlink opaque LDlast
), 1
4755 | 0xff51 -> (* left *)
4756 Some
(findlink opaque
(LDleft
n)), -1
4758 | 0xff53 -> (* right *)
4759 Some
(findlink opaque
(LDright
n)), 1
4761 | 0xff52 -> (* up *)
4762 Some
(findlink opaque
(LDup
n)), -1
4764 | 0xff54 -> (* down *)
4765 Some
(findlink opaque
(LDdown
n)), 1
4770 begin match findpwl
l.pageno dir with
4774 state.mode <- LinkNav
(Ltgendir
dir);
4775 let y, h = getpageyh pageno in
4778 then y + h - conf.winh
4783 begin match getopaque pageno, getpage pageno with
4784 | Some opaque
, Some
_ ->
4786 let ld = if dir > 0 then LDfirst
else LDlast
in
4789 begin match link with
4790 | Lfound
(m, x0, y0, x1, y1) ->
4791 let r = x0, y0, x1, y1 in
4792 showlinktype (getlink opaque
m);
4793 state.mode <- LinkNav
(Ltexact
((pageno, m), r));
4794 G.postRedisplay "linknav jpage";
4801 begin match opt with
4802 | Some Lnotfound
-> pwl l dir;
4803 | Some
(Lfound
(m, x0, y0, x1, y1)) ->
4808 then gotopage1 l.pageno y0
4810 let d = fstate.fontsize
+ 1 in
4811 if y1 - l.pagey > l.pagevh - d
4812 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
4813 else G.postRedisplay "linknav";
4815 let r = x0, y0, x1, y1 in
4816 showlinktype (getlink opaque
m);
4817 state.mode <- LinkNav
(Ltexact
((l.pageno, m), r));
4821 state.mode <- LinkNav
(Ltgendir
0);
4822 viewkeyboard key mask
4824 | _ -> viewkeyboard key mask
4829 G.postRedisplay "leave linknav"
4833 | Ltgendir
_ -> viewkeyboard key mask
4834 | Ltexact
(exact
, _) -> doexact exact
4837 let keyboard key mask
=
4838 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4839 then wcmd "interrupt"
4840 else state.uioh <- state.uioh#
key key mask
4843 let birdseyekeyboard key mask
4844 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4846 match conf.columns
with
4848 | Some
((c, _, _), _) -> c
4851 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4852 let y, h = getpageyh pageno in
4853 let top = (conf.winh
- h) / 2 in
4854 gotoy (max
0 (y - top))
4855 | 0xff0d -> leavebirdseye beye
false
4856 | 0xff1b -> leavebirdseye beye
true (* escape *)
4857 | 0xff52 -> upbirdseye incr beye
(* prior *)
4858 | 0xff54 -> downbirdseye incr beye
(* next *)
4859 | 0xff51 -> upbirdseye 1 beye
(* up *)
4860 | 0xff53 -> downbirdseye 1 beye
(* down *)
4863 begin match state.layout with
4867 state.mode <- Birdseye
(
4868 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4870 gotopage1 l.pageno 0;
4873 let layout = layout (state.y-conf.winh
) conf.winh
in
4875 | [] -> gotoy (clamp (-conf.winh
))
4877 state.mode <- Birdseye
(
4878 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4880 gotopage1 l.pageno 0
4883 | [] -> gotoy (clamp (-conf.winh
))
4887 begin match List.rev
state.layout with
4889 let layout = layout (state.y + conf.winh
) conf.winh
in
4890 begin match layout with
4892 let incr = l.pageh
- l.pagevh in
4897 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4899 G.postRedisplay "birdseye pagedown";
4901 else gotoy (clamp (incr + conf.interpagespace*2));
4905 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4906 gotopage1 l.pageno 0;
4909 | [] -> gotoy (clamp conf.winh
)
4913 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4917 let pageno = state.pagecount
- 1 in
4918 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4919 if not
(pagevisible state.layout pageno)
4922 match List.rev
state.pdims
with
4924 | (_, _, h, _) :: _ -> h
4926 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4927 else G.postRedisplay "birdseye end";
4928 | _ -> viewkeyboard key mask
4933 match state.mode with
4934 | Textentry
_ -> scalecolor 0.4
4936 | View
-> scalecolor 1.0
4937 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4938 if l.pageno = hooverpageno
4941 if l.pageno = pageno
4947 begin match getopaque l.pageno with
4949 if tileready l l.pagex l.pagey
4951 let x = l.pagedispx - l.pagex
4952 and y = l.pagedispy - l.pagey in
4953 postprocess opaque
conf.hlinks
x y;
4959 let scrollindicator () =
4960 let sbw, ph
, sh = state.uioh#
scrollph in
4961 let sbh, pw
, sw = state.uioh#scrollpw
in
4963 GlDraw.color (0.64, 0.64, 0.64);
4965 (float (conf.winw
- sbw), 0.)
4966 (float conf.winw
, float conf.winh
)
4969 (0., float (conf.winh
- sbh))
4970 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4972 GlDraw.color (0.0, 0.0, 0.0);
4975 (float (conf.winw
- sbw), ph
)
4976 (float conf.winw
, ph
+. sh)
4979 (pw
, float (conf.winh
- sbh))
4980 (pw
+. sw, float conf.winh
)
4985 match state.mstate
with
4986 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4989 | Msel
((x0, y0), (x1, y1)) ->
4990 let rec loop = function
4992 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4993 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4994 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4995 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4997 match getopaque l.pageno with
4999 let x0, y0 = pagetranslatepoint l x0 y0 in
5000 let x1, y1 = pagetranslatepoint l x1 y1 in
5001 seltext opaque
(x0, y0, x1, y1);
5009 let showrects rects
=
5011 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5012 GlDraw.polygon_mode `both `fill
;
5013 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5015 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5017 if l.pageno = pageno
5019 let dx = float (l.pagedispx - l.pagex) in
5020 let dy = float (l.pagedispy - l.pagey) in
5021 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5022 GlDraw.begins `quads
;
5024 GlDraw.vertex2
(x0+.dx, y0+.dy);
5025 GlDraw.vertex2
(x1+.dx, y1+.dy);
5026 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5027 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5038 GlClear.color (scalecolor2 conf.bgcolor
);
5039 GlClear.clear
[`
color];
5040 List.iter
drawpage state.layout;
5042 match state.mode with
5043 | LinkNav
(Ltexact
((pageno, _), (x0, y0, x1, y1))) ->
5055 begin match state.mstate
with
5056 | Mzoomrect
((x0, y0), (x1, y1)) ->
5058 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5059 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5060 GlDraw.rect (float x0, float y0)
5061 (float x1, float y1);
5070 let zoomrect x y x1 y1 =
5073 and y0 = min
y y1 in
5074 gotoy (state.y + y0);
5075 state.anchor <- getanchor ();
5076 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5078 if state.w < conf.winw
- state.scrollw
5079 then (conf.winw
- state.scrollw
- state.w) / 2
5082 state.x <- (state.x + margin) - x0;
5084 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5085 state.mstate
<- Mnone
;
5089 let winw = conf.winw - state.scrollw
- 1 in
5090 let s = float x /. float winw in
5091 let destx = truncate
(float (state.w + winw) *. s) in
5092 state.x <- winw - destx;
5093 gotoy_and_clear_text state.y;
5094 state.mstate
<- Mscrollx
;
5098 let s = float y /. float conf.winh
in
5099 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5100 gotoy_and_clear_text desty;
5101 state.mstate
<- Mscrolly
;
5104 let viewmouse button down
x y mask
=
5106 | n when (n == 4 || n == 5) && not down
->
5107 if Wsi.withctrl mask
5109 match state.mstate
with
5110 | Mzoom
(oldn
, i
) ->
5118 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5120 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5122 let zoom = conf.zoom -. incr in
5124 state.mstate
<- Mzoom
(n, 0);
5126 state.mstate
<- Mzoom
(n, i
+1);
5128 else state.mstate
<- Mzoom
(n, 0)
5130 | _ -> state.mstate
<- Mzoom
(n, 0)
5133 match state.autoscroll
with
5134 | Some step
-> setautoscrollspeed step
(n=4)
5138 then -conf.scrollstep
5139 else conf.scrollstep
5141 let incr = incr * 2 in
5142 let y = clamp incr in
5143 gotoy_and_clear_text y
5146 | 1 when Wsi.withctrl mask
->
5149 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5150 state.mstate
<- Mpan
(x, y)
5153 state.mstate
<- Mnone
5158 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5160 state.mstate
<- Mzoomrect
(p, p)
5163 match state.mstate
with
5164 | Mzoomrect
((x0, y0), _) ->
5165 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5166 then zoomrect x0 y0 x y
5168 state.mstate
<- Mnone
;
5169 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5170 G.postRedisplay "kill accidental zoom rect";
5173 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5174 state.mstate
<- Mnone
5177 | 1 when x > conf.winw - state.scrollw
->
5180 let _, position, sh = state.uioh#
scrollph in
5181 if y > truncate
position && y < truncate
(position +. sh)
5182 then state.mstate
<- Mscrolly
5185 state.mstate
<- Mnone
5187 | 1 when y > conf.winh
- state.hscrollh ->
5190 let _, position, sw = state.uioh#scrollpw
in
5191 if x > truncate
position && x < truncate
(position +. sw)
5192 then state.mstate
<- Mscrollx
5195 state.mstate
<- Mnone
5198 let dest = if down
then getunder x y else Unone
in
5199 begin match dest with
5200 | Ulinkgoto
(pageno, top) ->
5204 gotopage1 pageno top;
5210 | Uremote
(filename
, pageno) ->
5212 if Sys.file_exists filename
5215 let dir = Filename.dirname
state.path in
5216 let path = Filename.concat
dir filename
in
5217 if Sys.file_exists
path
5221 if String.length
path > 0
5223 let anchor = getanchor () in
5224 let ranchor = state.path, state.password
, anchor in
5225 state.anchor <- (pageno, 0.0);
5226 state.ranchors
<- ranchor :: state.ranchors
;
5229 else showtext '
!'
("Could not find " ^ filename
)
5231 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5233 | Unone
when down
->
5234 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5235 state.mstate
<- Mpan
(x, y);
5237 | Unone
| Utext
_ ->
5240 if conf.angle
mod 360 = 0
5242 state.mstate
<- Msel
((x, y), (x, y));
5243 G.postRedisplay "mouse select";
5247 match state.mstate
with
5250 | Mzoom
_ | Mscrollx
| Mscrolly
->
5251 state.mstate
<- Mnone
5253 | Mzoomrect
((x0, y0), _) ->
5257 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5258 state.mstate
<- Mnone
5260 | Msel
((_, y0), (_, y1)) ->
5261 let rec loop = function
5264 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5265 || ((y1 >= l.pagedispy
5266 && y1 <= (l.pagedispy + l.pagevh)))
5268 match getopaque l.pageno with
5270 copysel
conf.selcmd opaque
;
5271 G.postRedisplay "copysel"
5276 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5277 state.mstate
<- Mnone
;
5284 let birdseyemouse button down
x y mask
5285 (conf, leftx
, _, hooverpageno
, anchor) =
5288 let rec loop = function
5291 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5292 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5294 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5300 | _ -> viewmouse button down
x y mask
5303 let mouse button down
x y mask
=
5304 state.uioh <- state.uioh#button button down
x y mask
;
5308 state.uioh <- state.uioh#
motion x y
5312 state.uioh <- state.uioh#
pmotion x y;
5318 method key key mask
=
5319 begin match state.mode with
5320 | Textentry
textentry -> textentrykeyboard key mask
textentry
5321 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5322 | View
-> viewkeyboard key mask
5323 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5327 method button button bstate
x y mask
=
5328 begin match state.mode with
5330 | View
-> viewmouse button bstate
x y mask
5331 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5337 begin match state.mode with
5339 | View
| Birdseye
_ | LinkNav
_ ->
5340 match state.mstate
with
5341 | Mzoom
_ | Mnone
-> ()
5346 state.mstate
<- Mpan
(x, y);
5347 if conf.zoom > 1.0 then state.x <- state.x + dx;
5349 gotoy_and_clear_text y
5352 state.mstate
<- Msel
(a, (x, y));
5353 G.postRedisplay "motion select";
5356 let y = min
conf.winh
(max
0 y) in
5360 let x = min
conf.winw (max
0 x) in
5363 | Mzoomrect
(p0
, _) ->
5364 state.mstate
<- Mzoomrect
(p0
, (x, y));
5365 G.postRedisplay "motion zoomrect";
5369 method pmotion x y =
5370 begin match state.mode with
5371 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5372 let rec loop = function
5374 if hooverpageno
!= -1
5376 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5377 G.postRedisplay "pmotion birdseye no hoover";
5380 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5381 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5383 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5384 G.postRedisplay "pmotion birdseye hoover";
5394 match state.mstate
with
5395 | Mnone
-> updateunder x y
5396 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5401 method infochanged
_ = ()
5404 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5405 let p, h = scrollph state.y maxy in
5409 let winw = conf.winw - state.scrollw
- 1 in
5410 let fwinw = float winw in
5412 let sw = fwinw /. float state.w in
5413 let sw = fwinw *. sw in
5414 max
sw (float conf.scrollh
)
5417 let f = state.w+winw in
5418 let r = float (winw-state.x) /. float f in
5419 let p = fwinw *. r in
5423 if position +. sw > fwinw
5424 then fwinw -. position
5427 state.hscrollh, position, sw
5431 match state.mode with
5432 | LinkNav
_ -> "links"
5433 | Textentry
_ -> "textentry"
5434 | Birdseye
_ -> "birdseye"
5437 findkeyhash conf modename
5444 let fontpath = ref "";;
5447 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5450 let l = String.length
s in
5451 let b = Buffer.create
l in
5457 try Sys.getenv
"HOME"
5460 ("Can not determine home directory location: " ^
5461 Printexc.to_string exn
);
5465 let modifier_of_string = function
5466 | "alt" -> Wsi.altmask
5467 | "shift" -> Wsi.shiftmask
5468 | "ctrl" | "control" -> Wsi.ctrlmask
5469 | "meta" -> Wsi.metamask
5474 let r = Str.regexp
"-" in
5476 let elems = Str.full_split
r s in
5479 let m1 = modifier_of_string s in
5481 then (Wsi.namekey
s, m)
5484 | Str.Delim
s when n land 1 = 0 -> g s
5486 | Str.Delim
_ -> (k
, m)
5488 let rec loop n k
m = function
5491 let k, m = f n k m x in
5497 let keys_of_string =
5498 let r = Str.regexp
"[ \t]" in
5500 let elems = Str.split
r s in
5501 List.map
key_of_string elems
5504 let copykeyhashes c =
5505 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5508 let config_of c attrs
=
5512 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5513 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5514 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5515 | "preload" -> { c with preload = bool_of_string
v }
5516 | "page-bias" -> { c with pagebias
= int_of_string
v }
5517 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5518 | "auto-scroll-step" ->
5519 { c with autoscrollstep
= max
0 (int_of_string
v) }
5520 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5521 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5524 match String.lowercase
v with
5525 | "true" -> Some infinity
5527 | f -> Some
(float_of_string
f)
5529 { c with maxwait
= mw}
5530 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5531 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5532 | "vertical-margin" ->
5533 { c with interpagespace = max
0 (int_of_string
v) }
5535 let zoom = float_of_string
v /. 100. in
5536 let zoom = max
zoom 0.0 in
5537 { c with zoom = zoom }
5538 | "presentation" -> { c with presentation = bool_of_string
v }
5539 | "rotation-angle" -> { c with angle
= int_of_string
v }
5540 | "width" -> { c with winw = max
20 (int_of_string
v) }
5541 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5542 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5543 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5544 | "pixmap-cache-size" ->
5545 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5546 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5547 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5548 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5549 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5550 | "background-color" -> { c with bgcolor
= color_of_string v }
5551 | "scrollbar-in-presentation" ->
5552 { c with scrollbarinpm
= bool_of_string
v }
5553 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5554 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5555 | "mupdf-store-size" ->
5556 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5557 | "checkers" -> { c with checkers
= bool_of_string
v }
5558 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5559 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5560 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5561 | "uri-launcher" -> { c with urilauncher
= unent v }
5562 | "path-launcher" -> { c with pathlauncher
= unent v }
5563 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5564 | "invert-colors" -> { c with invert
= bool_of_string
v }
5565 | "brightness" -> { c with colorscale
= float_of_string
v }
5566 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5568 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5570 let nab = columns_of_string v in
5571 { c with columns
= Some
(nab, [||]) }
5572 | "birds-eye-columns" ->
5573 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5574 | "selection-command" -> { c with selcmd
= unent v }
5575 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5578 prerr_endline
("Error processing attribute (`" ^
5579 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5582 let rec fold c = function
5585 let c = apply c k v in
5588 fold { c with keyhashes
= copykeyhashes c } attrs
;
5591 let fromstring f pos
n v d =
5594 dolog "Error processing attribute (%S=%S) at %d\n%s"
5595 n v pos
(Printexc.to_string exn
)
5600 let bookmark_of attrs
=
5601 let rec fold title page
rely = function
5602 | ("title", v) :: rest
-> fold v page
rely rest
5603 | ("page", v) :: rest
-> fold title v rely rest
5604 | ("rely", v) :: rest
-> fold title page
v rest
5605 | _ :: rest
-> fold title page
rely rest
5606 | [] -> title, page
, rely
5608 fold "invalid" "0" "0" attrs
5612 let rec fold path page
rely pan
= function
5613 | ("path", v) :: rest
-> fold v page
rely pan rest
5614 | ("page", v) :: rest
-> fold path v rely pan rest
5615 | ("rely", v) :: rest
-> fold path page
v pan rest
5616 | ("pan", v) :: rest
-> fold path page
rely v rest
5617 | _ :: rest
-> fold path page
rely pan rest
5618 | [] -> path, page
, rely, pan
5620 fold "" "0" "0" "0" attrs
5624 let rec fold rs ls
= function
5625 | ("out", v) :: rest
-> fold v ls rest
5626 | ("in", v) :: rest
-> fold rs
v rest
5627 | _ :: rest
-> fold ls rs rest
5633 let setconf dst
src =
5634 dst
.scrollbw
<- src.scrollbw
;
5635 dst
.scrollh
<- src.scrollh
;
5636 dst
.icase
<- src.icase
;
5637 dst
.preload <- src.preload;
5638 dst
.pagebias
<- src.pagebias
;
5639 dst
.verbose
<- src.verbose
;
5640 dst
.scrollstep
<- src.scrollstep
;
5641 dst
.maxhfit
<- src.maxhfit
;
5642 dst
.crophack
<- src.crophack
;
5643 dst
.autoscrollstep
<- src.autoscrollstep
;
5644 dst
.maxwait
<- src.maxwait
;
5645 dst
.hlinks
<- src.hlinks
;
5646 dst
.underinfo
<- src.underinfo
;
5647 dst
.interpagespace <- src.interpagespace;
5648 dst
.zoom <- src.zoom;
5649 dst
.presentation <- src.presentation;
5650 dst
.angle
<- src.angle
;
5651 dst
.winw <- src.winw;
5652 dst
.winh
<- src.winh
;
5653 dst
.savebmarks
<- src.savebmarks
;
5654 dst
.memlimit
<- src.memlimit
;
5655 dst
.proportional
<- src.proportional
;
5656 dst
.texcount
<- src.texcount
;
5657 dst
.sliceheight
<- src.sliceheight
;
5658 dst
.thumbw
<- src.thumbw
;
5659 dst
.jumpback
<- src.jumpback
;
5660 dst
.bgcolor
<- src.bgcolor
;
5661 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5662 dst
.tilew
<- src.tilew
;
5663 dst
.tileh
<- src.tileh
;
5664 dst
.mustoresize
<- src.mustoresize
;
5665 dst
.checkers
<- src.checkers
;
5666 dst
.aalevel
<- src.aalevel
;
5667 dst
.trimmargins
<- src.trimmargins
;
5668 dst
.trimfuzz
<- src.trimfuzz
;
5669 dst
.urilauncher
<- src.urilauncher
;
5670 dst
.colorspace
<- src.colorspace
;
5671 dst
.invert
<- src.invert
;
5672 dst
.colorscale
<- src.colorscale
;
5673 dst
.redirectstderr <- src.redirectstderr;
5674 dst
.ghyllscroll
<- src.ghyllscroll
;
5675 dst
.columns
<- src.columns
;
5676 dst
.beyecolumns
<- src.beyecolumns
;
5677 dst
.selcmd
<- src.selcmd
;
5678 dst
.updatecurs
<- src.updatecurs
;
5679 dst
.pathlauncher
<- src.pathlauncher
;
5680 dst
.keyhashes
<- copykeyhashes src;
5684 let h = Hashtbl.create
10 in
5685 let dc = { defconf with angle
= defconf.angle
} in
5686 let rec toplevel v t spos
_ =
5688 | Vdata
| Vcdata
| Vend
-> v
5689 | Vopen
("llppconfig", _, closed
) ->
5692 else { v with f = llppconfig
}
5694 error
"unexpected subelement at top level" s spos
5695 | Vclose
_ -> error
"unexpected close at top level" s spos
5697 and llppconfig
v t spos
_ =
5699 | Vdata
| Vcdata
-> v
5700 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5701 | Vopen
("defaults", attrs
, closed
) ->
5702 let c = config_of dc attrs
in
5706 else { v with f = defaults
}
5708 | Vopen
("ui-font", attrs
, closed
) ->
5709 let rec getsize size
= function
5711 | ("size", v) :: rest
->
5713 fromstring int_of_string spos
"size" v fstate.fontsize
in
5715 | l -> getsize size l
5717 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5720 else { v with f = uifont
(Buffer.create
10) }
5722 | Vopen
("doc", attrs
, closed
) ->
5723 let pathent, spage
, srely
, span
= doc_of attrs
in
5724 let path = unent pathent
5725 and pageno = fromstring int_of_string spos
"page" spage
0
5726 and rely = fromstring float_of_string spos
"rely" srely
0.0
5727 and pan
= fromstring int_of_string spos
"pan" span
0 in
5728 let c = config_of dc attrs
in
5729 let anchor = (pageno, rely) in
5731 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5732 else { v with f = doc
path pan
anchor c [] }
5735 error
"unexpected subelement in llppconfig" s spos
5737 | Vclose
"llppconfig" -> { v with f = toplevel }
5738 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5740 and defaults
v t spos
_ =
5742 | Vdata
| Vcdata
-> v
5743 | Vend
-> error
"unexpected end of input in defaults" s spos
5744 | Vopen
("keymap", attrs
, closed
) ->
5746 try List.assoc
"mode" attrs
5747 with Not_found
-> "global" in
5752 let h = findkeyhash dc modename in
5753 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5756 { v with f = pkeymap
ret KeyMap.empty }
5758 | Vopen
(_, _, _) ->
5759 error
"unexpected subelement in defaults" s spos
5761 | Vclose
"defaults" ->
5762 { v with f = llppconfig
}
5764 | Vclose
_ -> error
"unexpected close in defaults" s spos
5766 and uifont
b v t spos
epos =
5769 Buffer.add_substring
b s spos
(epos - spos
);
5771 | Vopen
(_, _, _) ->
5772 error
"unexpected subelement in ui-font" s spos
5773 | Vclose
"ui-font" ->
5774 if String.length
!fontpath = 0
5775 then fontpath := Buffer.contents
b;
5776 { v with f = llppconfig
}
5777 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5778 | Vend
-> error
"unexpected end of input in ui-font" s spos
5780 and doc
path pan
anchor c bookmarks
v t spos
_ =
5782 | Vdata
| Vcdata
-> v
5783 | Vend
-> error
"unexpected end of input in doc" s spos
5784 | Vopen
("bookmarks", _, closed
) ->
5787 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5789 | Vopen
("keymap", attrs
, closed
) ->
5791 try List.assoc
"mode" attrs
5792 with Not_found
-> "global"
5798 let h = findkeyhash c modename in
5799 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5800 doc
path pan
anchor c bookmarks
5802 { v with f = pkeymap
ret KeyMap.empty }
5804 | Vopen
(_, _, _) ->
5805 error
"unexpected subelement in doc" s spos
5808 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5809 { v with f = llppconfig
}
5811 | Vclose
_ -> error
"unexpected close in doc" s spos
5813 and pkeymap
ret keymap
v t spos
_ =
5815 | Vdata
| Vcdata
-> v
5816 | Vend
-> error
"unexpected end of input in keymap" s spos
5817 | Vopen
("map", attrs
, closed
) ->
5818 let r, l = map_of attrs
in
5819 let kss = fromstring keys_of_string spos
"in" r [] in
5820 let lss = fromstring keys_of_string spos
"out" l [] in
5824 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5825 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5828 then { v with f = pkeymap
ret keymap }
5831 { v with f = skip
"map" f }
5834 error
"unexpected subelement in keymap" s spos
5836 | Vclose
"keymap" ->
5837 { v with f = ret keymap }
5839 | Vclose
_ -> error
"unexpected close in keymap" s spos
5841 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5843 | Vdata
| Vcdata
-> v
5844 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5845 | Vopen
("item", attrs
, closed
) ->
5846 let titleent, spage
, srely
= bookmark_of attrs
in
5847 let page = fromstring int_of_string spos
"page" spage
0
5848 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5849 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5851 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5854 { v with f = skip
"item" f }
5857 error
"unexpected subelement in bookmarks" s spos
5859 | Vclose
"bookmarks" ->
5860 { v with f = doc
path pan
anchor c bookmarks }
5862 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5864 and skip tag
f v t spos
_ =
5866 | Vdata
| Vcdata
-> v
5868 error
("unexpected end of input in skipped " ^ tag
) s spos
5869 | Vopen
(tag'
, _, closed
) ->
5873 let f'
() = { v with f = skip tag
f } in
5874 { v with f = skip tag'
f'
}
5878 else error
("unexpected close in skipped " ^ tag
) s spos
5881 parse
{ f = toplevel; accu = () } s;
5887 let len = in_channel_length ic
in
5888 let s = String.create
len in
5889 really_input ic
s 0 len;
5892 | Parse_error
(msg
, s, pos
) ->
5893 let subs = subs s pos
in
5894 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5895 failwith
("parse error: " ^
s)
5898 failwith
("config load error: " ^
Printexc.to_string exn
)
5904 let dir = Filename.concat
home ".config" in
5905 if Sys.is_directory
dir then dir else home
5908 Filename.concat
dir "llpp.conf"
5911 let confpath = ref defconfpath;;
5914 if Sys.file_exists
!confpath
5917 (try Some
(open_in_bin
!confpath)
5920 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5921 Printexc.to_string exn
);
5930 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5931 Printexc.to_string exn
);
5937 f (Hashtbl.create
0, defconf)
5942 let pc, pb
, px, pa
=
5944 Hashtbl.find h (Filename.basename
state.path)
5945 with Not_found
-> dc, [], 0, (0, 0.0)
5949 state.bookmarks <- pb
;
5951 state.scrollw
<- conf.scrollbw
;
5953 then state.anchor <- pa
;
5954 cbput state.hists
.nav pa
;
5959 let add_attrs bb always
dc c =
5962 then Printf.bprintf bb
"\n %s='%b'" s a
5965 then Printf.bprintf bb
"\n %s='%d'" s a
5968 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5971 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5974 then Printf.bprintf bb
"\n %s='%f'" s a
5978 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5982 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5986 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5990 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5996 | Some
(_N
, _A
, _B
) ->
5997 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6007 else string_of_float
f
6009 Printf.bprintf bb
"\n %s='%s'" s v
6014 | Some
((n, a, b), _) when n > 1 ->
6015 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6021 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6026 then dc.winw, dc.winh
6028 match state.fullscreen
with
6030 | None
-> c.winw, c.winh
6032 let zoom, presentation, interpagespace, maxwait
=
6034 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6036 match state.mode with
6037 | Birdseye
(bc
, _, _, _, _) ->
6038 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6039 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6041 oi
"width" w dc.winw;
6042 oi
"height" h dc.winh
;
6043 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6044 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6045 ob "case-insensitive-search" c.icase
dc.icase
;
6046 ob "preload" c.preload dc.preload;
6047 oi
"page-bias" c.pagebias
dc.pagebias
;
6048 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6049 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6050 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6051 ob "crop-hack" c.crophack
dc.crophack
;
6052 oW
"throttle" maxwait
dc.maxwait
;
6053 ob "highlight-links" c.hlinks
dc.hlinks
;
6054 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6055 oi
"vertical-margin" interpagespace dc.interpagespace;
6056 oz
"zoom" zoom dc.zoom;
6057 ob "presentation" presentation dc.presentation;
6058 oi
"rotation-angle" c.angle
dc.angle
;
6059 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6060 ob "proportional-display" c.proportional
dc.proportional
;
6061 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6062 oi
"tex-count" c.texcount
dc.texcount
;
6063 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6064 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6065 ob "persistent-location" c.jumpback
dc.jumpback
;
6066 oc
"background-color" c.bgcolor
dc.bgcolor
;
6067 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6068 oi
"tile-width" c.tilew
dc.tilew
;
6069 oi
"tile-height" c.tileh
dc.tileh
;
6070 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6071 ob "checkers" c.checkers
dc.checkers
;
6072 oi
"aalevel" c.aalevel
dc.aalevel
;
6073 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6074 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6075 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6076 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6077 oC
"color-space" c.colorspace
dc.colorspace
;
6078 ob "invert-colors" c.invert
dc.invert
;
6079 oF
"brightness" c.colorscale
dc.colorscale
;
6080 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6081 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6082 oco
"columns" c.columns
dc.columns
;
6083 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6084 os
"selection-command" c.selcmd
dc.selcmd
;
6085 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6088 let keymapsbuf always
dc c =
6089 let bb = Buffer.create
16 in
6090 let rec loop = function
6092 | (modename, h) :: rest
->
6093 let dh = findkeyhash dc modename in
6094 if always
|| h <> dh
6096 if Hashtbl.length
h > 0
6098 if Buffer.length
bb > 0
6099 then Buffer.add_char
bb '
\n'
;
6100 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6101 Hashtbl.iter
(fun i
o ->
6102 let isdifferent = always
||
6104 let dO = Hashtbl.find dh i
in
6106 with Not_found
-> true
6111 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6112 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6113 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6114 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6115 Buffer.add_string
bb (Wsi.keyname
k);
6118 let rec loop = function
6120 | km
:: [] -> addkm km
6121 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6125 Buffer.add_string
bb "<map in='";
6129 Buffer.add_string
bb "' out='";
6131 Buffer.add_string
bb "'/>\n"
6134 Buffer.add_string
bb "' out='";
6136 Buffer.add_string
bb "'/>\n"
6138 | KMmulti
(ins, kms
) ->
6139 Buffer.add_char
bb ' '
;
6141 Buffer.add_string
bb "' out='";
6143 Buffer.add_string
bb "'/>\n"
6145 Buffer.add_string
bb "</keymap>";
6155 let uifontsize = fstate.fontsize
in
6156 let bb = Buffer.create
32768 in
6158 let dc = if conf.bedefault
then conf else dc in
6159 Buffer.add_string
bb "<llppconfig>\n";
6161 if String.length
!fontpath > 0
6163 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6169 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6172 Buffer.add_string
bb "<defaults ";
6173 add_attrs bb true dc dc;
6174 let kb = keymapsbuf true dc dc in
6175 if Buffer.length
kb > 0
6177 Buffer.add_string
bb ">\n";
6178 Buffer.add_buffer
bb kb;
6179 Buffer.add_string
bb "\n</defaults>\n";
6181 else Buffer.add_string
bb "/>\n";
6183 let adddoc path pan
anchor c bookmarks =
6184 if bookmarks == [] && c = dc && anchor = emptyanchor
6187 Printf.bprintf
bb "<doc path='%s'"
6188 (enent
path 0 (String.length
path));
6190 if anchor <> emptyanchor
6192 let n, y = anchor in
6193 Printf.bprintf
bb " page='%d'" n;
6196 Printf.bprintf
bb " rely='%f'" y
6201 then Printf.bprintf
bb " pan='%d'" pan
;
6203 add_attrs bb false dc c;
6204 let kb = keymapsbuf false dc c in
6206 begin match bookmarks with
6208 if Buffer.length
kb > 0
6210 Buffer.add_string
bb ">\n";
6211 Buffer.add_buffer
bb kb;
6212 Buffer.add_string
bb "</doc>\n";
6214 else Buffer.add_string
bb "/>\n"
6216 Buffer.add_string
bb ">\n<bookmarks>\n";
6217 List.iter
(fun (title, _level
, (page, rely)) ->
6219 "<item title='%s' page='%d'"
6220 (enent
title 0 (String.length
title))
6225 Printf.bprintf
bb " rely='%f'" rely
6227 Buffer.add_string
bb "/>\n";
6229 Buffer.add_string
bb "</bookmarks>";
6230 if Buffer.length
kb > 0
6232 Buffer.add_string
bb "\n";
6233 Buffer.add_buffer
bb kb;
6235 Buffer.add_string
bb "\n</doc>\n";
6241 match state.mode with
6242 | Birdseye
(c, pan, _, _, _) ->
6244 match conf.columns
with
6245 | Some
((c, _, _), _) -> Some
c
6248 match c.columns
with
6249 | Some
(c, _) -> Some
(c, [||])
6252 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6253 | _ -> state.x, conf
6255 let basename = Filename.basename state.path in
6256 adddoc basename pan (getanchor ())
6259 match state.autoscroll
with
6261 | None
-> conf.autoscrollstep
}
6262 (if conf.savebmarks
then state.bookmarks else []);
6264 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6266 then adddoc path x y c bookmarks
6268 Buffer.add_string
bb "</llppconfig>";
6271 if Buffer.length
bb > 0
6274 let tmp = !confpath ^
".tmp" in
6275 let oc = open_out_bin
tmp in
6276 Buffer.output_buffer
oc bb;
6278 Unix.rename
tmp !confpath;
6281 ("error while saving configuration: " ^
Printexc.to_string exn
)
6288 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6289 "<password> Set password");
6291 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6292 "<path> Set path to the user interface font");
6294 ("-c", Arg.String
(fun s -> Config.confpath := s),
6295 "<path> Set path to the configuration file");
6297 ("-v", Arg.Unit
(fun () ->
6299 "%s\nconfiguration path: %s\n"
6303 exit
0), " Print version and exit");
6306 (fun s -> state.path <- s)
6307 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6309 if String.length
state.path = 0
6310 then (prerr_endline
"file name missing"; exit
1);
6314 let globalkeyhash = findkeyhash conf "global" in
6315 state.wsfd
<- Wsi.init
(object
6317 if nogeomcmds state.geomcmds
6319 method display = display ()
6320 method reshape w h = reshape w h
6321 method mouse b d x y m = mouse b d x y m
6322 method motion x y = state.mpos
<- (x, y); motion x y
6323 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6325 match state.keystate
with
6330 try Hashtbl.find globalkeyhash km
6332 let modehash = state.uioh#
modehash in
6333 try Hashtbl.find modehash km
6334 with Not_found
-> KMinsrt
(k, m)
6336 | KMinsrt
(k, m) -> keyboard k m
6337 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6338 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6340 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land m = m'
->
6341 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6342 state.keystate
<- KSnone
6343 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land m = m'
->
6344 state.keystate
<- KSinto
(keys
, insrt
)
6346 state.keystate
<- KSnone
6348 method enter
x y = state.mpos
<- (x, y); pmotion x y
6349 method leave = state.mpos
<- (-1, -1)
6350 method quit
= raise Quit
6351 end) conf.winw conf.winh
;
6354 List.exists
GlMisc.check_extension
6355 [ "GL_ARB_texture_rectangle"
6356 ; "GL_EXT_texture_recangle"
6357 ; "GL_NV_texture_rectangle" ]
6359 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6361 let cr, sw = Unix.pipe
()
6362 and sr
, cw
= Unix.pipe
() in
6369 setcheckers conf.checkers
;
6373 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6374 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6379 state.text <- "Opening " ^
state.path;
6380 opendoc state.path state.password
;
6382 setfontsize fstate.fontsize
;
6383 doreshape conf.winw conf.winh
;
6385 let rec loop deadline
=
6387 match state.errfd
with
6388 | None
-> [state.sr
; state.wsfd
]
6389 | Some fd
-> [state.sr
; state.wsfd
; fd
]
6393 state.redisplay
<- false;
6400 if deadline
= infinity
6402 else max
0.0 (deadline
-. now)
6407 try Unix.select
r [] [] timeout
6408 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6414 if state.ghyll
== noghyll
6416 match state.autoscroll
with
6417 | Some step
when step
!= 0 ->
6418 let y = state.y + step
in
6422 else if y >= state.maxy then 0 else y
6425 if state.mode = View
6426 then state.text <- "";
6429 else deadline
+. 0.01
6434 let rec checkfds = function
6436 | fd
:: rest
when fd
= state.sr
->
6437 let cmd = readcmd state.sr
in
6441 | fd
:: rest
when fd
= state.wsfd
->
6446 let s = String.create
80 in
6447 let n = Unix.read fd
s 0 80 in
6448 if conf.redirectstderr
6450 Buffer.add_substring
state.errmsgs
s 0 n;
6451 state.newerrmsgs
<- true;
6452 state.redisplay
<- true;
6455 prerr_string
(String.sub
s 0 n);
6463 if deadline
= infinity
6467 match state.autoscroll
with
6468 | Some step
when step
!= 0 -> deadline1
6469 | _ -> if state.ghyll
== noghyll then infinity
else deadline1