4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
9 | Uremote
of (string * int)
10 and facename
= string;;
12 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
13 let now = Unix.gettimeofday
;;
15 type params
= (angle
* proportional
* trimparams
16 * texcount
* sliceheight
* memsize
17 * colorspace
* fontpath
)
26 and proportional
= bool
27 and trimmargins
= bool
28 and interpagespace
= int
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
41 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
42 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
44 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
46 external init
: pipe
-> params
-> unit = "ml_init";;
47 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
48 external copysel
: string -> opaque
-> unit = "ml_copysel";;
49 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
50 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
51 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
52 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
53 external measurestr
: int -> string -> float = "ml_measure_string";;
54 external getmaxw
: unit -> float = "ml_getmaxw";;
55 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
56 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
57 external platform
: unit -> platform
= "ml_platform";;
58 external setaalevel
: int -> unit = "ml_setaalevel";;
59 external realloctexts
: int -> bool = "ml_realloctexts";;
60 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
62 let platform_to_string = function
63 | Punknown
-> "unknown"
67 | Pfreebsd
-> "FreeBSD"
68 | Pdragonflybsd
-> "DragonflyBSD"
69 | Popenbsd
-> "OpenBSD"
74 let platform = platform ();;
80 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
83 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
87 | Msel
of (mpos
* mpos
)
90 | Mzoom
of (int * int)
91 | Mzoomrect
of (mpos
* mpos
)
95 type textentry
= string * string * onhist
option * onkey
* ondone
96 and onkey
= string -> int -> te
97 and ondone
= string -> unit
98 and histcancel
= unit -> unit
99 and onhist
= ((histcmd
-> string) * histcancel
)
100 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
105 | TEswitch
of textentry
116 let bound v minv maxv
=
117 max minv
(min maxv v
);
121 { store
= Array.create n v
128 let drawstring size x y s
=
130 Gl.enable `texture_2d
;
131 ignore
(drawstr size x y s
);
133 Gl.disable `texture_2d
;
136 let drawstring1 size x y s
=
140 let drawstring2 size x y fmt
=
141 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
144 let cbcap b
= Array.length b
.store
;;
149 b
.wc
<- (b
.wc
+ 1) mod cap;
151 b
.len
<- min
(b
.len
+ 1) cap;
154 let cbempty b
= b
.len
= 0;;
156 let cbgetg b circular dir
=
160 let rc = b
.rc + dir
in
172 else max
0 (min
rc (b
.len
-1))
178 let cbget b
= cbgetg b
false;;
179 let cbgetc b
= cbgetg b
true;;
196 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
197 dolog " WxH %dx%d" l
.pagew l
.pageh
;
198 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
199 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
200 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
204 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
206 dolog " x0,y0=(% f, % f)" x0 y0
;
207 dolog " x1,y1=(% f, % f)" x1 y1
;
208 dolog " x2,y2=(% f, % f)" x2 y2
;
209 dolog " x3,y3=(% f, % f)" x3 y3
;
214 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
215 and multicol
= columncount
* covercount
* covercount
217 and columncount
= int
218 and covercount
= int;;
221 { mutable scrollbw
: int
222 ; mutable scrollh
: int
223 ; mutable icase
: bool
224 ; mutable preload
: bool
225 ; mutable pagebias
: int
226 ; mutable verbose
: bool
227 ; mutable debug
: bool
228 ; mutable scrollstep
: int
229 ; mutable maxhfit
: bool
230 ; mutable crophack
: bool
231 ; mutable autoscrollstep
: int
232 ; mutable maxwait
: float option
233 ; mutable hlinks
: bool
234 ; mutable underinfo
: bool
235 ; mutable interpagespace
: interpagespace
236 ; mutable zoom
: float
237 ; mutable presentation
: bool
238 ; mutable angle
: angle
241 ; mutable savebmarks
: bool
242 ; mutable proportional
: proportional
243 ; mutable trimmargins
: trimmargins
244 ; mutable trimfuzz
: irect
245 ; mutable memlimit
: memsize
246 ; mutable texcount
: texcount
247 ; mutable sliceheight
: sliceheight
248 ; mutable thumbw
: width
249 ; mutable jumpback
: bool
250 ; mutable bgcolor
: float * float * float
251 ; mutable bedefault
: bool
252 ; mutable scrollbarinpm
: bool
253 ; mutable tilew
: int
254 ; mutable tileh
: int
255 ; mutable mustoresize
: memsize
256 ; mutable checkers
: bool
257 ; mutable aalevel
: int
258 ; mutable urilauncher
: string
259 ; mutable colorspace
: colorspace
260 ; mutable invert
: bool
261 ; mutable colorscale
: float
262 ; mutable redirectstderr
: bool
263 ; mutable ghyllscroll
: (int * int * int) option
264 ; mutable columns
: columns
option
265 ; mutable beyecolumns
: columncount
option
266 ; mutable selcmd
: string
267 ; mutable updatecurs
: bool
271 type anchor
= pageno
* top
;;
273 type outline
= string * int * anchor
;;
275 type rect
= float * float * float * float * float * float * float * float;;
277 type tile
= opaque
* pixmapsize
* elapsed
278 and elapsed
= float;;
279 type pagemapkey
= pageno
* gen
;;
280 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
284 let emptyanchor = (0, 0.0);;
286 type infochange
= | Memused
| Docinfo
| Pdim
;;
288 class type uioh
= object
289 method display
: unit
290 method key
: int -> int -> uioh
291 method button
: int -> bool -> int -> int -> int -> uioh
292 method motion
: int -> int -> uioh
293 method pmotion
: int -> int -> uioh
294 method infochanged
: infochange
-> unit
295 method scrollpw
: (int * float * float)
296 method scrollph
: (int * float * float)
300 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
301 | Textentry
of (textentry
* onleave
)
303 and onleave
= leavetextentrystatus
-> unit
304 and leavetextentrystatus
= | Cancel
| Confirm
305 and helpitem
= string * int * action
308 | Action
of (uioh
-> uioh
)
311 let isbirdseye = function Birdseye _
-> true | _
-> false;;
312 let istextentry = function Textentry _
-> true | _
-> false;;
316 | Loading
of (page
* gen
)
318 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
320 | Outlining
of outline list
323 let nouioh : uioh
= object (self
)
325 method key _ _
= self
326 method button _ _ _ _ _
= self
327 method motion _ _
= self
328 method pmotion _ _
= self
329 method infochanged _
= ()
330 method scrollpw
= (0, nan
, nan
)
331 method scrollph
= (0, nan
, nan
)
335 { mutable sr
: Unix.file_descr
336 ; mutable sw
: Unix.file_descr
337 ; mutable wsfd
: Unix.file_descr
338 ; mutable errfd
: Unix.file_descr
option
339 ; mutable stderr
: Unix.file_descr
340 ; mutable errmsgs
: Buffer.t
341 ; mutable newerrmsgs
: bool
345 ; mutable scrollw
: int
346 ; mutable hscrollh
: int
347 ; mutable anchor
: anchor
348 ; mutable ranchors
: (string * string * anchor
) list
350 ; mutable layout
: page list
351 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
352 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
353 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
354 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
355 ; mutable pagecount
: int
356 ; mutable currently
: currently
357 ; mutable mstate
: mstate
358 ; mutable searchpattern
: string
359 ; mutable rects
: (pageno
* recttype
* rect
) list
360 ; mutable rects1
: (pageno
* recttype
* rect
) list
361 ; mutable text
: string
362 ; mutable fullscreen
: (width
* height
) option
363 ; mutable mode
: mode
364 ; mutable uioh
: uioh
365 ; mutable outlines
: outline array
366 ; mutable bookmarks
: outline list
367 ; mutable path
: string
368 ; mutable password
: string
369 ; mutable invalidated
: int
370 ; mutable memused
: memsize
372 ; mutable throttle
: (page list
* int * float) option
373 ; mutable autoscroll
: int option
374 ; mutable ghyll
: (int option -> unit)
375 ; mutable help
: helpitem array
376 ; mutable docinfo
: (int * string) list
377 ; mutable texid
: GlTex.texture_id
option
379 ; mutable prevzoom
: float
380 ; mutable progress
: float
381 ; mutable redisplay
: bool
382 ; mutable mpos
: mpos
385 { pat
: string circbuf
386 ; pag
: string circbuf
387 ; nav
: anchor circbuf
388 ; sel
: string circbuf
409 ; presentation
= false
414 ; proportional
= true
415 ; trimmargins
= false
416 ; trimfuzz
= (0,0,0,0)
417 ; memlimit
= 32 lsl 20
422 ; bgcolor
= (0.5, 0.5, 0.5)
424 ; scrollbarinpm
= true
427 ; mustoresize
= 128 lsl 20
432 | Plinux
| Pfreebsd
| Pdragonflybsd
433 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
434 | Posx
-> "open \"%s\""
435 | Pcygwin
-> "cygstart %s"
436 | Punknown
-> "echo %s")
439 | Plinux
| Pfreebsd
| Pdragonflybsd
440 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
447 ; redirectstderr
= false
455 let conf = { defconf with angle
= defconf.angle
};;
458 { mutable fontsize
: int
459 ; mutable wwidth
: float
460 ; mutable maxrows
: int
472 fstate.fontsize
<- n
;
473 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
474 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
478 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
479 let len = String.length s
in
480 if colonpos >= 0 && colonpos + 3 < len
482 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
485 try String.rindex_from s
colonpos ' '
489 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
492 | "http" | "ftp" | "mailto" ->
494 try String.index_from s
colonpos ' '
495 with Not_found
-> len
497 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
505 let shell, farg
= "/bin/sh", "-c" in
507 let args = [|shell; farg
; s
|] in
508 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
512 if String.length
conf.urilauncher
= 0
513 then print_endline uri
515 let url = geturl uri
in
516 if String.length
url = 0
517 then print_endline uri
519 let re = Str.regexp
"%s" in
520 let command = Str.global_replace
re url conf.urilauncher
in
524 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
530 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
531 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
535 let strings = version () :: "" :: Help.keys
in
538 let url = geturl s
in
539 if String.length
url > 0
540 then (s
, 0, Action
(fun u
-> gotouri url; u
))
541 else (s
, 0, Noaction
)
552 ; stderr
= Unix.stderr
553 ; errmsgs
= Buffer.create
0
560 ; anchor
= emptyanchor
564 ; tilelru
= Queue.create
()
565 ; pagemap
= Hashtbl.create
10
566 ; tilemap
= Hashtbl.create
10
583 { nav
= cbnew 10 (0, 0.0)
607 Printf.kprintf prerr_endline fmt
609 Printf.kprintf ignore fmt
612 let redirectstderr () =
613 if conf.redirectstderr
615 let rfd, wfd
= Unix.pipe
() in
616 state.stderr
<- Unix.dup
Unix.stderr
;
617 state.errfd
<- Some
rfd;
618 Unix.dup2 wfd
Unix.stderr
;
620 state.newerrmsgs
<- false;
621 begin match state.errfd
with
624 Unix.dup2
state.stderr
Unix.stderr
;
628 prerr_string
(Buffer.contents
state.errmsgs
);
630 Buffer.clear
state.errmsgs
;
636 let postRedisplay who
=
638 then prerr_endline
("redisplay for " ^ who
);
639 state.redisplay
<- true;
643 let getopaque pageno
=
644 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
645 with Not_found
-> None
648 let putopaque pageno opaque
=
649 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
652 let pagetranslatepoint l x y
=
653 let dy = y
- l
.pagedispy
in
654 let y = dy + l
.pagey
in
655 let dx = x
- l
.pagedispx
in
656 let x = dx + l
.pagex
in
663 begin match getopaque l
.pageno
with
665 let x0 = l
.pagedispx
in
666 let x1 = x0 + l
.pagevw
in
667 let y0 = l
.pagedispy
in
668 let y1 = y0 + l
.pagevh
in
669 if y >= y0 && y <= y1 && x >= x0 && x <= x1
671 let px, py
= pagetranslatepoint l
x y in
672 match whatsunder opaque
px py
with
685 state.text
<- Printf.sprintf
"%c%s" c s
;
686 G.postRedisplay "showtext";
689 let updateunder x y =
690 match getunder x y with
691 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
693 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
694 Wsi.setcursor
Wsi.CURSOR_INFO
695 | Ulinkgoto
(page
, _
) ->
697 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
698 Wsi.setcursor
Wsi.CURSOR_INFO
700 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
701 Wsi.setcursor
Wsi.CURSOR_TEXT
703 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
704 Wsi.setcursor
Wsi.CURSOR_INHERIT
706 if conf.underinfo
then showtext 'l'
("launch: " ^ s
);
707 Wsi.setcursor
Wsi.CURSOR_INHERIT
709 if conf.underinfo
then showtext 'n'
("named: " ^ s
);
710 Wsi.setcursor
Wsi.CURSOR_INHERIT
711 | Uremote
(filename
, pageno
) ->
712 if conf.underinfo
then showtext 'r'
713 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
714 Wsi.setcursor
Wsi.CURSOR_INFO
718 let b = Buffer.create
(String.length s
+ 1) in
719 Buffer.add_string
b s
;
724 let colorspace_of_string s
=
725 match String.lowercase s
with
729 | _
-> failwith
"invalid colorspace"
732 let int_of_colorspace = function
738 let colorspace_of_int = function
742 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
745 let colorspace_to_string = function
751 let intentry_with_suffix text key
=
753 if key
>= 32 && key
< 127
757 match Char.lowercase
c with
759 let text = addchar text c in
763 let text = addchar text c in
767 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
771 let columns_to_string (n
, a
, b) =
773 then Printf.sprintf
"%d" n
774 else Printf.sprintf
"%d,%d,%d" n a
b;
777 let columns_of_string s
=
779 (int_of_string s
, 0, 0)
781 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
785 let len = String.length s
in
787 let b = Buffer.create
n in
788 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
789 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
790 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
791 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
792 Buffer.add_string
b s
;
793 let s'
= Buffer.contents
b in
794 let n'
= Unix.write fd
s'
0 n in
795 if n'
!= n then failwith
"write failed";
800 let n = Unix.read fd
s 0 4 in
801 if n != 4 then failwith
"incomplete read(len)";
803 lor (Char.code
s.[0] lsl 24)
804 lor (Char.code
s.[1] lsl 16)
805 lor (Char.code
s.[2] lsl 8)
806 lor (Char.code
s.[3] lsl 0)
808 let s = String.create
len in
809 let n = Unix.read fd
s 0 len in
810 if n != len then failwith
"incomplete read(data)";
815 let b = Buffer.create
10 in
816 Buffer.add_string
b s;
817 let rec combine = function
820 Buffer.add_char
b ' '
;
823 | `
b b -> if b then "1" else "0"
825 | `i i
-> string_of_int i
826 | `
f f -> string_of_float
f
827 | `I
f -> string_of_int
(truncate
f)
829 Buffer.add_string
b s;
836 let cmd = Buffer.contents
(makecmd s l
) in
837 writecmd state.sw
cmd;
843 let d = conf.winh
- h
in
850 let rec f pn ph pi fh l
=
852 | (n, _
, h
, _
) :: rest
->
853 let ips = calcips h
in
858 if isbirdseye state.mode
&& pn
= 0
863 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
868 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
872 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
875 let fh = f 0 0 0 0 state.pdims
in
880 match conf.columns
with
881 | None
-> calcheight ()
883 if Array.length
b > 0
885 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
890 let getpageyh pageno
=
891 let rec f pn ph pi
y l
=
893 | (n, _
, h
, _
) :: rest
->
894 let ips = calcips h
in
897 let h = if n = pageno
then h else ph
in
898 if conf.presentation
&& n = pageno
900 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
902 y + (pageno
- pn
) * (ph
+ pi
), h
904 let y = y + (if conf.presentation
then pi
else 0) in
905 let y = y + (n - pn
) * (ph
+ pi
) in
909 y + (pageno
- pn
) * (ph
+ pi
), ph
911 f 0 0 0 0 state.pdims
914 let getpageyh pageno
=
915 match conf.columns
with
916 | None
-> getpageyh pageno
918 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
922 let getpagedim pageno
=
925 | (n, _
, _
, _
) as pdim
:: rest
->
927 then (if n = pageno
then pdim
else ppdim
)
932 f (-1, -1, -1, -1) state.pdims
935 let getpagey pageno
= fst
(getpageyh pageno
);;
938 let sh = sh - state.hscrollh
in
939 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
940 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
942 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
943 let ips = calcips h in
945 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
949 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
951 prev
, pdims
, pdimno
, 0
953 let dy = dy + yinc in
954 let py = py + yinc in
955 if pageno
= state.pagecount
|| dy >= sh
960 if py + h <= vy - yinc
962 let py = py + h + ips in
963 let dy = max
0 (py - y) in
972 let pagey = vy - py in
973 let pagevh = h - pagey in
974 let pagevh = min
(sh - dy) pagevh in
975 let off = if yinc > 0 then py - vy else 0 in
976 let py = py + h + ips in
979 if state.w
< conf.winw
- state.scrollw
980 then (conf.winw
- state.scrollw
- state.w
) / 2
983 let dispx = xoff + state.x in
989 let lw = w
- pagex in
990 min
lw (conf.winw
- state.scrollw
)
998 ; pagey = pagey + off
1000 ; pagevh = pagevh - off
1002 ; pagedispy
= dy + off
1005 let accu = e :: accu in
1006 f ~pageno
:(pageno
+1)
1014 if state.invalidated
= 0
1032 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1033 let sh = sh - state.hscrollh
in
1034 let rec fold accu n =
1035 if n = Array.length
b
1038 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1041 || n = state.pagecount
- coverB
1042 || (n - coverA
) mod columns
= columns
- 1)
1048 let pagey = max
0 (y - vy) in
1049 let pagedispy = if pagey > 0 then 0 else vy - y in
1050 let pagedispx, pagex, pagevw =
1052 if n = coverA
- 1 || n = state.pagecount
- coverB
1053 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1054 else dx + xoff + state.x
1057 then 0, -pdx, w
+ pdx
1058 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1060 let pagevh = min
(h - pagey) (sh - pagedispy) in
1061 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1065 ; pagedimno
= pdimno
1072 ; pagedispx = pagedispx
1073 ; pagedispy = pagedispy
1084 if state.invalidated
= 0
1085 then List.rev
(fold [] 0)
1090 match conf.columns
with
1091 | None
-> layout1 y sh
1092 | Some
c -> layoutN c y sh
1096 let y = state.y + incr
in
1098 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1103 let tilex = l
.pagex mod conf.tilew
in
1104 let tiley = l
.pagey mod conf.tileh
in
1106 let col = l
.pagex / conf.tilew
in
1107 let row = l
.pagey / conf.tileh
in
1110 let a = l
.pagew
- l
.pagex in
1111 let b = conf.winw
- state.scrollw
in
1113 and vh
= l
.pagevh in
1115 let rec rowloop row y0 dispy
h =
1119 let dh = conf.tileh
- y0 in
1120 let dh = min
h dh in
1121 let rec colloop col x0 dispx w
=
1125 let dw = conf.tilew
- x0 in
1126 let dw = min w
dw in
1128 f col row dispx dispy
x0 y0 dw dh;
1129 colloop (col+1) 0 (dispx+dw) (w
-dw)
1132 colloop col tilex l
.pagedispx vw;
1133 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1137 then rowloop row tiley l
.pagedispy vh
;
1140 let gettileopaque l
col row =
1142 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1144 try Some
(Hashtbl.find
state.tilemap
key)
1145 with Not_found
-> None
1148 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1149 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1150 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1153 let drawtiles l color
=
1155 let f col row x y tilex tiley w
h =
1156 match gettileopaque l
col row with
1157 | Some
(opaque
, _
, t
) ->
1158 let params = x, y, w
, h, tilex, tiley in
1162 GlFunc.blend_func `zero `one_minus_src_color
;
1164 drawtile
params opaque
;
1166 then Gl.disable `blend
;
1169 let s = Printf.sprintf
1173 let w = measurestr
fstate.fontsize
s in
1174 GlMisc.push_attrib
[`current
];
1175 GlDraw.color
(0.0, 0.0, 0.0);
1177 (float (x-2), float (y-2))
1178 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1179 GlDraw.color
(1.0, 1.0, 1.0);
1180 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1181 GlMisc.pop_attrib
();
1186 let lw = conf.winw
- state.scrollw
- x in
1189 let lh = conf.winh
- y in
1192 Gl.enable `texture_2d
;
1193 begin match state.texid
with
1195 GlTex.bind_texture `texture_2d id
;
1198 and x1 = float (x+w)
1199 and y1 = float (y+h) in
1201 let tw = float w /. 64.0
1202 and th
= float h /. 64.0 in
1203 let tx0 = float tilex /. 64.0
1204 and ty0
= float tiley /. 64.0 in
1206 and ty1
= ty0
+. th
in
1207 GlDraw.begins `quads
;
1208 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1209 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1210 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1211 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1214 Gl.disable `texture_2d
;
1216 GlDraw.color
(1.0, 1.0, 1.0);
1219 (float (x+w), float (y+h));
1221 if w > 128 && h > fstate.fontsize
+ 10
1223 GlDraw.color
(0.0, 0.0, 0.0);
1226 then (col*conf.tilew
, row*conf.tileh
)
1229 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1236 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1238 let tilevisible1 l
x y =
1240 and ax1
= l
.pagex + l
.pagevw
1242 and ay1
= l
.pagey + l
.pagevh in
1246 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1247 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1249 let rx0 = max
ax0 bx0
1250 and ry0
= max ay0 by0
1251 and rx1
= min ax1
bx1
1252 and ry1
= min ay1 by1
in
1254 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1255 nonemptyintersection
1258 let tilevisible layout n x y =
1259 let rec findpageinlayout = function
1260 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1261 | _
:: rest
-> findpageinlayout rest
1264 findpageinlayout layout
1267 let tileready l
x y =
1268 tilevisible1 l
x y &&
1269 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1272 let tilepage n p
layout =
1273 let rec loop = function
1277 let f col row _ _ _ _ _ _
=
1278 if state.currently
= Idle
1280 match gettileopaque l
col row with
1283 let x = col*conf.tilew
1284 and y = row*conf.tileh
in
1286 let w = l
.pagew
- x in
1290 let h = l
.pageh
- y in
1302 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1303 conf.tilew
, conf.tileh
1312 if state.invalidated
= 0 then loop layout;
1315 let preloadlayout visiblepages
=
1316 let presentation = conf.presentation in
1317 let interpagespace = conf.interpagespace in
1318 let maxy = state.maxy in
1319 conf.presentation <- false;
1320 conf.interpagespace <- 0;
1321 state.maxy <- calcheight ();
1323 match visiblepages
with
1325 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1327 let y = if y < conf.winh
then 0 else y - conf.winh
in
1328 let h = state.y - y + conf.winh
*3 in
1329 let pages = layout y h in
1330 conf.presentation <- presentation;
1331 conf.interpagespace <- interpagespace;
1337 let rec loop pages =
1338 if state.currently
!= Idle
1343 begin match getopaque l
.pageno
with
1345 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1346 state.currently
<- Loading
(l
, state.gen
);
1348 tilepage l
.pageno opaque
pages;
1353 if state.invalidated
= 0 then loop pages
1358 if conf.preload && state.currently
= Idle
1359 then load (preloadlayout pages);
1362 let layoutready layout =
1363 let rec fold all ls
=
1364 all
&& match ls
with
1366 let seen = ref false in
1367 let allvisible = ref true in
1368 let foo col row _ _ _ _ _ _
=
1370 allvisible := !allvisible &&
1371 begin match gettileopaque l
col row with
1377 fold (!seen && !allvisible) rest
1380 let alltilesvisible = fold true layout in
1385 let y = bound y 0 state.maxy in
1386 let y, layout, proceed
=
1387 match conf.maxwait
with
1388 | Some time
when state.ghyll
== noghyll ->
1389 begin match state.throttle
with
1391 let layout = layout y conf.winh
in
1392 let ready = layoutready layout in
1396 state.throttle
<- Some
(layout, y, now ());
1398 else G.postRedisplay "gotoy showall (None)";
1400 | Some
(_
, _
, started
) ->
1401 let dt = now () -. started
in
1404 state.throttle
<- None
;
1405 let layout = layout y conf.winh
in
1407 G.postRedisplay "maxwait";
1414 let layout = layout y conf.winh
in
1415 if true || layoutready layout
1416 then G.postRedisplay "gotoy ready";
1422 state.layout <- layout;
1423 begin match state.mode
with
1424 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1425 if not
(pagevisible layout pageno
)
1427 match state.layout with
1430 state.mode
<- Birdseye
(
1431 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1438 state.ghyll
<- noghyll;
1441 let conttiling pageno opaque
=
1442 tilepage pageno opaque
1443 (if conf.preload then preloadlayout state.layout else state.layout)
1446 let gotoy_and_clear_text y =
1448 if not
conf.verbose
then state.text <- "";
1452 match state.layout with
1454 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1457 let getanchory (n, top
) =
1458 let y, h = getpageyh n in
1459 y + (truncate
(top
*. float h));
1462 let gotoanchor anchor
=
1463 gotoy (getanchory anchor
);
1467 cbput state.hists
.nav
(getanchor ());
1471 let anchor = cbgetc state.hists
.nav dir
in
1476 let rec scroll f n a b =
1477 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1479 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1481 then s (float f /. float a)
1484 then 1.0 -. s ((float (f-b) /. float (n-b)))
1491 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1492 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1494 let ins = float a *. iv1
1495 and outs
= float (n-b) *. iv1 in
1497 ins +. outs
+. float ones
1499 let rec set (_N
, _A
, _B
) y sy
=
1500 let sum = summa
1.0 _N _A _B
in
1501 let dy = float (y - sy
) in
1505 then state.ghyll
<- noghyll
1508 let s = scroll n _N _A _B
in
1509 let y1 = y1 +. ((s *. dy) /. sum) in
1510 gotoy_and_clear_text (truncate
y1);
1511 state.ghyll
<- gf (n+1) y1;
1515 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1517 gf 0 (float state.y)
1520 match conf.ghyllscroll
with
1522 gotoy_and_clear_text y
1524 if state.ghyll
== noghyll
1525 then set nab
y state.y
1526 else state.ghyll
(Some
y)
1529 let gotopage n top
=
1530 let y, h = getpageyh n in
1531 let y = y + (truncate
(top
*. float h)) in
1535 let gotopage1 n top
=
1536 let y = getpagey n in
1546 state.invalidated
<- state.invalidated
+ 1;
1549 let writeopen path password
=
1550 writecmd state.sw
("open " ^ path ^
"\000" ^ password ^
"\000");
1553 let opendoc path password
=
1556 state.password
<- password
;
1557 state.gen
<- state.gen
+ 1;
1558 state.docinfo
<- [];
1560 setaalevel
conf.aalevel
;
1561 writeopen path password
;
1562 Wsi.settitle
("llpp " ^
Filename.basename path
);
1563 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1567 let c = c *. conf.colorscale
in
1571 let scalecolor2 (r
, g
, b) =
1572 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1576 let docolumns = function
1578 | Some
((columns
, coverA
, coverB
), _
) ->
1579 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1580 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1581 if pageno
= state.pagecount
1584 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1586 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1587 pdimno+1, pdim
, rest
1592 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1594 (conf.winw
- state.scrollw
- w) / 2,
1595 y + rowh
+ conf.interpagespace, h
1598 if (pageno
- coverA
) mod columns
= 0
1599 then 0, y + rowh
+ conf.interpagespace, h
1600 else x, y, max rowh
h
1603 let rec fixrow m
= if m
= pageno
then () else
1604 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1607 let y = y + (rowh
- h) / 2 in
1608 a.(m
) <- (pdimno, x, y, pdim
);
1612 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1613 then fixrow (pageno
- columns
);
1614 a.(pageno
) <- (pdimno, x, y, pdim
);
1615 let x = x + w + xoff*2 + conf.interpagespace in
1616 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1618 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1619 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1621 docolumns conf.columns
;
1622 state.maxy <- calcheight ();
1624 if state.w <= conf.winw
- state.scrollw
1628 match state.mode
with
1629 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1630 let y, h = getpageyh pageno
in
1631 let top = (conf.winh
- h) / 2 in
1632 gotoy (max
0 (y - top))
1633 | _
-> gotoanchor state.anchor
1637 let firsttime = ref true in
1639 GlDraw.viewport
0 0 w h;
1640 if state.invalidated
= 0 && not
!firsttime
1641 then state.anchor <- getanchor ();
1645 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1649 setfontsize fstate.fontsize
;
1650 GlMat.mode `modelview
;
1651 GlMat.load_identity
();
1653 GlMat.mode `projection
;
1654 GlMat.load_identity
();
1655 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1656 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1657 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1660 match conf.columns
with
1662 | Some
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1665 wcmd "geometry" [`i
w; `i
h];
1669 let len = String.length
state.text in
1672 match state.mode
with
1673 | View
-> state.hscrollh
1678 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1679 (x+.w, float (conf.winh
- hscrollh))
1682 let w = float (conf.winw
- state.scrollw
- 1) in
1683 if state.progress
>= 0.0 && state.progress
< 1.0
1685 GlDraw.color
(0.3, 0.3, 0.3);
1686 let w1 = w *. state.progress
in
1688 GlDraw.color
(0.0, 0.0, 0.0);
1692 GlDraw.color
(0.0, 0.0, 0.0);
1696 GlDraw.color
(1.0, 1.0, 1.0);
1697 drawstring fstate.fontsize
1698 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1701 match state.mode
with
1702 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1706 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1708 Printf.sprintf
"%s%s_" prefix
text
1717 if not
(istextentry state.mode
)
1719 let s1 = "(press 'e' to review error messasges)" in
1720 if String.length
s > 0 then s ^
" " ^
s1 else s1
1725 if String.length
s > 0
1730 let len = Queue.length
state.tilelru
in
1732 if state.memused
<= conf.memlimit
1737 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1738 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1739 let (_
, pw
, ph
, _
) = getpagedim n in
1742 && colorspace
= conf.colorspace
1743 && angle
= conf.angle
1748 match state.throttle
with
1751 then preloadlayout state.layout
1753 | Some
(layout, _
, _
) ->
1756 let x = col*conf.tilew
1757 and y = row*conf.tileh
in
1758 tilevisible layout n x y
1760 then Queue.push lruitem
state.tilelru
1762 wcmd "freetile" [`
s p
];
1763 state.memused
<- state.memused
- s;
1764 state.uioh#infochanged Memused
;
1765 Hashtbl.remove
state.tilemap k
;
1774 Queue.iter
(fun (k
, p
, s) ->
1775 wcmd "freetile" [`
s p
];
1776 state.memused
<- state.memused
- s;
1777 state.uioh#infochanged Memused
;
1778 Hashtbl.remove
state.tilemap k
;
1780 Queue.clear
state.tilelru
;
1784 let logcurrently = function
1785 | Idle
-> dolog "Idle"
1786 | Loading
(l
, gen
) ->
1787 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1788 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1790 "Tiling %d[%d,%d] page=%s cs=%s angle"
1791 l
.pageno
col row pageopaque
1792 (colorspace_to_string colorspace
)
1794 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1795 angle gen
conf.angle
state.gen
1797 conf.tilew
conf.tileh
1804 (* dolog "%S" cmds; *)
1807 try String.index cmds ' '
1808 with Not_found
-> -1
1813 let l = String.length cmds
in
1814 let op = String.sub cmds
0 spacepos in
1816 if l - spacepos < 2 then ""
1817 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1822 state.uioh#infochanged Pdim
;
1826 state.rects
<- state.rects1
;
1827 G.postRedisplay "clearrects";
1831 try Scanf.sscanf
args "%u" (fun n -> n)
1833 dolog "error processing 'continue' %S: %s"
1834 cmds
(Printexc.to_string exn
);
1837 state.pagecount
<- n;
1838 state.invalidated
<- state.invalidated
- 1;
1839 begin match state.currently
with
1841 state.currently
<- Idle
;
1842 state.outlines
<- Array.of_list
(List.rev
l)
1845 if state.invalidated
= 0
1847 if conf.maxwait
= None
1848 then G.postRedisplay "continue";
1858 then showtext ' '
args
1861 let progress, text =
1863 Scanf.sscanf
args "%f %n"
1865 f, String.sub
args pos
(String.length
args - pos
))
1867 dolog "error processing 'progress' %S: %s"
1868 cmds
(Printexc.to_string exn
);
1872 state.progress <- progress;
1873 G.postRedisplay "progress"
1876 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1878 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1879 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1880 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1882 dolog "error processing 'firstmatch' %S: %s"
1883 cmds
(Printexc.to_string exn
);
1886 let y = (getpagey pageno) + truncate
y0 in
1889 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1892 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1894 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1895 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1896 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1898 dolog "error processing 'match' %S: %s"
1899 cmds
(Printexc.to_string exn
);
1903 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1908 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1910 dolog "error processing 'page' %S: %s"
1911 cmds
(Printexc.to_string exn
);
1914 begin match state.currently
with
1915 | Loading
(l, gen
) ->
1916 vlog "page %d took %f sec" l.pageno t
;
1917 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1918 begin match state.throttle
with
1920 let preloadedpages =
1922 then preloadlayout state.layout
1927 Set.Make
(struct type t
= int let compare = (-) end) in
1929 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1930 IntSet.empty
preloadedpages
1933 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1934 if not
(IntSet.mem
pageno set)
1936 wcmd "freepage" [`
s opaque
];
1942 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1945 state.currently
<- Idle
;
1948 tilepage l.pageno pageopaque state.layout;
1950 load preloadedpages;
1951 if pagevisible state.layout l.pageno
1952 && layoutready state.layout
1953 then G.postRedisplay "page";
1956 | Some
(layout, _
, _
) ->
1957 state.currently
<- Idle
;
1958 tilepage l.pageno pageopaque layout;
1963 dolog "Inconsistent loading state";
1964 logcurrently state.currently
;
1969 let (x, y, opaque
, size
, t
) =
1971 Scanf.sscanf
args "%u %u %s %u %f"
1972 (fun x y p size t
-> (x, y, p
, size
, t
))
1974 dolog "error processing 'tile' %S: %s"
1975 cmds
(Printexc.to_string exn
);
1978 begin match state.currently
with
1979 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1980 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1982 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1984 wcmd "freetile" [`
s opaque
];
1985 state.currently
<- Idle
;
1989 puttileopaque l col row gen cs angle opaque size t
;
1990 state.memused
<- state.memused
+ size
;
1991 state.uioh#infochanged Memused
;
1993 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1994 opaque
, size
) state.tilelru
;
1997 match state.throttle
with
1998 | None
-> state.layout
1999 | Some
(layout, _
, _
) -> layout
2002 state.currently
<- Idle
;
2004 && conf.colorspace
= cs
2005 && conf.angle
= angle
2006 && tilevisible layout l.pageno x y
2007 then conttiling l.pageno pageopaque;
2009 begin match state.throttle
with
2011 preload state.layout;
2013 && conf.colorspace
= cs
2014 && conf.angle
= angle
2015 && tilevisible state.layout l.pageno x y
2016 then G.postRedisplay "tile nothrottle";
2018 | Some
(layout, y, _
) ->
2019 let ready = layoutready layout in
2023 state.layout <- layout;
2024 state.throttle
<- None
;
2025 G.postRedisplay "throttle";
2032 dolog "Inconsistent tiling state";
2033 logcurrently state.currently
;
2040 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2042 dolog "error processing 'pdim' %S: %s"
2043 cmds
(Printexc.to_string exn
);
2046 state.uioh#infochanged Pdim
;
2047 state.pdims
<- pdim :: state.pdims
2050 let (l, n, t
, h, pos
) =
2052 Scanf.sscanf
args "%u %u %d %u %n"
2053 (fun l n t
h pos
-> l, n, t
, h, pos
)
2055 dolog "error processing 'o' %S: %s"
2056 cmds
(Printexc.to_string exn
);
2059 let s = String.sub
args pos
(String.length
args - pos
) in
2060 let outline = (s, l, (n, float t
/. float h)) in
2061 begin match state.currently
with
2062 | Outlining outlines
->
2063 state.currently
<- Outlining
(outline :: outlines
)
2065 state.currently
<- Outlining
[outline]
2067 dolog "invalid outlining state";
2068 logcurrently currently
2072 state.docinfo
<- (1, args) :: state.docinfo
2075 state.uioh#infochanged Docinfo
;
2076 state.docinfo
<- List.rev
state.docinfo
2079 dolog "unknown cmd `%S'" cmds
2084 let action = function
2085 | HCprev
-> cbget cb ~
-1
2086 | HCnext
-> cbget cb
1
2087 | HCfirst
-> cbget cb ~
-(cb
.rc)
2088 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2089 and cancel
() = cb
.rc <- rc
2093 let search pattern forward
=
2094 if String.length pattern
> 0
2097 match state.layout with
2100 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2103 let b = makecmd "search"
2104 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2106 Buffer.add_char
b '
,'
;
2107 Buffer.add_string
b pattern
;
2108 Buffer.add_char
b '
\000'
;
2111 writecmd state.sw
cmd;
2114 let intentry text key =
2116 if key >= 32 && key < 127
2122 let text = addchar text c in
2126 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2130 let textentry text key =
2131 if key land 0xff00 = 0xff00
2133 else TEcont
(text ^
Wsi.toutf8
key)
2136 let reqlayout angle proportional
=
2137 match state.throttle
with
2139 if state.invalidated
= 0 then state.anchor <- getanchor ();
2140 conf.angle
<- angle
mod 360;
2141 conf.proportional
<- proportional
;
2143 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2147 let settrim trimmargins trimfuzz
=
2148 if state.invalidated
= 0 then state.anchor <- getanchor ();
2149 conf.trimmargins
<- trimmargins
;
2150 conf.trimfuzz
<- trimfuzz
;
2151 let x0, y0, x1, y1 = trimfuzz
in
2154 `
b conf.trimmargins
;
2160 Hashtbl.iter
(fun _ opaque
->
2161 wcmd "freepage" [`
s opaque
];
2163 Hashtbl.clear
state.pagemap
;
2167 match state.throttle
with
2169 let zoom = max
0.01 zoom in
2170 if zoom <> conf.zoom
2172 state.prevzoom
<- conf.zoom;
2175 then (state.x <- 0; 0.0)
2176 else float state.x /. float state.w
2179 reshape conf.winw
conf.winh
;
2182 let x = relx *. float state.w in
2183 state.x <- truncate
x;
2185 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2188 | Some
(layout, y, started
) ->
2190 match conf.maxwait
with
2194 let dt = now () -. started
in
2202 let setcolumns columns coverA coverB
=
2205 conf.columns
<- None
;
2210 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2213 reshape conf.winw
conf.winh
;
2216 let enterbirdseye () =
2217 let zoom = float conf.thumbw
/. float conf.winw
in
2218 let birdseyepageno =
2219 let cy = conf.winh
/ 2 in
2223 let rec fold best
= function
2226 let d = cy - (l.pagedispy + l.pagevh/2)
2227 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2228 if abs
d < abs dbest
2235 state.mode
<- Birdseye
(
2236 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2239 conf.presentation <- false;
2240 conf.interpagespace <- 10;
2241 conf.hlinks
<- false;
2243 state.mstate
<- Mnone
;
2244 conf.maxwait
<- None
;
2246 match conf.beyecolumns
with
2249 Some
((c, 0, 0), [||])
2252 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2255 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2260 reshape conf.winw
conf.winh
;
2263 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2265 conf.zoom <- c.zoom;
2266 conf.presentation <- c.presentation;
2267 conf.interpagespace <- c.interpagespace;
2268 conf.maxwait
<- c.maxwait
;
2269 conf.hlinks
<- c.hlinks
;
2270 conf.beyecolumns
<- (
2271 match conf.columns
with
2272 | Some
((c, _
, _
), _
) -> Some
c
2276 match c.columns
with
2277 | Some
(c, _
) -> Some
(c, [||])
2283 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2286 reshape conf.winw
conf.winh
;
2287 state.anchor <- if goback
then anchor else (pageno, 0.0);
2290 let togglebirdseye () =
2291 match state.mode
with
2292 | Birdseye vals
-> leavebirdseye vals
true
2293 | View
-> enterbirdseye ()
2297 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2298 let pageno = max
0 (pageno - incr
) in
2299 let rec loop = function
2300 | [] -> gotopage1 pageno 0
2301 | l :: _
when l.pageno = pageno ->
2302 if l.pagedispy >= 0 && l.pagey = 0
2303 then G.postRedisplay "upbirdseye"
2304 else gotopage1 pageno 0
2305 | _
:: rest
-> loop rest
2308 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2311 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2312 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2313 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2314 let rec loop = function
2316 let y, h = getpageyh pageno in
2317 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2319 | l :: _
when l.pageno = pageno ->
2320 if l.pagevh != l.pageh
2321 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2322 else G.postRedisplay "downbirdseye"
2323 | _
:: rest
-> loop rest
2328 let optentry mode _
key =
2329 let btos b = if b then "on" else "off" in
2330 if key >= 32 && key < 127
2332 let c = Char.chr
key in
2336 try conf.scrollstep
<- int_of_string
s with exc
->
2337 state.text <- Printf.sprintf
"bad integer `%s': %s"
2338 s (Printexc.to_string exc
)
2340 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2345 conf.autoscrollstep
<- int_of_string
s;
2346 if state.autoscroll
<> None
2347 then state.autoscroll
<- Some
conf.autoscrollstep
2349 state.text <- Printf.sprintf
"bad integer `%s': %s"
2350 s (Printexc.to_string exc
)
2352 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2357 let n, a, b = columns_of_string s in
2360 state.text <- Printf.sprintf
"bad columns `%s': %s"
2361 s (Printexc.to_string exc
)
2363 TEswitch
("columns: ", "", None
, textentry, ondone)
2368 let zoom = float (int_of_string
s) /. 100.0 in
2371 state.text <- Printf.sprintf
"bad integer `%s': %s"
2372 s (Printexc.to_string exc
)
2374 TEswitch
("zoom: ", "", None
, intentry, ondone)
2379 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2381 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2382 begin match mode
with
2384 leavebirdseye beye
false;
2389 state.text <- Printf.sprintf
"bad integer `%s': %s"
2390 s (Printexc.to_string exc
)
2392 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2397 Some
(int_of_string
s)
2399 state.text <- Printf.sprintf
"bad integer `%s': %s"
2400 s (Printexc.to_string exc
);
2403 | Some angle
-> reqlayout angle
conf.proportional
2406 TEswitch
("rotation: ", "", None
, intentry, ondone)
2409 conf.icase
<- not
conf.icase
;
2410 TEdone
("case insensitive search " ^
(btos conf.icase
))
2413 conf.preload <- not
conf.preload;
2415 TEdone
("preload " ^
(btos conf.preload))
2418 conf.verbose
<- not
conf.verbose
;
2419 TEdone
("verbose " ^
(btos conf.verbose
))
2422 conf.debug
<- not
conf.debug
;
2423 TEdone
("debug " ^
(btos conf.debug
))
2426 conf.maxhfit
<- not
conf.maxhfit
;
2428 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2429 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2432 conf.crophack
<- not
conf.crophack
;
2433 TEdone
("crophack " ^
btos conf.crophack
)
2437 match conf.maxwait
with
2439 conf.maxwait
<- Some infinity
;
2440 "always wait for page to complete"
2442 conf.maxwait
<- None
;
2443 "show placeholder if page is not ready"
2448 conf.underinfo
<- not
conf.underinfo
;
2449 TEdone
("underinfo " ^
btos conf.underinfo
)
2452 conf.savebmarks
<- not
conf.savebmarks
;
2453 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2459 match state.layout with
2464 conf.interpagespace <- int_of_string
s;
2465 state.maxy <- calcheight ();
2466 let y = getpagey pageno in
2469 state.text <- Printf.sprintf
"bad integer `%s': %s"
2470 s (Printexc.to_string exc
)
2472 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2475 reqlayout conf.angle
(not
conf.proportional
);
2476 TEdone
("proportional display " ^
btos conf.proportional
)
2479 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2480 TEdone
("trim margins " ^
btos conf.trimmargins
)
2483 conf.invert
<- not
conf.invert
;
2484 TEdone
("invert colors " ^
btos conf.invert
)
2488 cbput state.hists
.sel
s;
2491 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2495 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2501 class type lvsource
= object
2502 method getitemcount
: int
2503 method getitem
: int -> (string * int)
2504 method hasaction
: int -> bool
2513 method getactive
: int
2514 method getfirst
: int
2515 method getqsearch
: string
2516 method setqsearch
: string -> unit
2520 class virtual lvsourcebase
= object
2521 val mutable m_active
= 0
2522 val mutable m_first
= 0
2523 val mutable m_qsearch
= ""
2524 val mutable m_pan
= 0
2525 method getactive
= m_active
2526 method getfirst
= m_first
2527 method getqsearch
= m_qsearch
2528 method getpan
= m_pan
2529 method setqsearch
s = m_qsearch
<- s
2532 let withoutlastutf8 s =
2533 let len = String.length
s in
2541 let b = Char.code
s.[pos
] in
2542 if b land 0b110000 = 0b11000000
2547 if Char.code
s.[len-1] land 0x80 = 0
2551 String.sub
s 0 first;
2554 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2556 state.mode
<- Textentry
(te
, onleave
);
2559 G.postRedisplay "textentrykeyboard enttext";
2561 let histaction cmd =
2564 | Some
(action, _
) ->
2565 state.mode
<- Textentry
(
2566 (c, action cmd, opthist
, onkey
, ondone), onleave
2568 G.postRedisplay "textentry histaction"
2571 | 0xff08 -> (* backspace *)
2572 let s = withoutlastutf8 text in
2573 let len = String.length
s in
2577 G.postRedisplay "textentrykeyboard after cancel";
2580 enttext (c, s, opthist
, onkey
, ondone)
2586 G.postRedisplay "textentrykeyboard after confirm"
2588 | 0xff52 -> histaction HCprev
2589 | 0xff54 -> histaction HCnext
2590 | 0xff50 -> histaction HCfirst
2591 | 0xff57 -> histaction HClast
2593 | 0xff1b -> (* escape*)
2594 if String.length
text = 0
2596 begin match opthist
with
2598 | Some
(_
, onhistcancel
) -> onhistcancel
()
2602 G.postRedisplay "textentrykeyboard after cancel2"
2605 enttext (c, "", opthist
, onkey
, ondone)
2608 | 0xff9f | 0xffff -> () (* delete *)
2610 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2611 begin match onkey
text key with
2615 G.postRedisplay "textentrykeyboard after confirm2";
2618 enttext (c, text, opthist
, onkey
, ondone);
2622 G.postRedisplay "textentrykeyboard after cancel3"
2625 state.mode
<- Textentry
(te
, onleave
);
2626 G.postRedisplay "textentrykeyboard switch";
2630 vlog "unhandled key %#x" key
2633 let firstof first active
=
2634 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2635 then max
0 (active
- (fstate.maxrows
/2))
2639 let calcfirst first active
=
2642 let rows = active
- first in
2643 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2647 let scrollph y maxy =
2648 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2649 let sh = float conf.winh
/. sh in
2650 let sh = max
sh (float conf.scrollh
) in
2655 else float y /. float maxy
2657 let position = (float conf.winh
-. sh) *. percent in
2660 if position +. sh > float conf.winh
2661 then float conf.winh
-. sh
2667 let coe s = (s :> uioh
);;
2669 class listview ~
(source
:lvsource
) ~trusted
=
2671 val m_pan
= source#getpan
2672 val m_first
= source#getfirst
2673 val m_active
= source#getactive
2674 val m_qsearch
= source#getqsearch
2675 val m_prev_uioh
= state.uioh
2677 method private elemunder
y =
2678 let n = y / (fstate.fontsize
+1) in
2679 if m_first
+ n < source#getitemcount
2681 if source#hasaction
(m_first
+ n)
2682 then Some
(m_first
+ n)
2689 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2690 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2691 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2692 GlDraw.color
(1., 1., 1.);
2693 Gl.enable `texture_2d
;
2694 let fs = fstate.fontsize
in
2696 let ww = fstate.wwidth
in
2697 let tabw = 30.0*.ww in
2698 let itemcount = source#getitemcount
in
2700 if (row - m_first
) * nfs > conf.winh
2703 if row >= 0 && row < itemcount
2705 let (s, level
) = source#getitem
row in
2706 let y = (row - m_first
) * nfs in
2707 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2710 Gl.disable `texture_2d
;
2711 GlDraw.polygon_mode `both `line
;
2712 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2713 GlDraw.rect (1., float (y + 1))
2714 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2715 GlDraw.polygon_mode `both `fill
;
2716 GlDraw.color
(1., 1., 1.);
2717 Gl.enable `texture_2d
;
2720 let drawtabularstring s =
2721 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2724 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2727 let len = String.length
s - tabpos - 1 in
2728 let s1 = String.sub
s 0 tabpos
2729 and s2
= String.sub
s (tabpos + 1) len in
2730 let nx = drawstr x s1 in
2732 let x = x +. (max
tabw sw) in
2739 let _ = drawtabularstring s in
2746 Gl.disable `texture_2d
;
2748 method updownlevel incr
=
2749 let len = source#getitemcount
in
2751 if m_active
>= 0 && m_active
< len
2752 then snd
(source#getitem m_active
)
2756 if i
= len then i
-1 else if i
= -1 then 0 else
2757 let _, l = source#getitem i
in
2758 if l != curlevel then i
else flow (i
+incr
)
2760 let active = flow m_active
in
2761 let first = calcfirst m_first
active in
2762 G.postRedisplay "outline updownlevel";
2763 {< m_active
= active; m_first
= first >}
2765 method private key1
key mask
=
2766 let set1 active first qsearch
=
2767 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2769 let search active pattern incr
=
2772 if n >= 0 && n < source#getitemcount
2774 let s, _ = source#getitem
n in
2776 (try ignore
(Str.search_forward
re s 0); true
2777 with Not_found
-> false)
2779 else loop (n + incr
)
2786 let re = Str.regexp_case_fold pattern
in
2792 let itemcount = source#getitemcount
in
2793 let find start incr
=
2795 if i
= -1 || i
= itemcount
2798 if source#hasaction i
2800 else find (i
+ incr
)
2805 let set active first =
2806 let first = bound first 0 (itemcount - fstate.maxrows
) in
2808 coe {< m_active
= active; m_first
= first >}
2811 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2813 let incr1 = if incr
> 0 then 1 else -1 in
2814 if isvisible m_first m_active
2817 let next = m_active
+ incr
in
2819 if next < 0 || next >= itemcount
2821 else find next incr1
2823 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2829 let first = m_first
+ incr
in
2830 let first = bound first 0 (itemcount - 1) in
2832 let next = m_active
+ incr
in
2833 let next = bound next 0 (itemcount - 1) in
2836 let active = if next = -1 then m_active
else next in
2839 let first = min
next m_first
in
2841 if abs
(next - first) > fstate.maxrows
2847 let first = m_first
+ incr
in
2848 let first = bound first 0 (itemcount - 1) in
2850 let next = m_active
+ incr
in
2851 let next = bound next 0 (itemcount - 1) in
2852 let next = find next incr1 in
2854 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2856 let active = if m_active
= -1 then next else m_active
in
2861 if isvisible first active
2867 G.postRedisplay "listview navigate";
2871 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
2872 let incr = if key = 0x72 then -1 else 1 in
2874 match search (m_active
+ incr) m_qsearch
incr with
2876 state.text <- m_qsearch ^
" [not found]";
2879 state.text <- m_qsearch
;
2880 active, firstof m_first
active
2882 G.postRedisplay "listview ctrl-r/s";
2883 set1 active first m_qsearch
;
2885 | 0xff08 -> (* backspace *)
2886 if String.length m_qsearch
= 0
2889 let qsearch = withoutlastutf8 m_qsearch
in
2890 let len = String.length
qsearch in
2894 G.postRedisplay "listview empty qsearch";
2895 set1 m_active m_first
"";
2899 match search m_active
qsearch ~
-1 with
2901 state.text <- qsearch ^
" [not found]";
2904 state.text <- qsearch;
2905 active, firstof m_first
active
2907 G.postRedisplay "listview backspace qsearch";
2908 set1 active first qsearch
2911 | key when ((key >= 32 && key < 127)
2912 || (key != 0 && key land 0xff00 != 0xff00)) ->
2914 if key >= 32 && key < 127
2915 then addchar m_qsearch
(Char.chr
key)
2916 else m_qsearch ^
Wsi.toutf8
key
2919 match search m_active
pattern 1 with
2921 state.text <- pattern ^
" [not found]";
2924 state.text <- pattern;
2925 active, firstof m_first
active
2927 G.postRedisplay "listview qsearch add";
2928 set1 active first pattern;
2930 | 0xff1b -> (* escape *)
2932 if String.length m_qsearch
= 0
2934 G.postRedisplay "list view escape";
2937 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2939 | None
-> m_prev_uioh
2944 G.postRedisplay "list view kill qsearch";
2945 source#setqsearch
"";
2946 coe {< m_qsearch
= "" >}
2949 | 0xff0d -> (* return *)
2951 let self = {< m_qsearch
= "" >} in
2952 source#setqsearch
"";
2954 G.postRedisplay "listview enter";
2955 if m_active
>= 0 && m_active
< source#getitemcount
2957 source#exit
(coe self) false m_active m_first m_pan
"";
2960 source#exit
(coe self) true m_active m_first m_pan
"";
2963 begin match opt with
2964 | None
-> m_prev_uioh
2968 | 0xff9f | 0xffff -> (* delete *)
2971 | 0xff52 -> navigate ~
-1 (* up *)
2972 | 0xff54 -> navigate 1 (* down *)
2973 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
2974 | 0xff56 -> navigate fstate.maxrows
(* next *)
2976 | 0xff53 -> (* right *)
2978 G.postRedisplay "listview right";
2979 coe {< m_pan
= m_pan
- 1 >}
2981 | 0xff51 -> (* left *)
2983 G.postRedisplay "listview left";
2984 coe {< m_pan
= m_pan
+ 1 >}
2986 | 0xff50 -> (* home *)
2987 let active = find 0 1 in
2988 G.postRedisplay "listview home";
2991 | 0xff57 -> (* end *)
2992 let first = max
0 (itemcount - fstate.maxrows
) in
2993 let active = find (itemcount - 1) ~
-1 in
2994 G.postRedisplay "listview end";
2997 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3001 dolog "listview unknown key %#x" key; coe self
3003 method key key mask
=
3004 match state.mode
with
3005 | Textentry te
-> textentrykeyboard key mask te
; coe self
3006 | _ -> self#key1
key mask
3008 method button button down
x y _ =
3011 | 1 when x > conf.winw
- conf.scrollbw
->
3012 G.postRedisplay "listview scroll";
3015 let _, position, sh = self#
scrollph in
3016 if y > truncate
position && y < truncate
(position +. sh)
3018 state.mstate
<- Mscrolly
;
3022 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3023 let first = truncate
(s *. float source#getitemcount
) in
3024 let first = min source#getitemcount
first in
3025 Some
(coe {< m_first
= first; m_active
= first >})
3027 state.mstate
<- Mnone
;
3030 | 1 when not down
->
3031 begin match self#elemunder
y with
3033 G.postRedisplay "listview click";
3035 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3039 | n when (n == 4 || n == 5) && not down
->
3040 let len = source#getitemcount
in
3042 if n = 5 && m_first
+ fstate.maxrows
>= len
3046 let first = m_first
+ (if n == 3 then -1 else 1) in
3047 bound first 0 (len - 1)
3049 G.postRedisplay "listview wheel";
3050 Some
(coe {< m_first
= first >})
3055 | None
-> m_prev_uioh
3059 match state.mstate
with
3061 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3062 let first = truncate
(s *. float source#getitemcount
) in
3063 let first = min source#getitemcount
first in
3064 G.postRedisplay "listview motion";
3065 coe {< m_first
= first; m_active
= first >}
3068 method pmotion
x y =
3069 if x < conf.winw
- conf.scrollbw
3072 match self#elemunder
y with
3073 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3074 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3078 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3083 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3087 method infochanged
_ = ()
3089 method scrollpw
= (0, 0.0, 0.0)
3091 let nfs = fstate.fontsize
+ 1 in
3092 let y = m_first
* nfs in
3093 let itemcount = source#getitemcount
in
3094 let maxi = max
0 (itemcount - fstate.maxrows
) in
3095 let maxy = maxi * nfs in
3096 let p, h = scrollph y maxy in
3100 class outlinelistview ~source
=
3102 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3104 method key key mask
=
3105 let calcfirst first active =
3108 let rows = active - first in
3109 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3113 let active = m_active
+ incr in
3114 let active = bound active 0 (source#getitemcount
- 1) in
3115 let first = calcfirst m_first
active in
3116 G.postRedisplay "outline navigate";
3117 coe {< m_active
= active; m_first
= first >}
3120 | 110 when Wsi.withctrl mask
-> (* ctrl-n *)
3121 source#narrow m_qsearch
;
3122 G.postRedisplay "outline ctrl-n";
3123 coe {< m_first
= 0; m_active
= 0 >}
3125 | 117 when Wsi.withctrl mask
-> (* ctrl-u *)
3127 G.postRedisplay "outline ctrl-u";
3129 coe {< m_first
= 0; m_active
= 0 >}
3131 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
3132 let first = m_active
- (fstate.maxrows
/ 2) in
3133 G.postRedisplay "outline ctrl-l";
3134 coe {< m_first
= first >}
3136 | 0xff9f | 0xffff -> (* delete *)
3137 source#remove m_active
;
3138 G.postRedisplay "outline delete";
3139 let active = max
0 (m_active
-1) in
3140 coe {< m_first
= firstof m_first
active;
3141 m_active
= active >}
3143 | 0xff52 -> navigate ~
-1 (* up *)
3144 | 0xff54 -> navigate 1 (* down *)
3145 | 0xff55 -> (* prior *)
3146 navigate ~
-(fstate.maxrows
)
3147 | 0xff56 -> (* next *)
3148 navigate fstate.maxrows
3150 | 0xff53 -> (* [ctrl-]right *)
3152 if Wsi.withctrl mask
3154 G.postRedisplay "outline ctrl right";
3155 {< m_pan
= m_pan
+ 1 >}
3157 else self#updownlevel
1
3161 | 0xff51 -> (* [ctrl-]left *)
3163 if Wsi.withctrl mask
3165 G.postRedisplay "outline ctrl left";
3166 {< m_pan
= m_pan
- 1 >}
3168 else self#updownlevel ~
-1
3172 | 0xff50 -> (* home *)
3173 G.postRedisplay "outline home";
3174 coe {< m_first
= 0; m_active
= 0 >}
3176 | 0xff57 -> (* end *)
3177 let active = source#getitemcount
- 1 in
3178 let first = max
0 (active - fstate.maxrows
) in
3179 G.postRedisplay "outline end";
3180 coe {< m_active
= active; m_first
= first >}
3182 | _ -> super#
key key mask
3185 let outlinesource usebookmarks
=
3188 inherit lvsourcebase
3189 val mutable m_items
= empty
3190 val mutable m_orig_items
= empty
3191 val mutable m_prev_items
= empty
3192 val mutable m_narrow_pattern
= ""
3193 val mutable m_hadremovals
= false
3195 method getitemcount
=
3196 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3199 if n == Array.length m_items
&& m_hadremovals
3201 ("[Confirm removal]", 0)
3203 let s, n, _ = m_items
.(n) in
3206 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3207 ignore
(uioh
, first, qsearch);
3208 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3210 if String.length m_narrow_pattern
= 0
3216 if not
confrimremoval
3218 let _, _, anchor = m_items
.(active) in
3223 state.bookmarks
<- Array.to_list m_items
;
3224 m_orig_items
<- m_items
;
3227 else m_items
<- items;
3231 method hasaction
_ = true
3234 if Array.length m_items
!= Array.length m_orig_items
3235 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3238 method narrow
pattern =
3239 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3243 let rec loop accu n =
3246 m_narrow_pattern
<- pattern;
3247 m_items
<- Array.of_list
accu
3250 let (s, _, _) as o = m_items
.(n) in
3252 if (try ignore
(Str.search_forward
re s 0); true
3253 with Not_found
-> false)
3259 loop [] (Array.length m_items
- 1)
3264 then Array.of_list
state.bookmarks
3267 m_items
<- m_orig_items
3272 if m
>= 0 && m
< Array.length m_items
3274 m_hadremovals
<- true;
3275 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3276 let n = if n >= m
then n+1 else n in
3281 method reset
anchor items =
3282 m_hadremovals
<- false;
3283 if m_orig_items
== empty || m_prev_items
!= items
3285 m_orig_items
<- items;
3286 if String.length m_narrow_pattern
= 0
3287 then m_items
<- items;
3289 m_prev_items
<- items;
3290 let rely = getanchory anchor in
3292 let rec loop n best bestd
=
3293 if n = Array.length m_items
3296 let (_, _, anchor) = m_items
.(n) in
3297 let orely = getanchory anchor in
3298 let d = abs
(orely - rely) in
3301 else loop (n+1) best bestd
3306 m_first
<- firstof m_first
active
3310 let enterselector usebookmarks
=
3311 let source = outlinesource usebookmarks
in
3315 then Array.of_list
state.bookmarks
3318 if Array.length
outlines = 0
3320 showtext ' ' errmsg
;
3323 state.text <- source#greetmsg
;
3324 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3325 let anchor = getanchor () in
3326 source#reset
anchor outlines;
3327 state.uioh
<- coe (new outlinelistview ~
source);
3328 G.postRedisplay "enter selector";
3332 let enteroutlinemode =
3333 let f = enterselector false in
3334 fun ()-> f "Document has no outline";
3337 let enterbookmarkmode =
3338 let f = enterselector true in
3339 fun () -> f "Document has no bookmarks (yet)";
3342 let color_of_string s =
3343 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3344 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3348 let color_to_string (r
, g
, b) =
3349 let r = truncate
(r *. 256.0)
3350 and g
= truncate
(g
*. 256.0)
3351 and b = truncate
(b *. 256.0) in
3352 Printf.sprintf
"%d/%d/%d" r g
b
3355 let irect_of_string s =
3356 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3359 let irect_to_string (x0,y0,x1,y1) =
3360 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3363 let makecheckers () =
3364 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3366 converted by Issac Trotts. July 25, 2002 *)
3367 let image_height = 64
3368 and image_width
= 64 in
3372 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3374 for i
= 0 to image_width
- 1 do
3375 for j
= 0 to image_height - 1 do
3376 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3377 (if (i
land 8 ) lxor (j
land 8) = 0
3378 then [|255;255;255|] else [|200;200;200|])
3383 let image = make_image () in
3384 let id = GlTex.gen_texture
() in
3385 GlTex.bind_texture `texture_2d
id;
3386 GlPix.store
(`unpack_alignment
1);
3387 GlTex.image2d
image;
3388 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3391 `mag_filter `nearest
;
3392 `min_filter `nearest
];
3396 let setcheckers enabled
=
3397 match state.texid
with
3399 if enabled
then state.texid
<- Some
(makecheckers ())
3404 GlTex.delete_texture texid
;
3405 state.texid
<- None
;
3409 let int_of_string_with_suffix s =
3410 let l = String.length
s in
3414 let suffix = Char.lowercase
s.[l-1] in
3416 | 'k'
-> String.sub
s 0 (l-1), 10
3417 | 'm'
-> String.sub
s 0 (l-1), 20
3418 | 'g'
-> String.sub
s 0 (l-1), 30
3422 let n = int_of_string
s1 in
3423 let m = n lsl shift
in
3425 then raise
(Failure
"value too large")
3429 let string_with_suffix_of_int n =
3437 if n land ((1 lsl 20) - 1) = 0
3440 if n land ((1 lsl 10) - 1) = 0
3447 let h = n mod 1000 in
3450 then string_of_int
h ^
s
3452 let s = Printf.sprintf
"_%03d%s" h s in
3459 let defghyllscroll = (40, 8, 32);;
3460 let ghyllscroll_of_string s =
3461 let (n, a, b) as nab
=
3464 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3466 if n <= a || n <= b || a >= b
3467 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3471 let ghyllscroll_to_string ((n, a, b) as nab
) =
3472 if nab
= defghyllscroll
3474 else Printf.sprintf
"%d,%d,%d" n a b;
3477 let describe_location () =
3479 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3481 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3482 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3486 else (100. *. (float state.y /. float maxy))
3490 Printf.sprintf
"page %d of %d [%.2f%%]"
3491 (fn+1) state.pagecount
percent
3494 "pages %d-%d of %d [%.2f%%]"
3495 (fn+1) (ln
+1) state.pagecount
percent
3499 let btos b = if b then "\xe2\x88\x9a" else "" in
3500 let showextended = ref false in
3501 let leave mode
= function
3502 | Confirm
-> state.mode
<- mode
3503 | Cancel
-> state.mode
<- mode
in
3506 val mutable m_first_time
= true
3507 val mutable m_l
= []
3508 val mutable m_a
= [||]
3509 val mutable m_prev_uioh
= nouioh
3510 val mutable m_prev_mode
= View
3512 inherit lvsourcebase
3514 method reset prev_mode prev_uioh
=
3515 m_a
<- Array.of_list
(List.rev m_l
);
3517 m_prev_mode
<- prev_mode
;
3518 m_prev_uioh
<- prev_uioh
;
3522 if n >= Array.length m_a
3526 | _, _, _, Action
_ -> m_active
<- n
3530 m_first_time
<- false;
3533 method int name get
set =
3535 (name
, `
int get
, 1, Action
(
3538 try set (int_of_string
s)
3540 state.text <- Printf.sprintf
"bad integer `%s': %s"
3541 s (Printexc.to_string exn
)
3544 let te = name ^
": ", "", None
, intentry, ondone in
3545 state.mode
<- Textentry
(te, leave m_prev_mode
);
3549 method int_with_suffix name get
set =
3551 (name
, `intws get
, 1, Action
(
3554 try set (int_of_string_with_suffix s)
3556 state.text <- Printf.sprintf
"bad integer `%s': %s"
3557 s (Printexc.to_string exn
)
3561 name ^
": ", "", None
, intentry_with_suffix, ondone
3563 state.mode
<- Textentry
(te, leave m_prev_mode
);
3567 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3569 (name
, `
bool (btos, get
), offset
, Action
(
3576 method color name get
set =
3578 (name
, `color get
, 1, Action
(
3580 let invalid = (nan
, nan
, nan
) in
3583 try color_of_string s
3585 state.text <- Printf.sprintf
"bad color `%s': %s"
3586 s (Printexc.to_string exn
);
3592 let te = name ^
": ", "", None
, textentry, ondone in
3593 state.text <- color_to_string (get
());
3594 state.mode
<- Textentry
(te, leave m_prev_mode
);
3598 method string name get
set =
3600 (name
, `
string get
, 1, Action
(
3602 let ondone s = set s in
3603 let te = name ^
": ", "", None
, textentry, ondone in
3604 state.mode
<- Textentry
(te, leave m_prev_mode
);
3608 method colorspace name get
set =
3610 (name
, `
string get
, 1, Action
(
3613 let vals = [| "rgb"; "bgr"; "gray" |] in
3615 inherit lvsourcebase
3618 m_active
<- int_of_colorspace conf.colorspace
;
3621 method getitemcount
= Array.length
vals
3622 method getitem
n = (vals.(n), 0)
3623 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3624 ignore
(uioh
, first, pan
, qsearch);
3625 if not cancel
then set active;
3627 method hasaction
_ = true
3631 coe (new listview ~
source ~trusted
:true)
3634 method caption
s offset
=
3635 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3637 method caption2
s f offset
=
3638 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3640 method getitemcount
= Array.length m_a
3643 let tostr = function
3644 | `
int f -> string_of_int
(f ())
3645 | `intws
f -> string_with_suffix_of_int (f ())
3647 | `color
f -> color_to_string (f ())
3648 | `
bool (btos, f) -> btos (f ())
3651 let name, t
, offset
, _ = m_a
.(n) in
3652 ((let s = tostr t
in
3653 if String.length
s > 0
3654 then Printf.sprintf
"%s\t%s" name s
3658 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3662 m_qsearch
<- qsearch;
3664 match m_a
.(active) with
3665 | _, _, _, Action
f -> f uioh
3677 method hasaction
n =
3679 | _, _, _, Action
_ -> true
3683 let rec fillsrc prevmode prevuioh
=
3684 let sep () = src#caption
"" 0 in
3685 let colorp name get
set =
3687 (fun () -> color_to_string (get
()))
3690 let c = color_of_string v in
3693 state.text <- Printf.sprintf
"bad color `%s': %s"
3694 v (Printexc.to_string exn
);
3697 let oldmode = state.mode
in
3698 let birdseye = isbirdseye state.mode
in
3700 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3702 src#
bool "presentation mode"
3703 (fun () -> conf.presentation)
3705 conf.presentation <- v;
3706 state.anchor <- getanchor ();
3709 src#
bool "ignore case in searches"
3710 (fun () -> conf.icase
)
3711 (fun v -> conf.icase
<- v);
3714 (fun () -> conf.preload)
3715 (fun v -> conf.preload <- v);
3717 src#
bool "highlight links"
3718 (fun () -> conf.hlinks
)
3719 (fun v -> conf.hlinks
<- v);
3721 src#
bool "under info"
3722 (fun () -> conf.underinfo
)
3723 (fun v -> conf.underinfo
<- v);
3725 src#
bool "persistent bookmarks"
3726 (fun () -> conf.savebmarks
)
3727 (fun v -> conf.savebmarks
<- v);
3729 src#
bool "proportional display"
3730 (fun () -> conf.proportional
)
3731 (fun v -> reqlayout conf.angle
v);
3733 src#
bool "trim margins"
3734 (fun () -> conf.trimmargins
)
3735 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3737 src#
bool "persistent location"
3738 (fun () -> conf.jumpback
)
3739 (fun v -> conf.jumpback
<- v);
3742 src#
int "inter-page space"
3743 (fun () -> conf.interpagespace)
3745 conf.interpagespace <- n;
3747 match state.layout with
3752 state.maxy <- calcheight ();
3753 let y = getpagey pageno in
3758 (fun () -> conf.pagebias
)
3759 (fun v -> conf.pagebias
<- v);
3761 src#
int "scroll step"
3762 (fun () -> conf.scrollstep
)
3763 (fun n -> conf.scrollstep
<- n);
3765 src#
int "auto scroll step"
3767 match state.autoscroll
with
3769 | _ -> conf.autoscrollstep
)
3771 if state.autoscroll
<> None
3772 then state.autoscroll
<- Some
n;
3773 conf.autoscrollstep
<- n);
3776 (fun () -> truncate
(conf.zoom *. 100.))
3777 (fun v -> setzoom ((float v) /. 100.));
3780 (fun () -> conf.angle
)
3781 (fun v -> reqlayout v conf.proportional
);
3783 src#
int "scroll bar width"
3784 (fun () -> state.scrollw
)
3788 reshape conf.winw
conf.winh
;
3791 src#
int "scroll handle height"
3792 (fun () -> conf.scrollh
)
3793 (fun v -> conf.scrollh
<- v;);
3795 src#
int "thumbnail width"
3796 (fun () -> conf.thumbw
)
3798 conf.thumbw
<- min
4096 v;
3801 leavebirdseye beye
false;
3806 src#
string "columns"
3808 match conf.columns
with
3810 | Some
(multicol
, _) -> columns_to_string multicol
)
3812 let n, a, b = columns_of_string v in
3816 src#caption
"Presentation mode" 0;
3817 src#
bool "scrollbar visible"
3818 (fun () -> conf.scrollbarinpm
)
3820 if v != conf.scrollbarinpm
3822 conf.scrollbarinpm
<- v;
3823 if conf.presentation
3825 state.scrollw
<- if v then conf.scrollbw
else 0;
3826 reshape conf.winw
conf.winh
;
3832 src#caption
"Pixmap cache" 0;
3833 src#int_with_suffix
"size (advisory)"
3834 (fun () -> conf.memlimit
)
3835 (fun v -> conf.memlimit
<- v);
3838 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3839 (string_with_suffix_of_int state.memused
)
3840 (Hashtbl.length
state.tilemap
)) 1;
3843 src#caption
"Layout" 0;
3844 src#caption2
"Dimension"
3846 Printf.sprintf
"%dx%d (virtual %dx%d)"
3852 src#caption2
"Position" (fun () ->
3853 Printf.sprintf
"%dx%d" state.x state.y
3856 src#caption2
"Visible" (fun () -> describe_location ()) 1
3860 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3861 "Save these parameters as global defaults at exit"
3862 (fun () -> conf.bedefault
)
3863 (fun v -> conf.bedefault
<- v)
3867 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3868 src#
bool ~offset
:0 ~
btos "Extended parameters"
3869 (fun () -> !showextended)
3870 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3874 (fun () -> conf.checkers
)
3875 (fun v -> conf.checkers
<- v; setcheckers v);
3877 (fun () -> conf.verbose
)
3878 (fun v -> conf.verbose
<- v);
3879 src#
bool "invert colors"
3880 (fun () -> conf.invert
)
3881 (fun v -> conf.invert
<- v);
3883 (fun () -> conf.maxhfit
)
3884 (fun v -> conf.maxhfit
<- v);
3885 src#
bool "redirect stderr"
3886 (fun () -> conf.redirectstderr)
3887 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3888 src#
string "uri launcher"
3889 (fun () -> conf.urilauncher
)
3890 (fun v -> conf.urilauncher
<- v);
3891 src#
string "tile size"
3892 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3895 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3896 conf.tileh
<- max
64 w;
3897 conf.tilew
<- max
64 h;
3900 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3901 v (Printexc.to_string exn
));
3902 src#
int "texture count"
3903 (fun () -> conf.texcount
)
3906 then conf.texcount
<- v
3907 else showtext '
!'
" Failed to set texture count please retry later"
3909 src#
int "slice height"
3910 (fun () -> conf.sliceheight
)
3912 conf.sliceheight
<- v;
3913 wcmd "sliceh" [`i
conf.sliceheight
];
3915 src#
int "anti-aliasing level"
3916 (fun () -> conf.aalevel
)
3918 conf.aalevel
<- bound v 0 8;
3919 state.anchor <- getanchor ();
3920 opendoc state.path
state.password
;
3922 src#
int "ui font size"
3923 (fun () -> fstate.fontsize
)
3924 (fun v -> setfontsize (bound v 5 100));
3925 colorp "background color"
3926 (fun () -> conf.bgcolor
)
3927 (fun v -> conf.bgcolor
<- v);
3928 src#
bool "crop hack"
3929 (fun () -> conf.crophack
)
3930 (fun v -> conf.crophack
<- v);
3931 src#
string "trim fuzz"
3932 (fun () -> irect_to_string conf.trimfuzz
)
3935 conf.trimfuzz
<- irect_of_string v;
3937 then settrim true conf.trimfuzz
;
3939 state.text <- Printf.sprintf
"bad irect `%s': %s"
3940 v (Printexc.to_string exn
)
3942 src#
string "throttle"
3944 match conf.maxwait
with
3945 | None
-> "show place holder if page is not ready"
3948 then "wait for page to fully render"
3950 "wait " ^ string_of_float
time
3951 ^
" seconds before showing placeholder"
3955 let f = float_of_string
v in
3957 then conf.maxwait
<- None
3958 else conf.maxwait
<- Some
f
3960 state.text <- Printf.sprintf
"bad time `%s': %s"
3961 v (Printexc.to_string exn
)
3963 src#
string "ghyll scroll"
3965 match conf.ghyllscroll
with
3967 | Some nab
-> ghyllscroll_to_string nab
3972 if String.length
v = 0
3974 else Some
(ghyllscroll_of_string v)
3976 conf.ghyllscroll
<- gs
3978 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3979 v (Printexc.to_string exn
)
3981 src#
string "selection command"
3982 (fun () -> conf.selcmd
)
3983 (fun v -> conf.selcmd
<- v);
3984 src#colorspace
"color space"
3985 (fun () -> colorspace_to_string conf.colorspace
)
3987 conf.colorspace
<- colorspace_of_int v;
3994 src#caption
"Document" 0;
3995 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3996 src#caption2
"Pages"
3997 (fun () -> string_of_int
state.pagecount
) 1;
3998 src#caption2
"Dimensions"
3999 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4003 src#caption
"Trimmed margins" 0;
4004 src#caption2
"Dimensions"
4005 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4008 src#reset prevmode prevuioh
;
4012 let prevmode = state.mode
4013 and prevuioh
= state.uioh in
4014 fillsrc prevmode prevuioh
;
4015 let source = (src :> lvsource
) in
4016 state.uioh <- coe (object (self)
4017 inherit listview ~
source ~trusted
:true as super
4018 val mutable m_prevmemused
= 0
4019 method infochanged
= function
4021 if m_prevmemused
!= state.memused
4023 m_prevmemused
<- state.memused
;
4024 G.postRedisplay "memusedchanged";
4026 | Pdim
-> G.postRedisplay "pdimchanged"
4027 | Docinfo
-> fillsrc prevmode prevuioh
4029 method key key mask
=
4030 if not
(Wsi.withctrl mask
)
4033 | 0xff51 -> coe (self#updownlevel ~
-1)
4034 | 0xff53 -> coe (self#updownlevel
1)
4035 | _ -> super#
key key mask
4036 else super#
key key mask
4038 G.postRedisplay "info";
4044 inherit lvsourcebase
4045 method getitemcount
= Array.length
state.help
4047 let s, n, _ = state.help
.(n) in
4050 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4054 m_qsearch
<- qsearch;
4055 match state.help
.(active) with
4056 | _, _, Action
f -> Some
(f uioh)
4066 method hasaction
n =
4067 match state.help
.(n) with
4068 | _, _, Action
_ -> true
4075 state.uioh <- coe (new listview ~
source ~trusted
:true);
4076 G.postRedisplay "help";
4081 let re = Str.regexp
"[\r\n]" in
4083 inherit lvsourcebase
4084 val mutable m_items
= [||]
4086 method getitemcount
= 1 + Array.length m_items
4091 else m_items
.(n-1), 0
4093 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4098 then Buffer.clear
state.errmsgs
;
4099 m_qsearch
<- qsearch;
4106 method hasaction
n =
4110 state.newerrmsgs
<- false;
4111 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4112 m_items
<- Array.of_list
l
4120 let source = (msgsource :> lvsource
) in
4121 state.uioh <- coe (object
4122 inherit listview ~
source ~trusted
:false as super
4125 then msgsource#reset
;
4128 G.postRedisplay "msgs";
4131 let quickbookmark ?title
() =
4132 match state.layout with
4138 let sec = Unix.gettimeofday
() in
4139 let tm = Unix.localtime
sec in
4140 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4144 (tm.Unix.tm_year
+ 1900)
4147 | Some
title -> title
4150 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4155 state.fullscreen
<- None
;
4159 let setautoscrollspeed step goingdown
=
4160 let incr = max
1 ((abs step
) / 2) in
4161 let incr = if goingdown
then incr else -incr in
4162 let astep = step
+ incr in
4163 state.autoscroll
<- Some
astep;
4166 let viewkeyboard key mask
=
4168 let mode = state.mode in
4169 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4172 G.postRedisplay "view:enttext"
4178 | 0xff1b | 113 -> (* escape / q *)
4179 begin match state.mstate
with
4181 state.mstate
<- Mnone
;
4182 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4183 G.postRedisplay "kill zoom rect";
4185 match state.ranchors
with
4186 | [] -> raise
Wsi.Quit
4187 | (path
, password
, anchor) :: rest
->
4188 state.ranchors
<- rest
;
4189 state.anchor <- anchor;
4190 opendoc path password
4193 | 0xff08 -> (* backspace *)
4194 let y = getnav ~
-1 in
4195 gotoy_and_clear_text y
4203 G.postRedisplay "dehighlight";
4205 | 47 | 63 -> (* / ? *)
4206 let ondone isforw
s =
4207 cbput state.hists
.pat
s;
4208 state.searchpattern
<- s;
4211 let s = String.create
1 in
4212 s.[0] <- Char.chr
key;
4213 enttext (s, "", Some
(onhist state.hists
.pat
),
4214 textentry, ondone (key = 47))
4216 | 43 | 0xffab when Wsi.withctrl mask
-> (* + *)
4217 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4218 setzoom (conf.zoom +. incr)
4220 | 43 | 0xffab -> (* + *)
4223 try int_of_string
s with exc
->
4224 state.text <- Printf.sprintf
"bad integer `%s': %s"
4225 s (Printexc.to_string exc
);
4231 state.text <- "page bias is now " ^ string_of_int
n;
4234 enttext ("page bias: ", "", None
, intentry, ondone)
4236 | 45 | 0xffad when Wsi.withctrl mask
-> (* - *)
4237 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4238 setzoom (max
0.01 (conf.zoom -. decr))
4240 | 45 | 0xffad -> (* - *)
4241 let ondone msg
= state.text <- msg
in
4243 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4244 optentry state.mode, ondone
4247 | 48 when Wsi.withctrl mask
-> (* 0 *)
4250 | 49 when Wsi.withctrl mask
-> (* 1 *)
4251 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4255 | 0xffc6 -> (* f9 *)
4258 | 57 when Wsi.withctrl mask
-> (* ctrl-9 *)
4261 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4262 when not
(Wsi.withctrl mask
) -> (* 0..9 *)
4265 try int_of_string
s with exc
->
4266 state.text <- Printf.sprintf
"bad integer `%s': %s"
4267 s (Printexc.to_string exc
);
4273 cbput state.hists
.pag
(string_of_int
n);
4274 gotopage1 (n + conf.pagebias
- 1) 0;
4277 let pageentry text key =
4278 match Char.unsafe_chr
key with
4279 | 'g'
-> TEdone
text
4280 | _ -> intentry text key
4282 let text = "x" in text.[0] <- Char.chr
key;
4283 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4286 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4287 reshape conf.winw
conf.winh
;
4290 conf.hlinks
<- not
conf.hlinks
;
4291 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4292 G.postRedisplay "toggle highlightlinks";
4295 begin match state.autoscroll
with
4297 conf.autoscrollstep
<- step
;
4298 state.autoscroll
<- None
4300 if conf.autoscrollstep
= 0
4301 then state.autoscroll
<- Some
1
4302 else state.autoscroll
<- Some
conf.autoscrollstep
4306 conf.presentation <- not
conf.presentation;
4307 if conf.presentation
4309 if not
conf.scrollbarinpm
4310 then state.scrollw
<- 0;
4313 state.scrollw
<- conf.scrollbw
;
4315 showtext ' '
("presentation mode " ^
4316 if conf.presentation then "on" else "off");
4317 state.anchor <- getanchor ();
4321 begin match state.fullscreen
with
4323 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4326 state.fullscreen
<- None
;
4331 gotoy_and_clear_text 0
4334 gotopage1 (state.pagecount
- 1) 0
4336 | 112 | 78 -> (* p|N *)
4337 search state.searchpattern
false
4340 search state.searchpattern
true
4343 begin match state.layout with
4346 gotoy_and_clear_text (getpagey l.pageno)
4350 begin match List.rev
state.layout with
4353 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4354 gotoy_and_clear_text (getpagey pageno)
4357 | 0xff9f | 0xffff -> (* delete *)
4358 begin match state.layout with
4361 let pageno = max
0 (l.pageno-1) in
4362 gotoy_and_clear_text (getpagey pageno)
4366 showtext ' '
(describe_location ());
4369 begin match state.layout with
4372 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4377 enterbookmarkmode ()
4385 | 101 when conf.redirectstderr -> (* e *)
4390 match state.layout with
4393 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4397 enttext ("bookmark: ", "", None
, textentry, ondone)
4401 showtext ' '
"Quick bookmark added";
4404 begin match state.layout with
4406 let rect = getpdimrect
l.pagedimno
in
4410 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4411 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4413 (truncate
(rect.(1) -. rect.(0)),
4414 truncate
(rect.(3) -. rect.(0)))
4416 let w = truncate
((float w)*.conf.zoom)
4417 and h = truncate
((float h)*.conf.zoom) in
4420 state.anchor <- getanchor ();
4421 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4423 G.postRedisplay "z";
4428 | 50 when Wsi.withctrl mask
-> (* ctrl-2 *)
4429 let maxw = getmaxw
() in
4431 then setzoom (maxw /. float conf.winw
)
4433 | 60 | 62 -> (* < > *)
4434 reqlayout (conf.angle
+ (if key = 60 then 30 else -30)) conf.proportional
4436 | 91 | 93 -> (* [ ] *)
4438 bound (conf.colorscale
+. (if key = 92 then 0.1 else -0.1)) 0.0 1.0
4440 G.postRedisplay "brightness";
4442 | 107 | 0xff52 -> (* k UP *)
4443 begin match state.autoscroll
with
4445 begin match state.mode with
4446 | Birdseye beye
-> upbirdseye 1 beye
4448 if Wsi.withctrl mask
4449 then gotoy (-clamp (conf.winh
/2))
4450 else gotoy (clamp (-conf.scrollstep
))
4453 setautoscrollspeed n false
4456 | 106 | 0xff54 -> (* j DOWN *)
4457 begin match state.autoscroll
with
4459 begin match state.mode with
4460 | Birdseye beye
-> downbirdseye 1 beye
4462 if Wsi.withctrl mask
4463 then gotoy (clamp (conf.winh
/2))
4464 else gotoy (clamp conf.scrollstep
)
4467 setautoscrollspeed n true
4470 | 0xff51 | 0xff53 (* left / right *)
4471 when conf.zoom > 1.0->
4473 if Wsi.withctrl mask
4477 let dx = if key = 0xff51 then dx else -dx in
4478 state.x <- state.x + dx;
4481 | 0xff55 -> (* prior *)
4483 if Wsi.withctrl mask
4485 match state.layout with
4487 | l :: _ -> state.y - l.pagey
4493 | 0xff56 -> (* next *)
4495 if Wsi.withctrl mask
4497 match List.rev
state.layout with
4499 | l :: _ -> getpagey l.pageno
4505 | 0xff50 -> gotoghyll 0
4506 | 0xff57 -> gotoghyll (clamp state.maxy)
4507 | 0xff53 when Wsi.withalt mask
->
4508 gotoghyll (getnav ~
-1)
4509 | 0xff51 when Wsi.withalt mask
->
4510 gotoghyll (getnav 1)
4513 state.anchor <- getanchor ();
4514 opendoc state.path
state.password
4516 | 118 when conf.debug
-> (* v *)
4519 match getopaque l.pageno with
4522 let x0, y0, x1, y1 = pagebbox opaque
in
4523 let a,b = float x0, float y0 in
4524 let c,d = float x1, float y0 in
4525 let e,f = float x1, float y1 in
4526 let h,j
= float x0, float y1 in
4527 let rect = (a,b,c,d,e,f,h,j
) in
4529 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4531 G.postRedisplay "v";
4537 let keyboard key mask
=
4538 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
4539 then wcmd "interrupt" []
4540 else state.uioh <- state.uioh#
key key mask
4543 let birdseyekeyboard key mask
4544 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4546 match conf.columns
with
4548 | Some
((c, _, _), _) -> c
4551 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
4552 let y, h = getpageyh pageno in
4553 let top = (conf.winh
- h) / 2 in
4554 gotoy (max
0 (y - top))
4555 | 0xff0d -> leavebirdseye beye
false
4556 | 0xff1b -> leavebirdseye beye
true (* escape *)
4557 | 0xff52 -> upbirdseye incr beye
(* prior *)
4558 | 0xff54 -> downbirdseye incr beye
(* next *)
4559 | 0xff51 -> upbirdseye 1 beye
(* up *)
4560 | 0xff53 -> downbirdseye 1 beye
(* down *)
4563 begin match state.layout with
4567 state.mode <- Birdseye
(
4568 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4570 gotopage1 l.pageno 0;
4573 let layout = layout (state.y-conf.winh
) conf.winh
in
4575 | [] -> gotoy (clamp (-conf.winh
))
4577 state.mode <- Birdseye
(
4578 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4580 gotopage1 l.pageno 0
4583 | [] -> gotoy (clamp (-conf.winh
))
4587 begin match List.rev
state.layout with
4589 let layout = layout (state.y + conf.winh
) conf.winh
in
4590 begin match layout with
4592 let incr = l.pageh
- l.pagevh in
4597 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4599 G.postRedisplay "birdseye pagedown";
4601 else gotoy (clamp (incr + conf.interpagespace*2));
4605 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4606 gotopage1 l.pageno 0;
4609 | [] -> gotoy (clamp conf.winh
)
4613 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4617 let pageno = state.pagecount
- 1 in
4618 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4619 if not
(pagevisible state.layout pageno)
4622 match List.rev
state.pdims
with
4624 | (_, _, h, _) :: _ -> h
4626 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4627 else G.postRedisplay "birdseye end";
4628 | _ -> viewkeyboard key mask
4633 match state.mode with
4634 | Textentry
_ -> scalecolor 0.4
4635 | View
-> scalecolor 1.0
4636 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4637 if l.pageno = hooverpageno
4640 if l.pageno = pageno
4646 begin match getopaque l.pageno with
4648 if tileready l l.pagex l.pagey
4650 let x = l.pagedispx - l.pagex
4651 and y = l.pagedispy - l.pagey in
4652 postprocess opaque
conf.hlinks
x y;
4658 let scrollindicator () =
4659 let sbw, ph
, sh = state.uioh#
scrollph in
4660 let sbh, pw
, sw = state.uioh#scrollpw
in
4662 GlDraw.color (0.64, 0.64, 0.64);
4664 (float (conf.winw
- sbw), 0.)
4665 (float conf.winw
, float conf.winh
)
4668 (0., float (conf.winh
- sbh))
4669 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4671 GlDraw.color (0.0, 0.0, 0.0);
4674 (float (conf.winw
- sbw), ph
)
4675 (float conf.winw
, ph
+. sh)
4678 (pw
, float (conf.winh
- sbh))
4679 (pw
+. sw, float conf.winh
)
4684 match state.mstate
with
4685 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4688 | Msel
((x0, y0), (x1, y1)) ->
4689 let rec loop = function
4691 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4692 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4693 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4694 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
4696 match getopaque l.pageno with
4698 let dx, dy = pagetranslatepoint l 0 0 in
4703 GlMat.mode `modelview
;
4705 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4706 seltext opaque
(x0, y0, x1, y1);
4717 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4718 GlDraw.polygon_mode `both `fill
;
4719 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4721 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4723 if l.pageno = pageno
4725 let dx = float (l.pagedispx - l.pagex) in
4726 let dy = float (l.pagedispy - l.pagey) in
4727 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4728 GlDraw.begins `quads
;
4730 GlDraw.vertex2
(x0+.dx, y0+.dy);
4731 GlDraw.vertex2
(x1+.dx, y1+.dy);
4732 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4733 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4744 GlClear.color (scalecolor2 conf.bgcolor
);
4745 GlClear.clear
[`
color];
4746 List.iter
drawpage state.layout;
4751 begin match state.mstate
with
4752 | Mzoomrect
((x0, y0), (x1, y1)) ->
4754 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4755 GlDraw.polygon_mode `both `fill
;
4756 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4757 GlDraw.rect (float x0, float y0)
4758 (float x1, float y1);
4765 let mx, my
= state.mpos
in
4771 let zoomrect x y x1 y1 =
4774 and y0 = min
y y1 in
4775 gotoy (state.y + y0);
4776 state.anchor <- getanchor ();
4777 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4779 if state.w < conf.winw
- state.scrollw
4780 then (conf.winw
- state.scrollw
- state.w) / 2
4783 state.x <- (state.x + margin) - x0;
4785 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4786 state.mstate
<- Mnone
;
4790 let winw = conf.winw - state.scrollw
- 1 in
4791 let s = float x /. float winw in
4792 let destx = truncate
(float (state.w + winw) *. s) in
4793 state.x <- winw - destx;
4794 gotoy_and_clear_text state.y;
4795 state.mstate
<- Mscrollx
;
4799 let s = float y /. float conf.winh
in
4800 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4801 gotoy_and_clear_text desty;
4802 state.mstate
<- Mscrolly
;
4805 let viewmouse button down
x y mask
=
4807 | n when (n == 4 || n == 5) && not down
->
4808 if Wsi.withctrl mask
4810 match state.mstate
with
4811 | Mzoom
(oldn
, i
) ->
4819 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4821 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4823 let zoom = conf.zoom -. incr in
4825 state.mstate
<- Mzoom
(n, 0);
4827 state.mstate
<- Mzoom
(n, i
+1);
4829 else state.mstate
<- Mzoom
(n, 0)
4831 | _ -> state.mstate
<- Mzoom
(n, 0)
4834 match state.autoscroll
with
4835 | Some step
-> setautoscrollspeed step
(n=4)
4839 then -conf.scrollstep
4840 else conf.scrollstep
4842 let incr = incr * 2 in
4843 let y = clamp incr in
4844 gotoy_and_clear_text y
4847 | 1 when Wsi.withctrl mask
->
4850 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
4851 state.mstate
<- Mpan
(x, y)
4854 state.mstate
<- Mnone
4859 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4861 state.mstate
<- Mzoomrect
(p, p)
4864 match state.mstate
with
4865 | Mzoomrect
((x0, y0), _) ->
4866 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4867 then zoomrect x0 y0 x y
4869 state.mstate
<- Mnone
;
4870 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4871 G.postRedisplay "kill accidental zoom rect";
4874 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4875 state.mstate
<- Mnone
4878 | 1 when x > conf.winw - state.scrollw
->
4881 let _, position, sh = state.uioh#
scrollph in
4882 if y > truncate
position && y < truncate
(position +. sh)
4883 then state.mstate
<- Mscrolly
4886 state.mstate
<- Mnone
4888 | 1 when y > conf.winh
- state.hscrollh ->
4891 let _, position, sw = state.uioh#scrollpw
in
4892 if x > truncate
position && x < truncate
(position +. sw)
4893 then state.mstate
<- Mscrollx
4896 state.mstate
<- Mnone
4899 let dest = if down
then getunder x y else Unone
in
4900 begin match dest with
4901 | Ulinkgoto
(pageno, top) ->
4905 gotopage1 pageno top;
4911 | Uremote
(filename
, pageno) ->
4913 if Sys.file_exists filename
4916 let dir = Filename.dirname
state.path in
4917 let path = Filename.concat
dir filename
in
4918 if Sys.file_exists
path
4922 if String.length
path > 0
4924 let anchor = getanchor () in
4925 let ranchor = state.path, state.password
, anchor in
4926 state.anchor <- (pageno, 0.0);
4927 state.ranchors
<- ranchor :: state.ranchors
;
4930 else showtext '
!'
("Could not find " ^ filename
)
4932 | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
4934 | Unone
when down
->
4935 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
4936 state.mstate
<- Mpan
(x, y);
4938 | Unone
| Utext
_ ->
4941 if conf.angle
mod 360 = 0
4943 state.mstate
<- Msel
((x, y), (x, y));
4944 G.postRedisplay "mouse select";
4948 match state.mstate
with
4951 | Mzoom
_ | Mscrollx
| Mscrolly
->
4952 state.mstate
<- Mnone
4954 | Mzoomrect
((x0, y0), _) ->
4958 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4959 state.mstate
<- Mnone
4961 | Msel
((_, y0), (_, y1)) ->
4962 let rec loop = function
4965 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4966 || ((y1 >= l.pagedispy
4967 && y1 <= (l.pagedispy + l.pagevh)))
4969 match getopaque l.pageno with
4971 copysel
conf.selcmd opaque
;
4972 G.postRedisplay "copysel"
4977 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4978 state.mstate
<- Mnone
;
4985 let birdseyemouse button down
x y mask
4986 (conf, leftx
, _, hooverpageno
, anchor) =
4989 let rec loop = function
4992 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4993 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4995 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5001 | _ -> viewmouse button down
x y mask
5004 let mouse button down
x y mask
=
5005 state.uioh <- state.uioh#button button down
x y mask
;
5009 state.uioh <- state.uioh#
motion x y
5013 state.uioh <- state.uioh#
pmotion x y;
5019 method key key mask
=
5020 begin match state.mode with
5021 | Textentry
textentry -> textentrykeyboard key mask
textentry
5022 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5023 | View
-> viewkeyboard key mask
5027 method button button bstate
x y mask
=
5028 begin match state.mode with
5029 | View
-> viewmouse button bstate
x y mask
5030 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5036 begin match state.mode with
5038 | View
| Birdseye
_ ->
5039 match state.mstate
with
5040 | Mzoom
_ | Mnone
-> ()
5045 state.mstate
<- Mpan
(x, y);
5046 if conf.zoom > 1.0 then state.x <- state.x + dx;
5048 gotoy_and_clear_text y
5051 state.mstate
<- Msel
(a, (x, y));
5052 G.postRedisplay "motion select";
5055 let y = min
conf.winh
(max
0 y) in
5059 let x = min
conf.winw (max
0 x) in
5062 | Mzoomrect
(p0
, _) ->
5063 state.mstate
<- Mzoomrect
(p0
, (x, y));
5064 G.postRedisplay "motion zoomrect";
5068 method pmotion x y =
5069 begin match state.mode with
5070 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5071 let rec loop = function
5073 if hooverpageno
!= -1
5075 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5076 G.postRedisplay "pmotion birdseye no hoover";
5079 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5080 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5082 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5083 G.postRedisplay "pmotion birdseye hoover";
5092 match state.mstate
with
5093 | Mnone
-> updateunder x y
5094 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5099 method infochanged
_ = ()
5102 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5103 let p, h = scrollph state.y maxy in
5107 let winw = conf.winw - state.scrollw
- 1 in
5108 let fwinw = float winw in
5110 let sw = fwinw /. float state.w in
5111 let sw = fwinw *. sw in
5112 max
sw (float conf.scrollh
)
5115 let f = state.w+winw in
5116 let r = float (winw-state.x) /. float f in
5117 let p = fwinw *. r in
5121 if position +. sw > fwinw
5122 then fwinw -. position
5125 state.hscrollh, position, sw
5132 let fontpath = ref "";;
5135 let l = String.length
s in
5136 let b = Buffer.create
l in
5142 try Sys.getenv
"HOME"
5145 ("Can not determine home directory location: " ^
5146 Printexc.to_string exn
);
5150 let config_of c attrs
=
5154 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5155 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5156 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5157 | "preload" -> { c with preload = bool_of_string
v }
5158 | "page-bias" -> { c with pagebias
= int_of_string
v }
5159 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5160 | "auto-scroll-step" ->
5161 { c with autoscrollstep
= max
0 (int_of_string
v) }
5162 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5163 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5166 match String.lowercase
v with
5167 | "true" -> Some infinity
5169 | f -> Some
(float_of_string
f)
5171 { c with maxwait
= mw}
5172 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5173 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5174 | "vertical-margin" ->
5175 { c with interpagespace = max
0 (int_of_string
v) }
5177 let zoom = float_of_string
v /. 100. in
5178 let zoom = max
zoom 0.0 in
5179 { c with zoom = zoom }
5180 | "presentation" -> { c with presentation = bool_of_string
v }
5181 | "rotation-angle" -> { c with angle
= int_of_string
v }
5182 | "width" -> { c with winw = max
20 (int_of_string
v) }
5183 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5184 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5185 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5186 | "pixmap-cache-size" ->
5187 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5188 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5189 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5190 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5191 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5192 | "background-color" -> { c with bgcolor
= color_of_string v }
5193 | "scrollbar-in-presentation" ->
5194 { c with scrollbarinpm
= bool_of_string
v }
5195 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5196 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5197 | "mupdf-store-size" ->
5198 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5199 | "checkers" -> { c with checkers
= bool_of_string
v }
5200 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5201 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5202 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5203 | "uri-launcher" -> { c with urilauncher
= unent v }
5204 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5205 | "invert-colors" -> { c with invert
= bool_of_string
v }
5206 | "brightness" -> { c with colorscale
= float_of_string
v }
5207 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5209 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5211 let nab = columns_of_string v in
5212 { c with columns
= Some
(nab, [||]) }
5213 | "birds-eye-columns" ->
5214 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5215 | "selection-command" -> { c with selcmd
= unent v }
5218 prerr_endline
("Error processing attribute (`" ^
5219 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5222 let rec fold c = function
5225 let c = apply c k
v in
5231 let fromstring f pos
n v d =
5234 dolog "Error processing attribute (%S=%S) at %d\n%s"
5235 n v pos
(Printexc.to_string exn
)
5240 let bookmark_of attrs
=
5241 let rec fold title page
rely = function
5242 | ("title", v) :: rest
-> fold v page
rely rest
5243 | ("page", v) :: rest
-> fold title v rely rest
5244 | ("rely", v) :: rest
-> fold title page
v rest
5245 | _ :: rest
-> fold title page
rely rest
5246 | [] -> title, page
, rely
5248 fold "invalid" "0" "0" attrs
5252 let rec fold path page
rely pan
= function
5253 | ("path", v) :: rest
-> fold v page
rely pan rest
5254 | ("page", v) :: rest
-> fold path v rely pan rest
5255 | ("rely", v) :: rest
-> fold path page
v pan rest
5256 | ("pan", v) :: rest
-> fold path page
rely v rest
5257 | _ :: rest
-> fold path page
rely pan rest
5258 | [] -> path, page
, rely, pan
5260 fold "" "0" "0" "0" attrs
5263 let setconf dst
src =
5264 dst
.scrollbw
<- src.scrollbw
;
5265 dst
.scrollh
<- src.scrollh
;
5266 dst
.icase
<- src.icase
;
5267 dst
.preload <- src.preload;
5268 dst
.pagebias
<- src.pagebias
;
5269 dst
.verbose
<- src.verbose
;
5270 dst
.scrollstep
<- src.scrollstep
;
5271 dst
.maxhfit
<- src.maxhfit
;
5272 dst
.crophack
<- src.crophack
;
5273 dst
.autoscrollstep
<- src.autoscrollstep
;
5274 dst
.maxwait
<- src.maxwait
;
5275 dst
.hlinks
<- src.hlinks
;
5276 dst
.underinfo
<- src.underinfo
;
5277 dst
.interpagespace <- src.interpagespace;
5278 dst
.zoom <- src.zoom;
5279 dst
.presentation <- src.presentation;
5280 dst
.angle
<- src.angle
;
5281 dst
.winw <- src.winw;
5282 dst
.winh
<- src.winh
;
5283 dst
.savebmarks
<- src.savebmarks
;
5284 dst
.memlimit
<- src.memlimit
;
5285 dst
.proportional
<- src.proportional
;
5286 dst
.texcount
<- src.texcount
;
5287 dst
.sliceheight
<- src.sliceheight
;
5288 dst
.thumbw
<- src.thumbw
;
5289 dst
.jumpback
<- src.jumpback
;
5290 dst
.bgcolor
<- src.bgcolor
;
5291 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5292 dst
.tilew
<- src.tilew
;
5293 dst
.tileh
<- src.tileh
;
5294 dst
.mustoresize
<- src.mustoresize
;
5295 dst
.checkers
<- src.checkers
;
5296 dst
.aalevel
<- src.aalevel
;
5297 dst
.trimmargins
<- src.trimmargins
;
5298 dst
.trimfuzz
<- src.trimfuzz
;
5299 dst
.urilauncher
<- src.urilauncher
;
5300 dst
.colorspace
<- src.colorspace
;
5301 dst
.invert
<- src.invert
;
5302 dst
.colorscale
<- src.colorscale
;
5303 dst
.redirectstderr <- src.redirectstderr;
5304 dst
.ghyllscroll
<- src.ghyllscroll
;
5305 dst
.columns
<- src.columns
;
5306 dst
.beyecolumns
<- src.beyecolumns
;
5307 dst
.selcmd
<- src.selcmd
;
5311 let h = Hashtbl.create
10 in
5312 let dc = { defconf with angle
= defconf.angle
} in
5313 let rec toplevel v t spos
_ =
5315 | Vdata
| Vcdata
| Vend
-> v
5316 | Vopen
("llppconfig", _, closed
) ->
5319 else { v with f = llppconfig
}
5321 error
"unexpected subelement at top level" s spos
5322 | Vclose
_ -> error
"unexpected close at top level" s spos
5324 and llppconfig
v t spos
_ =
5326 | Vdata
| Vcdata
-> v
5327 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5328 | Vopen
("defaults", attrs
, closed
) ->
5329 let c = config_of dc attrs
in
5333 else { v with f = skip
"defaults" (fun () -> v) }
5335 | Vopen
("ui-font", attrs
, closed
) ->
5336 let rec getsize size
= function
5338 | ("size", v) :: rest
->
5340 fromstring int_of_string spos
"size" v fstate.fontsize
in
5342 | l -> getsize size l
5344 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5347 else { v with f = uifont
(Buffer.create
10) }
5349 | Vopen
("doc", attrs
, closed
) ->
5350 let pathent, spage
, srely
, span
= doc_of attrs
in
5351 let path = unent pathent
5352 and pageno = fromstring int_of_string spos
"page" spage
0
5353 and rely = fromstring float_of_string spos
"rely" srely
0.0
5354 and pan
= fromstring int_of_string spos
"pan" span
0 in
5355 let c = config_of dc attrs
in
5356 let anchor = (pageno, rely) in
5358 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5359 else { v with f = doc
path pan
anchor c [] }
5362 error
"unexpected subelement in llppconfig" s spos
5364 | Vclose
"llppconfig" -> { v with f = toplevel }
5365 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5367 and uifont
b v t spos
epos =
5370 Buffer.add_substring
b s spos
(epos - spos
);
5372 | Vopen
(_, _, _) ->
5373 error
"unexpected subelement in ui-font" s spos
5374 | Vclose
"ui-font" ->
5375 if String.length
!fontpath = 0
5376 then fontpath := Buffer.contents
b;
5377 { v with f = llppconfig
}
5378 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5379 | Vend
-> error
"unexpected end of input in ui-font" s spos
5381 and doc
path pan
anchor c bookmarks
v t spos
_ =
5383 | Vdata
| Vcdata
-> v
5384 | Vend
-> error
"unexpected end of input in doc" s spos
5385 | Vopen
("bookmarks", _, closed
) ->
5388 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5390 | Vopen
(_, _, _) ->
5391 error
"unexpected subelement in doc" s spos
5394 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5395 { v with f = llppconfig
}
5397 | Vclose
_ -> error
"unexpected close in doc" s spos
5399 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5401 | Vdata
| Vcdata
-> v
5402 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5403 | Vopen
("item", attrs
, closed
) ->
5404 let titleent, spage
, srely
= bookmark_of attrs
in
5405 let page = fromstring int_of_string spos
"page" spage
0
5406 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5407 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5409 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5412 { v with f = skip
"item" f }
5415 error
"unexpected subelement in bookmarks" s spos
5417 | Vclose
"bookmarks" ->
5418 { v with f = doc
path pan
anchor c bookmarks }
5420 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5422 and skip tag
f v t spos
_ =
5424 | Vdata
| Vcdata
-> v
5426 error
("unexpected end of input in skipped " ^ tag
) s spos
5427 | Vopen
(tag'
, _, closed
) ->
5431 let f'
() = { v with f = skip tag
f } in
5432 { v with f = skip tag'
f'
}
5436 else error
("unexpected close in skipped " ^ tag
) s spos
5439 parse
{ f = toplevel; accu = () } s;
5445 let len = in_channel_length ic
in
5446 let s = String.create
len in
5447 really_input ic
s 0 len;
5450 | Parse_error
(msg
, s, pos
) ->
5451 let subs = subs s pos
in
5452 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5453 failwith
("parse error: " ^
s)
5456 failwith
("config load error: " ^
Printexc.to_string exn
)
5462 let dir = Filename.concat
home ".config" in
5463 if Sys.is_directory
dir then dir else home
5466 Filename.concat
dir "llpp.conf"
5469 let confpath = ref defconfpath;;
5472 if Sys.file_exists
!confpath
5475 (try Some
(open_in_bin
!confpath)
5478 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5479 Printexc.to_string exn
);
5488 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5489 Printexc.to_string exn
);
5495 f (Hashtbl.create
0, defconf)
5500 let pc, pb
, px, pa
=
5502 Hashtbl.find h (Filename.basename
state.path)
5503 with Not_found
-> dc, [], 0, (0, 0.0)
5507 state.bookmarks <- pb
;
5509 state.scrollw
<- conf.scrollbw
;
5511 then state.anchor <- pa
;
5512 cbput state.hists
.nav pa
;
5517 let add_attrs bb always
dc c =
5520 then Printf.bprintf bb
"\n %s='%b'" s a
5523 then Printf.bprintf bb
"\n %s='%d'" s a
5526 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5529 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5532 then Printf.bprintf bb
"\n %s='%f'" s a
5536 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5540 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5544 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5548 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5554 | Some
(_N
, _A
, _B
) ->
5555 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5565 else string_of_float
f
5567 Printf.bprintf bb
"\n %s='%s'" s v
5572 | Some
((n, a, b), _) when n > 1 ->
5573 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5579 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5584 then dc.winw, dc.winh
5586 match state.fullscreen
with
5588 | None
-> c.winw, c.winh
5590 let zoom, presentation, interpagespace, maxwait
=
5592 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5594 match state.mode with
5595 | Birdseye
(bc
, _, _, _, _) ->
5596 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5597 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5599 oi
"width" w dc.winw;
5600 oi
"height" h dc.winh
;
5601 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5602 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5603 ob "case-insensitive-search" c.icase
dc.icase
;
5604 ob "preload" c.preload dc.preload;
5605 oi
"page-bias" c.pagebias
dc.pagebias
;
5606 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5607 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5608 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5609 ob "crop-hack" c.crophack
dc.crophack
;
5610 oW
"throttle" maxwait
dc.maxwait
;
5611 ob "highlight-links" c.hlinks
dc.hlinks
;
5612 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5613 oi
"vertical-margin" interpagespace dc.interpagespace;
5614 oz
"zoom" zoom dc.zoom;
5615 ob "presentation" presentation dc.presentation;
5616 oi
"rotation-angle" c.angle
dc.angle
;
5617 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5618 ob "proportional-display" c.proportional
dc.proportional
;
5619 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5620 oi
"tex-count" c.texcount
dc.texcount
;
5621 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5622 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5623 ob "persistent-location" c.jumpback
dc.jumpback
;
5624 oc
"background-color" c.bgcolor
dc.bgcolor
;
5625 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5626 oi
"tile-width" c.tilew
dc.tilew
;
5627 oi
"tile-height" c.tileh
dc.tileh
;
5628 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5629 ob "checkers" c.checkers
dc.checkers
;
5630 oi
"aalevel" c.aalevel
dc.aalevel
;
5631 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5632 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5633 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5634 oC
"color-space" c.colorspace
dc.colorspace
;
5635 ob "invert-colors" c.invert
dc.invert
;
5636 oF
"brightness" c.colorscale
dc.colorscale
;
5637 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5638 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5639 oco
"columns" c.columns
dc.columns
;
5640 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5641 os
"selection-command" c.selcmd
dc.selcmd
;
5645 let uifontsize = fstate.fontsize
in
5646 let bb = Buffer.create
32768 in
5648 let dc = if conf.bedefault
then conf else dc in
5649 Buffer.add_string
bb "<llppconfig>\n";
5651 if String.length
!fontpath > 0
5653 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5659 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5662 Buffer.add_string
bb "<defaults ";
5663 add_attrs bb true dc dc;
5664 Buffer.add_string
bb "/>\n";
5666 let adddoc path pan
anchor c bookmarks =
5667 if bookmarks == [] && c = dc && anchor = emptyanchor
5670 Printf.bprintf
bb "<doc path='%s'"
5671 (enent
path 0 (String.length
path));
5673 if anchor <> emptyanchor
5675 let n, y = anchor in
5676 Printf.bprintf
bb " page='%d'" n;
5679 Printf.bprintf
bb " rely='%f'" y
5684 then Printf.bprintf
bb " pan='%d'" pan
;
5686 add_attrs bb false dc c;
5688 begin match bookmarks with
5689 | [] -> Buffer.add_string
bb "/>\n"
5691 Buffer.add_string
bb ">\n<bookmarks>\n";
5692 List.iter
(fun (title, _level
, (page, rely)) ->
5694 "<item title='%s' page='%d'"
5695 (enent
title 0 (String.length
title))
5700 Printf.bprintf
bb " rely='%f'" rely
5702 Buffer.add_string
bb "/>\n";
5704 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5710 match state.mode with
5711 | Birdseye
(c, pan, _, _, _) ->
5713 match conf.columns
with
5714 | Some
((c, _, _), _) -> Some
c
5717 match c.columns
with
5718 | Some
(c, _) -> Some
(c, [||])
5721 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
5722 | _ -> state.x, conf
5724 let basename = Filename.basename state.path in
5725 adddoc basename pan (getanchor ())
5728 match state.autoscroll
with
5730 | None
-> conf.autoscrollstep
}
5731 (if conf.savebmarks
then state.bookmarks else []);
5733 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5735 then adddoc path x y c bookmarks
5737 Buffer.add_string
bb "</llppconfig>";
5740 if Buffer.length
bb > 0
5743 let tmp = !confpath ^
".tmp" in
5744 let oc = open_out_bin
tmp in
5745 Buffer.output_buffer
oc bb;
5747 Unix.rename
tmp !confpath;
5750 ("error while saving configuration: " ^
Printexc.to_string exn
)
5757 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5758 "<password> Set password");
5760 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5761 "<path> Set path to the user interface font");
5763 ("-c", Arg.String
(fun s -> Config.confpath := s),
5764 "<path> Set path to the configuration file");
5766 ("-v", Arg.Unit
(fun () ->
5768 "%s\nconfiguration path: %s\n"
5772 exit
0), " Print version and exit");
5775 (fun s -> state.path <- s)
5776 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5778 if String.length
state.path = 0
5779 then (prerr_endline
"file name missing"; exit
1);
5783 state.wsfd
<- Wsi.init
(object
5784 method display = display ()
5785 method reshape w h = reshape w h
5786 method mouse b d x y m = mouse b d x y m
5787 method motion x y = state.mpos
<- (x, y); motion x y
5788 method pmotion x y = state.mpos
<- (x, y); pmotion x y
5789 method key c m = keyboard c m
5790 method enter
x y = state.mpos
<- (x, y); pmotion x y
5791 method leave = state.mpos
<- (-1, -1)
5795 List.exists
GlMisc.check_extension
5796 [ "GL_ARB_texture_rectangle"
5797 ; "GL_EXT_texture_recangle"
5798 ; "GL_NV_texture_rectangle" ]
5800 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5802 let cr, sw = Unix.pipe
()
5803 and sr
, cw
= Unix.pipe
() in
5810 setcheckers conf.checkers
;
5814 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5815 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5820 state.text <- "Opening " ^
state.path;
5821 setaalevel
conf.aalevel
;
5822 writeopen state.path state.password
;
5824 setfontsize fstate.fontsize
;
5825 doreshape conf.winw conf.winh
;
5827 let rec loop deadline
=
5829 match state.errfd
with
5830 | None
-> [state.sr
; state.wsfd
]
5831 | Some fd
-> [state.sr
; state.wsfd
; fd
]
5835 state.redisplay
<- false;
5842 if deadline
= infinity
5844 else max
0.0 (deadline
-. now)
5849 try Unix.select
r [] [] timeout
5850 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5856 match state.autoscroll
with
5857 | Some step
when step
!= 0 ->
5858 let y = state.y + step
in
5862 else if y >= state.maxy then 0 else y
5865 if state.mode = View
5866 then state.text <- "";
5869 if state.ghyll
== noghyll then infinity
else deadline
+. 0.01
5874 let rec checkfds = function
5876 | fd
:: rest
when fd
= state.sr
->
5877 let cmd = readcmd state.sr
in
5881 | fd
:: rest
when fd
= state.wsfd
->
5886 let s = String.create
80 in
5887 let n = Unix.read fd
s 0 80 in
5888 if conf.redirectstderr
5890 Buffer.add_substring
state.errmsgs
s 0 n;
5891 state.newerrmsgs
<- true;
5892 state.redisplay
<- true;
5895 prerr_string
(String.sub
s 0 n);
5903 if deadline
= infinity
5907 match state.autoscroll
with
5908 | Some step
when step
!= 0 -> deadline1
5909 | _ -> if state.ghyll
== noghyll then infinity
else deadline1