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
* trimcachepath
29 and proportional
= bool
30 and trimmargins
= bool
31 and interpagespace
= int
38 and trimcachepath
= string
41 and irect
= (int * int * int * int)
42 and trimparams
= (trimmargins
* irect
)
43 and colorspace
= | Rgb
| Bgr
| Gray
53 | LDfirstvisible
of (int * int * int)
68 | KMmulti
of key list
* key list
70 and keyhash
= (key
, keymap
) Hashtbl.t
73 | KSinto
of (key list
* key list
)
76 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
77 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
79 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
81 external init
: pipe
-> params
-> unit = "ml_init";;
82 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
83 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
84 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
85 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
86 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
87 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
88 external measurestr
: int -> string -> float = "ml_measure_string";;
89 external getmaxw
: unit -> float = "ml_getmaxw";;
90 external postprocess
:
91 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
92 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
93 external platform
: unit -> platform
= "ml_platform";;
94 external setaalevel
: int -> unit = "ml_setaalevel";;
95 external realloctexts
: int -> bool = "ml_realloctexts";;
96 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
97 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
98 external getlink
: opaque
-> int -> under
= "ml_getlink";;
99 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
100 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
101 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
102 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
103 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
104 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
105 external freepbo
: string -> unit = "ml_freepbo";;
106 external unmappbo
: string -> unit = "ml_unmappbo";;
107 external pbousable
: unit -> bool = "ml_pbo_usable";;
109 let platform_to_string = function
110 | Punknown
-> "unknown"
114 | Pfreebsd
-> "FreeBSD"
115 | Pdragonflybsd
-> "DragonflyBSD"
116 | Popenbsd
-> "OpenBSD"
117 | Pnetbsd
-> "NetBSD"
118 | Pcygwin
-> "Cygwin"
121 let platform = platform ();;
124 if platform = Pcygwin
126 let sh = "/bin/sh" in
127 let args = [|sh; "-c"; cmd
|] in
128 let rec std si so se
= function
130 | (fd
, 0) :: rest
-> std fd so se rest
131 | (fd
, -1) :: rest
->
132 Unix.set_close_on_exec fd
;
135 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
137 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
138 ignore
(Unix.create_process
sh args si so se
)
147 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
150 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
152 type mpos
= int * int
154 | Msel
of (mpos
* mpos
)
156 | Mscrolly
| Mscrollx
157 | Mzoom
of (int * int)
158 | Mzoomrect
of (mpos
* mpos
)
162 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
163 and onkey
= string -> int -> te
164 and ondone
= string -> unit
165 and histcancel
= unit -> unit
166 and onhist
= ((histcmd
-> string) * histcancel
)
167 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
168 and cancelonempty
= bool
173 | TEswitch
of textentry
184 let bound v minv maxv
=
185 max minv
(min maxv v
);
189 { store
= Array.create n v
196 let cbcap b
= Array.length b
.store
;;
201 b
.wc
<- (b
.wc
+ 1) mod cap;
203 b
.len
<- min
(b
.len
+ 1) cap;
206 let cbempty b
= b
.len
= 0;;
208 let cbgetg b circular dir
=
212 let rc = b
.rc + dir
in
224 else bound rc 0 (b
.len
-1)
230 let cbget b
= cbgetg b
false;;
231 let cbgetc b
= cbgetg b
true;;
233 let drawstring size x y s
=
235 Gl.enable `texture_2d
;
236 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
237 ignore
(drawstr size x y s
);
239 Gl.disable `texture_2d
;
242 let drawstring1 size x y s
=
246 let drawstring2 size x y fmt
=
247 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
266 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
267 dolog " WxH %dx%d" l
.pagew l
.pageh
;
268 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
269 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
270 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
271 dolog " column %d" l
.pagecol
;
275 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
277 dolog " x0,y0=(% f, % f)" x0 y0
;
278 dolog " x1,y1=(% f, % f)" x1 y1
;
279 dolog " x2,y2=(% f, % f)" x2 y2
;
280 dolog " x3,y3=(% f, % f)" x3 y3
;
284 type multicolumns
= multicol
* pagegeom
285 and singlecolumn
= pagegeom
286 and splitcolumns
= columncount
* pagegeom
287 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
288 and multicol
= columncount
* covercount
* covercount
290 and columncount
= int
291 and covercount
= int;;
294 { mutable scrollbw
: int
295 ; mutable scrollh
: int
296 ; mutable icase
: bool
297 ; mutable preload
: bool
298 ; mutable pagebias
: int
299 ; mutable verbose
: bool
300 ; mutable debug
: bool
301 ; mutable scrollstep
: int
302 ; mutable hscrollstep
: int
303 ; mutable maxhfit
: bool
304 ; mutable crophack
: bool
305 ; mutable autoscrollstep
: int
306 ; mutable maxwait
: float option
307 ; mutable hlinks
: bool
308 ; mutable underinfo
: bool
309 ; mutable interpagespace
: interpagespace
310 ; mutable zoom
: float
311 ; mutable presentation
: bool
312 ; mutable angle
: angle
315 ; mutable savebmarks
: bool
316 ; mutable proportional
: proportional
317 ; mutable trimmargins
: trimmargins
318 ; mutable trimfuzz
: irect
319 ; mutable memlimit
: memsize
320 ; mutable texcount
: texcount
321 ; mutable sliceheight
: sliceheight
322 ; mutable thumbw
: width
323 ; mutable jumpback
: bool
324 ; mutable bgcolor
: float * float * float
325 ; mutable bedefault
: bool
326 ; mutable scrollbarinpm
: bool
327 ; mutable tilew
: int
328 ; mutable tileh
: int
329 ; mutable mustoresize
: memsize
330 ; mutable checkers
: bool
331 ; mutable aalevel
: int
332 ; mutable urilauncher
: string
333 ; mutable pathlauncher
: string
334 ; mutable colorspace
: colorspace
335 ; mutable invert
: bool
336 ; mutable colorscale
: float
337 ; mutable redirectstderr
: bool
338 ; mutable ghyllscroll
: (int * int * int) option
339 ; mutable columns
: columns
340 ; mutable beyecolumns
: columncount
option
341 ; mutable selcmd
: string
342 ; mutable updatecurs
: bool
343 ; mutable keyhashes
: (string * keyhash
) list
344 ; mutable hfsize
: int
345 ; mutable pgscale
: float
346 ; mutable usepbo
: bool
349 | Csingle
of singlecolumn
350 | Cmulti
of multicolumns
351 | Csplit
of splitcolumns
354 type anchor
= pageno
* top
* dtop
;;
356 type outline
= string * int * anchor
;;
358 type rect
= float * float * float * float * float * float * float * float;;
360 type tile
= opaque
* pixmapsize
* elapsed
361 and elapsed
= float;;
362 type pagemapkey
= pageno
* gen
;;
363 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
367 let emptyanchor = (0, 0.0, 0.0);;
369 type infochange
= | Memused
| Docinfo
| Pdim
;;
371 class type uioh
= object
372 method display
: unit
373 method key
: int -> int -> uioh
374 method button
: int -> bool -> int -> int -> int -> uioh
375 method motion
: int -> int -> uioh
376 method pmotion
: int -> int -> uioh
377 method infochanged
: infochange
-> unit
378 method scrollpw
: (int * float * float)
379 method scrollph
: (int * float * float)
380 method modehash
: keyhash
384 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
385 | Textentry
of (textentry
* onleave
)
387 | LinkNav
of linktarget
388 and onleave
= leavetextentrystatus
-> unit
389 and leavetextentrystatus
= | Cancel
| Confirm
390 and helpitem
= string * int * action
393 | Action
of (uioh
-> uioh
)
395 | Ltexact
of (pageno
* int)
399 let isbirdseye = function Birdseye _
-> true | _
-> false;;
400 let istextentry = function Textentry _
-> true | _
-> false;;
404 | Loading
of (page
* gen
)
406 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
408 | Outlining
of outline list
411 let emptykeyhash = Hashtbl.create
0;;
412 let nouioh : uioh
= object (self
)
414 method key _ _
= self
415 method button _ _ _ _ _
= self
416 method motion _ _
= self
417 method pmotion _ _
= self
418 method infochanged _
= ()
419 method scrollpw
= (0, nan
, nan
)
420 method scrollph
= (0, nan
, nan
)
421 method modehash
= emptykeyhash
425 { mutable sr
: Unix.file_descr
426 ; mutable sw
: Unix.file_descr
427 ; mutable wsfd
: Unix.file_descr
428 ; mutable errfd
: Unix.file_descr
option
429 ; mutable stderr
: Unix.file_descr
430 ; mutable errmsgs
: Buffer.t
431 ; mutable newerrmsgs
: bool
435 ; mutable scrollw
: int
436 ; mutable hscrollh
: int
437 ; mutable anchor
: anchor
438 ; mutable ranchors
: (string * string * anchor
) list
440 ; mutable layout
: page list
441 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
442 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
443 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
444 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
445 ; mutable pagecount
: int
446 ; mutable currently
: currently
447 ; mutable mstate
: mstate
448 ; mutable searchpattern
: string
449 ; mutable rects
: (pageno
* recttype
* rect
) list
450 ; mutable rects1
: (pageno
* recttype
* rect
) list
451 ; mutable text
: string
452 ; mutable fullscreen
: (width
* height
) option
453 ; mutable mode
: mode
454 ; mutable uioh
: uioh
455 ; mutable outlines
: outline array
456 ; mutable bookmarks
: outline list
457 ; mutable path
: string
458 ; mutable password
: string
459 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
460 ; mutable memused
: memsize
462 ; mutable throttle
: (page list
* int * float) option
463 ; mutable autoscroll
: int option
464 ; mutable ghyll
: (int option -> unit)
465 ; mutable help
: helpitem array
466 ; mutable docinfo
: (int * string) list
467 ; mutable texid
: GlTex.texture_id
option
469 ; mutable prevzoom
: float
470 ; mutable progress
: float
471 ; mutable redisplay
: bool
472 ; mutable mpos
: mpos
473 ; mutable keystate
: keystate
474 ; mutable glinks
: bool
475 ; mutable prevcolumns
: (columns
* float) option
478 { pat
: string circbuf
479 ; pag
: string circbuf
480 ; nav
: anchor circbuf
481 ; sel
: string circbuf
503 ; presentation
= false
508 ; proportional
= true
509 ; trimmargins
= false
510 ; trimfuzz
= (0,0,0,0)
511 ; memlimit
= 32 lsl 20
516 ; bgcolor
= (0.5, 0.5, 0.5)
518 ; scrollbarinpm
= true
521 ; mustoresize
= 256 lsl 20
526 | Plinux
| Pfreebsd
| Pdragonflybsd
527 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
528 | Posx
-> "open \"%s\""
529 | Pcygwin
-> "cygstart \"%s\""
530 | Punknown
-> "echo %s")
531 ; pathlauncher
= "lp \"%s\""
534 | Plinux
| Pfreebsd
| Pdragonflybsd
535 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
542 ; redirectstderr
= false
544 ; columns
= Csingle
[||]
551 let mk n
= (n
, Hashtbl.create
1) in
565 let findkeyhash c name
=
566 try List.assoc name c
.keyhashes
567 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
570 let conf = { defconf with angle
= defconf.angle
};;
572 let pgscale h
= truncate
(float h
*. conf.pgscale);;
575 { mutable fontsize
: int
576 ; mutable wwidth
: float
577 ; mutable maxrows
: int
589 fstate.fontsize
<- n
;
590 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
591 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
595 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
596 let len = String.length s
in
597 if colonpos >= 0 && colonpos + 3 < len
599 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
602 try String.rindex_from s
colonpos ' '
606 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
609 | "http" | "ftp" | "mailto" ->
611 try String.index_from s
colonpos ' '
612 with Not_found
-> len
614 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
622 if String.length
conf.urilauncher
= 0
623 then print_endline uri
625 let url = geturl uri
in
626 if String.length
url = 0
627 then print_endline uri
629 let re = Str.regexp
"%s" in
630 let command = Str.global_replace
re url conf.urilauncher
in
634 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
640 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
641 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
645 let strings = version () :: "" :: Help.keys
in
648 let url = geturl s
in
649 if String.length
url > 0
650 then (s
, 0, Action
(fun u
-> gotouri url; u
))
651 else (s
, 0, Noaction
)
656 let firstgeomcmds = "", [];;
663 ; stderr
= Unix.stderr
664 ; errmsgs
= Buffer.create
0
671 ; anchor
= emptyanchor
675 ; tilelru
= Queue.create
()
676 ; pagemap
= Hashtbl.create
10
677 ; tilemap
= Hashtbl.create
10
692 ; geomcmds
= firstgeomcmds
694 { nav
= cbnew 10 emptyanchor
721 Printf.kprintf prerr_endline fmt
723 Printf.kprintf ignore fmt
727 if String.length
conf.pathlauncher
= 0
728 then print_endline
state.path
730 let re = Str.regexp
"%s" in
731 let command = Str.global_replace
re state.path
conf.pathlauncher
in
735 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
741 type 'a t
= | Res
of 'a
| Exn
of exn
;;
744 try Res
(Unix.pipe ())
750 with exn
-> f
(Printexc.to_string exn
)
754 try Res
(Unix.dup fd
)
759 try Res
(Unix.dup2 fd1 fd2
)
764 let redirectstderr () =
765 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
766 if conf.redirectstderr
768 match Ne.pipe () with
770 dolog "failed to create stderr redirection pipes: %s"
771 (Printexc.to_string exn
)
774 begin match Ne.dup Unix.stderr
with
776 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
777 Ne.clo r
(clofail "pipe/r");
778 Ne.clo w
(clofail "pipe/w");
780 | Ne.Res dupstderr
->
781 begin match Ne.dup2 w
Unix.stderr
with
783 dolog "failed to dup2 to stderr: %s"
784 (Printexc.to_string exn
);
785 Ne.clo dupstderr
(clofail "stderr duplicate");
786 Ne.clo r
(clofail "redir pipe/r");
787 Ne.clo w
(clofail "redir pipe/w");
790 state.stderr
<- dupstderr
;
791 state.errfd
<- Some r
;
795 state.newerrmsgs
<- false;
796 begin match state.errfd
with
798 begin match Ne.dup2 state.stderr
Unix.stderr
with
800 dolog "failed to dup2 original stderr: %s"
801 (Printexc.to_string exn
)
803 Ne.clo fd
(clofail "dup of stderr");
804 Unix.dup2 state.stderr
Unix.stderr
;
809 prerr_string
(Buffer.contents
state.errmsgs
);
811 Buffer.clear
state.errmsgs
;
817 let postRedisplay who
=
819 then prerr_endline
("redisplay for " ^ who
);
820 state.redisplay
<- true;
824 let getopaque pageno
=
825 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
826 with Not_found
-> None
829 let putopaque pageno opaque
=
830 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
833 let pagetranslatepoint l x y
=
834 let dy = y
- l
.pagedispy
in
835 let y = dy + l
.pagey
in
836 let dx = x
- l
.pagedispx
in
837 let x = dx + l
.pagex
in
844 begin match getopaque l
.pageno
with
846 let x0 = l
.pagedispx
in
847 let x1 = x0 + l
.pagevw
in
848 let y0 = l
.pagedispy
in
849 let y1 = y0 + l
.pagevh
in
850 if y >= y0 && y <= y1 && x >= x0 && x <= x1
852 let px, py
= pagetranslatepoint l
x y in
853 match whatsunder opaque
px py
with
866 state.text
<- Printf.sprintf
"%c%s" c s
;
867 G.postRedisplay "showtext";
870 let undertext = function
873 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
874 | Utext s
-> "font: " ^ s
875 | Uunexpected s
-> "unexpected: " ^ s
876 | Ulaunch s
-> "launch: " ^ s
877 | Unamed s
-> "named: " ^ s
878 | Uremote
(filename
, pageno
) ->
879 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
882 let updateunder x y =
883 match getunder x y with
884 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
886 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
887 Wsi.setcursor
Wsi.CURSOR_INFO
888 | Ulinkgoto
(pageno
, _
) ->
890 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
891 Wsi.setcursor
Wsi.CURSOR_INFO
893 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
894 Wsi.setcursor
Wsi.CURSOR_TEXT
896 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
897 Wsi.setcursor
Wsi.CURSOR_INHERIT
899 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
900 Wsi.setcursor
Wsi.CURSOR_INHERIT
902 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
903 Wsi.setcursor
Wsi.CURSOR_INHERIT
904 | Uremote
(filename
, pageno
) ->
905 if conf.underinfo
then showtext 'r'
906 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
907 Wsi.setcursor
Wsi.CURSOR_INFO
910 let showlinktype under
=
916 let s = undertext under
in
921 let b = Buffer.create
(String.length
s + 1) in
922 Buffer.add_string
b s;
927 let colorspace_of_string s =
928 match String.lowercase
s with
932 | _
-> failwith
"invalid colorspace"
935 let int_of_colorspace = function
941 let colorspace_of_int = function
945 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
948 let colorspace_to_string = function
954 let intentry_with_suffix text key
=
956 if key
>= 32 && key
< 127
960 match Char.lowercase
c with
962 let text = addchar text c in
966 let text = addchar text c in
970 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
974 let multicolumns_to_string (n
, a
, b) =
976 then Printf.sprintf
"%d" n
977 else Printf.sprintf
"%d,%d,%d" n a
b;
980 let multicolumns_of_string s =
982 (int_of_string
s, 0, 0)
984 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
986 then failwith
"subtly broken"; (n
, a
, b)
992 let n = Unix.read fd
s 0 4 in
993 if n != 4 then failwith
"incomplete read(len)";
995 lor (Char.code
s.[0] lsl 24)
996 lor (Char.code
s.[1] lsl 16)
997 lor (Char.code
s.[2] lsl 8)
998 lor (Char.code
s.[3] lsl 0)
1000 let s = String.create
len in
1001 let n = Unix.read fd
s 0 len in
1002 if n != len then failwith
"incomplete read(data)";
1006 let btod b = if b then 1 else 0;;
1009 let b = Buffer.create
16 in
1010 Buffer.add_string
b "llll";
1013 let s = Buffer.contents
b in
1014 let n = String.length
s in
1016 (* dolog "wcmd %S" (String.sub s 4 len); *)
1017 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1018 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1019 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1020 s.[3] <- Char.chr
(len land 0xff);
1021 let n'
= Unix.write
state.sw
s 0 n in
1022 if n'
!= n then failwith
"write failed";
1027 let d = conf.winh
- h
in
1028 max
conf.interpagespace
((d + 1) / 2)
1031 let rowyh (c, coverA
, coverB
) b n =
1032 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1034 let _, _, vy
, (_, _, h
, _) = b.(n) in
1037 let n'
= n - coverA
in
1040 let e = min
state.pagecount
(s + c) in
1041 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1042 let _, _, y, (_, _, h
, _) = b.(m
) in
1043 let miny = min
miny y in
1044 let maxh = max
maxh h
in
1045 find (m
+1) miny maxh
1050 match conf.columns
with
1051 | Cmulti
((_, _, _) as cl
, b) ->
1052 if Array.length
b > 0
1054 let y, h
= rowyh cl
b (Array.length
b - 1) in
1055 y + h
+ (if conf.presentation
then calcips h
else 0)
1058 if Array.length
b > 0
1060 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1061 y + h
+ (if conf.presentation
then calcips h
else 0)
1064 if Array.length
b > 0
1066 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1071 let getpageyh pageno
=
1072 let pageno = bound pageno 0 (state.pagecount
-1) in
1073 match conf.columns
with
1075 if Array.length
b = 0
1078 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1080 if conf.presentation
1086 if Array.length
b = 0
1089 let y, h
= rowyh cl
b pageno in
1091 if conf.presentation
1097 if Array.length
b = 0
1101 let (_, _, y, (_, _, h
, _)) = b.(n) in
1105 let getpagedim pageno =
1108 | (n, _, _, _) as pdim
:: rest
->
1110 then (if n = pageno then pdim
else ppdim
)
1115 f (-1, -1, -1, -1) state.pdims
1118 let getpagey pageno = fst
(getpageyh pageno);;
1120 let nogeomcmds cmds
=
1122 | s, [] -> String.length
s = 0
1127 let ((c, coverA
, coverB
) as cl
), b =
1128 match conf.columns
with
1129 | Csingle
b -> (1, 0, 0), b
1130 | Cmulti
(c, b) -> c, b
1131 | Csplit
(_, b) -> (1, 0, 0), b
1133 let rec bsearch nmin nmax
=
1135 then bound nmin
0 (state.pagecount
-1)
1137 let n = (nmax
+ nmin
) / 2 in
1138 let vy, h
= rowyh cl
b n in
1140 if conf.presentation
1142 let ips = calcips h
in
1143 let y0 = vy - ips in
1144 let y1 = vy + h
+ ips in
1148 then 0, vy + h
+ conf.interpagespace
1150 let y0 = vy - conf.interpagespace
in
1151 y0, y0 + h
+ conf.interpagespace
1154 if y >= y0 && y < y1
1161 if n < state.pagecount
- coverB
1162 then ((n-coverA
)/c)*c + coverA
1169 then bsearch (n+1) nmax
1170 else bsearch nmin
(n-1)
1173 let r = bsearch 0 (state.pagecount
-1) in
1177 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1178 let sh = sh - state.hscrollh
in
1179 let rec fold accu
n =
1180 if n = Array.length
b
1183 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1186 || n = state.pagecount
- coverB
1187 || (n - coverA
) mod columns
= columns
- 1)
1193 let pagey = max
0 (y - vy) in
1194 let pagedispy = if pagey > 0 then 0 else vy - y in
1195 let pagedispx, pagex
=
1197 if n = coverA
- 1 || n = state.pagecount
- coverB
1198 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1199 else dx + xoff
+ state.x
1206 let vw = conf.winw
- state.scrollw
- pagedispx in
1207 let pw = w
- pagex
in
1210 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1211 if pagevw > 0 && pagevh > 0
1215 ; pagedimno
= pdimno
1222 ; pagedispx = pagedispx
1223 ; pagedispy = pagedispy
1235 List.rev
(fold [] (page_of_y y));
1238 let layoutS (columns
, b) y sh =
1239 let sh = sh - state.hscrollh
in
1240 let rec fold accu n =
1241 if n = Array.length
b
1244 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1251 let x = xoff
+ state.x in
1252 let pagey = max
0 (y - vy) in
1253 let pagedispy = if pagey > 0 then 0 else vy - y in
1254 let pagedispx, pagex
=
1268 let pagecolw = pagew
/columns
in
1270 if pagecolw < conf.winw
1271 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1275 let vw = conf.winw
- pagedispx - state.scrollw
in
1276 let pw = pagew
- pagex
in
1279 let pagevw = min
pagevw pagecolw in
1280 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1281 if pagevw > 0 && pagevh > 0
1284 { pageno = n/columns
1285 ; pagedimno
= pdimno
1292 ; pagedispx = pagedispx
1293 ; pagedispy = pagedispy
1294 ; pagecol
= n mod columns
1305 List.rev
(fold [] 0)
1309 if nogeomcmds state.geomcmds
1311 match conf.columns
with
1312 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1313 | Cmulti
c -> layoutN c y sh
1314 | Csplit
s -> layoutS s y sh
1319 let y = state.y + incr
in
1321 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1326 let tilex = l
.pagex
mod conf.tilew
in
1327 let tiley = l
.pagey mod conf.tileh
in
1329 let col = l
.pagex
/ conf.tilew
in
1330 let row = l
.pagey / conf.tileh
in
1332 let rec rowloop row y0 dispy h
=
1336 let dh = conf.tileh
- y0 in
1337 let dh = min h
dh in
1338 let rec colloop col x0 dispx w
=
1342 let dw = conf.tilew
- x0 in
1343 let dw = min w
dw in
1345 f col row dispx dispy
x0 y0 dw dh;
1346 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1349 colloop col tilex l
.pagedispx l
.pagevw;
1350 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1353 if l
.pagevw > 0 && l
.pagevh > 0
1354 then rowloop row tiley l
.pagedispy l
.pagevh;
1357 let gettileopaque l
col row =
1359 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1361 try Some
(Hashtbl.find state.tilemap
key)
1362 with Not_found
-> None
1365 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1366 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1367 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1370 let drawtiles l color
=
1372 let f col row x y tilex tiley w h
=
1373 match gettileopaque l
col row with
1374 | Some
(opaque
, _, t
) ->
1375 let params = x, y, w
, h
, tilex, tiley in
1379 GlFunc.blend_func `zero `one_minus_src_color
;
1381 drawtile
params opaque
;
1383 then Gl.disable `blend
;
1386 let s = Printf.sprintf
1390 let w = measurestr
fstate.fontsize
s in
1391 GlMisc.push_attrib
[`current
];
1392 GlDraw.color
(0.0, 0.0, 0.0);
1394 (float (x-2), float (y-2))
1395 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1396 GlDraw.color
(1.0, 1.0, 1.0);
1397 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1398 GlMisc.pop_attrib
();
1403 let lw = conf.winw
- state.scrollw
- x in
1406 let lh = conf.winh
- y in
1409 begin match state.texid
with
1411 Gl.enable `texture_2d
;
1412 GlTex.bind_texture `texture_2d id
;
1415 and x1 = float (x+w)
1416 and y1 = float (y+h
) in
1418 let tw = float w /. 16.0
1419 and th
= float h
/. 16.0 in
1420 let tx0 = float tilex /. 16.0
1421 and ty0
= float tiley /. 16.0 in
1423 and ty1
= ty0
+. th
in
1424 GlDraw.begins `quads
;
1425 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1426 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1427 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1428 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1431 Gl.disable `texture_2d
;
1433 GlDraw.color
(1.0, 1.0, 1.0);
1436 (float (x+w), float (y+h
));
1438 if w > 128 && h
> fstate.fontsize
+ 10
1440 GlDraw.color
(0.0, 0.0, 0.0);
1443 then (col*conf.tilew
, row*conf.tileh
)
1446 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1453 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1455 let tilevisible1 l
x y =
1457 and ax1
= l
.pagex
+ l
.pagevw
1459 and ay1
= l
.pagey + l
.pagevh in
1463 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1464 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1466 let rx0 = max
ax0 bx0
1467 and ry0
= max ay0 by0
1468 and rx1
= min ax1
bx1
1469 and ry1
= min ay1 by1
in
1471 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1472 nonemptyintersection
1475 let tilevisible layout n x y =
1476 let rec findpageinlayout m
= function
1477 | l
:: rest
when l
.pageno = n ->
1478 tilevisible1 l
x y || (
1479 match conf.columns
with
1480 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1483 | _ :: rest
-> findpageinlayout 0 rest
1486 findpageinlayout 0 layout;
1489 let tileready l
x y =
1490 tilevisible1 l
x y &&
1491 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1494 let tilepage n p
layout =
1495 let rec loop = function
1499 let f col row _ _ _ _ _ _ =
1500 if state.currently
= Idle
1502 match gettileopaque l
col row with
1505 let x = col*conf.tilew
1506 and y = row*conf.tileh
in
1508 let w = l
.pagew
- x in
1512 let h = l
.pageh
- y in
1517 then getpbo
w h conf.colorspace
1520 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1523 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1524 conf.tilew
, conf.tileh
1533 if nogeomcmds state.geomcmds
1537 let preloadlayout y =
1538 let y = if y < conf.winh
then 0 else y - conf.winh
in
1539 let h = conf.winh
*3 in
1544 let rec loop pages
=
1545 if state.currently
!= Idle
1550 begin match getopaque l
.pageno with
1552 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1553 state.currently
<- Loading
(l
, state.gen
);
1555 tilepage l
.pageno opaque pages
;
1560 if nogeomcmds state.geomcmds
1566 if conf.preload && state.currently
= Idle
1567 then load (preloadlayout state.y);
1570 let layoutready layout =
1571 let rec fold all ls
=
1572 all
&& match ls
with
1574 let seen = ref false in
1575 let allvisible = ref true in
1576 let foo col row _ _ _ _ _ _ =
1578 allvisible := !allvisible &&
1579 begin match gettileopaque l
col row with
1585 fold (!seen && !allvisible) rest
1588 let alltilesvisible = fold true layout in
1593 let y = bound y 0 state.maxy
in
1594 let y, layout, proceed
=
1595 match conf.maxwait
with
1596 | Some time
when state.ghyll
== noghyll ->
1597 begin match state.throttle
with
1599 let layout = layout y conf.winh
in
1600 let ready = layoutready layout in
1604 state.throttle
<- Some
(layout, y, now ());
1606 else G.postRedisplay "gotoy showall (None)";
1608 | Some
(_, _, started
) ->
1609 let dt = now () -. started
in
1612 state.throttle
<- None
;
1613 let layout = layout y conf.winh
in
1615 G.postRedisplay "maxwait";
1622 let layout = layout y conf.winh
in
1623 if true || layoutready layout
1624 then G.postRedisplay "gotoy ready";
1630 state.layout <- layout;
1631 begin match state.mode
with
1632 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1633 let rec loop = function
1635 state.mode
<- LinkNav
(Ltgendir
0)
1636 | l
:: _ when l
.pageno = pageno ->
1637 begin match getopaque pageno with
1639 state.mode
<- LinkNav
(Ltgendir
0)
1641 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1642 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1643 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1644 then state.mode
<- LinkNav
(Ltgendir
0)
1646 | _ :: rest
-> loop rest
1651 begin match state.mode
with
1652 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1653 if not
(pagevisible layout pageno)
1655 match state.layout with
1658 state.mode
<- Birdseye
(
1659 conf, leftx
, l
.pageno, hooverpageno
, anchor
1662 | LinkNav
(Ltgendir dir
as lt
) ->
1664 let rec loop = function
1667 match getopaque l
.pageno with
1673 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1675 if dir
> 0 then LDfirst
else LDlast
1681 | Lnotfound
-> loop rest
1683 showlinktype (getlink opaque
n);
1684 Ltexact
(l
.pageno, n)
1688 state.mode
<- LinkNav
linknav
1693 state.ghyll
<- noghyll;
1696 let mx, my
= state.mpos
in
1701 let conttiling pageno opaque
=
1702 tilepage pageno opaque
1703 (if conf.preload then preloadlayout state.y else state.layout)
1706 let gotoy_and_clear_text y =
1707 if not
conf.verbose
then state.text <- "";
1713 let coloff = l
.pagecol
* l
.pageh
in
1714 float (l
.pagey + coloff) /. float l
.pageh
1721 if conf.presentation
1722 then float l
.pagedispy /. float (calcips l
.pageh
)
1723 else float l
.pagedispy /. float conf.interpagespace
1725 (l
.pageno, top, dtop)
1729 match state.layout with
1730 | l
:: _ -> getanchor1 l
1732 let n = page_of_y state.y in
1733 let y, h = getpageyh n in
1734 let dy = y - state.y in
1736 if conf.presentation
1738 let ips = calcips h in
1739 float (dy + ips) /. float ips
1741 float dy /. float conf.interpagespace
1746 let getanchory (n, top, dtop) =
1747 let y, h = getpageyh n in
1748 if conf.presentation
1750 let ips = calcips h in
1751 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1753 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1756 let gotoanchor anchor
=
1757 gotoy (getanchory anchor
);
1761 cbput state.hists
.nav
(getanchor ());
1765 let anchor = cbgetc state.hists
.nav dir
in
1770 let scroll f n a
b =
1771 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1773 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1775 then s (float f /. float a
)
1778 then 1.0 -. s ((float (f-b) /. float (n-b)))
1785 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1786 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1788 let ins = float a
*. iv1
1789 and outs
= float (n-b) *. iv1 in
1791 ins +. outs
+. float ones
1793 let rec set (_N
, _A
, _B
) y sy
=
1794 let sum = summa
1.0 _N _A _B
in
1795 let dy = float (y - sy
) in
1799 then state.ghyll
<- noghyll
1802 let s = scroll n _N _A _B
in
1803 let y1 = y1 +. ((s *. dy) /. sum) in
1804 gotoy_and_clear_text (truncate
y1);
1805 state.ghyll
<- gf (n+1) y1;
1809 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1811 gf 0 (float state.y)
1814 match conf.ghyllscroll
with
1816 gotoy_and_clear_text y
1818 if state.ghyll
== noghyll
1819 then set nab
y state.y
1820 else state.ghyll
(Some
y)
1823 let gotopage n top =
1824 let y, h = getpageyh n in
1825 let y = y + (truncate
(top *. float h)) in
1829 let gotopage1 n top =
1830 let y = getpagey n in
1835 let invalidate s f =
1840 match state.geomcmds
with
1841 | ps
, [] when String.length ps
= 0 ->
1843 state.geomcmds
<- s, [];
1846 state.geomcmds
<- ps
, [s, f];
1848 | ps
, (s'
, _) :: rest
when s'
= s ->
1849 state.geomcmds
<- ps
, ((s, f) :: rest
);
1852 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1856 Hashtbl.iter
(fun _ opaque
->
1857 wcmd "freepage %s" opaque
;
1859 Hashtbl.clear
state.pagemap
;
1862 let opendoc path password
=
1864 state.password
<- password
;
1865 state.gen
<- state.gen
+ 1;
1866 state.docinfo
<- [];
1869 setaalevel
conf.aalevel
;
1870 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1871 wcmd "open %s\000%s\000" path password
;
1872 invalidate "reqlayout"
1874 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1878 state.anchor <- getanchor ();
1879 opendoc state.path
state.password
;
1883 let c = c *. conf.colorscale
in
1887 let scalecolor2 (r, g
, b) =
1888 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1891 let docolumns = function
1893 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1894 let rec loop pageno pdimno pdim
y ph pdims
=
1895 if pageno = state.pagecount
1898 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1900 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1901 pdimno+1, pdim
, rest
1905 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1907 (if conf.presentation
1908 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1909 else (if pageno = 0 then 0 else conf.interpagespace
)
1912 a.(pageno) <- (pdimno, x, y, pdim
);
1913 loop (pageno+1) pdimno pdim
(y + h) h pdims
1915 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1916 conf.columns
<- Csingle
a;
1918 | Cmulti
((columns
, coverA
, coverB
), _) ->
1919 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1920 let rec loop pageno pdimno pdim
x y rowh pdims
=
1921 let rec fixrow m
= if m
= pageno then () else
1922 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1925 let y = y + (rowh
- h) / 2 in
1926 a.(m
) <- (pdimno, x, y, pdim
);
1930 if pageno = state.pagecount
1931 then fixrow (((pageno - 1) / columns
) * columns
)
1933 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1935 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1936 pdimno+1, pdim
, rest
1941 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1943 let x = (conf.winw
- state.scrollw
- w) / 2 in
1945 if conf.presentation
then calcips h else conf.interpagespace
in
1946 x, y + ips + rowh
, h
1949 if (pageno - coverA
) mod columns
= 0
1951 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1953 if conf.presentation
1955 let ips = calcips h in
1956 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1958 y + (if pageno = 0 then 0 else conf.interpagespace
)
1962 else x, y, max rowh
h
1966 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1969 if pageno = columns
&& conf.presentation
1971 let ips = calcips rowh
in
1972 for i
= 0 to pred columns
1974 let (pdimno, x, y, pdim
) = a.(i
) in
1975 a.(i
) <- (pdimno, x, y+ips, pdim
)
1981 fixrow (pageno - columns
);
1986 a.(pageno) <- (pdimno, x, y, pdim
);
1987 let x = x + w + xoff
*2 + conf.interpagespace
in
1988 loop (pageno+1) pdimno pdim
x y rowh' pdims
1990 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1991 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1994 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1995 let rec loop pageno pdimno pdim
y pdims
=
1996 if pageno = state.pagecount
1999 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2001 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2002 pdimno+1, pdim
, rest
2007 let rec loop1 n x y =
2008 if n = c then y else (
2009 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2010 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2013 let y = loop1 0 0 y in
2014 loop (pageno+1) pdimno pdim
y pdims
2016 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2017 conf.columns
<- Csplit
(c, a);
2021 docolumns conf.columns
;
2022 state.maxy
<- calcheight ();
2024 if state.w <= conf.winw
- state.scrollw
2028 match state.mode
with
2029 | Birdseye
(_, _, pageno, _, _) ->
2030 let y, h = getpageyh pageno in
2031 let top = (conf.winh
- h) / 2 in
2032 gotoy (max
0 (y - top))
2033 | _ -> gotoanchor state.anchor
2037 GlDraw.viewport
0 0 w h;
2038 let firsttime = state.geomcmds
== firstgeomcmds in
2039 if not
firsttime && nogeomcmds state.geomcmds
2040 then state.anchor <- getanchor ();
2043 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2046 setfontsize fstate.fontsize
;
2047 GlMat.mode `modelview
;
2048 GlMat.load_identity
();
2050 GlMat.mode `projection
;
2051 GlMat.load_identity
();
2052 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2053 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2054 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2059 else float state.x /. float state.w
2061 invalidate "geometry"
2065 then state.x <- truncate
(relx *. float w);
2067 match conf.columns
with
2069 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2070 | Csplit
(c, _) -> w * c
2072 wcmd "geometry %d %d" w h);
2076 let len = String.length
state.text in
2079 match state.mode
with
2082 let h, _, _ = state.uioh#scrollpw
in
2088 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2089 (x+.w, float (conf.winh
- hscrollh))
2092 let w = float (conf.winw
- state.scrollw
- 1) in
2093 if state.progress
>= 0.0 && state.progress
< 1.0
2095 GlDraw.color
(0.3, 0.3, 0.3);
2096 let w1 = w *. state.progress
in
2098 GlDraw.color
(0.0, 0.0, 0.0);
2102 GlDraw.color
(0.0, 0.0, 0.0);
2106 GlDraw.color
(1.0, 1.0, 1.0);
2107 drawstring fstate.fontsize
2108 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2111 match state.mode
with
2112 | Textentry
((prefix
, text, _, _, _, _), _) ->
2116 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2118 Printf.sprintf
"%s%s_" prefix
text
2127 if not
(istextentry state.mode
)
2129 let s1 = "(press 'e' to review error messasges)" in
2130 if String.length
s > 0 then s ^
" " ^
s1 else s1
2135 if String.length
s > 0
2140 let len = Queue.length
state.tilelru
in
2142 match state.throttle
with
2145 then preloadlayout state.y
2147 | Some
(layout, _, _) ->
2151 if state.memused
<= conf.memlimit
2156 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2157 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2158 let (_, pw, ph
, _) = getpagedim n in
2161 && colorspace
= conf.colorspace
2162 && angle
= conf.angle
2166 let x = col*conf.tilew
2167 and y = row*conf.tileh
in
2168 tilevisible (Lazy.force_val
layout) n x y
2170 then Queue.push lruitem
state.tilelru
2173 wcmd "freetile %s" p
;
2174 state.memused
<- state.memused
- s;
2175 state.uioh#infochanged Memused
;
2176 Hashtbl.remove
state.tilemap k
;
2185 Queue.iter
(fun (k
, p
, s) ->
2186 wcmd "freetile %s" p
;
2187 state.memused
<- state.memused
- s;
2188 state.uioh#infochanged Memused
;
2189 Hashtbl.remove
state.tilemap k
;
2191 Queue.clear
state.tilelru
;
2195 let logcurrently = function
2196 | Idle
-> dolog "Idle"
2197 | Loading
(l
, gen
) ->
2198 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2199 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2201 "Tiling %d[%d,%d] page=%s cs=%s angle"
2202 l
.pageno col row pageopaque
2203 (colorspace_to_string colorspace
)
2205 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2206 angle gen
conf.angle
state.gen
2208 conf.tilew
conf.tileh
2215 (* dolog "%S" cmds; *)
2218 try String.index cmds ' '
2219 with Not_found
-> -1
2224 let l = String.length cmds
in
2225 let op = String.sub cmds
0 spacepos in
2227 if l - spacepos < 2 then ""
2228 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2233 state.uioh#infochanged Pdim
;
2237 state.rects
<- state.rects1
;
2238 G.postRedisplay "clearrects";
2242 try Scanf.sscanf
args "%u" (fun n -> n)
2244 dolog "error processing 'continue' %S: %s"
2245 cmds
(Printexc.to_string exn
);
2248 state.pagecount
<- n;
2249 begin match state.currently
with
2251 state.currently
<- Idle
;
2252 state.outlines
<- Array.of_list
(List.rev
l)
2256 let cur, cmds
= state.geomcmds
in
2257 if String.length
cur = 0
2258 then failwith
"umpossible";
2260 begin match List.rev cmds
with
2262 state.geomcmds
<- "", [];
2266 state.geomcmds
<- s, List.rev rest
;
2268 if conf.maxwait
= None
2269 then G.postRedisplay "continue";
2279 then showtext ' '
args
2282 let progress, text =
2284 Scanf.sscanf
args "%f %n"
2286 f, String.sub
args pos
(String.length
args - pos
))
2288 dolog "error processing 'progress' %S: %s"
2289 cmds
(Printexc.to_string exn
);
2293 state.progress <- progress;
2294 G.postRedisplay "progress"
2297 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2299 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2300 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2301 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2303 dolog "error processing 'firstmatch' %S: %s"
2304 cmds
(Printexc.to_string exn
);
2307 let y = (getpagey pageno) + truncate
y0 in
2310 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2313 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2315 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2316 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2317 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2319 dolog "error processing 'match' %S: %s"
2320 cmds
(Printexc.to_string exn
);
2324 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2329 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2331 dolog "error processing 'page' %S: %s"
2332 cmds
(Printexc.to_string exn
);
2335 begin match state.currently
with
2336 | Loading
(l, gen
) ->
2337 vlog "page %d took %f sec" l.pageno t
;
2338 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2339 begin match state.throttle
with
2341 let preloadedpages =
2343 then preloadlayout state.y
2348 Set.Make
(struct type t
= int let compare = (-) end) in
2350 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2351 IntSet.empty
preloadedpages
2354 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2355 if not
(IntSet.mem
pageno set)
2357 wcmd "freepage %s" opaque
;
2363 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2366 state.currently
<- Idle
;
2369 tilepage l.pageno pageopaque state.layout;
2371 load preloadedpages;
2372 if pagevisible state.layout l.pageno
2373 && layoutready state.layout
2374 then G.postRedisplay "page";
2377 | Some
(layout, _, _) ->
2378 state.currently
<- Idle
;
2379 tilepage l.pageno pageopaque layout;
2384 dolog "Inconsistent loading state";
2385 logcurrently state.currently
;
2390 let (x, y, opaque
, size
, t
) =
2392 Scanf.sscanf
args "%u %u %s %u %f"
2393 (fun x y p size t
-> (x, y, p
, size
, t
))
2395 dolog "error processing 'tile' %S: %s"
2396 cmds
(Printexc.to_string exn
);
2399 begin match state.currently
with
2400 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2401 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2404 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2406 wcmd "freetile %s" opaque
;
2407 state.currently
<- Idle
;
2411 puttileopaque l col row gen cs angle opaque size t
;
2412 state.memused
<- state.memused
+ size
;
2413 state.uioh#infochanged Memused
;
2415 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2416 opaque
, size
) state.tilelru
;
2419 match state.throttle
with
2420 | None
-> state.layout
2421 | Some
(layout, _, _) -> layout
2424 state.currently
<- Idle
;
2426 && conf.colorspace
= cs
2427 && conf.angle
= angle
2428 && tilevisible layout l.pageno x y
2429 then conttiling l.pageno pageopaque;
2431 begin match state.throttle
with
2433 preload state.layout;
2435 && conf.colorspace
= cs
2436 && conf.angle
= angle
2437 && tilevisible state.layout l.pageno x y
2438 then G.postRedisplay "tile nothrottle";
2440 | Some
(layout, y, _) ->
2441 let ready = layoutready layout in
2445 state.layout <- layout;
2446 state.throttle
<- None
;
2447 G.postRedisplay "throttle";
2454 dolog "Inconsistent tiling state";
2455 logcurrently state.currently
;
2462 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2464 dolog "error processing 'pdim' %S: %s"
2465 cmds
(Printexc.to_string exn
);
2468 state.uioh#infochanged Pdim
;
2469 state.pdims
<- pdim :: state.pdims
2472 let (l, n, t
, h, pos
) =
2474 Scanf.sscanf
args "%u %u %d %u %n"
2475 (fun l n t
h pos
-> l, n, t
, h, pos
)
2477 dolog "error processing 'o' %S: %s"
2478 cmds
(Printexc.to_string exn
);
2481 let s = String.sub
args pos
(String.length
args - pos
) in
2482 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2483 begin match state.currently
with
2484 | Outlining outlines
->
2485 state.currently
<- Outlining
(outline :: outlines
)
2487 state.currently
<- Outlining
[outline]
2489 dolog "invalid outlining state";
2490 logcurrently currently
2494 state.docinfo
<- (1, args) :: state.docinfo
2497 state.uioh#infochanged Docinfo
;
2498 state.docinfo
<- List.rev
state.docinfo
2501 dolog "unknown cmd `%S'" cmds
2506 let action = function
2507 | HCprev
-> cbget cb ~
-1
2508 | HCnext
-> cbget cb
1
2509 | HCfirst
-> cbget cb ~
-(cb
.rc)
2510 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2511 and cancel
() = cb
.rc <- rc
2515 let search pattern forward
=
2516 if String.length pattern
> 0
2519 match state.layout with
2522 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2524 wcmd "search %d %d %d %d,%s\000"
2525 (btod conf.icase
) pn py
(btod forward
) pattern
;
2528 let intentry text key =
2530 if key >= 32 && key < 127
2536 let text = addchar text c in
2540 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2544 let linknentry text key =
2546 if key >= 32 && key < 127
2552 let text = addchar text c in
2556 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2561 if String.length
s > 0
2564 let l = String.length
s in
2565 let rec loop pos
n = if pos
= l then n else
2566 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2567 loop (pos
+1) (n*26 + m)
2570 let rec loop n = function
2573 match getopaque l.pageno with
2574 | None
-> loop n rest
2576 let m = getlinkcount opaque
in
2579 let under = getlink opaque
n in
2582 else loop (n-m) rest
2584 loop n state.layout;
2588 let textentry text key =
2589 if key land 0xff00 = 0xff00
2591 else TEcont
(text ^
Wsi.toutf8
key)
2594 let reqlayout angle proportional
=
2595 match state.throttle
with
2597 if nogeomcmds state.geomcmds
2598 then state.anchor <- getanchor ();
2599 conf.angle
<- angle
mod 360;
2602 match state.mode
with
2603 | LinkNav
_ -> state.mode
<- View
2606 conf.proportional
<- proportional
;
2607 invalidate "reqlayout"
2608 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2612 let settrim trimmargins trimfuzz
=
2613 if nogeomcmds state.geomcmds
2614 then state.anchor <- getanchor ();
2615 conf.trimmargins
<- trimmargins
;
2616 conf.trimfuzz
<- trimfuzz
;
2617 let x0, y0, x1, y1 = trimfuzz
in
2618 invalidate "settrim"
2620 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2625 match state.throttle
with
2627 let zoom = max
0.01 zoom in
2628 if zoom <> conf.zoom
2630 state.prevzoom
<- conf.zoom;
2632 reshape conf.winw
conf.winh
;
2633 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2636 | Some
(layout, y, started
) ->
2638 match conf.maxwait
with
2642 let dt = now () -. started
in
2650 let setcolumns mode columns coverA coverB
=
2651 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2655 then showtext '
!'
"split mode doesn't work in bird's eye"
2657 conf.columns
<- Csplit
(-columns
, [||]);
2665 conf.columns
<- Csingle
[||];
2670 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2674 reshape conf.winw
conf.winh
;
2677 let enterbirdseye () =
2678 let zoom = float conf.thumbw
/. float conf.winw
in
2679 let birdseyepageno =
2680 let cy = conf.winh
/ 2 in
2684 let rec fold best
= function
2687 let d = cy - (l.pagedispy + l.pagevh/2)
2688 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2689 if abs
d < abs dbest
2696 state.mode
<- Birdseye
(
2697 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2700 conf.presentation
<- false;
2701 conf.interpagespace
<- 10;
2702 conf.hlinks
<- false;
2704 state.mstate
<- Mnone
;
2705 conf.maxwait
<- None
;
2707 match conf.beyecolumns
with
2710 Cmulti
((c, 0, 0), [||])
2711 | None
-> Csingle
[||]
2713 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2716 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2721 reshape conf.winw
conf.winh
;
2724 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2726 conf.zoom <- c.zoom;
2727 conf.presentation
<- c.presentation
;
2728 conf.interpagespace
<- c.interpagespace
;
2729 conf.maxwait
<- c.maxwait
;
2730 conf.hlinks
<- c.hlinks
;
2731 conf.beyecolumns
<- (
2732 match conf.columns
with
2733 | Cmulti
((c, _, _), _) -> Some
c
2735 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2738 match c.columns
with
2739 | Cmulti
(c, _) -> Cmulti
(c, [||])
2740 | Csingle
_ -> Csingle
[||]
2741 | Csplit
(c, _) -> Csplit
(c, [||])
2746 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2749 reshape conf.winw
conf.winh
;
2750 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2753 let togglebirdseye () =
2754 match state.mode
with
2755 | Birdseye vals
-> leavebirdseye vals
true
2756 | View
-> enterbirdseye ()
2760 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2761 let pageno = max
0 (pageno - incr
) in
2762 let rec loop = function
2763 | [] -> gotopage1 pageno 0
2764 | l :: _ when l.pageno = pageno ->
2765 if l.pagedispy >= 0 && l.pagey = 0
2766 then G.postRedisplay "upbirdseye"
2767 else gotopage1 pageno 0
2768 | _ :: rest
-> loop rest
2771 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2774 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2775 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2776 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2777 let rec loop = function
2779 let y, h = getpageyh pageno in
2780 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2782 | l :: _ when l.pageno = pageno ->
2783 if l.pagevh != l.pageh
2784 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2785 else G.postRedisplay "downbirdseye"
2786 | _ :: rest
-> loop rest
2791 let optentry mode
_ key =
2792 let btos b = if b then "on" else "off" in
2793 if key >= 32 && key < 127
2795 let c = Char.chr
key in
2799 try conf.scrollstep
<- int_of_string
s with exc
->
2800 state.text <- Printf.sprintf
"bad integer `%s': %s"
2801 s (Printexc.to_string exc
)
2803 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2808 conf.autoscrollstep
<- int_of_string
s;
2809 if state.autoscroll
<> None
2810 then state.autoscroll
<- Some
conf.autoscrollstep
2812 state.text <- Printf.sprintf
"bad integer `%s': %s"
2813 s (Printexc.to_string exc
)
2815 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2820 let n, a, b = multicolumns_of_string s in
2821 setcolumns mode
n a b;
2823 state.text <- Printf.sprintf
"bad columns `%s': %s"
2824 s (Printexc.to_string exc
)
2826 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2831 let zoom = float (int_of_string
s) /. 100.0 in
2834 state.text <- Printf.sprintf
"bad integer `%s': %s"
2835 s (Printexc.to_string exc
)
2837 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2842 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2844 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2845 begin match mode
with
2847 leavebirdseye beye
false;
2852 state.text <- Printf.sprintf
"bad integer `%s': %s"
2853 s (Printexc.to_string exc
)
2855 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2860 Some
(int_of_string
s)
2862 state.text <- Printf.sprintf
"bad integer `%s': %s"
2863 s (Printexc.to_string exc
);
2866 | Some angle
-> reqlayout angle
conf.proportional
2869 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2872 conf.icase
<- not
conf.icase
;
2873 TEdone
("case insensitive search " ^
(btos conf.icase
))
2876 conf.preload <- not
conf.preload;
2878 TEdone
("preload " ^
(btos conf.preload))
2881 conf.verbose
<- not
conf.verbose
;
2882 TEdone
("verbose " ^
(btos conf.verbose
))
2885 conf.debug
<- not
conf.debug
;
2886 TEdone
("debug " ^
(btos conf.debug
))
2889 conf.maxhfit
<- not
conf.maxhfit
;
2890 state.maxy
<- calcheight ();
2891 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2894 conf.crophack
<- not
conf.crophack
;
2895 TEdone
("crophack " ^
btos conf.crophack
)
2899 match conf.maxwait
with
2901 conf.maxwait
<- Some infinity
;
2902 "always wait for page to complete"
2904 conf.maxwait
<- None
;
2905 "show placeholder if page is not ready"
2910 conf.underinfo
<- not
conf.underinfo
;
2911 TEdone
("underinfo " ^
btos conf.underinfo
)
2914 conf.savebmarks
<- not
conf.savebmarks
;
2915 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2921 match state.layout with
2926 conf.interpagespace
<- int_of_string
s;
2927 docolumns conf.columns
;
2928 state.maxy
<- calcheight ();
2929 let y = getpagey pageno in
2932 state.text <- Printf.sprintf
"bad integer `%s': %s"
2933 s (Printexc.to_string exc
)
2935 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2938 reqlayout conf.angle
(not
conf.proportional
);
2939 TEdone
("proportional display " ^
btos conf.proportional
)
2942 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2943 TEdone
("trim margins " ^
btos conf.trimmargins
)
2946 conf.invert
<- not
conf.invert
;
2947 TEdone
("invert colors " ^
btos conf.invert
)
2951 cbput state.hists
.sel
s;
2954 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2955 textentry, ondone, true)
2958 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2964 class type lvsource
= object
2965 method getitemcount
: int
2966 method getitem
: int -> (string * int)
2967 method hasaction
: int -> bool
2976 method getactive
: int
2977 method getfirst
: int
2978 method getqsearch
: string
2979 method setqsearch
: string -> unit
2983 class virtual lvsourcebase
= object
2984 val mutable m_active
= 0
2985 val mutable m_first
= 0
2986 val mutable m_qsearch
= ""
2987 val mutable m_pan
= 0
2988 method getactive
= m_active
2989 method getfirst
= m_first
2990 method getqsearch
= m_qsearch
2991 method getpan
= m_pan
2992 method setqsearch
s = m_qsearch
<- s
2995 let withoutlastutf8 s =
2996 let len = String.length
s in
3004 let b = Char.code
s.[pos
] in
3005 if b land 0b11000000 = 0b11000000
3010 if Char.code
s.[len-1] land 0x80 = 0
3014 String.sub
s 0 first;
3017 let textentrykeyboard
3018 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3020 state.mode
<- Textentry
(te
, onleave
);
3023 G.postRedisplay "textentrykeyboard enttext";
3025 let histaction cmd
=
3028 | Some
(action, _) ->
3029 state.mode
<- Textentry
(
3030 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3032 G.postRedisplay "textentry histaction"
3035 | 0xff08 -> (* backspace *)
3036 let s = withoutlastutf8 text in
3037 let len = String.length
s in
3038 if cancelonempty
&& len = 0
3041 G.postRedisplay "textentrykeyboard after cancel";
3044 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3050 G.postRedisplay "textentrykeyboard after confirm"
3052 | 0xff52 -> histaction HCprev
3053 | 0xff54 -> histaction HCnext
3054 | 0xff50 -> histaction HCfirst
3055 | 0xff57 -> histaction HClast
3057 | 0xff1b -> (* escape*)
3058 if String.length
text = 0
3060 begin match opthist
with
3062 | Some
(_, onhistcancel
) -> onhistcancel
()
3066 G.postRedisplay "textentrykeyboard after cancel2"
3069 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3072 | 0xff9f | 0xffff -> () (* delete *)
3075 && key land 0xff00 != 0xff00 (* keyboard *)
3076 && key land 0xfe00 != 0xfe00 (* xkb *)
3077 && key land 0xfd00 != 0xfd00 (* 3270 *)
3079 begin match onkey
text key with
3083 G.postRedisplay "textentrykeyboard after confirm2";
3086 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3090 G.postRedisplay "textentrykeyboard after cancel3"
3093 state.mode
<- Textentry
(te
, onleave
);
3094 G.postRedisplay "textentrykeyboard switch";
3098 vlog "unhandled key %s" (Wsi.keyname
key)
3101 let firstof first active
=
3102 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3103 then max
0 (active
- (fstate.maxrows
/2))
3107 let calcfirst first active
=
3110 let rows = active
- first in
3111 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3115 let scrollph y maxy
=
3116 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3117 let sh = float conf.winh
/. sh in
3118 let sh = max
sh (float conf.scrollh
) in
3123 else float y /. float maxy
3125 let position = (float conf.winh
-. sh) *. percent in
3128 if position +. sh > float conf.winh
3129 then float conf.winh
-. sh
3135 let coe s = (s :> uioh
);;
3137 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3139 val m_pan
= source#getpan
3140 val m_first
= source#getfirst
3141 val m_active
= source#getactive
3142 val m_qsearch
= source#getqsearch
3143 val m_prev_uioh
= state.uioh
3145 method private elemunder
y =
3146 let n = y / (fstate.fontsize
+1) in
3147 if m_first
+ n < source#getitemcount
3149 if source#hasaction
(m_first
+ n)
3150 then Some
(m_first
+ n)
3157 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3158 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3159 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3160 GlDraw.color
(1., 1., 1.);
3161 Gl.enable `texture_2d
;
3162 let fs = fstate.fontsize
in
3164 let ww = fstate.wwidth
in
3165 let tabw = 30.0*.ww in
3166 let itemcount = source#getitemcount
in
3168 if (row - m_first
) > fstate.maxrows
3171 if row >= 0 && row < itemcount
3173 let (s, level
) = source#getitem
row in
3174 let y = (row - m_first
) * nfs in
3175 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3178 Gl.disable `texture_2d
;
3179 GlDraw.polygon_mode `both `line
;
3180 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3181 GlDraw.rect (1., float (y + 1))
3182 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3183 GlDraw.polygon_mode `both `fill
;
3184 GlDraw.color
(1., 1., 1.);
3185 Gl.enable `texture_2d
;
3188 let drawtabularstring s =
3189 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3192 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3195 let len = String.length
s - tabpos - 1 in
3196 let s1 = String.sub
s 0 tabpos
3197 and s2
= String.sub
s (tabpos + 1) len in
3198 let nx = drawstr x s1 in
3200 let x = x +. (max
tabw sw) in
3207 let _ = drawtabularstring s in
3214 Gl.disable `texture_2d
;
3216 method updownlevel incr
=
3217 let len = source#getitemcount
in
3219 if m_active
>= 0 && m_active
< len
3220 then snd
(source#getitem m_active
)
3224 if i
= len then i
-1 else if i
= -1 then 0 else
3225 let _, l = source#getitem i
in
3226 if l != curlevel then i
else flow (i
+incr
)
3228 let active = flow m_active
in
3229 let first = calcfirst m_first
active in
3230 G.postRedisplay "outline updownlevel";
3231 {< m_active
= active; m_first
= first >}
3233 method private key1
key mask
=
3234 let set1 active first qsearch
=
3235 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3237 let search active pattern incr
=
3240 if n >= 0 && n < source#getitemcount
3242 let s, _ = source#getitem
n in
3244 (try ignore
(Str.search_forward
re s 0); true
3245 with Not_found
-> false)
3247 else loop (n + incr
)
3254 let re = Str.regexp_case_fold pattern
in
3260 let itemcount = source#getitemcount
in
3261 let find start incr
=
3263 if i
= -1 || i
= itemcount
3266 if source#hasaction i
3268 else find (i
+ incr
)
3273 let set active first =
3274 let first = bound first 0 (itemcount - fstate.maxrows
) in
3276 coe {< m_active
= active; m_first
= first >}
3279 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3281 let incr1 = if incr
> 0 then 1 else -1 in
3282 if isvisible m_first m_active
3285 let next = m_active
+ incr
in
3287 if next < 0 || next >= itemcount
3289 else find next incr1
3291 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3297 let first = m_first
+ incr
in
3298 let first = bound first 0 (itemcount - 1) in
3300 let next = m_active
+ incr
in
3301 let next = bound next 0 (itemcount - 1) in
3304 let active = if next = -1 then m_active
else next in
3307 let first = min
next m_first
in
3309 if abs
(next - first) > fstate.maxrows
3315 let first = m_first
+ incr
in
3316 let first = bound first 0 (itemcount - 1) in
3318 let next = m_active
+ incr
in
3319 let next = bound next 0 (itemcount - 1) in
3320 let next = find next incr1 in
3322 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3324 let active = if m_active
= -1 then next else m_active
in
3329 if isvisible first active
3335 G.postRedisplay "listview navigate";
3339 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3340 let incr = if key = 0x72 then -1 else 1 in
3342 match search (m_active
+ incr) m_qsearch
incr with
3344 state.text <- m_qsearch ^
" [not found]";
3347 state.text <- m_qsearch
;
3348 active, firstof m_first
active
3350 G.postRedisplay "listview ctrl-r/s";
3351 set1 active first m_qsearch
;
3353 | 0xff08 -> (* backspace *)
3354 if String.length m_qsearch
= 0
3357 let qsearch = withoutlastutf8 m_qsearch
in
3358 let len = String.length
qsearch in
3362 G.postRedisplay "listview empty qsearch";
3363 set1 m_active m_first
"";
3367 match search m_active
qsearch ~
-1 with
3369 state.text <- qsearch ^
" [not found]";
3372 state.text <- qsearch;
3373 active, firstof m_first
active
3375 G.postRedisplay "listview backspace qsearch";
3376 set1 active first qsearch
3379 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3380 let pattern = m_qsearch ^
Wsi.toutf8
key in
3382 match search m_active
pattern 1 with
3384 state.text <- pattern ^
" [not found]";
3387 state.text <- pattern;
3388 active, firstof m_first
active
3390 G.postRedisplay "listview qsearch add";
3391 set1 active first pattern;
3393 | 0xff1b -> (* escape *)
3395 if String.length m_qsearch
= 0
3397 G.postRedisplay "list view escape";
3400 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3402 | None
-> m_prev_uioh
3407 G.postRedisplay "list view kill qsearch";
3408 source#setqsearch
"";
3409 coe {< m_qsearch
= "" >}
3412 | 0xff0d -> (* return *)
3414 let self = {< m_qsearch
= "" >} in
3415 source#setqsearch
"";
3417 G.postRedisplay "listview enter";
3418 if m_active
>= 0 && m_active
< source#getitemcount
3420 source#exit
(coe self) false m_active m_first m_pan
"";
3423 source#exit
(coe self) true m_active m_first m_pan
"";
3426 begin match opt with
3427 | None
-> m_prev_uioh
3431 | 0xff9f | 0xffff -> (* delete *)
3434 | 0xff52 -> navigate ~
-1 (* up *)
3435 | 0xff54 -> navigate 1 (* down *)
3436 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3437 | 0xff56 -> navigate fstate.maxrows
(* next *)
3439 | 0xff53 -> (* right *)
3441 G.postRedisplay "listview right";
3442 coe {< m_pan
= m_pan
- 1 >}
3444 | 0xff51 -> (* left *)
3446 G.postRedisplay "listview left";
3447 coe {< m_pan
= m_pan
+ 1 >}
3449 | 0xff50 -> (* home *)
3450 let active = find 0 1 in
3451 G.postRedisplay "listview home";
3454 | 0xff57 -> (* end *)
3455 let first = max
0 (itemcount - fstate.maxrows
) in
3456 let active = find (itemcount - 1) ~
-1 in
3457 G.postRedisplay "listview end";
3460 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3464 dolog "listview unknown key %#x" key; coe self
3466 method key key mask
=
3467 match state.mode
with
3468 | Textentry te
-> textentrykeyboard key mask te
; coe self
3469 | _ -> self#key1
key mask
3471 method button button down
x y _ =
3474 | 1 when x > conf.winw
- conf.scrollbw
->
3475 G.postRedisplay "listview scroll";
3478 let _, position, sh = self#
scrollph in
3479 if y > truncate
position && y < truncate
(position +. sh)
3481 state.mstate
<- Mscrolly
;
3485 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3486 let first = truncate
(s *. float source#getitemcount
) in
3487 let first = min source#getitemcount
first in
3488 Some
(coe {< m_first
= first; m_active
= first >})
3490 state.mstate
<- Mnone
;
3493 | 1 when not down
->
3494 begin match self#elemunder
y with
3496 G.postRedisplay "listview click";
3498 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3502 | n when (n == 4 || n == 5) && not down
->
3503 let len = source#getitemcount
in
3505 if n = 5 && m_first
+ fstate.maxrows
>= len
3509 let first = m_first
+ (if n == 4 then -1 else 1) in
3510 bound first 0 (len - 1)
3512 G.postRedisplay "listview wheel";
3513 Some
(coe {< m_first
= first >})
3514 | n when (n = 6 || n = 7) && not down
->
3515 let inc = m_first
+ (if n = 7 then -1 else 1) in
3516 G.postRedisplay "listview hwheel";
3517 Some
(coe {< m_pan
= m_pan
+ inc >})
3522 | None
-> m_prev_uioh
3526 match state.mstate
with
3528 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3529 let first = truncate
(s *. float source#getitemcount
) in
3530 let first = min source#getitemcount
first in
3531 G.postRedisplay "listview motion";
3532 coe {< m_first
= first; m_active
= first >}
3535 method pmotion
x y =
3536 if x < conf.winw
- conf.scrollbw
3539 match self#elemunder
y with
3540 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3541 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3545 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3550 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3554 method infochanged
_ = ()
3556 method scrollpw
= (0, 0.0, 0.0)
3558 let nfs = fstate.fontsize
+ 1 in
3559 let y = m_first
* nfs in
3560 let itemcount = source#getitemcount
in
3561 let maxi = max
0 (itemcount - fstate.maxrows
) in
3562 let maxy = maxi * nfs in
3563 let p, h = scrollph y maxy in
3566 method modehash
= modehash
3569 class outlinelistview ~source
=
3572 ~source
:(source
:> lvsource
)
3574 ~modehash
:(findkeyhash conf "outline")
3577 method key key mask
=
3578 let calcfirst first active =
3581 let rows = active - first in
3583 if String.length
state.text = 0
3585 else fstate.maxrows - 2
3587 if rows > maxrows then active - maxrows else first
3591 let active = m_active
+ incr in
3592 let active = bound active 0 (source#getitemcount
- 1) in
3593 let first = calcfirst m_first
active in
3594 G.postRedisplay "outline navigate";
3595 coe {< m_active
= active; m_first
= first >}
3597 let ctrl = Wsi.withctrl mask
in
3599 | 110 when ctrl -> (* ctrl-n *)
3600 source#narrow m_qsearch
;
3601 G.postRedisplay "outline ctrl-n";
3602 coe {< m_first
= 0; m_active
= 0 >}
3604 | 117 when ctrl -> (* ctrl-u *)
3606 G.postRedisplay "outline ctrl-u";
3608 coe {< m_first
= 0; m_active
= 0 >}
3610 | 108 when ctrl -> (* ctrl-l *)
3611 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3612 G.postRedisplay "outline ctrl-l";
3613 coe {< m_first
= first >}
3615 | 0xff9f | 0xffff -> (* delete *)
3616 source#remove m_active
;
3617 G.postRedisplay "outline delete";
3618 let active = max
0 (m_active
-1) in
3619 coe {< m_first
= firstof m_first
active;
3620 m_active
= active >}
3622 | 0xff52 -> navigate ~
-1 (* up *)
3623 | 0xff54 -> navigate 1 (* down *)
3624 | 0xff55 -> (* prior *)
3625 navigate ~
-(fstate.maxrows)
3626 | 0xff56 -> (* next *)
3627 navigate fstate.maxrows
3629 | 0xff53 -> (* [ctrl-]right *)
3633 G.postRedisplay "outline ctrl right";
3634 {< m_pan
= m_pan
+ 1 >}
3636 else self#updownlevel
1
3640 | 0xff51 -> (* [ctrl-]left *)
3644 G.postRedisplay "outline ctrl left";
3645 {< m_pan
= m_pan
- 1 >}
3647 else self#updownlevel ~
-1
3651 | 0xff50 -> (* home *)
3652 G.postRedisplay "outline home";
3653 coe {< m_first
= 0; m_active
= 0 >}
3655 | 0xff57 -> (* end *)
3656 let active = source#getitemcount
- 1 in
3657 let first = max
0 (active - fstate.maxrows) in
3658 G.postRedisplay "outline end";
3659 coe {< m_active
= active; m_first
= first >}
3661 | _ -> super#
key key mask
3664 let outlinesource usebookmarks
=
3667 inherit lvsourcebase
3668 val mutable m_items
= empty
3669 val mutable m_orig_items
= empty
3670 val mutable m_prev_items
= empty
3671 val mutable m_narrow_pattern
= ""
3672 val mutable m_hadremovals
= false
3674 method getitemcount
=
3675 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3678 if n == Array.length m_items
&& m_hadremovals
3680 ("[Confirm removal]", 0)
3682 let s, n, _ = m_items
.(n) in
3685 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3686 ignore
(uioh
, first, qsearch);
3687 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3689 if String.length m_narrow_pattern
= 0
3695 if not
confrimremoval
3697 let _, _, anchor = m_items
.(active) in
3698 gotoghyll (getanchory anchor);
3702 state.bookmarks
<- Array.to_list m_items
;
3703 m_orig_items
<- m_items
;
3706 else m_items
<- items;
3710 method hasaction
_ = true
3713 if Array.length m_items
!= Array.length m_orig_items
3714 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3717 method narrow
pattern =
3718 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3722 let rec loop accu n =
3725 m_narrow_pattern
<- pattern;
3726 m_items
<- Array.of_list
accu
3729 let (s, _, _) as o = m_items
.(n) in
3731 if (try ignore
(Str.search_forward
re s 0); true
3732 with Not_found
-> false)
3738 loop [] (Array.length m_items
- 1)
3743 then Array.of_list
state.bookmarks
3746 m_items
<- m_orig_items
3751 if m >= 0 && m < Array.length m_items
3753 m_hadremovals
<- true;
3754 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3755 let n = if n >= m then n+1 else n in
3760 method reset
anchor items =
3761 m_hadremovals
<- false;
3762 if m_orig_items
== empty || m_prev_items
!= items
3764 m_orig_items
<- items;
3765 if String.length m_narrow_pattern
= 0
3766 then m_items
<- items;
3768 m_prev_items
<- items;
3769 let rely = getanchory anchor in
3771 let rec loop n best bestd
=
3772 if n = Array.length m_items
3775 let (_, _, anchor) = m_items
.(n) in
3776 let orely = getanchory anchor in
3777 let d = abs
(orely - rely) in
3780 else loop (n+1) best bestd
3785 m_first
<- firstof m_first
active
3789 let enterselector usebookmarks
=
3790 let source = outlinesource usebookmarks
in
3794 then Array.of_list
state.bookmarks
3797 if Array.length
outlines = 0
3799 showtext ' ' errmsg
;
3802 state.text <- source#greetmsg
;
3803 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3804 let anchor = getanchor () in
3805 source#reset
anchor outlines;
3806 state.uioh
<- coe (new outlinelistview ~
source);
3807 G.postRedisplay "enter selector";
3811 let enteroutlinemode =
3812 let f = enterselector false in
3813 fun ()-> f "Document has no outline";
3816 let enterbookmarkmode =
3817 let f = enterselector true in
3818 fun () -> f "Document has no bookmarks (yet)";
3821 let color_of_string s =
3822 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3823 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3827 let color_to_string (r, g
, b) =
3828 let r = truncate
(r *. 256.0)
3829 and g
= truncate
(g
*. 256.0)
3830 and b = truncate
(b *. 256.0) in
3831 Printf.sprintf
"%d/%d/%d" r g
b
3834 let irect_of_string s =
3835 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3838 let irect_to_string (x0,y0,x1,y1) =
3839 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3842 let makecheckers () =
3843 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3845 converted by Issac Trotts. July 25, 2002 *)
3846 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3847 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3848 let id = GlTex.gen_texture
() in
3849 GlTex.bind_texture `texture_2d
id;
3850 GlPix.store
(`unpack_alignment
1);
3851 GlTex.image2d
image;
3852 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3855 `mag_filter `nearest
;
3856 `min_filter `nearest
];
3860 let setcheckers enabled
=
3861 match state.texid
with
3863 if enabled
then state.texid
<- Some
(makecheckers ())
3868 GlTex.delete_texture texid
;
3869 state.texid
<- None
;
3873 let int_of_string_with_suffix s =
3874 let l = String.length
s in
3878 let suffix = Char.lowercase
s.[l-1] in
3880 | 'k'
-> String.sub
s 0 (l-1), 10
3881 | '
m'
-> String.sub
s 0 (l-1), 20
3882 | 'g'
-> String.sub
s 0 (l-1), 30
3886 let n = int_of_string
s1 in
3887 let m = n lsl shift
in
3889 then raise
(Failure
"value too large")
3893 let string_with_suffix_of_int n =
3898 if n land ((1 lsl 30) - 1) = 0
3901 if n land ((1 lsl 20) - 1) = 0
3904 if n land ((1 lsl 10) - 1) = 0
3911 let h = n mod 1000 in
3914 then string_of_int
h ^
s
3916 let s = Printf.sprintf
"_%03d%s" h s in
3923 let defghyllscroll = (40, 8, 32);;
3924 let ghyllscroll_of_string s =
3925 let (n, a, b) as nab
=
3928 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3930 if n <= a || n <= b || a >= b
3931 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3935 let ghyllscroll_to_string ((n, a, b) as nab
) =
3936 if nab
= defghyllscroll
3938 else Printf.sprintf
"%d,%d,%d" n a b;
3941 let describe_location () =
3943 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3945 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3946 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3950 else (100. *. (float state.y /. float maxy))
3954 Printf.sprintf
"page %d of %d [%.2f%%]"
3955 (fn+1) state.pagecount
percent
3958 "pages %d-%d of %d [%.2f%%]"
3959 (fn+1) (ln
+1) state.pagecount
percent
3962 let setpresentationmode v
=
3963 let (n, _, _) = getanchor () in
3964 let _, h = getpageyh n in
3965 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
3966 state.anchor <- (n, 0.0, float ips);
3967 conf.presentation
<- v
;
3968 if conf.presentation
3970 if not
conf.scrollbarinpm
3971 then state.scrollw
<- 0;
3973 else state.scrollw
<- conf.scrollbw
;
3978 let btos b = if b then "\xe2\x88\x9a" else "" in
3979 let showextended = ref false in
3980 let leave mode
= function
3981 | Confirm
-> state.mode
<- mode
3982 | Cancel
-> state.mode
<- mode
in
3985 val mutable m_first_time
= true
3986 val mutable m_l
= []
3987 val mutable m_a
= [||]
3988 val mutable m_prev_uioh
= nouioh
3989 val mutable m_prev_mode
= View
3991 inherit lvsourcebase
3993 method reset prev_mode prev_uioh
=
3994 m_a
<- Array.of_list
(List.rev m_l
);
3996 m_prev_mode
<- prev_mode
;
3997 m_prev_uioh
<- prev_uioh
;
4001 if n >= Array.length m_a
4005 | _, _, _, Action
_ -> m_active
<- n
4009 m_first_time
<- false;
4012 method int name get
set =
4014 (name
, `
int get
, 1, Action
(
4017 try set (int_of_string
s)
4019 state.text <- Printf.sprintf
"bad integer `%s': %s"
4020 s (Printexc.to_string exn
)
4023 let te = name ^
": ", "", None
, intentry, ondone, true in
4024 state.mode
<- Textentry
(te, leave m_prev_mode
);
4028 method int_with_suffix name get
set =
4030 (name
, `intws get
, 1, Action
(
4033 try set (int_of_string_with_suffix s)
4035 state.text <- Printf.sprintf
"bad integer `%s': %s"
4036 s (Printexc.to_string exn
)
4040 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4042 state.mode
<- Textentry
(te, leave m_prev_mode
);
4046 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4048 (name
, `
bool (btos, get
), offset
, Action
(
4055 method color name get
set =
4057 (name
, `color get
, 1, Action
(
4059 let invalid = (nan
, nan
, nan
) in
4062 try color_of_string s
4064 state.text <- Printf.sprintf
"bad color `%s': %s"
4065 s (Printexc.to_string exn
);
4071 let te = name ^
": ", "", None
, textentry, ondone, true in
4072 state.text <- color_to_string (get
());
4073 state.mode
<- Textentry
(te, leave m_prev_mode
);
4077 method string name get
set =
4079 (name
, `
string get
, 1, Action
(
4081 let ondone s = set s in
4082 let te = name ^
": ", "", None
, textentry, ondone, true in
4083 state.mode
<- Textentry
(te, leave m_prev_mode
);
4087 method colorspace name get
set =
4089 (name
, `
string get
, 1, Action
(
4092 let vals = [| "rgb"; "bgr"; "gray" |] in
4094 inherit lvsourcebase
4097 m_active
<- int_of_colorspace conf.colorspace
;
4100 method getitemcount
= Array.length
vals
4101 method getitem
n = (vals.(n), 0)
4102 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4103 ignore
(uioh
, first, pan
, qsearch);
4104 if not cancel
then set active;
4106 method hasaction
_ = true
4110 let modehash = findkeyhash conf "info" in
4111 coe (new listview ~
source ~trusted
:true ~
modehash)
4114 method caption
s offset
=
4115 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4117 method caption2
s f offset
=
4118 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4120 method getitemcount
= Array.length m_a
4123 let tostr = function
4124 | `
int f -> string_of_int
(f ())
4125 | `intws
f -> string_with_suffix_of_int (f ())
4127 | `color
f -> color_to_string (f ())
4128 | `
bool (btos, f) -> btos (f ())
4131 let name, t
, offset
, _ = m_a
.(n) in
4132 ((let s = tostr t
in
4133 if String.length
s > 0
4134 then Printf.sprintf
"%s\t%s" name s
4138 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4142 m_qsearch
<- qsearch;
4144 match m_a
.(active) with
4145 | _, _, _, Action
f -> f uioh
4157 method hasaction
n =
4159 | _, _, _, Action
_ -> true
4163 let rec fillsrc prevmode prevuioh
=
4164 let sep () = src#caption
"" 0 in
4165 let colorp name get
set =
4167 (fun () -> color_to_string (get
()))
4170 let c = color_of_string v in
4173 state.text <- Printf.sprintf
"bad color `%s': %s"
4174 v (Printexc.to_string exn
);
4177 let oldmode = state.mode
in
4178 let birdseye = isbirdseye state.mode
in
4180 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4182 src#
bool "presentation mode"
4183 (fun () -> conf.presentation
)
4184 (fun v -> setpresentationmode v);
4186 src#
bool "ignore case in searches"
4187 (fun () -> conf.icase
)
4188 (fun v -> conf.icase
<- v);
4191 (fun () -> conf.preload)
4192 (fun v -> conf.preload <- v);
4194 src#
bool "highlight links"
4195 (fun () -> conf.hlinks
)
4196 (fun v -> conf.hlinks
<- v);
4198 src#
bool "under info"
4199 (fun () -> conf.underinfo
)
4200 (fun v -> conf.underinfo
<- v);
4202 src#
bool "persistent bookmarks"
4203 (fun () -> conf.savebmarks
)
4204 (fun v -> conf.savebmarks
<- v);
4206 src#
bool "proportional display"
4207 (fun () -> conf.proportional
)
4208 (fun v -> reqlayout conf.angle
v);
4210 src#
bool "trim margins"
4211 (fun () -> conf.trimmargins
)
4212 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4214 src#
bool "persistent location"
4215 (fun () -> conf.jumpback
)
4216 (fun v -> conf.jumpback
<- v);
4219 src#
int "inter-page space"
4220 (fun () -> conf.interpagespace
)
4222 conf.interpagespace
<- n;
4223 docolumns conf.columns
;
4225 match state.layout with
4230 state.maxy <- calcheight ();
4231 let y = getpagey pageno in
4236 (fun () -> conf.pagebias
)
4237 (fun v -> conf.pagebias
<- v);
4239 src#
int "scroll step"
4240 (fun () -> conf.scrollstep
)
4241 (fun n -> conf.scrollstep
<- n);
4243 src#
int "horizontal scroll step"
4244 (fun () -> conf.hscrollstep
)
4245 (fun v -> conf.hscrollstep
<- v);
4247 src#
int "auto scroll step"
4249 match state.autoscroll
with
4251 | _ -> conf.autoscrollstep
)
4253 if state.autoscroll
<> None
4254 then state.autoscroll
<- Some
n;
4255 conf.autoscrollstep
<- n);
4258 (fun () -> truncate
(conf.zoom *. 100.))
4259 (fun v -> setzoom ((float v) /. 100.));
4262 (fun () -> conf.angle
)
4263 (fun v -> reqlayout v conf.proportional
);
4265 src#
int "scroll bar width"
4266 (fun () -> state.scrollw
)
4270 reshape conf.winw
conf.winh
;
4273 src#
int "scroll handle height"
4274 (fun () -> conf.scrollh
)
4275 (fun v -> conf.scrollh
<- v;);
4277 src#
int "thumbnail width"
4278 (fun () -> conf.thumbw
)
4280 conf.thumbw
<- min
4096 v;
4283 leavebirdseye beye
false;
4288 let mode = state.mode in
4289 src#
string "columns"
4291 match conf.columns
with
4293 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4294 | Csplit
(count
, _) -> "-" ^ string_of_int count
4297 let n, a, b = multicolumns_of_string v in
4298 setcolumns mode n a b);
4301 src#caption
"Presentation mode" 0;
4302 src#
bool "scrollbar visible"
4303 (fun () -> conf.scrollbarinpm
)
4305 if v != conf.scrollbarinpm
4307 conf.scrollbarinpm
<- v;
4308 if conf.presentation
4310 state.scrollw
<- if v then conf.scrollbw
else 0;
4311 reshape conf.winw
conf.winh
;
4317 src#caption
"Pixmap cache" 0;
4318 src#int_with_suffix
"size (advisory)"
4319 (fun () -> conf.memlimit
)
4320 (fun v -> conf.memlimit
<- v);
4323 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4324 (string_with_suffix_of_int state.memused
)
4325 (Hashtbl.length
state.tilemap
)) 1;
4328 src#caption
"Layout" 0;
4329 src#caption2
"Dimension"
4331 Printf.sprintf
"%dx%d (virtual %dx%d)"
4337 src#caption2
"Position" (fun () ->
4338 Printf.sprintf
"%dx%d" state.x state.y
4341 src#caption2
"Visible" (fun () -> describe_location ()) 1
4345 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4346 "Save these parameters as global defaults at exit"
4347 (fun () -> conf.bedefault
)
4348 (fun v -> conf.bedefault
<- v)
4352 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4353 src#
bool ~offset
:0 ~
btos "Extended parameters"
4354 (fun () -> !showextended)
4355 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4359 (fun () -> conf.checkers
)
4360 (fun v -> conf.checkers
<- v; setcheckers v);
4361 src#
bool "update cursor"
4362 (fun () -> conf.updatecurs
)
4363 (fun v -> conf.updatecurs
<- v);
4365 (fun () -> conf.verbose
)
4366 (fun v -> conf.verbose
<- v);
4367 src#
bool "invert colors"
4368 (fun () -> conf.invert
)
4369 (fun v -> conf.invert
<- v);
4371 (fun () -> conf.maxhfit
)
4372 (fun v -> conf.maxhfit
<- v);
4373 src#
bool "redirect stderr"
4374 (fun () -> conf.redirectstderr)
4375 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4376 src#
string "uri launcher"
4377 (fun () -> conf.urilauncher
)
4378 (fun v -> conf.urilauncher
<- v);
4379 src#
string "path launcher"
4380 (fun () -> conf.pathlauncher
)
4381 (fun v -> conf.pathlauncher
<- v);
4382 src#
string "tile size"
4383 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4386 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4387 conf.tilew
<- max
64 w;
4388 conf.tileh
<- max
64 h;
4391 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4392 v (Printexc.to_string exn
));
4393 src#
int "texture count"
4394 (fun () -> conf.texcount
)
4397 then conf.texcount
<- v
4398 else showtext '
!'
" Failed to set texture count please retry later"
4400 src#
int "slice height"
4401 (fun () -> conf.sliceheight
)
4403 conf.sliceheight
<- v;
4404 wcmd "sliceh %d" conf.sliceheight
;
4406 src#
int "anti-aliasing level"
4407 (fun () -> conf.aalevel
)
4409 conf.aalevel
<- bound v 0 8;
4410 state.anchor <- getanchor ();
4411 opendoc state.path
state.password
;
4413 src#
string "page scroll scaling factor"
4414 (fun () -> string_of_float
conf.pgscale)
4417 let s = float_of_string
v in
4420 state.text <- Printf.sprintf
4421 "bad page scroll scaling factor `%s': %s"
4422 v (Printexc.to_string exn
)
4425 src#
int "ui font size"
4426 (fun () -> fstate.fontsize
)
4427 (fun v -> setfontsize (bound v 5 100));
4428 src#
int "hint font size"
4429 (fun () -> conf.hfsize
)
4430 (fun v -> conf.hfsize
<- bound v 5 100);
4431 colorp "background color"
4432 (fun () -> conf.bgcolor
)
4433 (fun v -> conf.bgcolor
<- v);
4434 src#
bool "crop hack"
4435 (fun () -> conf.crophack
)
4436 (fun v -> conf.crophack
<- v);
4437 src#
string "trim fuzz"
4438 (fun () -> irect_to_string conf.trimfuzz
)
4441 conf.trimfuzz
<- irect_of_string v;
4443 then settrim true conf.trimfuzz
;
4445 state.text <- Printf.sprintf
"bad irect `%s': %s"
4446 v (Printexc.to_string exn
)
4448 src#
string "throttle"
4450 match conf.maxwait
with
4451 | None
-> "show place holder if page is not ready"
4454 then "wait for page to fully render"
4456 "wait " ^ string_of_float
time
4457 ^
" seconds before showing placeholder"
4461 let f = float_of_string
v in
4463 then conf.maxwait
<- None
4464 else conf.maxwait
<- Some
f
4466 state.text <- Printf.sprintf
"bad time `%s': %s"
4467 v (Printexc.to_string exn
)
4469 src#
string "ghyll scroll"
4471 match conf.ghyllscroll
with
4473 | Some nab
-> ghyllscroll_to_string nab
4478 if String.length
v = 0
4480 else Some
(ghyllscroll_of_string v)
4482 conf.ghyllscroll
<- gs
4484 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4485 v (Printexc.to_string exn
)
4487 src#
string "selection command"
4488 (fun () -> conf.selcmd
)
4489 (fun v -> conf.selcmd
<- v);
4490 src#colorspace
"color space"
4491 (fun () -> colorspace_to_string conf.colorspace
)
4493 conf.colorspace
<- colorspace_of_int v;
4500 (fun () -> conf.usepbo
)
4501 (fun v -> conf.usepbo
<- v);
4505 src#caption
"Document" 0;
4506 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4507 src#caption2
"Pages"
4508 (fun () -> string_of_int
state.pagecount
) 1;
4509 src#caption2
"Dimensions"
4510 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4514 src#caption
"Trimmed margins" 0;
4515 src#caption2
"Dimensions"
4516 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4520 src#caption
"OpenGL" 0;
4521 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4522 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4523 src#reset prevmode prevuioh
;
4527 let prevmode = state.mode
4528 and prevuioh
= state.uioh in
4529 fillsrc prevmode prevuioh
;
4530 let source = (src :> lvsource
) in
4531 let modehash = findkeyhash conf "info" in
4532 state.uioh <- coe (object (self)
4533 inherit listview ~
source ~trusted
:true ~
modehash as super
4534 val mutable m_prevmemused
= 0
4535 method infochanged
= function
4537 if m_prevmemused
!= state.memused
4539 m_prevmemused
<- state.memused
;
4540 G.postRedisplay "memusedchanged";
4542 | Pdim
-> G.postRedisplay "pdimchanged"
4543 | Docinfo
-> fillsrc prevmode prevuioh
4545 method key key mask
=
4546 if not
(Wsi.withctrl mask
)
4549 | 0xff51 -> coe (self#updownlevel ~
-1)
4550 | 0xff53 -> coe (self#updownlevel
1)
4551 | _ -> super#
key key mask
4552 else super#
key key mask
4554 G.postRedisplay "info";
4560 inherit lvsourcebase
4561 method getitemcount
= Array.length
state.help
4563 let s, l, _ = state.help
.(n) in
4566 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4570 m_qsearch
<- qsearch;
4571 match state.help
.(active) with
4572 | _, _, Action
f -> Some
(f uioh)
4582 method hasaction
n =
4583 match state.help
.(n) with
4584 | _, _, Action
_ -> true
4591 let modehash = findkeyhash conf "help" in
4592 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4593 G.postRedisplay "help";
4598 let re = Str.regexp
"[\r\n]" in
4600 inherit lvsourcebase
4601 val mutable m_items
= [||]
4603 method getitemcount
= 1 + Array.length m_items
4608 else m_items
.(n-1), 0
4610 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4615 then Buffer.clear
state.errmsgs
;
4616 m_qsearch
<- qsearch;
4623 method hasaction
n =
4627 state.newerrmsgs
<- false;
4628 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4629 m_items
<- Array.of_list
l
4637 let source = (msgsource :> lvsource
) in
4638 let modehash = findkeyhash conf "listview" in
4639 state.uioh <- coe (object
4640 inherit listview ~
source ~trusted
:false ~
modehash as super
4643 then msgsource#reset
;
4646 G.postRedisplay "msgs";
4649 let quickbookmark ?title
() =
4650 match state.layout with
4656 let sec = Unix.gettimeofday
() in
4657 let tm = Unix.localtime
sec in
4658 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4662 (tm.Unix.tm_year
+ 1900)
4665 | Some
title -> title
4667 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4671 state.fullscreen
<- None
;
4675 let setautoscrollspeed step goingdown
=
4676 let incr = max
1 ((abs step
) / 2) in
4677 let incr = if goingdown
then incr else -incr in
4678 let astep = step
+ incr in
4679 state.autoscroll
<- Some
astep;
4682 let gotounder = function
4683 | Ulinkgoto
(pageno, top) ->
4687 gotopage1 pageno top;
4693 | Uremote
(filename
, pageno) ->
4695 if Sys.file_exists filename
4698 let dir = Filename.dirname
state.path in
4699 let path = Filename.concat
dir filename
in
4700 if Sys.file_exists
path
4704 if String.length
path > 0
4706 let anchor = getanchor () in
4707 let ranchor = state.path, state.password
, anchor in
4708 state.anchor <- (pageno, 0.0, 0.0);
4709 state.ranchors
<- ranchor :: state.ranchors
;
4712 else showtext '
!'
("Could not find " ^ filename
)
4714 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4718 match conf.columns
with
4720 | _ -> conf.zoom > 1.0
4723 let viewkeyboard key mask
=
4725 let mode = state.mode in
4726 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4729 G.postRedisplay "view:enttext"
4731 let ctrl = Wsi.withctrl mask
in
4732 let existsinrow pageno (columns
, coverA
, coverB
) p =
4733 let last = ((pageno - coverA
) mod columns
) + columns
in
4734 let rec any = function
4737 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4741 then (if l.pageno = last then false else any rest
)
4751 | 0xff63 -> (* insert *)
4752 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4754 state.mode <- LinkNav
(Ltgendir
0);
4757 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4759 | 0xff1b | 113 -> (* escape / q *)
4760 begin match state.mstate
with
4762 state.mstate
<- Mnone
;
4763 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4764 G.postRedisplay "kill zoom rect";
4766 begin match state.mode with
4769 G.postRedisplay "esc leave linknav"
4771 match state.ranchors
with
4773 | (path, password
, anchor) :: rest
->
4774 state.ranchors
<- rest
;
4775 state.anchor <- anchor;
4776 opendoc path password
4780 | 0xff08 -> (* backspace *)
4781 gotoghyll (getnav ~
-1)
4789 G.postRedisplay "dehighlight";
4791 | 47 | 63 -> (* / ? *)
4792 let ondone isforw
s =
4793 cbput state.hists
.pat
s;
4794 state.searchpattern
<- s;
4797 let s = String.create
1 in
4798 s.[0] <- Char.chr
key;
4799 enttext (s, "", Some
(onhist state.hists
.pat
),
4800 textentry, ondone (key = 47), true)
4802 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4803 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4804 setzoom (conf.zoom +. incr)
4806 | 43 | 0xffab -> (* + *)
4809 try int_of_string
s with exc
->
4810 state.text <- Printf.sprintf
"bad integer `%s': %s"
4811 s (Printexc.to_string exc
);
4817 state.text <- "page bias is now " ^ string_of_int
n;
4820 enttext ("page bias: ", "", None
, intentry, ondone, true)
4822 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4823 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4824 setzoom (max
0.01 (conf.zoom -. decr))
4826 | 45 | 0xffad -> (* - *)
4827 let ondone msg
= state.text <- msg
in
4829 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4830 optentry state.mode, ondone, true
4833 | 48 when ctrl -> (* ctrl-0 *)
4836 | 49 when ctrl -> (* ctrl-1 *)
4838 match conf.columns
with
4839 | Csingle
_ | Cmulti
_ -> 1
4840 | Csplit
(n, _) -> n
4842 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4846 | 0xffc6 -> (* f9 *)
4849 | 57 when ctrl -> (* ctrl-9 *)
4852 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4853 when not
ctrl -> (* 0..9 *)
4856 try int_of_string
s with exc
->
4857 state.text <- Printf.sprintf
"bad integer `%s': %s"
4858 s (Printexc.to_string exc
);
4864 cbput state.hists
.pag
(string_of_int
n);
4865 gotopage1 (n + conf.pagebias
- 1) 0;
4868 let pageentry text key =
4869 match Char.unsafe_chr
key with
4870 | 'g'
-> TEdone
text
4871 | _ -> intentry text key
4873 let text = "x" in text.[0] <- Char.chr
key;
4874 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4877 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4878 reshape conf.winw
conf.winh
;
4881 conf.hlinks
<- not
conf.hlinks
;
4882 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4883 G.postRedisplay "toggle highlightlinks";
4886 state.glinks
<- true;
4887 let mode = state.mode in
4888 state.mode <- Textentry
(
4889 (":", "", None
, linknentry, linkndone gotounder, false),
4891 state.glinks
<- false;
4895 G.postRedisplay "view:linkent(F)"
4898 state.glinks
<- true;
4899 let mode = state.mode in
4900 state.mode <- Textentry
(
4901 (":", "", None
, linknentry, linkndone (fun under ->
4902 match Ne.pipe () with
4904 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4905 (Printexc.to_string exn
));
4908 try popen conf.selcmd
[r, 0; w, -1]; true
4911 (Printf.sprintf
"failed to execute %s: %s"
4912 conf.selcmd
(Printexc.to_string exn
));
4916 Ne.clo fd
(fun msg
->
4917 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4920 let s = undertext under in
4924 let l = String.length
s in
4925 let n = Unix.write
w s 0 l in
4930 "failed to write %d characters to sel pipe, wrote %d"
4935 (Printf.sprintf
"failed to write to sel pipe: %s"
4936 (Printexc.to_string exn
)
4945 state.glinks
<- false;
4949 G.postRedisplay "view:linkent"
4952 begin match state.autoscroll
with
4954 conf.autoscrollstep
<- step
;
4955 state.autoscroll
<- None
4957 if conf.autoscrollstep
= 0
4958 then state.autoscroll
<- Some
1
4959 else state.autoscroll
<- Some
conf.autoscrollstep
4962 | 112 when ctrl -> (* ctrl-p *)
4966 setpresentationmode (not
conf.presentation
);
4967 showtext ' '
("presentation mode " ^
4968 if conf.presentation
then "on" else "off");
4971 begin match state.fullscreen
with
4973 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4976 state.fullscreen
<- None
;
4980 | 112 | 78 -> (* p|N *)
4981 search state.searchpattern
false
4983 | 110 | 0xffc0 -> (* n|F3 *)
4984 search state.searchpattern
true
4987 begin match state.layout with
4990 gotoy_and_clear_text (getpagey l.pageno)
4994 begin match state.layout with
4997 match conf.columns
with
4999 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5001 let y = clamp (pgscale conf.winh
) in
5004 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5005 gotoghyll (getpagey pageno)
5006 | Cmulti
((c, _, _) as cl
, _) ->
5007 if conf.presentation
5008 && (existsinrow l.pageno cl
5009 (fun l -> l.pageh
> l.pagey + l.pagevh))
5011 let y = clamp (pgscale conf.winh
) in
5014 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5015 gotoghyll (getpagey pageno)
5017 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5019 let pagey, pageh
= getpageyh l.pageno in
5020 let pagey = pagey + pageh
* l.pagecol
in
5021 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5022 gotoghyll (pagey + pageh
+ ips)
5025 | 0xff9f | 0xffff -> (* delete *)
5026 begin match state.layout with
5029 match conf.columns
with
5031 if conf.presentation
&& l.pagey != 0
5033 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
5035 let pageno = max
0 (l.pageno-1) in
5036 gotoghyll (getpagey pageno)
5037 | Cmulti
((c, _, coverB
) as cl
, _) ->
5038 if conf.presentation
&&
5039 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
5041 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
5044 if l.pageno = state.pagecount
- coverB
5048 let pageno = max
0 (l.pageno-decr) in
5049 gotoghyll (getpagey pageno)
5057 let pageno = max
0 (l.pageno-1) in
5058 let pagey, pageh
= getpageyh pageno in
5061 let pagey, pageh
= getpageyh l.pageno in
5062 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5068 showtext ' '
(describe_location ());
5071 begin match state.layout with
5074 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5079 enterbookmarkmode ()
5081 | 104 | 0xffbe -> (* h|F1 *)
5087 | 101 when conf.redirectstderr -> (* e *)
5092 match state.layout with
5093 | l :: _ -> state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5096 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5100 showtext ' '
"Quick bookmark added";
5103 begin match state.layout with
5105 let rect = getpdimrect
l.pagedimno
in
5109 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5110 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5112 (truncate
(rect.(1) -. rect.(0)),
5113 truncate
(rect.(3) -. rect.(0)))
5115 let w = truncate
((float w)*.conf.zoom)
5116 and h = truncate
((float h)*.conf.zoom) in
5119 state.anchor <- getanchor ();
5120 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5122 G.postRedisplay "z";
5127 | 50 when ctrl -> (* ctrl-2 *)
5128 let maxw = getmaxw
() in
5130 then setzoom (maxw /. float conf.winw
)
5132 | 60 | 62 -> (* < > *)
5133 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5135 | 91 | 93 -> (* [ ] *)
5137 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5139 G.postRedisplay "brightness";
5141 | 99 when state.mode = View
-> (* c *)
5143 match state.prevcolumns
with
5144 | None
-> (1, 0, 0), 1.0
5145 | Some
(columns
, z
) ->
5148 | Csplit
(c, _) -> -c, 0, 0
5149 | Cmulti
((c, a, b), _) -> c, a, b
5150 | Csingle
_ -> 1, 0, 0
5154 setcolumns View
c a b;
5157 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5158 setzoom state.prevzoom
5160 | 107 | 0xff52 -> (* k up *)
5161 begin match state.autoscroll
with
5163 begin match state.mode with
5164 | Birdseye beye
-> upbirdseye 1 beye
5167 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5168 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5171 setautoscrollspeed n false
5174 | 106 | 0xff54 -> (* j down *)
5175 begin match state.autoscroll
with
5177 begin match state.mode with
5178 | Birdseye beye
-> downbirdseye 1 beye
5181 then gotoy_and_clear_text (clamp (conf.winh
/2))
5182 else gotoy_and_clear_text (clamp conf.scrollstep
)
5185 setautoscrollspeed n true
5188 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5194 else conf.hscrollstep
5196 let dx = if key = 0xff51 then dx else -dx in
5197 state.x <- state.x + dx;
5198 gotoy_and_clear_text state.y
5201 G.postRedisplay "lef/right"
5204 | 0xff55 -> (* prior *)
5208 match state.layout with
5210 | l :: _ -> state.y - l.pagey
5212 clamp (pgscale (-conf.winh
))
5216 | 0xff56 -> (* next *)
5220 match List.rev
state.layout with
5222 | l :: _ -> getpagey l.pageno
5224 clamp (pgscale conf.winh
)
5228 | 103 | 0xff50 -> (* g home *)
5230 | 71 | 0xff57 -> (* G end *)
5231 gotoghyll (clamp state.maxy)
5233 | 0xff53 when Wsi.withalt mask
-> (* alt-right *)
5234 gotoghyll (getnav 1)
5235 | 0xff51 when Wsi.withalt mask
-> (* alt-left *)
5236 gotoghyll (getnav ~
-1)
5241 | 118 when conf.debug
-> (* v *)
5244 match getopaque l.pageno with
5247 let x0, y0, x1, y1 = pagebbox opaque
in
5248 let a,b = float x0, float y0 in
5249 let c,d = float x1, float y0 in
5250 let e,f = float x1, float y1 in
5251 let h,j
= float x0, float y1 in
5252 let rect = (a,b,c,d,e,f,h,j
) in
5254 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5256 G.postRedisplay "v";
5259 vlog "huh? %s" (Wsi.keyname
key)
5262 let linknavkeyboard key mask
linknav =
5263 let getpage pageno =
5264 let rec loop = function
5266 | l :: _ when l.pageno = pageno -> Some
l
5267 | _ :: rest
-> loop rest
5268 in loop state.layout
5270 let doexact (pageno, n) =
5271 match getopaque pageno, getpage pageno with
5272 | Some opaque
, Some
l ->
5275 let under = getlink opaque
n in
5276 G.postRedisplay "link gotounder";
5282 | 0xff50 -> (* home *)
5283 Some
(findlink opaque LDfirst
), -1
5285 | 0xff57 -> (* end *)
5286 Some
(findlink opaque LDlast
), 1
5288 | 0xff51 -> (* left *)
5289 Some
(findlink opaque
(LDleft
n)), -1
5291 | 0xff53 -> (* right *)
5292 Some
(findlink opaque
(LDright
n)), 1
5294 | 0xff52 -> (* up *)
5295 Some
(findlink opaque
(LDup
n)), -1
5297 | 0xff54 -> (* down *)
5298 Some
(findlink opaque
(LDdown
n)), 1
5303 begin match findpwl
l.pageno dir with
5307 state.mode <- LinkNav
(Ltgendir
dir);
5308 let y, h = getpageyh pageno in
5311 then y + h - conf.winh
5316 begin match getopaque pageno, getpage pageno with
5317 | Some opaque
, Some
_ ->
5319 let ld = if dir > 0 then LDfirst
else LDlast
in
5322 begin match link with
5324 showlinktype (getlink opaque
m);
5325 state.mode <- LinkNav
(Ltexact
(pageno, m));
5326 G.postRedisplay "linknav jpage";
5333 begin match opt with
5334 | Some Lnotfound
-> pwl l dir;
5335 | Some
(Lfound
m) ->
5339 let _, y0, _, y1 = getlinkrect opaque
m in
5341 then gotopage1 l.pageno y0
5343 let d = fstate.fontsize
+ 1 in
5344 if y1 - l.pagey > l.pagevh - d
5345 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5346 else G.postRedisplay "linknav";
5348 showlinktype (getlink opaque
m);
5349 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5352 | None
-> viewkeyboard key mask
5354 | _ -> viewkeyboard key mask
5359 G.postRedisplay "leave linknav"
5363 | Ltgendir
_ -> viewkeyboard key mask
5364 | Ltexact exact
-> doexact exact
5367 let keyboard key mask
=
5368 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5369 then wcmd "interrupt"
5370 else state.uioh <- state.uioh#
key key mask
5373 let birdseyekeyboard key mask
5374 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5376 match conf.columns
with
5378 | Cmulti
((c, _, _), _) -> c
5379 | Csplit
_ -> failwith
"bird's eye split mode"
5381 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5383 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5384 let y, h = getpageyh pageno in
5385 let top = (conf.winh
- h) / 2 in
5386 gotoy (max
0 (y - top))
5387 | 0xff0d -> leavebirdseye beye
false
5388 | 0xff1b -> leavebirdseye beye
true (* escape *)
5389 | 0xff52 -> upbirdseye incr beye
(* up *)
5390 | 0xff54 -> downbirdseye incr beye
(* down *)
5391 | 0xff51 -> upbirdseye 1 beye
(* left *)
5392 | 0xff53 -> downbirdseye 1 beye
(* right *)
5394 | 0xff55 -> (* prior *)
5395 begin match state.layout with
5399 state.mode <- Birdseye
(
5400 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5402 gotopage1 l.pageno 0;
5405 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5407 | [] -> gotoy (clamp (-conf.winh
))
5409 state.mode <- Birdseye
(
5410 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5412 gotopage1 l.pageno 0
5415 | [] -> gotoy (clamp (-conf.winh
))
5418 | 0xff56 -> (* next *)
5419 begin match List.rev
state.layout with
5421 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5422 begin match layout with
5424 let incr = l.pageh
- l.pagevh in
5429 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5431 G.postRedisplay "birdseye pagedown";
5433 else gotoy (clamp (incr + conf.interpagespace
*2));
5437 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5438 gotopage1 l.pageno 0;
5441 | [] -> gotoy (clamp conf.winh
)
5444 | 0xff50 -> (* home *)
5445 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5448 | 0xff57 -> (* end *)
5449 let pageno = state.pagecount
- 1 in
5450 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5451 if not
(pagevisible state.layout pageno)
5454 match List.rev
state.pdims
with
5456 | (_, _, h, _) :: _ -> h
5458 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5459 else G.postRedisplay "birdseye end";
5460 | _ -> viewkeyboard key mask
5463 let drawpage l linkindexbase
=
5465 match state.mode with
5466 | Textentry
_ -> scalecolor 0.4
5468 | View
-> scalecolor 1.0
5469 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5470 if l.pageno = hooverpageno
5473 if l.pageno = pageno
5479 begin match getopaque l.pageno with
5481 if tileready l l.pagex
l.pagey
5483 let x = l.pagedispx - l.pagex
5484 and y = l.pagedispy - l.pagey in
5486 match conf.columns
with
5487 | Csingle
_ | Cmulti
_ ->
5488 (if conf.hlinks
then 1 else 0)
5490 && not
(isbirdseye state.mode) then 2 else 0)
5494 match state.mode with
5495 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5498 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5505 let scrollindicator () =
5506 let sbw, ph
, sh = state.uioh#
scrollph in
5507 let sbh, pw, sw = state.uioh#scrollpw
in
5509 GlDraw.color (0.64, 0.64, 0.64);
5511 (float (conf.winw
- sbw), 0.)
5512 (float conf.winw
, float conf.winh
)
5515 (0., float (conf.winh
- sbh))
5516 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5518 GlDraw.color (0.0, 0.0, 0.0);
5521 (float (conf.winw
- sbw), ph
)
5522 (float conf.winw
, ph
+. sh)
5525 (pw, float (conf.winh
- sbh))
5526 (pw +. sw, float conf.winh
)
5531 match state.mstate
with
5532 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5535 | Msel
((x0, y0), (x1, y1)) ->
5536 let rec loop = function
5538 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5539 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5540 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5541 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5543 match getopaque l.pageno with
5545 let x0, y0 = pagetranslatepoint l x0 y0 in
5546 let x1, y1 = pagetranslatepoint l x1 y1 in
5547 seltext opaque
(x0, y0, x1, y1);
5555 let showrects rects
=
5557 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5558 GlDraw.polygon_mode `both `fill
;
5559 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5561 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5563 if l.pageno = pageno
5565 let dx = float (l.pagedispx - l.pagex
) in
5566 let dy = float (l.pagedispy - l.pagey) in
5567 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5568 GlDraw.begins `quads
;
5570 GlDraw.vertex2
(x0+.dx, y0+.dy);
5571 GlDraw.vertex2
(x1+.dx, y1+.dy);
5572 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5573 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5584 GlClear.color (scalecolor2 conf.bgcolor
);
5585 GlClear.clear
[`
color];
5586 let rec loop linkindexbase
= function
5588 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5589 loop linkindexbase rest
5592 loop 0 state.layout;
5594 match state.mode with
5595 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5596 begin match getopaque pageno with
5598 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5605 | None
-> state.rects
5612 begin match state.mstate
with
5613 | Mzoomrect
((x0, y0), (x1, y1)) ->
5615 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5616 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5617 GlDraw.rect (float x0, float y0)
5618 (float x1, float y1);
5627 let zoomrect x y x1 y1 =
5630 and y0 = min
y y1 in
5631 gotoy (state.y + y0);
5632 state.anchor <- getanchor ();
5633 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5635 if state.w < conf.winw
- state.scrollw
5636 then (conf.winw
- state.scrollw
- state.w) / 2
5639 state.x <- (state.x + margin) - x0;
5641 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5642 state.mstate
<- Mnone
;
5646 let winw = conf.winw - state.scrollw
- 1 in
5647 let s = float x /. float winw in
5648 let destx = truncate
(float (state.w + winw) *. s) in
5649 state.x <- winw - destx;
5650 gotoy_and_clear_text state.y;
5651 state.mstate
<- Mscrollx
;
5655 let s = float y /. float conf.winh
in
5656 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5657 gotoy_and_clear_text desty;
5658 state.mstate
<- Mscrolly
;
5661 let viewmouse button down
x y mask
=
5663 | n when (n == 4 || n == 5) && not down
->
5664 if Wsi.withctrl mask
5666 match state.mstate
with
5667 | Mzoom
(oldn
, i
) ->
5675 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5677 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5679 let zoom = conf.zoom -. incr in
5681 state.mstate
<- Mzoom
(n, 0);
5683 state.mstate
<- Mzoom
(n, i
+1);
5685 else state.mstate
<- Mzoom
(n, 0)
5687 | _ -> state.mstate
<- Mzoom
(n, 0)
5690 match state.autoscroll
with
5691 | Some step
-> setautoscrollspeed step
(n=4)
5695 then -conf.scrollstep
5696 else conf.scrollstep
5698 let incr = incr * 2 in
5699 let y = clamp incr in
5700 gotoy_and_clear_text y
5703 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5704 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5705 gotoy_and_clear_text state.y
5707 | 1 when Wsi.withctrl mask
->
5710 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5711 state.mstate
<- Mpan
(x, y)
5714 state.mstate
<- Mnone
5719 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5721 state.mstate
<- Mzoomrect
(p, p)
5724 match state.mstate
with
5725 | Mzoomrect
((x0, y0), _) ->
5726 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5727 then zoomrect x0 y0 x y
5729 state.mstate
<- Mnone
;
5730 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5731 G.postRedisplay "kill accidental zoom rect";
5734 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5735 state.mstate
<- Mnone
5738 | 1 when x > conf.winw - state.scrollw
->
5741 let _, position, sh = state.uioh#
scrollph in
5742 if y > truncate
position && y < truncate
(position +. sh)
5743 then state.mstate
<- Mscrolly
5746 state.mstate
<- Mnone
5748 | 1 when y > conf.winh
- state.hscrollh ->
5751 let _, position, sw = state.uioh#scrollpw
in
5752 if x > truncate
position && x < truncate
(position +. sw)
5753 then state.mstate
<- Mscrollx
5756 state.mstate
<- Mnone
5759 let dest = if down
then getunder x y else Unone
in
5760 begin match dest with
5764 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5767 | Unone
when down
->
5768 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5769 state.mstate
<- Mpan
(x, y);
5771 | Unone
| Utext
_ ->
5774 if conf.angle
mod 360 = 0
5776 state.mstate
<- Msel
((x, y), (x, y));
5777 G.postRedisplay "mouse select";
5781 match state.mstate
with
5784 | Mzoom
_ | Mscrollx
| Mscrolly
->
5785 state.mstate
<- Mnone
5787 | Mzoomrect
((x0, y0), _) ->
5791 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5792 state.mstate
<- Mnone
5794 | Msel
((x0, y0), (x1, y1)) ->
5795 let rec loop = function
5799 let a0 = l.pagedispy in
5800 let a1 = a0 + l.pagevh in
5801 let b0 = l.pagedispx in
5802 let b1 = b0 + l.pagevw in
5803 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5804 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5808 match getopaque l.pageno with
5811 match Ne.pipe () with
5815 "can not create sel pipe: %s"
5816 (Printexc.to_string exn
));
5818 let doclose what fd
=
5819 Ne.clo fd
(fun msg
->
5820 dolog "%s close failed: %s" what msg
)
5823 popen conf.selcmd
[r, 0; w, -1];
5826 G.postRedisplay "copysel";
5828 dolog "can not execute %S: %s"
5829 conf.selcmd
(Printexc.to_string exn
);
5837 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5838 state.mstate
<- Mnone
;
5845 let birdseyemouse button down
x y mask
5846 (conf, leftx
, _, hooverpageno
, anchor) =
5849 let rec loop = function
5852 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5853 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5855 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5861 | _ -> viewmouse button down
x y mask
5864 let mouse button down
x y mask
=
5865 state.uioh <- state.uioh#button button down
x y mask
;
5869 state.uioh <- state.uioh#
motion x y
5873 state.uioh <- state.uioh#
pmotion x y;
5879 method key key mask
=
5880 begin match state.mode with
5881 | Textentry
textentry -> textentrykeyboard key mask
textentry
5882 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5883 | View
-> viewkeyboard key mask
5884 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5888 method button button bstate
x y mask
=
5889 begin match state.mode with
5891 | View
-> viewmouse button bstate
x y mask
5892 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5898 begin match state.mode with
5900 | View
| Birdseye
_ | LinkNav
_ ->
5901 match state.mstate
with
5902 | Mzoom
_ | Mnone
-> ()
5907 state.mstate
<- Mpan
(x, y);
5909 then state.x <- state.x + dx;
5911 gotoy_and_clear_text y
5914 state.mstate
<- Msel
(a, (x, y));
5915 G.postRedisplay "motion select";
5918 let y = min
conf.winh
(max
0 y) in
5922 let x = min
conf.winw (max
0 x) in
5925 | Mzoomrect
(p0
, _) ->
5926 state.mstate
<- Mzoomrect
(p0
, (x, y));
5927 G.postRedisplay "motion zoomrect";
5931 method pmotion x y =
5932 begin match state.mode with
5933 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5934 let rec loop = function
5936 if hooverpageno
!= -1
5938 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5939 G.postRedisplay "pmotion birdseye no hoover";
5942 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5943 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5945 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5946 G.postRedisplay "pmotion birdseye hoover";
5956 match state.mstate
with
5957 | Mnone
-> updateunder x y
5958 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5963 method infochanged
_ = ()
5966 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5967 let p, h = scrollph state.y maxy in
5971 let winw = conf.winw - state.scrollw
- 1 in
5972 let fwinw = float winw in
5974 let sw = fwinw /. float state.w in
5975 let sw = fwinw *. sw in
5976 max
sw (float conf.scrollh
)
5979 let f = state.w+winw in
5980 let r = float (winw-state.x) /. float f in
5981 let p = fwinw *. r in
5985 if position +. sw > fwinw
5986 then fwinw -. position
5989 state.hscrollh, position, sw
5993 match state.mode with
5994 | LinkNav
_ -> "links"
5995 | Textentry
_ -> "textentry"
5996 | Birdseye
_ -> "birdseye"
5999 findkeyhash conf modename
6006 let fontpath = ref "";;
6009 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6012 let l = String.length
s in
6013 let b = Buffer.create
l in
6019 try Sys.getenv
"HOME"
6022 ("Can not determine home directory location: " ^
6023 Printexc.to_string exn
);
6027 let modifier_of_string = function
6028 | "alt" -> Wsi.altmask
6029 | "shift" -> Wsi.shiftmask
6030 | "ctrl" | "control" -> Wsi.ctrlmask
6031 | "meta" -> Wsi.metamask
6036 let r = Str.regexp
"-" in
6038 let elems = Str.full_split
r s in
6041 let m1 = modifier_of_string s in
6043 then (Wsi.namekey
s, m)
6046 | Str.Delim
s when n land 1 = 0 -> g s
6048 | Str.Delim
_ -> (k
, m)
6050 let rec loop n k
m = function
6053 let k, m = f n k m x in
6059 let keys_of_string =
6060 let r = Str.regexp
"[ \t]" in
6062 let elems = Str.split
r s in
6063 List.map
key_of_string elems
6066 let copykeyhashes c =
6067 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6070 let config_of c attrs
=
6074 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6075 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6076 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6077 | "preload" -> { c with preload = bool_of_string
v }
6078 | "page-bias" -> { c with pagebias
= int_of_string
v }
6079 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6080 | "horizontal-scroll-step" ->
6081 { c with hscrollstep
= max
(int_of_string
v) 1 }
6082 | "auto-scroll-step" ->
6083 { c with autoscrollstep
= max
0 (int_of_string
v) }
6084 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6085 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6088 match String.lowercase
v with
6089 | "true" -> Some infinity
6091 | f -> Some
(float_of_string
f)
6093 { c with maxwait
= mw}
6094 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6095 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6096 | "vertical-margin" ->
6097 { c with interpagespace
= max
0 (int_of_string
v) }
6099 let zoom = float_of_string
v /. 100. in
6100 let zoom = max
zoom 0.0 in
6101 { c with zoom = zoom }
6102 | "presentation" -> { c with presentation
= bool_of_string
v }
6103 | "rotation-angle" -> { c with angle
= int_of_string
v }
6104 | "width" -> { c with winw = max
20 (int_of_string
v) }
6105 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6106 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6107 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6108 | "pixmap-cache-size" ->
6109 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6110 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6111 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6112 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6113 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6114 | "background-color" -> { c with bgcolor
= color_of_string v }
6115 | "scrollbar-in-presentation" ->
6116 { c with scrollbarinpm
= bool_of_string
v }
6117 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6118 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6119 | "mupdf-store-size" ->
6120 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6121 | "checkers" -> { c with checkers
= bool_of_string
v }
6122 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6123 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6124 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6125 | "uri-launcher" -> { c with urilauncher
= unent v }
6126 | "path-launcher" -> { c with pathlauncher
= unent v }
6127 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6128 | "invert-colors" -> { c with invert
= bool_of_string
v }
6129 | "brightness" -> { c with colorscale
= float_of_string
v }
6130 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6132 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6134 let (n, _, _) as nab
= multicolumns_of_string v in
6136 then { c with columns
= Csplit
(-n, [||]) }
6137 else { c with columns
= Cmulti
(nab
, [||]) }
6138 | "birds-eye-columns" ->
6139 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6140 | "selection-command" -> { c with selcmd
= unent v }
6141 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6142 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6143 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6144 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6147 prerr_endline
("Error processing attribute (`" ^
6148 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6151 let rec fold c = function
6154 let c = apply c k v in
6157 fold { c with keyhashes
= copykeyhashes c } attrs
;
6160 let fromstring f pos
n v d =
6163 dolog "Error processing attribute (%S=%S) at %d\n%s"
6164 n v pos
(Printexc.to_string exn
)
6169 let bookmark_of attrs
=
6170 let rec fold title page
rely visy
= function
6171 | ("title", v) :: rest
-> fold v page
rely visy rest
6172 | ("page", v) :: rest
-> fold title v rely visy rest
6173 | ("rely", v) :: rest
-> fold title page
v visy rest
6174 | ("visy", v) :: rest
-> fold title page
rely v rest
6175 | _ :: rest
-> fold title page
rely visy rest
6176 | [] -> title, page
, rely, visy
6178 fold "invalid" "0" "0" "0" attrs
6182 let rec fold path page
rely pan visy
= function
6183 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6184 | ("page", v) :: rest
-> fold path v rely pan visy rest
6185 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6186 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6187 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6188 | _ :: rest
-> fold path page
rely pan visy rest
6189 | [] -> path, page
, rely, pan
, visy
6191 fold "" "0" "0" "0" "0" attrs
6195 let rec fold rs ls
= function
6196 | ("out", v) :: rest
-> fold v ls rest
6197 | ("in", v) :: rest
-> fold rs
v rest
6198 | _ :: rest
-> fold ls rs rest
6204 let setconf dst
src =
6205 dst
.scrollbw
<- src.scrollbw
;
6206 dst
.scrollh
<- src.scrollh
;
6207 dst
.icase
<- src.icase
;
6208 dst
.preload <- src.preload;
6209 dst
.pagebias
<- src.pagebias
;
6210 dst
.verbose
<- src.verbose
;
6211 dst
.scrollstep
<- src.scrollstep
;
6212 dst
.maxhfit
<- src.maxhfit
;
6213 dst
.crophack
<- src.crophack
;
6214 dst
.autoscrollstep
<- src.autoscrollstep
;
6215 dst
.maxwait
<- src.maxwait
;
6216 dst
.hlinks
<- src.hlinks
;
6217 dst
.underinfo
<- src.underinfo
;
6218 dst
.interpagespace
<- src.interpagespace
;
6219 dst
.zoom <- src.zoom;
6220 dst
.presentation
<- src.presentation
;
6221 dst
.angle
<- src.angle
;
6222 dst
.winw <- src.winw;
6223 dst
.winh
<- src.winh
;
6224 dst
.savebmarks
<- src.savebmarks
;
6225 dst
.memlimit
<- src.memlimit
;
6226 dst
.proportional
<- src.proportional
;
6227 dst
.texcount
<- src.texcount
;
6228 dst
.sliceheight
<- src.sliceheight
;
6229 dst
.thumbw
<- src.thumbw
;
6230 dst
.jumpback
<- src.jumpback
;
6231 dst
.bgcolor
<- src.bgcolor
;
6232 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6233 dst
.tilew
<- src.tilew
;
6234 dst
.tileh
<- src.tileh
;
6235 dst
.mustoresize
<- src.mustoresize
;
6236 dst
.checkers
<- src.checkers
;
6237 dst
.aalevel
<- src.aalevel
;
6238 dst
.trimmargins
<- src.trimmargins
;
6239 dst
.trimfuzz
<- src.trimfuzz
;
6240 dst
.urilauncher
<- src.urilauncher
;
6241 dst
.colorspace
<- src.colorspace
;
6242 dst
.invert
<- src.invert
;
6243 dst
.colorscale
<- src.colorscale
;
6244 dst
.redirectstderr <- src.redirectstderr;
6245 dst
.ghyllscroll
<- src.ghyllscroll
;
6246 dst
.columns
<- src.columns
;
6247 dst
.beyecolumns
<- src.beyecolumns
;
6248 dst
.selcmd
<- src.selcmd
;
6249 dst
.updatecurs
<- src.updatecurs
;
6250 dst
.pathlauncher
<- src.pathlauncher
;
6251 dst
.keyhashes
<- copykeyhashes src;
6252 dst
.hfsize
<- src.hfsize
;
6253 dst
.hscrollstep
<- src.hscrollstep
;
6254 dst
.pgscale <- src.pgscale;
6255 dst
.usepbo
<- src.usepbo
;
6259 let h = Hashtbl.create
10 in
6260 let dc = { defconf with angle
= defconf.angle
} in
6261 let rec toplevel v t spos
_ =
6263 | Vdata
| Vcdata
| Vend
-> v
6264 | Vopen
("llppconfig", _, closed
) ->
6267 else { v with f = llppconfig
}
6269 error
"unexpected subelement at top level" s spos
6270 | Vclose
_ -> error
"unexpected close at top level" s spos
6272 and llppconfig
v t spos
_ =
6274 | Vdata
| Vcdata
-> v
6275 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6276 | Vopen
("defaults", attrs
, closed
) ->
6277 let c = config_of dc attrs
in
6281 else { v with f = defaults
}
6283 | Vopen
("ui-font", attrs
, closed
) ->
6284 let rec getsize size
= function
6286 | ("size", v) :: rest
->
6288 fromstring int_of_string spos
"size" v fstate.fontsize
in
6290 | l -> getsize size l
6292 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6295 else { v with f = uifont
(Buffer.create
10) }
6297 | Vopen
("doc", attrs
, closed
) ->
6298 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6299 let path = unent pathent
6300 and pageno = fromstring int_of_string spos
"page" spage
0
6301 and rely = fromstring float_of_string spos
"rely" srely
0.0
6302 and pan
= fromstring int_of_string spos
"pan" span
0
6303 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6304 let c = config_of dc attrs
in
6305 let anchor = (pageno, rely, visy
) in
6307 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6308 else { v with f = doc
path pan
anchor c [] }
6311 error
"unexpected subelement in llppconfig" s spos
6313 | Vclose
"llppconfig" -> { v with f = toplevel }
6314 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6316 and defaults
v t spos
_ =
6318 | Vdata
| Vcdata
-> v
6319 | Vend
-> error
"unexpected end of input in defaults" s spos
6320 | Vopen
("keymap", attrs
, closed
) ->
6322 try List.assoc
"mode" attrs
6323 with Not_found
-> "global" in
6328 let h = findkeyhash dc modename in
6329 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6332 { v with f = pkeymap
ret KeyMap.empty }
6334 | Vopen
(_, _, _) ->
6335 error
"unexpected subelement in defaults" s spos
6337 | Vclose
"defaults" ->
6338 { v with f = llppconfig
}
6340 | Vclose
_ -> error
"unexpected close in defaults" s spos
6342 and uifont
b v t spos
epos =
6345 Buffer.add_substring
b s spos
(epos - spos
);
6347 | Vopen
(_, _, _) ->
6348 error
"unexpected subelement in ui-font" s spos
6349 | Vclose
"ui-font" ->
6350 if String.length
!fontpath = 0
6351 then fontpath := Buffer.contents
b;
6352 { v with f = llppconfig
}
6353 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6354 | Vend
-> error
"unexpected end of input in ui-font" s spos
6356 and doc
path pan
anchor c bookmarks
v t spos
_ =
6358 | Vdata
| Vcdata
-> v
6359 | Vend
-> error
"unexpected end of input in doc" s spos
6360 | Vopen
("bookmarks", _, closed
) ->
6363 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6365 | Vopen
("keymap", attrs
, closed
) ->
6367 try List.assoc
"mode" attrs
6368 with Not_found
-> "global"
6374 let h = findkeyhash c modename in
6375 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6376 doc
path pan
anchor c bookmarks
6378 { v with f = pkeymap
ret KeyMap.empty }
6380 | Vopen
(_, _, _) ->
6381 error
"unexpected subelement in doc" s spos
6384 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6385 { v with f = llppconfig
}
6387 | Vclose
_ -> error
"unexpected close in doc" s spos
6389 and pkeymap
ret keymap
v t spos
_ =
6391 | Vdata
| Vcdata
-> v
6392 | Vend
-> error
"unexpected end of input in keymap" s spos
6393 | Vopen
("map", attrs
, closed
) ->
6394 let r, l = map_of attrs
in
6395 let kss = fromstring keys_of_string spos
"in" r [] in
6396 let lss = fromstring keys_of_string spos
"out" l [] in
6400 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6401 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6404 then { v with f = pkeymap
ret keymap }
6407 { v with f = skip
"map" f }
6410 error
"unexpected subelement in keymap" s spos
6412 | Vclose
"keymap" ->
6413 { v with f = ret keymap }
6415 | Vclose
_ -> error
"unexpected close in keymap" s spos
6417 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6419 | Vdata
| Vcdata
-> v
6420 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6421 | Vopen
("item", attrs
, closed
) ->
6422 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6423 let page = fromstring int_of_string spos
"page" spage
0
6424 and rely = fromstring float_of_string spos
"rely" srely
0.0
6425 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6427 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6430 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6433 { v with f = skip
"item" f }
6436 error
"unexpected subelement in bookmarks" s spos
6438 | Vclose
"bookmarks" ->
6439 { v with f = doc
path pan
anchor c bookmarks }
6441 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6443 and skip tag
f v t spos
_ =
6445 | Vdata
| Vcdata
-> v
6447 error
("unexpected end of input in skipped " ^ tag
) s spos
6448 | Vopen
(tag'
, _, closed
) ->
6452 let f'
() = { v with f = skip tag
f } in
6453 { v with f = skip tag'
f'
}
6457 else error
("unexpected close in skipped " ^ tag
) s spos
6460 parse
{ f = toplevel; accu = () } s;
6466 let len = in_channel_length ic
in
6467 let s = String.create
len in
6468 really_input ic
s 0 len;
6471 | Parse_error
(msg
, s, pos
) ->
6472 let subs = subs s pos
in
6473 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6474 failwith
("parse error: " ^
s)
6477 failwith
("config load error: " ^
Printexc.to_string exn
)
6483 let dir = Filename.concat
home ".config" in
6484 if Sys.is_directory
dir then dir else home
6487 Filename.concat
dir "llpp.conf"
6490 let confpath = ref defconfpath;;
6493 if Sys.file_exists
!confpath
6496 (try Some
(open_in_bin
!confpath)
6499 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6500 Printexc.to_string exn
);
6510 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6511 Printexc.to_string exn
);
6519 f (Hashtbl.create
0, defconf)
6524 let pc, pb
, px, pa
=
6526 Hashtbl.find h (Filename.basename
state.path)
6527 with Not_found
-> dc, [], 0, emptyanchor
6531 state.bookmarks <- pb
;
6533 state.scrollw
<- conf.scrollbw
;
6535 then state.anchor <- pa
;
6536 cbput state.hists
.nav pa
;
6542 let add_attrs bb always
dc c =
6545 then Printf.bprintf bb
"\n %s='%b'" s a
6548 then Printf.bprintf bb
"\n %s='%d'" s a
6551 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6554 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6557 then Printf.bprintf bb
"\n %s='%f'" s a
6561 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6565 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6569 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6573 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6579 | Some
(_N
, _A
, _B
) ->
6580 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6590 else string_of_float
f
6592 Printf.bprintf bb
"\n %s='%s'" s v
6597 | Cmulti
((n, a, b), _) when n > 1 ->
6598 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6599 | Csplit
(n, _) when n > 1 ->
6600 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6606 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6611 then dc.winw, dc.winh
6613 match state.fullscreen
with
6615 | None
-> c.winw, c.winh
6617 oi
"width" w dc.winw;
6618 oi
"height" h dc.winh
;
6619 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6620 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6621 ob "case-insensitive-search" c.icase
dc.icase
;
6622 ob "preload" c.preload dc.preload;
6623 oi
"page-bias" c.pagebias
dc.pagebias
;
6624 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6625 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6626 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6627 ob "crop-hack" c.crophack
dc.crophack
;
6628 oW
"throttle" c.maxwait
dc.maxwait
;
6629 ob "highlight-links" c.hlinks
dc.hlinks
;
6630 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6631 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6632 oz
"zoom" c.zoom dc.zoom;
6633 ob "presentation" c.presentation
dc.presentation
;
6634 oi
"rotation-angle" c.angle
dc.angle
;
6635 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6636 ob "proportional-display" c.proportional
dc.proportional
;
6637 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6638 oi
"tex-count" c.texcount
dc.texcount
;
6639 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6640 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6641 ob "persistent-location" c.jumpback
dc.jumpback
;
6642 oc
"background-color" c.bgcolor
dc.bgcolor
;
6643 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6644 oi
"tile-width" c.tilew
dc.tilew
;
6645 oi
"tile-height" c.tileh
dc.tileh
;
6646 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6647 ob "checkers" c.checkers
dc.checkers
;
6648 oi
"aalevel" c.aalevel
dc.aalevel
;
6649 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6650 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6651 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6652 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6653 oC
"color-space" c.colorspace
dc.colorspace
;
6654 ob "invert-colors" c.invert
dc.invert
;
6655 oF
"brightness" c.colorscale
dc.colorscale
;
6656 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6657 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6658 oco
"columns" c.columns
dc.columns
;
6659 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6660 os
"selection-command" c.selcmd
dc.selcmd
;
6661 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6662 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6663 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6664 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6665 ob "use-pbo" c.usepbo
dc.usepbo
;
6668 let keymapsbuf always
dc c =
6669 let bb = Buffer.create
16 in
6670 let rec loop = function
6672 | (modename, h) :: rest
->
6673 let dh = findkeyhash dc modename in
6674 if always
|| h <> dh
6676 if Hashtbl.length
h > 0
6678 if Buffer.length
bb > 0
6679 then Buffer.add_char
bb '
\n'
;
6680 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6681 Hashtbl.iter
(fun i
o ->
6682 let isdifferent = always
||
6684 let dO = Hashtbl.find dh i
in
6686 with Not_found
-> true
6691 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6692 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6693 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6694 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6695 Buffer.add_string
bb (Wsi.keyname
k);
6698 let rec loop = function
6700 | km
:: [] -> addkm km
6701 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6705 Buffer.add_string
bb "<map in='";
6709 Buffer.add_string
bb "' out='";
6711 Buffer.add_string
bb "'/>\n"
6714 Buffer.add_string
bb "' out='";
6716 Buffer.add_string
bb "'/>\n"
6718 | KMmulti
(ins, kms
) ->
6719 Buffer.add_char
bb ' '
;
6721 Buffer.add_string
bb "' out='";
6723 Buffer.add_string
bb "'/>\n"
6725 Buffer.add_string
bb "</keymap>";
6735 let uifontsize = fstate.fontsize
in
6736 let bb = Buffer.create
32768 in
6738 let dc = if conf.bedefault
then conf else dc in
6739 Buffer.add_string
bb "<llppconfig>\n";
6741 if String.length
!fontpath > 0
6743 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6749 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6752 Buffer.add_string
bb "<defaults ";
6753 add_attrs bb true dc dc;
6754 let kb = keymapsbuf true dc dc in
6755 if Buffer.length
kb > 0
6757 Buffer.add_string
bb ">\n";
6758 Buffer.add_buffer
bb kb;
6759 Buffer.add_string
bb "\n</defaults>\n";
6761 else Buffer.add_string
bb "/>\n";
6763 let adddoc path pan
anchor c bookmarks =
6764 if bookmarks == [] && c = dc && anchor = emptyanchor
6767 Printf.bprintf
bb "<doc path='%s'"
6768 (enent
path 0 (String.length
path));
6770 if anchor <> emptyanchor
6772 let n, rely, visy
= anchor in
6773 Printf.bprintf
bb " page='%d'" n;
6776 Printf.bprintf
bb " rely='%f'" rely
6778 if abs_float visy
> 1e-6
6780 Printf.bprintf
bb " visy='%f'" visy
6785 then Printf.bprintf
bb " pan='%d'" pan
;
6787 add_attrs bb false dc c;
6788 let kb = keymapsbuf false dc c in
6790 begin match bookmarks with
6792 if Buffer.length
kb > 0
6794 Buffer.add_string
bb ">\n";
6795 Buffer.add_buffer
bb kb;
6796 Buffer.add_string
bb "\n</doc>\n";
6798 else Buffer.add_string
bb "/>\n"
6800 Buffer.add_string
bb ">\n<bookmarks>\n";
6801 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6803 "<item title='%s' page='%d'"
6804 (enent
title 0 (String.length
title))
6809 Printf.bprintf
bb " rely='%f'" rely
6811 if abs_float visy
> 1e-6
6813 Printf.bprintf
bb " visy='%f'" visy
6815 Buffer.add_string
bb "/>\n";
6817 Buffer.add_string
bb "</bookmarks>";
6818 if Buffer.length
kb > 0
6820 Buffer.add_string
bb "\n";
6821 Buffer.add_buffer
bb kb;
6823 Buffer.add_string
bb "\n</doc>\n";
6829 match state.mode with
6830 | Birdseye
(c, pan, _, _, _) ->
6832 match conf.columns
with
6833 | Cmulti
((c, _, _), _) -> Some
c
6837 match c.columns
with
6838 | Cmulti
(c, _) -> Cmulti
(c, [||])
6839 | Csingle
_ -> Csingle
[||]
6840 | Csplit
_ -> failwith
"quit from bird's eye while split"
6842 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6843 | _ -> state.x, conf
6845 let basename = Filename.basename state.path in
6846 adddoc basename pan (getanchor ())
6848 let autoscrollstep =
6849 match state.autoscroll
with
6851 | None
-> conf.autoscrollstep
6853 match state.mode with
6854 | Birdseye
(bc
, _, _, _, _) ->
6857 presentation
= bc
.presentation
;
6858 interpagespace
= bc
.interpagespace
;
6859 maxwait
= bc
.maxwait
;
6860 autoscrollstep = autoscrollstep }
6861 | _ -> { conf with autoscrollstep = autoscrollstep }
6863 (if conf.savebmarks
then state.bookmarks else []);
6865 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6867 then adddoc path x anchor c bookmarks
6869 Buffer.add_string
bb "</llppconfig>\n";
6872 if load1 f && Buffer.length
bb > 0
6875 let tmp = !confpath ^
".tmp" in
6876 let oc = open_out_bin
tmp in
6877 Buffer.output_buffer
oc bb;
6879 Unix.rename
tmp !confpath;
6882 ("error while saving configuration: " ^
Printexc.to_string exn
)
6887 let trimcachepath = ref "" in
6890 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6891 "<password> Set password");
6893 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6894 "<path> Set path to the user interface font");
6896 ("-c", Arg.String
(fun s -> Config.confpath := s),
6897 "<path> Set path to the configuration file");
6899 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6900 "<path> Set path to the trim cache file");
6902 ("-v", Arg.Unit
(fun () ->
6904 "%s\nconfiguration path: %s\n"
6908 exit
0), " Print version and exit");
6911 (fun s -> state.path <- s)
6912 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6914 if String.length
state.path = 0
6915 then (prerr_endline
"file name missing"; exit
1);
6917 if not
(Config.load ())
6918 then prerr_endline
"failed to load configuration";
6920 let globalkeyhash = findkeyhash conf "global" in
6921 let wsfd, winw, winh
= Wsi.init
(object
6923 if nogeomcmds state.geomcmds
|| platform == Posx
6926 GlClear.color (scalecolor2 conf.bgcolor
);
6927 GlClear.clear
[`
color];
6929 method display = display ()
6930 method reshape w h = reshape w h
6931 method mouse b d x y m = mouse b d x y m
6932 method motion x y = state.mpos
<- (x, y); motion x y
6933 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6935 let mascm = m land (
6936 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6938 match state.keystate
with
6940 let km = k, mascm in
6943 let modehash = state.uioh#
modehash in
6944 try Hashtbl.find modehash km
6946 try Hashtbl.find globalkeyhash km
6947 with Not_found
-> KMinsrt
(k, m)
6949 | KMinsrt
(k, m) -> keyboard k m
6950 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6951 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6953 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6954 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6955 state.keystate
<- KSnone
6956 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6957 state.keystate
<- KSinto
(keys
, insrt
)
6959 state.keystate
<- KSnone
6961 method enter
x y = state.mpos
<- (x, y); pmotion x y
6962 method leave = state.mpos
<- (-1, -1)
6963 method quit
= raise Quit
6964 end) conf.winw conf.winh
(platform = Posx
) in
6969 List.exists
GlMisc.check_extension
6970 [ "GL_ARB_texture_rectangle"
6971 ; "GL_EXT_texture_recangle"
6972 ; "GL_NV_texture_rectangle" ]
6974 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6977 match Ne.pipe () with
6979 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6983 match Ne.pipe () with
6985 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6995 setcheckers conf.checkers
;
6999 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7000 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7001 !Config.fontpath, !trimcachepath,
7002 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7006 state.text <- "Opening " ^
(mbtoutf8
state.path);
7008 opendoc state.path state.password
;
7011 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7013 let rec loop deadline
=
7015 match state.errfd
with
7016 | None
-> [state.sr
; state.wsfd]
7017 | Some fd
-> [state.sr
; state.wsfd; fd
]
7021 state.redisplay
<- false;
7028 if deadline
= infinity
7030 else max
0.0 (deadline
-. now)
7035 try Unix.select
r [] [] timeout
7036 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7042 if state.ghyll
== noghyll
7044 match state.autoscroll
with
7045 | Some step
when step
!= 0 ->
7046 let y = state.y + step
in
7050 else if y >= state.maxy then 0 else y
7053 if state.mode = View
7054 then state.text <- "";
7057 else deadline
+. 0.01
7062 let rec checkfds = function
7064 | fd
:: rest
when fd
= state.sr
->
7065 let cmd = readcmd state.sr
in
7069 | fd
:: rest
when fd
= state.wsfd ->
7074 let s = String.create
80 in
7075 let n = Unix.read fd
s 0 80 in
7076 if conf.redirectstderr
7078 Buffer.add_substring
state.errmsgs
s 0 n;
7079 state.newerrmsgs
<- true;
7080 state.redisplay
<- true;
7083 prerr_string
(String.sub
s 0 n);
7091 if deadline
= infinity
7095 match state.autoscroll
with
7096 | Some step
when step
!= 0 -> deadline1
7097 | _ -> if state.ghyll
== noghyll then infinity
else deadline1