6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: string -> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> int -> int -> int -> int -> int =
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
99 let platform_to_string = function
100 | Punknown
-> "unknown"
104 | Pfreebsd
-> "FreeBSD"
105 | Pdragonflybsd
-> "DragonflyBSD"
106 | Popenbsd
-> "OpenBSD"
107 | Pnetbsd
-> "NetBSD"
108 | Pcygwin
-> "Cygwin"
111 let platform = platform ();;
117 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
120 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
122 type mpos
= int * int
124 | Msel
of (mpos
* mpos
)
126 | Mscrolly
| Mscrollx
127 | Mzoom
of (int * int)
128 | Mzoomrect
of (mpos
* mpos
)
132 type textentry
= string * string * onhist
option * onkey
* ondone
133 and onkey
= string -> int -> te
134 and ondone
= string -> unit
135 and histcancel
= unit -> unit
136 and onhist
= ((histcmd
-> string) * histcancel
)
137 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
142 | TEswitch
of textentry
153 let bound v minv maxv
=
154 max minv
(min maxv v
);
158 { store
= Array.create n v
165 let drawstring size x y s
=
167 Gl.enable `texture_2d
;
168 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
169 ignore
(drawstr size x y s
);
171 Gl.disable `texture_2d
;
174 let drawstring1 size x y s
=
178 let drawstring2 size x y fmt
=
179 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
182 let cbcap b
= Array.length b
.store
;;
187 b
.wc
<- (b
.wc
+ 1) mod cap;
189 b
.len
<- min
(b
.len
+ 1) cap;
192 let cbempty b
= b
.len
= 0;;
194 let cbgetg b circular dir
=
198 let rc = b
.rc + dir
in
210 else max
0 (min
rc (b
.len
-1))
216 let cbget b
= cbgetg b
false;;
217 let cbgetc b
= cbgetg b
true;;
234 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
235 dolog " WxH %dx%d" l
.pagew l
.pageh
;
236 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
237 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
238 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
242 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
244 dolog " x0,y0=(% f, % f)" x0 y0
;
245 dolog " x1,y1=(% f, % f)" x1 y1
;
246 dolog " x2,y2=(% f, % f)" x2 y2
;
247 dolog " x3,y3=(% f, % f)" x3 y3
;
251 type multicolumns
= multicol
* pagegeom
252 and splitcolumns
= columncount
* pagegeom
253 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
254 and multicol
= columncount
* covercount
* covercount
256 and columncount
= int
257 and covercount
= int;;
260 { mutable scrollbw
: int
261 ; mutable scrollh
: int
262 ; mutable icase
: bool
263 ; mutable preload
: bool
264 ; mutable pagebias
: int
265 ; mutable verbose
: bool
266 ; mutable debug
: bool
267 ; mutable scrollstep
: int
268 ; mutable maxhfit
: bool
269 ; mutable crophack
: bool
270 ; mutable autoscrollstep
: int
271 ; mutable maxwait
: float option
272 ; mutable hlinks
: bool
273 ; mutable underinfo
: bool
274 ; mutable interpagespace
: interpagespace
275 ; mutable zoom
: float
276 ; mutable presentation
: bool
277 ; mutable angle
: angle
280 ; mutable savebmarks
: bool
281 ; mutable proportional
: proportional
282 ; mutable trimmargins
: trimmargins
283 ; mutable trimfuzz
: irect
284 ; mutable memlimit
: memsize
285 ; mutable texcount
: texcount
286 ; mutable sliceheight
: sliceheight
287 ; mutable thumbw
: width
288 ; mutable jumpback
: bool
289 ; mutable bgcolor
: float * float * float
290 ; mutable bedefault
: bool
291 ; mutable scrollbarinpm
: bool
292 ; mutable tilew
: int
293 ; mutable tileh
: int
294 ; mutable mustoresize
: memsize
295 ; mutable checkers
: bool
296 ; mutable aalevel
: int
297 ; mutable urilauncher
: string
298 ; mutable pathlauncher
: string
299 ; mutable colorspace
: colorspace
300 ; mutable invert
: bool
301 ; mutable colorscale
: float
302 ; mutable redirectstderr
: bool
303 ; mutable ghyllscroll
: (int * int * int) option
304 ; mutable columns
: columns
305 ; mutable beyecolumns
: columncount
option
306 ; mutable selcmd
: string
307 ; mutable updatecurs
: bool
308 ; mutable keyhashes
: (string * keyhash
) list
312 | Cmulti
of multicolumns
313 | Csplit
of splitcolumns
316 type anchor
= pageno
* top
;;
318 type outline
= string * int * anchor
;;
320 type rect
= float * float * float * float * float * float * float * float;;
322 type tile
= opaque
* pixmapsize
* elapsed
323 and elapsed
= float;;
324 type pagemapkey
= pageno
* gen
;;
325 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
329 let emptyanchor = (0, 0.0);;
331 type infochange
= | Memused
| Docinfo
| Pdim
;;
333 class type uioh
= object
334 method display
: unit
335 method key
: int -> int -> uioh
336 method button
: int -> bool -> int -> int -> int -> uioh
337 method motion
: int -> int -> uioh
338 method pmotion
: int -> int -> uioh
339 method infochanged
: infochange
-> unit
340 method scrollpw
: (int * float * float)
341 method scrollph
: (int * float * float)
342 method modehash
: keyhash
346 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
347 | Textentry
of (textentry
* onleave
)
349 | LinkNav
of linktarget
350 and onleave
= leavetextentrystatus
-> unit
351 and leavetextentrystatus
= | Cancel
| Confirm
352 and helpitem
= string * int * action
355 | Action
of (uioh
-> uioh
)
357 | Ltexact
of (pageno
* int)
361 let isbirdseye = function Birdseye _
-> true | _
-> false;;
362 let istextentry = function Textentry _
-> true | _
-> false;;
366 | Loading
of (page
* gen
)
368 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
370 | Outlining
of outline list
373 let emptykeyhash = Hashtbl.create
0;;
374 let nouioh : uioh
= object (self
)
376 method key _ _
= self
377 method button _ _ _ _ _
= self
378 method motion _ _
= self
379 method pmotion _ _
= self
380 method infochanged _
= ()
381 method scrollpw
= (0, nan
, nan
)
382 method scrollph
= (0, nan
, nan
)
383 method modehash
= emptykeyhash
387 { mutable sr
: Unix.file_descr
388 ; mutable sw
: Unix.file_descr
389 ; mutable wsfd
: Unix.file_descr
390 ; mutable errfd
: Unix.file_descr
option
391 ; mutable stderr
: Unix.file_descr
392 ; mutable errmsgs
: Buffer.t
393 ; mutable newerrmsgs
: bool
397 ; mutable scrollw
: int
398 ; mutable hscrollh
: int
399 ; mutable anchor
: anchor
400 ; mutable ranchors
: (string * string * anchor
) list
402 ; mutable layout
: page list
403 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
404 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
405 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
406 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
407 ; mutable pagecount
: int
408 ; mutable currently
: currently
409 ; mutable mstate
: mstate
410 ; mutable searchpattern
: string
411 ; mutable rects
: (pageno
* recttype
* rect
) list
412 ; mutable rects1
: (pageno
* recttype
* rect
) list
413 ; mutable text
: string
414 ; mutable fullscreen
: (width
* height
) option
415 ; mutable mode
: mode
416 ; mutable uioh
: uioh
417 ; mutable outlines
: outline array
418 ; mutable bookmarks
: outline list
419 ; mutable path
: string
420 ; mutable password
: string
421 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
422 ; mutable memused
: memsize
424 ; mutable throttle
: (page list
* int * float) option
425 ; mutable autoscroll
: int option
426 ; mutable ghyll
: (int option -> unit)
427 ; mutable help
: helpitem array
428 ; mutable docinfo
: (int * string) list
429 ; mutable texid
: GlTex.texture_id
option
431 ; mutable prevzoom
: float
432 ; mutable progress
: float
433 ; mutable redisplay
: bool
434 ; mutable mpos
: mpos
435 ; mutable keystate
: keystate
436 ; mutable glinks
: bool
439 { pat
: string circbuf
440 ; pag
: string circbuf
441 ; nav
: anchor circbuf
442 ; sel
: string circbuf
463 ; presentation
= false
468 ; proportional
= true
469 ; trimmargins
= false
470 ; trimfuzz
= (0,0,0,0)
471 ; memlimit
= 32 lsl 20
476 ; bgcolor
= (0.5, 0.5, 0.5)
478 ; scrollbarinpm
= true
481 ; mustoresize
= 128 lsl 20
486 | Plinux
| Pfreebsd
| Pdragonflybsd
487 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
488 | Posx
-> "open \"%s\""
489 | Pcygwin
-> "cygstart %s"
490 | Punknown
-> "echo %s")
491 ; pathlauncher
= "lp \"%s\""
494 | Plinux
| Pfreebsd
| Pdragonflybsd
495 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
502 ; redirectstderr
= false
508 let mk n
= (n
, Hashtbl.create
1) in
521 let findkeyhash c name
=
522 try List.assoc name c
.keyhashes
523 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
526 let conf = { defconf with angle
= defconf.angle
};;
529 { mutable fontsize
: int
530 ; mutable wwidth
: float
531 ; mutable maxrows
: int
543 fstate.fontsize
<- n
;
544 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
545 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
549 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
550 let len = String.length s
in
551 if colonpos >= 0 && colonpos + 3 < len
553 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
556 try String.rindex_from s
colonpos ' '
560 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
563 | "http" | "ftp" | "mailto" ->
565 try String.index_from s
colonpos ' '
566 with Not_found
-> len
568 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
576 let shell, farg
= "/bin/sh", "-c" in
578 let args = [|shell; farg
; s
|] in
579 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
583 if String.length
conf.urilauncher
= 0
584 then print_endline uri
586 let url = geturl uri
in
587 if String.length
url = 0
588 then print_endline uri
590 let re = Str.regexp
"%s" in
591 let command = Str.global_replace
re url conf.urilauncher
in
595 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
601 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
602 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
606 let strings = version () :: "" :: Help.keys
in
609 let url = geturl s
in
610 if String.length
url > 0
611 then (s
, 0, Action
(fun u
-> gotouri url; u
))
612 else (s
, 0, Noaction
)
617 let firstgeomcmds = "", [];;
624 ; stderr
= Unix.stderr
625 ; errmsgs
= Buffer.create
0
632 ; anchor
= emptyanchor
636 ; tilelru
= Queue.create
()
637 ; pagemap
= Hashtbl.create
10
638 ; tilemap
= Hashtbl.create
10
653 ; geomcmds
= firstgeomcmds
655 { nav
= cbnew 10 (0, 0.0)
681 Printf.kprintf prerr_endline fmt
683 Printf.kprintf ignore fmt
687 if String.length
conf.pathlauncher
= 0
688 then print_endline
state.path
690 let re = Str.regexp
"%s" in
691 let command = Str.global_replace
re state.path
conf.pathlauncher
in
695 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
700 let redirectstderr () =
701 if conf.redirectstderr
703 let rfd, wfd
= Unix.pipe
() in
704 state.stderr
<- Unix.dup
Unix.stderr
;
705 state.errfd
<- Some
rfd;
706 Unix.dup2 wfd
Unix.stderr
;
708 state.newerrmsgs
<- false;
709 begin match state.errfd
with
712 Unix.dup2
state.stderr
Unix.stderr
;
716 prerr_string
(Buffer.contents
state.errmsgs
);
718 Buffer.clear
state.errmsgs
;
724 let postRedisplay who
=
726 then prerr_endline
("redisplay for " ^ who
);
727 state.redisplay
<- true;
731 let getopaque pageno
=
732 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
733 with Not_found
-> None
736 let putopaque pageno opaque
=
737 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
740 let pagetranslatepoint l x y
=
741 let dy = y
- l
.pagedispy
in
742 let y = dy + l
.pagey
in
743 let dx = x
- l
.pagedispx
in
744 let x = dx + l
.pagex
in
751 begin match getopaque l
.pageno
with
753 let x0 = l
.pagedispx
in
754 let x1 = x0 + l
.pagevw
in
755 let y0 = l
.pagedispy
in
756 let y1 = y0 + l
.pagevh
in
757 if y >= y0 && y <= y1 && x >= x0 && x <= x1
759 let px, py
= pagetranslatepoint l
x y in
760 match whatsunder opaque
px py
with
773 state.text
<- Printf.sprintf
"%c%s" c s
;
774 G.postRedisplay "showtext";
777 let updateunder x y =
778 match getunder x y with
779 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
781 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
782 Wsi.setcursor
Wsi.CURSOR_INFO
783 | Ulinkgoto
(page
, _
) ->
785 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
786 Wsi.setcursor
Wsi.CURSOR_INFO
788 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
789 Wsi.setcursor
Wsi.CURSOR_TEXT
791 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
792 Wsi.setcursor
Wsi.CURSOR_INHERIT
794 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
795 Wsi.setcursor
Wsi.CURSOR_INHERIT
797 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
798 Wsi.setcursor
Wsi.CURSOR_INHERIT
799 | Uremote
(filename
, pageno
) ->
800 if conf.underinfo
then showtext 'r'
801 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
802 Wsi.setcursor
Wsi.CURSOR_INFO
805 let showlinktype under
=
811 showtext 'u'
("ri: " ^ uri
)
812 | Ulinkgoto
(page
, _
) ->
813 showtext 'p'
("age: " ^ string_of_int
(page
+1));
815 showtext '
f'
("ont: " ^ s
);
817 showtext 'u'
("nexpected: " ^ s
);
819 showtext 'l'
("aunch: " ^ s
);
821 showtext 'n'
("amed: " ^ s
);
822 | Uremote
(filename
, pageno
) ->
823 showtext 'r'
(Printf.sprintf
"emote: %s (%d)" filename pageno
);
827 let b = Buffer.create
(String.length s
+ 1) in
828 Buffer.add_string
b s
;
833 let colorspace_of_string s
=
834 match String.lowercase s
with
838 | _
-> failwith
"invalid colorspace"
841 let int_of_colorspace = function
847 let colorspace_of_int = function
851 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
854 let colorspace_to_string = function
860 let intentry_with_suffix text key
=
862 if key
>= 32 && key
< 127
866 match Char.lowercase
c with
868 let text = addchar text c in
872 let text = addchar text c in
876 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
880 let multicolumns_to_string (n
, a
, b) =
882 then Printf.sprintf
"%d" n
883 else Printf.sprintf
"%d,%d,%d" n a
b;
886 let multicolumns_of_string s
=
888 (int_of_string s
, 0, 0)
890 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
895 let n = Unix.read fd
s 0 4 in
896 if n != 4 then failwith
"incomplete read(len)";
898 lor (Char.code
s.[0] lsl 24)
899 lor (Char.code
s.[1] lsl 16)
900 lor (Char.code
s.[2] lsl 8)
901 lor (Char.code
s.[3] lsl 0)
903 let s = String.create
len in
904 let n = Unix.read fd
s 0 len in
905 if n != len then failwith
"incomplete read(data)";
909 let btod b = if b then 1 else 0;;
912 let b = Buffer.create
16 in
913 Buffer.add_string
b "llll";
916 let s = Buffer.contents
b in
917 let n = String.length
s in
919 (* dolog "wcmd %S" (String.sub s 4 len); *)
920 s.[0] <- Char.chr
((len lsr 24) land 0xff);
921 s.[1] <- Char.chr
((len lsr 16) land 0xff);
922 s.[2] <- Char.chr
((len lsr 8) land 0xff);
923 s.[3] <- Char.chr
(len land 0xff);
924 let n'
= Unix.write
state.sw
s 0 n in
925 if n'
!= n then failwith
"write failed";
932 let d = conf.winh
- h
in
939 let rec f pn ph pi fh l
=
941 | (n, _
, h
, _
) :: rest
->
942 let ips = calcips h
in
947 if isbirdseye state.mode
&& pn
= 0
952 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
957 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
961 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
964 let fh = f 0 0 0 0 state.pdims
in
969 match conf.columns
with
970 | Csingle
-> calcheight ()
972 if Array.length
b > 0
974 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
978 if Array.length
b > 0
980 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
985 let getpageyh pageno
=
986 let rec f pn ph pi
y l
=
988 | (n, _
, h
, _
) :: rest
->
989 let ips = calcips h
in
992 let h = if n = pageno
then h else ph
in
993 if conf.presentation
&& n = pageno
995 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
997 y + (pageno
- pn
) * (ph
+ pi
), h
999 let y = y + (if conf.presentation
then pi
else 0) in
1000 let y = y + (n - pn
) * (ph
+ pi
) in
1004 y + (pageno
- pn
) * (ph
+ pi
), ph
1006 f 0 0 0 0 state.pdims
1009 let getpageyh pageno
=
1010 match conf.columns
with
1011 | Csingle
-> getpageyh pageno
1013 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1015 | Csplit _
-> getpageyh pageno
1018 let getpagedim pageno
=
1021 | (n, _
, _
, _
) as pdim
:: rest
->
1023 then (if n = pageno
then pdim
else ppdim
)
1028 f (-1, -1, -1, -1) state.pdims
1031 let getpagey pageno
= fst
(getpageyh pageno
);;
1033 let nogeomcmds cmds
=
1035 | s, [] -> String.length
s = 0
1040 let sh = sh - state.hscrollh
in
1041 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1042 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1044 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1045 let ips = calcips h in
1047 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1051 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1053 prev
, pdims
, pdimno
, 0
1055 let dy = dy + yinc in
1056 let py = py + yinc in
1057 if pageno
= state.pagecount
|| dy >= sh
1062 if py + h <= vy - yinc
1064 let py = py + h + ips in
1065 let dy = max
0 (py - y) in
1066 f ~pageno
:(pageno
+1)
1074 let pagey = vy - py in
1075 let pagevh = h - pagey in
1076 let pagevh = min
(sh - dy) pagevh in
1077 let off = if yinc > 0 then py - vy else 0 in
1078 let py = py + h + ips in
1081 if state.w
< conf.winw
- state.scrollw
1082 then (conf.winw
- state.scrollw
- state.w
) / 2
1085 let dispx = xoff + state.x in
1091 let lw = w
- pagex in
1092 min
lw (conf.winw
- state.scrollw
)
1096 ; pagedimno
= pdimno
1100 ; pagey = pagey + off
1102 ; pagevh = pagevh - off
1104 ; pagedispy
= dy + off
1107 let accu = e :: accu in
1108 f ~pageno
:(pageno
+1)
1129 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1130 let sh = sh - state.hscrollh
in
1131 let rec fold accu n =
1132 if n = Array.length
b
1135 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1138 || n = state.pagecount
- coverB
1139 || (n - coverA
) mod columns
= columns
- 1)
1145 let pagey = max
0 (y - vy) in
1146 let pagedispy = if pagey > 0 then 0 else vy - y in
1147 let pagedispx, pagex =
1149 if n = coverA
- 1 || n = state.pagecount
- coverB
1150 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1151 else dx + xoff + state.x
1158 let vw = conf.winw
- state.scrollw
- pagedispx in
1159 let pw = w
- pagex in
1162 let pagevh = min
(h - pagey) (sh - pagedispy) in
1163 if pagevw > 0 && pagevh > 0
1167 ; pagedimno
= pdimno
1174 ; pagedispx = pagedispx
1175 ; pagedispy = pagedispy
1186 List.rev
(fold [] 0)
1189 let layoutS (columns
, b) y sh =
1190 let sh = sh - state.hscrollh
in
1191 let rec fold accu n =
1192 if n = Array.length
b
1195 let pdimno, px, vy, (_
, pw, h, xoff) = b.(n) in
1202 let x = xoff + state.x in
1203 let pagey = max
0 (y - vy) in
1204 let pagedispy = if pagey > 0 then 0 else vy - y in
1205 let pagedispx, pagex =
1210 let w = pw/columns
in
1211 let pagevw = min
(w - (pagex mod w)) (conf.winw
- state.scrollw
) in
1212 let pagevh = min
(h - pagey) (sh - pagedispy) in
1213 if pagevw > 0 && pagevh > 0
1216 { pageno
= n/columns
1217 ; pagedimno
= pdimno
1224 ; pagedispx = pagedispx
1225 ; pagedispy = pagedispy
1236 List.rev
(fold [] 0)
1240 if nogeomcmds state.geomcmds
1242 match conf.columns
with
1243 | Csingle
-> layout1 y sh
1244 | Cmulti
c -> layoutN c y sh
1245 | Csplit
s -> layoutS s y sh
1250 let y = state.y + incr
in
1252 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1257 let tilex = l
.pagex mod conf.tilew
in
1258 let tiley = l
.pagey mod conf.tileh
in
1260 let col = l
.pagex / conf.tilew
in
1261 let row = l
.pagey / conf.tileh
in
1264 let a = l
.pagew
- l
.pagex in
1265 let b = conf.winw
- state.scrollw
in
1267 and vh
= l
.pagevh in
1269 let rec rowloop row y0 dispy
h =
1273 let dh = conf.tileh
- y0 in
1274 let dh = min
h dh in
1275 let rec colloop col x0 dispx w =
1279 let dw = conf.tilew
- x0 in
1280 let dw = min
w dw in
1282 f col row dispx dispy
x0 y0 dw dh;
1283 colloop (col+1) 0 (dispx+dw) (w-dw)
1286 colloop col tilex l
.pagedispx vw;
1287 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1291 then rowloop row tiley l
.pagedispy vh
;
1294 let gettileopaque l
col row =
1296 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1298 try Some
(Hashtbl.find
state.tilemap
key)
1299 with Not_found
-> None
1302 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1303 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1304 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1307 let drawtiles l color
=
1309 let f col row x y tilex tiley w h =
1310 match gettileopaque l
col row with
1311 | Some
(opaque
, _
, t
) ->
1312 let params = x, y, w, h, tilex, tiley in
1316 GlFunc.blend_func `zero `one_minus_src_color
;
1318 drawtile
params opaque
;
1320 then Gl.disable `blend
;
1323 let s = Printf.sprintf
1327 let w = measurestr
fstate.fontsize
s in
1328 GlMisc.push_attrib
[`current
];
1329 GlDraw.color
(0.0, 0.0, 0.0);
1331 (float (x-2), float (y-2))
1332 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1333 GlDraw.color
(1.0, 1.0, 1.0);
1334 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1335 GlMisc.pop_attrib
();
1340 let lw = conf.winw
- state.scrollw
- x in
1343 let lh = conf.winh
- y in
1346 Gl.enable `texture_2d
;
1347 begin match state.texid
with
1349 GlTex.bind_texture `texture_2d id
;
1352 and x1 = float (x+w)
1353 and y1 = float (y+h) in
1355 let tw = float w /. 64.0
1356 and th
= float h /. 64.0 in
1357 let tx0 = float tilex /. 64.0
1358 and ty0
= float tiley /. 64.0 in
1360 and ty1
= ty0
+. th
in
1361 GlDraw.begins `quads
;
1362 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1363 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1364 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1365 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1368 Gl.disable `texture_2d
;
1370 GlDraw.color
(1.0, 1.0, 1.0);
1373 (float (x+w), float (y+h));
1375 if w > 128 && h > fstate.fontsize
+ 10
1377 GlDraw.color
(0.0, 0.0, 0.0);
1380 then (col*conf.tilew
, row*conf.tileh
)
1383 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1390 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1392 let tilevisible1 l
x y =
1394 and ax1
= l
.pagex + l
.pagevw
1396 and ay1
= l
.pagey + l
.pagevh in
1400 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1401 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1403 let rx0 = max
ax0 bx0
1404 and ry0
= max ay0 by0
1405 and rx1
= min ax1
bx1
1406 and ry1
= min ay1 by1
in
1408 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1409 nonemptyintersection
1412 let tilevisible layout n x y =
1413 let rec findpageinlayout = function
1414 | l
:: _
when l
.pageno
= n -> tilevisible1 l
x y
1415 | _
:: rest
-> findpageinlayout rest
1418 findpageinlayout layout
1421 let tileready l
x y =
1422 tilevisible1 l
x y &&
1423 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1426 let tilepage n p
layout =
1427 let rec loop = function
1431 let f col row _ _ _ _ _ _
=
1432 if state.currently
= Idle
1434 match gettileopaque l
col row with
1437 let x = col*conf.tilew
1438 and y = row*conf.tileh
in
1440 let w = l
.pagew
- x in
1444 let h = l
.pageh
- y in
1447 wcmd "tile %s %d %d %d %d" p
x y w h;
1450 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1451 conf.tilew
, conf.tileh
1460 if nogeomcmds state.geomcmds
1464 let preloadlayout visiblepages
=
1465 let presentation = conf.presentation in
1466 let interpagespace = conf.interpagespace in
1467 let maxy = state.maxy in
1468 conf.presentation <- false;
1469 conf.interpagespace <- 0;
1470 state.maxy <- calcheight ();
1472 match visiblepages
with
1474 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1476 let y = if y < conf.winh
then 0 else y - conf.winh
in
1477 let h = state.y - y + conf.winh
*3 in
1478 let pages = layout y h in
1479 conf.presentation <- presentation;
1480 conf.interpagespace <- interpagespace;
1486 let rec loop pages =
1487 if state.currently
!= Idle
1492 begin match getopaque l
.pageno
with
1494 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1495 state.currently
<- Loading
(l
, state.gen
);
1497 tilepage l
.pageno opaque
pages;
1502 if nogeomcmds state.geomcmds
1508 if conf.preload && state.currently
= Idle
1509 then load (preloadlayout pages);
1512 let layoutready layout =
1513 let rec fold all ls
=
1514 all
&& match ls
with
1516 let seen = ref false in
1517 let allvisible = ref true in
1518 let foo col row _ _ _ _ _ _
=
1520 allvisible := !allvisible &&
1521 begin match gettileopaque l
col row with
1527 fold (!seen && !allvisible) rest
1530 let alltilesvisible = fold true layout in
1535 let y = bound y 0 state.maxy in
1536 let y, layout, proceed
=
1537 match conf.maxwait
with
1538 | Some time
when state.ghyll
== noghyll ->
1539 begin match state.throttle
with
1541 let layout = layout y conf.winh
in
1542 let ready = layoutready layout in
1546 state.throttle
<- Some
(layout, y, now ());
1548 else G.postRedisplay "gotoy showall (None)";
1550 | Some
(_
, _
, started
) ->
1551 let dt = now () -. started
in
1554 state.throttle
<- None
;
1555 let layout = layout y conf.winh
in
1557 G.postRedisplay "maxwait";
1564 let layout = layout y conf.winh
in
1565 if true || layoutready layout
1566 then G.postRedisplay "gotoy ready";
1572 state.layout <- layout;
1573 begin match state.mode
with
1574 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1575 let rec loop = function
1577 state.mode
<- LinkNav
(Ltgendir
0)
1578 | l
:: _
when l
.pageno
= pageno
->
1579 begin match getopaque pageno
with
1581 state.mode
<- LinkNav
(Ltgendir
0)
1583 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1584 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1585 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1586 then state.mode
<- LinkNav
(Ltgendir
0)
1588 | _
:: rest
-> loop rest
1593 begin match state.mode
with
1594 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1595 if not
(pagevisible layout pageno
)
1597 match state.layout with
1600 state.mode
<- Birdseye
(
1601 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1604 | LinkNav
(Ltgendir dir
as lt
) ->
1606 let rec loop = function
1609 match getopaque l
.pageno
with
1615 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1617 if dir
> 0 then LDfirst
else LDlast
1623 | Lnotfound
-> loop rest
1625 showlinktype (getlink opaque
n);
1626 Ltexact
(l
.pageno
, n)
1630 state.mode
<- LinkNav
linknav
1635 state.ghyll
<- noghyll;
1638 let mx, my
= state.mpos
in
1643 let conttiling pageno opaque
=
1644 tilepage pageno opaque
1645 (if conf.preload then preloadlayout state.layout else state.layout)
1648 let gotoy_and_clear_text y =
1649 if not
conf.verbose
then state.text <- "";
1654 match state.layout with
1656 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1659 let getanchory (n, top
) =
1660 let y, h = getpageyh n in
1661 y + (truncate
(top
*. float h));
1664 let gotoanchor anchor
=
1665 gotoy (getanchory anchor
);
1669 cbput state.hists
.nav
(getanchor ());
1673 let anchor = cbgetc state.hists
.nav dir
in
1678 let rec scroll f n a b =
1679 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1681 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1683 then s (float f /. float a)
1686 then 1.0 -. s ((float (f-b) /. float (n-b)))
1693 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1694 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1696 let ins = float a *. iv1
1697 and outs
= float (n-b) *. iv1 in
1699 ins +. outs
+. float ones
1701 let rec set (_N
, _A
, _B
) y sy
=
1702 let sum = summa
1.0 _N _A _B
in
1703 let dy = float (y - sy
) in
1707 then state.ghyll
<- noghyll
1710 let s = scroll n _N _A _B
in
1711 let y1 = y1 +. ((s *. dy) /. sum) in
1712 gotoy_and_clear_text (truncate
y1);
1713 state.ghyll
<- gf (n+1) y1;
1717 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1719 gf 0 (float state.y)
1722 match conf.ghyllscroll
with
1724 gotoy_and_clear_text y
1726 if state.ghyll
== noghyll
1727 then set nab
y state.y
1728 else state.ghyll
(Some
y)
1731 let gotopage n top
=
1732 let y, h = getpageyh n in
1733 let y = y + (truncate
(top
*. float h)) in
1737 let gotopage1 n top
=
1738 let y = getpagey n in
1743 let invalidate s f =
1748 match state.geomcmds
with
1749 | ps
, [] when String.length ps
= 0 ->
1751 state.geomcmds
<- s, [];
1754 state.geomcmds
<- ps
, [s, f];
1756 | ps
, (s'
, _
) :: rest
when s'
= s ->
1757 state.geomcmds
<- ps
, ((s, f) :: rest
);
1760 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1763 let opendoc path password
=
1765 state.password
<- password
;
1766 state.gen
<- state.gen
+ 1;
1767 state.docinfo
<- [];
1769 setaalevel
conf.aalevel
;
1770 Wsi.settitle
("llpp " ^
Filename.basename path
);
1771 wcmd "open %s\000%s\000" path password
;
1772 invalidate "reqlayout"
1774 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1778 let c = c *. conf.colorscale
in
1782 let scalecolor2 (r
, g
, b) =
1783 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1787 let docolumns = function
1790 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1791 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1792 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1793 if pageno
= state.pagecount
1796 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1798 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1799 pdimno+1, pdim
, rest
1804 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1806 (conf.winw
- state.scrollw
- w) / 2,
1807 y + rowh
+ conf.interpagespace, h
1810 if (pageno
- coverA
) mod columns
= 0
1811 then 0, y + rowh
+ conf.interpagespace, h
1812 else x, y, max rowh
h
1815 let rec fixrow m
= if m
= pageno
then () else
1816 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1819 let y = y + (rowh
- h) / 2 in
1820 a.(m
) <- (pdimno, x, y, pdim
);
1824 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1825 then fixrow (pageno
- columns
);
1826 a.(pageno
) <- (pdimno, x, y, pdim
);
1827 let x = x + w + xoff*2 + conf.interpagespace in
1828 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1830 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1831 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1834 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1835 let rec loop pageno
pdimno pdim
y pdims
=
1836 if pageno
= state.pagecount
1839 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1841 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1842 pdimno+1, pdim
, rest
1847 let rec loop1 n x y =
1848 if n = c then y else (
1849 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1850 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1853 let y = loop1 0 0 y in
1854 loop (pageno
+1) pdimno pdim
y pdims
1856 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1857 conf.columns
<- Csplit
(c, a);
1859 docolumns conf.columns
;
1860 state.maxy <- calcheight ();
1862 if state.w <= conf.winw
- state.scrollw
1866 match state.mode
with
1867 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1868 let y, h = getpageyh pageno
in
1869 let top = (conf.winh
- h) / 2 in
1870 gotoy (max
0 (y - top))
1871 | _
-> gotoanchor state.anchor
1875 GlDraw.viewport
0 0 w h;
1876 if state.geomcmds
!= firstgeomcmds && nogeomcmds state.geomcmds
1877 then state.anchor <- getanchor ();
1880 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1883 setfontsize fstate.fontsize
;
1884 GlMat.mode `modelview
;
1885 GlMat.load_identity
();
1887 GlMat.mode `projection
;
1888 GlMat.load_identity
();
1889 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1890 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1891 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1896 else float state.x /. float state.w
1898 invalidate "geometry"
1901 state.x <- truncate
(relx *. float w);
1903 match conf.columns
with
1905 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1906 | Csplit
(c, _
) -> w * c
1908 wcmd "geometry %d %d" w h);
1912 let len = String.length
state.text in
1915 match state.mode
with
1917 | View
-> state.hscrollh
1922 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1923 (x+.w, float (conf.winh
- hscrollh))
1926 let w = float (conf.winw
- state.scrollw
- 1) in
1927 if state.progress
>= 0.0 && state.progress
< 1.0
1929 GlDraw.color
(0.3, 0.3, 0.3);
1930 let w1 = w *. state.progress
in
1932 GlDraw.color
(0.0, 0.0, 0.0);
1936 GlDraw.color
(0.0, 0.0, 0.0);
1940 GlDraw.color
(1.0, 1.0, 1.0);
1941 drawstring fstate.fontsize
1942 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1945 match state.mode
with
1946 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1950 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1952 Printf.sprintf
"%s%s_" prefix
text
1961 if not
(istextentry state.mode
)
1963 let s1 = "(press 'e' to review error messasges)" in
1964 if String.length
s > 0 then s ^
" " ^
s1 else s1
1969 if String.length
s > 0
1974 let len = Queue.length
state.tilelru
in
1976 if state.memused
<= conf.memlimit
1981 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1982 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1983 let (_
, pw, ph
, _
) = getpagedim n in
1986 && colorspace
= conf.colorspace
1987 && angle
= conf.angle
1992 match state.throttle
with
1995 then preloadlayout state.layout
1997 | Some
(layout, _
, _
) ->
2000 let x = col*conf.tilew
2001 and y = row*conf.tileh
in
2002 tilevisible layout n x y
2004 then Queue.push lruitem
state.tilelru
2006 wcmd "freetile %s" p
;
2007 state.memused
<- state.memused
- s;
2008 state.uioh#infochanged Memused
;
2009 Hashtbl.remove
state.tilemap k
;
2018 Queue.iter
(fun (k
, p
, s) ->
2019 wcmd "freetile %s" p
;
2020 state.memused
<- state.memused
- s;
2021 state.uioh#infochanged Memused
;
2022 Hashtbl.remove
state.tilemap k
;
2024 Queue.clear
state.tilelru
;
2028 let logcurrently = function
2029 | Idle
-> dolog "Idle"
2030 | Loading
(l
, gen
) ->
2031 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2032 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2034 "Tiling %d[%d,%d] page=%s cs=%s angle"
2035 l
.pageno
col row pageopaque
2036 (colorspace_to_string colorspace
)
2038 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2039 angle gen
conf.angle
state.gen
2041 conf.tilew
conf.tileh
2048 (* dolog "%S" cmds; *)
2051 try String.index cmds ' '
2052 with Not_found
-> -1
2057 let l = String.length cmds
in
2058 let op = String.sub cmds
0 spacepos in
2060 if l - spacepos < 2 then ""
2061 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2066 state.uioh#infochanged Pdim
;
2070 state.rects
<- state.rects1
;
2071 G.postRedisplay "clearrects";
2075 try Scanf.sscanf
args "%u" (fun n -> n)
2077 dolog "error processing 'continue' %S: %s"
2078 cmds
(Printexc.to_string exn
);
2081 state.pagecount
<- n;
2082 begin match state.currently
with
2084 state.currently
<- Idle
;
2085 state.outlines
<- Array.of_list
(List.rev
l)
2089 let cur, cmds
= state.geomcmds
in
2090 if String.length
cur = 0
2091 then failwith
"umpossible";
2093 begin match List.rev cmds
with
2095 state.geomcmds
<- "", [];
2099 state.geomcmds
<- s, List.rev rest
;
2101 if conf.maxwait
= None
2102 then G.postRedisplay "continue";
2112 then showtext ' '
args
2115 let progress, text =
2117 Scanf.sscanf
args "%f %n"
2119 f, String.sub
args pos
(String.length
args - pos
))
2121 dolog "error processing 'progress' %S: %s"
2122 cmds
(Printexc.to_string exn
);
2126 state.progress <- progress;
2127 G.postRedisplay "progress"
2130 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2132 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2133 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2134 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2136 dolog "error processing 'firstmatch' %S: %s"
2137 cmds
(Printexc.to_string exn
);
2140 let y = (getpagey pageno) + truncate
y0 in
2143 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2146 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2148 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2149 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2150 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2152 dolog "error processing 'match' %S: %s"
2153 cmds
(Printexc.to_string exn
);
2157 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2162 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2164 dolog "error processing 'page' %S: %s"
2165 cmds
(Printexc.to_string exn
);
2168 begin match state.currently
with
2169 | Loading
(l, gen
) ->
2170 vlog "page %d took %f sec" l.pageno t
;
2171 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2172 begin match state.throttle
with
2174 let preloadedpages =
2176 then preloadlayout state.layout
2181 Set.Make
(struct type t
= int let compare = (-) end) in
2183 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2184 IntSet.empty
preloadedpages
2187 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2188 if not
(IntSet.mem
pageno set)
2190 wcmd "freepage %s" opaque
;
2196 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2199 state.currently
<- Idle
;
2202 tilepage l.pageno pageopaque state.layout;
2204 load preloadedpages;
2205 if pagevisible state.layout l.pageno
2206 && layoutready state.layout
2207 then G.postRedisplay "page";
2210 | Some
(layout, _
, _
) ->
2211 state.currently
<- Idle
;
2212 tilepage l.pageno pageopaque layout;
2217 dolog "Inconsistent loading state";
2218 logcurrently state.currently
;
2223 let (x, y, opaque
, size
, t
) =
2225 Scanf.sscanf
args "%u %u %s %u %f"
2226 (fun x y p size t
-> (x, y, p
, size
, t
))
2228 dolog "error processing 'tile' %S: %s"
2229 cmds
(Printexc.to_string exn
);
2232 begin match state.currently
with
2233 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2234 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2236 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2238 wcmd "freetile %s" opaque
;
2239 state.currently
<- Idle
;
2243 puttileopaque l col row gen cs angle opaque size t
;
2244 state.memused
<- state.memused
+ size
;
2245 state.uioh#infochanged Memused
;
2247 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2248 opaque
, size
) state.tilelru
;
2251 match state.throttle
with
2252 | None
-> state.layout
2253 | Some
(layout, _
, _
) -> layout
2256 state.currently
<- Idle
;
2258 && conf.colorspace
= cs
2259 && conf.angle
= angle
2260 && tilevisible layout l.pageno x y
2261 then conttiling l.pageno pageopaque;
2263 begin match state.throttle
with
2265 preload state.layout;
2267 && conf.colorspace
= cs
2268 && conf.angle
= angle
2269 && tilevisible state.layout l.pageno x y
2270 then G.postRedisplay "tile nothrottle";
2272 | Some
(layout, y, _
) ->
2273 let ready = layoutready layout in
2277 state.layout <- layout;
2278 state.throttle
<- None
;
2279 G.postRedisplay "throttle";
2286 dolog "Inconsistent tiling state";
2287 logcurrently state.currently
;
2294 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2296 dolog "error processing 'pdim' %S: %s"
2297 cmds
(Printexc.to_string exn
);
2300 state.uioh#infochanged Pdim
;
2301 state.pdims
<- pdim :: state.pdims
2304 let (l, n, t
, h, pos
) =
2306 Scanf.sscanf
args "%u %u %d %u %n"
2307 (fun l n t
h pos
-> l, n, t
, h, pos
)
2309 dolog "error processing 'o' %S: %s"
2310 cmds
(Printexc.to_string exn
);
2313 let s = String.sub
args pos
(String.length
args - pos
) in
2314 let outline = (s, l, (n, float t
/. float h)) in
2315 begin match state.currently
with
2316 | Outlining outlines
->
2317 state.currently
<- Outlining
(outline :: outlines
)
2319 state.currently
<- Outlining
[outline]
2321 dolog "invalid outlining state";
2322 logcurrently currently
2326 state.docinfo
<- (1, args) :: state.docinfo
2329 state.uioh#infochanged Docinfo
;
2330 state.docinfo
<- List.rev
state.docinfo
2333 dolog "unknown cmd `%S'" cmds
2338 let action = function
2339 | HCprev
-> cbget cb ~
-1
2340 | HCnext
-> cbget cb
1
2341 | HCfirst
-> cbget cb ~
-(cb
.rc)
2342 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2343 and cancel
() = cb
.rc <- rc
2347 let search pattern forward
=
2348 if String.length pattern
> 0
2351 match state.layout with
2354 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2356 wcmd "search %d %d %d %d,%s\000"
2357 (btod conf.icase
) pn py (btod forward
) pattern
;
2360 let intentry text key =
2362 if key >= 32 && key < 127
2368 let text = addchar text c in
2372 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2376 let textentry text key =
2377 if key land 0xff00 = 0xff00
2379 else TEcont
(text ^
Wsi.toutf8
key)
2382 let reqlayout angle proportional
=
2383 match state.throttle
with
2385 if nogeomcmds state.geomcmds
2386 then state.anchor <- getanchor ();
2387 conf.angle
<- angle
mod 360;
2390 match state.mode
with
2391 | LinkNav _
-> state.mode
<- View
2394 conf.proportional
<- proportional
;
2395 invalidate "reqlayout"
2396 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2400 let settrim trimmargins trimfuzz
=
2401 if nogeomcmds state.geomcmds
2402 then state.anchor <- getanchor ();
2403 conf.trimmargins
<- trimmargins
;
2404 conf.trimfuzz
<- trimfuzz
;
2405 let x0, y0, x1, y1 = trimfuzz
in
2406 invalidate "settrim"
2408 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2409 Hashtbl.iter
(fun _ opaque
->
2410 wcmd "freepage %s" opaque
;
2412 Hashtbl.clear
state.pagemap
;
2416 match state.throttle
with
2418 let zoom = max
0.01 zoom in
2419 if zoom <> conf.zoom
2421 state.prevzoom
<- conf.zoom;
2423 reshape conf.winw
conf.winh
;
2424 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2427 | Some
(layout, y, started
) ->
2429 match conf.maxwait
with
2433 let dt = now () -. started
in
2441 let setcolumns mode columns coverA coverB
=
2445 then showtext '
!'
"split mode doesn't work in bird's eye"
2447 conf.columns
<- Csplit
(-columns
, [||]);
2455 conf.columns
<- Csingle
;
2460 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2464 reshape conf.winw
conf.winh
;
2467 let enterbirdseye () =
2468 let zoom = float conf.thumbw
/. float conf.winw
in
2469 let birdseyepageno =
2470 let cy = conf.winh
/ 2 in
2474 let rec fold best
= function
2477 let d = cy - (l.pagedispy + l.pagevh/2)
2478 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2479 if abs
d < abs dbest
2486 state.mode
<- Birdseye
(
2487 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2490 conf.presentation <- false;
2491 conf.interpagespace <- 10;
2492 conf.hlinks
<- false;
2494 state.mstate
<- Mnone
;
2495 conf.maxwait
<- None
;
2497 match conf.beyecolumns
with
2500 Cmulti
((c, 0, 0), [||])
2503 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2506 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2511 reshape conf.winw
conf.winh
;
2514 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2516 conf.zoom <- c.zoom;
2517 conf.presentation <- c.presentation;
2518 conf.interpagespace <- c.interpagespace;
2519 conf.maxwait
<- c.maxwait
;
2520 conf.hlinks
<- c.hlinks
;
2521 conf.beyecolumns
<- (
2522 match conf.columns
with
2523 | Cmulti
((c, _
, _
), _
) -> Some
c
2525 | Csplit _
-> assert false
2528 match c.columns
with
2529 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2530 | Csingle
-> Csingle
2531 | Csplit _
-> failwith
"leaving bird's eye split mode"
2536 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2539 reshape conf.winw
conf.winh
;
2540 state.anchor <- if goback
then anchor else (pageno, 0.0);
2543 let togglebirdseye () =
2544 match state.mode
with
2545 | Birdseye vals
-> leavebirdseye vals
true
2546 | View
-> enterbirdseye ()
2550 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2551 let pageno = max
0 (pageno - incr
) in
2552 let rec loop = function
2553 | [] -> gotopage1 pageno 0
2554 | l :: _
when l.pageno = pageno ->
2555 if l.pagedispy >= 0 && l.pagey = 0
2556 then G.postRedisplay "upbirdseye"
2557 else gotopage1 pageno 0
2558 | _
:: rest
-> loop rest
2561 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2564 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2565 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2566 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2567 let rec loop = function
2569 let y, h = getpageyh pageno in
2570 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2572 | l :: _
when l.pageno = pageno ->
2573 if l.pagevh != l.pageh
2574 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2575 else G.postRedisplay "downbirdseye"
2576 | _
:: rest
-> loop rest
2581 let optentry mode _
key =
2582 let btos b = if b then "on" else "off" in
2583 if key >= 32 && key < 127
2585 let c = Char.chr
key in
2589 try conf.scrollstep
<- int_of_string
s with exc
->
2590 state.text <- Printf.sprintf
"bad integer `%s': %s"
2591 s (Printexc.to_string exc
)
2593 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2598 conf.autoscrollstep
<- int_of_string
s;
2599 if state.autoscroll
<> None
2600 then state.autoscroll
<- Some
conf.autoscrollstep
2602 state.text <- Printf.sprintf
"bad integer `%s': %s"
2603 s (Printexc.to_string exc
)
2605 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2608 let mode = state.mode in
2611 let n, a, b = multicolumns_of_string s in
2612 setcolumns mode n a b;
2614 state.text <- Printf.sprintf
"bad columns `%s': %s"
2615 s (Printexc.to_string exc
)
2617 TEswitch
("columns: ", "", None
, textentry, ondone)
2622 let zoom = float (int_of_string
s) /. 100.0 in
2625 state.text <- Printf.sprintf
"bad integer `%s': %s"
2626 s (Printexc.to_string exc
)
2628 TEswitch
("zoom: ", "", None
, intentry, ondone)
2633 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2635 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2636 begin match mode with
2638 leavebirdseye beye
false;
2643 state.text <- Printf.sprintf
"bad integer `%s': %s"
2644 s (Printexc.to_string exc
)
2646 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2651 Some
(int_of_string
s)
2653 state.text <- Printf.sprintf
"bad integer `%s': %s"
2654 s (Printexc.to_string exc
);
2657 | Some angle
-> reqlayout angle
conf.proportional
2660 TEswitch
("rotation: ", "", None
, intentry, ondone)
2663 conf.icase
<- not
conf.icase
;
2664 TEdone
("case insensitive search " ^
(btos conf.icase
))
2667 conf.preload <- not
conf.preload;
2669 TEdone
("preload " ^
(btos conf.preload))
2672 conf.verbose
<- not
conf.verbose
;
2673 TEdone
("verbose " ^
(btos conf.verbose
))
2676 conf.debug
<- not
conf.debug
;
2677 TEdone
("debug " ^
(btos conf.debug
))
2680 conf.maxhfit
<- not
conf.maxhfit
;
2682 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2683 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2686 conf.crophack
<- not
conf.crophack
;
2687 TEdone
("crophack " ^
btos conf.crophack
)
2691 match conf.maxwait
with
2693 conf.maxwait
<- Some infinity
;
2694 "always wait for page to complete"
2696 conf.maxwait
<- None
;
2697 "show placeholder if page is not ready"
2702 conf.underinfo
<- not
conf.underinfo
;
2703 TEdone
("underinfo " ^
btos conf.underinfo
)
2706 conf.savebmarks
<- not
conf.savebmarks
;
2707 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2713 match state.layout with
2718 conf.interpagespace <- int_of_string
s;
2719 state.maxy <- calcheight ();
2720 let y = getpagey pageno in
2723 state.text <- Printf.sprintf
"bad integer `%s': %s"
2724 s (Printexc.to_string exc
)
2726 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2729 reqlayout conf.angle
(not
conf.proportional
);
2730 TEdone
("proportional display " ^
btos conf.proportional
)
2733 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2734 TEdone
("trim margins " ^
btos conf.trimmargins
)
2737 conf.invert
<- not
conf.invert
;
2738 TEdone
("invert colors " ^
btos conf.invert
)
2742 cbput state.hists
.sel
s;
2745 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2749 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2755 class type lvsource
= object
2756 method getitemcount
: int
2757 method getitem
: int -> (string * int)
2758 method hasaction
: int -> bool
2767 method getactive
: int
2768 method getfirst
: int
2769 method getqsearch
: string
2770 method setqsearch
: string -> unit
2774 class virtual lvsourcebase
= object
2775 val mutable m_active
= 0
2776 val mutable m_first
= 0
2777 val mutable m_qsearch
= ""
2778 val mutable m_pan
= 0
2779 method getactive
= m_active
2780 method getfirst
= m_first
2781 method getqsearch
= m_qsearch
2782 method getpan
= m_pan
2783 method setqsearch
s = m_qsearch
<- s
2786 let withoutlastutf8 s =
2787 let len = String.length
s in
2795 let b = Char.code
s.[pos
] in
2796 if b land 0b110000 = 0b11000000
2801 if Char.code
s.[len-1] land 0x80 = 0
2805 String.sub
s 0 first;
2808 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2810 state.mode <- Textentry
(te
, onleave
);
2813 G.postRedisplay "textentrykeyboard enttext";
2815 let histaction cmd
=
2818 | Some
(action, _
) ->
2819 state.mode <- Textentry
(
2820 (c, action cmd
, opthist
, onkey
, ondone), onleave
2822 G.postRedisplay "textentry histaction"
2825 | 0xff08 -> (* backspace *)
2826 let s = withoutlastutf8 text in
2827 let len = String.length
s in
2831 G.postRedisplay "textentrykeyboard after cancel";
2834 enttext (c, s, opthist
, onkey
, ondone)
2840 G.postRedisplay "textentrykeyboard after confirm"
2842 | 0xff52 -> histaction HCprev
2843 | 0xff54 -> histaction HCnext
2844 | 0xff50 -> histaction HCfirst
2845 | 0xff57 -> histaction HClast
2847 | 0xff1b -> (* escape*)
2848 if String.length
text = 0
2850 begin match opthist
with
2852 | Some
(_
, onhistcancel
) -> onhistcancel
()
2856 G.postRedisplay "textentrykeyboard after cancel2"
2859 enttext (c, "", opthist
, onkey
, ondone)
2862 | 0xff9f | 0xffff -> () (* delete *)
2864 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2865 begin match onkey
text key with
2869 G.postRedisplay "textentrykeyboard after confirm2";
2872 enttext (c, text, opthist
, onkey
, ondone);
2876 G.postRedisplay "textentrykeyboard after cancel3"
2879 state.mode <- Textentry
(te
, onleave
);
2880 G.postRedisplay "textentrykeyboard switch";
2884 vlog "unhandled key %s" (Wsi.keyname
key)
2887 let firstof first active
=
2888 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2889 then max
0 (active
- (fstate.maxrows
/2))
2893 let calcfirst first active
=
2896 let rows = active
- first in
2897 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2901 let scrollph y maxy =
2902 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2903 let sh = float conf.winh
/. sh in
2904 let sh = max
sh (float conf.scrollh
) in
2909 else float y /. float maxy
2911 let position = (float conf.winh
-. sh) *. percent in
2914 if position +. sh > float conf.winh
2915 then float conf.winh
-. sh
2921 let coe s = (s :> uioh
);;
2923 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2925 val m_pan
= source#getpan
2926 val m_first
= source#getfirst
2927 val m_active
= source#getactive
2928 val m_qsearch
= source#getqsearch
2929 val m_prev_uioh
= state.uioh
2931 method private elemunder
y =
2932 let n = y / (fstate.fontsize
+1) in
2933 if m_first
+ n < source#getitemcount
2935 if source#hasaction
(m_first
+ n)
2936 then Some
(m_first
+ n)
2943 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2944 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2945 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2946 GlDraw.color
(1., 1., 1.);
2947 Gl.enable `texture_2d
;
2948 let fs = fstate.fontsize
in
2950 let ww = fstate.wwidth
in
2951 let tabw = 30.0*.ww in
2952 let itemcount = source#getitemcount
in
2954 if (row - m_first
) * nfs > conf.winh
2957 if row >= 0 && row < itemcount
2959 let (s, level
) = source#getitem
row in
2960 let y = (row - m_first
) * nfs in
2961 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2964 Gl.disable `texture_2d
;
2965 GlDraw.polygon_mode `both `line
;
2966 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2967 GlDraw.rect (1., float (y + 1))
2968 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2969 GlDraw.polygon_mode `both `fill
;
2970 GlDraw.color
(1., 1., 1.);
2971 Gl.enable `texture_2d
;
2974 let drawtabularstring s =
2975 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2978 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2981 let len = String.length
s - tabpos - 1 in
2982 let s1 = String.sub
s 0 tabpos
2983 and s2
= String.sub
s (tabpos + 1) len in
2984 let nx = drawstr x s1 in
2986 let x = x +. (max
tabw sw) in
2993 let _ = drawtabularstring s in
3000 Gl.disable `texture_2d
;
3002 method updownlevel incr
=
3003 let len = source#getitemcount
in
3005 if m_active
>= 0 && m_active
< len
3006 then snd
(source#getitem m_active
)
3010 if i
= len then i
-1 else if i
= -1 then 0 else
3011 let _, l = source#getitem i
in
3012 if l != curlevel then i
else flow (i
+incr
)
3014 let active = flow m_active
in
3015 let first = calcfirst m_first
active in
3016 G.postRedisplay "outline updownlevel";
3017 {< m_active
= active; m_first
= first >}
3019 method private key1
key mask
=
3020 let set1 active first qsearch
=
3021 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3023 let search active pattern incr
=
3026 if n >= 0 && n < source#getitemcount
3028 let s, _ = source#getitem
n in
3030 (try ignore
(Str.search_forward
re s 0); true
3031 with Not_found
-> false)
3033 else loop (n + incr
)
3040 let re = Str.regexp_case_fold pattern
in
3046 let itemcount = source#getitemcount
in
3047 let find start incr
=
3049 if i
= -1 || i
= itemcount
3052 if source#hasaction i
3054 else find (i
+ incr
)
3059 let set active first =
3060 let first = bound first 0 (itemcount - fstate.maxrows
) in
3062 coe {< m_active
= active; m_first
= first >}
3065 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3067 let incr1 = if incr
> 0 then 1 else -1 in
3068 if isvisible m_first m_active
3071 let next = m_active
+ incr
in
3073 if next < 0 || next >= itemcount
3075 else find next incr1
3077 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3083 let first = m_first
+ incr
in
3084 let first = bound first 0 (itemcount - 1) in
3086 let next = m_active
+ incr
in
3087 let next = bound next 0 (itemcount - 1) in
3090 let active = if next = -1 then m_active
else next in
3093 let first = min
next m_first
in
3095 if abs
(next - first) > fstate.maxrows
3101 let first = m_first
+ incr
in
3102 let first = bound first 0 (itemcount - 1) in
3104 let next = m_active
+ incr
in
3105 let next = bound next 0 (itemcount - 1) in
3106 let next = find next incr1 in
3108 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3110 let active = if m_active
= -1 then next else m_active
in
3115 if isvisible first active
3121 G.postRedisplay "listview navigate";
3125 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3126 let incr = if key = 0x72 then -1 else 1 in
3128 match search (m_active
+ incr) m_qsearch
incr with
3130 state.text <- m_qsearch ^
" [not found]";
3133 state.text <- m_qsearch
;
3134 active, firstof m_first
active
3136 G.postRedisplay "listview ctrl-r/s";
3137 set1 active first m_qsearch
;
3139 | 0xff08 -> (* backspace *)
3140 if String.length m_qsearch
= 0
3143 let qsearch = withoutlastutf8 m_qsearch
in
3144 let len = String.length
qsearch in
3148 G.postRedisplay "listview empty qsearch";
3149 set1 m_active m_first
"";
3153 match search m_active
qsearch ~
-1 with
3155 state.text <- qsearch ^
" [not found]";
3158 state.text <- qsearch;
3159 active, firstof m_first
active
3161 G.postRedisplay "listview backspace qsearch";
3162 set1 active first qsearch
3165 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3166 let pattern = m_qsearch ^
Wsi.toutf8
key in
3168 match search m_active
pattern 1 with
3170 state.text <- pattern ^
" [not found]";
3173 state.text <- pattern;
3174 active, firstof m_first
active
3176 G.postRedisplay "listview qsearch add";
3177 set1 active first pattern;
3179 | 0xff1b -> (* escape *)
3181 if String.length m_qsearch
= 0
3183 G.postRedisplay "list view escape";
3186 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3188 | None
-> m_prev_uioh
3193 G.postRedisplay "list view kill qsearch";
3194 source#setqsearch
"";
3195 coe {< m_qsearch
= "" >}
3198 | 0xff0d -> (* return *)
3200 let self = {< m_qsearch
= "" >} in
3201 source#setqsearch
"";
3203 G.postRedisplay "listview enter";
3204 if m_active
>= 0 && m_active
< source#getitemcount
3206 source#exit
(coe self) false m_active m_first m_pan
"";
3209 source#exit
(coe self) true m_active m_first m_pan
"";
3212 begin match opt with
3213 | None
-> m_prev_uioh
3217 | 0xff9f | 0xffff -> (* delete *)
3220 | 0xff52 -> navigate ~
-1 (* up *)
3221 | 0xff54 -> navigate 1 (* down *)
3222 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3223 | 0xff56 -> navigate fstate.maxrows
(* next *)
3225 | 0xff53 -> (* right *)
3227 G.postRedisplay "listview right";
3228 coe {< m_pan
= m_pan
- 1 >}
3230 | 0xff51 -> (* left *)
3232 G.postRedisplay "listview left";
3233 coe {< m_pan
= m_pan
+ 1 >}
3235 | 0xff50 -> (* home *)
3236 let active = find 0 1 in
3237 G.postRedisplay "listview home";
3240 | 0xff57 -> (* end *)
3241 let first = max
0 (itemcount - fstate.maxrows
) in
3242 let active = find (itemcount - 1) ~
-1 in
3243 G.postRedisplay "listview end";
3246 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3250 dolog "listview unknown key %#x" key; coe self
3252 method key key mask
=
3253 match state.mode with
3254 | Textentry te
-> textentrykeyboard key mask te
; coe self
3255 | _ -> self#key1
key mask
3257 method button button down
x y _ =
3260 | 1 when x > conf.winw
- conf.scrollbw
->
3261 G.postRedisplay "listview scroll";
3264 let _, position, sh = self#
scrollph in
3265 if y > truncate
position && y < truncate
(position +. sh)
3267 state.mstate
<- Mscrolly
;
3271 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3272 let first = truncate
(s *. float source#getitemcount
) in
3273 let first = min source#getitemcount
first in
3274 Some
(coe {< m_first
= first; m_active
= first >})
3276 state.mstate
<- Mnone
;
3279 | 1 when not down
->
3280 begin match self#elemunder
y with
3282 G.postRedisplay "listview click";
3284 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3288 | n when (n == 4 || n == 5) && not down
->
3289 let len = source#getitemcount
in
3291 if n = 5 && m_first
+ fstate.maxrows
>= len
3295 let first = m_first
+ (if n == 4 then -1 else 1) in
3296 bound first 0 (len - 1)
3298 G.postRedisplay "listview wheel";
3299 Some
(coe {< m_first
= first >})
3304 | None
-> m_prev_uioh
3308 match state.mstate
with
3310 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3311 let first = truncate
(s *. float source#getitemcount
) in
3312 let first = min source#getitemcount
first in
3313 G.postRedisplay "listview motion";
3314 coe {< m_first
= first; m_active
= first >}
3317 method pmotion
x y =
3318 if x < conf.winw
- conf.scrollbw
3321 match self#elemunder
y with
3322 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3323 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3327 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3332 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3336 method infochanged
_ = ()
3338 method scrollpw
= (0, 0.0, 0.0)
3340 let nfs = fstate.fontsize
+ 1 in
3341 let y = m_first
* nfs in
3342 let itemcount = source#getitemcount
in
3343 let maxi = max
0 (itemcount - fstate.maxrows
) in
3344 let maxy = maxi * nfs in
3345 let p, h = scrollph y maxy in
3348 method modehash
= modehash
3351 class outlinelistview ~source
=
3354 ~source
:(source
:> lvsource
)
3356 ~modehash
:(findkeyhash conf "outline")
3359 method key key mask
=
3360 let calcfirst first active =
3363 let rows = active - first in
3364 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3368 let active = m_active
+ incr in
3369 let active = bound active 0 (source#getitemcount
- 1) in
3370 let first = calcfirst m_first
active in
3371 G.postRedisplay "outline navigate";
3372 coe {< m_active
= active; m_first
= first >}
3374 let ctrl = Wsi.withctrl mask
in
3376 | 110 when ctrl -> (* ctrl-n *)
3377 source#narrow m_qsearch
;
3378 G.postRedisplay "outline ctrl-n";
3379 coe {< m_first
= 0; m_active
= 0 >}
3381 | 117 when ctrl -> (* ctrl-u *)
3383 G.postRedisplay "outline ctrl-u";
3385 coe {< m_first
= 0; m_active
= 0 >}
3387 | 108 when ctrl -> (* ctrl-l *)
3388 let first = m_active
- (fstate.maxrows
/ 2) in
3389 G.postRedisplay "outline ctrl-l";
3390 coe {< m_first
= first >}
3392 | 0xff9f | 0xffff -> (* delete *)
3393 source#remove m_active
;
3394 G.postRedisplay "outline delete";
3395 let active = max
0 (m_active
-1) in
3396 coe {< m_first
= firstof m_first
active;
3397 m_active
= active >}
3399 | 0xff52 -> navigate ~
-1 (* up *)
3400 | 0xff54 -> navigate 1 (* down *)
3401 | 0xff55 -> (* prior *)
3402 navigate ~
-(fstate.maxrows
)
3403 | 0xff56 -> (* next *)
3404 navigate fstate.maxrows
3406 | 0xff53 -> (* [ctrl-]right *)
3410 G.postRedisplay "outline ctrl right";
3411 {< m_pan
= m_pan
+ 1 >}
3413 else self#updownlevel
1
3417 | 0xff51 -> (* [ctrl-]left *)
3421 G.postRedisplay "outline ctrl left";
3422 {< m_pan
= m_pan
- 1 >}
3424 else self#updownlevel ~
-1
3428 | 0xff50 -> (* home *)
3429 G.postRedisplay "outline home";
3430 coe {< m_first
= 0; m_active
= 0 >}
3432 | 0xff57 -> (* end *)
3433 let active = source#getitemcount
- 1 in
3434 let first = max
0 (active - fstate.maxrows
) in
3435 G.postRedisplay "outline end";
3436 coe {< m_active
= active; m_first
= first >}
3438 | _ -> super#
key key mask
3441 let outlinesource usebookmarks
=
3444 inherit lvsourcebase
3445 val mutable m_items
= empty
3446 val mutable m_orig_items
= empty
3447 val mutable m_prev_items
= empty
3448 val mutable m_narrow_pattern
= ""
3449 val mutable m_hadremovals
= false
3451 method getitemcount
=
3452 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3455 if n == Array.length m_items
&& m_hadremovals
3457 ("[Confirm removal]", 0)
3459 let s, n, _ = m_items
.(n) in
3462 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3463 ignore
(uioh
, first, qsearch);
3464 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3466 if String.length m_narrow_pattern
= 0
3472 if not
confrimremoval
3474 let _, _, anchor = m_items
.(active) in
3479 state.bookmarks
<- Array.to_list m_items
;
3480 m_orig_items
<- m_items
;
3483 else m_items
<- items;
3487 method hasaction
_ = true
3490 if Array.length m_items
!= Array.length m_orig_items
3491 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3494 method narrow
pattern =
3495 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3499 let rec loop accu n =
3502 m_narrow_pattern
<- pattern;
3503 m_items
<- Array.of_list
accu
3506 let (s, _, _) as o = m_items
.(n) in
3508 if (try ignore
(Str.search_forward
re s 0); true
3509 with Not_found
-> false)
3515 loop [] (Array.length m_items
- 1)
3520 then Array.of_list
state.bookmarks
3523 m_items
<- m_orig_items
3528 if m
>= 0 && m
< Array.length m_items
3530 m_hadremovals
<- true;
3531 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3532 let n = if n >= m
then n+1 else n in
3537 method reset
anchor items =
3538 m_hadremovals
<- false;
3539 if m_orig_items
== empty || m_prev_items
!= items
3541 m_orig_items
<- items;
3542 if String.length m_narrow_pattern
= 0
3543 then m_items
<- items;
3545 m_prev_items
<- items;
3546 let rely = getanchory anchor in
3548 let rec loop n best bestd
=
3549 if n = Array.length m_items
3552 let (_, _, anchor) = m_items
.(n) in
3553 let orely = getanchory anchor in
3554 let d = abs
(orely - rely) in
3557 else loop (n+1) best bestd
3562 m_first
<- firstof m_first
active
3566 let enterselector usebookmarks
=
3567 let source = outlinesource usebookmarks
in
3571 then Array.of_list
state.bookmarks
3574 if Array.length
outlines = 0
3576 showtext ' ' errmsg
;
3579 state.text <- source#greetmsg
;
3580 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3581 let anchor = getanchor () in
3582 source#reset
anchor outlines;
3583 state.uioh
<- coe (new outlinelistview ~
source);
3584 G.postRedisplay "enter selector";
3588 let enteroutlinemode =
3589 let f = enterselector false in
3590 fun ()-> f "Document has no outline";
3593 let enterbookmarkmode =
3594 let f = enterselector true in
3595 fun () -> f "Document has no bookmarks (yet)";
3598 let color_of_string s =
3599 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3600 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3604 let color_to_string (r
, g
, b) =
3605 let r = truncate
(r *. 256.0)
3606 and g
= truncate
(g
*. 256.0)
3607 and b = truncate
(b *. 256.0) in
3608 Printf.sprintf
"%d/%d/%d" r g
b
3611 let irect_of_string s =
3612 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3615 let irect_to_string (x0,y0,x1,y1) =
3616 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3619 let makecheckers () =
3620 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3622 converted by Issac Trotts. July 25, 2002 *)
3623 let image_height = 64
3624 and image_width
= 64 in
3628 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3630 for i
= 0 to image_width
- 1 do
3631 for j
= 0 to image_height - 1 do
3632 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3633 (if (i
land 8 ) lxor (j
land 8) = 0
3634 then [|255;255;255|] else [|200;200;200|])
3639 let image = make_image () in
3640 let id = GlTex.gen_texture
() in
3641 GlTex.bind_texture `texture_2d
id;
3642 GlPix.store
(`unpack_alignment
1);
3643 GlTex.image2d
image;
3644 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3647 `mag_filter `nearest
;
3648 `min_filter `nearest
];
3652 let setcheckers enabled
=
3653 match state.texid
with
3655 if enabled
then state.texid
<- Some
(makecheckers ())
3660 GlTex.delete_texture texid
;
3661 state.texid
<- None
;
3665 let int_of_string_with_suffix s =
3666 let l = String.length
s in
3670 let suffix = Char.lowercase
s.[l-1] in
3672 | 'k'
-> String.sub
s 0 (l-1), 10
3673 | 'm'
-> String.sub
s 0 (l-1), 20
3674 | 'g'
-> String.sub
s 0 (l-1), 30
3678 let n = int_of_string
s1 in
3679 let m = n lsl shift
in
3681 then raise
(Failure
"value too large")
3685 let string_with_suffix_of_int n =
3693 if n land ((1 lsl 20) - 1) = 0
3696 if n land ((1 lsl 10) - 1) = 0
3703 let h = n mod 1000 in
3706 then string_of_int
h ^
s
3708 let s = Printf.sprintf
"_%03d%s" h s in
3715 let defghyllscroll = (40, 8, 32);;
3716 let ghyllscroll_of_string s =
3717 let (n, a, b) as nab
=
3720 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3722 if n <= a || n <= b || a >= b
3723 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3727 let ghyllscroll_to_string ((n, a, b) as nab
) =
3728 if nab
= defghyllscroll
3730 else Printf.sprintf
"%d,%d,%d" n a b;
3733 let describe_location () =
3735 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3737 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3738 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3742 else (100. *. (float state.y /. float maxy))
3746 Printf.sprintf
"page %d of %d [%.2f%%]"
3747 (fn+1) state.pagecount
percent
3750 "pages %d-%d of %d [%.2f%%]"
3751 (fn+1) (ln
+1) state.pagecount
percent
3755 let btos b = if b then "\xe2\x88\x9a" else "" in
3756 let showextended = ref false in
3757 let leave mode = function
3758 | Confirm
-> state.mode <- mode
3759 | Cancel
-> state.mode <- mode in
3762 val mutable m_first_time
= true
3763 val mutable m_l
= []
3764 val mutable m_a
= [||]
3765 val mutable m_prev_uioh
= nouioh
3766 val mutable m_prev_mode
= View
3768 inherit lvsourcebase
3770 method reset prev_mode prev_uioh
=
3771 m_a
<- Array.of_list
(List.rev m_l
);
3773 m_prev_mode
<- prev_mode
;
3774 m_prev_uioh
<- prev_uioh
;
3778 if n >= Array.length m_a
3782 | _, _, _, Action
_ -> m_active
<- n
3786 m_first_time
<- false;
3789 method int name get
set =
3791 (name
, `
int get
, 1, Action
(
3794 try set (int_of_string
s)
3796 state.text <- Printf.sprintf
"bad integer `%s': %s"
3797 s (Printexc.to_string exn
)
3800 let te = name ^
": ", "", None
, intentry, ondone in
3801 state.mode <- Textentry
(te, leave m_prev_mode
);
3805 method int_with_suffix name get
set =
3807 (name
, `intws get
, 1, Action
(
3810 try set (int_of_string_with_suffix s)
3812 state.text <- Printf.sprintf
"bad integer `%s': %s"
3813 s (Printexc.to_string exn
)
3817 name ^
": ", "", None
, intentry_with_suffix, ondone
3819 state.mode <- Textentry
(te, leave m_prev_mode
);
3823 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3825 (name
, `
bool (btos, get
), offset
, Action
(
3832 method color name get
set =
3834 (name
, `color get
, 1, Action
(
3836 let invalid = (nan
, nan
, nan
) in
3839 try color_of_string s
3841 state.text <- Printf.sprintf
"bad color `%s': %s"
3842 s (Printexc.to_string exn
);
3848 let te = name ^
": ", "", None
, textentry, ondone in
3849 state.text <- color_to_string (get
());
3850 state.mode <- Textentry
(te, leave m_prev_mode
);
3854 method string name get
set =
3856 (name
, `
string get
, 1, Action
(
3858 let ondone s = set s in
3859 let te = name ^
": ", "", None
, textentry, ondone in
3860 state.mode <- Textentry
(te, leave m_prev_mode
);
3864 method colorspace name get
set =
3866 (name
, `
string get
, 1, Action
(
3869 let vals = [| "rgb"; "bgr"; "gray" |] in
3871 inherit lvsourcebase
3874 m_active
<- int_of_colorspace conf.colorspace
;
3877 method getitemcount
= Array.length
vals
3878 method getitem
n = (vals.(n), 0)
3879 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3880 ignore
(uioh
, first, pan
, qsearch);
3881 if not cancel
then set active;
3883 method hasaction
_ = true
3887 let modehash = findkeyhash conf "info" in
3888 coe (new listview ~
source ~trusted
:true ~
modehash)
3891 method caption
s offset
=
3892 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3894 method caption2
s f offset
=
3895 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3897 method getitemcount
= Array.length m_a
3900 let tostr = function
3901 | `
int f -> string_of_int
(f ())
3902 | `intws
f -> string_with_suffix_of_int (f ())
3904 | `color
f -> color_to_string (f ())
3905 | `
bool (btos, f) -> btos (f ())
3908 let name, t
, offset
, _ = m_a
.(n) in
3909 ((let s = tostr t
in
3910 if String.length
s > 0
3911 then Printf.sprintf
"%s\t%s" name s
3915 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3919 m_qsearch
<- qsearch;
3921 match m_a
.(active) with
3922 | _, _, _, Action
f -> f uioh
3934 method hasaction
n =
3936 | _, _, _, Action
_ -> true
3940 let rec fillsrc prevmode prevuioh
=
3941 let sep () = src#caption
"" 0 in
3942 let colorp name get
set =
3944 (fun () -> color_to_string (get
()))
3947 let c = color_of_string v in
3950 state.text <- Printf.sprintf
"bad color `%s': %s"
3951 v (Printexc.to_string exn
);
3954 let oldmode = state.mode in
3955 let birdseye = isbirdseye state.mode in
3957 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3959 src#
bool "presentation mode"
3960 (fun () -> conf.presentation)
3962 conf.presentation <- v;
3963 state.anchor <- getanchor ();
3966 src#
bool "ignore case in searches"
3967 (fun () -> conf.icase
)
3968 (fun v -> conf.icase
<- v);
3971 (fun () -> conf.preload)
3972 (fun v -> conf.preload <- v);
3974 src#
bool "highlight links"
3975 (fun () -> conf.hlinks
)
3976 (fun v -> conf.hlinks
<- v);
3978 src#
bool "under info"
3979 (fun () -> conf.underinfo
)
3980 (fun v -> conf.underinfo
<- v);
3982 src#
bool "persistent bookmarks"
3983 (fun () -> conf.savebmarks
)
3984 (fun v -> conf.savebmarks
<- v);
3986 src#
bool "proportional display"
3987 (fun () -> conf.proportional
)
3988 (fun v -> reqlayout conf.angle
v);
3990 src#
bool "trim margins"
3991 (fun () -> conf.trimmargins
)
3992 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3994 src#
bool "persistent location"
3995 (fun () -> conf.jumpback
)
3996 (fun v -> conf.jumpback
<- v);
3999 src#
int "inter-page space"
4000 (fun () -> conf.interpagespace)
4002 conf.interpagespace <- n;
4004 match state.layout with
4009 state.maxy <- calcheight ();
4010 let y = getpagey pageno in
4015 (fun () -> conf.pagebias
)
4016 (fun v -> conf.pagebias
<- v);
4018 src#
int "scroll step"
4019 (fun () -> conf.scrollstep
)
4020 (fun n -> conf.scrollstep
<- n);
4022 src#
int "auto scroll step"
4024 match state.autoscroll
with
4026 | _ -> conf.autoscrollstep
)
4028 if state.autoscroll
<> None
4029 then state.autoscroll
<- Some
n;
4030 conf.autoscrollstep
<- n);
4033 (fun () -> truncate
(conf.zoom *. 100.))
4034 (fun v -> setzoom ((float v) /. 100.));
4037 (fun () -> conf.angle
)
4038 (fun v -> reqlayout v conf.proportional
);
4040 src#
int "scroll bar width"
4041 (fun () -> state.scrollw
)
4045 reshape conf.winw
conf.winh
;
4048 src#
int "scroll handle height"
4049 (fun () -> conf.scrollh
)
4050 (fun v -> conf.scrollh
<- v;);
4052 src#
int "thumbnail width"
4053 (fun () -> conf.thumbw
)
4055 conf.thumbw
<- min
4096 v;
4058 leavebirdseye beye
false;
4063 let mode = state.mode in
4064 src#
string "columns"
4066 match conf.columns
with
4068 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4069 | Csplit
(count
, _) -> string_of_int count
4072 let n, a, b = multicolumns_of_string v in
4073 setcolumns mode n a b);
4076 src#caption
"Presentation mode" 0;
4077 src#
bool "scrollbar visible"
4078 (fun () -> conf.scrollbarinpm
)
4080 if v != conf.scrollbarinpm
4082 conf.scrollbarinpm
<- v;
4083 if conf.presentation
4085 state.scrollw
<- if v then conf.scrollbw
else 0;
4086 reshape conf.winw
conf.winh
;
4092 src#caption
"Pixmap cache" 0;
4093 src#int_with_suffix
"size (advisory)"
4094 (fun () -> conf.memlimit
)
4095 (fun v -> conf.memlimit
<- v);
4098 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4099 (string_with_suffix_of_int state.memused
)
4100 (Hashtbl.length
state.tilemap
)) 1;
4103 src#caption
"Layout" 0;
4104 src#caption2
"Dimension"
4106 Printf.sprintf
"%dx%d (virtual %dx%d)"
4112 src#caption2
"Position" (fun () ->
4113 Printf.sprintf
"%dx%d" state.x state.y
4116 src#caption2
"Visible" (fun () -> describe_location ()) 1
4120 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4121 "Save these parameters as global defaults at exit"
4122 (fun () -> conf.bedefault
)
4123 (fun v -> conf.bedefault
<- v)
4127 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4128 src#
bool ~offset
:0 ~
btos "Extended parameters"
4129 (fun () -> !showextended)
4130 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4134 (fun () -> conf.checkers
)
4135 (fun v -> conf.checkers
<- v; setcheckers v);
4136 src#
bool "update cursor"
4137 (fun () -> conf.updatecurs
)
4138 (fun v -> conf.updatecurs
<- v);
4140 (fun () -> conf.verbose
)
4141 (fun v -> conf.verbose
<- v);
4142 src#
bool "invert colors"
4143 (fun () -> conf.invert
)
4144 (fun v -> conf.invert
<- v);
4146 (fun () -> conf.maxhfit
)
4147 (fun v -> conf.maxhfit
<- v);
4148 src#
bool "redirect stderr"
4149 (fun () -> conf.redirectstderr)
4150 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4151 src#
string "uri launcher"
4152 (fun () -> conf.urilauncher
)
4153 (fun v -> conf.urilauncher
<- v);
4154 src#
string "path launcher"
4155 (fun () -> conf.pathlauncher
)
4156 (fun v -> conf.pathlauncher
<- v);
4157 src#
string "tile size"
4158 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4161 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4162 conf.tileh
<- max
64 w;
4163 conf.tilew
<- max
64 h;
4166 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4167 v (Printexc.to_string exn
));
4168 src#
int "texture count"
4169 (fun () -> conf.texcount
)
4172 then conf.texcount
<- v
4173 else showtext '
!'
" Failed to set texture count please retry later"
4175 src#
int "slice height"
4176 (fun () -> conf.sliceheight
)
4178 conf.sliceheight
<- v;
4179 wcmd "sliceh %d" conf.sliceheight
;
4181 src#
int "anti-aliasing level"
4182 (fun () -> conf.aalevel
)
4184 conf.aalevel
<- bound v 0 8;
4185 state.anchor <- getanchor ();
4186 opendoc state.path
state.password
;
4188 src#
int "ui font size"
4189 (fun () -> fstate.fontsize
)
4190 (fun v -> setfontsize (bound v 5 100));
4191 colorp "background color"
4192 (fun () -> conf.bgcolor
)
4193 (fun v -> conf.bgcolor
<- v);
4194 src#
bool "crop hack"
4195 (fun () -> conf.crophack
)
4196 (fun v -> conf.crophack
<- v);
4197 src#
string "trim fuzz"
4198 (fun () -> irect_to_string conf.trimfuzz
)
4201 conf.trimfuzz
<- irect_of_string v;
4203 then settrim true conf.trimfuzz
;
4205 state.text <- Printf.sprintf
"bad irect `%s': %s"
4206 v (Printexc.to_string exn
)
4208 src#
string "throttle"
4210 match conf.maxwait
with
4211 | None
-> "show place holder if page is not ready"
4214 then "wait for page to fully render"
4216 "wait " ^ string_of_float
time
4217 ^
" seconds before showing placeholder"
4221 let f = float_of_string
v in
4223 then conf.maxwait
<- None
4224 else conf.maxwait
<- Some
f
4226 state.text <- Printf.sprintf
"bad time `%s': %s"
4227 v (Printexc.to_string exn
)
4229 src#
string "ghyll scroll"
4231 match conf.ghyllscroll
with
4233 | Some nab
-> ghyllscroll_to_string nab
4238 if String.length
v = 0
4240 else Some
(ghyllscroll_of_string v)
4242 conf.ghyllscroll
<- gs
4244 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4245 v (Printexc.to_string exn
)
4247 src#
string "selection command"
4248 (fun () -> conf.selcmd
)
4249 (fun v -> conf.selcmd
<- v);
4250 src#colorspace
"color space"
4251 (fun () -> colorspace_to_string conf.colorspace
)
4253 conf.colorspace
<- colorspace_of_int v;
4260 src#caption
"Document" 0;
4261 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4262 src#caption2
"Pages"
4263 (fun () -> string_of_int
state.pagecount
) 1;
4264 src#caption2
"Dimensions"
4265 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4269 src#caption
"Trimmed margins" 0;
4270 src#caption2
"Dimensions"
4271 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4274 src#reset prevmode prevuioh
;
4278 let prevmode = state.mode
4279 and prevuioh
= state.uioh in
4280 fillsrc prevmode prevuioh
;
4281 let source = (src :> lvsource
) in
4282 let modehash = findkeyhash conf "info" in
4283 state.uioh <- coe (object (self)
4284 inherit listview ~
source ~trusted
:true ~
modehash as super
4285 val mutable m_prevmemused
= 0
4286 method infochanged
= function
4288 if m_prevmemused
!= state.memused
4290 m_prevmemused
<- state.memused
;
4291 G.postRedisplay "memusedchanged";
4293 | Pdim
-> G.postRedisplay "pdimchanged"
4294 | Docinfo
-> fillsrc prevmode prevuioh
4296 method key key mask
=
4297 if not
(Wsi.withctrl mask
)
4300 | 0xff51 -> coe (self#updownlevel ~
-1)
4301 | 0xff53 -> coe (self#updownlevel
1)
4302 | _ -> super#
key key mask
4303 else super#
key key mask
4305 G.postRedisplay "info";
4311 inherit lvsourcebase
4312 method getitemcount
= Array.length
state.help
4314 let s, n, _ = state.help
.(n) in
4317 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4321 m_qsearch
<- qsearch;
4322 match state.help
.(active) with
4323 | _, _, Action
f -> Some
(f uioh)
4333 method hasaction
n =
4334 match state.help
.(n) with
4335 | _, _, Action
_ -> true
4342 let modehash = findkeyhash conf "help" in
4343 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4344 G.postRedisplay "help";
4349 let re = Str.regexp
"[\r\n]" in
4351 inherit lvsourcebase
4352 val mutable m_items
= [||]
4354 method getitemcount
= 1 + Array.length m_items
4359 else m_items
.(n-1), 0
4361 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4366 then Buffer.clear
state.errmsgs
;
4367 m_qsearch
<- qsearch;
4374 method hasaction
n =
4378 state.newerrmsgs
<- false;
4379 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4380 m_items
<- Array.of_list
l
4388 let source = (msgsource :> lvsource
) in
4389 let modehash = findkeyhash conf "listview" in
4390 state.uioh <- coe (object
4391 inherit listview ~
source ~trusted
:false ~
modehash as super
4394 then msgsource#reset
;
4397 G.postRedisplay "msgs";
4400 let quickbookmark ?title
() =
4401 match state.layout with
4407 let sec = Unix.gettimeofday
() in
4408 let tm = Unix.localtime
sec in
4409 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4413 (tm.Unix.tm_year
+ 1900)
4416 | Some
title -> title
4419 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4424 state.fullscreen
<- None
;
4428 let setautoscrollspeed step goingdown
=
4429 let incr = max
1 ((abs step
) / 2) in
4430 let incr = if goingdown
then incr else -incr in
4431 let astep = step
+ incr in
4432 state.autoscroll
<- Some
astep;
4435 let gotounder = function
4436 | Ulinkgoto
(pageno, top) ->
4440 gotopage1 pageno top;
4446 | Uremote
(filename
, pageno) ->
4448 if Sys.file_exists filename
4451 let dir = Filename.dirname
state.path in
4452 let path = Filename.concat
dir filename
in
4453 if Sys.file_exists
path
4457 if String.length
path > 0
4459 let anchor = getanchor () in
4460 let ranchor = state.path, state.password
, anchor in
4461 state.anchor <- (pageno, 0.0);
4462 state.ranchors
<- ranchor :: state.ranchors
;
4465 else showtext '
!'
("Could not find " ^ filename
)
4467 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4471 match conf.columns
with
4473 | _ -> conf.zoom > 1.0
4476 let viewkeyboard key mask
=
4478 let mode = state.mode in
4479 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4482 G.postRedisplay "view:enttext"
4484 let ctrl = Wsi.withctrl mask
in
4489 | 0xff63 -> (* insert *)
4490 if conf.angle
mod 360 = 0
4492 state.mode <- LinkNav
(Ltgendir
0);
4495 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4497 | 0xff1b | 113 -> (* escape / q *)
4498 begin match state.mstate
with
4500 state.mstate
<- Mnone
;
4501 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4502 G.postRedisplay "kill zoom rect";
4504 match state.ranchors
with
4506 | (path, password
, anchor) :: rest
->
4507 state.ranchors
<- rest
;
4508 state.anchor <- anchor;
4509 opendoc path password
4512 | 0xff08 -> (* backspace *)
4513 let y = getnav ~
-1 in
4514 gotoy_and_clear_text y
4522 G.postRedisplay "dehighlight";
4524 | 47 | 63 -> (* / ? *)
4525 let ondone isforw
s =
4526 cbput state.hists
.pat
s;
4527 state.searchpattern
<- s;
4530 let s = String.create
1 in
4531 s.[0] <- Char.chr
key;
4532 enttext (s, "", Some
(onhist state.hists
.pat
),
4533 textentry, ondone (key = 47))
4535 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4536 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4537 setzoom (conf.zoom +. incr)
4539 | 43 | 0xffab -> (* + *)
4542 try int_of_string
s with exc
->
4543 state.text <- Printf.sprintf
"bad integer `%s': %s"
4544 s (Printexc.to_string exc
);
4550 state.text <- "page bias is now " ^ string_of_int
n;
4553 enttext ("page bias: ", "", None
, intentry, ondone)
4555 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4556 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4557 setzoom (max
0.01 (conf.zoom -. decr))
4559 | 45 | 0xffad -> (* - *)
4560 let ondone msg
= state.text <- msg
in
4562 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4563 optentry state.mode, ondone
4566 | 48 when ctrl -> (* ctrl-0 *)
4569 | 49 when ctrl -> (* 1 *)
4570 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4574 | 0xffc6 -> (* f9 *)
4577 | 57 when ctrl -> (* ctrl-9 *)
4580 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4581 when not
ctrl -> (* 0..9 *)
4584 try int_of_string
s with exc
->
4585 state.text <- Printf.sprintf
"bad integer `%s': %s"
4586 s (Printexc.to_string exc
);
4592 cbput state.hists
.pag
(string_of_int
n);
4593 gotopage1 (n + conf.pagebias
- 1) 0;
4596 let pageentry text key =
4597 match Char.unsafe_chr
key with
4598 | 'g'
-> TEdone
text
4599 | _ -> intentry text key
4601 let text = "x" in text.[0] <- Char.chr
key;
4602 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4605 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4606 reshape conf.winw
conf.winh
;
4609 conf.hlinks
<- not
conf.hlinks
;
4610 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4611 G.postRedisplay "toggle highlightlinks";
4614 state.glinks
<- true;
4617 try int_of_string
s with exc
->
4618 state.text <- Printf.sprintf
"bad integer `%s': %s"
4619 s (Printexc.to_string exc
);
4624 let rec loop n = function
4627 match getopaque l.pageno with
4628 | None
-> loop n rest
4630 let m = getlinkcount opaque
in
4633 let under = getlink opaque
n in
4637 else loop (n-m) rest
4639 loop n state.layout;
4642 let onkey text key =
4643 match Char.unsafe_chr
key with
4644 | 'g'
-> TEdone
text
4645 | _ -> intentry text key
4647 let mode = state.mode in
4648 state.mode <- Textentry
(
4649 (":", "", Some
(onhist state.hists
.pag
), onkey, ondone),
4651 state.glinks
<- false;
4655 G.postRedisplay "view:enttext"
4658 begin match state.autoscroll
with
4660 conf.autoscrollstep
<- step
;
4661 state.autoscroll
<- None
4663 if conf.autoscrollstep
= 0
4664 then state.autoscroll
<- Some
1
4665 else state.autoscroll
<- Some
conf.autoscrollstep
4668 | 112 when ctrl -> (* ctrl-p *)
4672 conf.presentation <- not
conf.presentation;
4673 if conf.presentation
4675 if not
conf.scrollbarinpm
4676 then state.scrollw
<- 0;
4679 state.scrollw
<- conf.scrollbw
;
4681 showtext ' '
("presentation mode " ^
4682 if conf.presentation then "on" else "off");
4683 state.anchor <- getanchor ();
4687 begin match state.fullscreen
with
4689 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4692 state.fullscreen
<- None
;
4697 gotoy_and_clear_text 0
4700 gotopage1 (state.pagecount
- 1) 0
4702 | 112 | 78 -> (* p|N *)
4703 search state.searchpattern
false
4705 | 110 | 0xffc0 -> (* n|F3 *)
4706 search state.searchpattern
true
4709 begin match state.layout with
4712 gotoy_and_clear_text (getpagey l.pageno)
4716 begin match List.rev
state.layout with
4719 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4720 gotoy_and_clear_text (getpagey pageno)
4723 | 0xff9f | 0xffff -> (* delete *)
4724 begin match state.layout with
4727 let pageno = max
0 (l.pageno-1) in
4728 gotoy_and_clear_text (getpagey pageno)
4732 showtext ' '
(describe_location ());
4735 begin match state.layout with
4738 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4743 enterbookmarkmode ()
4745 | 104 | 0xffbe -> (* h|F1 *)
4751 | 101 when conf.redirectstderr -> (* e *)
4756 match state.layout with
4759 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4763 enttext ("bookmark: ", "", None
, textentry, ondone)
4767 showtext ' '
"Quick bookmark added";
4770 begin match state.layout with
4772 let rect = getpdimrect
l.pagedimno
in
4776 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4777 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4779 (truncate
(rect.(1) -. rect.(0)),
4780 truncate
(rect.(3) -. rect.(0)))
4782 let w = truncate
((float w)*.conf.zoom)
4783 and h = truncate
((float h)*.conf.zoom) in
4786 state.anchor <- getanchor ();
4787 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4789 G.postRedisplay "z";
4794 | 50 when ctrl -> (* ctrl-2 *)
4795 let maxw = getmaxw
() in
4797 then setzoom (maxw /. float conf.winw
)
4799 | 60 | 62 -> (* < > *)
4800 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4802 | 91 | 93 -> (* [ ] *)
4804 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4806 G.postRedisplay "brightness";
4808 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4809 setzoom state.prevzoom
4811 | 107 | 0xff52 -> (* k up *)
4812 begin match state.autoscroll
with
4814 begin match state.mode with
4815 | Birdseye beye
-> upbirdseye 1 beye
4818 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4819 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4822 setautoscrollspeed n false
4825 | 106 | 0xff54 -> (* j down *)
4826 begin match state.autoscroll
with
4828 begin match state.mode with
4829 | Birdseye beye
-> downbirdseye 1 beye
4832 then gotoy_and_clear_text (clamp (conf.winh
/2))
4833 else gotoy_and_clear_text (clamp conf.scrollstep
)
4836 setautoscrollspeed n true
4839 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4847 let dx = if key = 0xff51 then dx else -dx in
4848 state.x <- state.x + dx;
4849 gotoy_and_clear_text state.y
4852 G.postRedisplay "lef/right"
4855 | 0xff55 -> (* prior *)
4859 match state.layout with
4861 | l :: _ -> state.y - l.pagey
4867 | 0xff56 -> (* next *)
4871 match List.rev
state.layout with
4873 | l :: _ -> getpagey l.pageno
4879 | 0xff50 -> gotoghyll 0
4880 | 0xff57 -> gotoghyll (clamp state.maxy)
4881 | 0xff53 when Wsi.withalt mask
->
4882 gotoghyll (getnav ~
-1)
4883 | 0xff51 when Wsi.withalt mask
->
4884 gotoghyll (getnav 1)
4887 state.anchor <- getanchor ();
4888 opendoc state.path state.password
4890 | 118 when conf.debug
-> (* v *)
4893 match getopaque l.pageno with
4896 let x0, y0, x1, y1 = pagebbox opaque
in
4897 let a,b = float x0, float y0 in
4898 let c,d = float x1, float y0 in
4899 let e,f = float x1, float y1 in
4900 let h,j
= float x0, float y1 in
4901 let rect = (a,b,c,d,e,f,h,j
) in
4903 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4905 G.postRedisplay "v";
4908 vlog "huh? %s" (Wsi.keyname
key)
4911 let linknavkeyboard key mask
linknav =
4912 let getpage pageno =
4913 let rec loop = function
4915 | l :: _ when l.pageno = pageno -> Some
l
4916 | _ :: rest
-> loop rest
4917 in loop state.layout
4919 let doexact (pageno, n) =
4920 match getopaque pageno, getpage pageno with
4921 | Some opaque
, Some
l ->
4924 let under = getlink opaque
n in
4925 G.postRedisplay "link gotounder";
4931 | 0xff50 -> (* home *)
4932 Some
(findlink opaque LDfirst
), -1
4934 | 0xff57 -> (* end *)
4935 Some
(findlink opaque LDlast
), 1
4937 | 0xff51 -> (* left *)
4938 Some
(findlink opaque
(LDleft
n)), -1
4940 | 0xff53 -> (* right *)
4941 Some
(findlink opaque
(LDright
n)), 1
4943 | 0xff52 -> (* up *)
4944 Some
(findlink opaque
(LDup
n)), -1
4946 | 0xff54 -> (* down *)
4947 Some
(findlink opaque
(LDdown
n)), 1
4952 begin match findpwl
l.pageno dir with
4956 state.mode <- LinkNav
(Ltgendir
dir);
4957 let y, h = getpageyh pageno in
4960 then y + h - conf.winh
4965 begin match getopaque pageno, getpage pageno with
4966 | Some opaque
, Some
_ ->
4968 let ld = if dir > 0 then LDfirst
else LDlast
in
4971 begin match link with
4973 showlinktype (getlink opaque
m);
4974 state.mode <- LinkNav
(Ltexact
(pageno, m));
4975 G.postRedisplay "linknav jpage";
4982 begin match opt with
4983 | Some Lnotfound
-> pwl l dir;
4984 | Some
(Lfound
m) ->
4988 let _, y0, _, y1 = getlinkrect opaque
m in
4990 then gotopage1 l.pageno y0
4992 let d = fstate.fontsize
+ 1 in
4993 if y1 - l.pagey > l.pagevh - d
4994 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
4995 else G.postRedisplay "linknav";
4997 showlinktype (getlink opaque
m);
4998 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5001 | None
-> viewkeyboard key mask
5003 | _ -> viewkeyboard key mask
5008 G.postRedisplay "leave linknav"
5012 | Ltgendir
_ -> viewkeyboard key mask
5013 | Ltexact exact
-> doexact exact
5016 let keyboard key mask
=
5017 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5018 then wcmd "interrupt"
5019 else state.uioh <- state.uioh#
key key mask
5022 let birdseyekeyboard key mask
5023 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5025 match conf.columns
with
5027 | Cmulti
((c, _, _), _) -> c
5028 | Csplit
_ -> failwith
"bird's eye split mode"
5031 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5032 let y, h = getpageyh pageno in
5033 let top = (conf.winh
- h) / 2 in
5034 gotoy (max
0 (y - top))
5035 | 0xff0d -> leavebirdseye beye
false
5036 | 0xff1b -> leavebirdseye beye
true (* escape *)
5037 | 0xff52 -> upbirdseye incr beye
(* prior *)
5038 | 0xff54 -> downbirdseye incr beye
(* next *)
5039 | 0xff51 -> upbirdseye 1 beye
(* up *)
5040 | 0xff53 -> downbirdseye 1 beye
(* down *)
5043 begin match state.layout with
5047 state.mode <- Birdseye
(
5048 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5050 gotopage1 l.pageno 0;
5053 let layout = layout (state.y-conf.winh
) conf.winh
in
5055 | [] -> gotoy (clamp (-conf.winh
))
5057 state.mode <- Birdseye
(
5058 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5060 gotopage1 l.pageno 0
5063 | [] -> gotoy (clamp (-conf.winh
))
5067 begin match List.rev
state.layout with
5069 let layout = layout (state.y + conf.winh
) conf.winh
in
5070 begin match layout with
5072 let incr = l.pageh
- l.pagevh in
5077 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5079 G.postRedisplay "birdseye pagedown";
5081 else gotoy (clamp (incr + conf.interpagespace*2));
5085 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5086 gotopage1 l.pageno 0;
5089 | [] -> gotoy (clamp conf.winh
)
5093 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5097 let pageno = state.pagecount
- 1 in
5098 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5099 if not
(pagevisible state.layout pageno)
5102 match List.rev
state.pdims
with
5104 | (_, _, h, _) :: _ -> h
5106 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5107 else G.postRedisplay "birdseye end";
5108 | _ -> viewkeyboard key mask
5111 let drawpage l linkindexbase
=
5113 match state.mode with
5114 | Textentry
_ -> scalecolor 0.4
5116 | View
-> scalecolor 1.0
5117 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5118 if l.pageno = hooverpageno
5121 if l.pageno = pageno
5127 begin match getopaque l.pageno with
5129 if tileready l l.pagex l.pagey
5131 let x = l.pagedispx - l.pagex
5132 and y = l.pagedispy - l.pagey in
5133 let hlmask = (if conf.hlinks
then 1 else 0)
5134 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5136 postprocess opaque
hlmask x y linkindexbase
;
5143 let scrollindicator () =
5144 let sbw, ph
, sh = state.uioh#
scrollph in
5145 let sbh, pw, sw = state.uioh#scrollpw
in
5147 GlDraw.color (0.64, 0.64, 0.64);
5149 (float (conf.winw
- sbw), 0.)
5150 (float conf.winw
, float conf.winh
)
5153 (0., float (conf.winh
- sbh))
5154 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5156 GlDraw.color (0.0, 0.0, 0.0);
5159 (float (conf.winw
- sbw), ph
)
5160 (float conf.winw
, ph
+. sh)
5163 (pw, float (conf.winh
- sbh))
5164 (pw +. sw, float conf.winh
)
5169 match state.mstate
with
5170 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5173 | Msel
((x0, y0), (x1, y1)) ->
5174 let rec loop = function
5176 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5177 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5178 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5179 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5181 match getopaque l.pageno with
5183 let x0, y0 = pagetranslatepoint l x0 y0 in
5184 let x1, y1 = pagetranslatepoint l x1 y1 in
5185 seltext opaque
(x0, y0, x1, y1);
5193 let showrects rects
=
5195 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5196 GlDraw.polygon_mode `both `fill
;
5197 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5199 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5201 if l.pageno = pageno
5203 let dx = float (l.pagedispx - l.pagex) in
5204 let dy = float (l.pagedispy - l.pagey) in
5205 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5206 GlDraw.begins `quads
;
5208 GlDraw.vertex2
(x0+.dx, y0+.dy);
5209 GlDraw.vertex2
(x1+.dx, y1+.dy);
5210 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5211 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5222 GlClear.color (scalecolor2 conf.bgcolor
);
5223 GlClear.clear
[`
color];
5224 let rec loop linkindexbase
= function
5226 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5227 loop linkindexbase rest
5230 loop 0 state.layout;
5232 match state.mode with
5233 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5234 begin match getopaque pageno with
5236 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5243 | None
-> state.rects
5250 begin match state.mstate
with
5251 | Mzoomrect
((x0, y0), (x1, y1)) ->
5253 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5254 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5255 GlDraw.rect (float x0, float y0)
5256 (float x1, float y1);
5265 let zoomrect x y x1 y1 =
5268 and y0 = min
y y1 in
5269 gotoy (state.y + y0);
5270 state.anchor <- getanchor ();
5271 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5273 if state.w < conf.winw
- state.scrollw
5274 then (conf.winw
- state.scrollw
- state.w) / 2
5277 state.x <- (state.x + margin) - x0;
5279 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5280 state.mstate
<- Mnone
;
5284 let winw = conf.winw - state.scrollw
- 1 in
5285 let s = float x /. float winw in
5286 let destx = truncate
(float (state.w + winw) *. s) in
5287 state.x <- winw - destx;
5288 gotoy_and_clear_text state.y;
5289 state.mstate
<- Mscrollx
;
5293 let s = float y /. float conf.winh
in
5294 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5295 gotoy_and_clear_text desty;
5296 state.mstate
<- Mscrolly
;
5299 let viewmouse button down
x y mask
=
5301 | n when (n == 4 || n == 5) && not down
->
5302 if Wsi.withctrl mask
5304 match state.mstate
with
5305 | Mzoom
(oldn
, i
) ->
5313 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5315 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5317 let zoom = conf.zoom -. incr in
5319 state.mstate
<- Mzoom
(n, 0);
5321 state.mstate
<- Mzoom
(n, i
+1);
5323 else state.mstate
<- Mzoom
(n, 0)
5325 | _ -> state.mstate
<- Mzoom
(n, 0)
5328 match state.autoscroll
with
5329 | Some step
-> setautoscrollspeed step
(n=4)
5333 then -conf.scrollstep
5334 else conf.scrollstep
5336 let incr = incr * 2 in
5337 let y = clamp incr in
5338 gotoy_and_clear_text y
5341 | 1 when Wsi.withctrl mask
->
5344 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5345 state.mstate
<- Mpan
(x, y)
5348 state.mstate
<- Mnone
5353 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5355 state.mstate
<- Mzoomrect
(p, p)
5358 match state.mstate
with
5359 | Mzoomrect
((x0, y0), _) ->
5360 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5361 then zoomrect x0 y0 x y
5363 state.mstate
<- Mnone
;
5364 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5365 G.postRedisplay "kill accidental zoom rect";
5368 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5369 state.mstate
<- Mnone
5372 | 1 when x > conf.winw - state.scrollw
->
5375 let _, position, sh = state.uioh#
scrollph in
5376 if y > truncate
position && y < truncate
(position +. sh)
5377 then state.mstate
<- Mscrolly
5380 state.mstate
<- Mnone
5382 | 1 when y > conf.winh
- state.hscrollh ->
5385 let _, position, sw = state.uioh#scrollpw
in
5386 if x > truncate
position && x < truncate
(position +. sw)
5387 then state.mstate
<- Mscrollx
5390 state.mstate
<- Mnone
5393 let dest = if down
then getunder x y else Unone
in
5394 begin match dest with
5398 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5401 | Unone
when down
->
5402 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5403 state.mstate
<- Mpan
(x, y);
5405 | Unone
| Utext
_ ->
5408 if conf.angle
mod 360 = 0
5410 state.mstate
<- Msel
((x, y), (x, y));
5411 G.postRedisplay "mouse select";
5415 match state.mstate
with
5418 | Mzoom
_ | Mscrollx
| Mscrolly
->
5419 state.mstate
<- Mnone
5421 | Mzoomrect
((x0, y0), _) ->
5425 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5426 state.mstate
<- Mnone
5428 | Msel
((_, y0), (_, y1)) ->
5429 let rec loop = function
5432 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5433 || ((y1 >= l.pagedispy
5434 && y1 <= (l.pagedispy + l.pagevh)))
5436 match getopaque l.pageno with
5438 copysel
conf.selcmd opaque
;
5439 G.postRedisplay "copysel"
5444 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5445 state.mstate
<- Mnone
;
5452 let birdseyemouse button down
x y mask
5453 (conf, leftx
, _, hooverpageno
, anchor) =
5456 let rec loop = function
5459 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5460 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5462 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5468 | _ -> viewmouse button down
x y mask
5471 let mouse button down
x y mask
=
5472 state.uioh <- state.uioh#button button down
x y mask
;
5476 state.uioh <- state.uioh#
motion x y
5480 state.uioh <- state.uioh#
pmotion x y;
5486 method key key mask
=
5487 begin match state.mode with
5488 | Textentry
textentry -> textentrykeyboard key mask
textentry
5489 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5490 | View
-> viewkeyboard key mask
5491 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5495 method button button bstate
x y mask
=
5496 begin match state.mode with
5498 | View
-> viewmouse button bstate
x y mask
5499 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5505 begin match state.mode with
5507 | View
| Birdseye
_ | LinkNav
_ ->
5508 match state.mstate
with
5509 | Mzoom
_ | Mnone
-> ()
5514 state.mstate
<- Mpan
(x, y);
5516 then state.x <- state.x + dx;
5518 gotoy_and_clear_text y
5521 state.mstate
<- Msel
(a, (x, y));
5522 G.postRedisplay "motion select";
5525 let y = min
conf.winh
(max
0 y) in
5529 let x = min
conf.winw (max
0 x) in
5532 | Mzoomrect
(p0
, _) ->
5533 state.mstate
<- Mzoomrect
(p0
, (x, y));
5534 G.postRedisplay "motion zoomrect";
5538 method pmotion x y =
5539 begin match state.mode with
5540 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5541 let rec loop = function
5543 if hooverpageno
!= -1
5545 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5546 G.postRedisplay "pmotion birdseye no hoover";
5549 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5550 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5552 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5553 G.postRedisplay "pmotion birdseye hoover";
5563 match state.mstate
with
5564 | Mnone
-> updateunder x y
5565 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5570 method infochanged
_ = ()
5573 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5574 let p, h = scrollph state.y maxy in
5578 let winw = conf.winw - state.scrollw
- 1 in
5579 let fwinw = float winw in
5581 let sw = fwinw /. float state.w in
5582 let sw = fwinw *. sw in
5583 max
sw (float conf.scrollh
)
5586 let f = state.w+winw in
5587 let r = float (winw-state.x) /. float f in
5588 let p = fwinw *. r in
5592 if position +. sw > fwinw
5593 then fwinw -. position
5596 state.hscrollh, position, sw
5600 match state.mode with
5601 | LinkNav
_ -> "links"
5602 | Textentry
_ -> "textentry"
5603 | Birdseye
_ -> "birdseye"
5606 findkeyhash conf modename
5613 let fontpath = ref "";;
5616 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5619 let l = String.length
s in
5620 let b = Buffer.create
l in
5626 try Sys.getenv
"HOME"
5629 ("Can not determine home directory location: " ^
5630 Printexc.to_string exn
);
5634 let modifier_of_string = function
5635 | "alt" -> Wsi.altmask
5636 | "shift" -> Wsi.shiftmask
5637 | "ctrl" | "control" -> Wsi.ctrlmask
5638 | "meta" -> Wsi.metamask
5643 let r = Str.regexp
"-" in
5645 let elems = Str.full_split
r s in
5648 let m1 = modifier_of_string s in
5650 then (Wsi.namekey
s, m)
5653 | Str.Delim
s when n land 1 = 0 -> g s
5655 | Str.Delim
_ -> (k
, m)
5657 let rec loop n k
m = function
5660 let k, m = f n k m x in
5666 let keys_of_string =
5667 let r = Str.regexp
"[ \t]" in
5669 let elems = Str.split
r s in
5670 List.map
key_of_string elems
5673 let copykeyhashes c =
5674 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5677 let config_of c attrs
=
5681 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5682 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5683 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5684 | "preload" -> { c with preload = bool_of_string
v }
5685 | "page-bias" -> { c with pagebias
= int_of_string
v }
5686 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5687 | "auto-scroll-step" ->
5688 { c with autoscrollstep
= max
0 (int_of_string
v) }
5689 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5690 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5693 match String.lowercase
v with
5694 | "true" -> Some infinity
5696 | f -> Some
(float_of_string
f)
5698 { c with maxwait
= mw}
5699 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5700 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5701 | "vertical-margin" ->
5702 { c with interpagespace = max
0 (int_of_string
v) }
5704 let zoom = float_of_string
v /. 100. in
5705 let zoom = max
zoom 0.0 in
5706 { c with zoom = zoom }
5707 | "presentation" -> { c with presentation = bool_of_string
v }
5708 | "rotation-angle" -> { c with angle
= int_of_string
v }
5709 | "width" -> { c with winw = max
20 (int_of_string
v) }
5710 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5711 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5712 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5713 | "pixmap-cache-size" ->
5714 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5715 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5716 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5717 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5718 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5719 | "background-color" -> { c with bgcolor
= color_of_string v }
5720 | "scrollbar-in-presentation" ->
5721 { c with scrollbarinpm
= bool_of_string
v }
5722 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5723 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5724 | "mupdf-store-size" ->
5725 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5726 | "checkers" -> { c with checkers
= bool_of_string
v }
5727 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5728 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5729 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5730 | "uri-launcher" -> { c with urilauncher
= unent v }
5731 | "path-launcher" -> { c with pathlauncher
= unent v }
5732 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5733 | "invert-colors" -> { c with invert
= bool_of_string
v }
5734 | "brightness" -> { c with colorscale
= float_of_string
v }
5735 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5737 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5739 let (n, _, _) as nab
= multicolumns_of_string v in
5741 then { c with columns
= Csplit
(-n, [||]) }
5742 else { c with columns
= Cmulti
(nab
, [||]) }
5743 | "birds-eye-columns" ->
5744 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5745 | "selection-command" -> { c with selcmd
= unent v }
5746 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5749 prerr_endline
("Error processing attribute (`" ^
5750 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5753 let rec fold c = function
5756 let c = apply c k v in
5759 fold { c with keyhashes
= copykeyhashes c } attrs
;
5762 let fromstring f pos
n v d =
5765 dolog "Error processing attribute (%S=%S) at %d\n%s"
5766 n v pos
(Printexc.to_string exn
)
5771 let bookmark_of attrs
=
5772 let rec fold title page
rely = function
5773 | ("title", v) :: rest
-> fold v page
rely rest
5774 | ("page", v) :: rest
-> fold title v rely rest
5775 | ("rely", v) :: rest
-> fold title page
v rest
5776 | _ :: rest
-> fold title page
rely rest
5777 | [] -> title, page
, rely
5779 fold "invalid" "0" "0" attrs
5783 let rec fold path page
rely pan
= function
5784 | ("path", v) :: rest
-> fold v page
rely pan rest
5785 | ("page", v) :: rest
-> fold path v rely pan rest
5786 | ("rely", v) :: rest
-> fold path page
v pan rest
5787 | ("pan", v) :: rest
-> fold path page
rely v rest
5788 | _ :: rest
-> fold path page
rely pan rest
5789 | [] -> path, page
, rely, pan
5791 fold "" "0" "0" "0" attrs
5795 let rec fold rs ls
= function
5796 | ("out", v) :: rest
-> fold v ls rest
5797 | ("in", v) :: rest
-> fold rs
v rest
5798 | _ :: rest
-> fold ls rs rest
5804 let setconf dst
src =
5805 dst
.scrollbw
<- src.scrollbw
;
5806 dst
.scrollh
<- src.scrollh
;
5807 dst
.icase
<- src.icase
;
5808 dst
.preload <- src.preload;
5809 dst
.pagebias
<- src.pagebias
;
5810 dst
.verbose
<- src.verbose
;
5811 dst
.scrollstep
<- src.scrollstep
;
5812 dst
.maxhfit
<- src.maxhfit
;
5813 dst
.crophack
<- src.crophack
;
5814 dst
.autoscrollstep
<- src.autoscrollstep
;
5815 dst
.maxwait
<- src.maxwait
;
5816 dst
.hlinks
<- src.hlinks
;
5817 dst
.underinfo
<- src.underinfo
;
5818 dst
.interpagespace <- src.interpagespace;
5819 dst
.zoom <- src.zoom;
5820 dst
.presentation <- src.presentation;
5821 dst
.angle
<- src.angle
;
5822 dst
.winw <- src.winw;
5823 dst
.winh
<- src.winh
;
5824 dst
.savebmarks
<- src.savebmarks
;
5825 dst
.memlimit
<- src.memlimit
;
5826 dst
.proportional
<- src.proportional
;
5827 dst
.texcount
<- src.texcount
;
5828 dst
.sliceheight
<- src.sliceheight
;
5829 dst
.thumbw
<- src.thumbw
;
5830 dst
.jumpback
<- src.jumpback
;
5831 dst
.bgcolor
<- src.bgcolor
;
5832 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5833 dst
.tilew
<- src.tilew
;
5834 dst
.tileh
<- src.tileh
;
5835 dst
.mustoresize
<- src.mustoresize
;
5836 dst
.checkers
<- src.checkers
;
5837 dst
.aalevel
<- src.aalevel
;
5838 dst
.trimmargins
<- src.trimmargins
;
5839 dst
.trimfuzz
<- src.trimfuzz
;
5840 dst
.urilauncher
<- src.urilauncher
;
5841 dst
.colorspace
<- src.colorspace
;
5842 dst
.invert
<- src.invert
;
5843 dst
.colorscale
<- src.colorscale
;
5844 dst
.redirectstderr <- src.redirectstderr;
5845 dst
.ghyllscroll
<- src.ghyllscroll
;
5846 dst
.columns
<- src.columns
;
5847 dst
.beyecolumns
<- src.beyecolumns
;
5848 dst
.selcmd
<- src.selcmd
;
5849 dst
.updatecurs
<- src.updatecurs
;
5850 dst
.pathlauncher
<- src.pathlauncher
;
5851 dst
.keyhashes
<- copykeyhashes src;
5855 let h = Hashtbl.create
10 in
5856 let dc = { defconf with angle
= defconf.angle
} in
5857 let rec toplevel v t spos
_ =
5859 | Vdata
| Vcdata
| Vend
-> v
5860 | Vopen
("llppconfig", _, closed
) ->
5863 else { v with f = llppconfig
}
5865 error
"unexpected subelement at top level" s spos
5866 | Vclose
_ -> error
"unexpected close at top level" s spos
5868 and llppconfig
v t spos
_ =
5870 | Vdata
| Vcdata
-> v
5871 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5872 | Vopen
("defaults", attrs
, closed
) ->
5873 let c = config_of dc attrs
in
5877 else { v with f = defaults
}
5879 | Vopen
("ui-font", attrs
, closed
) ->
5880 let rec getsize size
= function
5882 | ("size", v) :: rest
->
5884 fromstring int_of_string spos
"size" v fstate.fontsize
in
5886 | l -> getsize size l
5888 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5891 else { v with f = uifont
(Buffer.create
10) }
5893 | Vopen
("doc", attrs
, closed
) ->
5894 let pathent, spage
, srely
, span
= doc_of attrs
in
5895 let path = unent pathent
5896 and pageno = fromstring int_of_string spos
"page" spage
0
5897 and rely = fromstring float_of_string spos
"rely" srely
0.0
5898 and pan
= fromstring int_of_string spos
"pan" span
0 in
5899 let c = config_of dc attrs
in
5900 let anchor = (pageno, rely) in
5902 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5903 else { v with f = doc
path pan
anchor c [] }
5906 error
"unexpected subelement in llppconfig" s spos
5908 | Vclose
"llppconfig" -> { v with f = toplevel }
5909 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5911 and defaults
v t spos
_ =
5913 | Vdata
| Vcdata
-> v
5914 | Vend
-> error
"unexpected end of input in defaults" s spos
5915 | Vopen
("keymap", attrs
, closed
) ->
5917 try List.assoc
"mode" attrs
5918 with Not_found
-> "global" in
5923 let h = findkeyhash dc modename in
5924 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5927 { v with f = pkeymap
ret KeyMap.empty }
5929 | Vopen
(_, _, _) ->
5930 error
"unexpected subelement in defaults" s spos
5932 | Vclose
"defaults" ->
5933 { v with f = llppconfig
}
5935 | Vclose
_ -> error
"unexpected close in defaults" s spos
5937 and uifont
b v t spos
epos =
5940 Buffer.add_substring
b s spos
(epos - spos
);
5942 | Vopen
(_, _, _) ->
5943 error
"unexpected subelement in ui-font" s spos
5944 | Vclose
"ui-font" ->
5945 if String.length
!fontpath = 0
5946 then fontpath := Buffer.contents
b;
5947 { v with f = llppconfig
}
5948 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5949 | Vend
-> error
"unexpected end of input in ui-font" s spos
5951 and doc
path pan
anchor c bookmarks
v t spos
_ =
5953 | Vdata
| Vcdata
-> v
5954 | Vend
-> error
"unexpected end of input in doc" s spos
5955 | Vopen
("bookmarks", _, closed
) ->
5958 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5960 | Vopen
("keymap", attrs
, closed
) ->
5962 try List.assoc
"mode" attrs
5963 with Not_found
-> "global"
5969 let h = findkeyhash c modename in
5970 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5971 doc
path pan
anchor c bookmarks
5973 { v with f = pkeymap
ret KeyMap.empty }
5975 | Vopen
(_, _, _) ->
5976 error
"unexpected subelement in doc" s spos
5979 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5980 { v with f = llppconfig
}
5982 | Vclose
_ -> error
"unexpected close in doc" s spos
5984 and pkeymap
ret keymap
v t spos
_ =
5986 | Vdata
| Vcdata
-> v
5987 | Vend
-> error
"unexpected end of input in keymap" s spos
5988 | Vopen
("map", attrs
, closed
) ->
5989 let r, l = map_of attrs
in
5990 let kss = fromstring keys_of_string spos
"in" r [] in
5991 let lss = fromstring keys_of_string spos
"out" l [] in
5995 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
5996 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
5999 then { v with f = pkeymap
ret keymap }
6002 { v with f = skip
"map" f }
6005 error
"unexpected subelement in keymap" s spos
6007 | Vclose
"keymap" ->
6008 { v with f = ret keymap }
6010 | Vclose
_ -> error
"unexpected close in keymap" s spos
6012 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6014 | Vdata
| Vcdata
-> v
6015 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6016 | Vopen
("item", attrs
, closed
) ->
6017 let titleent, spage
, srely
= bookmark_of attrs
in
6018 let page = fromstring int_of_string spos
"page" spage
0
6019 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6020 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6022 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6025 { v with f = skip
"item" f }
6028 error
"unexpected subelement in bookmarks" s spos
6030 | Vclose
"bookmarks" ->
6031 { v with f = doc
path pan
anchor c bookmarks }
6033 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6035 and skip tag
f v t spos
_ =
6037 | Vdata
| Vcdata
-> v
6039 error
("unexpected end of input in skipped " ^ tag
) s spos
6040 | Vopen
(tag'
, _, closed
) ->
6044 let f'
() = { v with f = skip tag
f } in
6045 { v with f = skip tag'
f'
}
6049 else error
("unexpected close in skipped " ^ tag
) s spos
6052 parse
{ f = toplevel; accu = () } s;
6058 let len = in_channel_length ic
in
6059 let s = String.create
len in
6060 really_input ic
s 0 len;
6063 | Parse_error
(msg
, s, pos
) ->
6064 let subs = subs s pos
in
6065 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6066 failwith
("parse error: " ^
s)
6069 failwith
("config load error: " ^
Printexc.to_string exn
)
6075 let dir = Filename.concat
home ".config" in
6076 if Sys.is_directory
dir then dir else home
6079 Filename.concat
dir "llpp.conf"
6082 let confpath = ref defconfpath;;
6085 if Sys.file_exists
!confpath
6088 (try Some
(open_in_bin
!confpath)
6091 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6092 Printexc.to_string exn
);
6101 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6102 Printexc.to_string exn
);
6108 f (Hashtbl.create
0, defconf)
6113 let pc, pb
, px, pa
=
6115 Hashtbl.find h (Filename.basename
state.path)
6116 with Not_found
-> dc, [], 0, (0, 0.0)
6120 state.bookmarks <- pb
;
6122 state.scrollw
<- conf.scrollbw
;
6124 then state.anchor <- pa
;
6125 cbput state.hists
.nav pa
;
6130 let add_attrs bb always
dc c =
6133 then Printf.bprintf bb
"\n %s='%b'" s a
6136 then Printf.bprintf bb
"\n %s='%d'" s a
6139 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6142 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6145 then Printf.bprintf bb
"\n %s='%f'" s a
6149 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6153 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6157 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6161 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6167 | Some
(_N
, _A
, _B
) ->
6168 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6178 else string_of_float
f
6180 Printf.bprintf bb
"\n %s='%s'" s v
6185 | Cmulti
((n, a, b), _) when n > 1 ->
6186 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6187 | Csplit
(n, _) when n > 1 ->
6188 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6194 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6199 then dc.winw, dc.winh
6201 match state.fullscreen
with
6203 | None
-> c.winw, c.winh
6205 let zoom, presentation, interpagespace, maxwait
=
6207 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6209 match state.mode with
6210 | Birdseye
(bc
, _, _, _, _) ->
6211 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6212 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6214 oi
"width" w dc.winw;
6215 oi
"height" h dc.winh
;
6216 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6217 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6218 ob "case-insensitive-search" c.icase
dc.icase
;
6219 ob "preload" c.preload dc.preload;
6220 oi
"page-bias" c.pagebias
dc.pagebias
;
6221 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6222 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6223 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6224 ob "crop-hack" c.crophack
dc.crophack
;
6225 oW
"throttle" maxwait
dc.maxwait
;
6226 ob "highlight-links" c.hlinks
dc.hlinks
;
6227 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6228 oi
"vertical-margin" interpagespace dc.interpagespace;
6229 oz
"zoom" zoom dc.zoom;
6230 ob "presentation" presentation dc.presentation;
6231 oi
"rotation-angle" c.angle
dc.angle
;
6232 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6233 ob "proportional-display" c.proportional
dc.proportional
;
6234 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6235 oi
"tex-count" c.texcount
dc.texcount
;
6236 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6237 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6238 ob "persistent-location" c.jumpback
dc.jumpback
;
6239 oc
"background-color" c.bgcolor
dc.bgcolor
;
6240 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6241 oi
"tile-width" c.tilew
dc.tilew
;
6242 oi
"tile-height" c.tileh
dc.tileh
;
6243 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6244 ob "checkers" c.checkers
dc.checkers
;
6245 oi
"aalevel" c.aalevel
dc.aalevel
;
6246 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6247 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6248 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6249 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6250 oC
"color-space" c.colorspace
dc.colorspace
;
6251 ob "invert-colors" c.invert
dc.invert
;
6252 oF
"brightness" c.colorscale
dc.colorscale
;
6253 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6254 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6255 oco
"columns" c.columns
dc.columns
;
6256 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6257 os
"selection-command" c.selcmd
dc.selcmd
;
6258 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6261 let keymapsbuf always
dc c =
6262 let bb = Buffer.create
16 in
6263 let rec loop = function
6265 | (modename, h) :: rest
->
6266 let dh = findkeyhash dc modename in
6267 if always
|| h <> dh
6269 if Hashtbl.length
h > 0
6271 if Buffer.length
bb > 0
6272 then Buffer.add_char
bb '
\n'
;
6273 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6274 Hashtbl.iter
(fun i
o ->
6275 let isdifferent = always
||
6277 let dO = Hashtbl.find dh i
in
6279 with Not_found
-> true
6284 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6285 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6286 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6287 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6288 Buffer.add_string
bb (Wsi.keyname
k);
6291 let rec loop = function
6293 | km
:: [] -> addkm km
6294 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6298 Buffer.add_string
bb "<map in='";
6302 Buffer.add_string
bb "' out='";
6304 Buffer.add_string
bb "'/>\n"
6307 Buffer.add_string
bb "' out='";
6309 Buffer.add_string
bb "'/>\n"
6311 | KMmulti
(ins, kms
) ->
6312 Buffer.add_char
bb ' '
;
6314 Buffer.add_string
bb "' out='";
6316 Buffer.add_string
bb "'/>\n"
6318 Buffer.add_string
bb "</keymap>";
6328 let uifontsize = fstate.fontsize
in
6329 let bb = Buffer.create
32768 in
6331 let dc = if conf.bedefault
then conf else dc in
6332 Buffer.add_string
bb "<llppconfig>\n";
6334 if String.length
!fontpath > 0
6336 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6342 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6345 Buffer.add_string
bb "<defaults ";
6346 add_attrs bb true dc dc;
6347 let kb = keymapsbuf true dc dc in
6348 if Buffer.length
kb > 0
6350 Buffer.add_string
bb ">\n";
6351 Buffer.add_buffer
bb kb;
6352 Buffer.add_string
bb "\n</defaults>\n";
6354 else Buffer.add_string
bb "/>\n";
6356 let adddoc path pan
anchor c bookmarks =
6357 if bookmarks == [] && c = dc && anchor = emptyanchor
6360 Printf.bprintf
bb "<doc path='%s'"
6361 (enent
path 0 (String.length
path));
6363 if anchor <> emptyanchor
6365 let n, y = anchor in
6366 Printf.bprintf
bb " page='%d'" n;
6369 Printf.bprintf
bb " rely='%f'" y
6374 then Printf.bprintf
bb " pan='%d'" pan
;
6376 add_attrs bb false dc c;
6377 let kb = keymapsbuf false dc c in
6379 begin match bookmarks with
6381 if Buffer.length
kb > 0
6383 Buffer.add_string
bb ">\n";
6384 Buffer.add_buffer
bb kb;
6385 Buffer.add_string
bb "</doc>\n";
6387 else Buffer.add_string
bb "/>\n"
6389 Buffer.add_string
bb ">\n<bookmarks>\n";
6390 List.iter
(fun (title, _level
, (page, rely)) ->
6392 "<item title='%s' page='%d'"
6393 (enent
title 0 (String.length
title))
6398 Printf.bprintf
bb " rely='%f'" rely
6400 Buffer.add_string
bb "/>\n";
6402 Buffer.add_string
bb "</bookmarks>";
6403 if Buffer.length
kb > 0
6405 Buffer.add_string
bb "\n";
6406 Buffer.add_buffer
bb kb;
6408 Buffer.add_string
bb "\n</doc>\n";
6414 match state.mode with
6415 | Birdseye
(c, pan, _, _, _) ->
6417 match conf.columns
with
6418 | Cmulti
((c, _, _), _) -> Some
c
6422 match c.columns
with
6423 | Cmulti
(c, _) -> Cmulti
(c, [||])
6424 | Csingle
-> Csingle
6425 | Csplit
_ -> failwith
"quit from bird's eye while split"
6427 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6428 | _ -> state.x, conf
6430 let basename = Filename.basename state.path in
6431 adddoc basename pan (getanchor ())
6434 match state.autoscroll
with
6436 | None
-> conf.autoscrollstep
}
6437 (if conf.savebmarks
then state.bookmarks else []);
6439 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6441 then adddoc path x y c bookmarks
6443 Buffer.add_string
bb "</llppconfig>";
6446 if Buffer.length
bb > 0
6449 let tmp = !confpath ^
".tmp" in
6450 let oc = open_out_bin
tmp in
6451 Buffer.output_buffer
oc bb;
6453 Unix.rename
tmp !confpath;
6456 ("error while saving configuration: " ^
Printexc.to_string exn
)
6463 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6464 "<password> Set password");
6466 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6467 "<path> Set path to the user interface font");
6469 ("-c", Arg.String
(fun s -> Config.confpath := s),
6470 "<path> Set path to the configuration file");
6472 ("-v", Arg.Unit
(fun () ->
6474 "%s\nconfiguration path: %s\n"
6478 exit
0), " Print version and exit");
6481 (fun s -> state.path <- s)
6482 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6484 if String.length
state.path = 0
6485 then (prerr_endline
"file name missing"; exit
1);
6489 let globalkeyhash = findkeyhash conf "global" in
6490 let wsfd, winw, winh
= Wsi.init
(object
6492 if nogeomcmds state.geomcmds
6494 method display = display ()
6495 method reshape w h = reshape w h
6496 method mouse b d x y m = mouse b d x y m
6497 method motion x y = state.mpos
<- (x, y); motion x y
6498 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6500 let mascm = m land (
6501 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6503 match state.keystate
with
6505 let km = k, mascm in
6508 try Hashtbl.find globalkeyhash km
6510 let modehash = state.uioh#
modehash in
6511 try Hashtbl.find modehash km
6512 with Not_found
-> KMinsrt
(k, m)
6514 | KMinsrt
(k, m) -> keyboard k m
6515 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6516 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6518 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6519 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6520 state.keystate
<- KSnone
6521 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6522 state.keystate
<- KSinto
(keys
, insrt
)
6524 state.keystate
<- KSnone
6526 method enter
x y = state.mpos
<- (x, y); pmotion x y
6527 method leave = state.mpos
<- (-1, -1)
6528 method quit
= raise Quit
6529 end) conf.winw conf.winh
(platform = Posx
) in
6534 List.exists
GlMisc.check_extension
6535 [ "GL_ARB_texture_rectangle"
6536 ; "GL_EXT_texture_recangle"
6537 ; "GL_NV_texture_rectangle" ]
6539 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6541 let cr, sw = Unix.pipe
()
6542 and sr
, cw = Unix.pipe
() in
6549 setcheckers conf.checkers
;
6553 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6554 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6559 state.text <- "Opening " ^
state.path;
6561 opendoc state.path state.password
;
6564 let rec loop deadline
=
6566 match state.errfd
with
6567 | None
-> [state.sr
; state.wsfd]
6568 | Some fd
-> [state.sr
; state.wsfd; fd
]
6572 state.redisplay
<- false;
6579 if deadline
= infinity
6581 else max
0.0 (deadline
-. now)
6586 try Unix.select
r [] [] timeout
6587 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6593 if state.ghyll
== noghyll
6595 match state.autoscroll
with
6596 | Some step
when step
!= 0 ->
6597 let y = state.y + step
in
6601 else if y >= state.maxy then 0 else y
6604 if state.mode = View
6605 then state.text <- "";
6608 else deadline
+. 0.01
6613 let rec checkfds = function
6615 | fd
:: rest
when fd
= state.sr
->
6616 let cmd = readcmd state.sr
in
6620 | fd
:: rest
when fd
= state.wsfd ->
6625 let s = String.create
80 in
6626 let n = Unix.read fd
s 0 80 in
6627 if conf.redirectstderr
6629 Buffer.add_substring
state.errmsgs
s 0 n;
6630 state.newerrmsgs
<- true;
6631 state.redisplay
<- true;
6634 prerr_string
(String.sub
s 0 n);
6642 if deadline
= infinity
6646 match state.autoscroll
with
6647 | Some step
when step
!= 0 -> deadline1
6648 | _ -> if state.ghyll
== noghyll then infinity
else deadline1