6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
45 | Lfound
of (int * int * int * int * int)
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: string -> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
87 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
88 external platform
: unit -> platform
= "ml_platform";;
89 external setaalevel
: int -> unit = "ml_setaalevel";;
90 external realloctexts
: int -> bool = "ml_realloctexts";;
91 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
92 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
93 external getlink
: opaque
-> int -> under
= "ml_getlink";;
94 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
96 let platform_to_string = function
97 | Punknown
-> "unknown"
101 | Pfreebsd
-> "FreeBSD"
102 | Pdragonflybsd
-> "DragonflyBSD"
103 | Popenbsd
-> "OpenBSD"
104 | Pnetbsd
-> "NetBSD"
105 | Pcygwin
-> "Cygwin"
108 let platform = platform ();;
114 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
117 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
119 type mpos
= int * int
121 | Msel
of (mpos
* mpos
)
123 | Mscrolly
| Mscrollx
124 | Mzoom
of (int * int)
125 | Mzoomrect
of (mpos
* mpos
)
129 type textentry
= string * string * onhist
option * onkey
* ondone
130 and onkey
= string -> int -> te
131 and ondone
= string -> unit
132 and histcancel
= unit -> unit
133 and onhist
= ((histcmd
-> string) * histcancel
)
134 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
139 | TEswitch
of textentry
150 let bound v minv maxv
=
151 max minv
(min maxv v
);
155 { store
= Array.create n v
162 let drawstring size x y s
=
164 Gl.enable `texture_2d
;
165 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
166 ignore
(drawstr size x y s
);
168 Gl.disable `texture_2d
;
171 let drawstring1 size x y s
=
175 let drawstring2 size x y fmt
=
176 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
179 let cbcap b
= Array.length b
.store
;;
184 b
.wc
<- (b
.wc
+ 1) mod cap;
186 b
.len
<- min
(b
.len
+ 1) cap;
189 let cbempty b
= b
.len
= 0;;
191 let cbgetg b circular dir
=
195 let rc = b
.rc + dir
in
207 else max
0 (min
rc (b
.len
-1))
213 let cbget b
= cbgetg b
false;;
214 let cbgetc b
= cbgetg b
true;;
231 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
232 dolog " WxH %dx%d" l
.pagew l
.pageh
;
233 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
234 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
235 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
239 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
241 dolog " x0,y0=(% f, % f)" x0 y0
;
242 dolog " x1,y1=(% f, % f)" x1 y1
;
243 dolog " x2,y2=(% f, % f)" x2 y2
;
244 dolog " x3,y3=(% f, % f)" x3 y3
;
249 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
250 and multicol
= columncount
* covercount
* covercount
252 and columncount
= int
253 and covercount
= int;;
256 { mutable scrollbw
: int
257 ; mutable scrollh
: int
258 ; mutable icase
: bool
259 ; mutable preload
: bool
260 ; mutable pagebias
: int
261 ; mutable verbose
: bool
262 ; mutable debug
: bool
263 ; mutable scrollstep
: int
264 ; mutable maxhfit
: bool
265 ; mutable crophack
: bool
266 ; mutable autoscrollstep
: int
267 ; mutable maxwait
: float option
268 ; mutable hlinks
: bool
269 ; mutable underinfo
: bool
270 ; mutable interpagespace
: interpagespace
271 ; mutable zoom
: float
272 ; mutable presentation
: bool
273 ; mutable angle
: angle
276 ; mutable savebmarks
: bool
277 ; mutable proportional
: proportional
278 ; mutable trimmargins
: trimmargins
279 ; mutable trimfuzz
: irect
280 ; mutable memlimit
: memsize
281 ; mutable texcount
: texcount
282 ; mutable sliceheight
: sliceheight
283 ; mutable thumbw
: width
284 ; mutable jumpback
: bool
285 ; mutable bgcolor
: float * float * float
286 ; mutable bedefault
: bool
287 ; mutable scrollbarinpm
: bool
288 ; mutable tilew
: int
289 ; mutable tileh
: int
290 ; mutable mustoresize
: memsize
291 ; mutable checkers
: bool
292 ; mutable aalevel
: int
293 ; mutable urilauncher
: string
294 ; mutable pathlauncher
: string
295 ; mutable colorspace
: colorspace
296 ; mutable invert
: bool
297 ; mutable colorscale
: float
298 ; mutable redirectstderr
: bool
299 ; mutable ghyllscroll
: (int * int * int) option
300 ; mutable columns
: columns
option
301 ; mutable beyecolumns
: columncount
option
302 ; mutable selcmd
: string
303 ; mutable updatecurs
: bool
304 ; mutable keyhashes
: (string * keyhash
) list
308 type anchor
= pageno
* top
;;
310 type outline
= string * int * anchor
;;
312 type rect
= float * float * float * float * float * float * float * float;;
314 type tile
= opaque
* pixmapsize
* elapsed
315 and elapsed
= float;;
316 type pagemapkey
= pageno
* gen
;;
317 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
321 let emptyanchor = (0, 0.0);;
323 type infochange
= | Memused
| Docinfo
| Pdim
;;
325 class type uioh
= object
326 method display
: unit
327 method key
: int -> int -> uioh
328 method button
: int -> bool -> int -> int -> int -> uioh
329 method motion
: int -> int -> uioh
330 method pmotion
: int -> int -> uioh
331 method infochanged
: infochange
-> unit
332 method scrollpw
: (int * float * float)
333 method scrollph
: (int * float * float)
334 method modehash
: keyhash
338 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
339 | Textentry
of (textentry
* onleave
)
341 | LinkNav
of linktarget
342 and onleave
= leavetextentrystatus
-> unit
343 and leavetextentrystatus
= | Cancel
| Confirm
344 and helpitem
= string * int * action
347 | Action
of (uioh
-> uioh
)
349 | Ltexact
of ((pageno
* int) * (int * int * int * int))
353 let isbirdseye = function Birdseye _
-> true | _
-> false;;
354 let istextentry = function Textentry _
-> true | _
-> false;;
358 | Loading
of (page
* gen
)
360 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
362 | Outlining
of outline list
365 let emptykeyhash = Hashtbl.create
0;;
366 let nouioh : uioh
= object (self
)
368 method key _ _
= self
369 method button _ _ _ _ _
= self
370 method motion _ _
= self
371 method pmotion _ _
= self
372 method infochanged _
= ()
373 method scrollpw
= (0, nan
, nan
)
374 method scrollph
= (0, nan
, nan
)
375 method modehash
= emptykeyhash
379 { mutable sr
: Unix.file_descr
380 ; mutable sw
: Unix.file_descr
381 ; mutable wsfd
: Unix.file_descr
382 ; mutable errfd
: Unix.file_descr
option
383 ; mutable stderr
: Unix.file_descr
384 ; mutable errmsgs
: Buffer.t
385 ; mutable newerrmsgs
: bool
389 ; mutable scrollw
: int
390 ; mutable hscrollh
: int
391 ; mutable anchor
: anchor
392 ; mutable ranchors
: (string * string * anchor
) list
394 ; mutable layout
: page list
395 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
396 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
397 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
398 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
399 ; mutable pagecount
: int
400 ; mutable currently
: currently
401 ; mutable mstate
: mstate
402 ; mutable searchpattern
: string
403 ; mutable rects
: (pageno
* recttype
* rect
) list
404 ; mutable rects1
: (pageno
* recttype
* rect
) list
405 ; mutable text
: string
406 ; mutable fullscreen
: (width
* height
) option
407 ; mutable mode
: mode
408 ; mutable uioh
: uioh
409 ; mutable outlines
: outline array
410 ; mutable bookmarks
: outline list
411 ; mutable path
: string
412 ; mutable password
: string
413 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
414 ; mutable memused
: memsize
416 ; mutable throttle
: (page list
* int * float) option
417 ; mutable autoscroll
: int option
418 ; mutable ghyll
: (int option -> unit)
419 ; mutable help
: helpitem array
420 ; mutable docinfo
: (int * string) list
421 ; mutable texid
: GlTex.texture_id
option
423 ; mutable prevzoom
: float
424 ; mutable progress
: float
425 ; mutable redisplay
: bool
426 ; mutable mpos
: mpos
427 ; mutable keystate
: keystate
430 { pat
: string circbuf
431 ; pag
: string circbuf
432 ; nav
: anchor circbuf
433 ; sel
: string circbuf
454 ; presentation
= false
459 ; proportional
= true
460 ; trimmargins
= false
461 ; trimfuzz
= (0,0,0,0)
462 ; memlimit
= 32 lsl 20
467 ; bgcolor
= (0.5, 0.5, 0.5)
469 ; scrollbarinpm
= true
472 ; mustoresize
= 128 lsl 20
477 | Plinux
| Pfreebsd
| Pdragonflybsd
478 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
479 | Posx
-> "open \"%s\""
480 | Pcygwin
-> "cygstart %s"
481 | Punknown
-> "echo %s")
482 ; pathlauncher
= "lp \"%s\""
485 | Plinux
| Pfreebsd
| Pdragonflybsd
486 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
493 ; redirectstderr
= false
499 let mk n
= (n
, Hashtbl.create
1) in
512 let findkeyhash c name
=
513 try List.assoc name c
.keyhashes
514 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
517 let conf = { defconf with angle
= defconf.angle
};;
520 { mutable fontsize
: int
521 ; mutable wwidth
: float
522 ; mutable maxrows
: int
534 fstate.fontsize
<- n
;
535 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
536 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
540 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
541 let len = String.length s
in
542 if colonpos >= 0 && colonpos + 3 < len
544 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
547 try String.rindex_from s
colonpos ' '
551 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
554 | "http" | "ftp" | "mailto" ->
556 try String.index_from s
colonpos ' '
557 with Not_found
-> len
559 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
567 let shell, farg
= "/bin/sh", "-c" in
569 let args = [|shell; farg
; s
|] in
570 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
574 if String.length
conf.urilauncher
= 0
575 then print_endline uri
577 let url = geturl uri
in
578 if String.length
url = 0
579 then print_endline uri
581 let re = Str.regexp
"%s" in
582 let command = Str.global_replace
re url conf.urilauncher
in
586 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
592 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
593 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
597 let strings = version () :: "" :: Help.keys
in
600 let url = geturl s
in
601 if String.length
url > 0
602 then (s
, 0, Action
(fun u
-> gotouri url; u
))
603 else (s
, 0, Noaction
)
608 let firstgeomcmds = "", [];;
615 ; stderr
= Unix.stderr
616 ; errmsgs
= Buffer.create
0
623 ; anchor
= emptyanchor
627 ; tilelru
= Queue.create
()
628 ; pagemap
= Hashtbl.create
10
629 ; tilemap
= Hashtbl.create
10
644 ; geomcmds
= firstgeomcmds
646 { nav
= cbnew 10 (0, 0.0)
671 Printf.kprintf prerr_endline fmt
673 Printf.kprintf ignore fmt
677 if String.length
conf.pathlauncher
= 0
678 then print_endline
state.path
680 let re = Str.regexp
"%s" in
681 let command = Str.global_replace
re state.path
conf.pathlauncher
in
685 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
690 let redirectstderr () =
691 if conf.redirectstderr
693 let rfd, wfd
= Unix.pipe
() in
694 state.stderr
<- Unix.dup
Unix.stderr
;
695 state.errfd
<- Some
rfd;
696 Unix.dup2 wfd
Unix.stderr
;
698 state.newerrmsgs
<- false;
699 begin match state.errfd
with
702 Unix.dup2
state.stderr
Unix.stderr
;
706 prerr_string
(Buffer.contents
state.errmsgs
);
708 Buffer.clear
state.errmsgs
;
714 let postRedisplay who
=
716 then prerr_endline
("redisplay for " ^ who
);
717 state.redisplay
<- true;
721 let getopaque pageno
=
722 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
723 with Not_found
-> None
726 let putopaque pageno opaque
=
727 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
730 let pagetranslatepoint l x y
=
731 let dy = y
- l
.pagedispy
in
732 let y = dy + l
.pagey
in
733 let dx = x
- l
.pagedispx
in
734 let x = dx + l
.pagex
in
741 begin match getopaque l
.pageno
with
743 let x0 = l
.pagedispx
in
744 let x1 = x0 + l
.pagevw
in
745 let y0 = l
.pagedispy
in
746 let y1 = y0 + l
.pagevh
in
747 if y >= y0 && y <= y1 && x >= x0 && x <= x1
749 let px, py
= pagetranslatepoint l
x y in
750 match whatsunder opaque
px py
with
763 state.text
<- Printf.sprintf
"%c%s" c s
;
764 G.postRedisplay "showtext";
767 let updateunder x y =
768 match getunder x y with
769 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
771 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
772 Wsi.setcursor
Wsi.CURSOR_INFO
773 | Ulinkgoto
(page
, _
) ->
775 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
776 Wsi.setcursor
Wsi.CURSOR_INFO
778 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
779 Wsi.setcursor
Wsi.CURSOR_TEXT
781 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
782 Wsi.setcursor
Wsi.CURSOR_INHERIT
784 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
785 Wsi.setcursor
Wsi.CURSOR_INHERIT
787 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
788 Wsi.setcursor
Wsi.CURSOR_INHERIT
789 | Uremote
(filename
, pageno
) ->
790 if conf.underinfo
then showtext 'r'
791 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
792 Wsi.setcursor
Wsi.CURSOR_INFO
795 let showlinktype under
=
801 showtext 'u'
("ri: " ^ uri
)
802 | Ulinkgoto
(page
, _
) ->
803 showtext 'p'
("age: " ^ string_of_int
(page
+1));
805 showtext '
f'
("ont: " ^ s
);
807 showtext 'u'
("nexpected: " ^ s
);
809 showtext 'l'
("aunch: " ^ s
);
811 showtext 'n'
("amed: " ^ s
);
812 | Uremote
(filename
, pageno
) ->
813 showtext 'r'
(Printf.sprintf
"emote: %s (%d)" filename pageno
);
817 let b = Buffer.create
(String.length s
+ 1) in
818 Buffer.add_string
b s
;
823 let colorspace_of_string s
=
824 match String.lowercase s
with
828 | _
-> failwith
"invalid colorspace"
831 let int_of_colorspace = function
837 let colorspace_of_int = function
841 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
844 let colorspace_to_string = function
850 let intentry_with_suffix text key
=
852 if key
>= 32 && key
< 127
856 match Char.lowercase
c with
858 let text = addchar text c in
862 let text = addchar text c in
866 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
870 let columns_to_string (n
, a
, b) =
872 then Printf.sprintf
"%d" n
873 else Printf.sprintf
"%d,%d,%d" n a
b;
876 let columns_of_string s
=
878 (int_of_string s
, 0, 0)
880 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
885 let n = Unix.read fd
s 0 4 in
886 if n != 4 then failwith
"incomplete read(len)";
888 lor (Char.code
s.[0] lsl 24)
889 lor (Char.code
s.[1] lsl 16)
890 lor (Char.code
s.[2] lsl 8)
891 lor (Char.code
s.[3] lsl 0)
893 let s = String.create
len in
894 let n = Unix.read fd
s 0 len in
895 if n != len then failwith
"incomplete read(data)";
899 let btod b = if b then 1 else 0;;
902 let b = Buffer.create
16 in
903 Buffer.add_string
b "llll";
906 let s = Buffer.contents
b in
907 let n = String.length
s in
909 (* dolog "wcmd %S" (String.sub s 4 len); *)
910 s.[0] <- Char.chr
((len lsr 24) land 0xff);
911 s.[1] <- Char.chr
((len lsr 16) land 0xff);
912 s.[2] <- Char.chr
((len lsr 8) land 0xff);
913 s.[3] <- Char.chr
(len land 0xff);
914 let n'
= Unix.write
state.sw
s 0 n in
915 if n'
!= n then failwith
"write failed";
922 let d = conf.winh
- h
in
929 let rec f pn ph pi fh l
=
931 | (n, _
, h
, _
) :: rest
->
932 let ips = calcips h
in
937 if isbirdseye state.mode
&& pn
= 0
942 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
947 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
951 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
954 let fh = f 0 0 0 0 state.pdims
in
959 match conf.columns
with
960 | None
-> calcheight ()
962 if Array.length
b > 0
964 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
969 let getpageyh pageno
=
970 let rec f pn ph pi
y l
=
972 | (n, _
, h
, _
) :: rest
->
973 let ips = calcips h
in
976 let h = if n = pageno
then h else ph
in
977 if conf.presentation
&& n = pageno
979 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
981 y + (pageno
- pn
) * (ph
+ pi
), h
983 let y = y + (if conf.presentation
then pi
else 0) in
984 let y = y + (n - pn
) * (ph
+ pi
) in
988 y + (pageno
- pn
) * (ph
+ pi
), ph
990 f 0 0 0 0 state.pdims
993 let getpageyh pageno
=
994 match conf.columns
with
995 | None
-> getpageyh pageno
997 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1001 let getpagedim pageno
=
1004 | (n, _
, _
, _
) as pdim
:: rest
->
1006 then (if n = pageno
then pdim
else ppdim
)
1011 f (-1, -1, -1, -1) state.pdims
1014 let getpagey pageno
= fst
(getpageyh pageno
);;
1016 let nogeomcmds cmds
=
1018 | s, [] -> String.length
s = 0
1023 let sh = sh - state.hscrollh
in
1024 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1025 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1027 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1028 let ips = calcips h in
1030 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1034 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1036 prev
, pdims
, pdimno
, 0
1038 let dy = dy + yinc in
1039 let py = py + yinc in
1040 if pageno
= state.pagecount
|| dy >= sh
1045 if py + h <= vy - yinc
1047 let py = py + h + ips in
1048 let dy = max
0 (py - y) in
1049 f ~pageno
:(pageno
+1)
1057 let pagey = vy - py in
1058 let pagevh = h - pagey in
1059 let pagevh = min
(sh - dy) pagevh in
1060 let off = if yinc > 0 then py - vy else 0 in
1061 let py = py + h + ips in
1064 if state.w
< conf.winw
- state.scrollw
1065 then (conf.winw
- state.scrollw
- state.w
) / 2
1068 let dispx = xoff + state.x in
1074 let lw = w
- pagex in
1075 min
lw (conf.winw
- state.scrollw
)
1079 ; pagedimno
= pdimno
1083 ; pagey = pagey + off
1085 ; pagevh = pagevh - off
1087 ; pagedispy
= dy + off
1090 let accu = e :: accu in
1091 f ~pageno
:(pageno
+1)
1099 if nogeomcmds state.geomcmds
1117 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1118 let sh = sh - state.hscrollh
in
1119 let rec fold accu n =
1120 if n = Array.length
b
1123 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1126 || n = state.pagecount
- coverB
1127 || (n - coverA
) mod columns
= columns
- 1)
1133 let pagey = max
0 (y - vy) in
1134 let pagedispy = if pagey > 0 then 0 else vy - y in
1135 let pagedispx, pagex, pagevw =
1137 if n = coverA
- 1 || n = state.pagecount
- coverB
1138 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1139 else dx + xoff + state.x
1142 then 0, -pdx, w
+ pdx
1143 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1145 let pagevh = min
(h - pagey) (sh - pagedispy) in
1146 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1150 ; pagedimno
= pdimno
1157 ; pagedispx = pagedispx
1158 ; pagedispy = pagedispy
1169 if nogeomcmds state.geomcmds
1170 then List.rev
(fold [] 0)
1175 match conf.columns
with
1176 | None
-> layout1 y sh
1177 | Some
c -> layoutN c y sh
1181 let y = state.y + incr
in
1183 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1188 let tilex = l
.pagex mod conf.tilew
in
1189 let tiley = l
.pagey mod conf.tileh
in
1191 let col = l
.pagex / conf.tilew
in
1192 let row = l
.pagey / conf.tileh
in
1195 let a = l
.pagew
- l
.pagex in
1196 let b = conf.winw
- state.scrollw
in
1198 and vh
= l
.pagevh in
1200 let rec rowloop row y0 dispy
h =
1204 let dh = conf.tileh
- y0 in
1205 let dh = min
h dh in
1206 let rec colloop col x0 dispx w
=
1210 let dw = conf.tilew
- x0 in
1211 let dw = min w
dw in
1213 f col row dispx dispy
x0 y0 dw dh;
1214 colloop (col+1) 0 (dispx+dw) (w
-dw)
1217 colloop col tilex l
.pagedispx vw;
1218 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1222 then rowloop row tiley l
.pagedispy vh
;
1225 let gettileopaque l
col row =
1227 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1229 try Some
(Hashtbl.find
state.tilemap
key)
1230 with Not_found
-> None
1233 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1234 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1235 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1238 let drawtiles l color
=
1240 let f col row x y tilex tiley w
h =
1241 match gettileopaque l
col row with
1242 | Some
(opaque
, _
, t
) ->
1243 let params = x, y, w
, h, tilex, tiley in
1247 GlFunc.blend_func `zero `one_minus_src_color
;
1249 drawtile
params opaque
;
1251 then Gl.disable `blend
;
1254 let s = Printf.sprintf
1258 let w = measurestr
fstate.fontsize
s in
1259 GlMisc.push_attrib
[`current
];
1260 GlDraw.color
(0.0, 0.0, 0.0);
1262 (float (x-2), float (y-2))
1263 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1264 GlDraw.color
(1.0, 1.0, 1.0);
1265 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1266 GlMisc.pop_attrib
();
1271 let lw = conf.winw
- state.scrollw
- x in
1274 let lh = conf.winh
- y in
1277 Gl.enable `texture_2d
;
1278 begin match state.texid
with
1280 GlTex.bind_texture `texture_2d id
;
1283 and x1 = float (x+w)
1284 and y1 = float (y+h) in
1286 let tw = float w /. 64.0
1287 and th
= float h /. 64.0 in
1288 let tx0 = float tilex /. 64.0
1289 and ty0
= float tiley /. 64.0 in
1291 and ty1
= ty0
+. th
in
1292 GlDraw.begins `quads
;
1293 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1294 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1295 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1296 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1299 Gl.disable `texture_2d
;
1301 GlDraw.color
(1.0, 1.0, 1.0);
1304 (float (x+w), float (y+h));
1306 if w > 128 && h > fstate.fontsize
+ 10
1308 GlDraw.color
(0.0, 0.0, 0.0);
1311 then (col*conf.tilew
, row*conf.tileh
)
1314 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1321 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1323 let tilevisible1 l
x y =
1325 and ax1
= l
.pagex + l
.pagevw
1327 and ay1
= l
.pagey + l
.pagevh in
1331 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1332 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1334 let rx0 = max
ax0 bx0
1335 and ry0
= max ay0 by0
1336 and rx1
= min ax1
bx1
1337 and ry1
= min ay1 by1
in
1339 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1340 nonemptyintersection
1343 let tilevisible layout n x y =
1344 let rec findpageinlayout = function
1345 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1346 | _
:: rest
-> findpageinlayout rest
1349 findpageinlayout layout
1352 let tileready l
x y =
1353 tilevisible1 l
x y &&
1354 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1357 let tilepage n p
layout =
1358 let rec loop = function
1362 let f col row _ _ _ _ _ _
=
1363 if state.currently
= Idle
1365 match gettileopaque l
col row with
1368 let x = col*conf.tilew
1369 and y = row*conf.tileh
in
1371 let w = l
.pagew
- x in
1375 let h = l
.pageh
- y in
1378 wcmd "tile %s %d %d %d %d" p
x y w h;
1381 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1382 conf.tilew
, conf.tileh
1391 if nogeomcmds state.geomcmds
1395 let preloadlayout visiblepages
=
1396 let presentation = conf.presentation in
1397 let interpagespace = conf.interpagespace in
1398 let maxy = state.maxy in
1399 conf.presentation <- false;
1400 conf.interpagespace <- 0;
1401 state.maxy <- calcheight ();
1403 match visiblepages
with
1405 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1407 let y = if y < conf.winh
then 0 else y - conf.winh
in
1408 let h = state.y - y + conf.winh
*3 in
1409 let pages = layout y h in
1410 conf.presentation <- presentation;
1411 conf.interpagespace <- interpagespace;
1417 let rec loop pages =
1418 if state.currently
!= Idle
1423 begin match getopaque l
.pageno
with
1425 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1426 state.currently
<- Loading
(l
, state.gen
);
1428 tilepage l
.pageno opaque
pages;
1433 if nogeomcmds state.geomcmds
1439 if conf.preload && state.currently
= Idle
1440 then load (preloadlayout pages);
1443 let layoutready layout =
1444 let rec fold all ls
=
1445 all
&& match ls
with
1447 let seen = ref false in
1448 let allvisible = ref true in
1449 let foo col row _ _ _ _ _ _
=
1451 allvisible := !allvisible &&
1452 begin match gettileopaque l
col row with
1458 fold (!seen && !allvisible) rest
1461 let alltilesvisible = fold true layout in
1466 let y = bound y 0 state.maxy in
1467 let y, layout, proceed
=
1468 match conf.maxwait
with
1469 | Some time
when state.ghyll
== noghyll ->
1470 begin match state.throttle
with
1472 let layout = layout y conf.winh
in
1473 let ready = layoutready layout in
1477 state.throttle
<- Some
(layout, y, now ());
1479 else G.postRedisplay "gotoy showall (None)";
1481 | Some
(_
, _
, started
) ->
1482 let dt = now () -. started
in
1485 state.throttle
<- None
;
1486 let layout = layout y conf.winh
in
1488 G.postRedisplay "maxwait";
1495 let layout = layout y conf.winh
in
1496 if true || layoutready layout
1497 then G.postRedisplay "gotoy ready";
1503 state.layout <- layout;
1504 begin match state.mode
with
1505 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1506 if not
(pagevisible layout pageno
)
1508 match state.layout with
1511 state.mode
<- Birdseye
(
1512 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1515 | LinkNav
(Ltgendir dir
as lt
) ->
1517 let rec loop = function
1520 match getopaque l
.pageno
with
1526 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1528 if dir
> 0 then LDfirst
else LDlast
1534 | Lnotfound
-> loop rest
1535 | Lfound
(n, x0, y0, x1, y1) ->
1536 showlinktype (getlink opaque
n);
1537 Ltexact
((l
.pageno
, n), (x0, y0, x1, y1))
1541 state.mode
<- LinkNav
linknav
1546 state.ghyll
<- noghyll;
1549 let mx, my
= state.mpos
in
1554 let conttiling pageno opaque
=
1555 tilepage pageno opaque
1556 (if conf.preload then preloadlayout state.layout else state.layout)
1559 let gotoy_and_clear_text y =
1560 if not
conf.verbose
then state.text <- "";
1565 match state.layout with
1567 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1570 let getanchory (n, top
) =
1571 let y, h = getpageyh n in
1572 y + (truncate
(top
*. float h));
1575 let gotoanchor anchor
=
1576 gotoy (getanchory anchor
);
1580 cbput state.hists
.nav
(getanchor ());
1584 let anchor = cbgetc state.hists
.nav dir
in
1589 let rec scroll f n a b =
1590 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1592 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1594 then s (float f /. float a)
1597 then 1.0 -. s ((float (f-b) /. float (n-b)))
1604 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1605 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1607 let ins = float a *. iv1
1608 and outs
= float (n-b) *. iv1 in
1610 ins +. outs
+. float ones
1612 let rec set (_N
, _A
, _B
) y sy
=
1613 let sum = summa
1.0 _N _A _B
in
1614 let dy = float (y - sy
) in
1618 then state.ghyll
<- noghyll
1621 let s = scroll n _N _A _B
in
1622 let y1 = y1 +. ((s *. dy) /. sum) in
1623 gotoy_and_clear_text (truncate
y1);
1624 state.ghyll
<- gf (n+1) y1;
1628 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1630 gf 0 (float state.y)
1633 match conf.ghyllscroll
with
1635 gotoy_and_clear_text y
1637 if state.ghyll
== noghyll
1638 then set nab
y state.y
1639 else state.ghyll
(Some
y)
1642 let gotopage n top
=
1643 let y, h = getpageyh n in
1644 let y = y + (truncate
(top
*. float h)) in
1648 let gotopage1 n top
=
1649 let y = getpagey n in
1654 let invalidate s f =
1659 match state.geomcmds
with
1660 | ps
, [] when String.length ps
= 0 ->
1662 state.geomcmds
<- s, [];
1665 state.geomcmds
<- ps
, [s, f];
1667 | ps
, (s'
, _
) :: rest
when s'
= s ->
1668 state.geomcmds
<- ps
, ((s, f) :: rest
);
1671 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1674 let opendoc path password
=
1676 state.password
<- password
;
1677 state.gen
<- state.gen
+ 1;
1678 state.docinfo
<- [];
1680 setaalevel
conf.aalevel
;
1681 Wsi.settitle
("llpp " ^
Filename.basename path
);
1682 wcmd "open %s\000%s\000" path password
;
1683 invalidate "reqlayout"
1685 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1689 let c = c *. conf.colorscale
in
1693 let scalecolor2 (r
, g
, b) =
1694 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1698 let docolumns = function
1700 | Some
((columns
, coverA
, coverB
), _
) ->
1701 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1702 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1703 if pageno
= state.pagecount
1706 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1708 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1709 pdimno+1, pdim
, rest
1714 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1716 (conf.winw
- state.scrollw
- w) / 2,
1717 y + rowh
+ conf.interpagespace, h
1720 if (pageno
- coverA
) mod columns
= 0
1721 then 0, y + rowh
+ conf.interpagespace, h
1722 else x, y, max rowh
h
1725 let rec fixrow m
= if m
= pageno
then () else
1726 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1729 let y = y + (rowh
- h) / 2 in
1730 a.(m
) <- (pdimno, x, y, pdim
);
1734 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1735 then fixrow (pageno
- columns
);
1736 a.(pageno
) <- (pdimno, x, y, pdim
);
1737 let x = x + w + xoff*2 + conf.interpagespace in
1738 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1740 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1741 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1743 docolumns conf.columns
;
1744 state.maxy <- calcheight ();
1746 if state.w <= conf.winw
- state.scrollw
1750 match state.mode
with
1751 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1752 let y, h = getpageyh pageno
in
1753 let top = (conf.winh
- h) / 2 in
1754 gotoy (max
0 (y - top))
1755 | _
-> gotoanchor state.anchor
1759 GlDraw.viewport
0 0 w h;
1760 if state.geomcmds
!= firstgeomcmds && nogeomcmds state.geomcmds
1761 then state.anchor <- getanchor ();
1764 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1767 setfontsize fstate.fontsize
;
1768 GlMat.mode `modelview
;
1769 GlMat.load_identity
();
1771 GlMat.mode `projection
;
1772 GlMat.load_identity
();
1773 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1774 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1775 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1780 else float state.x /. float state.w
1782 invalidate "geometry"
1785 state.x <- truncate
(relx *. float w);
1787 match conf.columns
with
1789 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1791 wcmd "geometry %d %d" w h);
1795 let len = String.length
state.text in
1798 match state.mode
with
1800 | View
-> state.hscrollh
1805 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1806 (x+.w, float (conf.winh
- hscrollh))
1809 let w = float (conf.winw
- state.scrollw
- 1) in
1810 if state.progress
>= 0.0 && state.progress
< 1.0
1812 GlDraw.color
(0.3, 0.3, 0.3);
1813 let w1 = w *. state.progress
in
1815 GlDraw.color
(0.0, 0.0, 0.0);
1819 GlDraw.color
(0.0, 0.0, 0.0);
1823 GlDraw.color
(1.0, 1.0, 1.0);
1824 drawstring fstate.fontsize
1825 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1828 match state.mode
with
1829 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1833 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1835 Printf.sprintf
"%s%s_" prefix
text
1844 if not
(istextentry state.mode
)
1846 let s1 = "(press 'e' to review error messasges)" in
1847 if String.length
s > 0 then s ^
" " ^
s1 else s1
1852 if String.length
s > 0
1857 let len = Queue.length
state.tilelru
in
1859 if state.memused
<= conf.memlimit
1864 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1865 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1866 let (_
, pw
, ph
, _
) = getpagedim n in
1869 && colorspace
= conf.colorspace
1870 && angle
= conf.angle
1875 match state.throttle
with
1878 then preloadlayout state.layout
1880 | Some
(layout, _
, _
) ->
1883 let x = col*conf.tilew
1884 and y = row*conf.tileh
in
1885 tilevisible layout n x y
1887 then Queue.push lruitem
state.tilelru
1889 wcmd "freetile %s" p
;
1890 state.memused
<- state.memused
- s;
1891 state.uioh#infochanged Memused
;
1892 Hashtbl.remove
state.tilemap k
;
1901 Queue.iter
(fun (k
, p
, s) ->
1902 wcmd "freetile %s" p
;
1903 state.memused
<- state.memused
- s;
1904 state.uioh#infochanged Memused
;
1905 Hashtbl.remove
state.tilemap k
;
1907 Queue.clear
state.tilelru
;
1911 let logcurrently = function
1912 | Idle
-> dolog "Idle"
1913 | Loading
(l
, gen
) ->
1914 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1915 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1917 "Tiling %d[%d,%d] page=%s cs=%s angle"
1918 l
.pageno
col row pageopaque
1919 (colorspace_to_string colorspace
)
1921 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1922 angle gen
conf.angle
state.gen
1924 conf.tilew
conf.tileh
1931 (* dolog "%S" cmds; *)
1934 try String.index cmds ' '
1935 with Not_found
-> -1
1940 let l = String.length cmds
in
1941 let op = String.sub cmds
0 spacepos in
1943 if l - spacepos < 2 then ""
1944 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1949 state.uioh#infochanged Pdim
;
1953 state.rects
<- state.rects1
;
1954 G.postRedisplay "clearrects";
1958 try Scanf.sscanf
args "%u" (fun n -> n)
1960 dolog "error processing 'continue' %S: %s"
1961 cmds
(Printexc.to_string exn
);
1964 state.pagecount
<- n;
1965 begin match state.currently
with
1967 state.currently
<- Idle
;
1968 state.outlines
<- Array.of_list
(List.rev
l)
1972 let cur, cmds
= state.geomcmds
in
1973 if String.length
cur = 0
1974 then failwith
"umpossible";
1976 begin match List.rev cmds
with
1978 state.geomcmds
<- "", [];
1982 state.geomcmds
<- s, List.rev rest
;
1984 if conf.maxwait
= None
1985 then G.postRedisplay "continue";
1995 then showtext ' '
args
1998 let progress, text =
2000 Scanf.sscanf
args "%f %n"
2002 f, String.sub
args pos
(String.length
args - pos
))
2004 dolog "error processing 'progress' %S: %s"
2005 cmds
(Printexc.to_string exn
);
2009 state.progress <- progress;
2010 G.postRedisplay "progress"
2013 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2015 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2016 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2017 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2019 dolog "error processing 'firstmatch' %S: %s"
2020 cmds
(Printexc.to_string exn
);
2023 let y = (getpagey pageno) + truncate
y0 in
2026 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2029 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2031 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2032 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2033 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2035 dolog "error processing 'match' %S: %s"
2036 cmds
(Printexc.to_string exn
);
2040 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2045 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2047 dolog "error processing 'page' %S: %s"
2048 cmds
(Printexc.to_string exn
);
2051 begin match state.currently
with
2052 | Loading
(l, gen
) ->
2053 vlog "page %d took %f sec" l.pageno t
;
2054 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2055 begin match state.throttle
with
2057 let preloadedpages =
2059 then preloadlayout state.layout
2064 Set.Make
(struct type t
= int let compare = (-) end) in
2066 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2067 IntSet.empty
preloadedpages
2070 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2071 if not
(IntSet.mem
pageno set)
2073 wcmd "freepage %s" opaque
;
2079 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2082 state.currently
<- Idle
;
2085 tilepage l.pageno pageopaque state.layout;
2087 load preloadedpages;
2088 if pagevisible state.layout l.pageno
2089 && layoutready state.layout
2090 then G.postRedisplay "page";
2093 | Some
(layout, _
, _
) ->
2094 state.currently
<- Idle
;
2095 tilepage l.pageno pageopaque layout;
2100 dolog "Inconsistent loading state";
2101 logcurrently state.currently
;
2106 let (x, y, opaque
, size
, t
) =
2108 Scanf.sscanf
args "%u %u %s %u %f"
2109 (fun x y p size t
-> (x, y, p
, size
, t
))
2111 dolog "error processing 'tile' %S: %s"
2112 cmds
(Printexc.to_string exn
);
2115 begin match state.currently
with
2116 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2117 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2119 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2121 wcmd "freetile %s" opaque
;
2122 state.currently
<- Idle
;
2126 puttileopaque l col row gen cs angle opaque size t
;
2127 state.memused
<- state.memused
+ size
;
2128 state.uioh#infochanged Memused
;
2130 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2131 opaque
, size
) state.tilelru
;
2134 match state.throttle
with
2135 | None
-> state.layout
2136 | Some
(layout, _
, _
) -> layout
2139 state.currently
<- Idle
;
2141 && conf.colorspace
= cs
2142 && conf.angle
= angle
2143 && tilevisible layout l.pageno x y
2144 then conttiling l.pageno pageopaque;
2146 begin match state.throttle
with
2148 preload state.layout;
2150 && conf.colorspace
= cs
2151 && conf.angle
= angle
2152 && tilevisible state.layout l.pageno x y
2153 then G.postRedisplay "tile nothrottle";
2155 | Some
(layout, y, _
) ->
2156 let ready = layoutready layout in
2160 state.layout <- layout;
2161 state.throttle
<- None
;
2162 G.postRedisplay "throttle";
2169 dolog "Inconsistent tiling state";
2170 logcurrently state.currently
;
2177 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2179 dolog "error processing 'pdim' %S: %s"
2180 cmds
(Printexc.to_string exn
);
2183 state.uioh#infochanged Pdim
;
2184 state.pdims
<- pdim :: state.pdims
2187 let (l, n, t
, h, pos
) =
2189 Scanf.sscanf
args "%u %u %d %u %n"
2190 (fun l n t
h pos
-> l, n, t
, h, pos
)
2192 dolog "error processing 'o' %S: %s"
2193 cmds
(Printexc.to_string exn
);
2196 let s = String.sub
args pos
(String.length
args - pos
) in
2197 let outline = (s, l, (n, float t
/. float h)) in
2198 begin match state.currently
with
2199 | Outlining outlines
->
2200 state.currently
<- Outlining
(outline :: outlines
)
2202 state.currently
<- Outlining
[outline]
2204 dolog "invalid outlining state";
2205 logcurrently currently
2209 state.docinfo
<- (1, args) :: state.docinfo
2212 state.uioh#infochanged Docinfo
;
2213 state.docinfo
<- List.rev
state.docinfo
2216 dolog "unknown cmd `%S'" cmds
2221 let action = function
2222 | HCprev
-> cbget cb ~
-1
2223 | HCnext
-> cbget cb
1
2224 | HCfirst
-> cbget cb ~
-(cb
.rc)
2225 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2226 and cancel
() = cb
.rc <- rc
2230 let search pattern forward
=
2231 if String.length pattern
> 0
2234 match state.layout with
2237 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2239 wcmd "search %d %d %d %d,%s\000"
2240 (btod conf.icase
) pn py (btod forward
) pattern
;
2243 let intentry text key =
2245 if key >= 32 && key < 127
2251 let text = addchar text c in
2255 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2259 let textentry text key =
2260 if key land 0xff00 = 0xff00
2262 else TEcont
(text ^
Wsi.toutf8
key)
2265 let reqlayout angle proportional
=
2266 match state.throttle
with
2268 if nogeomcmds state.geomcmds
2269 then state.anchor <- getanchor ();
2270 conf.angle
<- angle
mod 360;
2273 match state.mode
with
2274 | LinkNav _
-> state.mode
<- View
2277 conf.proportional
<- proportional
;
2278 invalidate "reqlayout"
2279 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2283 let settrim trimmargins trimfuzz
=
2284 if nogeomcmds state.geomcmds
2285 then state.anchor <- getanchor ();
2286 conf.trimmargins
<- trimmargins
;
2287 conf.trimfuzz
<- trimfuzz
;
2288 let x0, y0, x1, y1 = trimfuzz
in
2289 invalidate "settrim"
2291 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2292 Hashtbl.iter
(fun _ opaque
->
2293 wcmd "freepage %s" opaque
;
2295 Hashtbl.clear
state.pagemap
;
2299 match state.throttle
with
2301 let zoom = max
0.01 zoom in
2302 if zoom <> conf.zoom
2304 state.prevzoom
<- conf.zoom;
2306 reshape conf.winw
conf.winh
;
2307 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2310 | Some
(layout, y, started
) ->
2312 match conf.maxwait
with
2316 let dt = now () -. started
in
2324 let setcolumns columns coverA coverB
=
2327 conf.columns
<- None
;
2332 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2335 reshape conf.winw
conf.winh
;
2338 let enterbirdseye () =
2339 let zoom = float conf.thumbw
/. float conf.winw
in
2340 let birdseyepageno =
2341 let cy = conf.winh
/ 2 in
2345 let rec fold best
= function
2348 let d = cy - (l.pagedispy + l.pagevh/2)
2349 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2350 if abs
d < abs dbest
2357 state.mode
<- Birdseye
(
2358 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2361 conf.presentation <- false;
2362 conf.interpagespace <- 10;
2363 conf.hlinks
<- false;
2365 state.mstate
<- Mnone
;
2366 conf.maxwait
<- None
;
2368 match conf.beyecolumns
with
2371 Some
((c, 0, 0), [||])
2374 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2377 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2382 reshape conf.winw
conf.winh
;
2385 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2387 conf.zoom <- c.zoom;
2388 conf.presentation <- c.presentation;
2389 conf.interpagespace <- c.interpagespace;
2390 conf.maxwait
<- c.maxwait
;
2391 conf.hlinks
<- c.hlinks
;
2392 conf.beyecolumns
<- (
2393 match conf.columns
with
2394 | Some
((c, _
, _
), _
) -> Some
c
2398 match c.columns
with
2399 | Some
(c, _
) -> Some
(c, [||])
2405 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2408 reshape conf.winw
conf.winh
;
2409 state.anchor <- if goback
then anchor else (pageno, 0.0);
2412 let togglebirdseye () =
2413 match state.mode
with
2414 | Birdseye vals
-> leavebirdseye vals
true
2415 | View
-> enterbirdseye ()
2419 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2420 let pageno = max
0 (pageno - incr
) in
2421 let rec loop = function
2422 | [] -> gotopage1 pageno 0
2423 | l :: _
when l.pageno = pageno ->
2424 if l.pagedispy >= 0 && l.pagey = 0
2425 then G.postRedisplay "upbirdseye"
2426 else gotopage1 pageno 0
2427 | _
:: rest
-> loop rest
2430 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2433 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2434 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2435 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2436 let rec loop = function
2438 let y, h = getpageyh pageno in
2439 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2441 | l :: _
when l.pageno = pageno ->
2442 if l.pagevh != l.pageh
2443 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2444 else G.postRedisplay "downbirdseye"
2445 | _
:: rest
-> loop rest
2450 let optentry mode _
key =
2451 let btos b = if b then "on" else "off" in
2452 if key >= 32 && key < 127
2454 let c = Char.chr
key in
2458 try conf.scrollstep
<- int_of_string
s with exc
->
2459 state.text <- Printf.sprintf
"bad integer `%s': %s"
2460 s (Printexc.to_string exc
)
2462 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2467 conf.autoscrollstep
<- int_of_string
s;
2468 if state.autoscroll
<> None
2469 then state.autoscroll
<- Some
conf.autoscrollstep
2471 state.text <- Printf.sprintf
"bad integer `%s': %s"
2472 s (Printexc.to_string exc
)
2474 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2479 let n, a, b = columns_of_string s in
2482 state.text <- Printf.sprintf
"bad columns `%s': %s"
2483 s (Printexc.to_string exc
)
2485 TEswitch
("columns: ", "", None
, textentry, ondone)
2490 let zoom = float (int_of_string
s) /. 100.0 in
2493 state.text <- Printf.sprintf
"bad integer `%s': %s"
2494 s (Printexc.to_string exc
)
2496 TEswitch
("zoom: ", "", None
, intentry, ondone)
2501 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2503 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2504 begin match mode
with
2506 leavebirdseye beye
false;
2511 state.text <- Printf.sprintf
"bad integer `%s': %s"
2512 s (Printexc.to_string exc
)
2514 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2519 Some
(int_of_string
s)
2521 state.text <- Printf.sprintf
"bad integer `%s': %s"
2522 s (Printexc.to_string exc
);
2525 | Some angle
-> reqlayout angle
conf.proportional
2528 TEswitch
("rotation: ", "", None
, intentry, ondone)
2531 conf.icase
<- not
conf.icase
;
2532 TEdone
("case insensitive search " ^
(btos conf.icase
))
2535 conf.preload <- not
conf.preload;
2537 TEdone
("preload " ^
(btos conf.preload))
2540 conf.verbose
<- not
conf.verbose
;
2541 TEdone
("verbose " ^
(btos conf.verbose
))
2544 conf.debug
<- not
conf.debug
;
2545 TEdone
("debug " ^
(btos conf.debug
))
2548 conf.maxhfit
<- not
conf.maxhfit
;
2550 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2551 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2554 conf.crophack
<- not
conf.crophack
;
2555 TEdone
("crophack " ^
btos conf.crophack
)
2559 match conf.maxwait
with
2561 conf.maxwait
<- Some infinity
;
2562 "always wait for page to complete"
2564 conf.maxwait
<- None
;
2565 "show placeholder if page is not ready"
2570 conf.underinfo
<- not
conf.underinfo
;
2571 TEdone
("underinfo " ^
btos conf.underinfo
)
2574 conf.savebmarks
<- not
conf.savebmarks
;
2575 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2581 match state.layout with
2586 conf.interpagespace <- int_of_string
s;
2587 state.maxy <- calcheight ();
2588 let y = getpagey pageno in
2591 state.text <- Printf.sprintf
"bad integer `%s': %s"
2592 s (Printexc.to_string exc
)
2594 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2597 reqlayout conf.angle
(not
conf.proportional
);
2598 TEdone
("proportional display " ^
btos conf.proportional
)
2601 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2602 TEdone
("trim margins " ^
btos conf.trimmargins
)
2605 conf.invert
<- not
conf.invert
;
2606 TEdone
("invert colors " ^
btos conf.invert
)
2610 cbput state.hists
.sel
s;
2613 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2617 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2623 class type lvsource
= object
2624 method getitemcount
: int
2625 method getitem
: int -> (string * int)
2626 method hasaction
: int -> bool
2635 method getactive
: int
2636 method getfirst
: int
2637 method getqsearch
: string
2638 method setqsearch
: string -> unit
2642 class virtual lvsourcebase
= object
2643 val mutable m_active
= 0
2644 val mutable m_first
= 0
2645 val mutable m_qsearch
= ""
2646 val mutable m_pan
= 0
2647 method getactive
= m_active
2648 method getfirst
= m_first
2649 method getqsearch
= m_qsearch
2650 method getpan
= m_pan
2651 method setqsearch
s = m_qsearch
<- s
2654 let withoutlastutf8 s =
2655 let len = String.length
s in
2663 let b = Char.code
s.[pos
] in
2664 if b land 0b110000 = 0b11000000
2669 if Char.code
s.[len-1] land 0x80 = 0
2673 String.sub
s 0 first;
2676 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2678 state.mode
<- Textentry
(te
, onleave
);
2681 G.postRedisplay "textentrykeyboard enttext";
2683 let histaction cmd
=
2686 | Some
(action, _
) ->
2687 state.mode
<- Textentry
(
2688 (c, action cmd
, opthist
, onkey
, ondone), onleave
2690 G.postRedisplay "textentry histaction"
2693 | 0xff08 -> (* backspace *)
2694 let s = withoutlastutf8 text in
2695 let len = String.length
s in
2699 G.postRedisplay "textentrykeyboard after cancel";
2702 enttext (c, s, opthist
, onkey
, ondone)
2708 G.postRedisplay "textentrykeyboard after confirm"
2710 | 0xff52 -> histaction HCprev
2711 | 0xff54 -> histaction HCnext
2712 | 0xff50 -> histaction HCfirst
2713 | 0xff57 -> histaction HClast
2715 | 0xff1b -> (* escape*)
2716 if String.length
text = 0
2718 begin match opthist
with
2720 | Some
(_
, onhistcancel
) -> onhistcancel
()
2724 G.postRedisplay "textentrykeyboard after cancel2"
2727 enttext (c, "", opthist
, onkey
, ondone)
2730 | 0xff9f | 0xffff -> () (* delete *)
2732 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2733 begin match onkey
text key with
2737 G.postRedisplay "textentrykeyboard after confirm2";
2740 enttext (c, text, opthist
, onkey
, ondone);
2744 G.postRedisplay "textentrykeyboard after cancel3"
2747 state.mode
<- Textentry
(te
, onleave
);
2748 G.postRedisplay "textentrykeyboard switch";
2752 vlog "unhandled key %s" (Wsi.keyname
key)
2755 let firstof first active
=
2756 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2757 then max
0 (active
- (fstate.maxrows
/2))
2761 let calcfirst first active
=
2764 let rows = active
- first in
2765 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2769 let scrollph y maxy =
2770 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2771 let sh = float conf.winh
/. sh in
2772 let sh = max
sh (float conf.scrollh
) in
2777 else float y /. float maxy
2779 let position = (float conf.winh
-. sh) *. percent in
2782 if position +. sh > float conf.winh
2783 then float conf.winh
-. sh
2789 let coe s = (s :> uioh
);;
2791 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2793 val m_pan
= source#getpan
2794 val m_first
= source#getfirst
2795 val m_active
= source#getactive
2796 val m_qsearch
= source#getqsearch
2797 val m_prev_uioh
= state.uioh
2799 method private elemunder
y =
2800 let n = y / (fstate.fontsize
+1) in
2801 if m_first
+ n < source#getitemcount
2803 if source#hasaction
(m_first
+ n)
2804 then Some
(m_first
+ n)
2811 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2812 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2813 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2814 GlDraw.color
(1., 1., 1.);
2815 Gl.enable `texture_2d
;
2816 let fs = fstate.fontsize
in
2818 let ww = fstate.wwidth
in
2819 let tabw = 30.0*.ww in
2820 let itemcount = source#getitemcount
in
2822 if (row - m_first
) * nfs > conf.winh
2825 if row >= 0 && row < itemcount
2827 let (s, level
) = source#getitem
row in
2828 let y = (row - m_first
) * nfs in
2829 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2832 Gl.disable `texture_2d
;
2833 GlDraw.polygon_mode `both `line
;
2834 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2835 GlDraw.rect (1., float (y + 1))
2836 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2837 GlDraw.polygon_mode `both `fill
;
2838 GlDraw.color
(1., 1., 1.);
2839 Gl.enable `texture_2d
;
2842 let drawtabularstring s =
2843 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2846 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2849 let len = String.length
s - tabpos - 1 in
2850 let s1 = String.sub
s 0 tabpos
2851 and s2
= String.sub
s (tabpos + 1) len in
2852 let nx = drawstr x s1 in
2854 let x = x +. (max
tabw sw) in
2861 let _ = drawtabularstring s in
2868 Gl.disable `texture_2d
;
2870 method updownlevel incr
=
2871 let len = source#getitemcount
in
2873 if m_active
>= 0 && m_active
< len
2874 then snd
(source#getitem m_active
)
2878 if i
= len then i
-1 else if i
= -1 then 0 else
2879 let _, l = source#getitem i
in
2880 if l != curlevel then i
else flow (i
+incr
)
2882 let active = flow m_active
in
2883 let first = calcfirst m_first
active in
2884 G.postRedisplay "outline updownlevel";
2885 {< m_active
= active; m_first
= first >}
2887 method private key1
key mask
=
2888 let set1 active first qsearch
=
2889 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2891 let search active pattern incr
=
2894 if n >= 0 && n < source#getitemcount
2896 let s, _ = source#getitem
n in
2898 (try ignore
(Str.search_forward
re s 0); true
2899 with Not_found
-> false)
2901 else loop (n + incr
)
2908 let re = Str.regexp_case_fold pattern
in
2914 let itemcount = source#getitemcount
in
2915 let find start incr
=
2917 if i
= -1 || i
= itemcount
2920 if source#hasaction i
2922 else find (i
+ incr
)
2927 let set active first =
2928 let first = bound first 0 (itemcount - fstate.maxrows
) in
2930 coe {< m_active
= active; m_first
= first >}
2933 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2935 let incr1 = if incr
> 0 then 1 else -1 in
2936 if isvisible m_first m_active
2939 let next = m_active
+ incr
in
2941 if next < 0 || next >= itemcount
2943 else find next incr1
2945 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2951 let first = m_first
+ incr
in
2952 let first = bound first 0 (itemcount - 1) in
2954 let next = m_active
+ incr
in
2955 let next = bound next 0 (itemcount - 1) in
2958 let active = if next = -1 then m_active
else next in
2961 let first = min
next m_first
in
2963 if abs
(next - first) > fstate.maxrows
2969 let first = m_first
+ incr
in
2970 let first = bound first 0 (itemcount - 1) in
2972 let next = m_active
+ incr
in
2973 let next = bound next 0 (itemcount - 1) in
2974 let next = find next incr1 in
2976 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2978 let active = if m_active
= -1 then next else m_active
in
2983 if isvisible first active
2989 G.postRedisplay "listview navigate";
2993 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2994 let incr = if key = 0x72 then -1 else 1 in
2996 match search (m_active
+ incr) m_qsearch
incr with
2998 state.text <- m_qsearch ^
" [not found]";
3001 state.text <- m_qsearch
;
3002 active, firstof m_first
active
3004 G.postRedisplay "listview ctrl-r/s";
3005 set1 active first m_qsearch
;
3007 | 0xff08 -> (* backspace *)
3008 if String.length m_qsearch
= 0
3011 let qsearch = withoutlastutf8 m_qsearch
in
3012 let len = String.length
qsearch in
3016 G.postRedisplay "listview empty qsearch";
3017 set1 m_active m_first
"";
3021 match search m_active
qsearch ~
-1 with
3023 state.text <- qsearch ^
" [not found]";
3026 state.text <- qsearch;
3027 active, firstof m_first
active
3029 G.postRedisplay "listview backspace qsearch";
3030 set1 active first qsearch
3033 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3034 let pattern = m_qsearch ^
Wsi.toutf8
key in
3036 match search m_active
pattern 1 with
3038 state.text <- pattern ^
" [not found]";
3041 state.text <- pattern;
3042 active, firstof m_first
active
3044 G.postRedisplay "listview qsearch add";
3045 set1 active first pattern;
3047 | 0xff1b -> (* escape *)
3049 if String.length m_qsearch
= 0
3051 G.postRedisplay "list view escape";
3054 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3056 | None
-> m_prev_uioh
3061 G.postRedisplay "list view kill qsearch";
3062 source#setqsearch
"";
3063 coe {< m_qsearch
= "" >}
3066 | 0xff0d -> (* return *)
3068 let self = {< m_qsearch
= "" >} in
3069 source#setqsearch
"";
3071 G.postRedisplay "listview enter";
3072 if m_active
>= 0 && m_active
< source#getitemcount
3074 source#exit
(coe self) false m_active m_first m_pan
"";
3077 source#exit
(coe self) true m_active m_first m_pan
"";
3080 begin match opt with
3081 | None
-> m_prev_uioh
3085 | 0xff9f | 0xffff -> (* delete *)
3088 | 0xff52 -> navigate ~
-1 (* up *)
3089 | 0xff54 -> navigate 1 (* down *)
3090 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3091 | 0xff56 -> navigate fstate.maxrows
(* next *)
3093 | 0xff53 -> (* right *)
3095 G.postRedisplay "listview right";
3096 coe {< m_pan
= m_pan
- 1 >}
3098 | 0xff51 -> (* left *)
3100 G.postRedisplay "listview left";
3101 coe {< m_pan
= m_pan
+ 1 >}
3103 | 0xff50 -> (* home *)
3104 let active = find 0 1 in
3105 G.postRedisplay "listview home";
3108 | 0xff57 -> (* end *)
3109 let first = max
0 (itemcount - fstate.maxrows
) in
3110 let active = find (itemcount - 1) ~
-1 in
3111 G.postRedisplay "listview end";
3114 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3118 dolog "listview unknown key %#x" key; coe self
3120 method key key mask
=
3121 match state.mode
with
3122 | Textentry te
-> textentrykeyboard key mask te
; coe self
3123 | _ -> self#key1
key mask
3125 method button button down
x y _ =
3128 | 1 when x > conf.winw
- conf.scrollbw
->
3129 G.postRedisplay "listview scroll";
3132 let _, position, sh = self#
scrollph in
3133 if y > truncate
position && y < truncate
(position +. sh)
3135 state.mstate
<- Mscrolly
;
3139 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3140 let first = truncate
(s *. float source#getitemcount
) in
3141 let first = min source#getitemcount
first in
3142 Some
(coe {< m_first
= first; m_active
= first >})
3144 state.mstate
<- Mnone
;
3147 | 1 when not down
->
3148 begin match self#elemunder
y with
3150 G.postRedisplay "listview click";
3152 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3156 | n when (n == 4 || n == 5) && not down
->
3157 let len = source#getitemcount
in
3159 if n = 5 && m_first
+ fstate.maxrows
>= len
3163 let first = m_first
+ (if n == 4 then -1 else 1) in
3164 bound first 0 (len - 1)
3166 G.postRedisplay "listview wheel";
3167 Some
(coe {< m_first
= first >})
3172 | None
-> m_prev_uioh
3176 match state.mstate
with
3178 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3179 let first = truncate
(s *. float source#getitemcount
) in
3180 let first = min source#getitemcount
first in
3181 G.postRedisplay "listview motion";
3182 coe {< m_first
= first; m_active
= first >}
3185 method pmotion
x y =
3186 if x < conf.winw
- conf.scrollbw
3189 match self#elemunder
y with
3190 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3191 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3195 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3200 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3204 method infochanged
_ = ()
3206 method scrollpw
= (0, 0.0, 0.0)
3208 let nfs = fstate.fontsize
+ 1 in
3209 let y = m_first
* nfs in
3210 let itemcount = source#getitemcount
in
3211 let maxi = max
0 (itemcount - fstate.maxrows
) in
3212 let maxy = maxi * nfs in
3213 let p, h = scrollph y maxy in
3216 method modehash
= modehash
3219 class outlinelistview ~source
=
3222 ~source
:(source
:> lvsource
)
3224 ~modehash
:(findkeyhash conf "outline")
3227 method key key mask
=
3228 let calcfirst first active =
3231 let rows = active - first in
3232 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3236 let active = m_active
+ incr in
3237 let active = bound active 0 (source#getitemcount
- 1) in
3238 let first = calcfirst m_first
active in
3239 G.postRedisplay "outline navigate";
3240 coe {< m_active
= active; m_first
= first >}
3242 let ctrl = Wsi.withctrl mask
in
3244 | 110 when ctrl -> (* ctrl-n *)
3245 source#narrow m_qsearch
;
3246 G.postRedisplay "outline ctrl-n";
3247 coe {< m_first
= 0; m_active
= 0 >}
3249 | 117 when ctrl -> (* ctrl-u *)
3251 G.postRedisplay "outline ctrl-u";
3253 coe {< m_first
= 0; m_active
= 0 >}
3255 | 108 when ctrl -> (* ctrl-l *)
3256 let first = m_active
- (fstate.maxrows
/ 2) in
3257 G.postRedisplay "outline ctrl-l";
3258 coe {< m_first
= first >}
3260 | 0xff9f | 0xffff -> (* delete *)
3261 source#remove m_active
;
3262 G.postRedisplay "outline delete";
3263 let active = max
0 (m_active
-1) in
3264 coe {< m_first
= firstof m_first
active;
3265 m_active
= active >}
3267 | 0xff52 -> navigate ~
-1 (* up *)
3268 | 0xff54 -> navigate 1 (* down *)
3269 | 0xff55 -> (* prior *)
3270 navigate ~
-(fstate.maxrows
)
3271 | 0xff56 -> (* next *)
3272 navigate fstate.maxrows
3274 | 0xff53 -> (* [ctrl-]right *)
3278 G.postRedisplay "outline ctrl right";
3279 {< m_pan
= m_pan
+ 1 >}
3281 else self#updownlevel
1
3285 | 0xff51 -> (* [ctrl-]left *)
3289 G.postRedisplay "outline ctrl left";
3290 {< m_pan
= m_pan
- 1 >}
3292 else self#updownlevel ~
-1
3296 | 0xff50 -> (* home *)
3297 G.postRedisplay "outline home";
3298 coe {< m_first
= 0; m_active
= 0 >}
3300 | 0xff57 -> (* end *)
3301 let active = source#getitemcount
- 1 in
3302 let first = max
0 (active - fstate.maxrows
) in
3303 G.postRedisplay "outline end";
3304 coe {< m_active
= active; m_first
= first >}
3306 | _ -> super#
key key mask
3309 let outlinesource usebookmarks
=
3312 inherit lvsourcebase
3313 val mutable m_items
= empty
3314 val mutable m_orig_items
= empty
3315 val mutable m_prev_items
= empty
3316 val mutable m_narrow_pattern
= ""
3317 val mutable m_hadremovals
= false
3319 method getitemcount
=
3320 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3323 if n == Array.length m_items
&& m_hadremovals
3325 ("[Confirm removal]", 0)
3327 let s, n, _ = m_items
.(n) in
3330 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3331 ignore
(uioh
, first, qsearch);
3332 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3334 if String.length m_narrow_pattern
= 0
3340 if not
confrimremoval
3342 let _, _, anchor = m_items
.(active) in
3347 state.bookmarks
<- Array.to_list m_items
;
3348 m_orig_items
<- m_items
;
3351 else m_items
<- items;
3355 method hasaction
_ = true
3358 if Array.length m_items
!= Array.length m_orig_items
3359 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3362 method narrow
pattern =
3363 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3367 let rec loop accu n =
3370 m_narrow_pattern
<- pattern;
3371 m_items
<- Array.of_list
accu
3374 let (s, _, _) as o = m_items
.(n) in
3376 if (try ignore
(Str.search_forward
re s 0); true
3377 with Not_found
-> false)
3383 loop [] (Array.length m_items
- 1)
3388 then Array.of_list
state.bookmarks
3391 m_items
<- m_orig_items
3396 if m
>= 0 && m
< Array.length m_items
3398 m_hadremovals
<- true;
3399 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3400 let n = if n >= m
then n+1 else n in
3405 method reset
anchor items =
3406 m_hadremovals
<- false;
3407 if m_orig_items
== empty || m_prev_items
!= items
3409 m_orig_items
<- items;
3410 if String.length m_narrow_pattern
= 0
3411 then m_items
<- items;
3413 m_prev_items
<- items;
3414 let rely = getanchory anchor in
3416 let rec loop n best bestd
=
3417 if n = Array.length m_items
3420 let (_, _, anchor) = m_items
.(n) in
3421 let orely = getanchory anchor in
3422 let d = abs
(orely - rely) in
3425 else loop (n+1) best bestd
3430 m_first
<- firstof m_first
active
3434 let enterselector usebookmarks
=
3435 let source = outlinesource usebookmarks
in
3439 then Array.of_list
state.bookmarks
3442 if Array.length
outlines = 0
3444 showtext ' ' errmsg
;
3447 state.text <- source#greetmsg
;
3448 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3449 let anchor = getanchor () in
3450 source#reset
anchor outlines;
3451 state.uioh
<- coe (new outlinelistview ~
source);
3452 G.postRedisplay "enter selector";
3456 let enteroutlinemode =
3457 let f = enterselector false in
3458 fun ()-> f "Document has no outline";
3461 let enterbookmarkmode =
3462 let f = enterselector true in
3463 fun () -> f "Document has no bookmarks (yet)";
3466 let color_of_string s =
3467 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3468 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3472 let color_to_string (r
, g
, b) =
3473 let r = truncate
(r *. 256.0)
3474 and g
= truncate
(g
*. 256.0)
3475 and b = truncate
(b *. 256.0) in
3476 Printf.sprintf
"%d/%d/%d" r g
b
3479 let irect_of_string s =
3480 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3483 let irect_to_string (x0,y0,x1,y1) =
3484 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3487 let makecheckers () =
3488 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3490 converted by Issac Trotts. July 25, 2002 *)
3491 let image_height = 64
3492 and image_width
= 64 in
3496 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3498 for i
= 0 to image_width
- 1 do
3499 for j
= 0 to image_height - 1 do
3500 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3501 (if (i
land 8 ) lxor (j
land 8) = 0
3502 then [|255;255;255|] else [|200;200;200|])
3507 let image = make_image () in
3508 let id = GlTex.gen_texture
() in
3509 GlTex.bind_texture `texture_2d
id;
3510 GlPix.store
(`unpack_alignment
1);
3511 GlTex.image2d
image;
3512 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3515 `mag_filter `nearest
;
3516 `min_filter `nearest
];
3520 let setcheckers enabled
=
3521 match state.texid
with
3523 if enabled
then state.texid
<- Some
(makecheckers ())
3528 GlTex.delete_texture texid
;
3529 state.texid
<- None
;
3533 let int_of_string_with_suffix s =
3534 let l = String.length
s in
3538 let suffix = Char.lowercase
s.[l-1] in
3540 | 'k'
-> String.sub
s 0 (l-1), 10
3541 | 'm'
-> String.sub
s 0 (l-1), 20
3542 | 'g'
-> String.sub
s 0 (l-1), 30
3546 let n = int_of_string
s1 in
3547 let m = n lsl shift
in
3549 then raise
(Failure
"value too large")
3553 let string_with_suffix_of_int n =
3561 if n land ((1 lsl 20) - 1) = 0
3564 if n land ((1 lsl 10) - 1) = 0
3571 let h = n mod 1000 in
3574 then string_of_int
h ^
s
3576 let s = Printf.sprintf
"_%03d%s" h s in
3583 let defghyllscroll = (40, 8, 32);;
3584 let ghyllscroll_of_string s =
3585 let (n, a, b) as nab
=
3588 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3590 if n <= a || n <= b || a >= b
3591 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3595 let ghyllscroll_to_string ((n, a, b) as nab
) =
3596 if nab
= defghyllscroll
3598 else Printf.sprintf
"%d,%d,%d" n a b;
3601 let describe_location () =
3603 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3605 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3606 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3610 else (100. *. (float state.y /. float maxy))
3614 Printf.sprintf
"page %d of %d [%.2f%%]"
3615 (fn+1) state.pagecount
percent
3618 "pages %d-%d of %d [%.2f%%]"
3619 (fn+1) (ln
+1) state.pagecount
percent
3623 let btos b = if b then "\xe2\x88\x9a" else "" in
3624 let showextended = ref false in
3625 let leave mode
= function
3626 | Confirm
-> state.mode
<- mode
3627 | Cancel
-> state.mode
<- mode
in
3630 val mutable m_first_time
= true
3631 val mutable m_l
= []
3632 val mutable m_a
= [||]
3633 val mutable m_prev_uioh
= nouioh
3634 val mutable m_prev_mode
= View
3636 inherit lvsourcebase
3638 method reset prev_mode prev_uioh
=
3639 m_a
<- Array.of_list
(List.rev m_l
);
3641 m_prev_mode
<- prev_mode
;
3642 m_prev_uioh
<- prev_uioh
;
3646 if n >= Array.length m_a
3650 | _, _, _, Action
_ -> m_active
<- n
3654 m_first_time
<- false;
3657 method int name get
set =
3659 (name
, `
int get
, 1, Action
(
3662 try set (int_of_string
s)
3664 state.text <- Printf.sprintf
"bad integer `%s': %s"
3665 s (Printexc.to_string exn
)
3668 let te = name ^
": ", "", None
, intentry, ondone in
3669 state.mode
<- Textentry
(te, leave m_prev_mode
);
3673 method int_with_suffix name get
set =
3675 (name
, `intws get
, 1, Action
(
3678 try set (int_of_string_with_suffix s)
3680 state.text <- Printf.sprintf
"bad integer `%s': %s"
3681 s (Printexc.to_string exn
)
3685 name ^
": ", "", None
, intentry_with_suffix, ondone
3687 state.mode
<- Textentry
(te, leave m_prev_mode
);
3691 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3693 (name
, `
bool (btos, get
), offset
, Action
(
3700 method color name get
set =
3702 (name
, `color get
, 1, Action
(
3704 let invalid = (nan
, nan
, nan
) in
3707 try color_of_string s
3709 state.text <- Printf.sprintf
"bad color `%s': %s"
3710 s (Printexc.to_string exn
);
3716 let te = name ^
": ", "", None
, textentry, ondone in
3717 state.text <- color_to_string (get
());
3718 state.mode
<- Textentry
(te, leave m_prev_mode
);
3722 method string name get
set =
3724 (name
, `
string get
, 1, Action
(
3726 let ondone s = set s in
3727 let te = name ^
": ", "", None
, textentry, ondone in
3728 state.mode
<- Textentry
(te, leave m_prev_mode
);
3732 method colorspace name get
set =
3734 (name
, `
string get
, 1, Action
(
3737 let vals = [| "rgb"; "bgr"; "gray" |] in
3739 inherit lvsourcebase
3742 m_active
<- int_of_colorspace conf.colorspace
;
3745 method getitemcount
= Array.length
vals
3746 method getitem
n = (vals.(n), 0)
3747 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3748 ignore
(uioh
, first, pan
, qsearch);
3749 if not cancel
then set active;
3751 method hasaction
_ = true
3755 let modehash = findkeyhash conf "info" in
3756 coe (new listview ~
source ~trusted
:true ~
modehash)
3759 method caption
s offset
=
3760 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3762 method caption2
s f offset
=
3763 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3765 method getitemcount
= Array.length m_a
3768 let tostr = function
3769 | `
int f -> string_of_int
(f ())
3770 | `intws
f -> string_with_suffix_of_int (f ())
3772 | `color
f -> color_to_string (f ())
3773 | `
bool (btos, f) -> btos (f ())
3776 let name, t
, offset
, _ = m_a
.(n) in
3777 ((let s = tostr t
in
3778 if String.length
s > 0
3779 then Printf.sprintf
"%s\t%s" name s
3783 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3787 m_qsearch
<- qsearch;
3789 match m_a
.(active) with
3790 | _, _, _, Action
f -> f uioh
3802 method hasaction
n =
3804 | _, _, _, Action
_ -> true
3808 let rec fillsrc prevmode prevuioh
=
3809 let sep () = src#caption
"" 0 in
3810 let colorp name get
set =
3812 (fun () -> color_to_string (get
()))
3815 let c = color_of_string v in
3818 state.text <- Printf.sprintf
"bad color `%s': %s"
3819 v (Printexc.to_string exn
);
3822 let oldmode = state.mode
in
3823 let birdseye = isbirdseye state.mode
in
3825 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3827 src#
bool "presentation mode"
3828 (fun () -> conf.presentation)
3830 conf.presentation <- v;
3831 state.anchor <- getanchor ();
3834 src#
bool "ignore case in searches"
3835 (fun () -> conf.icase
)
3836 (fun v -> conf.icase
<- v);
3839 (fun () -> conf.preload)
3840 (fun v -> conf.preload <- v);
3842 src#
bool "highlight links"
3843 (fun () -> conf.hlinks
)
3844 (fun v -> conf.hlinks
<- v);
3846 src#
bool "under info"
3847 (fun () -> conf.underinfo
)
3848 (fun v -> conf.underinfo
<- v);
3850 src#
bool "persistent bookmarks"
3851 (fun () -> conf.savebmarks
)
3852 (fun v -> conf.savebmarks
<- v);
3854 src#
bool "proportional display"
3855 (fun () -> conf.proportional
)
3856 (fun v -> reqlayout conf.angle
v);
3858 src#
bool "trim margins"
3859 (fun () -> conf.trimmargins
)
3860 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3862 src#
bool "persistent location"
3863 (fun () -> conf.jumpback
)
3864 (fun v -> conf.jumpback
<- v);
3867 src#
int "inter-page space"
3868 (fun () -> conf.interpagespace)
3870 conf.interpagespace <- n;
3872 match state.layout with
3877 state.maxy <- calcheight ();
3878 let y = getpagey pageno in
3883 (fun () -> conf.pagebias
)
3884 (fun v -> conf.pagebias
<- v);
3886 src#
int "scroll step"
3887 (fun () -> conf.scrollstep
)
3888 (fun n -> conf.scrollstep
<- n);
3890 src#
int "auto scroll step"
3892 match state.autoscroll
with
3894 | _ -> conf.autoscrollstep
)
3896 if state.autoscroll
<> None
3897 then state.autoscroll
<- Some
n;
3898 conf.autoscrollstep
<- n);
3901 (fun () -> truncate
(conf.zoom *. 100.))
3902 (fun v -> setzoom ((float v) /. 100.));
3905 (fun () -> conf.angle
)
3906 (fun v -> reqlayout v conf.proportional
);
3908 src#
int "scroll bar width"
3909 (fun () -> state.scrollw
)
3913 reshape conf.winw
conf.winh
;
3916 src#
int "scroll handle height"
3917 (fun () -> conf.scrollh
)
3918 (fun v -> conf.scrollh
<- v;);
3920 src#
int "thumbnail width"
3921 (fun () -> conf.thumbw
)
3923 conf.thumbw
<- min
4096 v;
3926 leavebirdseye beye
false;
3931 src#
string "columns"
3933 match conf.columns
with
3935 | Some
(multicol
, _) -> columns_to_string multicol
)
3937 let n, a, b = columns_of_string v in
3941 src#caption
"Presentation mode" 0;
3942 src#
bool "scrollbar visible"
3943 (fun () -> conf.scrollbarinpm
)
3945 if v != conf.scrollbarinpm
3947 conf.scrollbarinpm
<- v;
3948 if conf.presentation
3950 state.scrollw
<- if v then conf.scrollbw
else 0;
3951 reshape conf.winw
conf.winh
;
3957 src#caption
"Pixmap cache" 0;
3958 src#int_with_suffix
"size (advisory)"
3959 (fun () -> conf.memlimit
)
3960 (fun v -> conf.memlimit
<- v);
3963 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3964 (string_with_suffix_of_int state.memused
)
3965 (Hashtbl.length
state.tilemap
)) 1;
3968 src#caption
"Layout" 0;
3969 src#caption2
"Dimension"
3971 Printf.sprintf
"%dx%d (virtual %dx%d)"
3977 src#caption2
"Position" (fun () ->
3978 Printf.sprintf
"%dx%d" state.x state.y
3981 src#caption2
"Visible" (fun () -> describe_location ()) 1
3985 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3986 "Save these parameters as global defaults at exit"
3987 (fun () -> conf.bedefault
)
3988 (fun v -> conf.bedefault
<- v)
3992 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3993 src#
bool ~offset
:0 ~
btos "Extended parameters"
3994 (fun () -> !showextended)
3995 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3999 (fun () -> conf.checkers
)
4000 (fun v -> conf.checkers
<- v; setcheckers v);
4001 src#
bool "update cursor"
4002 (fun () -> conf.updatecurs
)
4003 (fun v -> conf.updatecurs
<- v);
4005 (fun () -> conf.verbose
)
4006 (fun v -> conf.verbose
<- v);
4007 src#
bool "invert colors"
4008 (fun () -> conf.invert
)
4009 (fun v -> conf.invert
<- v);
4011 (fun () -> conf.maxhfit
)
4012 (fun v -> conf.maxhfit
<- v);
4013 src#
bool "redirect stderr"
4014 (fun () -> conf.redirectstderr)
4015 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4016 src#
string "uri launcher"
4017 (fun () -> conf.urilauncher
)
4018 (fun v -> conf.urilauncher
<- v);
4019 src#
string "path launcher"
4020 (fun () -> conf.pathlauncher
)
4021 (fun v -> conf.pathlauncher
<- v);
4022 src#
string "tile size"
4023 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4026 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4027 conf.tileh
<- max
64 w;
4028 conf.tilew
<- max
64 h;
4031 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4032 v (Printexc.to_string exn
));
4033 src#
int "texture count"
4034 (fun () -> conf.texcount
)
4037 then conf.texcount
<- v
4038 else showtext '
!'
" Failed to set texture count please retry later"
4040 src#
int "slice height"
4041 (fun () -> conf.sliceheight
)
4043 conf.sliceheight
<- v;
4044 wcmd "sliceh %d" conf.sliceheight
;
4046 src#
int "anti-aliasing level"
4047 (fun () -> conf.aalevel
)
4049 conf.aalevel
<- bound v 0 8;
4050 state.anchor <- getanchor ();
4051 opendoc state.path
state.password
;
4053 src#
int "ui font size"
4054 (fun () -> fstate.fontsize
)
4055 (fun v -> setfontsize (bound v 5 100));
4056 colorp "background color"
4057 (fun () -> conf.bgcolor
)
4058 (fun v -> conf.bgcolor
<- v);
4059 src#
bool "crop hack"
4060 (fun () -> conf.crophack
)
4061 (fun v -> conf.crophack
<- v);
4062 src#
string "trim fuzz"
4063 (fun () -> irect_to_string conf.trimfuzz
)
4066 conf.trimfuzz
<- irect_of_string v;
4068 then settrim true conf.trimfuzz
;
4070 state.text <- Printf.sprintf
"bad irect `%s': %s"
4071 v (Printexc.to_string exn
)
4073 src#
string "throttle"
4075 match conf.maxwait
with
4076 | None
-> "show place holder if page is not ready"
4079 then "wait for page to fully render"
4081 "wait " ^ string_of_float
time
4082 ^
" seconds before showing placeholder"
4086 let f = float_of_string
v in
4088 then conf.maxwait
<- None
4089 else conf.maxwait
<- Some
f
4091 state.text <- Printf.sprintf
"bad time `%s': %s"
4092 v (Printexc.to_string exn
)
4094 src#
string "ghyll scroll"
4096 match conf.ghyllscroll
with
4098 | Some nab
-> ghyllscroll_to_string nab
4103 if String.length
v = 0
4105 else Some
(ghyllscroll_of_string v)
4107 conf.ghyllscroll
<- gs
4109 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4110 v (Printexc.to_string exn
)
4112 src#
string "selection command"
4113 (fun () -> conf.selcmd
)
4114 (fun v -> conf.selcmd
<- v);
4115 src#colorspace
"color space"
4116 (fun () -> colorspace_to_string conf.colorspace
)
4118 conf.colorspace
<- colorspace_of_int v;
4125 src#caption
"Document" 0;
4126 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4127 src#caption2
"Pages"
4128 (fun () -> string_of_int
state.pagecount
) 1;
4129 src#caption2
"Dimensions"
4130 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4134 src#caption
"Trimmed margins" 0;
4135 src#caption2
"Dimensions"
4136 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4139 src#reset prevmode prevuioh
;
4143 let prevmode = state.mode
4144 and prevuioh
= state.uioh in
4145 fillsrc prevmode prevuioh
;
4146 let source = (src :> lvsource
) in
4147 let modehash = findkeyhash conf "info" in
4148 state.uioh <- coe (object (self)
4149 inherit listview ~
source ~trusted
:true ~
modehash as super
4150 val mutable m_prevmemused
= 0
4151 method infochanged
= function
4153 if m_prevmemused
!= state.memused
4155 m_prevmemused
<- state.memused
;
4156 G.postRedisplay "memusedchanged";
4158 | Pdim
-> G.postRedisplay "pdimchanged"
4159 | Docinfo
-> fillsrc prevmode prevuioh
4161 method key key mask
=
4162 if not
(Wsi.withctrl mask
)
4165 | 0xff51 -> coe (self#updownlevel ~
-1)
4166 | 0xff53 -> coe (self#updownlevel
1)
4167 | _ -> super#
key key mask
4168 else super#
key key mask
4170 G.postRedisplay "info";
4176 inherit lvsourcebase
4177 method getitemcount
= Array.length
state.help
4179 let s, n, _ = state.help
.(n) in
4182 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4186 m_qsearch
<- qsearch;
4187 match state.help
.(active) with
4188 | _, _, Action
f -> Some
(f uioh)
4198 method hasaction
n =
4199 match state.help
.(n) with
4200 | _, _, Action
_ -> true
4207 let modehash = findkeyhash conf "help" in
4208 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4209 G.postRedisplay "help";
4214 let re = Str.regexp
"[\r\n]" in
4216 inherit lvsourcebase
4217 val mutable m_items
= [||]
4219 method getitemcount
= 1 + Array.length m_items
4224 else m_items
.(n-1), 0
4226 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4231 then Buffer.clear
state.errmsgs
;
4232 m_qsearch
<- qsearch;
4239 method hasaction
n =
4243 state.newerrmsgs
<- false;
4244 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4245 m_items
<- Array.of_list
l
4253 let source = (msgsource :> lvsource
) in
4254 let modehash = findkeyhash conf "listview" in
4255 state.uioh <- coe (object
4256 inherit listview ~
source ~trusted
:false ~
modehash as super
4259 then msgsource#reset
;
4262 G.postRedisplay "msgs";
4265 let quickbookmark ?title
() =
4266 match state.layout with
4272 let sec = Unix.gettimeofday
() in
4273 let tm = Unix.localtime
sec in
4274 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4278 (tm.Unix.tm_year
+ 1900)
4281 | Some
title -> title
4284 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4289 state.fullscreen
<- None
;
4293 let setautoscrollspeed step goingdown
=
4294 let incr = max
1 ((abs step
) / 2) in
4295 let incr = if goingdown
then incr else -incr in
4296 let astep = step
+ incr in
4297 state.autoscroll
<- Some
astep;
4300 let viewkeyboard key mask
=
4302 let mode = state.mode in
4303 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4306 G.postRedisplay "view:enttext"
4308 let ctrl = Wsi.withctrl mask
in
4313 | 0xff63 -> (* insert *)
4314 if conf.angle
mod 360 = 0
4316 state.mode <- LinkNav
(Ltgendir
0);
4319 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4321 | 0xff1b | 113 -> (* escape / q *)
4322 begin match state.mstate
with
4324 state.mstate
<- Mnone
;
4325 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4326 G.postRedisplay "kill zoom rect";
4328 match state.ranchors
with
4330 | (path
, password
, anchor) :: rest
->
4331 state.ranchors
<- rest
;
4332 state.anchor <- anchor;
4333 opendoc path password
4336 | 0xff08 -> (* backspace *)
4337 let y = getnav ~
-1 in
4338 gotoy_and_clear_text y
4346 G.postRedisplay "dehighlight";
4348 | 47 | 63 -> (* / ? *)
4349 let ondone isforw
s =
4350 cbput state.hists
.pat
s;
4351 state.searchpattern
<- s;
4354 let s = String.create
1 in
4355 s.[0] <- Char.chr
key;
4356 enttext (s, "", Some
(onhist state.hists
.pat
),
4357 textentry, ondone (key = 47))
4359 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4360 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4361 setzoom (conf.zoom +. incr)
4363 | 43 | 0xffab -> (* + *)
4366 try int_of_string
s with exc
->
4367 state.text <- Printf.sprintf
"bad integer `%s': %s"
4368 s (Printexc.to_string exc
);
4374 state.text <- "page bias is now " ^ string_of_int
n;
4377 enttext ("page bias: ", "", None
, intentry, ondone)
4379 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4380 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4381 setzoom (max
0.01 (conf.zoom -. decr))
4383 | 45 | 0xffad -> (* - *)
4384 let ondone msg
= state.text <- msg
in
4386 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4387 optentry state.mode, ondone
4390 | 48 when ctrl -> (* ctrl-0 *)
4393 | 49 when ctrl -> (* 1 *)
4394 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4398 | 0xffc6 -> (* f9 *)
4401 | 57 when ctrl -> (* ctrl-9 *)
4404 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4405 when not
ctrl -> (* 0..9 *)
4408 try int_of_string
s with exc
->
4409 state.text <- Printf.sprintf
"bad integer `%s': %s"
4410 s (Printexc.to_string exc
);
4416 cbput state.hists
.pag
(string_of_int
n);
4417 gotopage1 (n + conf.pagebias
- 1) 0;
4420 let pageentry text key =
4421 match Char.unsafe_chr
key with
4422 | 'g'
-> TEdone
text
4423 | _ -> intentry text key
4425 let text = "x" in text.[0] <- Char.chr
key;
4426 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4429 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4430 reshape conf.winw
conf.winh
;
4433 conf.hlinks
<- not
conf.hlinks
;
4434 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4435 G.postRedisplay "toggle highlightlinks";
4438 begin match state.autoscroll
with
4440 conf.autoscrollstep
<- step
;
4441 state.autoscroll
<- None
4443 if conf.autoscrollstep
= 0
4444 then state.autoscroll
<- Some
1
4445 else state.autoscroll
<- Some
conf.autoscrollstep
4449 conf.presentation <- not
conf.presentation;
4450 if conf.presentation
4452 if not
conf.scrollbarinpm
4453 then state.scrollw
<- 0;
4456 state.scrollw
<- conf.scrollbw
;
4458 showtext ' '
("presentation mode " ^
4459 if conf.presentation then "on" else "off");
4460 state.anchor <- getanchor ();
4464 begin match state.fullscreen
with
4466 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4469 state.fullscreen
<- None
;
4474 gotoy_and_clear_text 0
4477 gotopage1 (state.pagecount
- 1) 0
4479 | 112 | 78 -> (* p|N *)
4480 search state.searchpattern
false
4482 | 110 | 0xffc0 -> (* n|F3 *)
4483 search state.searchpattern
true
4486 begin match state.layout with
4489 gotoy_and_clear_text (getpagey l.pageno)
4493 begin match List.rev
state.layout with
4496 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4497 gotoy_and_clear_text (getpagey pageno)
4500 | 0xff9f | 0xffff -> (* delete *)
4501 begin match state.layout with
4504 let pageno = max
0 (l.pageno-1) in
4505 gotoy_and_clear_text (getpagey pageno)
4509 showtext ' '
(describe_location ());
4512 begin match state.layout with
4515 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4520 enterbookmarkmode ()
4522 | 104 | 0xffbe -> (* h|F1 *)
4528 | 101 when conf.redirectstderr -> (* e *)
4533 match state.layout with
4536 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4540 enttext ("bookmark: ", "", None
, textentry, ondone)
4544 showtext ' '
"Quick bookmark added";
4547 begin match state.layout with
4549 let rect = getpdimrect
l.pagedimno
in
4553 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4554 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4556 (truncate
(rect.(1) -. rect.(0)),
4557 truncate
(rect.(3) -. rect.(0)))
4559 let w = truncate
((float w)*.conf.zoom)
4560 and h = truncate
((float h)*.conf.zoom) in
4563 state.anchor <- getanchor ();
4564 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4566 G.postRedisplay "z";
4571 | 50 when ctrl -> (* ctrl-2 *)
4572 let maxw = getmaxw
() in
4574 then setzoom (maxw /. float conf.winw
)
4576 | 60 | 62 -> (* < > *)
4577 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4579 | 91 | 93 -> (* [ ] *)
4581 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4583 G.postRedisplay "brightness";
4585 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4586 setzoom state.prevzoom
4588 | 107 | 0xff52 -> (* k up *)
4589 begin match state.autoscroll
with
4591 begin match state.mode with
4592 | Birdseye beye
-> upbirdseye 1 beye
4595 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4596 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4599 setautoscrollspeed n false
4602 | 106 | 0xff54 -> (* j down *)
4603 begin match state.autoscroll
with
4605 begin match state.mode with
4606 | Birdseye beye
-> downbirdseye 1 beye
4609 then gotoy_and_clear_text (clamp (conf.winh
/2))
4610 else gotoy_and_clear_text (clamp conf.scrollstep
)
4613 setautoscrollspeed n true
4616 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4624 let dx = if key = 0xff51 then dx else -dx in
4625 state.x <- state.x + dx;
4626 gotoy_and_clear_text state.y
4629 G.postRedisplay "lef/right"
4632 | 0xff55 -> (* prior *)
4636 match state.layout with
4638 | l :: _ -> state.y - l.pagey
4644 | 0xff56 -> (* next *)
4648 match List.rev
state.layout with
4650 | l :: _ -> getpagey l.pageno
4656 | 0xff50 -> gotoghyll 0
4657 | 0xff57 -> gotoghyll (clamp state.maxy)
4658 | 0xff53 when Wsi.withalt mask
->
4659 gotoghyll (getnav ~
-1)
4660 | 0xff51 when Wsi.withalt mask
->
4661 gotoghyll (getnav 1)
4664 state.anchor <- getanchor ();
4665 opendoc state.path
state.password
4670 | 118 when conf.debug
-> (* v *)
4673 match getopaque l.pageno with
4676 let x0, y0, x1, y1 = pagebbox opaque
in
4677 let a,b = float x0, float y0 in
4678 let c,d = float x1, float y0 in
4679 let e,f = float x1, float y1 in
4680 let h,j
= float x0, float y1 in
4681 let rect = (a,b,c,d,e,f,h,j
) in
4683 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4685 G.postRedisplay "v";
4688 vlog "huh? %s" (Wsi.keyname
key)
4691 let gotounder = function
4692 | Ulinkgoto
(pageno, top) ->
4696 gotopage1 pageno top;
4702 | Uremote
(filename
, pageno) ->
4704 if Sys.file_exists filename
4707 let dir = Filename.dirname
state.path in
4708 let path = Filename.concat
dir filename
in
4709 if Sys.file_exists
path
4713 if String.length
path > 0
4715 let anchor = getanchor () in
4716 let ranchor = state.path, state.password
, anchor in
4717 state.anchor <- (pageno, 0.0);
4718 state.ranchors
<- ranchor :: state.ranchors
;
4721 else showtext '
!'
("Could not find " ^ filename
)
4723 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4726 let linknavkeyboard key mask
linknav =
4727 let getpage pageno =
4728 let rec loop = function
4730 | l :: _ when l.pageno = pageno -> Some
l
4731 | _ :: rest
-> loop rest
4732 in loop state.layout
4734 let doexact (pageno, n) =
4735 match getopaque pageno, getpage pageno with
4736 | Some opaque
, Some
l ->
4739 let under = getlink opaque
n in
4740 G.postRedisplay "link gotounder";
4746 | 0xff50 -> (* home *)
4747 Some
(findlink opaque LDfirst
), -1
4749 | 0xff57 -> (* end *)
4750 Some
(findlink opaque LDlast
), 1
4752 | 0xff51 -> (* left *)
4753 Some
(findlink opaque
(LDleft
n)), -1
4755 | 0xff53 -> (* right *)
4756 Some
(findlink opaque
(LDright
n)), 1
4758 | 0xff52 -> (* up *)
4759 Some
(findlink opaque
(LDup
n)), -1
4761 | 0xff54 -> (* down *)
4762 Some
(findlink opaque
(LDdown
n)), 1
4767 begin match findpwl
l.pageno dir with
4771 state.mode <- LinkNav
(Ltgendir
dir);
4772 let y, h = getpageyh pageno in
4775 then y + h - conf.winh
4780 begin match getopaque pageno, getpage pageno with
4781 | Some opaque
, Some
_ ->
4783 let ld = if dir > 0 then LDfirst
else LDlast
in
4786 begin match link with
4787 | Lfound
(m, x0, y0, x1, y1) ->
4788 let r = x0, y0, x1, y1 in
4789 showlinktype (getlink opaque
m);
4790 state.mode <- LinkNav
(Ltexact
((pageno, m), r));
4791 G.postRedisplay "linknav jpage";
4798 begin match opt with
4799 | Some Lnotfound
-> pwl l dir;
4800 | Some
(Lfound
(m, x0, y0, x1, y1)) ->
4805 then gotopage1 l.pageno y0
4807 let d = fstate.fontsize
+ 1 in
4808 if y1 - l.pagey > l.pagevh - d
4809 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
4810 else G.postRedisplay "linknav";
4812 let r = x0, y0, x1, y1 in
4813 showlinktype (getlink opaque
m);
4814 state.mode <- LinkNav
(Ltexact
((l.pageno, m), r));
4818 state.mode <- LinkNav
(Ltgendir
0);
4819 viewkeyboard key mask
4821 | _ -> viewkeyboard key mask
4826 G.postRedisplay "leave linknav"
4830 | Ltgendir
_ -> viewkeyboard key mask
4831 | Ltexact
(exact
, _) -> doexact exact
4834 let keyboard key mask
=
4835 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4836 then wcmd "interrupt"
4837 else state.uioh <- state.uioh#
key key mask
4840 let birdseyekeyboard key mask
4841 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4843 match conf.columns
with
4845 | Some
((c, _, _), _) -> c
4848 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4849 let y, h = getpageyh pageno in
4850 let top = (conf.winh
- h) / 2 in
4851 gotoy (max
0 (y - top))
4852 | 0xff0d -> leavebirdseye beye
false
4853 | 0xff1b -> leavebirdseye beye
true (* escape *)
4854 | 0xff52 -> upbirdseye incr beye
(* prior *)
4855 | 0xff54 -> downbirdseye incr beye
(* next *)
4856 | 0xff51 -> upbirdseye 1 beye
(* up *)
4857 | 0xff53 -> downbirdseye 1 beye
(* down *)
4860 begin match state.layout with
4864 state.mode <- Birdseye
(
4865 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4867 gotopage1 l.pageno 0;
4870 let layout = layout (state.y-conf.winh
) conf.winh
in
4872 | [] -> gotoy (clamp (-conf.winh
))
4874 state.mode <- Birdseye
(
4875 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4877 gotopage1 l.pageno 0
4880 | [] -> gotoy (clamp (-conf.winh
))
4884 begin match List.rev
state.layout with
4886 let layout = layout (state.y + conf.winh
) conf.winh
in
4887 begin match layout with
4889 let incr = l.pageh
- l.pagevh in
4894 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4896 G.postRedisplay "birdseye pagedown";
4898 else gotoy (clamp (incr + conf.interpagespace*2));
4902 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4903 gotopage1 l.pageno 0;
4906 | [] -> gotoy (clamp conf.winh
)
4910 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4914 let pageno = state.pagecount
- 1 in
4915 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4916 if not
(pagevisible state.layout pageno)
4919 match List.rev
state.pdims
with
4921 | (_, _, h, _) :: _ -> h
4923 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4924 else G.postRedisplay "birdseye end";
4925 | _ -> viewkeyboard key mask
4930 match state.mode with
4931 | Textentry
_ -> scalecolor 0.4
4933 | View
-> scalecolor 1.0
4934 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4935 if l.pageno = hooverpageno
4938 if l.pageno = pageno
4944 begin match getopaque l.pageno with
4946 if tileready l l.pagex l.pagey
4948 let x = l.pagedispx - l.pagex
4949 and y = l.pagedispy - l.pagey in
4950 postprocess opaque
conf.hlinks
x y;
4956 let scrollindicator () =
4957 let sbw, ph
, sh = state.uioh#
scrollph in
4958 let sbh, pw
, sw = state.uioh#scrollpw
in
4960 GlDraw.color (0.64, 0.64, 0.64);
4962 (float (conf.winw
- sbw), 0.)
4963 (float conf.winw
, float conf.winh
)
4966 (0., float (conf.winh
- sbh))
4967 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4969 GlDraw.color (0.0, 0.0, 0.0);
4972 (float (conf.winw
- sbw), ph
)
4973 (float conf.winw
, ph
+. sh)
4976 (pw
, float (conf.winh
- sbh))
4977 (pw
+. sw, float conf.winh
)
4982 match state.mstate
with
4983 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4986 | Msel
((x0, y0), (x1, y1)) ->
4987 let rec loop = function
4989 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4990 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4991 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4992 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4994 match getopaque l.pageno with
4996 let x0, y0 = pagetranslatepoint l x0 y0 in
4997 let x1, y1 = pagetranslatepoint l x1 y1 in
4998 seltext opaque
(x0, y0, x1, y1);
5006 let showrects rects
=
5008 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5009 GlDraw.polygon_mode `both `fill
;
5010 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5012 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5014 if l.pageno = pageno
5016 let dx = float (l.pagedispx - l.pagex) in
5017 let dy = float (l.pagedispy - l.pagey) in
5018 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5019 GlDraw.begins `quads
;
5021 GlDraw.vertex2
(x0+.dx, y0+.dy);
5022 GlDraw.vertex2
(x1+.dx, y1+.dy);
5023 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5024 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5035 GlClear.color (scalecolor2 conf.bgcolor
);
5036 GlClear.clear
[`
color];
5037 List.iter
drawpage state.layout;
5039 match state.mode with
5040 | LinkNav
(Ltexact
((pageno, _), (x0, y0, x1, y1))) ->
5052 begin match state.mstate
with
5053 | Mzoomrect
((x0, y0), (x1, y1)) ->
5055 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5056 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5057 GlDraw.rect (float x0, float y0)
5058 (float x1, float y1);
5067 let zoomrect x y x1 y1 =
5070 and y0 = min
y y1 in
5071 gotoy (state.y + y0);
5072 state.anchor <- getanchor ();
5073 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5075 if state.w < conf.winw
- state.scrollw
5076 then (conf.winw
- state.scrollw
- state.w) / 2
5079 state.x <- (state.x + margin) - x0;
5081 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5082 state.mstate
<- Mnone
;
5086 let winw = conf.winw - state.scrollw
- 1 in
5087 let s = float x /. float winw in
5088 let destx = truncate
(float (state.w + winw) *. s) in
5089 state.x <- winw - destx;
5090 gotoy_and_clear_text state.y;
5091 state.mstate
<- Mscrollx
;
5095 let s = float y /. float conf.winh
in
5096 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5097 gotoy_and_clear_text desty;
5098 state.mstate
<- Mscrolly
;
5101 let viewmouse button down
x y mask
=
5103 | n when (n == 4 || n == 5) && not down
->
5104 if Wsi.withctrl mask
5106 match state.mstate
with
5107 | Mzoom
(oldn
, i
) ->
5115 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5117 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5119 let zoom = conf.zoom -. incr in
5121 state.mstate
<- Mzoom
(n, 0);
5123 state.mstate
<- Mzoom
(n, i
+1);
5125 else state.mstate
<- Mzoom
(n, 0)
5127 | _ -> state.mstate
<- Mzoom
(n, 0)
5130 match state.autoscroll
with
5131 | Some step
-> setautoscrollspeed step
(n=4)
5135 then -conf.scrollstep
5136 else conf.scrollstep
5138 let incr = incr * 2 in
5139 let y = clamp incr in
5140 gotoy_and_clear_text y
5143 | 1 when Wsi.withctrl mask
->
5146 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5147 state.mstate
<- Mpan
(x, y)
5150 state.mstate
<- Mnone
5155 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5157 state.mstate
<- Mzoomrect
(p, p)
5160 match state.mstate
with
5161 | Mzoomrect
((x0, y0), _) ->
5162 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5163 then zoomrect x0 y0 x y
5165 state.mstate
<- Mnone
;
5166 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5167 G.postRedisplay "kill accidental zoom rect";
5170 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5171 state.mstate
<- Mnone
5174 | 1 when x > conf.winw - state.scrollw
->
5177 let _, position, sh = state.uioh#
scrollph in
5178 if y > truncate
position && y < truncate
(position +. sh)
5179 then state.mstate
<- Mscrolly
5182 state.mstate
<- Mnone
5184 | 1 when y > conf.winh
- state.hscrollh ->
5187 let _, position, sw = state.uioh#scrollpw
in
5188 if x > truncate
position && x < truncate
(position +. sw)
5189 then state.mstate
<- Mscrollx
5192 state.mstate
<- Mnone
5195 let dest = if down
then getunder x y else Unone
in
5196 begin match dest with
5197 | Ulinkgoto
(pageno, top) ->
5201 gotopage1 pageno top;
5207 | Uremote
(filename
, pageno) ->
5209 if Sys.file_exists filename
5212 let dir = Filename.dirname
state.path in
5213 let path = Filename.concat
dir filename
in
5214 if Sys.file_exists
path
5218 if String.length
path > 0
5220 let anchor = getanchor () in
5221 let ranchor = state.path, state.password
, anchor in
5222 state.anchor <- (pageno, 0.0);
5223 state.ranchors
<- ranchor :: state.ranchors
;
5226 else showtext '
!'
("Could not find " ^ filename
)
5228 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
5230 | Unone
when down
->
5231 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5232 state.mstate
<- Mpan
(x, y);
5234 | Unone
| Utext
_ ->
5237 if conf.angle
mod 360 = 0
5239 state.mstate
<- Msel
((x, y), (x, y));
5240 G.postRedisplay "mouse select";
5244 match state.mstate
with
5247 | Mzoom
_ | Mscrollx
| Mscrolly
->
5248 state.mstate
<- Mnone
5250 | Mzoomrect
((x0, y0), _) ->
5254 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5255 state.mstate
<- Mnone
5257 | Msel
((_, y0), (_, y1)) ->
5258 let rec loop = function
5261 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5262 || ((y1 >= l.pagedispy
5263 && y1 <= (l.pagedispy + l.pagevh)))
5265 match getopaque l.pageno with
5267 copysel
conf.selcmd opaque
;
5268 G.postRedisplay "copysel"
5273 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5274 state.mstate
<- Mnone
;
5281 let birdseyemouse button down
x y mask
5282 (conf, leftx
, _, hooverpageno
, anchor) =
5285 let rec loop = function
5288 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5289 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5291 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5297 | _ -> viewmouse button down
x y mask
5300 let mouse button down
x y mask
=
5301 state.uioh <- state.uioh#button button down
x y mask
;
5305 state.uioh <- state.uioh#
motion x y
5309 state.uioh <- state.uioh#
pmotion x y;
5315 method key key mask
=
5316 begin match state.mode with
5317 | Textentry
textentry -> textentrykeyboard key mask
textentry
5318 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5319 | View
-> viewkeyboard key mask
5320 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5324 method button button bstate
x y mask
=
5325 begin match state.mode with
5327 | View
-> viewmouse button bstate
x y mask
5328 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5334 begin match state.mode with
5336 | View
| Birdseye
_ | LinkNav
_ ->
5337 match state.mstate
with
5338 | Mzoom
_ | Mnone
-> ()
5343 state.mstate
<- Mpan
(x, y);
5344 if conf.zoom > 1.0 then state.x <- state.x + dx;
5346 gotoy_and_clear_text y
5349 state.mstate
<- Msel
(a, (x, y));
5350 G.postRedisplay "motion select";
5353 let y = min
conf.winh
(max
0 y) in
5357 let x = min
conf.winw (max
0 x) in
5360 | Mzoomrect
(p0
, _) ->
5361 state.mstate
<- Mzoomrect
(p0
, (x, y));
5362 G.postRedisplay "motion zoomrect";
5366 method pmotion x y =
5367 begin match state.mode with
5368 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5369 let rec loop = function
5371 if hooverpageno
!= -1
5373 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5374 G.postRedisplay "pmotion birdseye no hoover";
5377 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5378 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5380 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5381 G.postRedisplay "pmotion birdseye hoover";
5391 match state.mstate
with
5392 | Mnone
-> updateunder x y
5393 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5398 method infochanged
_ = ()
5401 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5402 let p, h = scrollph state.y maxy in
5406 let winw = conf.winw - state.scrollw
- 1 in
5407 let fwinw = float winw in
5409 let sw = fwinw /. float state.w in
5410 let sw = fwinw *. sw in
5411 max
sw (float conf.scrollh
)
5414 let f = state.w+winw in
5415 let r = float (winw-state.x) /. float f in
5416 let p = fwinw *. r in
5420 if position +. sw > fwinw
5421 then fwinw -. position
5424 state.hscrollh, position, sw
5428 match state.mode with
5429 | LinkNav
_ -> "links"
5430 | Textentry
_ -> "textentry"
5431 | Birdseye
_ -> "birdseye"
5434 findkeyhash conf modename
5441 let fontpath = ref "";;
5444 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5447 let l = String.length
s in
5448 let b = Buffer.create
l in
5454 try Sys.getenv
"HOME"
5457 ("Can not determine home directory location: " ^
5458 Printexc.to_string exn
);
5462 let modifier_of_string = function
5463 | "alt" -> Wsi.altmask
5464 | "shift" -> Wsi.shiftmask
5465 | "ctrl" | "control" -> Wsi.ctrlmask
5466 | "meta" -> Wsi.metamask
5471 let r = Str.regexp
"-" in
5473 let elems = Str.full_split
r s in
5476 let m1 = modifier_of_string s in
5478 then (Wsi.namekey
s, m)
5481 | Str.Delim
s when n land 1 = 0 -> g s
5483 | Str.Delim
_ -> (k
, m)
5485 let rec loop n k
m = function
5488 let k, m = f n k m x in
5494 let keys_of_string =
5495 let r = Str.regexp
"[ \t]" in
5497 let elems = Str.split
r s in
5498 List.map
key_of_string elems
5501 let copykeyhashes c =
5502 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5505 let config_of c attrs
=
5509 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5510 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5511 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5512 | "preload" -> { c with preload = bool_of_string
v }
5513 | "page-bias" -> { c with pagebias
= int_of_string
v }
5514 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5515 | "auto-scroll-step" ->
5516 { c with autoscrollstep
= max
0 (int_of_string
v) }
5517 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5518 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5521 match String.lowercase
v with
5522 | "true" -> Some infinity
5524 | f -> Some
(float_of_string
f)
5526 { c with maxwait
= mw}
5527 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5528 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5529 | "vertical-margin" ->
5530 { c with interpagespace = max
0 (int_of_string
v) }
5532 let zoom = float_of_string
v /. 100. in
5533 let zoom = max
zoom 0.0 in
5534 { c with zoom = zoom }
5535 | "presentation" -> { c with presentation = bool_of_string
v }
5536 | "rotation-angle" -> { c with angle
= int_of_string
v }
5537 | "width" -> { c with winw = max
20 (int_of_string
v) }
5538 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5539 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5540 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5541 | "pixmap-cache-size" ->
5542 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5543 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5544 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5545 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5546 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5547 | "background-color" -> { c with bgcolor
= color_of_string v }
5548 | "scrollbar-in-presentation" ->
5549 { c with scrollbarinpm
= bool_of_string
v }
5550 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5551 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5552 | "mupdf-store-size" ->
5553 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5554 | "checkers" -> { c with checkers
= bool_of_string
v }
5555 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5556 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5557 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5558 | "uri-launcher" -> { c with urilauncher
= unent v }
5559 | "path-launcher" -> { c with pathlauncher
= unent v }
5560 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5561 | "invert-colors" -> { c with invert
= bool_of_string
v }
5562 | "brightness" -> { c with colorscale
= float_of_string
v }
5563 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5565 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5567 let nab = columns_of_string v in
5568 { c with columns
= Some
(nab, [||]) }
5569 | "birds-eye-columns" ->
5570 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5571 | "selection-command" -> { c with selcmd
= unent v }
5572 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5575 prerr_endline
("Error processing attribute (`" ^
5576 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5579 let rec fold c = function
5582 let c = apply c k v in
5585 fold { c with keyhashes
= copykeyhashes c } attrs
;
5588 let fromstring f pos
n v d =
5591 dolog "Error processing attribute (%S=%S) at %d\n%s"
5592 n v pos
(Printexc.to_string exn
)
5597 let bookmark_of attrs
=
5598 let rec fold title page
rely = function
5599 | ("title", v) :: rest
-> fold v page
rely rest
5600 | ("page", v) :: rest
-> fold title v rely rest
5601 | ("rely", v) :: rest
-> fold title page
v rest
5602 | _ :: rest
-> fold title page
rely rest
5603 | [] -> title, page
, rely
5605 fold "invalid" "0" "0" attrs
5609 let rec fold path page
rely pan
= function
5610 | ("path", v) :: rest
-> fold v page
rely pan rest
5611 | ("page", v) :: rest
-> fold path v rely pan rest
5612 | ("rely", v) :: rest
-> fold path page
v pan rest
5613 | ("pan", v) :: rest
-> fold path page
rely v rest
5614 | _ :: rest
-> fold path page
rely pan rest
5615 | [] -> path, page
, rely, pan
5617 fold "" "0" "0" "0" attrs
5621 let rec fold rs ls
= function
5622 | ("out", v) :: rest
-> fold v ls rest
5623 | ("in", v) :: rest
-> fold rs
v rest
5624 | _ :: rest
-> fold ls rs rest
5630 let setconf dst
src =
5631 dst
.scrollbw
<- src.scrollbw
;
5632 dst
.scrollh
<- src.scrollh
;
5633 dst
.icase
<- src.icase
;
5634 dst
.preload <- src.preload;
5635 dst
.pagebias
<- src.pagebias
;
5636 dst
.verbose
<- src.verbose
;
5637 dst
.scrollstep
<- src.scrollstep
;
5638 dst
.maxhfit
<- src.maxhfit
;
5639 dst
.crophack
<- src.crophack
;
5640 dst
.autoscrollstep
<- src.autoscrollstep
;
5641 dst
.maxwait
<- src.maxwait
;
5642 dst
.hlinks
<- src.hlinks
;
5643 dst
.underinfo
<- src.underinfo
;
5644 dst
.interpagespace <- src.interpagespace;
5645 dst
.zoom <- src.zoom;
5646 dst
.presentation <- src.presentation;
5647 dst
.angle
<- src.angle
;
5648 dst
.winw <- src.winw;
5649 dst
.winh
<- src.winh
;
5650 dst
.savebmarks
<- src.savebmarks
;
5651 dst
.memlimit
<- src.memlimit
;
5652 dst
.proportional
<- src.proportional
;
5653 dst
.texcount
<- src.texcount
;
5654 dst
.sliceheight
<- src.sliceheight
;
5655 dst
.thumbw
<- src.thumbw
;
5656 dst
.jumpback
<- src.jumpback
;
5657 dst
.bgcolor
<- src.bgcolor
;
5658 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5659 dst
.tilew
<- src.tilew
;
5660 dst
.tileh
<- src.tileh
;
5661 dst
.mustoresize
<- src.mustoresize
;
5662 dst
.checkers
<- src.checkers
;
5663 dst
.aalevel
<- src.aalevel
;
5664 dst
.trimmargins
<- src.trimmargins
;
5665 dst
.trimfuzz
<- src.trimfuzz
;
5666 dst
.urilauncher
<- src.urilauncher
;
5667 dst
.colorspace
<- src.colorspace
;
5668 dst
.invert
<- src.invert
;
5669 dst
.colorscale
<- src.colorscale
;
5670 dst
.redirectstderr <- src.redirectstderr;
5671 dst
.ghyllscroll
<- src.ghyllscroll
;
5672 dst
.columns
<- src.columns
;
5673 dst
.beyecolumns
<- src.beyecolumns
;
5674 dst
.selcmd
<- src.selcmd
;
5675 dst
.updatecurs
<- src.updatecurs
;
5676 dst
.pathlauncher
<- src.pathlauncher
;
5677 dst
.keyhashes
<- copykeyhashes src;
5681 let h = Hashtbl.create
10 in
5682 let dc = { defconf with angle
= defconf.angle
} in
5683 let rec toplevel v t spos
_ =
5685 | Vdata
| Vcdata
| Vend
-> v
5686 | Vopen
("llppconfig", _, closed
) ->
5689 else { v with f = llppconfig
}
5691 error
"unexpected subelement at top level" s spos
5692 | Vclose
_ -> error
"unexpected close at top level" s spos
5694 and llppconfig
v t spos
_ =
5696 | Vdata
| Vcdata
-> v
5697 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5698 | Vopen
("defaults", attrs
, closed
) ->
5699 let c = config_of dc attrs
in
5703 else { v with f = defaults
}
5705 | Vopen
("ui-font", attrs
, closed
) ->
5706 let rec getsize size
= function
5708 | ("size", v) :: rest
->
5710 fromstring int_of_string spos
"size" v fstate.fontsize
in
5712 | l -> getsize size l
5714 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5717 else { v with f = uifont
(Buffer.create
10) }
5719 | Vopen
("doc", attrs
, closed
) ->
5720 let pathent, spage
, srely
, span
= doc_of attrs
in
5721 let path = unent pathent
5722 and pageno = fromstring int_of_string spos
"page" spage
0
5723 and rely = fromstring float_of_string spos
"rely" srely
0.0
5724 and pan
= fromstring int_of_string spos
"pan" span
0 in
5725 let c = config_of dc attrs
in
5726 let anchor = (pageno, rely) in
5728 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5729 else { v with f = doc
path pan
anchor c [] }
5732 error
"unexpected subelement in llppconfig" s spos
5734 | Vclose
"llppconfig" -> { v with f = toplevel }
5735 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5737 and defaults
v t spos
_ =
5739 | Vdata
| Vcdata
-> v
5740 | Vend
-> error
"unexpected end of input in defaults" s spos
5741 | Vopen
("keymap", attrs
, closed
) ->
5743 try List.assoc
"mode" attrs
5744 with Not_found
-> "global" in
5749 let h = findkeyhash dc modename in
5750 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5753 { v with f = pkeymap
ret KeyMap.empty }
5755 | Vopen
(_, _, _) ->
5756 error
"unexpected subelement in defaults" s spos
5758 | Vclose
"defaults" ->
5759 { v with f = llppconfig
}
5761 | Vclose
_ -> error
"unexpected close in defaults" s spos
5763 and uifont
b v t spos
epos =
5766 Buffer.add_substring
b s spos
(epos - spos
);
5768 | Vopen
(_, _, _) ->
5769 error
"unexpected subelement in ui-font" s spos
5770 | Vclose
"ui-font" ->
5771 if String.length
!fontpath = 0
5772 then fontpath := Buffer.contents
b;
5773 { v with f = llppconfig
}
5774 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5775 | Vend
-> error
"unexpected end of input in ui-font" s spos
5777 and doc
path pan
anchor c bookmarks
v t spos
_ =
5779 | Vdata
| Vcdata
-> v
5780 | Vend
-> error
"unexpected end of input in doc" s spos
5781 | Vopen
("bookmarks", _, closed
) ->
5784 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5786 | Vopen
("keymap", attrs
, closed
) ->
5788 try List.assoc
"mode" attrs
5789 with Not_found
-> "global"
5795 let h = findkeyhash c modename in
5796 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5797 doc
path pan
anchor c bookmarks
5799 { v with f = pkeymap
ret KeyMap.empty }
5801 | Vopen
(_, _, _) ->
5802 error
"unexpected subelement in doc" s spos
5805 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5806 { v with f = llppconfig
}
5808 | Vclose
_ -> error
"unexpected close in doc" s spos
5810 and pkeymap
ret keymap
v t spos
_ =
5812 | Vdata
| Vcdata
-> v
5813 | Vend
-> error
"unexpected end of input in keymap" s spos
5814 | Vopen
("map", attrs
, closed
) ->
5815 let r, l = map_of attrs
in
5816 let kss = fromstring keys_of_string spos
"in" r [] in
5817 let lss = fromstring keys_of_string spos
"out" l [] in
5821 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5822 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5825 then { v with f = pkeymap
ret keymap }
5828 { v with f = skip
"map" f }
5831 error
"unexpected subelement in keymap" s spos
5833 | Vclose
"keymap" ->
5834 { v with f = ret keymap }
5836 | Vclose
_ -> error
"unexpected close in keymap" s spos
5838 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5840 | Vdata
| Vcdata
-> v
5841 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5842 | Vopen
("item", attrs
, closed
) ->
5843 let titleent, spage
, srely
= bookmark_of attrs
in
5844 let page = fromstring int_of_string spos
"page" spage
0
5845 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5846 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5848 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5851 { v with f = skip
"item" f }
5854 error
"unexpected subelement in bookmarks" s spos
5856 | Vclose
"bookmarks" ->
5857 { v with f = doc
path pan
anchor c bookmarks }
5859 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5861 and skip tag
f v t spos
_ =
5863 | Vdata
| Vcdata
-> v
5865 error
("unexpected end of input in skipped " ^ tag
) s spos
5866 | Vopen
(tag'
, _, closed
) ->
5870 let f'
() = { v with f = skip tag
f } in
5871 { v with f = skip tag'
f'
}
5875 else error
("unexpected close in skipped " ^ tag
) s spos
5878 parse
{ f = toplevel; accu = () } s;
5884 let len = in_channel_length ic
in
5885 let s = String.create
len in
5886 really_input ic
s 0 len;
5889 | Parse_error
(msg
, s, pos
) ->
5890 let subs = subs s pos
in
5891 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5892 failwith
("parse error: " ^
s)
5895 failwith
("config load error: " ^
Printexc.to_string exn
)
5901 let dir = Filename.concat
home ".config" in
5902 if Sys.is_directory
dir then dir else home
5905 Filename.concat
dir "llpp.conf"
5908 let confpath = ref defconfpath;;
5911 if Sys.file_exists
!confpath
5914 (try Some
(open_in_bin
!confpath)
5917 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5918 Printexc.to_string exn
);
5927 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5928 Printexc.to_string exn
);
5934 f (Hashtbl.create
0, defconf)
5939 let pc, pb
, px, pa
=
5941 Hashtbl.find h (Filename.basename
state.path)
5942 with Not_found
-> dc, [], 0, (0, 0.0)
5946 state.bookmarks <- pb
;
5948 state.scrollw
<- conf.scrollbw
;
5950 then state.anchor <- pa
;
5951 cbput state.hists
.nav pa
;
5956 let add_attrs bb always
dc c =
5959 then Printf.bprintf bb
"\n %s='%b'" s a
5962 then Printf.bprintf bb
"\n %s='%d'" s a
5965 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5968 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5971 then Printf.bprintf bb
"\n %s='%f'" s a
5975 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5979 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5983 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5987 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5993 | Some
(_N
, _A
, _B
) ->
5994 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6004 else string_of_float
f
6006 Printf.bprintf bb
"\n %s='%s'" s v
6011 | Some
((n, a, b), _) when n > 1 ->
6012 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6018 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6023 then dc.winw, dc.winh
6025 match state.fullscreen
with
6027 | None
-> c.winw, c.winh
6029 let zoom, presentation, interpagespace, maxwait
=
6031 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6033 match state.mode with
6034 | Birdseye
(bc
, _, _, _, _) ->
6035 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6036 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6038 oi
"width" w dc.winw;
6039 oi
"height" h dc.winh
;
6040 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6041 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6042 ob "case-insensitive-search" c.icase
dc.icase
;
6043 ob "preload" c.preload dc.preload;
6044 oi
"page-bias" c.pagebias
dc.pagebias
;
6045 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6046 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6047 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6048 ob "crop-hack" c.crophack
dc.crophack
;
6049 oW
"throttle" maxwait
dc.maxwait
;
6050 ob "highlight-links" c.hlinks
dc.hlinks
;
6051 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6052 oi
"vertical-margin" interpagespace dc.interpagespace;
6053 oz
"zoom" zoom dc.zoom;
6054 ob "presentation" presentation dc.presentation;
6055 oi
"rotation-angle" c.angle
dc.angle
;
6056 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6057 ob "proportional-display" c.proportional
dc.proportional
;
6058 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6059 oi
"tex-count" c.texcount
dc.texcount
;
6060 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6061 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6062 ob "persistent-location" c.jumpback
dc.jumpback
;
6063 oc
"background-color" c.bgcolor
dc.bgcolor
;
6064 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6065 oi
"tile-width" c.tilew
dc.tilew
;
6066 oi
"tile-height" c.tileh
dc.tileh
;
6067 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6068 ob "checkers" c.checkers
dc.checkers
;
6069 oi
"aalevel" c.aalevel
dc.aalevel
;
6070 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6071 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6072 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6073 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6074 oC
"color-space" c.colorspace
dc.colorspace
;
6075 ob "invert-colors" c.invert
dc.invert
;
6076 oF
"brightness" c.colorscale
dc.colorscale
;
6077 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6078 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6079 oco
"columns" c.columns
dc.columns
;
6080 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6081 os
"selection-command" c.selcmd
dc.selcmd
;
6082 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6085 let keymapsbuf always
dc c =
6086 let bb = Buffer.create
16 in
6087 let rec loop = function
6089 | (modename, h) :: rest
->
6090 let dh = findkeyhash dc modename in
6091 if always
|| h <> dh
6093 if Hashtbl.length
h > 0
6095 if Buffer.length
bb > 0
6096 then Buffer.add_char
bb '
\n'
;
6097 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6098 Hashtbl.iter
(fun i
o ->
6099 let isdifferent = always
||
6101 let dO = Hashtbl.find dh i
in
6103 with Not_found
-> true
6108 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6109 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6110 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6111 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6112 Buffer.add_string
bb (Wsi.keyname
k);
6115 let rec loop = function
6117 | km
:: [] -> addkm km
6118 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6122 Buffer.add_string
bb "<map in='";
6126 Buffer.add_string
bb "' out='";
6128 Buffer.add_string
bb "'/>\n"
6131 Buffer.add_string
bb "' out='";
6133 Buffer.add_string
bb "'/>\n"
6135 | KMmulti
(ins, kms
) ->
6136 Buffer.add_char
bb ' '
;
6138 Buffer.add_string
bb "' out='";
6140 Buffer.add_string
bb "'/>\n"
6142 Buffer.add_string
bb "</keymap>";
6152 let uifontsize = fstate.fontsize
in
6153 let bb = Buffer.create
32768 in
6155 let dc = if conf.bedefault
then conf else dc in
6156 Buffer.add_string
bb "<llppconfig>\n";
6158 if String.length
!fontpath > 0
6160 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6166 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6169 Buffer.add_string
bb "<defaults ";
6170 add_attrs bb true dc dc;
6171 let kb = keymapsbuf true dc dc in
6172 if Buffer.length
kb > 0
6174 Buffer.add_string
bb ">\n";
6175 Buffer.add_buffer
bb kb;
6176 Buffer.add_string
bb "\n</defaults>\n";
6178 else Buffer.add_string
bb "/>\n";
6180 let adddoc path pan
anchor c bookmarks =
6181 if bookmarks == [] && c = dc && anchor = emptyanchor
6184 Printf.bprintf
bb "<doc path='%s'"
6185 (enent
path 0 (String.length
path));
6187 if anchor <> emptyanchor
6189 let n, y = anchor in
6190 Printf.bprintf
bb " page='%d'" n;
6193 Printf.bprintf
bb " rely='%f'" y
6198 then Printf.bprintf
bb " pan='%d'" pan
;
6200 add_attrs bb false dc c;
6201 let kb = keymapsbuf false dc c in
6203 begin match bookmarks with
6205 if Buffer.length
kb > 0
6207 Buffer.add_string
bb ">\n";
6208 Buffer.add_buffer
bb kb;
6209 Buffer.add_string
bb "</doc>\n";
6211 else Buffer.add_string
bb "/>\n"
6213 Buffer.add_string
bb ">\n<bookmarks>\n";
6214 List.iter
(fun (title, _level
, (page, rely)) ->
6216 "<item title='%s' page='%d'"
6217 (enent
title 0 (String.length
title))
6222 Printf.bprintf
bb " rely='%f'" rely
6224 Buffer.add_string
bb "/>\n";
6226 Buffer.add_string
bb "</bookmarks>";
6227 if Buffer.length
kb > 0
6229 Buffer.add_string
bb "\n";
6230 Buffer.add_buffer
bb kb;
6232 Buffer.add_string
bb "\n</doc>\n";
6238 match state.mode with
6239 | Birdseye
(c, pan, _, _, _) ->
6241 match conf.columns
with
6242 | Some
((c, _, _), _) -> Some
c
6245 match c.columns
with
6246 | Some
(c, _) -> Some
(c, [||])
6249 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6250 | _ -> state.x, conf
6252 let basename = Filename.basename state.path in
6253 adddoc basename pan (getanchor ())
6256 match state.autoscroll
with
6258 | None
-> conf.autoscrollstep
}
6259 (if conf.savebmarks
then state.bookmarks else []);
6261 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6263 then adddoc path x y c bookmarks
6265 Buffer.add_string
bb "</llppconfig>";
6268 if Buffer.length
bb > 0
6271 let tmp = !confpath ^
".tmp" in
6272 let oc = open_out_bin
tmp in
6273 Buffer.output_buffer
oc bb;
6275 Unix.rename
tmp !confpath;
6278 ("error while saving configuration: " ^
Printexc.to_string exn
)
6285 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6286 "<password> Set password");
6288 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6289 "<path> Set path to the user interface font");
6291 ("-c", Arg.String
(fun s -> Config.confpath := s),
6292 "<path> Set path to the configuration file");
6294 ("-v", Arg.Unit
(fun () ->
6296 "%s\nconfiguration path: %s\n"
6300 exit
0), " Print version and exit");
6303 (fun s -> state.path <- s)
6304 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6306 if String.length
state.path = 0
6307 then (prerr_endline
"file name missing"; exit
1);
6311 let globalkeyhash = findkeyhash conf "global" in
6312 let wsfd, winw, winh
= Wsi.init
(object
6314 if nogeomcmds state.geomcmds
6316 method display = display ()
6317 method reshape w h = reshape w h
6318 method mouse b d x y m = mouse b d x y m
6319 method motion x y = state.mpos
<- (x, y); motion x y
6320 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6322 let mascm = m land (
6323 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6325 match state.keystate
with
6327 let km = k, mascm in
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 mascm = 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 mascm = 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
in
6356 List.exists
GlMisc.check_extension
6357 [ "GL_ARB_texture_rectangle"
6358 ; "GL_EXT_texture_recangle"
6359 ; "GL_NV_texture_rectangle" ]
6361 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6363 let cr, sw = Unix.pipe
()
6364 and sr
, cw
= Unix.pipe
() in
6371 setcheckers conf.checkers
;
6375 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6376 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6381 state.text <- "Opening " ^
state.path;
6382 opendoc state.path state.password
;
6384 setfontsize fstate.fontsize
;
6387 let rec loop deadline
=
6389 match state.errfd
with
6390 | None
-> [state.sr
; state.wsfd]
6391 | Some fd
-> [state.sr
; state.wsfd; fd
]
6395 state.redisplay
<- false;
6402 if deadline
= infinity
6404 else max
0.0 (deadline
-. now)
6409 try Unix.select
r [] [] timeout
6410 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6416 if state.ghyll
== noghyll
6418 match state.autoscroll
with
6419 | Some step
when step
!= 0 ->
6420 let y = state.y + step
in
6424 else if y >= state.maxy then 0 else y
6427 if state.mode = View
6428 then state.text <- "";
6431 else deadline
+. 0.01
6436 let rec checkfds = function
6438 | fd
:: rest
when fd
= state.sr
->
6439 let cmd = readcmd state.sr
in
6443 | fd
:: rest
when fd
= state.wsfd ->
6448 let s = String.create
80 in
6449 let n = Unix.read fd
s 0 80 in
6450 if conf.redirectstderr
6452 Buffer.add_substring
state.errmsgs
s 0 n;
6453 state.newerrmsgs
<- true;
6454 state.redisplay
<- true;
6457 prerr_string
(String.sub
s 0 n);
6465 if deadline
= infinity
6469 match state.autoscroll
with
6470 | Some step
when step
!= 0 -> deadline1
6471 | _ -> if state.ghyll
== noghyll then infinity
else deadline1