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
476 ; mutable wthack
: bool
479 { pat
: string circbuf
480 ; pag
: string circbuf
481 ; nav
: anchor circbuf
482 ; sel
: string circbuf
504 ; presentation
= false
509 ; proportional
= true
510 ; trimmargins
= false
511 ; trimfuzz
= (0,0,0,0)
512 ; memlimit
= 32 lsl 20
517 ; bgcolor
= (0.5, 0.5, 0.5)
519 ; scrollbarinpm
= true
522 ; mustoresize
= 256 lsl 20
527 | Plinux
| Pfreebsd
| Pdragonflybsd
528 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
529 | Posx
-> "open \"%s\""
530 | Pcygwin
-> "cygstart \"%s\""
531 | Punknown
-> "echo %s")
532 ; pathlauncher
= "lp \"%s\""
535 | Plinux
| Pfreebsd
| Pdragonflybsd
536 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
543 ; redirectstderr
= false
545 ; columns
= Csingle
[||]
552 let mk n
= (n
, Hashtbl.create
1) in
566 let findkeyhash c name
=
567 try List.assoc name c
.keyhashes
568 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
571 let conf = { defconf with angle
= defconf.angle
};;
573 let pgscale h
= truncate
(float h
*. conf.pgscale);;
576 { mutable fontsize
: int
577 ; mutable wwidth
: float
578 ; mutable maxrows
: int
590 fstate.fontsize
<- n
;
591 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
592 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
596 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
597 let len = String.length s
in
598 if colonpos >= 0 && colonpos + 3 < len
600 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
603 try String.rindex_from s
colonpos ' '
607 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
610 | "http" | "ftp" | "mailto" ->
612 try String.index_from s
colonpos ' '
613 with Not_found
-> len
615 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
623 if String.length
conf.urilauncher
= 0
624 then print_endline uri
626 let url = geturl uri
in
627 if String.length
url = 0
628 then print_endline uri
630 let re = Str.regexp
"%s" in
631 let command = Str.global_replace
re url conf.urilauncher
in
635 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
641 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
642 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
646 let strings = version () :: "" :: Help.keys
in
649 let url = geturl s
in
650 if String.length
url > 0
651 then (s
, 0, Action
(fun u
-> gotouri url; u
))
652 else (s
, 0, Noaction
)
657 let firstgeomcmds = "", [];;
664 ; stderr
= Unix.stderr
665 ; errmsgs
= Buffer.create
0
672 ; anchor
= emptyanchor
676 ; tilelru
= Queue.create
()
677 ; pagemap
= Hashtbl.create
10
678 ; tilemap
= Hashtbl.create
10
693 ; geomcmds
= firstgeomcmds
695 { nav
= cbnew 10 emptyanchor
723 Printf.kprintf prerr_endline fmt
725 Printf.kprintf ignore fmt
729 if String.length
conf.pathlauncher
= 0
730 then print_endline
state.path
732 let re = Str.regexp
"%s" in
733 let command = Str.global_replace
re state.path
conf.pathlauncher
in
737 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
743 type 'a t
= | Res
of 'a
| Exn
of exn
;;
746 try Res
(Unix.pipe ())
752 with exn
-> f
(Printexc.to_string exn
)
756 try Res
(Unix.dup fd
)
761 try Res
(Unix.dup2 fd1 fd2
)
766 let redirectstderr () =
767 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
768 if conf.redirectstderr
770 match Ne.pipe () with
772 dolog "failed to create stderr redirection pipes: %s"
773 (Printexc.to_string exn
)
776 begin match Ne.dup Unix.stderr
with
778 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
779 Ne.clo r
(clofail "pipe/r");
780 Ne.clo w
(clofail "pipe/w");
782 | Ne.Res dupstderr
->
783 begin match Ne.dup2 w
Unix.stderr
with
785 dolog "failed to dup2 to stderr: %s"
786 (Printexc.to_string exn
);
787 Ne.clo dupstderr
(clofail "stderr duplicate");
788 Ne.clo r
(clofail "redir pipe/r");
789 Ne.clo w
(clofail "redir pipe/w");
792 state.stderr
<- dupstderr
;
793 state.errfd
<- Some r
;
797 state.newerrmsgs
<- false;
798 begin match state.errfd
with
800 begin match Ne.dup2 state.stderr
Unix.stderr
with
802 dolog "failed to dup2 original stderr: %s"
803 (Printexc.to_string exn
)
805 Ne.clo fd
(clofail "dup of stderr");
806 Unix.dup2 state.stderr
Unix.stderr
;
811 prerr_string
(Buffer.contents
state.errmsgs
);
813 Buffer.clear
state.errmsgs
;
819 let postRedisplay who
=
821 then prerr_endline
("redisplay for " ^ who
);
822 state.redisplay
<- true;
826 let getopaque pageno
=
827 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
828 with Not_found
-> None
831 let putopaque pageno opaque
=
832 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
835 let pagetranslatepoint l x y
=
836 let dy = y
- l
.pagedispy
in
837 let y = dy + l
.pagey
in
838 let dx = x
- l
.pagedispx
in
839 let x = dx + l
.pagex
in
846 begin match getopaque l
.pageno
with
848 let x0 = l
.pagedispx
in
849 let x1 = x0 + l
.pagevw
in
850 let y0 = l
.pagedispy
in
851 let y1 = y0 + l
.pagevh
in
852 if y >= y0 && y <= y1 && x >= x0 && x <= x1
854 let px, py
= pagetranslatepoint l
x y in
855 match whatsunder opaque
px py
with
868 state.text
<- Printf.sprintf
"%c%s" c s
;
869 G.postRedisplay "showtext";
872 let undertext = function
875 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
876 | Utext s
-> "font: " ^ s
877 | Uunexpected s
-> "unexpected: " ^ s
878 | Ulaunch s
-> "launch: " ^ s
879 | Unamed s
-> "named: " ^ s
880 | Uremote
(filename
, pageno
) ->
881 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
884 let updateunder x y =
885 match getunder x y with
886 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
888 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
889 Wsi.setcursor
Wsi.CURSOR_INFO
890 | Ulinkgoto
(pageno
, _
) ->
892 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
893 Wsi.setcursor
Wsi.CURSOR_INFO
895 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
896 Wsi.setcursor
Wsi.CURSOR_TEXT
898 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
899 Wsi.setcursor
Wsi.CURSOR_INHERIT
901 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
902 Wsi.setcursor
Wsi.CURSOR_INHERIT
904 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
905 Wsi.setcursor
Wsi.CURSOR_INHERIT
906 | Uremote
(filename
, pageno
) ->
907 if conf.underinfo
then showtext 'r'
908 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
909 Wsi.setcursor
Wsi.CURSOR_INFO
912 let showlinktype under
=
918 let s = undertext under
in
923 let b = Buffer.create
(String.length
s + 1) in
924 Buffer.add_string
b s;
929 let colorspace_of_string s =
930 match String.lowercase
s with
934 | _
-> failwith
"invalid colorspace"
937 let int_of_colorspace = function
943 let colorspace_of_int = function
947 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
950 let colorspace_to_string = function
956 let intentry_with_suffix text key
=
958 if key
>= 32 && key
< 127
962 match Char.lowercase
c with
964 let text = addchar text c in
968 let text = addchar text c in
972 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
976 let multicolumns_to_string (n
, a
, b) =
978 then Printf.sprintf
"%d" n
979 else Printf.sprintf
"%d,%d,%d" n a
b;
982 let multicolumns_of_string s =
984 (int_of_string
s, 0, 0)
986 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
988 then failwith
"subtly broken"; (n
, a
, b)
994 let n = Unix.read fd
s 0 4 in
995 if n != 4 then failwith
"incomplete read(len)";
997 lor (Char.code
s.[0] lsl 24)
998 lor (Char.code
s.[1] lsl 16)
999 lor (Char.code
s.[2] lsl 8)
1000 lor (Char.code
s.[3] lsl 0)
1002 let s = String.create
len in
1003 let n = Unix.read fd
s 0 len in
1004 if n != len then failwith
"incomplete read(data)";
1008 let btod b = if b then 1 else 0;;
1011 let b = Buffer.create
16 in
1012 Buffer.add_string
b "llll";
1015 let s = Buffer.contents
b in
1016 let n = String.length
s in
1018 (* dolog "wcmd %S" (String.sub s 4 len); *)
1019 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1020 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1021 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1022 s.[3] <- Char.chr
(len land 0xff);
1023 let n'
= Unix.write
state.sw
s 0 n in
1024 if n'
!= n then failwith
"write failed";
1029 let d = conf.winh
- h
in
1030 max
conf.interpagespace
((d + 1) / 2)
1033 let rowyh (c, coverA
, coverB
) b n =
1034 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1036 let _, _, vy
, (_, _, h
, _) = b.(n) in
1039 let n'
= n - coverA
in
1042 let e = min
state.pagecount
(s + c) in
1043 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1044 let _, _, y, (_, _, h
, _) = b.(m
) in
1045 let miny = min
miny y in
1046 let maxh = max
maxh h
in
1047 find (m
+1) miny maxh
1052 match conf.columns
with
1053 | Cmulti
((_, _, _) as cl
, b) ->
1054 if Array.length
b > 0
1056 let y, h
= rowyh cl
b (Array.length
b - 1) in
1057 y + h
+ (if conf.presentation
then calcips h
else 0)
1060 if Array.length
b > 0
1062 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1063 y + h
+ (if conf.presentation
then calcips h
else 0)
1066 if Array.length
b > 0
1068 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1073 let getpageyh pageno
=
1074 let pageno = bound pageno 0 (state.pagecount
-1) in
1075 match conf.columns
with
1077 if Array.length
b = 0
1080 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1082 if conf.presentation
1088 if Array.length
b = 0
1091 let y, h
= rowyh cl
b pageno in
1093 if conf.presentation
1099 if Array.length
b = 0
1103 let (_, _, y, (_, _, h
, _)) = b.(n) in
1107 let getpagedim pageno =
1110 | (n, _, _, _) as pdim
:: rest
->
1112 then (if n = pageno then pdim
else ppdim
)
1117 f (-1, -1, -1, -1) state.pdims
1120 let getpagey pageno = fst
(getpageyh pageno);;
1122 let nogeomcmds cmds
=
1124 | s, [] -> String.length
s = 0
1129 let ((c, coverA
, coverB
) as cl
), b =
1130 match conf.columns
with
1131 | Csingle
b -> (1, 0, 0), b
1132 | Cmulti
(c, b) -> c, b
1133 | Csplit
(_, b) -> (1, 0, 0), b
1135 let rec bsearch nmin nmax
=
1137 then bound nmin
0 (state.pagecount
-1)
1139 let n = (nmax
+ nmin
) / 2 in
1140 let vy, h
= rowyh cl
b n in
1142 if conf.presentation
1144 let ips = calcips h
in
1145 let y0 = vy - ips in
1146 let y1 = vy + h
+ ips in
1150 then 0, vy + h
+ conf.interpagespace
1152 let y0 = vy - conf.interpagespace
in
1153 y0, y0 + h
+ conf.interpagespace
1156 if y >= y0 && y < y1
1163 if n < state.pagecount
- coverB
1164 then ((n-coverA
)/c)*c + coverA
1171 then bsearch (n+1) nmax
1172 else bsearch nmin
(n-1)
1175 let r = bsearch 0 (state.pagecount
-1) in
1179 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1180 let sh = sh - state.hscrollh
in
1181 let rec fold accu
n =
1182 if n = Array.length
b
1185 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1188 || n = state.pagecount
- coverB
1189 || (n - coverA
) mod columns
= columns
- 1)
1195 let pagey = max
0 (y - vy) in
1196 let pagedispy = if pagey > 0 then 0 else vy - y in
1197 let pagedispx, pagex
=
1199 if n = coverA
- 1 || n = state.pagecount
- coverB
1200 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1201 else dx + xoff
+ state.x
1208 let vw = conf.winw
- state.scrollw
- pagedispx in
1209 let pw = w
- pagex
in
1212 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1213 if pagevw > 0 && pagevh > 0
1217 ; pagedimno
= pdimno
1224 ; pagedispx = pagedispx
1225 ; pagedispy = pagedispy
1237 List.rev
(fold [] (page_of_y y));
1240 let layoutS (columns
, b) y sh =
1241 let sh = sh - state.hscrollh
in
1242 let rec fold accu n =
1243 if n = Array.length
b
1246 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1253 let x = xoff
+ state.x in
1254 let pagey = max
0 (y - vy) in
1255 let pagedispy = if pagey > 0 then 0 else vy - y in
1256 let pagedispx, pagex
=
1270 let pagecolw = pagew
/columns
in
1272 if pagecolw < conf.winw
1273 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1277 let vw = conf.winw
- pagedispx - state.scrollw
in
1278 let pw = pagew
- pagex
in
1281 let pagevw = min
pagevw pagecolw in
1282 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1283 if pagevw > 0 && pagevh > 0
1286 { pageno = n/columns
1287 ; pagedimno
= pdimno
1294 ; pagedispx = pagedispx
1295 ; pagedispy = pagedispy
1296 ; pagecol
= n mod columns
1307 List.rev
(fold [] 0)
1311 if nogeomcmds state.geomcmds
1313 match conf.columns
with
1314 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1315 | Cmulti
c -> layoutN c y sh
1316 | Csplit
s -> layoutS s y sh
1321 let y = state.y + incr
in
1323 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1328 let tilex = l
.pagex
mod conf.tilew
in
1329 let tiley = l
.pagey mod conf.tileh
in
1331 let col = l
.pagex
/ conf.tilew
in
1332 let row = l
.pagey / conf.tileh
in
1334 let rec rowloop row y0 dispy h
=
1338 let dh = conf.tileh
- y0 in
1339 let dh = min h
dh in
1340 let rec colloop col x0 dispx w
=
1344 let dw = conf.tilew
- x0 in
1345 let dw = min w
dw in
1347 f col row dispx dispy
x0 y0 dw dh;
1348 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1351 colloop col tilex l
.pagedispx l
.pagevw;
1352 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1355 if l
.pagevw > 0 && l
.pagevh > 0
1356 then rowloop row tiley l
.pagedispy l
.pagevh;
1359 let gettileopaque l
col row =
1361 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1363 try Some
(Hashtbl.find state.tilemap
key)
1364 with Not_found
-> None
1367 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1368 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1369 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1372 let drawtiles l color
=
1374 let f col row x y tilex tiley w h
=
1375 match gettileopaque l
col row with
1376 | Some
(opaque
, _, t
) ->
1377 let params = x, y, w
, h
, tilex, tiley in
1381 GlFunc.blend_func `zero `one_minus_src_color
;
1383 drawtile
params opaque
;
1385 then Gl.disable `blend
;
1388 let s = Printf.sprintf
1392 let w = measurestr
fstate.fontsize
s in
1393 GlMisc.push_attrib
[`current
];
1394 GlDraw.color
(0.0, 0.0, 0.0);
1396 (float (x-2), float (y-2))
1397 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1398 GlDraw.color
(1.0, 1.0, 1.0);
1399 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1400 GlMisc.pop_attrib
();
1405 let lw = conf.winw
- state.scrollw
- x in
1408 let lh = conf.winh
- y in
1411 begin match state.texid
with
1413 Gl.enable `texture_2d
;
1414 GlTex.bind_texture `texture_2d id
;
1417 and x1 = float (x+w)
1418 and y1 = float (y+h
) in
1420 let tw = float w /. 16.0
1421 and th
= float h
/. 16.0 in
1422 let tx0 = float tilex /. 16.0
1423 and ty0
= float tiley /. 16.0 in
1425 and ty1
= ty0
+. th
in
1426 GlDraw.begins `quads
;
1427 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1428 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1429 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1430 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1433 Gl.disable `texture_2d
;
1435 GlDraw.color
(1.0, 1.0, 1.0);
1438 (float (x+w), float (y+h
));
1440 if w > 128 && h
> fstate.fontsize
+ 10
1442 GlDraw.color
(0.0, 0.0, 0.0);
1445 then (col*conf.tilew
, row*conf.tileh
)
1448 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1455 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1457 let tilevisible1 l
x y =
1459 and ax1
= l
.pagex
+ l
.pagevw
1461 and ay1
= l
.pagey + l
.pagevh in
1465 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1466 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1468 let rx0 = max
ax0 bx0
1469 and ry0
= max ay0 by0
1470 and rx1
= min ax1
bx1
1471 and ry1
= min ay1 by1
in
1473 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1474 nonemptyintersection
1477 let tilevisible layout n x y =
1478 let rec findpageinlayout m
= function
1479 | l
:: rest
when l
.pageno = n ->
1480 tilevisible1 l
x y || (
1481 match conf.columns
with
1482 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1485 | _ :: rest
-> findpageinlayout 0 rest
1488 findpageinlayout 0 layout;
1491 let tileready l
x y =
1492 tilevisible1 l
x y &&
1493 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1496 let tilepage n p
layout =
1497 let rec loop = function
1501 let f col row _ _ _ _ _ _ =
1502 if state.currently
= Idle
1504 match gettileopaque l
col row with
1507 let x = col*conf.tilew
1508 and y = row*conf.tileh
in
1510 let w = l
.pagew
- x in
1514 let h = l
.pageh
- y in
1519 then getpbo
w h conf.colorspace
1522 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1525 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1526 conf.tilew
, conf.tileh
1535 if nogeomcmds state.geomcmds
1539 let preloadlayout y =
1540 let y = if y < conf.winh
then 0 else y - conf.winh
in
1541 let h = conf.winh
*3 in
1546 let rec loop pages
=
1547 if state.currently
!= Idle
1552 begin match getopaque l
.pageno with
1554 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1555 state.currently
<- Loading
(l
, state.gen
);
1557 tilepage l
.pageno opaque pages
;
1562 if nogeomcmds state.geomcmds
1568 if conf.preload && state.currently
= Idle
1569 then load (preloadlayout state.y);
1572 let layoutready layout =
1573 let rec fold all ls
=
1574 all
&& match ls
with
1576 let seen = ref false in
1577 let allvisible = ref true in
1578 let foo col row _ _ _ _ _ _ =
1580 allvisible := !allvisible &&
1581 begin match gettileopaque l
col row with
1587 fold (!seen && !allvisible) rest
1590 let alltilesvisible = fold true layout in
1595 let y = bound y 0 state.maxy
in
1596 let y, layout, proceed
=
1597 match conf.maxwait
with
1598 | Some time
when state.ghyll
== noghyll ->
1599 begin match state.throttle
with
1601 let layout = layout y conf.winh
in
1602 let ready = layoutready layout in
1606 state.throttle
<- Some
(layout, y, now ());
1608 else G.postRedisplay "gotoy showall (None)";
1610 | Some
(_, _, started
) ->
1611 let dt = now () -. started
in
1614 state.throttle
<- None
;
1615 let layout = layout y conf.winh
in
1617 G.postRedisplay "maxwait";
1624 let layout = layout y conf.winh
in
1625 if true || layoutready layout
1626 then G.postRedisplay "gotoy ready";
1632 state.layout <- layout;
1633 begin match state.mode
with
1634 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1635 let rec loop = function
1637 state.mode
<- LinkNav
(Ltgendir
0)
1638 | l
:: _ when l
.pageno = pageno ->
1639 begin match getopaque pageno with
1641 state.mode
<- LinkNav
(Ltgendir
0)
1643 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1644 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1645 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1646 then state.mode
<- LinkNav
(Ltgendir
0)
1648 | _ :: rest
-> loop rest
1653 begin match state.mode
with
1654 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1655 if not
(pagevisible layout pageno)
1657 match state.layout with
1660 state.mode
<- Birdseye
(
1661 conf, leftx
, l
.pageno, hooverpageno
, anchor
1664 | LinkNav
(Ltgendir dir
as lt
) ->
1666 let rec loop = function
1669 match getopaque l
.pageno with
1675 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1677 if dir
> 0 then LDfirst
else LDlast
1683 | Lnotfound
-> loop rest
1685 showlinktype (getlink opaque
n);
1686 Ltexact
(l
.pageno, n)
1690 state.mode
<- LinkNav
linknav
1695 state.ghyll
<- noghyll;
1698 let mx, my
= state.mpos
in
1703 let conttiling pageno opaque
=
1704 tilepage pageno opaque
1705 (if conf.preload then preloadlayout state.y else state.layout)
1708 let gotoy_and_clear_text y =
1709 if not
conf.verbose
then state.text <- "";
1715 let coloff = l
.pagecol
* l
.pageh
in
1716 float (l
.pagey + coloff) /. float l
.pageh
1723 if conf.presentation
1724 then float l
.pagedispy /. float (calcips l
.pageh
)
1725 else float l
.pagedispy /. float conf.interpagespace
1727 (l
.pageno, top, dtop)
1731 match state.layout with
1732 | l
:: _ -> getanchor1 l
1734 let n = page_of_y state.y in
1735 let y, h = getpageyh n in
1736 let dy = y - state.y in
1738 if conf.presentation
1740 let ips = calcips h in
1741 float (dy + ips) /. float ips
1743 float dy /. float conf.interpagespace
1748 let getanchory (n, top, dtop) =
1749 let y, h = getpageyh n in
1750 if conf.presentation
1752 let ips = calcips h in
1753 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1755 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1758 let gotoanchor anchor
=
1759 gotoy (getanchory anchor
);
1763 cbput state.hists
.nav
(getanchor ());
1767 let anchor = cbgetc state.hists
.nav dir
in
1772 let scroll f n a
b =
1773 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1775 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1777 then s (float f /. float a
)
1780 then 1.0 -. s ((float (f-b) /. float (n-b)))
1787 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1788 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1790 let ins = float a
*. iv1
1791 and outs
= float (n-b) *. iv1 in
1793 ins +. outs
+. float ones
1795 let rec set (_N
, _A
, _B
) y sy
=
1796 let sum = summa
1.0 _N _A _B
in
1797 let dy = float (y - sy
) in
1801 then state.ghyll
<- noghyll
1804 let s = scroll n _N _A _B
in
1805 let y1 = y1 +. ((s *. dy) /. sum) in
1806 gotoy_and_clear_text (truncate
y1);
1807 state.ghyll
<- gf (n+1) y1;
1811 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1813 gf 0 (float state.y)
1816 match conf.ghyllscroll
with
1818 gotoy_and_clear_text y
1820 if state.ghyll
== noghyll
1821 then set nab
y state.y
1822 else state.ghyll
(Some
y)
1825 let gotopage n top =
1826 let y, h = getpageyh n in
1827 let y = y + (truncate
(top *. float h)) in
1831 let gotopage1 n top =
1832 let y = getpagey n in
1837 let invalidate s f =
1842 match state.geomcmds
with
1843 | ps
, [] when String.length ps
= 0 ->
1845 state.geomcmds
<- s, [];
1848 state.geomcmds
<- ps
, [s, f];
1850 | ps
, (s'
, _) :: rest
when s'
= s ->
1851 state.geomcmds
<- ps
, ((s, f) :: rest
);
1854 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1858 Hashtbl.iter
(fun _ opaque
->
1859 wcmd "freepage %s" opaque
;
1861 Hashtbl.clear
state.pagemap
;
1864 let opendoc path password
=
1866 state.password
<- password
;
1867 state.gen
<- state.gen
+ 1;
1868 state.docinfo
<- [];
1871 setaalevel
conf.aalevel
;
1872 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1873 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1874 invalidate "reqlayout"
1876 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1880 state.anchor <- getanchor ();
1881 state.wthack
<- true;
1882 opendoc state.path
state.password
;
1886 let c = c *. conf.colorscale
in
1890 let scalecolor2 (r, g
, b) =
1891 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1894 let docolumns = function
1896 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1897 let rec loop pageno pdimno pdim
y ph pdims
=
1898 if pageno = state.pagecount
1901 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1903 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1904 pdimno+1, pdim
, rest
1908 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1910 (if conf.presentation
1911 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1912 else (if pageno = 0 then 0 else conf.interpagespace
)
1915 a.(pageno) <- (pdimno, x, y, pdim
);
1916 loop (pageno+1) pdimno pdim
(y + h) h pdims
1918 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1919 conf.columns
<- Csingle
a;
1921 | Cmulti
((columns
, coverA
, coverB
), _) ->
1922 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1923 let rec loop pageno pdimno pdim
x y rowh pdims
=
1924 let rec fixrow m
= if m
= pageno then () else
1925 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1928 let y = y + (rowh
- h) / 2 in
1929 a.(m
) <- (pdimno, x, y, pdim
);
1933 if pageno = state.pagecount
1934 then fixrow (((pageno - 1) / columns
) * columns
)
1936 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1938 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1939 pdimno+1, pdim
, rest
1944 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1946 let x = (conf.winw
- state.scrollw
- w) / 2 in
1948 if conf.presentation
then calcips h else conf.interpagespace
in
1949 x, y + ips + rowh
, h
1952 if (pageno - coverA
) mod columns
= 0
1954 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1956 if conf.presentation
1958 let ips = calcips h in
1959 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1961 y + (if pageno = 0 then 0 else conf.interpagespace
)
1965 else x, y, max rowh
h
1969 if pageno > 1 && (pageno - coverA
) mod columns
= 0
1972 if pageno = columns
&& conf.presentation
1974 let ips = calcips rowh
in
1975 for i
= 0 to pred columns
1977 let (pdimno, x, y, pdim
) = a.(i
) in
1978 a.(i
) <- (pdimno, x, y+ips, pdim
)
1984 fixrow (pageno - columns
);
1989 a.(pageno) <- (pdimno, x, y, pdim
);
1990 let x = x + w + xoff
*2 + conf.interpagespace
in
1991 loop (pageno+1) pdimno pdim
x y rowh' pdims
1993 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1994 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1997 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1998 let rec loop pageno pdimno pdim
y pdims
=
1999 if pageno = state.pagecount
2002 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2004 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2005 pdimno+1, pdim
, rest
2010 let rec loop1 n x y =
2011 if n = c then y else (
2012 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2013 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2016 let y = loop1 0 0 y in
2017 loop (pageno+1) pdimno pdim
y pdims
2019 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2020 conf.columns
<- Csplit
(c, a);
2024 docolumns conf.columns
;
2025 state.maxy
<- calcheight ();
2027 if state.w <= conf.winw
- state.scrollw
2031 match state.mode
with
2032 | Birdseye
(_, _, pageno, _, _) ->
2033 let y, h = getpageyh pageno in
2034 let top = (conf.winh
- h) / 2 in
2035 gotoy (max
0 (y - top))
2036 | _ -> gotoanchor state.anchor
2040 state.wthack
<- false;
2041 GlDraw.viewport
0 0 w h;
2042 let firsttime = state.geomcmds
== firstgeomcmds in
2043 if not
firsttime && nogeomcmds state.geomcmds
2044 then state.anchor <- getanchor ();
2047 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2050 setfontsize fstate.fontsize
;
2051 GlMat.mode `modelview
;
2052 GlMat.load_identity
();
2054 GlMat.mode `projection
;
2055 GlMat.load_identity
();
2056 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2057 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2058 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2063 else float state.x /. float state.w
2065 invalidate "geometry"
2069 then state.x <- truncate
(relx *. float w);
2071 match conf.columns
with
2073 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2074 | Csplit
(c, _) -> w * c
2076 wcmd "geometry %d %d" w h);
2080 let len = String.length
state.text in
2083 match state.mode
with
2086 let h, _, _ = state.uioh#scrollpw
in
2092 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2093 (x+.w, float (conf.winh
- hscrollh))
2096 let w = float (conf.winw
- state.scrollw
- 1) in
2097 if state.progress
>= 0.0 && state.progress
< 1.0
2099 GlDraw.color
(0.3, 0.3, 0.3);
2100 let w1 = w *. state.progress
in
2102 GlDraw.color
(0.0, 0.0, 0.0);
2106 GlDraw.color
(0.0, 0.0, 0.0);
2110 GlDraw.color
(1.0, 1.0, 1.0);
2111 drawstring fstate.fontsize
2112 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2115 match state.mode
with
2116 | Textentry
((prefix
, text, _, _, _, _), _) ->
2120 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2122 Printf.sprintf
"%s%s_" prefix
text
2131 if not
(istextentry state.mode
)
2133 let s1 = "(press 'e' to review error messasges)" in
2134 if String.length
s > 0 then s ^
" " ^
s1 else s1
2139 if String.length
s > 0
2144 let len = Queue.length
state.tilelru
in
2146 match state.throttle
with
2149 then preloadlayout state.y
2151 | Some
(layout, _, _) ->
2155 if state.memused
<= conf.memlimit
2160 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2161 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2162 let (_, pw, ph
, _) = getpagedim n in
2165 && colorspace
= conf.colorspace
2166 && angle
= conf.angle
2170 let x = col*conf.tilew
2171 and y = row*conf.tileh
in
2172 tilevisible (Lazy.force_val
layout) n x y
2174 then Queue.push lruitem
state.tilelru
2177 wcmd "freetile %s" p
;
2178 state.memused
<- state.memused
- s;
2179 state.uioh#infochanged Memused
;
2180 Hashtbl.remove
state.tilemap k
;
2189 Queue.iter
(fun (k
, p
, s) ->
2190 wcmd "freetile %s" p
;
2191 state.memused
<- state.memused
- s;
2192 state.uioh#infochanged Memused
;
2193 Hashtbl.remove
state.tilemap k
;
2195 Queue.clear
state.tilelru
;
2199 let logcurrently = function
2200 | Idle
-> dolog "Idle"
2201 | Loading
(l
, gen
) ->
2202 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2203 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2205 "Tiling %d[%d,%d] page=%s cs=%s angle"
2206 l
.pageno col row pageopaque
2207 (colorspace_to_string colorspace
)
2209 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2210 angle gen
conf.angle
state.gen
2212 conf.tilew
conf.tileh
2219 (* dolog "%S" cmds; *)
2222 try String.index cmds ' '
2223 with Not_found
-> -1
2228 let l = String.length cmds
in
2229 let op = String.sub cmds
0 spacepos in
2231 if l - spacepos < 2 then ""
2232 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2237 state.uioh#infochanged Pdim
;
2241 state.rects
<- state.rects1
;
2242 G.postRedisplay "clearrects";
2246 try Scanf.sscanf
args "%u" (fun n -> n)
2248 dolog "error processing 'continue' %S: %s"
2249 cmds
(Printexc.to_string exn
);
2252 state.pagecount
<- n;
2253 begin match state.currently
with
2255 state.currently
<- Idle
;
2256 state.outlines
<- Array.of_list
(List.rev
l)
2260 let cur, cmds
= state.geomcmds
in
2261 if String.length
cur = 0
2262 then failwith
"umpossible";
2264 begin match List.rev cmds
with
2266 state.geomcmds
<- "", [];
2270 state.geomcmds
<- s, List.rev rest
;
2272 if conf.maxwait
= None
2273 then G.postRedisplay "continue";
2283 then showtext ' '
args
2286 let progress, text =
2288 Scanf.sscanf
args "%f %n"
2290 f, String.sub
args pos
(String.length
args - pos
))
2292 dolog "error processing 'progress' %S: %s"
2293 cmds
(Printexc.to_string exn
);
2297 state.progress <- progress;
2298 G.postRedisplay "progress"
2301 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2303 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2304 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2305 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2307 dolog "error processing 'firstmatch' %S: %s"
2308 cmds
(Printexc.to_string exn
);
2311 let y = (getpagey pageno) + truncate
y0 in
2314 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2317 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2319 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2320 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2321 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2323 dolog "error processing 'match' %S: %s"
2324 cmds
(Printexc.to_string exn
);
2328 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2333 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2335 dolog "error processing 'page' %S: %s"
2336 cmds
(Printexc.to_string exn
);
2339 begin match state.currently
with
2340 | Loading
(l, gen
) ->
2341 vlog "page %d took %f sec" l.pageno t
;
2342 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2343 begin match state.throttle
with
2345 let preloadedpages =
2347 then preloadlayout state.y
2352 Set.Make
(struct type t
= int let compare = (-) end) in
2354 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2355 IntSet.empty
preloadedpages
2358 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2359 if not
(IntSet.mem
pageno set)
2361 wcmd "freepage %s" opaque
;
2367 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2370 state.currently
<- Idle
;
2373 tilepage l.pageno pageopaque state.layout;
2375 load preloadedpages;
2376 if pagevisible state.layout l.pageno
2377 && layoutready state.layout
2378 then G.postRedisplay "page";
2381 | Some
(layout, _, _) ->
2382 state.currently
<- Idle
;
2383 tilepage l.pageno pageopaque layout;
2388 dolog "Inconsistent loading state";
2389 logcurrently state.currently
;
2394 let (x, y, opaque
, size
, t
) =
2396 Scanf.sscanf
args "%u %u %s %u %f"
2397 (fun x y p size t
-> (x, y, p
, size
, t
))
2399 dolog "error processing 'tile' %S: %s"
2400 cmds
(Printexc.to_string exn
);
2403 begin match state.currently
with
2404 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2405 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2408 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2410 wcmd "freetile %s" opaque
;
2411 state.currently
<- Idle
;
2415 puttileopaque l col row gen cs angle opaque size t
;
2416 state.memused
<- state.memused
+ size
;
2417 state.uioh#infochanged Memused
;
2419 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2420 opaque
, size
) state.tilelru
;
2423 match state.throttle
with
2424 | None
-> state.layout
2425 | Some
(layout, _, _) -> layout
2428 state.currently
<- Idle
;
2430 && conf.colorspace
= cs
2431 && conf.angle
= angle
2432 && tilevisible layout l.pageno x y
2433 then conttiling l.pageno pageopaque;
2435 begin match state.throttle
with
2437 state.wthack
<- false;
2438 preload state.layout;
2440 && conf.colorspace
= cs
2441 && conf.angle
= angle
2442 && tilevisible state.layout l.pageno x y
2443 then G.postRedisplay "tile nothrottle";
2445 | Some
(layout, y, _) ->
2446 let ready = layoutready layout in
2449 state.wthack
<- false;
2451 state.layout <- layout;
2452 state.throttle
<- None
;
2453 G.postRedisplay "throttle";
2460 dolog "Inconsistent tiling state";
2461 logcurrently state.currently
;
2468 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2470 dolog "error processing 'pdim' %S: %s"
2471 cmds
(Printexc.to_string exn
);
2474 state.uioh#infochanged Pdim
;
2475 state.pdims
<- pdim :: state.pdims
2478 let (l, n, t
, h, pos
) =
2480 Scanf.sscanf
args "%u %u %d %u %n"
2481 (fun l n t
h pos
-> l, n, t
, h, pos
)
2483 dolog "error processing 'o' %S: %s"
2484 cmds
(Printexc.to_string exn
);
2487 let s = String.sub
args pos
(String.length
args - pos
) in
2488 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2489 begin match state.currently
with
2490 | Outlining outlines
->
2491 state.currently
<- Outlining
(outline :: outlines
)
2493 state.currently
<- Outlining
[outline]
2495 dolog "invalid outlining state";
2496 logcurrently currently
2500 state.docinfo
<- (1, args) :: state.docinfo
2503 state.uioh#infochanged Docinfo
;
2504 state.docinfo
<- List.rev
state.docinfo
2507 dolog "unknown cmd `%S'" cmds
2512 let action = function
2513 | HCprev
-> cbget cb ~
-1
2514 | HCnext
-> cbget cb
1
2515 | HCfirst
-> cbget cb ~
-(cb
.rc)
2516 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2517 and cancel
() = cb
.rc <- rc
2521 let search pattern forward
=
2522 if String.length pattern
> 0
2525 match state.layout with
2528 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2530 wcmd "search %d %d %d %d,%s\000"
2531 (btod conf.icase
) pn py
(btod forward
) pattern
;
2534 let intentry text key =
2536 if key >= 32 && key < 127
2542 let text = addchar text c in
2546 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2550 let linknentry text key =
2552 if key >= 32 && key < 127
2558 let text = addchar text c in
2562 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2567 if String.length
s > 0
2570 let l = String.length
s in
2571 let rec loop pos
n = if pos
= l then n else
2572 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2573 loop (pos
+1) (n*26 + m)
2576 let rec loop n = function
2579 match getopaque l.pageno with
2580 | None
-> loop n rest
2582 let m = getlinkcount opaque
in
2585 let under = getlink opaque
n in
2588 else loop (n-m) rest
2590 loop n state.layout;
2594 let textentry text key =
2595 if key land 0xff00 = 0xff00
2597 else TEcont
(text ^
Wsi.toutf8
key)
2600 let reqlayout angle proportional
=
2601 match state.throttle
with
2603 if nogeomcmds state.geomcmds
2604 then state.anchor <- getanchor ();
2605 conf.angle
<- angle
mod 360;
2608 match state.mode
with
2609 | LinkNav
_ -> state.mode
<- View
2612 conf.proportional
<- proportional
;
2613 invalidate "reqlayout"
2614 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2618 let settrim trimmargins trimfuzz
=
2619 if nogeomcmds state.geomcmds
2620 then state.anchor <- getanchor ();
2621 conf.trimmargins
<- trimmargins
;
2622 conf.trimfuzz
<- trimfuzz
;
2623 let x0, y0, x1, y1 = trimfuzz
in
2624 invalidate "settrim"
2626 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2631 match state.throttle
with
2633 let zoom = max
0.01 zoom in
2634 if zoom <> conf.zoom
2636 state.prevzoom
<- conf.zoom;
2638 reshape conf.winw
conf.winh
;
2639 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2642 | Some
(layout, y, started
) ->
2644 match conf.maxwait
with
2648 let dt = now () -. started
in
2656 let setcolumns mode columns coverA coverB
=
2657 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2661 then showtext '
!'
"split mode doesn't work in bird's eye"
2663 conf.columns
<- Csplit
(-columns
, [||]);
2671 conf.columns
<- Csingle
[||];
2676 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2680 reshape conf.winw
conf.winh
;
2683 let enterbirdseye () =
2684 let zoom = float conf.thumbw
/. float conf.winw
in
2685 let birdseyepageno =
2686 let cy = conf.winh
/ 2 in
2690 let rec fold best
= function
2693 let d = cy - (l.pagedispy + l.pagevh/2)
2694 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2695 if abs
d < abs dbest
2702 state.mode
<- Birdseye
(
2703 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2706 conf.presentation
<- false;
2707 conf.interpagespace
<- 10;
2708 conf.hlinks
<- false;
2710 state.mstate
<- Mnone
;
2711 conf.maxwait
<- None
;
2713 match conf.beyecolumns
with
2716 Cmulti
((c, 0, 0), [||])
2717 | None
-> Csingle
[||]
2719 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2722 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2727 reshape conf.winw
conf.winh
;
2730 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2732 conf.zoom <- c.zoom;
2733 conf.presentation
<- c.presentation
;
2734 conf.interpagespace
<- c.interpagespace
;
2735 conf.maxwait
<- c.maxwait
;
2736 conf.hlinks
<- c.hlinks
;
2737 conf.beyecolumns
<- (
2738 match conf.columns
with
2739 | Cmulti
((c, _, _), _) -> Some
c
2741 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2744 match c.columns
with
2745 | Cmulti
(c, _) -> Cmulti
(c, [||])
2746 | Csingle
_ -> Csingle
[||]
2747 | Csplit
(c, _) -> Csplit
(c, [||])
2752 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2755 reshape conf.winw
conf.winh
;
2756 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2759 let togglebirdseye () =
2760 match state.mode
with
2761 | Birdseye vals
-> leavebirdseye vals
true
2762 | View
-> enterbirdseye ()
2766 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2767 let pageno = max
0 (pageno - incr
) in
2768 let rec loop = function
2769 | [] -> gotopage1 pageno 0
2770 | l :: _ when l.pageno = pageno ->
2771 if l.pagedispy >= 0 && l.pagey = 0
2772 then G.postRedisplay "upbirdseye"
2773 else gotopage1 pageno 0
2774 | _ :: rest
-> loop rest
2777 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2780 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2781 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2782 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2783 let rec loop = function
2785 let y, h = getpageyh pageno in
2786 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2788 | l :: _ when l.pageno = pageno ->
2789 if l.pagevh != l.pageh
2790 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2791 else G.postRedisplay "downbirdseye"
2792 | _ :: rest
-> loop rest
2797 let optentry mode
_ key =
2798 let btos b = if b then "on" else "off" in
2799 if key >= 32 && key < 127
2801 let c = Char.chr
key in
2805 try conf.scrollstep
<- int_of_string
s with exc
->
2806 state.text <- Printf.sprintf
"bad integer `%s': %s"
2807 s (Printexc.to_string exc
)
2809 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2814 conf.autoscrollstep
<- int_of_string
s;
2815 if state.autoscroll
<> None
2816 then state.autoscroll
<- Some
conf.autoscrollstep
2818 state.text <- Printf.sprintf
"bad integer `%s': %s"
2819 s (Printexc.to_string exc
)
2821 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2826 let n, a, b = multicolumns_of_string s in
2827 setcolumns mode
n a b;
2829 state.text <- Printf.sprintf
"bad columns `%s': %s"
2830 s (Printexc.to_string exc
)
2832 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2837 let zoom = float (int_of_string
s) /. 100.0 in
2840 state.text <- Printf.sprintf
"bad integer `%s': %s"
2841 s (Printexc.to_string exc
)
2843 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2848 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2850 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2851 begin match mode
with
2853 leavebirdseye beye
false;
2858 state.text <- Printf.sprintf
"bad integer `%s': %s"
2859 s (Printexc.to_string exc
)
2861 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2866 Some
(int_of_string
s)
2868 state.text <- Printf.sprintf
"bad integer `%s': %s"
2869 s (Printexc.to_string exc
);
2872 | Some angle
-> reqlayout angle
conf.proportional
2875 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2878 conf.icase
<- not
conf.icase
;
2879 TEdone
("case insensitive search " ^
(btos conf.icase
))
2882 conf.preload <- not
conf.preload;
2884 TEdone
("preload " ^
(btos conf.preload))
2887 conf.verbose
<- not
conf.verbose
;
2888 TEdone
("verbose " ^
(btos conf.verbose
))
2891 conf.debug
<- not
conf.debug
;
2892 TEdone
("debug " ^
(btos conf.debug
))
2895 conf.maxhfit
<- not
conf.maxhfit
;
2896 state.maxy
<- calcheight ();
2897 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2900 conf.crophack
<- not
conf.crophack
;
2901 TEdone
("crophack " ^
btos conf.crophack
)
2905 match conf.maxwait
with
2907 conf.maxwait
<- Some infinity
;
2908 "always wait for page to complete"
2910 conf.maxwait
<- None
;
2911 "show placeholder if page is not ready"
2916 conf.underinfo
<- not
conf.underinfo
;
2917 TEdone
("underinfo " ^
btos conf.underinfo
)
2920 conf.savebmarks
<- not
conf.savebmarks
;
2921 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2927 match state.layout with
2932 conf.interpagespace
<- int_of_string
s;
2933 docolumns conf.columns
;
2934 state.maxy
<- calcheight ();
2935 let y = getpagey pageno in
2938 state.text <- Printf.sprintf
"bad integer `%s': %s"
2939 s (Printexc.to_string exc
)
2941 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2944 reqlayout conf.angle
(not
conf.proportional
);
2945 TEdone
("proportional display " ^
btos conf.proportional
)
2948 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2949 TEdone
("trim margins " ^
btos conf.trimmargins
)
2952 conf.invert
<- not
conf.invert
;
2953 TEdone
("invert colors " ^
btos conf.invert
)
2957 cbput state.hists
.sel
s;
2960 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2961 textentry, ondone, true)
2964 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2970 class type lvsource
= object
2971 method getitemcount
: int
2972 method getitem
: int -> (string * int)
2973 method hasaction
: int -> bool
2982 method getactive
: int
2983 method getfirst
: int
2984 method getqsearch
: string
2985 method setqsearch
: string -> unit
2989 class virtual lvsourcebase
= object
2990 val mutable m_active
= 0
2991 val mutable m_first
= 0
2992 val mutable m_qsearch
= ""
2993 val mutable m_pan
= 0
2994 method getactive
= m_active
2995 method getfirst
= m_first
2996 method getqsearch
= m_qsearch
2997 method getpan
= m_pan
2998 method setqsearch
s = m_qsearch
<- s
3001 let withoutlastutf8 s =
3002 let len = String.length
s in
3010 let b = Char.code
s.[pos
] in
3011 if b land 0b11000000 = 0b11000000
3016 if Char.code
s.[len-1] land 0x80 = 0
3020 String.sub
s 0 first;
3023 let textentrykeyboard
3024 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3026 if key >= 0xffb0 && key <= 0xffb9
3027 then key - 0xffb0 + 48 else key
3030 state.mode
<- Textentry
(te
, onleave
);
3033 G.postRedisplay "textentrykeyboard enttext";
3035 let histaction cmd
=
3038 | Some
(action, _) ->
3039 state.mode
<- Textentry
(
3040 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3042 G.postRedisplay "textentry histaction"
3045 | 0xff08 -> (* backspace *)
3046 let s = withoutlastutf8 text in
3047 let len = String.length
s in
3048 if cancelonempty
&& len = 0
3051 G.postRedisplay "textentrykeyboard after cancel";
3054 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3057 | 0xff0d | 0xff8d -> (* (kp) enter *)
3060 G.postRedisplay "textentrykeyboard after confirm"
3062 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3063 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3064 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3065 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3067 | 0xff1b -> (* escape*)
3068 if String.length
text = 0
3070 begin match opthist
with
3072 | Some
(_, onhistcancel
) -> onhistcancel
()
3076 G.postRedisplay "textentrykeyboard after cancel2"
3079 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3082 | 0xff9f | 0xffff -> () (* delete *)
3085 && key land 0xff00 != 0xff00 (* keyboard *)
3086 && key land 0xfe00 != 0xfe00 (* xkb *)
3087 && key land 0xfd00 != 0xfd00 (* 3270 *)
3089 begin match onkey
text key with
3093 G.postRedisplay "textentrykeyboard after confirm2";
3096 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3100 G.postRedisplay "textentrykeyboard after cancel3"
3103 state.mode
<- Textentry
(te
, onleave
);
3104 G.postRedisplay "textentrykeyboard switch";
3108 vlog "unhandled key %s" (Wsi.keyname
key)
3111 let firstof first active
=
3112 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3113 then max
0 (active
- (fstate.maxrows
/2))
3117 let calcfirst first active
=
3120 let rows = active
- first in
3121 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3125 let scrollph y maxy
=
3126 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3127 let sh = float conf.winh
/. sh in
3128 let sh = max
sh (float conf.scrollh
) in
3133 else float y /. float maxy
3135 let position = (float conf.winh
-. sh) *. percent in
3138 if position +. sh > float conf.winh
3139 then float conf.winh
-. sh
3145 let coe s = (s :> uioh
);;
3147 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3149 val m_pan
= source#getpan
3150 val m_first
= source#getfirst
3151 val m_active
= source#getactive
3152 val m_qsearch
= source#getqsearch
3153 val m_prev_uioh
= state.uioh
3155 method private elemunder
y =
3156 let n = y / (fstate.fontsize
+1) in
3157 if m_first
+ n < source#getitemcount
3159 if source#hasaction
(m_first
+ n)
3160 then Some
(m_first
+ n)
3167 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3168 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3169 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3170 GlDraw.color
(1., 1., 1.);
3171 Gl.enable `texture_2d
;
3172 let fs = fstate.fontsize
in
3174 let ww = fstate.wwidth
in
3175 let tabw = 30.0*.ww in
3176 let itemcount = source#getitemcount
in
3178 if (row - m_first
) > fstate.maxrows
3181 if row >= 0 && row < itemcount
3183 let (s, level
) = source#getitem
row in
3184 let y = (row - m_first
) * nfs in
3185 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3188 Gl.disable `texture_2d
;
3189 GlDraw.polygon_mode `both `line
;
3190 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3191 GlDraw.rect (1., float (y + 1))
3192 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3193 GlDraw.polygon_mode `both `fill
;
3194 GlDraw.color
(1., 1., 1.);
3195 Gl.enable `texture_2d
;
3198 let drawtabularstring s =
3199 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3202 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3205 let len = String.length
s - tabpos - 1 in
3206 let s1 = String.sub
s 0 tabpos
3207 and s2
= String.sub
s (tabpos + 1) len in
3208 let nx = drawstr x s1 in
3210 let x = x +. (max
tabw sw) in
3217 let _ = drawtabularstring s in
3224 Gl.disable `texture_2d
;
3226 method updownlevel incr
=
3227 let len = source#getitemcount
in
3229 if m_active
>= 0 && m_active
< len
3230 then snd
(source#getitem m_active
)
3234 if i
= len then i
-1 else if i
= -1 then 0 else
3235 let _, l = source#getitem i
in
3236 if l != curlevel then i
else flow (i
+incr
)
3238 let active = flow m_active
in
3239 let first = calcfirst m_first
active in
3240 G.postRedisplay "outline updownlevel";
3241 {< m_active
= active; m_first
= first >}
3243 method private key1
key mask
=
3244 let set1 active first qsearch
=
3245 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3247 let search active pattern incr
=
3250 if n >= 0 && n < source#getitemcount
3252 let s, _ = source#getitem
n in
3254 (try ignore
(Str.search_forward
re s 0); true
3255 with Not_found
-> false)
3257 else loop (n + incr
)
3264 let re = Str.regexp_case_fold pattern
in
3270 let itemcount = source#getitemcount
in
3271 let find start incr
=
3273 if i
= -1 || i
= itemcount
3276 if source#hasaction i
3278 else find (i
+ incr
)
3283 let set active first =
3284 let first = bound first 0 (itemcount - fstate.maxrows
) in
3286 coe {< m_active
= active; m_first
= first >}
3289 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3291 let incr1 = if incr
> 0 then 1 else -1 in
3292 if isvisible m_first m_active
3295 let next = m_active
+ incr
in
3297 if next < 0 || next >= itemcount
3299 else find next incr1
3301 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3307 let first = m_first
+ incr
in
3308 let first = bound first 0 (itemcount - 1) in
3310 let next = m_active
+ incr
in
3311 let next = bound next 0 (itemcount - 1) in
3314 let active = if next = -1 then m_active
else next in
3317 let first = min
next m_first
in
3319 if abs
(next - first) > fstate.maxrows
3325 let first = m_first
+ incr
in
3326 let first = bound first 0 (itemcount - 1) in
3328 let next = m_active
+ incr
in
3329 let next = bound next 0 (itemcount - 1) in
3330 let next = find next incr1 in
3332 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3334 let active = if m_active
= -1 then next else m_active
in
3339 if isvisible first active
3345 G.postRedisplay "listview navigate";
3349 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3350 let incr = if key = 0x72 then -1 else 1 in
3352 match search (m_active
+ incr) m_qsearch
incr with
3354 state.text <- m_qsearch ^
" [not found]";
3357 state.text <- m_qsearch
;
3358 active, firstof m_first
active
3360 G.postRedisplay "listview ctrl-r/s";
3361 set1 active first m_qsearch
;
3363 | 0xff08 -> (* backspace *)
3364 if String.length m_qsearch
= 0
3367 let qsearch = withoutlastutf8 m_qsearch
in
3368 let len = String.length
qsearch in
3372 G.postRedisplay "listview empty qsearch";
3373 set1 m_active m_first
"";
3377 match search m_active
qsearch ~
-1 with
3379 state.text <- qsearch ^
" [not found]";
3382 state.text <- qsearch;
3383 active, firstof m_first
active
3385 G.postRedisplay "listview backspace qsearch";
3386 set1 active first qsearch
3389 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3390 let pattern = m_qsearch ^
Wsi.toutf8
key in
3392 match search m_active
pattern 1 with
3394 state.text <- pattern ^
" [not found]";
3397 state.text <- pattern;
3398 active, firstof m_first
active
3400 G.postRedisplay "listview qsearch add";
3401 set1 active first pattern;
3403 | 0xff1b -> (* escape *)
3405 if String.length m_qsearch
= 0
3407 G.postRedisplay "list view escape";
3410 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3412 | None
-> m_prev_uioh
3417 G.postRedisplay "list view kill qsearch";
3418 source#setqsearch
"";
3419 coe {< m_qsearch
= "" >}
3422 | 0xff0d | 0xff8d -> (* (kp) enter *)
3424 let self = {< m_qsearch
= "" >} in
3425 source#setqsearch
"";
3427 G.postRedisplay "listview enter";
3428 if m_active
>= 0 && m_active
< source#getitemcount
3430 source#exit
(coe self) false m_active m_first m_pan
"";
3433 source#exit
(coe self) true m_active m_first m_pan
"";
3436 begin match opt with
3437 | None
-> m_prev_uioh
3441 | 0xff9f | 0xffff -> (* (kp) delete *)
3444 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3445 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3446 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3447 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3449 | 0xff53 | 0xff98 -> (* (kp) right *)
3451 G.postRedisplay "listview right";
3452 coe {< m_pan
= m_pan
- 1 >}
3454 | 0xff51 | 0xff96 -> (* (kp) left *)
3456 G.postRedisplay "listview left";
3457 coe {< m_pan
= m_pan
+ 1 >}
3459 | 0xff50 | 0xff95 -> (* (kp) home *)
3460 let active = find 0 1 in
3461 G.postRedisplay "listview home";
3464 | 0xff57 | 0xff9c -> (* (kp) end *)
3465 let first = max
0 (itemcount - fstate.maxrows
) in
3466 let active = find (itemcount - 1) ~
-1 in
3467 G.postRedisplay "listview end";
3470 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3474 dolog "listview unknown key %#x" key; coe self
3476 method key key mask
=
3477 match state.mode
with
3478 | Textentry te
-> textentrykeyboard key mask te
; coe self
3479 | _ -> self#key1
key mask
3481 method button button down
x y _ =
3484 | 1 when x > conf.winw
- conf.scrollbw
->
3485 G.postRedisplay "listview scroll";
3488 let _, position, sh = self#
scrollph in
3489 if y > truncate
position && y < truncate
(position +. sh)
3491 state.mstate
<- Mscrolly
;
3495 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3496 let first = truncate
(s *. float source#getitemcount
) in
3497 let first = min source#getitemcount
first in
3498 Some
(coe {< m_first
= first; m_active
= first >})
3500 state.mstate
<- Mnone
;
3503 | 1 when not down
->
3504 begin match self#elemunder
y with
3506 G.postRedisplay "listview click";
3508 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3512 | n when (n == 4 || n == 5) && not down
->
3513 let len = source#getitemcount
in
3515 if n = 5 && m_first
+ fstate.maxrows
>= len
3519 let first = m_first
+ (if n == 4 then -1 else 1) in
3520 bound first 0 (len - 1)
3522 G.postRedisplay "listview wheel";
3523 Some
(coe {< m_first
= first >})
3524 | n when (n = 6 || n = 7) && not down
->
3525 let inc = m_first
+ (if n = 7 then -1 else 1) in
3526 G.postRedisplay "listview hwheel";
3527 Some
(coe {< m_pan
= m_pan
+ inc >})
3532 | None
-> m_prev_uioh
3536 match state.mstate
with
3538 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3539 let first = truncate
(s *. float source#getitemcount
) in
3540 let first = min source#getitemcount
first in
3541 G.postRedisplay "listview motion";
3542 coe {< m_first
= first; m_active
= first >}
3545 method pmotion
x y =
3546 if x < conf.winw
- conf.scrollbw
3549 match self#elemunder
y with
3550 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3551 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3555 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3560 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3564 method infochanged
_ = ()
3566 method scrollpw
= (0, 0.0, 0.0)
3568 let nfs = fstate.fontsize
+ 1 in
3569 let y = m_first
* nfs in
3570 let itemcount = source#getitemcount
in
3571 let maxi = max
0 (itemcount - fstate.maxrows
) in
3572 let maxy = maxi * nfs in
3573 let p, h = scrollph y maxy in
3576 method modehash
= modehash
3579 class outlinelistview ~source
=
3582 ~source
:(source
:> lvsource
)
3584 ~modehash
:(findkeyhash conf "outline")
3587 method key key mask
=
3588 let calcfirst first active =
3591 let rows = active - first in
3593 if String.length
state.text = 0
3595 else fstate.maxrows - 2
3597 if rows > maxrows then active - maxrows else first
3601 let active = m_active
+ incr in
3602 let active = bound active 0 (source#getitemcount
- 1) in
3603 let first = calcfirst m_first
active in
3604 G.postRedisplay "outline navigate";
3605 coe {< m_active
= active; m_first
= first >}
3607 let ctrl = Wsi.withctrl mask
in
3609 | 110 when ctrl -> (* ctrl-n *)
3610 source#narrow m_qsearch
;
3611 G.postRedisplay "outline ctrl-n";
3612 coe {< m_first
= 0; m_active
= 0 >}
3614 | 117 when ctrl -> (* ctrl-u *)
3616 G.postRedisplay "outline ctrl-u";
3618 coe {< m_first
= 0; m_active
= 0 >}
3620 | 108 when ctrl -> (* ctrl-l *)
3621 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3622 G.postRedisplay "outline ctrl-l";
3623 coe {< m_first
= first >}
3625 | 0xff9f | 0xffff -> (* (kp) delete *)
3626 source#remove m_active
;
3627 G.postRedisplay "outline delete";
3628 let active = max
0 (m_active
-1) in
3629 coe {< m_first
= firstof m_first
active;
3630 m_active
= active >}
3632 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3633 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3634 | 0xff55 | 0xff9a -> (* (kp) prior *)
3635 navigate ~
-(fstate.maxrows)
3636 | 0xff56 | 0xff9b -> (* (kp) next *)
3637 navigate fstate.maxrows
3639 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3643 G.postRedisplay "outline ctrl right";
3644 {< m_pan
= m_pan
+ 1 >}
3646 else self#updownlevel
1
3650 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3654 G.postRedisplay "outline ctrl left";
3655 {< m_pan
= m_pan
- 1 >}
3657 else self#updownlevel ~
-1
3661 | 0xff50 | 0xff95 -> (* (kp) home *)
3662 G.postRedisplay "outline home";
3663 coe {< m_first
= 0; m_active
= 0 >}
3665 | 0xff57 | 0xff9c -> (* (kp) end *)
3666 let active = source#getitemcount
- 1 in
3667 let first = max
0 (active - fstate.maxrows) in
3668 G.postRedisplay "outline end";
3669 coe {< m_active
= active; m_first
= first >}
3671 | _ -> super#
key key mask
3674 let outlinesource usebookmarks
=
3677 inherit lvsourcebase
3678 val mutable m_items
= empty
3679 val mutable m_orig_items
= empty
3680 val mutable m_prev_items
= empty
3681 val mutable m_narrow_pattern
= ""
3682 val mutable m_hadremovals
= false
3684 method getitemcount
=
3685 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3688 if n == Array.length m_items
&& m_hadremovals
3690 ("[Confirm removal]", 0)
3692 let s, n, _ = m_items
.(n) in
3695 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3696 ignore
(uioh
, first, qsearch);
3697 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3699 if String.length m_narrow_pattern
= 0
3705 if not
confrimremoval
3707 let _, _, anchor = m_items
.(active) in
3708 gotoghyll (getanchory anchor);
3712 state.bookmarks
<- Array.to_list m_items
;
3713 m_orig_items
<- m_items
;
3716 else m_items
<- items;
3720 method hasaction
_ = true
3723 if Array.length m_items
!= Array.length m_orig_items
3724 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3727 method narrow
pattern =
3728 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3732 let rec loop accu n =
3735 m_narrow_pattern
<- pattern;
3736 m_items
<- Array.of_list
accu
3739 let (s, _, _) as o = m_items
.(n) in
3741 if (try ignore
(Str.search_forward
re s 0); true
3742 with Not_found
-> false)
3748 loop [] (Array.length m_items
- 1)
3753 then Array.of_list
state.bookmarks
3756 m_items
<- m_orig_items
3761 if m >= 0 && m < Array.length m_items
3763 m_hadremovals
<- true;
3764 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3765 let n = if n >= m then n+1 else n in
3770 method reset
anchor items =
3771 m_hadremovals
<- false;
3772 if m_orig_items
== empty || m_prev_items
!= items
3774 m_orig_items
<- items;
3775 if String.length m_narrow_pattern
= 0
3776 then m_items
<- items;
3778 m_prev_items
<- items;
3779 let rely = getanchory anchor in
3781 let rec loop n best bestd
=
3782 if n = Array.length m_items
3785 let (_, _, anchor) = m_items
.(n) in
3786 let orely = getanchory anchor in
3787 let d = abs
(orely - rely) in
3790 else loop (n+1) best bestd
3795 m_first
<- firstof m_first
active
3799 let enterselector usebookmarks
=
3800 let source = outlinesource usebookmarks
in
3804 then Array.of_list
state.bookmarks
3807 if Array.length
outlines = 0
3809 showtext ' ' errmsg
;
3812 state.text <- source#greetmsg
;
3813 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3814 let anchor = getanchor () in
3815 source#reset
anchor outlines;
3816 state.uioh
<- coe (new outlinelistview ~
source);
3817 G.postRedisplay "enter selector";
3821 let enteroutlinemode =
3822 let f = enterselector false in
3823 fun ()-> f "Document has no outline";
3826 let enterbookmarkmode =
3827 let f = enterselector true in
3828 fun () -> f "Document has no bookmarks (yet)";
3831 let color_of_string s =
3832 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3833 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3837 let color_to_string (r, g
, b) =
3838 let r = truncate
(r *. 256.0)
3839 and g
= truncate
(g
*. 256.0)
3840 and b = truncate
(b *. 256.0) in
3841 Printf.sprintf
"%d/%d/%d" r g
b
3844 let irect_of_string s =
3845 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3848 let irect_to_string (x0,y0,x1,y1) =
3849 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3852 let makecheckers () =
3853 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3855 converted by Issac Trotts. July 25, 2002 *)
3856 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3857 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3858 let id = GlTex.gen_texture
() in
3859 GlTex.bind_texture `texture_2d
id;
3860 GlPix.store
(`unpack_alignment
1);
3861 GlTex.image2d
image;
3862 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3865 `mag_filter `nearest
;
3866 `min_filter `nearest
];
3870 let setcheckers enabled
=
3871 match state.texid
with
3873 if enabled
then state.texid
<- Some
(makecheckers ())
3878 GlTex.delete_texture texid
;
3879 state.texid
<- None
;
3883 let int_of_string_with_suffix s =
3884 let l = String.length
s in
3888 let suffix = Char.lowercase
s.[l-1] in
3890 | 'k'
-> String.sub
s 0 (l-1), 10
3891 | '
m'
-> String.sub
s 0 (l-1), 20
3892 | 'g'
-> String.sub
s 0 (l-1), 30
3896 let n = int_of_string
s1 in
3897 let m = n lsl shift
in
3899 then raise
(Failure
"value too large")
3903 let string_with_suffix_of_int n =
3908 if n land ((1 lsl 30) - 1) = 0
3911 if n land ((1 lsl 20) - 1) = 0
3914 if n land ((1 lsl 10) - 1) = 0
3921 let h = n mod 1000 in
3924 then string_of_int
h ^
s
3926 let s = Printf.sprintf
"_%03d%s" h s in
3933 let defghyllscroll = (40, 8, 32);;
3934 let ghyllscroll_of_string s =
3935 let (n, a, b) as nab
=
3938 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3940 if n <= a || n <= b || a >= b
3941 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3945 let ghyllscroll_to_string ((n, a, b) as nab
) =
3946 if nab
= defghyllscroll
3948 else Printf.sprintf
"%d,%d,%d" n a b;
3951 let describe_location () =
3953 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3955 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3956 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3960 else (100. *. (float state.y /. float maxy))
3964 Printf.sprintf
"page %d of %d [%.2f%%]"
3965 (fn+1) state.pagecount
percent
3968 "pages %d-%d of %d [%.2f%%]"
3969 (fn+1) (ln
+1) state.pagecount
percent
3972 let setpresentationmode v
=
3973 let (n, _, _) = getanchor () in
3974 let _, h = getpageyh n in
3975 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
3976 state.anchor <- (n, 0.0, float ips);
3977 conf.presentation
<- v
;
3978 if conf.presentation
3980 if not
conf.scrollbarinpm
3981 then state.scrollw
<- 0;
3983 else state.scrollw
<- conf.scrollbw
;
3988 let btos b = if b then "\xe2\x88\x9a" else "" in
3989 let showextended = ref false in
3990 let leave mode
= function
3991 | Confirm
-> state.mode
<- mode
3992 | Cancel
-> state.mode
<- mode
in
3995 val mutable m_first_time
= true
3996 val mutable m_l
= []
3997 val mutable m_a
= [||]
3998 val mutable m_prev_uioh
= nouioh
3999 val mutable m_prev_mode
= View
4001 inherit lvsourcebase
4003 method reset prev_mode prev_uioh
=
4004 m_a
<- Array.of_list
(List.rev m_l
);
4006 m_prev_mode
<- prev_mode
;
4007 m_prev_uioh
<- prev_uioh
;
4011 if n >= Array.length m_a
4015 | _, _, _, Action
_ -> m_active
<- n
4019 m_first_time
<- false;
4022 method int name get
set =
4024 (name
, `
int get
, 1, Action
(
4027 try set (int_of_string
s)
4029 state.text <- Printf.sprintf
"bad integer `%s': %s"
4030 s (Printexc.to_string exn
)
4033 let te = name ^
": ", "", None
, intentry, ondone, true in
4034 state.mode
<- Textentry
(te, leave m_prev_mode
);
4038 method int_with_suffix name get
set =
4040 (name
, `intws get
, 1, Action
(
4043 try set (int_of_string_with_suffix s)
4045 state.text <- Printf.sprintf
"bad integer `%s': %s"
4046 s (Printexc.to_string exn
)
4050 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4052 state.mode
<- Textentry
(te, leave m_prev_mode
);
4056 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4058 (name
, `
bool (btos, get
), offset
, Action
(
4065 method color name get
set =
4067 (name
, `color get
, 1, Action
(
4069 let invalid = (nan
, nan
, nan
) in
4072 try color_of_string s
4074 state.text <- Printf.sprintf
"bad color `%s': %s"
4075 s (Printexc.to_string exn
);
4081 let te = name ^
": ", "", None
, textentry, ondone, true in
4082 state.text <- color_to_string (get
());
4083 state.mode
<- Textentry
(te, leave m_prev_mode
);
4087 method string name get
set =
4089 (name
, `
string get
, 1, Action
(
4091 let ondone s = set s in
4092 let te = name ^
": ", "", None
, textentry, ondone, true in
4093 state.mode
<- Textentry
(te, leave m_prev_mode
);
4097 method colorspace name get
set =
4099 (name
, `
string get
, 1, Action
(
4102 let vals = [| "rgb"; "bgr"; "gray" |] in
4104 inherit lvsourcebase
4107 m_active
<- int_of_colorspace conf.colorspace
;
4110 method getitemcount
= Array.length
vals
4111 method getitem
n = (vals.(n), 0)
4112 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4113 ignore
(uioh
, first, pan
, qsearch);
4114 if not cancel
then set active;
4116 method hasaction
_ = true
4120 let modehash = findkeyhash conf "info" in
4121 coe (new listview ~
source ~trusted
:true ~
modehash)
4124 method caption
s offset
=
4125 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4127 method caption2
s f offset
=
4128 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4130 method getitemcount
= Array.length m_a
4133 let tostr = function
4134 | `
int f -> string_of_int
(f ())
4135 | `intws
f -> string_with_suffix_of_int (f ())
4137 | `color
f -> color_to_string (f ())
4138 | `
bool (btos, f) -> btos (f ())
4141 let name, t
, offset
, _ = m_a
.(n) in
4142 ((let s = tostr t
in
4143 if String.length
s > 0
4144 then Printf.sprintf
"%s\t%s" name s
4148 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4152 m_qsearch
<- qsearch;
4154 match m_a
.(active) with
4155 | _, _, _, Action
f -> f uioh
4167 method hasaction
n =
4169 | _, _, _, Action
_ -> true
4173 let rec fillsrc prevmode prevuioh
=
4174 let sep () = src#caption
"" 0 in
4175 let colorp name get
set =
4177 (fun () -> color_to_string (get
()))
4180 let c = color_of_string v in
4183 state.text <- Printf.sprintf
"bad color `%s': %s"
4184 v (Printexc.to_string exn
);
4187 let oldmode = state.mode
in
4188 let birdseye = isbirdseye state.mode
in
4190 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4192 src#
bool "presentation mode"
4193 (fun () -> conf.presentation
)
4194 (fun v -> setpresentationmode v);
4196 src#
bool "ignore case in searches"
4197 (fun () -> conf.icase
)
4198 (fun v -> conf.icase
<- v);
4201 (fun () -> conf.preload)
4202 (fun v -> conf.preload <- v);
4204 src#
bool "highlight links"
4205 (fun () -> conf.hlinks
)
4206 (fun v -> conf.hlinks
<- v);
4208 src#
bool "under info"
4209 (fun () -> conf.underinfo
)
4210 (fun v -> conf.underinfo
<- v);
4212 src#
bool "persistent bookmarks"
4213 (fun () -> conf.savebmarks
)
4214 (fun v -> conf.savebmarks
<- v);
4216 src#
bool "proportional display"
4217 (fun () -> conf.proportional
)
4218 (fun v -> reqlayout conf.angle
v);
4220 src#
bool "trim margins"
4221 (fun () -> conf.trimmargins
)
4222 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4224 src#
bool "persistent location"
4225 (fun () -> conf.jumpback
)
4226 (fun v -> conf.jumpback
<- v);
4229 src#
int "inter-page space"
4230 (fun () -> conf.interpagespace
)
4232 conf.interpagespace
<- n;
4233 docolumns conf.columns
;
4235 match state.layout with
4240 state.maxy <- calcheight ();
4241 let y = getpagey pageno in
4246 (fun () -> conf.pagebias
)
4247 (fun v -> conf.pagebias
<- v);
4249 src#
int "scroll step"
4250 (fun () -> conf.scrollstep
)
4251 (fun n -> conf.scrollstep
<- n);
4253 src#
int "horizontal scroll step"
4254 (fun () -> conf.hscrollstep
)
4255 (fun v -> conf.hscrollstep
<- v);
4257 src#
int "auto scroll step"
4259 match state.autoscroll
with
4261 | _ -> conf.autoscrollstep
)
4263 if state.autoscroll
<> None
4264 then state.autoscroll
<- Some
n;
4265 conf.autoscrollstep
<- n);
4268 (fun () -> truncate
(conf.zoom *. 100.))
4269 (fun v -> setzoom ((float v) /. 100.));
4272 (fun () -> conf.angle
)
4273 (fun v -> reqlayout v conf.proportional
);
4275 src#
int "scroll bar width"
4276 (fun () -> state.scrollw
)
4280 reshape conf.winw
conf.winh
;
4283 src#
int "scroll handle height"
4284 (fun () -> conf.scrollh
)
4285 (fun v -> conf.scrollh
<- v;);
4287 src#
int "thumbnail width"
4288 (fun () -> conf.thumbw
)
4290 conf.thumbw
<- min
4096 v;
4293 leavebirdseye beye
false;
4298 let mode = state.mode in
4299 src#
string "columns"
4301 match conf.columns
with
4303 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4304 | Csplit
(count
, _) -> "-" ^ string_of_int count
4307 let n, a, b = multicolumns_of_string v in
4308 setcolumns mode n a b);
4311 src#caption
"Presentation mode" 0;
4312 src#
bool "scrollbar visible"
4313 (fun () -> conf.scrollbarinpm
)
4315 if v != conf.scrollbarinpm
4317 conf.scrollbarinpm
<- v;
4318 if conf.presentation
4320 state.scrollw
<- if v then conf.scrollbw
else 0;
4321 reshape conf.winw
conf.winh
;
4327 src#caption
"Pixmap cache" 0;
4328 src#int_with_suffix
"size (advisory)"
4329 (fun () -> conf.memlimit
)
4330 (fun v -> conf.memlimit
<- v);
4333 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4334 (string_with_suffix_of_int state.memused
)
4335 (Hashtbl.length
state.tilemap
)) 1;
4338 src#caption
"Layout" 0;
4339 src#caption2
"Dimension"
4341 Printf.sprintf
"%dx%d (virtual %dx%d)"
4347 src#caption2
"Position" (fun () ->
4348 Printf.sprintf
"%dx%d" state.x state.y
4351 src#caption2
"Visible" (fun () -> describe_location ()) 1
4355 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4356 "Save these parameters as global defaults at exit"
4357 (fun () -> conf.bedefault
)
4358 (fun v -> conf.bedefault
<- v)
4362 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4363 src#
bool ~offset
:0 ~
btos "Extended parameters"
4364 (fun () -> !showextended)
4365 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4369 (fun () -> conf.checkers
)
4370 (fun v -> conf.checkers
<- v; setcheckers v);
4371 src#
bool "update cursor"
4372 (fun () -> conf.updatecurs
)
4373 (fun v -> conf.updatecurs
<- v);
4375 (fun () -> conf.verbose
)
4376 (fun v -> conf.verbose
<- v);
4377 src#
bool "invert colors"
4378 (fun () -> conf.invert
)
4379 (fun v -> conf.invert
<- v);
4381 (fun () -> conf.maxhfit
)
4382 (fun v -> conf.maxhfit
<- v);
4383 src#
bool "redirect stderr"
4384 (fun () -> conf.redirectstderr)
4385 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4386 src#
string "uri launcher"
4387 (fun () -> conf.urilauncher
)
4388 (fun v -> conf.urilauncher
<- v);
4389 src#
string "path launcher"
4390 (fun () -> conf.pathlauncher
)
4391 (fun v -> conf.pathlauncher
<- v);
4392 src#
string "tile size"
4393 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4396 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4397 conf.tilew
<- max
64 w;
4398 conf.tileh
<- max
64 h;
4401 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4402 v (Printexc.to_string exn
));
4403 src#
int "texture count"
4404 (fun () -> conf.texcount
)
4407 then conf.texcount
<- v
4408 else showtext '
!'
" Failed to set texture count please retry later"
4410 src#
int "slice height"
4411 (fun () -> conf.sliceheight
)
4413 conf.sliceheight
<- v;
4414 wcmd "sliceh %d" conf.sliceheight
;
4416 src#
int "anti-aliasing level"
4417 (fun () -> conf.aalevel
)
4419 conf.aalevel
<- bound v 0 8;
4420 state.anchor <- getanchor ();
4421 opendoc state.path
state.password
;
4423 src#
string "page scroll scaling factor"
4424 (fun () -> string_of_float
conf.pgscale)
4427 let s = float_of_string
v in
4430 state.text <- Printf.sprintf
4431 "bad page scroll scaling factor `%s': %s"
4432 v (Printexc.to_string exn
)
4435 src#
int "ui font size"
4436 (fun () -> fstate.fontsize
)
4437 (fun v -> setfontsize (bound v 5 100));
4438 src#
int "hint font size"
4439 (fun () -> conf.hfsize
)
4440 (fun v -> conf.hfsize
<- bound v 5 100);
4441 colorp "background color"
4442 (fun () -> conf.bgcolor
)
4443 (fun v -> conf.bgcolor
<- v);
4444 src#
bool "crop hack"
4445 (fun () -> conf.crophack
)
4446 (fun v -> conf.crophack
<- v);
4447 src#
string "trim fuzz"
4448 (fun () -> irect_to_string conf.trimfuzz
)
4451 conf.trimfuzz
<- irect_of_string v;
4453 then settrim true conf.trimfuzz
;
4455 state.text <- Printf.sprintf
"bad irect `%s': %s"
4456 v (Printexc.to_string exn
)
4458 src#
string "throttle"
4460 match conf.maxwait
with
4461 | None
-> "show place holder if page is not ready"
4464 then "wait for page to fully render"
4466 "wait " ^ string_of_float
time
4467 ^
" seconds before showing placeholder"
4471 let f = float_of_string
v in
4473 then conf.maxwait
<- None
4474 else conf.maxwait
<- Some
f
4476 state.text <- Printf.sprintf
"bad time `%s': %s"
4477 v (Printexc.to_string exn
)
4479 src#
string "ghyll scroll"
4481 match conf.ghyllscroll
with
4483 | Some nab
-> ghyllscroll_to_string nab
4488 if String.length
v = 0
4490 else Some
(ghyllscroll_of_string v)
4492 conf.ghyllscroll
<- gs
4494 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4495 v (Printexc.to_string exn
)
4497 src#
string "selection command"
4498 (fun () -> conf.selcmd
)
4499 (fun v -> conf.selcmd
<- v);
4500 src#colorspace
"color space"
4501 (fun () -> colorspace_to_string conf.colorspace
)
4503 conf.colorspace
<- colorspace_of_int v;
4510 (fun () -> conf.usepbo
)
4511 (fun v -> conf.usepbo
<- v);
4515 src#caption
"Document" 0;
4516 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4517 src#caption2
"Pages"
4518 (fun () -> string_of_int
state.pagecount
) 1;
4519 src#caption2
"Dimensions"
4520 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4524 src#caption
"Trimmed margins" 0;
4525 src#caption2
"Dimensions"
4526 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4530 src#caption
"OpenGL" 0;
4531 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4532 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4533 src#reset prevmode prevuioh
;
4537 let prevmode = state.mode
4538 and prevuioh
= state.uioh in
4539 fillsrc prevmode prevuioh
;
4540 let source = (src :> lvsource
) in
4541 let modehash = findkeyhash conf "info" in
4542 state.uioh <- coe (object (self)
4543 inherit listview ~
source ~trusted
:true ~
modehash as super
4544 val mutable m_prevmemused
= 0
4545 method infochanged
= function
4547 if m_prevmemused
!= state.memused
4549 m_prevmemused
<- state.memused
;
4550 G.postRedisplay "memusedchanged";
4552 | Pdim
-> G.postRedisplay "pdimchanged"
4553 | Docinfo
-> fillsrc prevmode prevuioh
4555 method key key mask
=
4556 if not
(Wsi.withctrl mask
)
4559 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4560 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4561 | _ -> super#
key key mask
4562 else super#
key key mask
4564 G.postRedisplay "info";
4570 inherit lvsourcebase
4571 method getitemcount
= Array.length
state.help
4573 let s, l, _ = state.help
.(n) in
4576 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4580 m_qsearch
<- qsearch;
4581 match state.help
.(active) with
4582 | _, _, Action
f -> Some
(f uioh)
4592 method hasaction
n =
4593 match state.help
.(n) with
4594 | _, _, Action
_ -> true
4601 let modehash = findkeyhash conf "help" in
4602 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4603 G.postRedisplay "help";
4608 let re = Str.regexp
"[\r\n]" in
4610 inherit lvsourcebase
4611 val mutable m_items
= [||]
4613 method getitemcount
= 1 + Array.length m_items
4618 else m_items
.(n-1), 0
4620 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4625 then Buffer.clear
state.errmsgs
;
4626 m_qsearch
<- qsearch;
4633 method hasaction
n =
4637 state.newerrmsgs
<- false;
4638 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4639 m_items
<- Array.of_list
l
4647 let source = (msgsource :> lvsource
) in
4648 let modehash = findkeyhash conf "listview" in
4649 state.uioh <- coe (object
4650 inherit listview ~
source ~trusted
:false ~
modehash as super
4653 then msgsource#reset
;
4656 G.postRedisplay "msgs";
4659 let quickbookmark ?title
() =
4660 match state.layout with
4666 let sec = Unix.gettimeofday
() in
4667 let tm = Unix.localtime
sec in
4668 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4672 (tm.Unix.tm_year
+ 1900)
4675 | Some
title -> title
4677 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4681 state.fullscreen
<- None
;
4685 let setautoscrollspeed step goingdown
=
4686 let incr = max
1 ((abs step
) / 2) in
4687 let incr = if goingdown
then incr else -incr in
4688 let astep = step
+ incr in
4689 state.autoscroll
<- Some
astep;
4692 let gotounder = function
4693 | Ulinkgoto
(pageno, top) ->
4697 gotopage1 pageno top;
4703 | Uremote
(filename
, pageno) ->
4705 if Sys.file_exists filename
4708 let dir = Filename.dirname
state.path in
4709 let path = Filename.concat
dir filename
in
4710 if Sys.file_exists
path
4714 if String.length
path > 0
4716 let anchor = getanchor () in
4717 let ranchor = state.path, state.password
, anchor in
4718 state.anchor <- (pageno, 0.0, 0.0);
4719 state.ranchors
<- ranchor :: state.ranchors
;
4722 else showtext '
!'
("Could not find " ^ filename
)
4724 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4728 match conf.columns
with
4730 | _ -> conf.zoom > 1.0
4733 let viewkeyboard key mask
=
4735 let mode = state.mode in
4736 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4739 G.postRedisplay "view:enttext"
4741 let ctrl = Wsi.withctrl mask
in
4742 let existsinrow pageno (columns
, coverA
, coverB
) p =
4743 let last = ((pageno - coverA
) mod columns
) + columns
in
4744 let rec any = function
4747 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4751 then (if l.pageno = last then false else any rest
)
4758 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4764 | 0xff63 -> (* insert *)
4765 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4767 state.mode <- LinkNav
(Ltgendir
0);
4770 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4772 | 0xff1b | 113 -> (* escape / q *)
4773 begin match state.mstate
with
4775 state.mstate
<- Mnone
;
4776 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4777 G.postRedisplay "kill zoom rect";
4779 begin match state.mode with
4782 G.postRedisplay "esc leave linknav"
4784 match state.ranchors
with
4786 | (path, password
, anchor) :: rest
->
4787 state.ranchors
<- rest
;
4788 state.anchor <- anchor;
4789 opendoc path password
4793 | 0xff08 -> (* backspace *)
4794 gotoghyll (getnav ~
-1)
4802 G.postRedisplay "dehighlight";
4804 | 47 | 63 -> (* / ? *)
4805 let ondone isforw
s =
4806 cbput state.hists
.pat
s;
4807 state.searchpattern
<- s;
4810 let s = String.create
1 in
4811 s.[0] <- Char.chr
key;
4812 enttext (s, "", Some
(onhist state.hists
.pat
),
4813 textentry, ondone (key = 47), true)
4815 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4816 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4817 setzoom (conf.zoom +. incr)
4819 | 43 | 0xffab -> (* + *)
4822 try int_of_string
s with exc
->
4823 state.text <- Printf.sprintf
"bad integer `%s': %s"
4824 s (Printexc.to_string exc
);
4830 state.text <- "page bias is now " ^ string_of_int
n;
4833 enttext ("page bias: ", "", None
, intentry, ondone, true)
4835 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4836 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4837 setzoom (max
0.01 (conf.zoom -. decr))
4839 | 45 | 0xffad -> (* - *)
4840 let ondone msg
= state.text <- msg
in
4842 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4843 optentry state.mode, ondone, true
4846 | 48 when ctrl -> (* ctrl-0 *)
4849 | 49 when ctrl -> (* ctrl-1 *)
4851 match conf.columns
with
4852 | Csingle
_ | Cmulti
_ -> 1
4853 | Csplit
(n, _) -> n
4855 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4859 | 0xffc6 -> (* f9 *)
4862 | 57 when ctrl -> (* ctrl-9 *)
4865 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4866 when not
ctrl -> (* 0..9 *)
4869 try int_of_string
s with exc
->
4870 state.text <- Printf.sprintf
"bad integer `%s': %s"
4871 s (Printexc.to_string exc
);
4877 cbput state.hists
.pag
(string_of_int
n);
4878 gotopage1 (n + conf.pagebias
- 1) 0;
4881 let pageentry text key =
4882 match Char.unsafe_chr
key with
4883 | 'g'
-> TEdone
text
4884 | _ -> intentry text key
4886 let text = "x" in text.[0] <- Char.chr
key;
4887 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4890 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4891 reshape conf.winw
conf.winh
;
4894 conf.hlinks
<- not
conf.hlinks
;
4895 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4896 G.postRedisplay "toggle highlightlinks";
4899 state.glinks
<- true;
4900 let mode = state.mode in
4901 state.mode <- Textentry
(
4902 (":", "", None
, linknentry, linkndone gotounder, false),
4904 state.glinks
<- false;
4908 G.postRedisplay "view:linkent(F)"
4911 state.glinks
<- true;
4912 let mode = state.mode in
4913 state.mode <- Textentry
(
4914 (":", "", None
, linknentry, linkndone (fun under ->
4915 match Ne.pipe () with
4917 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4918 (Printexc.to_string exn
));
4921 try popen conf.selcmd
[r, 0; w, -1]; true
4924 (Printf.sprintf
"failed to execute %s: %s"
4925 conf.selcmd
(Printexc.to_string exn
));
4929 Ne.clo fd
(fun msg
->
4930 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4933 let s = undertext under in
4937 let l = String.length
s in
4938 let n = Unix.write
w s 0 l in
4943 "failed to write %d characters to sel pipe, wrote %d"
4948 (Printf.sprintf
"failed to write to sel pipe: %s"
4949 (Printexc.to_string exn
)
4958 state.glinks
<- false;
4962 G.postRedisplay "view:linkent"
4965 begin match state.autoscroll
with
4967 conf.autoscrollstep
<- step
;
4968 state.autoscroll
<- None
4970 if conf.autoscrollstep
= 0
4971 then state.autoscroll
<- Some
1
4972 else state.autoscroll
<- Some
conf.autoscrollstep
4975 | 112 when ctrl -> (* ctrl-p *)
4979 setpresentationmode (not
conf.presentation
);
4980 showtext ' '
("presentation mode " ^
4981 if conf.presentation
then "on" else "off");
4984 begin match state.fullscreen
with
4986 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4989 state.fullscreen
<- None
;
4993 | 112 | 78 -> (* p|N *)
4994 search state.searchpattern
false
4996 | 110 | 0xffc0 -> (* n|F3 *)
4997 search state.searchpattern
true
5000 begin match state.layout with
5003 gotoy_and_clear_text (getpagey l.pageno)
5007 begin match state.layout with
5010 match conf.columns
with
5012 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5014 let y = clamp (pgscale conf.winh
) in
5017 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5018 gotoghyll (getpagey pageno)
5019 | Cmulti
((c, _, _) as cl
, _) ->
5020 if conf.presentation
5021 && (existsinrow l.pageno cl
5022 (fun l -> l.pageh
> l.pagey + l.pagevh))
5024 let y = clamp (pgscale conf.winh
) in
5027 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5028 gotoghyll (getpagey pageno)
5030 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5032 let pagey, pageh
= getpageyh l.pageno in
5033 let pagey = pagey + pageh
* l.pagecol
in
5034 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5035 gotoghyll (pagey + pageh
+ ips)
5038 | 0xff9f | 0xffff -> (* delete *)
5039 begin match state.layout with
5042 match conf.columns
with
5044 if conf.presentation
&& l.pagey != 0
5046 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
5048 let pageno = max
0 (l.pageno-1) in
5049 gotoghyll (getpagey pageno)
5050 | Cmulti
((c, _, coverB
) as cl
, _) ->
5051 if conf.presentation
&&
5052 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
5054 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
5057 if l.pageno = state.pagecount
- coverB
5061 let pageno = max
0 (l.pageno-decr) in
5062 gotoghyll (getpagey pageno)
5070 let pageno = max
0 (l.pageno-1) in
5071 let pagey, pageh
= getpageyh pageno in
5074 let pagey, pageh
= getpageyh l.pageno in
5075 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5081 showtext ' '
(describe_location ());
5084 begin match state.layout with
5087 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5092 enterbookmarkmode ()
5094 | 104 | 0xffbe -> (* h|F1 *)
5100 | 101 when conf.redirectstderr -> (* e *)
5105 match state.layout with
5107 if String.length
s > 0
5109 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5112 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5116 showtext ' '
"Quick bookmark added";
5119 begin match state.layout with
5121 let rect = getpdimrect
l.pagedimno
in
5125 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5126 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5128 (truncate
(rect.(1) -. rect.(0)),
5129 truncate
(rect.(3) -. rect.(0)))
5131 let w = truncate
((float w)*.conf.zoom)
5132 and h = truncate
((float h)*.conf.zoom) in
5135 state.anchor <- getanchor ();
5136 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5138 G.postRedisplay "z";
5143 | 50 when ctrl -> (* ctrl-2 *)
5144 let maxw = getmaxw
() in
5146 then setzoom (maxw /. float conf.winw
)
5148 | 60 | 62 -> (* < > *)
5149 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5151 | 91 | 93 -> (* [ ] *)
5153 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5155 G.postRedisplay "brightness";
5157 | 99 when state.mode = View
-> (* c *)
5159 match state.prevcolumns
with
5160 | None
-> (1, 0, 0), 1.0
5161 | Some
(columns
, z
) ->
5164 | Csplit
(c, _) -> -c, 0, 0
5165 | Cmulti
((c, a, b), _) -> c, a, b
5166 | Csingle
_ -> 1, 0, 0
5170 setcolumns View
c a b;
5173 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5174 setzoom state.prevzoom
5176 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5177 begin match state.autoscroll
with
5179 begin match state.mode with
5180 | Birdseye beye
-> upbirdseye 1 beye
5183 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5184 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5187 setautoscrollspeed n false
5190 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5191 begin match state.autoscroll
with
5193 begin match state.mode with
5194 | Birdseye beye
-> downbirdseye 1 beye
5197 then gotoy_and_clear_text (clamp (conf.winh
/2))
5198 else gotoy_and_clear_text (clamp conf.scrollstep
)
5201 setautoscrollspeed n true
5204 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5210 else conf.hscrollstep
5212 let dx = if key = 0xff51 then dx else -dx in
5213 state.x <- state.x + dx;
5214 gotoy_and_clear_text state.y
5217 G.postRedisplay "lef/right"
5220 | 0xff55 | 0xff9a -> (* (kp) prior *)
5224 match state.layout with
5226 | l :: _ -> state.y - l.pagey
5228 clamp (pgscale (-conf.winh
))
5232 | 0xff56 | 0xff9b -> (* (kp) next *)
5236 match List.rev
state.layout with
5238 | l :: _ -> getpagey l.pageno
5240 clamp (pgscale conf.winh
)
5244 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5246 | 71 | 0xff57 | 0xff9c -> (* G end *)
5247 gotoghyll (clamp state.maxy)
5249 | 0xff53 when Wsi.withalt mask
-> (* alt-right *)
5250 gotoghyll (getnav 1)
5251 | 0xff51 when Wsi.withalt mask
-> (* alt-left *)
5252 gotoghyll (getnav ~
-1)
5257 | 118 when conf.debug
-> (* v *)
5260 match getopaque l.pageno with
5263 let x0, y0, x1, y1 = pagebbox opaque
in
5264 let a,b = float x0, float y0 in
5265 let c,d = float x1, float y0 in
5266 let e,f = float x1, float y1 in
5267 let h,j
= float x0, float y1 in
5268 let rect = (a,b,c,d,e,f,h,j
) in
5270 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5272 G.postRedisplay "v";
5275 vlog "huh? %s" (Wsi.keyname
key)
5278 let linknavkeyboard key mask
linknav =
5279 let getpage pageno =
5280 let rec loop = function
5282 | l :: _ when l.pageno = pageno -> Some
l
5283 | _ :: rest
-> loop rest
5284 in loop state.layout
5286 let doexact (pageno, n) =
5287 match getopaque pageno, getpage pageno with
5288 | Some opaque
, Some
l ->
5289 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5291 let under = getlink opaque
n in
5292 G.postRedisplay "link gotounder";
5298 | 0xff50 -> (* home *)
5299 Some
(findlink opaque LDfirst
), -1
5301 | 0xff57 -> (* end *)
5302 Some
(findlink opaque LDlast
), 1
5304 | 0xff51 -> (* left *)
5305 Some
(findlink opaque
(LDleft
n)), -1
5307 | 0xff53 -> (* right *)
5308 Some
(findlink opaque
(LDright
n)), 1
5310 | 0xff52 -> (* up *)
5311 Some
(findlink opaque
(LDup
n)), -1
5313 | 0xff54 -> (* down *)
5314 Some
(findlink opaque
(LDdown
n)), 1
5319 begin match findpwl
l.pageno dir with
5323 state.mode <- LinkNav
(Ltgendir
dir);
5324 let y, h = getpageyh pageno in
5327 then y + h - conf.winh
5332 begin match getopaque pageno, getpage pageno with
5333 | Some opaque
, Some
_ ->
5335 let ld = if dir > 0 then LDfirst
else LDlast
in
5338 begin match link with
5340 showlinktype (getlink opaque
m);
5341 state.mode <- LinkNav
(Ltexact
(pageno, m));
5342 G.postRedisplay "linknav jpage";
5349 begin match opt with
5350 | Some Lnotfound
-> pwl l dir;
5351 | Some
(Lfound
m) ->
5355 let _, y0, _, y1 = getlinkrect opaque
m in
5357 then gotopage1 l.pageno y0
5359 let d = fstate.fontsize
+ 1 in
5360 if y1 - l.pagey > l.pagevh - d
5361 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5362 else G.postRedisplay "linknav";
5364 showlinktype (getlink opaque
m);
5365 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5368 | None
-> viewkeyboard key mask
5370 | _ -> viewkeyboard key mask
5375 G.postRedisplay "leave linknav"
5379 | Ltgendir
_ -> viewkeyboard key mask
5380 | Ltexact exact
-> doexact exact
5383 let keyboard key mask
=
5384 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5385 then wcmd "interrupt"
5386 else state.uioh <- state.uioh#
key key mask
5389 let birdseyekeyboard key mask
5390 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5392 match conf.columns
with
5394 | Cmulti
((c, _, _), _) -> c
5395 | Csplit
_ -> failwith
"bird's eye split mode"
5397 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5399 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5400 let y, h = getpageyh pageno in
5401 let top = (conf.winh
- h) / 2 in
5402 gotoy (max
0 (y - top))
5403 | 0xff0d (* enter *)
5404 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5405 | 0xff1b -> leavebirdseye beye
true (* escape *)
5406 | 0xff52 -> upbirdseye incr beye
(* up *)
5407 | 0xff54 -> downbirdseye incr beye
(* down *)
5408 | 0xff51 -> upbirdseye 1 beye
(* left *)
5409 | 0xff53 -> downbirdseye 1 beye
(* right *)
5411 | 0xff55 -> (* prior *)
5412 begin match state.layout with
5416 state.mode <- Birdseye
(
5417 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5419 gotopage1 l.pageno 0;
5422 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5424 | [] -> gotoy (clamp (-conf.winh
))
5426 state.mode <- Birdseye
(
5427 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5429 gotopage1 l.pageno 0
5432 | [] -> gotoy (clamp (-conf.winh
))
5435 | 0xff56 -> (* next *)
5436 begin match List.rev
state.layout with
5438 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5439 begin match layout with
5441 let incr = l.pageh
- l.pagevh in
5446 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5448 G.postRedisplay "birdseye pagedown";
5450 else gotoy (clamp (incr + conf.interpagespace
*2));
5454 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5455 gotopage1 l.pageno 0;
5458 | [] -> gotoy (clamp conf.winh
)
5461 | 0xff50 -> (* home *)
5462 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5465 | 0xff57 -> (* end *)
5466 let pageno = state.pagecount
- 1 in
5467 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5468 if not
(pagevisible state.layout pageno)
5471 match List.rev
state.pdims
with
5473 | (_, _, h, _) :: _ -> h
5475 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5476 else G.postRedisplay "birdseye end";
5477 | _ -> viewkeyboard key mask
5480 let drawpage l linkindexbase
=
5482 match state.mode with
5483 | Textentry
_ -> scalecolor 0.4
5485 | View
-> scalecolor 1.0
5486 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5487 if l.pageno = hooverpageno
5490 if l.pageno = pageno
5496 begin match getopaque l.pageno with
5498 if tileready l l.pagex
l.pagey
5500 let x = l.pagedispx - l.pagex
5501 and y = l.pagedispy - l.pagey in
5503 match conf.columns
with
5504 | Csingle
_ | Cmulti
_ ->
5505 (if conf.hlinks
then 1 else 0)
5507 && not
(isbirdseye state.mode) then 2 else 0)
5511 match state.mode with
5512 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5515 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5522 let scrollindicator () =
5523 let sbw, ph
, sh = state.uioh#
scrollph in
5524 let sbh, pw, sw = state.uioh#scrollpw
in
5526 GlDraw.color (0.64, 0.64, 0.64);
5528 (float (conf.winw
- sbw), 0.)
5529 (float conf.winw
, float conf.winh
)
5532 (0., float (conf.winh
- sbh))
5533 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5535 GlDraw.color (0.0, 0.0, 0.0);
5538 (float (conf.winw
- sbw), ph
)
5539 (float conf.winw
, ph
+. sh)
5542 (pw, float (conf.winh
- sbh))
5543 (pw +. sw, float conf.winh
)
5548 match state.mstate
with
5549 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5552 | Msel
((x0, y0), (x1, y1)) ->
5553 let rec loop = function
5555 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5556 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5557 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5558 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5560 match getopaque l.pageno with
5562 let x0, y0 = pagetranslatepoint l x0 y0 in
5563 let x1, y1 = pagetranslatepoint l x1 y1 in
5564 seltext opaque
(x0, y0, x1, y1);
5572 let showrects rects
=
5574 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5575 GlDraw.polygon_mode `both `fill
;
5576 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5578 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5580 if l.pageno = pageno
5582 let dx = float (l.pagedispx - l.pagex
) in
5583 let dy = float (l.pagedispy - l.pagey) in
5584 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5585 GlDraw.begins `quads
;
5587 GlDraw.vertex2
(x0+.dx, y0+.dy);
5588 GlDraw.vertex2
(x1+.dx, y1+.dy);
5589 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5590 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5601 GlClear.color (scalecolor2 conf.bgcolor
);
5602 GlClear.clear
[`
color];
5603 let rec loop linkindexbase
= function
5605 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5606 loop linkindexbase rest
5609 loop 0 state.layout;
5611 match state.mode with
5612 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5613 begin match getopaque pageno with
5615 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5622 | None
-> state.rects
5629 begin match state.mstate
with
5630 | Mzoomrect
((x0, y0), (x1, y1)) ->
5632 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5633 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5634 GlDraw.rect (float x0, float y0)
5635 (float x1, float y1);
5641 if not
state.wthack
then Wsi.swapb
();
5644 let zoomrect x y x1 y1 =
5647 and y0 = min
y y1 in
5648 gotoy (state.y + y0);
5649 state.anchor <- getanchor ();
5650 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5652 if state.w < conf.winw
- state.scrollw
5653 then (conf.winw
- state.scrollw
- state.w) / 2
5656 state.x <- (state.x + margin) - x0;
5658 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5659 state.mstate
<- Mnone
;
5663 let winw = conf.winw - state.scrollw
- 1 in
5664 let s = float x /. float winw in
5665 let destx = truncate
(float (state.w + winw) *. s) in
5666 state.x <- winw - destx;
5667 gotoy_and_clear_text state.y;
5668 state.mstate
<- Mscrollx
;
5672 let s = float y /. float conf.winh
in
5673 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5674 gotoy_and_clear_text desty;
5675 state.mstate
<- Mscrolly
;
5678 let viewmouse button down
x y mask
=
5680 | n when (n == 4 || n == 5) && not down
->
5681 if Wsi.withctrl mask
5683 match state.mstate
with
5684 | Mzoom
(oldn
, i
) ->
5692 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5694 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5696 let zoom = conf.zoom -. incr in
5698 state.mstate
<- Mzoom
(n, 0);
5700 state.mstate
<- Mzoom
(n, i
+1);
5702 else state.mstate
<- Mzoom
(n, 0)
5704 | _ -> state.mstate
<- Mzoom
(n, 0)
5707 match state.autoscroll
with
5708 | Some step
-> setautoscrollspeed step
(n=4)
5712 then -conf.scrollstep
5713 else conf.scrollstep
5715 let incr = incr * 2 in
5716 let y = clamp incr in
5717 gotoy_and_clear_text y
5720 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5721 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5722 gotoy_and_clear_text state.y
5724 | 1 when Wsi.withctrl mask
->
5727 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5728 state.mstate
<- Mpan
(x, y)
5731 state.mstate
<- Mnone
5736 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5738 state.mstate
<- Mzoomrect
(p, p)
5741 match state.mstate
with
5742 | Mzoomrect
((x0, y0), _) ->
5743 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5744 then zoomrect x0 y0 x y
5746 state.mstate
<- Mnone
;
5747 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5748 G.postRedisplay "kill accidental zoom rect";
5751 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5752 state.mstate
<- Mnone
5755 | 1 when x > conf.winw - state.scrollw
->
5758 let _, position, sh = state.uioh#
scrollph in
5759 if y > truncate
position && y < truncate
(position +. sh)
5760 then state.mstate
<- Mscrolly
5763 state.mstate
<- Mnone
5765 | 1 when y > conf.winh
- state.hscrollh ->
5768 let _, position, sw = state.uioh#scrollpw
in
5769 if x > truncate
position && x < truncate
(position +. sw)
5770 then state.mstate
<- Mscrollx
5773 state.mstate
<- Mnone
5776 let dest = if down
then getunder x y else Unone
in
5777 begin match dest with
5781 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5784 | Unone
when down
->
5785 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5786 state.mstate
<- Mpan
(x, y);
5788 | Unone
| Utext
_ ->
5791 if conf.angle
mod 360 = 0
5793 state.mstate
<- Msel
((x, y), (x, y));
5794 G.postRedisplay "mouse select";
5798 match state.mstate
with
5801 | Mzoom
_ | Mscrollx
| Mscrolly
->
5802 state.mstate
<- Mnone
5804 | Mzoomrect
((x0, y0), _) ->
5808 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5809 state.mstate
<- Mnone
5811 | Msel
((x0, y0), (x1, y1)) ->
5812 let rec loop = function
5816 let a0 = l.pagedispy in
5817 let a1 = a0 + l.pagevh in
5818 let b0 = l.pagedispx in
5819 let b1 = b0 + l.pagevw in
5820 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5821 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5825 match getopaque l.pageno with
5828 match Ne.pipe () with
5832 "can not create sel pipe: %s"
5833 (Printexc.to_string exn
));
5835 let doclose what fd
=
5836 Ne.clo fd
(fun msg
->
5837 dolog "%s close failed: %s" what msg
)
5840 popen conf.selcmd
[r, 0; w, -1];
5843 G.postRedisplay "copysel";
5845 dolog "can not execute %S: %s"
5846 conf.selcmd
(Printexc.to_string exn
);
5854 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5855 state.mstate
<- Mnone
;
5862 let birdseyemouse button down
x y mask
5863 (conf, leftx
, _, hooverpageno
, anchor) =
5866 let rec loop = function
5869 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5870 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5872 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5878 | _ -> viewmouse button down
x y mask
5881 let mouse button down
x y mask
=
5882 state.uioh <- state.uioh#button button down
x y mask
;
5886 state.uioh <- state.uioh#
motion x y
5890 state.uioh <- state.uioh#
pmotion x y;
5896 method key key mask
=
5897 begin match state.mode with
5898 | Textentry
textentry -> textentrykeyboard key mask
textentry
5899 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5900 | View
-> viewkeyboard key mask
5901 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5905 method button button bstate
x y mask
=
5906 begin match state.mode with
5908 | View
-> viewmouse button bstate
x y mask
5909 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5915 begin match state.mode with
5917 | View
| Birdseye
_ | LinkNav
_ ->
5918 match state.mstate
with
5919 | Mzoom
_ | Mnone
-> ()
5924 state.mstate
<- Mpan
(x, y);
5926 then state.x <- state.x + dx;
5928 gotoy_and_clear_text y
5931 state.mstate
<- Msel
(a, (x, y));
5932 G.postRedisplay "motion select";
5935 let y = min
conf.winh
(max
0 y) in
5939 let x = min
conf.winw (max
0 x) in
5942 | Mzoomrect
(p0
, _) ->
5943 state.mstate
<- Mzoomrect
(p0
, (x, y));
5944 G.postRedisplay "motion zoomrect";
5948 method pmotion x y =
5949 begin match state.mode with
5950 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5951 let rec loop = function
5953 if hooverpageno
!= -1
5955 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5956 G.postRedisplay "pmotion birdseye no hoover";
5959 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5960 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5962 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5963 G.postRedisplay "pmotion birdseye hoover";
5973 match state.mstate
with
5974 | Mnone
-> updateunder x y
5975 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5980 method infochanged
_ = ()
5983 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5984 let p, h = scrollph state.y maxy in
5988 let winw = conf.winw - state.scrollw
- 1 in
5989 let fwinw = float winw in
5991 let sw = fwinw /. float state.w in
5992 let sw = fwinw *. sw in
5993 max
sw (float conf.scrollh
)
5996 let f = state.w+winw in
5997 let r = float (winw-state.x) /. float f in
5998 let p = fwinw *. r in
6002 if position +. sw > fwinw
6003 then fwinw -. position
6006 state.hscrollh, position, sw
6010 match state.mode with
6011 | LinkNav
_ -> "links"
6012 | Textentry
_ -> "textentry"
6013 | Birdseye
_ -> "birdseye"
6016 findkeyhash conf modename
6023 let fontpath = ref "";;
6026 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6029 let l = String.length
s in
6030 let b = Buffer.create
l in
6036 try Sys.getenv
"HOME"
6039 ("Can not determine home directory location: " ^
6040 Printexc.to_string exn
);
6044 let modifier_of_string = function
6045 | "alt" -> Wsi.altmask
6046 | "shift" -> Wsi.shiftmask
6047 | "ctrl" | "control" -> Wsi.ctrlmask
6048 | "meta" -> Wsi.metamask
6053 let r = Str.regexp
"-" in
6055 let elems = Str.full_split
r s in
6058 let m1 = modifier_of_string s in
6060 then (Wsi.namekey
s, m)
6063 | Str.Delim
s when n land 1 = 0 -> g s
6065 | Str.Delim
_ -> (k
, m)
6067 let rec loop n k
m = function
6070 let k, m = f n k m x in
6076 let keys_of_string =
6077 let r = Str.regexp
"[ \t]" in
6079 let elems = Str.split
r s in
6080 List.map
key_of_string elems
6083 let copykeyhashes c =
6084 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6087 let config_of c attrs
=
6091 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6092 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6093 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6094 | "preload" -> { c with preload = bool_of_string
v }
6095 | "page-bias" -> { c with pagebias
= int_of_string
v }
6096 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6097 | "horizontal-scroll-step" ->
6098 { c with hscrollstep
= max
(int_of_string
v) 1 }
6099 | "auto-scroll-step" ->
6100 { c with autoscrollstep
= max
0 (int_of_string
v) }
6101 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6102 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6105 match String.lowercase
v with
6106 | "true" -> Some infinity
6108 | f -> Some
(float_of_string
f)
6110 { c with maxwait
= mw}
6111 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6112 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6113 | "vertical-margin" ->
6114 { c with interpagespace
= max
0 (int_of_string
v) }
6116 let zoom = float_of_string
v /. 100. in
6117 let zoom = max
zoom 0.0 in
6118 { c with zoom = zoom }
6119 | "presentation" -> { c with presentation
= bool_of_string
v }
6120 | "rotation-angle" -> { c with angle
= int_of_string
v }
6121 | "width" -> { c with winw = max
20 (int_of_string
v) }
6122 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6123 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6124 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6125 | "pixmap-cache-size" ->
6126 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6127 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6128 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6129 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6130 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6131 | "background-color" -> { c with bgcolor
= color_of_string v }
6132 | "scrollbar-in-presentation" ->
6133 { c with scrollbarinpm
= bool_of_string
v }
6134 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6135 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6136 | "mupdf-store-size" ->
6137 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6138 | "checkers" -> { c with checkers
= bool_of_string
v }
6139 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6140 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6141 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6142 | "uri-launcher" -> { c with urilauncher
= unent v }
6143 | "path-launcher" -> { c with pathlauncher
= unent v }
6144 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6145 | "invert-colors" -> { c with invert
= bool_of_string
v }
6146 | "brightness" -> { c with colorscale
= float_of_string
v }
6147 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6149 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6151 let (n, _, _) as nab
= multicolumns_of_string v in
6153 then { c with columns
= Csplit
(-n, [||]) }
6154 else { c with columns
= Cmulti
(nab
, [||]) }
6155 | "birds-eye-columns" ->
6156 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6157 | "selection-command" -> { c with selcmd
= unent v }
6158 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6159 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6160 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6161 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6164 prerr_endline
("Error processing attribute (`" ^
6165 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6168 let rec fold c = function
6171 let c = apply c k v in
6174 fold { c with keyhashes
= copykeyhashes c } attrs
;
6177 let fromstring f pos
n v d =
6180 dolog "Error processing attribute (%S=%S) at %d\n%s"
6181 n v pos
(Printexc.to_string exn
)
6186 let bookmark_of attrs
=
6187 let rec fold title page
rely visy
= function
6188 | ("title", v) :: rest
-> fold v page
rely visy rest
6189 | ("page", v) :: rest
-> fold title v rely visy rest
6190 | ("rely", v) :: rest
-> fold title page
v visy rest
6191 | ("visy", v) :: rest
-> fold title page
rely v rest
6192 | _ :: rest
-> fold title page
rely visy rest
6193 | [] -> title, page
, rely, visy
6195 fold "invalid" "0" "0" "0" attrs
6199 let rec fold path page
rely pan visy
= function
6200 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6201 | ("page", v) :: rest
-> fold path v rely pan visy rest
6202 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6203 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6204 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6205 | _ :: rest
-> fold path page
rely pan visy rest
6206 | [] -> path, page
, rely, pan
, visy
6208 fold "" "0" "0" "0" "0" attrs
6212 let rec fold rs ls
= function
6213 | ("out", v) :: rest
-> fold v ls rest
6214 | ("in", v) :: rest
-> fold rs
v rest
6215 | _ :: rest
-> fold ls rs rest
6221 let setconf dst
src =
6222 dst
.scrollbw
<- src.scrollbw
;
6223 dst
.scrollh
<- src.scrollh
;
6224 dst
.icase
<- src.icase
;
6225 dst
.preload <- src.preload;
6226 dst
.pagebias
<- src.pagebias
;
6227 dst
.verbose
<- src.verbose
;
6228 dst
.scrollstep
<- src.scrollstep
;
6229 dst
.maxhfit
<- src.maxhfit
;
6230 dst
.crophack
<- src.crophack
;
6231 dst
.autoscrollstep
<- src.autoscrollstep
;
6232 dst
.maxwait
<- src.maxwait
;
6233 dst
.hlinks
<- src.hlinks
;
6234 dst
.underinfo
<- src.underinfo
;
6235 dst
.interpagespace
<- src.interpagespace
;
6236 dst
.zoom <- src.zoom;
6237 dst
.presentation
<- src.presentation
;
6238 dst
.angle
<- src.angle
;
6239 dst
.winw <- src.winw;
6240 dst
.winh
<- src.winh
;
6241 dst
.savebmarks
<- src.savebmarks
;
6242 dst
.memlimit
<- src.memlimit
;
6243 dst
.proportional
<- src.proportional
;
6244 dst
.texcount
<- src.texcount
;
6245 dst
.sliceheight
<- src.sliceheight
;
6246 dst
.thumbw
<- src.thumbw
;
6247 dst
.jumpback
<- src.jumpback
;
6248 dst
.bgcolor
<- src.bgcolor
;
6249 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6250 dst
.tilew
<- src.tilew
;
6251 dst
.tileh
<- src.tileh
;
6252 dst
.mustoresize
<- src.mustoresize
;
6253 dst
.checkers
<- src.checkers
;
6254 dst
.aalevel
<- src.aalevel
;
6255 dst
.trimmargins
<- src.trimmargins
;
6256 dst
.trimfuzz
<- src.trimfuzz
;
6257 dst
.urilauncher
<- src.urilauncher
;
6258 dst
.colorspace
<- src.colorspace
;
6259 dst
.invert
<- src.invert
;
6260 dst
.colorscale
<- src.colorscale
;
6261 dst
.redirectstderr <- src.redirectstderr;
6262 dst
.ghyllscroll
<- src.ghyllscroll
;
6263 dst
.columns
<- src.columns
;
6264 dst
.beyecolumns
<- src.beyecolumns
;
6265 dst
.selcmd
<- src.selcmd
;
6266 dst
.updatecurs
<- src.updatecurs
;
6267 dst
.pathlauncher
<- src.pathlauncher
;
6268 dst
.keyhashes
<- copykeyhashes src;
6269 dst
.hfsize
<- src.hfsize
;
6270 dst
.hscrollstep
<- src.hscrollstep
;
6271 dst
.pgscale <- src.pgscale;
6272 dst
.usepbo
<- src.usepbo
;
6276 let h = Hashtbl.create
10 in
6277 let dc = { defconf with angle
= defconf.angle
} in
6278 let rec toplevel v t spos
_ =
6280 | Vdata
| Vcdata
| Vend
-> v
6281 | Vopen
("llppconfig", _, closed
) ->
6284 else { v with f = llppconfig
}
6286 error
"unexpected subelement at top level" s spos
6287 | Vclose
_ -> error
"unexpected close at top level" s spos
6289 and llppconfig
v t spos
_ =
6291 | Vdata
| Vcdata
-> v
6292 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6293 | Vopen
("defaults", attrs
, closed
) ->
6294 let c = config_of dc attrs
in
6298 else { v with f = defaults
}
6300 | Vopen
("ui-font", attrs
, closed
) ->
6301 let rec getsize size
= function
6303 | ("size", v) :: rest
->
6305 fromstring int_of_string spos
"size" v fstate.fontsize
in
6307 | l -> getsize size l
6309 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6312 else { v with f = uifont
(Buffer.create
10) }
6314 | Vopen
("doc", attrs
, closed
) ->
6315 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6316 let path = unent pathent
6317 and pageno = fromstring int_of_string spos
"page" spage
0
6318 and rely = fromstring float_of_string spos
"rely" srely
0.0
6319 and pan
= fromstring int_of_string spos
"pan" span
0
6320 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6321 let c = config_of dc attrs
in
6322 let anchor = (pageno, rely, visy
) in
6324 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6325 else { v with f = doc
path pan
anchor c [] }
6328 error
"unexpected subelement in llppconfig" s spos
6330 | Vclose
"llppconfig" -> { v with f = toplevel }
6331 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6333 and defaults
v t spos
_ =
6335 | Vdata
| Vcdata
-> v
6336 | Vend
-> error
"unexpected end of input in defaults" s spos
6337 | Vopen
("keymap", attrs
, closed
) ->
6339 try List.assoc
"mode" attrs
6340 with Not_found
-> "global" in
6345 let h = findkeyhash dc modename in
6346 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6349 { v with f = pkeymap
ret KeyMap.empty }
6351 | Vopen
(_, _, _) ->
6352 error
"unexpected subelement in defaults" s spos
6354 | Vclose
"defaults" ->
6355 { v with f = llppconfig
}
6357 | Vclose
_ -> error
"unexpected close in defaults" s spos
6359 and uifont
b v t spos
epos =
6362 Buffer.add_substring
b s spos
(epos - spos
);
6364 | Vopen
(_, _, _) ->
6365 error
"unexpected subelement in ui-font" s spos
6366 | Vclose
"ui-font" ->
6367 if String.length
!fontpath = 0
6368 then fontpath := Buffer.contents
b;
6369 { v with f = llppconfig
}
6370 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6371 | Vend
-> error
"unexpected end of input in ui-font" s spos
6373 and doc
path pan
anchor c bookmarks
v t spos
_ =
6375 | Vdata
| Vcdata
-> v
6376 | Vend
-> error
"unexpected end of input in doc" s spos
6377 | Vopen
("bookmarks", _, closed
) ->
6380 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6382 | Vopen
("keymap", attrs
, closed
) ->
6384 try List.assoc
"mode" attrs
6385 with Not_found
-> "global"
6391 let h = findkeyhash c modename in
6392 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6393 doc
path pan
anchor c bookmarks
6395 { v with f = pkeymap
ret KeyMap.empty }
6397 | Vopen
(_, _, _) ->
6398 error
"unexpected subelement in doc" s spos
6401 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6402 { v with f = llppconfig
}
6404 | Vclose
_ -> error
"unexpected close in doc" s spos
6406 and pkeymap
ret keymap
v t spos
_ =
6408 | Vdata
| Vcdata
-> v
6409 | Vend
-> error
"unexpected end of input in keymap" s spos
6410 | Vopen
("map", attrs
, closed
) ->
6411 let r, l = map_of attrs
in
6412 let kss = fromstring keys_of_string spos
"in" r [] in
6413 let lss = fromstring keys_of_string spos
"out" l [] in
6417 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6418 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6421 then { v with f = pkeymap
ret keymap }
6424 { v with f = skip
"map" f }
6427 error
"unexpected subelement in keymap" s spos
6429 | Vclose
"keymap" ->
6430 { v with f = ret keymap }
6432 | Vclose
_ -> error
"unexpected close in keymap" s spos
6434 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6436 | Vdata
| Vcdata
-> v
6437 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6438 | Vopen
("item", attrs
, closed
) ->
6439 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6440 let page = fromstring int_of_string spos
"page" spage
0
6441 and rely = fromstring float_of_string spos
"rely" srely
0.0
6442 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6444 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6447 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6450 { v with f = skip
"item" f }
6453 error
"unexpected subelement in bookmarks" s spos
6455 | Vclose
"bookmarks" ->
6456 { v with f = doc
path pan
anchor c bookmarks }
6458 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6460 and skip tag
f v t spos
_ =
6462 | Vdata
| Vcdata
-> v
6464 error
("unexpected end of input in skipped " ^ tag
) s spos
6465 | Vopen
(tag'
, _, closed
) ->
6469 let f'
() = { v with f = skip tag
f } in
6470 { v with f = skip tag'
f'
}
6474 else error
("unexpected close in skipped " ^ tag
) s spos
6477 parse
{ f = toplevel; accu = () } s;
6483 let len = in_channel_length ic
in
6484 let s = String.create
len in
6485 really_input ic
s 0 len;
6488 | Parse_error
(msg
, s, pos
) ->
6489 let subs = subs s pos
in
6490 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6491 failwith
("parse error: " ^
s)
6494 failwith
("config load error: " ^
Printexc.to_string exn
)
6500 let dir = Filename.concat
home ".config" in
6501 if Sys.is_directory
dir then dir else home
6504 Filename.concat
dir "llpp.conf"
6507 let confpath = ref defconfpath;;
6510 if Sys.file_exists
!confpath
6513 (try Some
(open_in_bin
!confpath)
6516 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6517 Printexc.to_string exn
);
6527 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6528 Printexc.to_string exn
);
6536 f (Hashtbl.create
0, defconf)
6541 let pc, pb
, px, pa
=
6543 Hashtbl.find h (Filename.basename
state.path)
6544 with Not_found
-> dc, [], 0, emptyanchor
6548 state.bookmarks <- pb
;
6550 state.scrollw
<- conf.scrollbw
;
6552 then state.anchor <- pa
;
6553 cbput state.hists
.nav pa
;
6559 let add_attrs bb always
dc c =
6562 then Printf.bprintf bb
"\n %s='%b'" s a
6565 then Printf.bprintf bb
"\n %s='%d'" s a
6568 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6571 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6574 then Printf.bprintf bb
"\n %s='%f'" s a
6578 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6582 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6586 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6590 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6596 | Some
(_N
, _A
, _B
) ->
6597 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6607 else string_of_float
f
6609 Printf.bprintf bb
"\n %s='%s'" s v
6614 | Cmulti
((n, a, b), _) when n > 1 ->
6615 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6616 | Csplit
(n, _) when n > 1 ->
6617 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6623 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6628 then dc.winw, dc.winh
6630 match state.fullscreen
with
6632 | None
-> c.winw, c.winh
6634 oi
"width" w dc.winw;
6635 oi
"height" h dc.winh
;
6636 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6637 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6638 ob "case-insensitive-search" c.icase
dc.icase
;
6639 ob "preload" c.preload dc.preload;
6640 oi
"page-bias" c.pagebias
dc.pagebias
;
6641 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6642 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6643 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6644 ob "crop-hack" c.crophack
dc.crophack
;
6645 oW
"throttle" c.maxwait
dc.maxwait
;
6646 ob "highlight-links" c.hlinks
dc.hlinks
;
6647 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6648 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6649 oz
"zoom" c.zoom dc.zoom;
6650 ob "presentation" c.presentation
dc.presentation
;
6651 oi
"rotation-angle" c.angle
dc.angle
;
6652 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6653 ob "proportional-display" c.proportional
dc.proportional
;
6654 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6655 oi
"tex-count" c.texcount
dc.texcount
;
6656 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6657 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6658 ob "persistent-location" c.jumpback
dc.jumpback
;
6659 oc
"background-color" c.bgcolor
dc.bgcolor
;
6660 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6661 oi
"tile-width" c.tilew
dc.tilew
;
6662 oi
"tile-height" c.tileh
dc.tileh
;
6663 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6664 ob "checkers" c.checkers
dc.checkers
;
6665 oi
"aalevel" c.aalevel
dc.aalevel
;
6666 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6667 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6668 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6669 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6670 oC
"color-space" c.colorspace
dc.colorspace
;
6671 ob "invert-colors" c.invert
dc.invert
;
6672 oF
"brightness" c.colorscale
dc.colorscale
;
6673 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6674 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6675 oco
"columns" c.columns
dc.columns
;
6676 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6677 os
"selection-command" c.selcmd
dc.selcmd
;
6678 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6679 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6680 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6681 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6682 ob "use-pbo" c.usepbo
dc.usepbo
;
6685 let keymapsbuf always
dc c =
6686 let bb = Buffer.create
16 in
6687 let rec loop = function
6689 | (modename, h) :: rest
->
6690 let dh = findkeyhash dc modename in
6691 if always
|| h <> dh
6693 if Hashtbl.length
h > 0
6695 if Buffer.length
bb > 0
6696 then Buffer.add_char
bb '
\n'
;
6697 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6698 Hashtbl.iter
(fun i
o ->
6699 let isdifferent = always
||
6701 let dO = Hashtbl.find dh i
in
6703 with Not_found
-> true
6708 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6709 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6710 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6711 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6712 Buffer.add_string
bb (Wsi.keyname
k);
6715 let rec loop = function
6717 | km
:: [] -> addkm km
6718 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6722 Buffer.add_string
bb "<map in='";
6726 Buffer.add_string
bb "' out='";
6728 Buffer.add_string
bb "'/>\n"
6731 Buffer.add_string
bb "' out='";
6733 Buffer.add_string
bb "'/>\n"
6735 | KMmulti
(ins, kms
) ->
6736 Buffer.add_char
bb ' '
;
6738 Buffer.add_string
bb "' out='";
6740 Buffer.add_string
bb "'/>\n"
6742 Buffer.add_string
bb "</keymap>";
6752 let uifontsize = fstate.fontsize
in
6753 let bb = Buffer.create
32768 in
6755 let dc = if conf.bedefault
then conf else dc in
6756 Buffer.add_string
bb "<llppconfig>\n";
6758 if String.length
!fontpath > 0
6760 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6766 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6769 Buffer.add_string
bb "<defaults ";
6770 add_attrs bb true dc dc;
6771 let kb = keymapsbuf true dc dc in
6772 if Buffer.length
kb > 0
6774 Buffer.add_string
bb ">\n";
6775 Buffer.add_buffer
bb kb;
6776 Buffer.add_string
bb "\n</defaults>\n";
6778 else Buffer.add_string
bb "/>\n";
6780 let adddoc path pan
anchor c bookmarks =
6781 if bookmarks == [] && c = dc && anchor = emptyanchor
6784 Printf.bprintf
bb "<doc path='%s'"
6785 (enent
path 0 (String.length
path));
6787 if anchor <> emptyanchor
6789 let n, rely, visy
= anchor in
6790 Printf.bprintf
bb " page='%d'" n;
6793 Printf.bprintf
bb " rely='%f'" rely
6795 if abs_float visy
> 1e-6
6797 Printf.bprintf
bb " visy='%f'" visy
6802 then Printf.bprintf
bb " pan='%d'" pan
;
6804 add_attrs bb false dc c;
6805 let kb = keymapsbuf false dc c in
6807 begin match bookmarks with
6809 if Buffer.length
kb > 0
6811 Buffer.add_string
bb ">\n";
6812 Buffer.add_buffer
bb kb;
6813 Buffer.add_string
bb "\n</doc>\n";
6815 else Buffer.add_string
bb "/>\n"
6817 Buffer.add_string
bb ">\n<bookmarks>\n";
6818 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6820 "<item title='%s' page='%d'"
6821 (enent
title 0 (String.length
title))
6826 Printf.bprintf
bb " rely='%f'" rely
6828 if abs_float visy
> 1e-6
6830 Printf.bprintf
bb " visy='%f'" visy
6832 Buffer.add_string
bb "/>\n";
6834 Buffer.add_string
bb "</bookmarks>";
6835 if Buffer.length
kb > 0
6837 Buffer.add_string
bb "\n";
6838 Buffer.add_buffer
bb kb;
6840 Buffer.add_string
bb "\n</doc>\n";
6846 match state.mode with
6847 | Birdseye
(c, pan, _, _, _) ->
6849 match conf.columns
with
6850 | Cmulti
((c, _, _), _) -> Some
c
6854 match c.columns
with
6855 | Cmulti
(c, _) -> Cmulti
(c, [||])
6856 | Csingle
_ -> Csingle
[||]
6857 | Csplit
_ -> failwith
"quit from bird's eye while split"
6859 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6860 | _ -> state.x, conf
6862 let basename = Filename.basename state.path in
6863 adddoc basename pan (getanchor ())
6865 let autoscrollstep =
6866 match state.autoscroll
with
6868 | None
-> conf.autoscrollstep
6870 match state.mode with
6871 | Birdseye
(bc
, _, _, _, _) ->
6874 presentation
= bc
.presentation
;
6875 interpagespace
= bc
.interpagespace
;
6876 maxwait
= bc
.maxwait
;
6877 autoscrollstep = autoscrollstep }
6878 | _ -> { conf with autoscrollstep = autoscrollstep }
6880 (if conf.savebmarks
then state.bookmarks else []);
6882 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6884 then adddoc path x anchor c bookmarks
6886 Buffer.add_string
bb "</llppconfig>\n";
6889 if load1 f && Buffer.length
bb > 0
6892 let tmp = !confpath ^
".tmp" in
6893 let oc = open_out_bin
tmp in
6894 Buffer.output_buffer
oc bb;
6896 Unix.rename
tmp !confpath;
6899 ("error while saving configuration: " ^
Printexc.to_string exn
)
6904 let trimcachepath = ref "" in
6907 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6908 "<password> Set password");
6910 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6911 "<path> Set path to the user interface font");
6913 ("-c", Arg.String
(fun s -> Config.confpath := s),
6914 "<path> Set path to the configuration file");
6916 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
6917 "<path> Set path to the trim cache file");
6919 ("-v", Arg.Unit
(fun () ->
6921 "%s\nconfiguration path: %s\n"
6925 exit
0), " Print version and exit");
6928 (fun s -> state.path <- s)
6929 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6931 if String.length
state.path = 0
6932 then (prerr_endline
"file name missing"; exit
1);
6934 if not
(Config.load ())
6935 then prerr_endline
"failed to load configuration";
6937 let globalkeyhash = findkeyhash conf "global" in
6938 let wsfd, winw, winh
= Wsi.init
(object
6940 state.wthack
<- false;
6941 if nogeomcmds state.geomcmds
|| platform == Posx
6944 GlClear.color (scalecolor2 conf.bgcolor
);
6945 GlClear.clear
[`
color];
6947 method display = display ()
6948 method reshape w h = reshape w h
6949 method mouse b d x y m = mouse b d x y m
6950 method motion x y = state.mpos
<- (x, y); motion x y
6951 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6953 let mascm = m land (
6954 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6956 match state.keystate
with
6958 let km = k, mascm in
6961 let modehash = state.uioh#
modehash in
6962 try Hashtbl.find modehash km
6964 try Hashtbl.find globalkeyhash km
6965 with Not_found
-> KMinsrt
(k, m)
6967 | KMinsrt
(k, m) -> keyboard k m
6968 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6969 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6971 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6972 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6973 state.keystate
<- KSnone
6974 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6975 state.keystate
<- KSinto
(keys
, insrt
)
6977 state.keystate
<- KSnone
6979 method enter
x y = state.mpos
<- (x, y); pmotion x y
6980 method leave = state.mpos
<- (-1, -1)
6981 method quit
= raise Quit
6982 end) conf.winw conf.winh
(platform = Posx
) in
6987 List.exists
GlMisc.check_extension
6988 [ "GL_ARB_texture_rectangle"
6989 ; "GL_EXT_texture_recangle"
6990 ; "GL_NV_texture_rectangle" ]
6992 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6995 match Ne.pipe () with
6997 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7001 match Ne.pipe () with
7003 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7013 setcheckers conf.checkers
;
7017 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7018 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7019 !Config.fontpath, !trimcachepath,
7020 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7024 state.text <- "Opening " ^
(mbtoutf8
state.path);
7026 opendoc state.path state.password
;
7029 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7031 let rec loop deadline
=
7033 match state.errfd
with
7034 | None
-> [state.sr
; state.wsfd]
7035 | Some fd
-> [state.sr
; state.wsfd; fd
]
7039 state.redisplay
<- false;
7046 if deadline
= infinity
7048 else max
0.0 (deadline
-. now)
7053 try Unix.select
r [] [] timeout
7054 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7060 if state.ghyll
== noghyll
7062 match state.autoscroll
with
7063 | Some step
when step
!= 0 ->
7064 let y = state.y + step
in
7068 else if y >= state.maxy then 0 else y
7071 if state.mode = View
7072 then state.text <- "";
7075 else deadline
+. 0.01
7080 let rec checkfds = function
7082 | fd
:: rest
when fd
= state.sr
->
7083 let cmd = readcmd state.sr
in
7087 | fd
:: rest
when fd
= state.wsfd ->
7092 let s = String.create
80 in
7093 let n = Unix.read fd
s 0 80 in
7094 if conf.redirectstderr
7096 Buffer.add_substring
state.errmsgs
s 0 n;
7097 state.newerrmsgs
<- true;
7098 state.redisplay
<- true;
7101 prerr_string
(String.sub
s 0 n);
7109 if deadline
= infinity
7113 match state.autoscroll
with
7114 | Some step
when step
!= 0 -> deadline1
7115 | _ -> if state.ghyll
== noghyll then infinity
else deadline1