3 let tempfailureretry = Wsi.tempfailureretry;;
8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
17 let now = Unix.gettimeofday
;;
19 type params
= (angle
* proportional
* trimparams
20 * texcount
* sliceheight
* memsize
21 * colorspace
* fontpath
* trimcachepath
31 and proportional
= bool
32 and trimmargins
= bool
33 and interpagespace
= int
40 and trimcachepath
= string
43 and irect
= (int * int * int * int)
44 and trimparams
= (trimmargins
* irect
)
45 and colorspace
= | Rgb
| Bgr
| Gray
55 | LDfirstvisible
of (int * int * int)
70 | KMmulti
of key list
* key list
72 and keyhash
= (key
, keymap
) Hashtbl.t
75 | KSinto
of (key list
* key list
)
78 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
79 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
81 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
83 external init
: pipe
-> params
-> unit = "ml_init";;
84 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
85 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
86 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
87 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
88 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
89 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
90 external measurestr
: int -> string -> float = "ml_measure_string";;
91 external getmaxw
: unit -> float = "ml_getmaxw";;
92 external postprocess
:
93 opaque
-> int -> int -> int -> (int * string * int) -> int
95 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
96 external platform
: unit -> platform
= "ml_platform";;
97 external setaalevel
: int -> unit = "ml_setaalevel";;
98 external realloctexts
: int -> bool = "ml_realloctexts";;
99 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
100 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
101 external getlink
: opaque
-> int -> under
= "ml_getlink";;
102 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
103 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
104 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
105 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
106 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
107 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
108 external freepbo
: string -> unit = "ml_freepbo";;
109 external unmappbo
: string -> unit = "ml_unmappbo";;
110 external pbousable
: unit -> bool = "ml_pbo_usable";;
111 external unproject
: opaque
-> int -> int -> (int * int) option
114 let platform_to_string = function
115 | Punknown
-> "unknown"
119 | Pfreebsd
-> "FreeBSD"
120 | Pdragonflybsd
-> "DragonflyBSD"
121 | Popenbsd
-> "OpenBSD"
122 | Pnetbsd
-> "NetBSD"
123 | Pcygwin
-> "Cygwin"
126 let platform = platform ();;
129 if platform = Pcygwin
131 let sh = "/bin/sh" in
132 let args = [|sh; "-c"; cmd
|] in
133 let rec std si so se
= function
135 | (fd
, 0) :: rest
-> std fd so se rest
136 | (fd
, -1) :: rest
->
137 Unix.set_close_on_exec fd
;
140 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
142 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
143 ignore
(Unix.create_process
sh args si so se
)
152 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
155 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
157 type mpos
= int * int
159 | Msel
of (mpos
* mpos
)
161 | Mscrolly
| Mscrollx
162 | Mzoom
of (int * int)
163 | Mzoomrect
of (mpos
* mpos
)
167 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
168 and onkey
= string -> int -> te
169 and ondone
= string -> unit
170 and histcancel
= unit -> unit
171 and onhist
= ((histcmd
-> string) * histcancel
)
172 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
173 and cancelonempty
= bool
178 | TEswitch
of textentry
189 let bound v minv maxv
=
190 max minv
(min maxv v
);
194 { store
= Array.create n v
201 let cbcap b
= Array.length b
.store
;;
206 b
.wc
<- (b
.wc
+ 1) mod cap;
208 b
.len
<- min
(b
.len
+ 1) cap;
211 let cbempty b
= b
.len
= 0;;
213 let cbgetg b circular dir
=
217 let rc = b
.rc + dir
in
229 else bound rc 0 (b
.len
-1)
235 let cbget b
= cbgetg b
false;;
236 let cbgetc b
= cbgetg b
true;;
238 let drawstring size x y s
=
240 Gl.enable `texture_2d
;
241 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
242 ignore
(drawstr size x y s
);
244 Gl.disable `texture_2d
;
247 let drawstring1 size x y s
=
251 let drawstring2 size x y fmt
=
252 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
271 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
272 dolog " WxH %dx%d" l
.pagew l
.pageh
;
273 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
274 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
275 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
276 dolog " column %d" l
.pagecol
;
280 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
282 dolog " x0,y0=(% f, % f)" x0 y0
;
283 dolog " x1,y1=(% f, % f)" x1 y1
;
284 dolog " x2,y2=(% f, % f)" x2 y2
;
285 dolog " x3,y3=(% f, % f)" x3 y3
;
289 type multicolumns
= multicol
* pagegeom
290 and singlecolumn
= pagegeom
291 and splitcolumns
= columncount
* pagegeom
292 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
293 and multicol
= columncount
* covercount
* covercount
295 and columncount
= int
296 and covercount
= int;;
299 { mutable scrollbw
: int
300 ; mutable scrollh
: int
301 ; mutable icase
: bool
302 ; mutable preload
: bool
303 ; mutable pagebias
: int
304 ; mutable verbose
: bool
305 ; mutable debug
: bool
306 ; mutable scrollstep
: int
307 ; mutable hscrollstep
: int
308 ; mutable maxhfit
: bool
309 ; mutable crophack
: bool
310 ; mutable autoscrollstep
: int
311 ; mutable maxwait
: float option
312 ; mutable hlinks
: bool
313 ; mutable underinfo
: bool
314 ; mutable interpagespace
: interpagespace
315 ; mutable zoom
: float
316 ; mutable presentation
: bool
317 ; mutable angle
: angle
320 ; mutable savebmarks
: bool
321 ; mutable proportional
: proportional
322 ; mutable trimmargins
: trimmargins
323 ; mutable trimfuzz
: irect
324 ; mutable memlimit
: memsize
325 ; mutable texcount
: texcount
326 ; mutable sliceheight
: sliceheight
327 ; mutable thumbw
: width
328 ; mutable jumpback
: bool
329 ; mutable bgcolor
: float * float * float
330 ; mutable bedefault
: bool
331 ; mutable scrollbarinpm
: bool
332 ; mutable tilew
: int
333 ; mutable tileh
: int
334 ; mutable mustoresize
: memsize
335 ; mutable checkers
: bool
336 ; mutable aalevel
: int
337 ; mutable urilauncher
: string
338 ; mutable pathlauncher
: string
339 ; mutable colorspace
: colorspace
340 ; mutable invert
: bool
341 ; mutable colorscale
: float
342 ; mutable redirectstderr
: bool
343 ; mutable ghyllscroll
: (int * int * int) option
344 ; mutable columns
: columns
345 ; mutable beyecolumns
: columncount
option
346 ; mutable selcmd
: string
347 ; mutable updatecurs
: bool
348 ; mutable keyhashes
: (string * keyhash
) list
349 ; mutable hfsize
: int
350 ; mutable pgscale
: float
351 ; mutable usepbo
: bool
352 ; mutable wheelbypage
: bool
353 ; mutable stcmd
: string
356 | Csingle
of singlecolumn
357 | Cmulti
of multicolumns
358 | Csplit
of splitcolumns
361 type anchor
= pageno
* top
* dtop
;;
363 type outline
= string * int * anchor
;;
365 type rect
= float * float * float * float * float * float * float * float;;
367 type tile
= opaque
* pixmapsize
* elapsed
368 and elapsed
= float;;
369 type pagemapkey
= pageno
* gen
;;
370 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
374 let emptyanchor = (0, 0.0, 0.0);;
376 type infochange
= | Memused
| Docinfo
| Pdim
;;
378 class type uioh
= object
379 method display
: unit
380 method key
: int -> int -> uioh
381 method button
: int -> bool -> int -> int -> int -> uioh
382 method motion
: int -> int -> uioh
383 method pmotion
: int -> int -> uioh
384 method infochanged
: infochange
-> unit
385 method scrollpw
: (int * float * float)
386 method scrollph
: (int * float * float)
387 method modehash
: keyhash
391 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
392 | Textentry
of (textentry
* onleave
)
394 | LinkNav
of linktarget
395 and onleave
= leavetextentrystatus
-> unit
396 and leavetextentrystatus
= | Cancel
| Confirm
397 and helpitem
= string * int * action
400 | Action
of (uioh
-> uioh
)
402 | Ltexact
of (pageno
* int)
406 let isbirdseye = function Birdseye _
-> true | _
-> false;;
407 let istextentry = function Textentry _
-> true | _
-> false;;
411 | Loading
of (page
* gen
)
413 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
415 | Outlining
of outline list
418 let emptykeyhash = Hashtbl.create
0;;
419 let nouioh : uioh
= object (self
)
421 method key _ _
= self
422 method button _ _ _ _ _
= self
423 method motion _ _
= self
424 method pmotion _ _
= self
425 method infochanged _
= ()
426 method scrollpw
= (0, nan
, nan
)
427 method scrollph
= (0, nan
, nan
)
428 method modehash
= emptykeyhash
432 { mutable sr
: Unix.file_descr
433 ; mutable sw
: Unix.file_descr
434 ; mutable wsfd
: Unix.file_descr
435 ; mutable errfd
: Unix.file_descr
option
436 ; mutable stderr
: Unix.file_descr
437 ; mutable errmsgs
: Buffer.t
438 ; mutable newerrmsgs
: bool
442 ; mutable scrollw
: int
443 ; mutable hscrollh
: int
444 ; mutable anchor
: anchor
445 ; mutable ranchors
: (string * string * anchor
) list
447 ; mutable layout
: page list
448 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
449 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
450 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
451 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
452 ; mutable pagecount
: int
453 ; mutable currently
: currently
454 ; mutable mstate
: mstate
455 ; mutable searchpattern
: string
456 ; mutable rects
: (pageno
* recttype
* rect
) list
457 ; mutable rects1
: (pageno
* recttype
* rect
) list
458 ; mutable text
: string
459 ; mutable fullscreen
: (width
* height
) option
460 ; mutable mode
: mode
461 ; mutable uioh
: uioh
462 ; mutable outlines
: outline array
463 ; mutable bookmarks
: outline list
464 ; mutable path
: string
465 ; mutable password
: string
466 ; mutable nameddest
: string
467 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
468 ; mutable memused
: memsize
470 ; mutable throttle
: (page list
* int * float) option
471 ; mutable autoscroll
: int option
472 ; mutable ghyll
: (int option -> unit)
473 ; mutable help
: helpitem array
474 ; mutable docinfo
: (int * string) list
475 ; mutable texid
: GlTex.texture_id
option
477 ; mutable prevzoom
: float
478 ; mutable progress
: float
479 ; mutable redisplay
: bool
480 ; mutable mpos
: mpos
481 ; mutable keystate
: keystate
482 ; mutable glinks
: bool
483 ; mutable prevcolumns
: (columns
* float) option
484 ; mutable wthack
: bool
487 { pat
: string circbuf
488 ; pag
: string circbuf
489 ; nav
: anchor circbuf
490 ; sel
: string circbuf
512 ; presentation
= false
517 ; proportional
= true
518 ; trimmargins
= false
519 ; trimfuzz
= (0,0,0,0)
520 ; memlimit
= 32 lsl 20
525 ; bgcolor
= (0.5, 0.5, 0.5)
527 ; scrollbarinpm
= true
530 ; mustoresize
= 256 lsl 20
535 | Plinux
| Pfreebsd
| Pdragonflybsd
536 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
537 | Posx
-> "open \"%s\""
538 | Pcygwin
-> "cygstart \"%s\""
539 | Punknown
-> "echo %s")
540 ; pathlauncher
= "lp \"%s\""
543 | Plinux
| Pfreebsd
| Pdragonflybsd
544 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
551 ; redirectstderr
= false
553 ; columns
= Csingle
[||]
559 ; wheelbypage
= false
560 ; stcmd
= "echo SyncTex"
562 let mk n
= (n
, Hashtbl.create
1) in
576 let wtmode = ref false;;
578 let findkeyhash c name
=
579 try List.assoc name c
.keyhashes
580 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
583 let conf = { defconf with angle
= defconf.angle
};;
585 let pgscale h
= truncate
(float h
*. conf.pgscale);;
588 { mutable fontsize
: int
589 ; mutable wwidth
: float
590 ; mutable maxrows
: int
602 fstate.fontsize
<- n
;
603 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
604 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
608 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
609 let len = String.length s
in
610 if colonpos >= 0 && colonpos + 3 < len
612 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
615 try String.rindex_from s
colonpos ' '
619 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
622 | "http" | "ftp" | "mailto" ->
624 try String.index_from s
colonpos ' '
625 with Not_found
-> len
627 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
635 if String.length
conf.urilauncher
= 0
636 then print_endline uri
638 let url = geturl uri
in
639 if String.length
url = 0
640 then print_endline uri
642 let re = Str.regexp
"%s" in
643 let command = Str.global_replace
re url conf.urilauncher
in
647 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
653 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
654 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
658 let strings = version () :: "" :: Help.keys
in
661 let url = geturl s
in
662 if String.length
url > 0
663 then (s
, 0, Action
(fun u
-> gotouri url; u
))
664 else (s
, 0, Noaction
)
669 let firstgeomcmds = "", [];;
676 ; stderr
= Unix.stderr
677 ; errmsgs
= Buffer.create
0
684 ; anchor
= emptyanchor
688 ; tilelru
= Queue.create
()
689 ; pagemap
= Hashtbl.create
10
690 ; tilemap
= Hashtbl.create
10
706 ; geomcmds
= firstgeomcmds
708 { nav
= cbnew 10 emptyanchor
736 Printf.kprintf prerr_endline fmt
738 Printf.kprintf ignore fmt
742 if String.length
conf.pathlauncher
= 0
743 then print_endline
state.path
745 let re = Str.regexp
"%s" in
746 let command = Str.global_replace
re state.path
conf.pathlauncher
in
750 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
756 type 'a t
= | Res
of 'a
| Exn
of exn
;;
759 try Res
(Unix.pipe ())
764 try tempfailureretry Unix.close fd
765 with exn
-> f
(Printexc.to_string exn
)
769 try Res
(tempfailureretry Unix.dup fd
)
774 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
779 let redirectstderr () =
780 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
781 if conf.redirectstderr
783 match Ne.pipe () with
785 dolog "failed to create stderr redirection pipes: %s"
786 (Printexc.to_string exn
)
789 begin match Ne.dup Unix.stderr
with
791 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
792 Ne.clo r
(clofail "pipe/r");
793 Ne.clo w
(clofail "pipe/w");
795 | Ne.Res dupstderr
->
796 begin match Ne.dup2 w
Unix.stderr
with
798 dolog "failed to dup2 to stderr: %s"
799 (Printexc.to_string exn
);
800 Ne.clo dupstderr
(clofail "stderr duplicate");
801 Ne.clo r
(clofail "redir pipe/r");
802 Ne.clo w
(clofail "redir pipe/w");
805 state.stderr
<- dupstderr
;
806 state.errfd
<- Some r
;
810 state.newerrmsgs
<- false;
811 begin match state.errfd
with
813 begin match Ne.dup2 state.stderr
Unix.stderr
with
815 dolog "failed to dup2 original stderr: %s"
816 (Printexc.to_string exn
)
818 Ne.clo fd
(clofail "dup of stderr");
823 prerr_string
(Buffer.contents
state.errmsgs
);
825 Buffer.clear
state.errmsgs
;
831 let postRedisplay who
=
833 then prerr_endline
("redisplay for " ^ who
);
834 state.redisplay
<- true;
838 let getopaque pageno
=
839 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
840 with Not_found
-> None
843 let putopaque pageno opaque
=
844 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
847 let pagetranslatepoint l x y
=
848 let dy = y
- l
.pagedispy
in
849 let y = dy + l
.pagey
in
850 let dx = x
- l
.pagedispx
in
851 let x = dx + l
.pagex
in
855 let onppundermouse g
x y d
=
858 begin match getopaque l
.pageno
with
860 let x0 = l
.pagedispx
in
861 let x1 = x0 + l
.pagevw
in
862 let y0 = l
.pagedispy
in
863 let y1 = y0 + l
.pagevh
in
864 if y >= y0 && y <= y1 && x >= x0 && x <= x1
866 let px, py
= pagetranslatepoint l
x y in
867 match g opaque l
px py
with
880 let g opaque _
px py
=
881 match whatsunder opaque
px py
with
883 | under
-> Some under
885 onppundermouse g x y Unone
890 match unproject opaque
x y with
891 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
894 onppundermouse g x y None
;
898 state.text
<- Printf.sprintf
"%c%s" c s
;
899 G.postRedisplay "showtext";
902 let undertext = function
905 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
906 | Utext s
-> "font: " ^ s
907 | Uunexpected s
-> "unexpected: " ^ s
908 | Ulaunch s
-> "launch: " ^ s
909 | Unamed s
-> "named: " ^ s
910 | Uremote
(filename
, pageno
) ->
911 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
914 let updateunder x y =
915 match getunder x y with
916 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
918 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
919 Wsi.setcursor
Wsi.CURSOR_INFO
920 | Ulinkgoto
(pageno
, _
) ->
922 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
923 Wsi.setcursor
Wsi.CURSOR_INFO
925 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
926 Wsi.setcursor
Wsi.CURSOR_TEXT
928 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
929 Wsi.setcursor
Wsi.CURSOR_INHERIT
931 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
932 Wsi.setcursor
Wsi.CURSOR_INHERIT
934 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
935 Wsi.setcursor
Wsi.CURSOR_INHERIT
936 | Uremote
(filename
, pageno
) ->
937 if conf.underinfo
then showtext 'r'
938 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
939 Wsi.setcursor
Wsi.CURSOR_INFO
942 let showlinktype under
=
948 let s = undertext under
in
953 let b = Buffer.create
(String.length
s + 1) in
954 Buffer.add_string
b s;
959 let colorspace_of_string s =
960 match String.lowercase
s with
964 | _
-> failwith
"invalid colorspace"
967 let int_of_colorspace = function
973 let colorspace_of_int = function
977 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
980 let colorspace_to_string = function
986 let intentry_with_suffix text key
=
988 if key
>= 32 && key
< 127
992 match Char.lowercase
c with
994 let text = addchar text c in
998 let text = addchar text c in
1002 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1006 let multicolumns_to_string (n
, a
, b) =
1008 then Printf.sprintf
"%d" n
1009 else Printf.sprintf
"%d,%d,%d" n a
b;
1012 let multicolumns_of_string s =
1014 (int_of_string
s, 0, 0)
1016 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1018 then failwith
"subtly broken"; (n
, a
, b)
1024 let n = tempfailureretry (Unix.read fd
s 0) 4 in
1025 if n != 4 then failwith
"incomplete read(len)";
1027 lor (Char.code
s.[0] lsl 24)
1028 lor (Char.code
s.[1] lsl 16)
1029 lor (Char.code
s.[2] lsl 8)
1030 lor (Char.code
s.[3] lsl 0)
1032 let s = String.create
len in
1033 let n = tempfailureretry (Unix.read fd
s 0) len in
1034 if n != len then failwith
"incomplete read(data)";
1038 let btod b = if b then 1 else 0;;
1041 let b = Buffer.create
16 in
1042 Buffer.add_string
b "llll";
1045 let s = Buffer.contents
b in
1046 let n = String.length
s in
1048 (* dolog "wcmd %S" (String.sub s 4 len); *)
1049 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1050 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1051 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1052 s.[3] <- Char.chr
(len land 0xff);
1053 let n'
= tempfailureretry (Unix.write
state.sw
s 0) n in
1054 if n'
!= n then failwith
"write failed";
1059 let d = conf.winh
- h
in
1060 max
conf.interpagespace
((d + 1) / 2)
1063 let rowyh (c, coverA
, coverB
) b n =
1064 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1066 let _, _, vy
, (_, _, h
, _) = b.(n) in
1069 let n'
= n - coverA
in
1072 let e = min
state.pagecount
(s + c) in
1073 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1074 let _, _, y, (_, _, h
, _) = b.(m
) in
1075 let miny = min
miny y in
1076 let maxh = max
maxh h
in
1077 find (m
+1) miny maxh
1082 match conf.columns
with
1083 | Cmulti
((_, _, _) as cl
, b) ->
1084 if Array.length
b > 0
1086 let y, h
= rowyh cl
b (Array.length
b - 1) in
1087 y + h
+ (if conf.presentation
then calcips h
else 0)
1090 if Array.length
b > 0
1092 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1093 y + h
+ (if conf.presentation
then calcips h
else 0)
1096 if Array.length
b > 0
1098 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1103 let getpageyh pageno
=
1104 let pageno = bound pageno 0 (state.pagecount
-1) in
1105 match conf.columns
with
1107 if Array.length
b = 0
1110 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1112 if conf.presentation
1118 if Array.length
b = 0
1121 let y, h
= rowyh cl
b pageno in
1123 if conf.presentation
1129 if Array.length
b = 0
1133 let (_, _, y, (_, _, h
, _)) = b.(n) in
1137 let getpagedim pageno =
1140 | (n, _, _, _) as pdim
:: rest
->
1142 then (if n = pageno then pdim
else ppdim
)
1147 f (-1, -1, -1, -1) state.pdims
1150 let getpagey pageno = fst
(getpageyh pageno);;
1152 let nogeomcmds cmds
=
1154 | s, [] -> String.length
s = 0
1159 let ((c, coverA
, coverB
) as cl
), b =
1160 match conf.columns
with
1161 | Csingle
b -> (1, 0, 0), b
1162 | Cmulti
(c, b) -> c, b
1163 | Csplit
(_, b) -> (1, 0, 0), b
1165 let rec bsearch nmin nmax
=
1167 then bound nmin
0 (state.pagecount
-1)
1169 let n = (nmax
+ nmin
) / 2 in
1170 let vy, h
= rowyh cl
b n in
1172 if conf.presentation
1174 let ips = calcips h
in
1175 let y0 = vy - ips in
1176 let y1 = vy + h
+ ips in
1180 then 0, vy + h
+ conf.interpagespace
1182 let y0 = vy - conf.interpagespace
in
1183 y0, y0 + h
+ conf.interpagespace
1186 if y >= y0 && y < y1
1193 if n < state.pagecount
- coverB
1194 then ((n-coverA
)/c)*c + coverA
1201 then bsearch (n+1) nmax
1202 else bsearch nmin
(n-1)
1205 let r = bsearch 0 (state.pagecount
-1) in
1209 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1210 let sh = sh - state.hscrollh
in
1211 let rec fold accu
n =
1212 if n = Array.length
b
1215 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1218 || n = state.pagecount
- coverB
1219 || (n - coverA
) mod columns
= columns
- 1)
1225 let pagey = max
0 (y - vy) in
1226 let pagedispy = if pagey > 0 then 0 else vy - y in
1227 let pagedispx, pagex
=
1229 if n = coverA
- 1 || n = state.pagecount
- coverB
1230 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1231 else dx + xoff
+ state.x
1238 let vw = conf.winw
- state.scrollw
- pagedispx in
1239 let pw = w
- pagex
in
1242 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1243 if pagevw > 0 && pagevh > 0
1247 ; pagedimno
= pdimno
1254 ; pagedispx = pagedispx
1255 ; pagedispy = pagedispy
1267 List.rev
(fold [] (page_of_y y));
1270 let layoutS (columns
, b) y sh =
1271 let sh = sh - state.hscrollh
in
1272 let rec fold accu n =
1273 if n = Array.length
b
1276 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1283 let x = xoff
+ state.x in
1284 let pagey = max
0 (y - vy) in
1285 let pagedispy = if pagey > 0 then 0 else vy - y in
1286 let pagedispx, pagex
=
1300 let pagecolw = pagew
/columns
in
1302 if pagecolw < conf.winw
1303 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1307 let vw = conf.winw
- pagedispx - state.scrollw
in
1308 let pw = pagew
- pagex
in
1311 let pagevw = min
pagevw pagecolw in
1312 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1313 if pagevw > 0 && pagevh > 0
1316 { pageno = n/columns
1317 ; pagedimno
= pdimno
1324 ; pagedispx = pagedispx
1325 ; pagedispy = pagedispy
1326 ; pagecol
= n mod columns
1337 List.rev
(fold [] 0)
1341 if nogeomcmds state.geomcmds
1343 match conf.columns
with
1344 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1345 | Cmulti
c -> layoutN c y sh
1346 | Csplit
s -> layoutS s y sh
1351 let y = state.y + incr
in
1353 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1358 let tilex = l
.pagex
mod conf.tilew
in
1359 let tiley = l
.pagey mod conf.tileh
in
1361 let col = l
.pagex
/ conf.tilew
in
1362 let row = l
.pagey / conf.tileh
in
1364 let rec rowloop row y0 dispy h
=
1368 let dh = conf.tileh
- y0 in
1369 let dh = min h
dh in
1370 let rec colloop col x0 dispx w
=
1374 let dw = conf.tilew
- x0 in
1375 let dw = min w
dw in
1377 f col row dispx dispy
x0 y0 dw dh;
1378 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1381 colloop col tilex l
.pagedispx l
.pagevw;
1382 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1385 if l
.pagevw > 0 && l
.pagevh > 0
1386 then rowloop row tiley l
.pagedispy l
.pagevh;
1389 let gettileopaque l
col row =
1391 l
.pageno, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1393 try Some
(Hashtbl.find state.tilemap
key)
1394 with Not_found
-> None
1397 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1398 let key = l
.pageno, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1399 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1402 let drawtiles l color
=
1404 let f col row x y tilex tiley w h
=
1405 match gettileopaque l
col row with
1406 | Some
(opaque
, _, t
) ->
1407 let params = x, y, w
, h
, tilex, tiley in
1411 GlFunc.blend_func `zero `one_minus_src_color
;
1413 drawtile
params opaque
;
1415 then Gl.disable `blend
;
1418 let s = Printf.sprintf
1422 let w = measurestr
fstate.fontsize
s in
1423 GlMisc.push_attrib
[`current
];
1424 GlDraw.color
(0.0, 0.0, 0.0);
1426 (float (x-2), float (y-2))
1427 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1428 GlDraw.color
(1.0, 1.0, 1.0);
1429 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1430 GlMisc.pop_attrib
();
1435 let lw = conf.winw
- state.scrollw
- x in
1438 let lh = conf.winh
- y in
1441 begin match state.texid
with
1443 Gl.enable `texture_2d
;
1444 GlTex.bind_texture `texture_2d id
;
1447 and x1 = float (x+w)
1448 and y1 = float (y+h
) in
1450 let tw = float w /. 16.0
1451 and th
= float h
/. 16.0 in
1452 let tx0 = float tilex /. 16.0
1453 and ty0
= float tiley /. 16.0 in
1455 and ty1
= ty0
+. th
in
1456 GlDraw.begins `quads
;
1457 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1458 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1459 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1460 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1463 Gl.disable `texture_2d
;
1465 GlDraw.color
(1.0, 1.0, 1.0);
1468 (float (x+w), float (y+h
));
1470 if w > 128 && h
> fstate.fontsize
+ 10
1472 GlDraw.color
(0.0, 0.0, 0.0);
1475 then (col*conf.tilew
, row*conf.tileh
)
1478 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno c r;
1485 let pagevisible layout n = List.exists
(fun l
-> l
.pageno = n) layout;;
1487 let tilevisible1 l
x y =
1489 and ax1
= l
.pagex
+ l
.pagevw
1491 and ay1
= l
.pagey + l
.pagevh in
1495 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1496 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1498 let rx0 = max
ax0 bx0
1499 and ry0
= max ay0 by0
1500 and rx1
= min ax1
bx1
1501 and ry1
= min ay1 by1
in
1503 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1504 nonemptyintersection
1507 let tilevisible layout n x y =
1508 let rec findpageinlayout m
= function
1509 | l
:: rest
when l
.pageno = n ->
1510 tilevisible1 l
x y || (
1511 match conf.columns
with
1512 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1515 | _ :: rest
-> findpageinlayout 0 rest
1518 findpageinlayout 0 layout;
1521 let tileready l
x y =
1522 tilevisible1 l
x y &&
1523 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1526 let tilepage n p
layout =
1527 let rec loop = function
1531 let f col row _ _ _ _ _ _ =
1532 if state.currently
= Idle
1534 match gettileopaque l
col row with
1537 let x = col*conf.tilew
1538 and y = row*conf.tileh
in
1540 let w = l
.pagew
- x in
1544 let h = l
.pageh
- y in
1549 then getpbo
w h conf.colorspace
1552 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1555 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1556 conf.tilew
, conf.tileh
1565 if nogeomcmds state.geomcmds
1569 let preloadlayout y =
1570 let y = if y < conf.winh
then 0 else y - conf.winh
in
1571 let h = conf.winh
*3 in
1576 let rec loop pages
=
1577 if state.currently
!= Idle
1582 begin match getopaque l
.pageno with
1584 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1585 state.currently
<- Loading
(l
, state.gen
);
1587 tilepage l
.pageno opaque pages
;
1592 if nogeomcmds state.geomcmds
1598 if conf.preload && state.currently
= Idle
1599 then load (preloadlayout state.y);
1602 let layoutready layout =
1603 let rec fold all ls
=
1604 all
&& match ls
with
1606 let seen = ref false in
1607 let allvisible = ref true in
1608 let foo col row _ _ _ _ _ _ =
1610 allvisible := !allvisible &&
1611 begin match gettileopaque l
col row with
1617 fold (!seen && !allvisible) rest
1620 let alltilesvisible = fold true layout in
1625 state.wthack
<- false;
1626 let y = bound y 0 state.maxy
in
1627 let y, layout, proceed
=
1628 match conf.maxwait
with
1629 | Some time
when state.ghyll
== noghyll ->
1630 begin match state.throttle
with
1632 let layout = layout y conf.winh
in
1633 let ready = layoutready layout in
1637 state.throttle
<- Some
(layout, y, now ());
1639 else G.postRedisplay "gotoy showall (None)";
1641 | Some
(_, _, started
) ->
1642 let dt = now () -. started
in
1645 state.throttle
<- None
;
1646 let layout = layout y conf.winh
in
1648 G.postRedisplay "maxwait";
1655 let layout = layout y conf.winh
in
1656 G.postRedisplay "gotoy ready";
1662 state.layout <- layout;
1663 begin match state.mode
with
1664 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1665 let rec loop = function
1667 state.mode
<- LinkNav
(Ltgendir
0)
1668 | l
:: _ when l
.pageno = pageno ->
1669 begin match getopaque pageno with
1671 state.mode
<- LinkNav
(Ltgendir
0)
1673 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1674 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
1675 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1676 then state.mode
<- LinkNav
(Ltgendir
0)
1678 | _ :: rest
-> loop rest
1683 begin match state.mode
with
1684 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1685 if not
(pagevisible layout pageno)
1687 match state.layout with
1690 state.mode
<- Birdseye
(
1691 conf, leftx
, l
.pageno, hooverpageno
, anchor
1694 | LinkNav
(Ltgendir dir
as lt
) ->
1696 let rec loop = function
1699 match getopaque l
.pageno with
1705 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1707 if dir
> 0 then LDfirst
else LDlast
1713 | Lnotfound
-> loop rest
1715 showlinktype (getlink opaque
n);
1716 Ltexact
(l
.pageno, n)
1720 state.mode
<- LinkNav
linknav
1725 state.ghyll
<- noghyll;
1728 let mx, my
= state.mpos
in
1733 let conttiling pageno opaque
=
1734 tilepage pageno opaque
1735 (if conf.preload then preloadlayout state.y else state.layout)
1738 let gotoy_and_clear_text y =
1739 if not
conf.verbose
then state.text <- "";
1745 let coloff = l
.pagecol
* l
.pageh
in
1746 float (l
.pagey + coloff) /. float l
.pageh
1753 if conf.presentation
1754 then float l
.pagedispy /. float (calcips l
.pageh
)
1755 else float l
.pagedispy /. float conf.interpagespace
1757 (l
.pageno, top, dtop)
1761 match state.layout with
1762 | l
:: _ -> getanchor1 l
1764 let n = page_of_y state.y in
1765 let y, h = getpageyh n in
1766 let dy = y - state.y in
1768 if conf.presentation
1770 let ips = calcips h in
1771 float (dy + ips) /. float ips
1773 float dy /. float conf.interpagespace
1778 let getanchory (n, top, dtop) =
1779 let y, h = getpageyh n in
1780 if conf.presentation
1782 let ips = calcips h in
1783 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1785 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1788 let gotoanchor anchor
=
1789 gotoy (getanchory anchor
);
1793 cbput state.hists
.nav
(getanchor ());
1797 let anchor = cbgetc state.hists
.nav dir
in
1802 let scroll f n a
b =
1803 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1805 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1807 then s (float f /. float a
)
1810 then 1.0 -. s ((float (f-b) /. float (n-b)))
1817 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1818 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1820 let ins = float a
*. iv1
1821 and outs
= float (n-b) *. iv1 in
1823 ins +. outs
+. float ones
1825 let rec set (_N
, _A
, _B
) y sy
=
1826 let sum = summa
1.0 _N _A _B
in
1827 let dy = float (y - sy
) in
1831 then state.ghyll
<- noghyll
1834 let s = scroll n _N _A _B
in
1835 let y1 = y1 +. ((s *. dy) /. sum) in
1836 gotoy_and_clear_text (truncate
y1);
1837 state.ghyll
<- gf (n+1) y1;
1841 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1843 gf 0 (float state.y)
1846 match conf.ghyllscroll
with
1848 gotoy_and_clear_text y
1850 if state.ghyll
== noghyll
1851 then set nab
y state.y
1852 else state.ghyll
(Some
y)
1855 let gotopage n top =
1856 let y, h = getpageyh n in
1857 let y = y + (truncate
(top *. float h)) in
1861 let gotopage1 n top =
1862 let y = getpagey n in
1867 let invalidate s f =
1872 match state.geomcmds
with
1873 | ps
, [] when String.length ps
= 0 ->
1875 state.geomcmds
<- s, [];
1878 state.geomcmds
<- ps
, [s, f];
1880 | ps
, (s'
, _) :: rest
when s'
= s ->
1881 state.geomcmds
<- ps
, ((s, f) :: rest
);
1884 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1888 Hashtbl.iter
(fun _ opaque
->
1889 wcmd "freepage %s" opaque
;
1891 Hashtbl.clear
state.pagemap
;
1894 let opendoc path password
=
1896 state.password
<- password
;
1897 state.gen
<- state.gen
+ 1;
1898 state.docinfo
<- [];
1901 setaalevel
conf.aalevel
;
1902 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename path
)));
1903 wcmd "open %d %s\000%s\000" (btod state.wthack
) path password
;
1904 invalidate "reqlayout"
1906 wcmd "reqlayout %d %d %s\000"
1907 conf.angle
(btod conf.proportional
) state.nameddest
;
1912 state.anchor <- getanchor ();
1913 state.wthack
<- !wtmode;
1914 opendoc state.path
state.password
;
1918 let c = c *. conf.colorscale
in
1922 let scalecolor2 (r, g, b) =
1923 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
1926 let docolumns = function
1928 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1929 let rec loop pageno pdimno pdim
y ph pdims
=
1930 if pageno = state.pagecount
1933 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1935 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1936 pdimno+1, pdim
, rest
1940 let x = max
0 (((conf.winw
- state.scrollw
- w) / 2) - xoff
) in
1942 (if conf.presentation
1943 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
1944 else (if pageno = 0 then 0 else conf.interpagespace
)
1947 a.(pageno) <- (pdimno, x, y, pdim
);
1948 loop (pageno+1) pdimno pdim
(y + h) h pdims
1950 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
1951 conf.columns
<- Csingle
a;
1953 | Cmulti
((columns
, coverA
, coverB
), _) ->
1954 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1955 let rec loop pageno pdimno pdim
x y rowh pdims
=
1956 let rec fixrow m
= if m
= pageno then () else
1957 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1960 let y = y + (rowh
- h) / 2 in
1961 a.(m
) <- (pdimno, x, y, pdim
);
1965 if pageno = state.pagecount
1966 then fixrow (((pageno - 1) / columns
) * columns
)
1968 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
1970 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
1971 pdimno+1, pdim
, rest
1976 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
1978 let x = (conf.winw
- state.scrollw
- w) / 2 in
1980 if conf.presentation
then calcips h else conf.interpagespace
in
1981 x, y + ips + rowh
, h
1984 if (pageno - coverA
) mod columns
= 0
1986 let x = max
0 (conf.winw
- state.scrollw
- state.w) / 2 in
1988 if conf.presentation
1990 let ips = calcips h in
1991 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
1993 y + (if pageno = 0 then 0 else conf.interpagespace
)
1997 else x, y, max rowh
h
2001 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2004 if pageno = columns
&& conf.presentation
2006 let ips = calcips rowh
in
2007 for i
= 0 to pred columns
2009 let (pdimno, x, y, pdim
) = a.(i
) in
2010 a.(i
) <- (pdimno, x, y+ips, pdim
)
2016 fixrow (pageno - columns
);
2021 a.(pageno) <- (pdimno, x, y, pdim
);
2022 let x = x + w + xoff
*2 + conf.interpagespace
in
2023 loop (pageno+1) pdimno pdim
x y rowh' pdims
2025 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2026 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2029 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2030 let rec loop pageno pdimno pdim
y pdims
=
2031 if pageno = state.pagecount
2034 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2036 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2037 pdimno+1, pdim
, rest
2042 let rec loop1 n x y =
2043 if n = c then y else (
2044 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2045 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2048 let y = loop1 0 0 y in
2049 loop (pageno+1) pdimno pdim
y pdims
2051 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2052 conf.columns
<- Csplit
(c, a);
2056 docolumns conf.columns
;
2057 state.maxy
<- calcheight ();
2059 if state.w <= conf.winw
- state.scrollw
2063 let wthack = state.wthack in
2064 begin match state.mode
with
2065 | Birdseye
(_, _, pageno, _, _) ->
2066 let y, h = getpageyh pageno in
2067 let top = (conf.winh
- h) / 2 in
2068 gotoy (max
0 (y - top))
2069 | _ -> gotoanchor state.anchor
2071 state.wthack <- wthack;
2075 state.wthack <- false;
2076 GlDraw.viewport
0 0 w h;
2077 let firsttime = state.geomcmds
== firstgeomcmds in
2078 if not
firsttime && nogeomcmds state.geomcmds
2079 then state.anchor <- getanchor ();
2082 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2085 setfontsize fstate.fontsize
;
2086 GlMat.mode `modelview
;
2087 GlMat.load_identity
();
2089 GlMat.mode `projection
;
2090 GlMat.load_identity
();
2091 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2092 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2093 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2098 else float state.x /. float state.w
2100 invalidate "geometry"
2104 then state.x <- truncate
(relx *. float w);
2106 match conf.columns
with
2108 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2109 | Csplit
(c, _) -> w * c
2111 wcmd "geometry %d %d" w h);
2115 let len = String.length
state.text in
2118 match state.mode
with
2121 let h, _, _ = state.uioh#scrollpw
in
2127 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2128 (x+.w, float (conf.winh
- hscrollh))
2131 let w = float (conf.winw
- state.scrollw
- 1) in
2132 if state.progress
>= 0.0 && state.progress
< 1.0
2134 GlDraw.color
(0.3, 0.3, 0.3);
2135 let w1 = w *. state.progress
in
2137 GlDraw.color
(0.0, 0.0, 0.0);
2141 GlDraw.color
(0.0, 0.0, 0.0);
2145 GlDraw.color
(1.0, 1.0, 1.0);
2146 drawstring fstate.fontsize
2147 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2150 match state.mode
with
2151 | Textentry
((prefix
, text, _, _, _, _), _) ->
2155 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2157 Printf.sprintf
"%s%s_" prefix
text
2166 if not
(istextentry state.mode
)
2168 let s1 = "(press 'e' to review error messasges)" in
2169 if String.length
s > 0 then s ^
" " ^
s1 else s1
2174 if String.length
s > 0
2179 let len = Queue.length
state.tilelru
in
2181 match state.throttle
with
2184 then preloadlayout state.y
2186 | Some
(layout, _, _) ->
2190 if state.memused
<= conf.memlimit
2195 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2196 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2197 let (_, pw, ph
, _) = getpagedim n in
2200 && colorspace
= conf.colorspace
2201 && angle
= conf.angle
2205 let x = col*conf.tilew
2206 and y = row*conf.tileh
in
2207 tilevisible (Lazy.force_val
layout) n x y
2209 then Queue.push lruitem
state.tilelru
2212 wcmd "freetile %s" p
;
2213 state.memused
<- state.memused
- s;
2214 state.uioh#infochanged Memused
;
2215 Hashtbl.remove
state.tilemap k
;
2224 Queue.iter
(fun (k
, p
, s) ->
2225 wcmd "freetile %s" p
;
2226 state.memused
<- state.memused
- s;
2227 state.uioh#infochanged Memused
;
2228 Hashtbl.remove
state.tilemap k
;
2230 Queue.clear
state.tilelru
;
2234 let logcurrently = function
2235 | Idle
-> dolog "Idle"
2236 | Loading
(l
, gen
) ->
2237 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2238 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2240 "Tiling %d[%d,%d] page=%s cs=%s angle"
2241 l
.pageno col row pageopaque
2242 (colorspace_to_string colorspace
)
2244 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2245 angle gen
conf.angle
state.gen
2247 conf.tilew
conf.tileh
2254 (* dolog "%S" cmds; *)
2257 try String.index cmds ' '
2258 with Not_found
-> -1
2263 let l = String.length cmds
in
2264 let op = String.sub cmds
0 spacepos in
2266 if l - spacepos < 2 then ""
2267 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2272 state.uioh#infochanged Pdim
;
2276 state.rects
<- state.rects1
;
2277 G.postRedisplay "clearrects";
2281 try Scanf.sscanf
args "%u" (fun n -> n)
2283 dolog "error processing 'continue' %S: %s"
2284 cmds
(Printexc.to_string exn
);
2287 state.pagecount
<- n;
2288 begin match state.currently
with
2290 state.currently
<- Idle
;
2291 state.outlines
<- Array.of_list
(List.rev
l)
2295 let cur, cmds
= state.geomcmds
in
2296 if String.length
cur = 0
2297 then failwith
"umpossible";
2299 begin match List.rev cmds
with
2301 state.geomcmds
<- "", [];
2305 state.geomcmds
<- s, List.rev rest
;
2307 if conf.maxwait
= None
2308 then G.postRedisplay "continue";
2318 then showtext ' '
args
2321 Buffer.add_string
state.errmsgs
args;
2322 state.newerrmsgs
<- true;
2323 G.postRedisplay "error message"
2326 let progress, text =
2328 Scanf.sscanf
args "%f %n"
2330 f, String.sub
args pos
(String.length
args - pos
))
2332 dolog "error processing 'progress' %S: %s"
2333 cmds
(Printexc.to_string exn
);
2337 state.progress <- progress;
2338 G.postRedisplay "progress"
2341 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2343 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2344 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2345 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2347 dolog "error processing 'firstmatch' %S: %s"
2348 cmds
(Printexc.to_string exn
);
2351 let y = (getpagey pageno) + truncate
y0 in
2354 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2357 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2359 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2360 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2361 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2363 dolog "error processing 'match' %S: %s"
2364 cmds
(Printexc.to_string exn
);
2368 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2373 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2375 dolog "error processing 'page' %S: %s"
2376 cmds
(Printexc.to_string exn
);
2379 begin match state.currently
with
2380 | Loading
(l, gen
) ->
2381 vlog "page %d took %f sec" l.pageno t
;
2382 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2383 begin match state.throttle
with
2385 let preloadedpages =
2387 then preloadlayout state.y
2392 Set.Make
(struct type t
= int let compare = (-) end) in
2394 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2395 IntSet.empty
preloadedpages
2398 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2399 if not
(IntSet.mem
pageno set)
2401 wcmd "freepage %s" opaque
;
2407 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2410 state.currently
<- Idle
;
2413 tilepage l.pageno pageopaque state.layout;
2415 load preloadedpages;
2416 if pagevisible state.layout l.pageno
2417 && layoutready state.layout
2418 then G.postRedisplay "page";
2421 | Some
(layout, _, _) ->
2422 state.currently
<- Idle
;
2423 tilepage l.pageno pageopaque layout;
2428 dolog "Inconsistent loading state";
2429 logcurrently state.currently
;
2434 let (x, y, opaque
, size
, t
) =
2436 Scanf.sscanf
args "%u %u %s %u %f"
2437 (fun x y p size t
-> (x, y, p
, size
, t
))
2439 dolog "error processing 'tile' %S: %s"
2440 cmds
(Printexc.to_string exn
);
2443 begin match state.currently
with
2444 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2445 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2448 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2450 wcmd "freetile %s" opaque
;
2451 state.currently
<- Idle
;
2455 puttileopaque l col row gen cs angle opaque size t
;
2456 state.memused
<- state.memused
+ size
;
2457 state.uioh#infochanged Memused
;
2459 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2460 opaque
, size
) state.tilelru
;
2463 match state.throttle
with
2464 | None
-> state.layout
2465 | Some
(layout, _, _) -> layout
2468 state.currently
<- Idle
;
2470 && conf.colorspace
= cs
2471 && conf.angle
= angle
2472 && tilevisible layout l.pageno x y
2473 then conttiling l.pageno pageopaque;
2475 begin match state.throttle
with
2478 then state.wthack <- not
(layoutready state.layout);
2479 preload state.layout;
2481 && conf.colorspace
= cs
2482 && conf.angle
= angle
2483 && tilevisible state.layout l.pageno x y
2484 then G.postRedisplay "tile nothrottle";
2486 | Some
(layout, y, _) ->
2487 let ready = layoutready layout in
2490 state.wthack <- false;
2492 state.layout <- layout;
2493 state.throttle
<- None
;
2494 G.postRedisplay "throttle";
2501 dolog "Inconsistent tiling state";
2502 logcurrently state.currently
;
2509 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2511 dolog "error processing 'pdim' %S: %s"
2512 cmds
(Printexc.to_string exn
);
2515 state.uioh#infochanged Pdim
;
2516 state.pdims
<- pdim :: state.pdims
2519 let (l, n, t
, h, pos
) =
2521 Scanf.sscanf
args "%u %u %d %u %n"
2522 (fun l n t
h pos
-> l, n, t
, h, pos
)
2524 dolog "error processing 'o' %S: %s"
2525 cmds
(Printexc.to_string exn
);
2528 let s = String.sub
args pos
(String.length
args - pos
) in
2529 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2530 begin match state.currently
with
2531 | Outlining outlines
->
2532 state.currently
<- Outlining
(outline :: outlines
)
2534 state.currently
<- Outlining
[outline]
2536 dolog "invalid outlining state";
2537 logcurrently currently
2543 Scanf.sscanf
args "%u %u %d"
2544 (fun n t
h -> n, t
, h)
2546 dolog "error processing 'a' %S: %s"
2547 cmds
(Printexc.to_string exn
);
2551 if conf.presentation
2553 else float t
/. float h, 0.0
2555 state.anchor <- (n, top, dtop)
2558 state.docinfo
<- (1, args) :: state.docinfo
2561 state.uioh#infochanged Docinfo
;
2562 state.docinfo
<- List.rev
state.docinfo
2565 dolog "unknown cmd `%S'" cmds
2570 let action = function
2571 | HCprev
-> cbget cb ~
-1
2572 | HCnext
-> cbget cb
1
2573 | HCfirst
-> cbget cb ~
-(cb
.rc)
2574 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2575 and cancel
() = cb
.rc <- rc
2579 let search pattern forward
=
2580 if String.length pattern
> 0
2583 match state.layout with
2586 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2588 wcmd "search %d %d %d %d,%s\000"
2589 (btod conf.icase
) pn py
(btod forward
) pattern
;
2592 let intentry text key =
2594 if key >= 32 && key < 127
2600 let text = addchar text c in
2604 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2608 let linknentry text key =
2610 if key >= 32 && key < 127
2616 let text = addchar text c in
2620 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2625 if String.length
s > 0
2628 let l = String.length
s in
2629 let rec loop pos
n = if pos
= l then n else
2630 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2631 loop (pos
+1) (n*26 + m)
2634 let rec loop n = function
2637 match getopaque l.pageno with
2638 | None
-> loop n rest
2640 let m = getlinkcount opaque
in
2643 let under = getlink opaque
n in
2646 else loop (n-m) rest
2648 loop n state.layout;
2652 let textentry text key =
2653 if key land 0xff00 = 0xff00
2655 else TEcont
(text ^
Wsi.toutf8
key)
2658 let reqlayout angle proportional
=
2659 match state.throttle
with
2661 if nogeomcmds state.geomcmds
2662 then state.anchor <- getanchor ();
2663 conf.angle
<- angle
mod 360;
2666 match state.mode
with
2667 | LinkNav
_ -> state.mode
<- View
2670 conf.proportional
<- proportional
;
2671 invalidate "reqlayout"
2672 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2676 let settrim trimmargins trimfuzz
=
2677 if nogeomcmds state.geomcmds
2678 then state.anchor <- getanchor ();
2679 conf.trimmargins
<- trimmargins
;
2680 conf.trimfuzz
<- trimfuzz
;
2681 let x0, y0, x1, y1 = trimfuzz
in
2682 invalidate "settrim"
2684 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2689 match state.throttle
with
2691 let zoom = max
0.01 zoom in
2692 if zoom <> conf.zoom
2694 state.prevzoom
<- conf.zoom;
2696 reshape conf.winw
conf.winh
;
2697 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2700 | Some
(layout, y, started
) ->
2702 match conf.maxwait
with
2706 let dt = now () -. started
in
2714 let setcolumns mode columns coverA coverB
=
2715 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2719 then showtext '
!'
"split mode doesn't work in bird's eye"
2721 conf.columns
<- Csplit
(-columns
, [||]);
2729 conf.columns
<- Csingle
[||];
2734 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2738 reshape conf.winw
conf.winh
;
2741 let enterbirdseye () =
2742 let zoom = float conf.thumbw
/. float conf.winw
in
2743 let birdseyepageno =
2744 let cy = conf.winh
/ 2 in
2748 let rec fold best
= function
2751 let d = cy - (l.pagedispy + l.pagevh/2)
2752 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2753 if abs
d < abs dbest
2760 state.mode
<- Birdseye
(
2761 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2764 conf.presentation
<- false;
2765 conf.interpagespace
<- 10;
2766 conf.hlinks
<- false;
2768 state.mstate
<- Mnone
;
2769 conf.maxwait
<- None
;
2771 match conf.beyecolumns
with
2774 Cmulti
((c, 0, 0), [||])
2775 | None
-> Csingle
[||]
2777 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2780 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2785 reshape conf.winw
conf.winh
;
2788 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2790 conf.zoom <- c.zoom;
2791 conf.presentation
<- c.presentation
;
2792 conf.interpagespace
<- c.interpagespace
;
2793 conf.maxwait
<- c.maxwait
;
2794 conf.hlinks
<- c.hlinks
;
2795 conf.beyecolumns
<- (
2796 match conf.columns
with
2797 | Cmulti
((c, _, _), _) -> Some
c
2799 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2802 match c.columns
with
2803 | Cmulti
(c, _) -> Cmulti
(c, [||])
2804 | Csingle
_ -> Csingle
[||]
2805 | Csplit
(c, _) -> Csplit
(c, [||])
2810 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2813 reshape conf.winw
conf.winh
;
2814 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2817 let togglebirdseye () =
2818 match state.mode
with
2819 | Birdseye vals
-> leavebirdseye vals
true
2820 | View
-> enterbirdseye ()
2824 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2825 let pageno = max
0 (pageno - incr
) in
2826 let rec loop = function
2827 | [] -> gotopage1 pageno 0
2828 | l :: _ when l.pageno = pageno ->
2829 if l.pagedispy >= 0 && l.pagey = 0
2830 then G.postRedisplay "upbirdseye"
2831 else gotopage1 pageno 0
2832 | _ :: rest
-> loop rest
2835 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2838 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2839 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2840 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2841 let rec loop = function
2843 let y, h = getpageyh pageno in
2844 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace
) in
2846 | l :: _ when l.pageno = pageno ->
2847 if l.pagevh != l.pageh
2848 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2849 else G.postRedisplay "downbirdseye"
2850 | _ :: rest
-> loop rest
2855 let optentry mode
_ key =
2856 let btos b = if b then "on" else "off" in
2857 if key >= 32 && key < 127
2859 let c = Char.chr
key in
2863 try conf.scrollstep
<- int_of_string
s with exc
->
2864 state.text <- Printf.sprintf
"bad integer `%s': %s"
2865 s (Printexc.to_string exc
)
2867 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2872 conf.autoscrollstep
<- int_of_string
s;
2873 if state.autoscroll
<> None
2874 then state.autoscroll
<- Some
conf.autoscrollstep
2876 state.text <- Printf.sprintf
"bad integer `%s': %s"
2877 s (Printexc.to_string exc
)
2879 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2884 let n, a, b = multicolumns_of_string s in
2885 setcolumns mode
n a b;
2887 state.text <- Printf.sprintf
"bad columns `%s': %s"
2888 s (Printexc.to_string exc
)
2890 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2895 let zoom = float (int_of_string
s) /. 100.0 in
2898 state.text <- Printf.sprintf
"bad integer `%s': %s"
2899 s (Printexc.to_string exc
)
2901 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2906 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2908 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2909 begin match mode
with
2911 leavebirdseye beye
false;
2916 state.text <- Printf.sprintf
"bad integer `%s': %s"
2917 s (Printexc.to_string exc
)
2919 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2924 Some
(int_of_string
s)
2926 state.text <- Printf.sprintf
"bad integer `%s': %s"
2927 s (Printexc.to_string exc
);
2930 | Some angle
-> reqlayout angle
conf.proportional
2933 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2936 conf.icase
<- not
conf.icase
;
2937 TEdone
("case insensitive search " ^
(btos conf.icase
))
2940 conf.preload <- not
conf.preload;
2942 TEdone
("preload " ^
(btos conf.preload))
2945 conf.verbose
<- not
conf.verbose
;
2946 TEdone
("verbose " ^
(btos conf.verbose
))
2949 conf.debug
<- not
conf.debug
;
2950 TEdone
("debug " ^
(btos conf.debug
))
2953 conf.maxhfit
<- not
conf.maxhfit
;
2954 state.maxy
<- calcheight ();
2955 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2958 conf.crophack
<- not
conf.crophack
;
2959 TEdone
("crophack " ^
btos conf.crophack
)
2963 match conf.maxwait
with
2965 conf.maxwait
<- Some infinity
;
2966 "always wait for page to complete"
2968 conf.maxwait
<- None
;
2969 "show placeholder if page is not ready"
2974 conf.underinfo
<- not
conf.underinfo
;
2975 TEdone
("underinfo " ^
btos conf.underinfo
)
2978 conf.savebmarks
<- not
conf.savebmarks
;
2979 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2985 match state.layout with
2990 conf.interpagespace
<- int_of_string
s;
2991 docolumns conf.columns
;
2992 state.maxy
<- calcheight ();
2993 let y = getpagey pageno in
2996 state.text <- Printf.sprintf
"bad integer `%s': %s"
2997 s (Printexc.to_string exc
)
2999 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3002 reqlayout conf.angle
(not
conf.proportional
);
3003 TEdone
("proportional display " ^
btos conf.proportional
)
3006 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3007 TEdone
("trim margins " ^
btos conf.trimmargins
)
3010 conf.invert
<- not
conf.invert
;
3011 TEdone
("invert colors " ^
btos conf.invert
)
3015 cbput state.hists
.sel
s;
3018 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3019 textentry, ondone, true)
3022 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3028 class type lvsource
= object
3029 method getitemcount
: int
3030 method getitem
: int -> (string * int)
3031 method hasaction
: int -> bool
3040 method getactive
: int
3041 method getfirst
: int
3042 method getqsearch
: string
3043 method setqsearch
: string -> unit
3047 class virtual lvsourcebase
= object
3048 val mutable m_active
= 0
3049 val mutable m_first
= 0
3050 val mutable m_qsearch
= ""
3051 val mutable m_pan
= 0
3052 method getactive
= m_active
3053 method getfirst
= m_first
3054 method getqsearch
= m_qsearch
3055 method getpan
= m_pan
3056 method setqsearch
s = m_qsearch
<- s
3059 let withoutlastutf8 s =
3060 let len = String.length
s in
3068 let b = Char.code
s.[pos
] in
3069 if b land 0b11000000 = 0b11000000
3074 if Char.code
s.[len-1] land 0x80 = 0
3078 String.sub
s 0 first;
3081 let textentrykeyboard
3082 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3084 if key >= 0xffb0 && key <= 0xffb9
3085 then key - 0xffb0 + 48 else key
3088 state.mode
<- Textentry
(te
, onleave
);
3091 G.postRedisplay "textentrykeyboard enttext";
3093 let histaction cmd
=
3096 | Some
(action, _) ->
3097 state.mode
<- Textentry
(
3098 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3100 G.postRedisplay "textentry histaction"
3103 | 0xff08 -> (* backspace *)
3104 let s = withoutlastutf8 text in
3105 let len = String.length
s in
3106 if cancelonempty
&& len = 0
3109 G.postRedisplay "textentrykeyboard after cancel";
3112 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3115 | 0xff0d | 0xff8d -> (* (kp) enter *)
3118 G.postRedisplay "textentrykeyboard after confirm"
3120 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3121 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3122 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3123 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3125 | 0xff1b -> (* escape*)
3126 if String.length
text = 0
3128 begin match opthist
with
3130 | Some
(_, onhistcancel
) -> onhistcancel
()
3134 G.postRedisplay "textentrykeyboard after cancel2"
3137 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3140 | 0xff9f | 0xffff -> () (* delete *)
3143 && key land 0xff00 != 0xff00 (* keyboard *)
3144 && key land 0xfe00 != 0xfe00 (* xkb *)
3145 && key land 0xfd00 != 0xfd00 (* 3270 *)
3147 begin match onkey
text key with
3151 G.postRedisplay "textentrykeyboard after confirm2";
3154 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3158 G.postRedisplay "textentrykeyboard after cancel3"
3161 state.mode
<- Textentry
(te
, onleave
);
3162 G.postRedisplay "textentrykeyboard switch";
3166 vlog "unhandled key %s" (Wsi.keyname
key)
3169 let firstof first active
=
3170 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3171 then max
0 (active
- (fstate.maxrows
/2))
3175 let calcfirst first active
=
3178 let rows = active
- first in
3179 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3183 let scrollph y maxy
=
3184 let sh = (float (maxy
+ conf.winh
) /. float conf.winh
) in
3185 let sh = float conf.winh
/. sh in
3186 let sh = max
sh (float conf.scrollh
) in
3191 else float y /. float maxy
3193 let position = (float conf.winh
-. sh) *. percent in
3196 if position +. sh > float conf.winh
3197 then float conf.winh
-. sh
3203 let coe s = (s :> uioh
);;
3205 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3207 val m_pan
= source#getpan
3208 val m_first
= source#getfirst
3209 val m_active
= source#getactive
3210 val m_qsearch
= source#getqsearch
3211 val m_prev_uioh
= state.uioh
3213 method private elemunder
y =
3214 let n = y / (fstate.fontsize
+1) in
3215 if m_first
+ n < source#getitemcount
3217 if source#hasaction
(m_first
+ n)
3218 then Some
(m_first
+ n)
3225 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3226 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3227 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3228 GlDraw.color
(1., 1., 1.);
3229 Gl.enable `texture_2d
;
3230 let fs = fstate.fontsize
in
3232 let ww = fstate.wwidth
in
3233 let tabw = 30.0*.ww in
3234 let itemcount = source#getitemcount
in
3236 if (row - m_first
) > fstate.maxrows
3239 if row >= 0 && row < itemcount
3241 let (s, level
) = source#getitem
row in
3242 let y = (row - m_first
) * nfs in
3243 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3246 Gl.disable `texture_2d
;
3247 GlDraw.polygon_mode `both `line
;
3248 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3249 GlDraw.rect (1., float (y + 1))
3250 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3251 GlDraw.polygon_mode `both `fill
;
3252 GlDraw.color
(1., 1., 1.);
3253 Gl.enable `texture_2d
;
3256 let drawtabularstring s =
3257 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3260 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3263 let len = String.length
s - tabpos - 1 in
3264 let s1 = String.sub
s 0 tabpos
3265 and s2
= String.sub
s (tabpos + 1) len in
3266 let nx = drawstr x s1 in
3268 let x = x +. (max
tabw sw) in
3275 let _ = drawtabularstring s in
3282 Gl.disable `texture_2d
;
3284 method updownlevel incr
=
3285 let len = source#getitemcount
in
3287 if m_active
>= 0 && m_active
< len
3288 then snd
(source#getitem m_active
)
3292 if i
= len then i
-1 else if i
= -1 then 0 else
3293 let _, l = source#getitem i
in
3294 if l != curlevel then i
else flow (i
+incr
)
3296 let active = flow m_active
in
3297 let first = calcfirst m_first
active in
3298 G.postRedisplay "outline updownlevel";
3299 {< m_active
= active; m_first
= first >}
3301 method private key1
key mask
=
3302 let set1 active first qsearch
=
3303 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3305 let search active pattern incr
=
3308 if n >= 0 && n < source#getitemcount
3310 let s, _ = source#getitem
n in
3312 (try ignore
(Str.search_forward
re s 0); true
3313 with Not_found
-> false)
3315 else loop (n + incr
)
3322 let re = Str.regexp_case_fold pattern
in
3328 let itemcount = source#getitemcount
in
3329 let find start incr
=
3331 if i
= -1 || i
= itemcount
3334 if source#hasaction i
3336 else find (i
+ incr
)
3341 let set active first =
3342 let first = bound first 0 (itemcount - fstate.maxrows
) in
3344 coe {< m_active
= active; m_first
= first >}
3347 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3349 let incr1 = if incr
> 0 then 1 else -1 in
3350 if isvisible m_first m_active
3353 let next = m_active
+ incr
in
3355 if next < 0 || next >= itemcount
3357 else find next incr1
3359 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3365 let first = m_first
+ incr
in
3366 let first = bound first 0 (itemcount - 1) in
3368 let next = m_active
+ incr
in
3369 let next = bound next 0 (itemcount - 1) in
3372 let active = if next = -1 then m_active
else next in
3375 let first = min
next m_first
in
3377 if abs
(next - first) > fstate.maxrows
3383 let first = m_first
+ incr
in
3384 let first = bound first 0 (itemcount - 1) in
3386 let next = m_active
+ incr
in
3387 let next = bound next 0 (itemcount - 1) in
3388 let next = find next incr1 in
3390 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3392 let active = if m_active
= -1 then next else m_active
in
3397 if isvisible first active
3403 G.postRedisplay "listview navigate";
3407 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3408 let incr = if key = 0x72 then -1 else 1 in
3410 match search (m_active
+ incr) m_qsearch
incr with
3412 state.text <- m_qsearch ^
" [not found]";
3415 state.text <- m_qsearch
;
3416 active, firstof m_first
active
3418 G.postRedisplay "listview ctrl-r/s";
3419 set1 active first m_qsearch
;
3421 | 0xff08 -> (* backspace *)
3422 if String.length m_qsearch
= 0
3425 let qsearch = withoutlastutf8 m_qsearch
in
3426 let len = String.length
qsearch in
3430 G.postRedisplay "listview empty qsearch";
3431 set1 m_active m_first
"";
3435 match search m_active
qsearch ~
-1 with
3437 state.text <- qsearch ^
" [not found]";
3440 state.text <- qsearch;
3441 active, firstof m_first
active
3443 G.postRedisplay "listview backspace qsearch";
3444 set1 active first qsearch
3447 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3448 let pattern = m_qsearch ^
Wsi.toutf8
key in
3450 match search m_active
pattern 1 with
3452 state.text <- pattern ^
" [not found]";
3455 state.text <- pattern;
3456 active, firstof m_first
active
3458 G.postRedisplay "listview qsearch add";
3459 set1 active first pattern;
3461 | 0xff1b -> (* escape *)
3463 if String.length m_qsearch
= 0
3465 G.postRedisplay "list view escape";
3468 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3470 | None
-> m_prev_uioh
3475 G.postRedisplay "list view kill qsearch";
3476 source#setqsearch
"";
3477 coe {< m_qsearch
= "" >}
3480 | 0xff0d | 0xff8d -> (* (kp) enter *)
3482 let self = {< m_qsearch
= "" >} in
3483 source#setqsearch
"";
3485 G.postRedisplay "listview enter";
3486 if m_active
>= 0 && m_active
< source#getitemcount
3488 source#exit
(coe self) false m_active m_first m_pan
"";
3491 source#exit
(coe self) true m_active m_first m_pan
"";
3494 begin match opt with
3495 | None
-> m_prev_uioh
3499 | 0xff9f | 0xffff -> (* (kp) delete *)
3502 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3503 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3504 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3505 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3507 | 0xff53 | 0xff98 -> (* (kp) right *)
3509 G.postRedisplay "listview right";
3510 coe {< m_pan
= m_pan
- 1 >}
3512 | 0xff51 | 0xff96 -> (* (kp) left *)
3514 G.postRedisplay "listview left";
3515 coe {< m_pan
= m_pan
+ 1 >}
3517 | 0xff50 | 0xff95 -> (* (kp) home *)
3518 let active = find 0 1 in
3519 G.postRedisplay "listview home";
3522 | 0xff57 | 0xff9c -> (* (kp) end *)
3523 let first = max
0 (itemcount - fstate.maxrows
) in
3524 let active = find (itemcount - 1) ~
-1 in
3525 G.postRedisplay "listview end";
3528 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3532 dolog "listview unknown key %#x" key; coe self
3534 method key key mask
=
3535 match state.mode
with
3536 | Textentry te
-> textentrykeyboard key mask te
; coe self
3537 | _ -> self#key1
key mask
3539 method button button down
x y _ =
3542 | 1 when x > conf.winw
- conf.scrollbw
->
3543 G.postRedisplay "listview scroll";
3546 let _, position, sh = self#
scrollph in
3547 if y > truncate
position && y < truncate
(position +. sh)
3549 state.mstate
<- Mscrolly
;
3553 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3554 let first = truncate
(s *. float source#getitemcount
) in
3555 let first = min source#getitemcount
first in
3556 Some
(coe {< m_first
= first; m_active
= first >})
3558 state.mstate
<- Mnone
;
3561 | 1 when not down
->
3562 begin match self#elemunder
y with
3564 G.postRedisplay "listview click";
3566 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3570 | n when (n == 4 || n == 5) && not down
->
3571 let len = source#getitemcount
in
3573 if n = 5 && m_first
+ fstate.maxrows
>= len
3577 let first = m_first
+ (if n == 4 then -1 else 1) in
3578 bound first 0 (len - 1)
3580 G.postRedisplay "listview wheel";
3581 Some
(coe {< m_first
= first >})
3582 | n when (n = 6 || n = 7) && not down
->
3583 let inc = m_first
+ (if n = 7 then -1 else 1) in
3584 G.postRedisplay "listview hwheel";
3585 Some
(coe {< m_pan
= m_pan
+ inc >})
3590 | None
-> m_prev_uioh
3594 match state.mstate
with
3596 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3597 let first = truncate
(s *. float source#getitemcount
) in
3598 let first = min source#getitemcount
first in
3599 G.postRedisplay "listview motion";
3600 coe {< m_first
= first; m_active
= first >}
3603 method pmotion
x y =
3604 if x < conf.winw
- conf.scrollbw
3607 match self#elemunder
y with
3608 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3609 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3613 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3618 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3622 method infochanged
_ = ()
3624 method scrollpw
= (0, 0.0, 0.0)
3626 let nfs = fstate.fontsize
+ 1 in
3627 let y = m_first
* nfs in
3628 let itemcount = source#getitemcount
in
3629 let maxi = max
0 (itemcount - fstate.maxrows
) in
3630 let maxy = maxi * nfs in
3631 let p, h = scrollph y maxy in
3634 method modehash
= modehash
3637 class outlinelistview ~source
=
3640 ~source
:(source
:> lvsource
)
3642 ~modehash
:(findkeyhash conf "outline")
3645 method key key mask
=
3646 let calcfirst first active =
3649 let rows = active - first in
3651 if String.length
state.text = 0
3653 else fstate.maxrows - 2
3655 if rows > maxrows then active - maxrows else first
3659 let active = m_active
+ incr in
3660 let active = bound active 0 (source#getitemcount
- 1) in
3661 let first = calcfirst m_first
active in
3662 G.postRedisplay "outline navigate";
3663 coe {< m_active
= active; m_first
= first >}
3665 let ctrl = Wsi.withctrl mask
in
3667 | 110 when ctrl -> (* ctrl-n *)
3668 source#narrow m_qsearch
;
3669 G.postRedisplay "outline ctrl-n";
3670 coe {< m_first
= 0; m_active
= 0 >}
3672 | 117 when ctrl -> (* ctrl-u *)
3674 G.postRedisplay "outline ctrl-u";
3676 coe {< m_first
= 0; m_active
= 0 >}
3678 | 108 when ctrl -> (* ctrl-l *)
3679 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3680 G.postRedisplay "outline ctrl-l";
3681 coe {< m_first
= first >}
3683 | 0xff9f | 0xffff -> (* (kp) delete *)
3684 source#remove m_active
;
3685 G.postRedisplay "outline delete";
3686 let active = max
0 (m_active
-1) in
3687 coe {< m_first
= firstof m_first
active;
3688 m_active
= active >}
3690 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3691 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3692 | 0xff55 | 0xff9a -> (* (kp) prior *)
3693 navigate ~
-(fstate.maxrows)
3694 | 0xff56 | 0xff9b -> (* (kp) next *)
3695 navigate fstate.maxrows
3697 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3701 G.postRedisplay "outline ctrl right";
3702 {< m_pan
= m_pan
+ 1 >}
3704 else self#updownlevel
1
3708 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3712 G.postRedisplay "outline ctrl left";
3713 {< m_pan
= m_pan
- 1 >}
3715 else self#updownlevel ~
-1
3719 | 0xff50 | 0xff95 -> (* (kp) home *)
3720 G.postRedisplay "outline home";
3721 coe {< m_first
= 0; m_active
= 0 >}
3723 | 0xff57 | 0xff9c -> (* (kp) end *)
3724 let active = source#getitemcount
- 1 in
3725 let first = max
0 (active - fstate.maxrows) in
3726 G.postRedisplay "outline end";
3727 coe {< m_active
= active; m_first
= first >}
3729 | _ -> super#
key key mask
3732 let outlinesource usebookmarks
=
3735 inherit lvsourcebase
3736 val mutable m_items
= empty
3737 val mutable m_orig_items
= empty
3738 val mutable m_prev_items
= empty
3739 val mutable m_narrow_pattern
= ""
3740 val mutable m_hadremovals
= false
3742 method getitemcount
=
3743 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3746 if n == Array.length m_items
&& m_hadremovals
3748 ("[Confirm removal]", 0)
3750 let s, n, _ = m_items
.(n) in
3753 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3754 ignore
(uioh
, first, qsearch);
3755 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3757 if String.length m_narrow_pattern
= 0
3763 if not
confrimremoval
3765 let _, _, anchor = m_items
.(active) in
3766 gotoghyll (getanchory anchor);
3770 state.bookmarks
<- Array.to_list m_items
;
3771 m_orig_items
<- m_items
;
3774 else m_items
<- items;
3778 method hasaction
_ = true
3781 if Array.length m_items
!= Array.length m_orig_items
3782 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3785 method narrow
pattern =
3786 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3790 let rec loop accu n =
3793 m_narrow_pattern
<- pattern;
3794 m_items
<- Array.of_list
accu
3797 let (s, _, _) as o = m_items
.(n) in
3799 if (try ignore
(Str.search_forward
re s 0); true
3800 with Not_found
-> false)
3806 loop [] (Array.length m_items
- 1)
3811 then Array.of_list
state.bookmarks
3814 m_items
<- m_orig_items
3819 if m >= 0 && m < Array.length m_items
3821 m_hadremovals
<- true;
3822 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3823 let n = if n >= m then n+1 else n in
3828 method reset
anchor items =
3829 m_hadremovals
<- false;
3830 if m_orig_items
== empty || m_prev_items
!= items
3832 m_orig_items
<- items;
3833 if String.length m_narrow_pattern
= 0
3834 then m_items
<- items;
3836 m_prev_items
<- items;
3837 let rely = getanchory anchor in
3839 let rec loop n best bestd
=
3840 if n = Array.length m_items
3843 let (_, _, anchor) = m_items
.(n) in
3844 let orely = getanchory anchor in
3845 let d = abs
(orely - rely) in
3848 else loop (n+1) best bestd
3853 m_first
<- firstof m_first
active
3857 let enterselector usebookmarks
=
3858 let source = outlinesource usebookmarks
in
3862 then Array.of_list
state.bookmarks
3865 if Array.length
outlines = 0
3867 showtext ' ' errmsg
;
3870 state.text <- source#greetmsg
;
3871 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3872 let anchor = getanchor () in
3873 source#reset
anchor outlines;
3874 state.uioh
<- coe (new outlinelistview ~
source);
3875 G.postRedisplay "enter selector";
3879 let enteroutlinemode =
3880 let f = enterselector false in
3881 fun ()-> f "Document has no outline";
3884 let enterbookmarkmode =
3885 let f = enterselector true in
3886 fun () -> f "Document has no bookmarks (yet)";
3889 let color_of_string s =
3890 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
3891 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
3895 let color_to_string (r, g, b) =
3896 let r = truncate
(r *. 256.0)
3897 and g = truncate
(g *. 256.0)
3898 and b = truncate
(b *. 256.0) in
3899 Printf.sprintf
"%d/%d/%d" r g b
3902 let irect_of_string s =
3903 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3906 let irect_to_string (x0,y0,x1,y1) =
3907 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3910 let makecheckers () =
3911 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3913 converted by Issac Trotts. July 25, 2002 *)
3914 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
3915 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
3916 let id = GlTex.gen_texture
() in
3917 GlTex.bind_texture `texture_2d
id;
3918 GlPix.store
(`unpack_alignment
1);
3919 GlTex.image2d
image;
3920 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3921 [ `mag_filter `nearest
; `min_filter `nearest
];
3925 let setcheckers enabled
=
3926 match state.texid
with
3928 if enabled
then state.texid
<- Some
(makecheckers ())
3933 GlTex.delete_texture texid
;
3934 state.texid
<- None
;
3938 let int_of_string_with_suffix s =
3939 let l = String.length
s in
3943 let suffix = Char.lowercase
s.[l-1] in
3945 | 'k'
-> String.sub
s 0 (l-1), 10
3946 | '
m'
-> String.sub
s 0 (l-1), 20
3947 | '
g'
-> String.sub
s 0 (l-1), 30
3951 let n = int_of_string
s1 in
3952 let m = n lsl shift
in
3954 then raise
(Failure
"value too large")
3958 let string_with_suffix_of_int n =
3963 if n land ((1 lsl 30) - 1) = 0
3966 if n land ((1 lsl 20) - 1) = 0
3969 if n land ((1 lsl 10) - 1) = 0
3976 let h = n mod 1000 in
3979 then string_of_int
h ^
s
3981 let s = Printf.sprintf
"_%03d%s" h s in
3988 let defghyllscroll = (40, 8, 32);;
3989 let ghyllscroll_of_string s =
3990 let (n, a, b) as nab
=
3993 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3995 if n <= a || n <= b || a >= b
3996 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4000 let ghyllscroll_to_string ((n, a, b) as nab
) =
4001 if nab
= defghyllscroll
4003 else Printf.sprintf
"%d,%d,%d" n a b;
4006 let describe_location () =
4008 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
4010 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
4011 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4015 else (100. *. (float state.y /. float maxy))
4019 Printf.sprintf
"page %d of %d [%.2f%%]"
4020 (fn+1) state.pagecount
percent
4023 "pages %d-%d of %d [%.2f%%]"
4024 (fn+1) (ln
+1) state.pagecount
percent
4027 let setpresentationmode v
=
4028 let (n, _, _) = getanchor () in
4029 let _, h = getpageyh n in
4030 let ips = if conf.presentation
then calcips h else conf.interpagespace
in
4031 state.anchor <- (n, 0.0, float ips);
4032 conf.presentation
<- v
;
4033 if conf.presentation
4035 if not
conf.scrollbarinpm
4036 then state.scrollw
<- 0;
4038 else state.scrollw
<- conf.scrollbw
;
4043 let btos b = if b then "\xe2\x88\x9a" else "" in
4044 let showextended = ref false in
4045 let leave mode
= function
4046 | Confirm
-> state.mode
<- mode
4047 | Cancel
-> state.mode
<- mode
in
4050 val mutable m_first_time
= true
4051 val mutable m_l
= []
4052 val mutable m_a
= [||]
4053 val mutable m_prev_uioh
= nouioh
4054 val mutable m_prev_mode
= View
4056 inherit lvsourcebase
4058 method reset prev_mode prev_uioh
=
4059 m_a
<- Array.of_list
(List.rev m_l
);
4061 m_prev_mode
<- prev_mode
;
4062 m_prev_uioh
<- prev_uioh
;
4066 if n >= Array.length m_a
4070 | _, _, _, Action
_ -> m_active
<- n
4074 m_first_time
<- false;
4077 method int name get
set =
4079 (name
, `
int get
, 1, Action
(
4082 try set (int_of_string
s)
4084 state.text <- Printf.sprintf
"bad integer `%s': %s"
4085 s (Printexc.to_string exn
)
4088 let te = name ^
": ", "", None
, intentry, ondone, true in
4089 state.mode
<- Textentry
(te, leave m_prev_mode
);
4093 method int_with_suffix name get
set =
4095 (name
, `intws get
, 1, Action
(
4098 try set (int_of_string_with_suffix s)
4100 state.text <- Printf.sprintf
"bad integer `%s': %s"
4101 s (Printexc.to_string exn
)
4105 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4107 state.mode
<- Textentry
(te, leave m_prev_mode
);
4111 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4113 (name
, `
bool (btos, get
), offset
, Action
(
4120 method color name get
set =
4122 (name
, `color get
, 1, Action
(
4124 let invalid = (nan
, nan
, nan
) in
4127 try color_of_string s
4129 state.text <- Printf.sprintf
"bad color `%s': %s"
4130 s (Printexc.to_string exn
);
4136 let te = name ^
": ", "", None
, textentry, ondone, true in
4137 state.text <- color_to_string (get
());
4138 state.mode
<- Textentry
(te, leave m_prev_mode
);
4142 method string name get
set =
4144 (name
, `
string get
, 1, Action
(
4146 let ondone s = set s in
4147 let te = name ^
": ", "", None
, textentry, ondone, true in
4148 state.mode
<- Textentry
(te, leave m_prev_mode
);
4152 method colorspace name get
set =
4154 (name
, `
string get
, 1, Action
(
4157 let vals = [| "rgb"; "bgr"; "gray" |] in
4159 inherit lvsourcebase
4162 m_active
<- int_of_colorspace conf.colorspace
;
4165 method getitemcount
= Array.length
vals
4166 method getitem
n = (vals.(n), 0)
4167 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4168 ignore
(uioh
, first, pan
, qsearch);
4169 if not cancel
then set active;
4171 method hasaction
_ = true
4175 let modehash = findkeyhash conf "info" in
4176 coe (new listview ~
source ~trusted
:true ~
modehash)
4179 method caption
s offset
=
4180 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4182 method caption2
s f offset
=
4183 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4185 method getitemcount
= Array.length m_a
4188 let tostr = function
4189 | `
int f -> string_of_int
(f ())
4190 | `intws
f -> string_with_suffix_of_int (f ())
4192 | `color
f -> color_to_string (f ())
4193 | `
bool (btos, f) -> btos (f ())
4196 let name, t
, offset
, _ = m_a
.(n) in
4197 ((let s = tostr t
in
4198 if String.length
s > 0
4199 then Printf.sprintf
"%s\t%s" name s
4203 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4207 m_qsearch
<- qsearch;
4209 match m_a
.(active) with
4210 | _, _, _, Action
f -> f uioh
4222 method hasaction
n =
4224 | _, _, _, Action
_ -> true
4228 let rec fillsrc prevmode prevuioh
=
4229 let sep () = src#caption
"" 0 in
4230 let colorp name get
set =
4232 (fun () -> color_to_string (get
()))
4235 let c = color_of_string v in
4238 state.text <- Printf.sprintf
"bad color `%s': %s"
4239 v (Printexc.to_string exn
);
4242 let oldmode = state.mode
in
4243 let birdseye = isbirdseye state.mode
in
4245 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4247 src#
bool "presentation mode"
4248 (fun () -> conf.presentation
)
4249 (fun v -> setpresentationmode v);
4251 src#
bool "ignore case in searches"
4252 (fun () -> conf.icase
)
4253 (fun v -> conf.icase
<- v);
4256 (fun () -> conf.preload)
4257 (fun v -> conf.preload <- v);
4259 src#
bool "highlight links"
4260 (fun () -> conf.hlinks
)
4261 (fun v -> conf.hlinks
<- v);
4263 src#
bool "under info"
4264 (fun () -> conf.underinfo
)
4265 (fun v -> conf.underinfo
<- v);
4267 src#
bool "persistent bookmarks"
4268 (fun () -> conf.savebmarks
)
4269 (fun v -> conf.savebmarks
<- v);
4271 src#
bool "proportional display"
4272 (fun () -> conf.proportional
)
4273 (fun v -> reqlayout conf.angle
v);
4275 src#
bool "trim margins"
4276 (fun () -> conf.trimmargins
)
4277 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4279 src#
bool "persistent location"
4280 (fun () -> conf.jumpback
)
4281 (fun v -> conf.jumpback
<- v);
4284 src#
int "inter-page space"
4285 (fun () -> conf.interpagespace
)
4287 conf.interpagespace
<- n;
4288 docolumns conf.columns
;
4290 match state.layout with
4295 state.maxy <- calcheight ();
4296 let y = getpagey pageno in
4301 (fun () -> conf.pagebias
)
4302 (fun v -> conf.pagebias
<- v);
4304 src#
int "scroll step"
4305 (fun () -> conf.scrollstep
)
4306 (fun n -> conf.scrollstep
<- n);
4308 src#
int "horizontal scroll step"
4309 (fun () -> conf.hscrollstep
)
4310 (fun v -> conf.hscrollstep
<- v);
4312 src#
int "auto scroll step"
4314 match state.autoscroll
with
4316 | _ -> conf.autoscrollstep
)
4318 if state.autoscroll
<> None
4319 then state.autoscroll
<- Some
n;
4320 conf.autoscrollstep
<- n);
4323 (fun () -> truncate
(conf.zoom *. 100.))
4324 (fun v -> setzoom ((float v) /. 100.));
4327 (fun () -> conf.angle
)
4328 (fun v -> reqlayout v conf.proportional
);
4330 src#
int "scroll bar width"
4331 (fun () -> state.scrollw
)
4335 reshape conf.winw
conf.winh
;
4338 src#
int "scroll handle height"
4339 (fun () -> conf.scrollh
)
4340 (fun v -> conf.scrollh
<- v;);
4342 src#
int "thumbnail width"
4343 (fun () -> conf.thumbw
)
4345 conf.thumbw
<- min
4096 v;
4348 leavebirdseye beye
false;
4353 let mode = state.mode in
4354 src#
string "columns"
4356 match conf.columns
with
4358 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4359 | Csplit
(count
, _) -> "-" ^ string_of_int count
4362 let n, a, b = multicolumns_of_string v in
4363 setcolumns mode n a b);
4366 src#caption
"Presentation mode" 0;
4367 src#
bool "scrollbar visible"
4368 (fun () -> conf.scrollbarinpm
)
4370 if v != conf.scrollbarinpm
4372 conf.scrollbarinpm
<- v;
4373 if conf.presentation
4375 state.scrollw
<- if v then conf.scrollbw
else 0;
4376 reshape conf.winw
conf.winh
;
4382 src#caption
"Pixmap cache" 0;
4383 src#int_with_suffix
"size (advisory)"
4384 (fun () -> conf.memlimit
)
4385 (fun v -> conf.memlimit
<- v);
4388 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4389 (string_with_suffix_of_int state.memused
)
4390 (Hashtbl.length
state.tilemap
)) 1;
4393 src#caption
"Layout" 0;
4394 src#caption2
"Dimension"
4396 Printf.sprintf
"%dx%d (virtual %dx%d)"
4402 src#caption2
"Position" (fun () ->
4403 Printf.sprintf
"%dx%d" state.x state.y
4406 src#caption2
"Visible" (fun () -> describe_location ()) 1
4410 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4411 "Save these parameters as global defaults at exit"
4412 (fun () -> conf.bedefault
)
4413 (fun v -> conf.bedefault
<- v)
4417 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4418 src#
bool ~offset
:0 ~
btos "Extended parameters"
4419 (fun () -> !showextended)
4420 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4424 (fun () -> conf.checkers
)
4425 (fun v -> conf.checkers
<- v; setcheckers v);
4426 src#
bool "update cursor"
4427 (fun () -> conf.updatecurs
)
4428 (fun v -> conf.updatecurs
<- v);
4430 (fun () -> conf.verbose
)
4431 (fun v -> conf.verbose
<- v);
4432 src#
bool "invert colors"
4433 (fun () -> conf.invert
)
4434 (fun v -> conf.invert
<- v);
4436 (fun () -> conf.maxhfit
)
4437 (fun v -> conf.maxhfit
<- v);
4438 src#
bool "redirect stderr"
4439 (fun () -> conf.redirectstderr)
4440 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4441 src#
string "uri launcher"
4442 (fun () -> conf.urilauncher
)
4443 (fun v -> conf.urilauncher
<- v);
4444 src#
string "path launcher"
4445 (fun () -> conf.pathlauncher
)
4446 (fun v -> conf.pathlauncher
<- v);
4447 src#
string "tile size"
4448 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4451 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4452 conf.tilew
<- max
64 w;
4453 conf.tileh
<- max
64 h;
4456 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4457 v (Printexc.to_string exn
));
4458 src#
int "texture count"
4459 (fun () -> conf.texcount
)
4462 then conf.texcount
<- v
4463 else showtext '
!'
" Failed to set texture count please retry later"
4465 src#
int "slice height"
4466 (fun () -> conf.sliceheight
)
4468 conf.sliceheight
<- v;
4469 wcmd "sliceh %d" conf.sliceheight
;
4471 src#
int "anti-aliasing level"
4472 (fun () -> conf.aalevel
)
4474 conf.aalevel
<- bound v 0 8;
4475 state.anchor <- getanchor ();
4476 opendoc state.path
state.password
;
4478 src#
string "page scroll scaling factor"
4479 (fun () -> string_of_float
conf.pgscale)
4482 let s = float_of_string
v in
4485 state.text <- Printf.sprintf
4486 "bad page scroll scaling factor `%s': %s"
4487 v (Printexc.to_string exn
)
4490 src#
int "ui font size"
4491 (fun () -> fstate.fontsize
)
4492 (fun v -> setfontsize (bound v 5 100));
4493 src#
int "hint font size"
4494 (fun () -> conf.hfsize
)
4495 (fun v -> conf.hfsize
<- bound v 5 100);
4496 colorp "background color"
4497 (fun () -> conf.bgcolor
)
4498 (fun v -> conf.bgcolor
<- v);
4499 src#
bool "crop hack"
4500 (fun () -> conf.crophack
)
4501 (fun v -> conf.crophack
<- v);
4502 src#
string "trim fuzz"
4503 (fun () -> irect_to_string conf.trimfuzz
)
4506 conf.trimfuzz
<- irect_of_string v;
4508 then settrim true conf.trimfuzz
;
4510 state.text <- Printf.sprintf
"bad irect `%s': %s"
4511 v (Printexc.to_string exn
)
4513 src#
string "throttle"
4515 match conf.maxwait
with
4516 | None
-> "show place holder if page is not ready"
4519 then "wait for page to fully render"
4521 "wait " ^ string_of_float
time
4522 ^
" seconds before showing placeholder"
4526 let f = float_of_string
v in
4528 then conf.maxwait
<- None
4529 else conf.maxwait
<- Some
f
4531 state.text <- Printf.sprintf
"bad time `%s': %s"
4532 v (Printexc.to_string exn
)
4534 src#
string "ghyll scroll"
4536 match conf.ghyllscroll
with
4538 | Some nab
-> ghyllscroll_to_string nab
4543 if String.length
v = 0
4545 else Some
(ghyllscroll_of_string v)
4547 conf.ghyllscroll
<- gs
4549 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4550 v (Printexc.to_string exn
)
4552 src#
string "selection command"
4553 (fun () -> conf.selcmd
)
4554 (fun v -> conf.selcmd
<- v);
4555 src#
string "synctex command"
4556 (fun () -> conf.stcmd
)
4557 (fun v -> conf.stcmd
<- v);
4558 src#colorspace
"color space"
4559 (fun () -> colorspace_to_string conf.colorspace
)
4561 conf.colorspace
<- colorspace_of_int v;
4568 (fun () -> conf.usepbo
)
4569 (fun v -> conf.usepbo
<- v);
4570 src#
bool "mouse wheel scrolls pages"
4571 (fun () -> conf.wheelbypage
)
4572 (fun v -> conf.wheelbypage
<- v);
4576 src#caption
"Document" 0;
4577 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4578 src#caption2
"Pages"
4579 (fun () -> string_of_int
state.pagecount
) 1;
4580 src#caption2
"Dimensions"
4581 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4585 src#caption
"Trimmed margins" 0;
4586 src#caption2
"Dimensions"
4587 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4591 src#caption
"OpenGL" 0;
4592 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4593 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4594 src#reset prevmode prevuioh
;
4598 let prevmode = state.mode
4599 and prevuioh
= state.uioh in
4600 fillsrc prevmode prevuioh
;
4601 let source = (src :> lvsource
) in
4602 let modehash = findkeyhash conf "info" in
4603 state.uioh <- coe (object (self)
4604 inherit listview ~
source ~trusted
:true ~
modehash as super
4605 val mutable m_prevmemused
= 0
4606 method infochanged
= function
4608 if m_prevmemused
!= state.memused
4610 m_prevmemused
<- state.memused
;
4611 G.postRedisplay "memusedchanged";
4613 | Pdim
-> G.postRedisplay "pdimchanged"
4614 | Docinfo
-> fillsrc prevmode prevuioh
4616 method key key mask
=
4617 if not
(Wsi.withctrl mask
)
4620 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4621 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4622 | _ -> super#
key key mask
4623 else super#
key key mask
4625 G.postRedisplay "info";
4631 inherit lvsourcebase
4632 method getitemcount
= Array.length
state.help
4634 let s, l, _ = state.help
.(n) in
4637 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4641 m_qsearch
<- qsearch;
4642 match state.help
.(active) with
4643 | _, _, Action
f -> Some
(f uioh)
4653 method hasaction
n =
4654 match state.help
.(n) with
4655 | _, _, Action
_ -> true
4662 let modehash = findkeyhash conf "help" in
4663 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4664 G.postRedisplay "help";
4669 let re = Str.regexp
"[\r\n]" in
4671 inherit lvsourcebase
4672 val mutable m_items
= [||]
4674 method getitemcount
= 1 + Array.length m_items
4679 else m_items
.(n-1), 0
4681 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4686 then Buffer.clear
state.errmsgs
;
4687 m_qsearch
<- qsearch;
4694 method hasaction
n =
4698 state.newerrmsgs
<- false;
4699 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4700 m_items
<- Array.of_list
l
4708 let source = (msgsource :> lvsource
) in
4709 let modehash = findkeyhash conf "listview" in
4710 state.uioh <- coe (object
4711 inherit listview ~
source ~trusted
:false ~
modehash as super
4714 then msgsource#reset
;
4717 G.postRedisplay "msgs";
4720 let quickbookmark ?title
() =
4721 match state.layout with
4727 let sec = Unix.gettimeofday
() in
4728 let tm = Unix.localtime
sec in
4729 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4733 (tm.Unix.tm_year
+ 1900)
4736 | Some
title -> title
4738 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4742 state.fullscreen
<- None
;
4746 let setautoscrollspeed step goingdown
=
4747 let incr = max
1 ((abs step
) / 2) in
4748 let incr = if goingdown
then incr else -incr in
4749 let astep = step
+ incr in
4750 state.autoscroll
<- Some
astep;
4753 let gotounder = function
4754 | Ulinkgoto
(pageno, top) ->
4758 gotopage1 pageno top;
4764 | Uremote
(filename
, pageno) ->
4766 if Sys.file_exists filename
4769 let dir = Filename.dirname
state.path in
4770 let path = Filename.concat
dir filename
in
4771 if Sys.file_exists
path
4775 if String.length
path > 0
4777 let anchor = getanchor () in
4778 let ranchor = state.path, state.password
, anchor in
4779 state.anchor <- (pageno, 0.0, 0.0);
4780 state.ranchors
<- ranchor :: state.ranchors
;
4783 else showtext '
!'
("Could not find " ^ filename
)
4785 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4789 match conf.columns
with
4791 | _ -> conf.zoom > 1.0
4794 let existsinrow pageno (columns
, coverA
, coverB
) p =
4795 let last = ((pageno - coverA
) mod columns
) + columns
in
4796 let rec any = function
4799 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4803 then (if l.pageno = last then false else any rest
)
4811 match state.layout with
4814 match conf.columns
with
4816 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4818 let y = clamp (pgscale conf.winh
) in
4821 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4822 gotoghyll (getpagey pageno)
4823 | Cmulti
((c, _, _) as cl
, _) ->
4824 if conf.presentation
4825 && (existsinrow l.pageno cl
4826 (fun l -> l.pageh
> l.pagey + l.pagevh))
4828 let y = clamp (pgscale conf.winh
) in
4831 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4832 gotoghyll (getpagey pageno)
4834 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4836 let pagey, pageh
= getpageyh l.pageno in
4837 let pagey = pagey + pageh
* l.pagecol
in
4838 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4839 gotoghyll (pagey + pageh
+ ips)
4843 match state.layout with
4846 match conf.columns
with
4848 if conf.presentation
&& l.pagey != 0
4850 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4852 let pageno = max
0 (l.pageno-1) in
4853 gotoghyll (getpagey pageno)
4854 | Cmulti
((c, _, coverB
) as cl
, _) ->
4855 if conf.presentation
&&
4856 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
4858 gotoghyll (clamp (pgscale ~
-(conf.winh
)))
4861 if l.pageno = state.pagecount
- coverB
4865 let pageno = max
0 (l.pageno-decr) in
4866 gotoghyll (getpagey pageno)
4874 let pageno = max
0 (l.pageno-1) in
4875 let pagey, pageh
= getpageyh pageno in
4878 let pagey, pageh
= getpageyh l.pageno in
4879 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
4884 let viewkeyboard key mask
=
4886 let mode = state.mode in
4887 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4890 G.postRedisplay "view:enttext"
4892 let ctrl = Wsi.withctrl mask
in
4894 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
4900 | 0xff63 -> (* insert *)
4901 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
4903 state.mode <- LinkNav
(Ltgendir
0);
4906 else showtext '
!'
"Keyboard link navigation does not work under rotation"
4908 | 0xff1b | 113 -> (* escape / q *)
4909 begin match state.mstate
with
4911 state.mstate
<- Mnone
;
4912 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4913 G.postRedisplay "kill zoom rect";
4915 begin match state.mode with
4918 G.postRedisplay "esc leave linknav"
4920 match state.ranchors
with
4922 | (path, password
, anchor) :: rest
->
4923 state.ranchors
<- rest
;
4924 state.anchor <- anchor;
4925 opendoc path password
4929 | 0xff08 -> (* backspace *)
4930 gotoghyll (getnav ~
-1)
4938 G.postRedisplay "dehighlight";
4940 | 47 | 63 -> (* / ? *)
4941 let ondone isforw
s =
4942 cbput state.hists
.pat
s;
4943 state.searchpattern
<- s;
4946 let s = String.create
1 in
4947 s.[0] <- Char.chr
key;
4948 enttext (s, "", Some
(onhist state.hists
.pat
),
4949 textentry, ondone (key = 47), true)
4951 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
4952 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4953 setzoom (conf.zoom +. incr)
4955 | 43 | 0xffab -> (* + *)
4958 try int_of_string
s with exc
->
4959 state.text <- Printf.sprintf
"bad integer `%s': %s"
4960 s (Printexc.to_string exc
);
4966 state.text <- "page bias is now " ^ string_of_int
n;
4969 enttext ("page bias: ", "", None
, intentry, ondone, true)
4971 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4972 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4973 setzoom (max
0.01 (conf.zoom -. decr))
4975 | 45 | 0xffad -> (* - *)
4976 let ondone msg
= state.text <- msg
in
4978 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4979 optentry state.mode, ondone, true
4982 | 48 when ctrl -> (* ctrl-0 *)
4985 | 49 when ctrl -> (* ctrl-1 *)
4987 match conf.columns
with
4988 | Csingle
_ | Cmulti
_ -> 1
4989 | Csplit
(n, _) -> n
4991 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
cols in
4995 | 0xffc6 -> (* f9 *)
4998 | 57 when ctrl -> (* ctrl-9 *)
5001 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5002 when not
ctrl -> (* 0..9 *)
5005 try int_of_string
s with exc
->
5006 state.text <- Printf.sprintf
"bad integer `%s': %s"
5007 s (Printexc.to_string exc
);
5013 cbput state.hists
.pag
(string_of_int
n);
5014 gotopage1 (n + conf.pagebias
- 1) 0;
5017 let pageentry text key =
5018 match Char.unsafe_chr
key with
5019 | '
g'
-> TEdone
text
5020 | _ -> intentry text key
5022 let text = "x" in text.[0] <- Char.chr
key;
5023 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5026 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5027 reshape conf.winw
conf.winh
;
5030 conf.hlinks
<- not
conf.hlinks
;
5031 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5032 G.postRedisplay "toggle highlightlinks";
5035 state.glinks
<- true;
5036 let mode = state.mode in
5037 state.mode <- Textentry
(
5038 (":", "", None
, linknentry, linkndone gotounder, false),
5040 state.glinks
<- false;
5044 G.postRedisplay "view:linkent(F)"
5047 state.glinks
<- true;
5048 let mode = state.mode in
5049 state.mode <- Textentry
(
5050 (":", "", None
, linknentry, linkndone (fun under ->
5051 match Ne.pipe () with
5053 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
5054 (Printexc.to_string exn
));
5057 try popen conf.selcmd
[r, 0; w, -1]; true
5060 (Printf.sprintf
"failed to execute %s: %s"
5061 conf.selcmd
(Printexc.to_string exn
));
5065 Ne.clo fd
(fun msg
->
5066 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
5069 let s = undertext under in
5073 let l = String.length
s in
5074 let n = tempfailureretry (Unix.write
w s 0) l in
5079 "failed to write %d characters to sel pipe, wrote %d"
5084 (Printf.sprintf
"failed to write to sel pipe: %s"
5085 (Printexc.to_string exn
)
5094 state.glinks
<- false;
5098 G.postRedisplay "view:linkent"
5101 begin match state.autoscroll
with
5103 conf.autoscrollstep
<- step
;
5104 state.autoscroll
<- None
5106 if conf.autoscrollstep
= 0
5107 then state.autoscroll
<- Some
1
5108 else state.autoscroll
<- Some
conf.autoscrollstep
5111 | 112 when ctrl -> (* ctrl-p *)
5115 setpresentationmode (not
conf.presentation
);
5116 showtext ' '
("presentation mode " ^
5117 if conf.presentation
then "on" else "off");
5120 begin match state.fullscreen
with
5122 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
5125 state.fullscreen
<- None
;
5129 | 112 | 78 -> (* p|N *)
5130 search state.searchpattern
false
5132 | 110 | 0xffc0 -> (* n|F3 *)
5133 search state.searchpattern
true
5136 begin match state.layout with
5139 gotoy_and_clear_text (getpagey l.pageno)
5145 | 0xff9f | 0xffff -> (* delete *)
5149 showtext ' '
(describe_location ());
5152 begin match state.layout with
5155 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
5160 enterbookmarkmode ()
5162 | 104 | 0xffbe -> (* h|F1 *)
5168 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5173 match state.layout with
5175 if String.length
s > 0
5177 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5180 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5184 showtext ' '
"Quick bookmark added";
5187 begin match state.layout with
5189 let rect = getpdimrect
l.pagedimno
in
5193 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5194 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5196 (truncate
(rect.(1) -. rect.(0)),
5197 truncate
(rect.(3) -. rect.(0)))
5199 let w = truncate
((float w)*.conf.zoom)
5200 and h = truncate
((float h)*.conf.zoom) in
5203 state.anchor <- getanchor ();
5204 doreshape (w + state.scrollw
) (h + conf.interpagespace
)
5206 G.postRedisplay "z";
5211 | 50 when ctrl -> (* ctrl-2 *)
5212 let maxw = getmaxw
() in
5214 then setzoom (maxw /. float conf.winw
)
5216 | 60 | 62 -> (* < > *)
5217 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5219 | 91 | 93 -> (* [ ] *)
5221 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5223 G.postRedisplay "brightness";
5225 | 99 when state.mode = View
-> (* c *)
5227 match state.prevcolumns
with
5228 | None
-> (1, 0, 0), 1.0
5229 | Some
(columns
, z
) ->
5232 | Csplit
(c, _) -> -c, 0, 0
5233 | Cmulti
((c, a, b), _) -> c, a, b
5234 | Csingle
_ -> 1, 0, 0
5238 setcolumns View
c a b;
5241 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5242 setzoom state.prevzoom
5244 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5245 begin match state.autoscroll
with
5247 begin match state.mode with
5248 | Birdseye beye
-> upbirdseye 1 beye
5251 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5252 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5255 setautoscrollspeed n false
5258 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5259 begin match state.autoscroll
with
5261 begin match state.mode with
5262 | Birdseye beye
-> downbirdseye 1 beye
5265 then gotoy_and_clear_text (clamp (conf.winh
/2))
5266 else gotoy_and_clear_text (clamp conf.scrollstep
)
5269 setautoscrollspeed n true
5272 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5273 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5279 else conf.hscrollstep
5281 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5282 state.x <- state.x + dx;
5283 gotoy_and_clear_text state.y
5286 G.postRedisplay "lef/right"
5289 | 0xff55 | 0xff9a -> (* (kp) prior *)
5293 match state.layout with
5295 | l :: _ -> state.y - l.pagey
5297 clamp (pgscale (-conf.winh
))
5301 | 0xff56 | 0xff9b -> (* (kp) next *)
5305 match List.rev
state.layout with
5307 | l :: _ -> getpagey l.pageno
5309 clamp (pgscale conf.winh
)
5313 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5315 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5316 gotoghyll (clamp state.maxy)
5319 when Wsi.withalt mask
-> (* alt-(kp) right *)
5320 gotoghyll (getnav 1)
5322 when Wsi.withalt mask
-> (* alt-(kp) left *)
5323 gotoghyll (getnav ~
-1)
5328 | 118 when conf.debug
-> (* v *)
5331 match getopaque l.pageno with
5334 let x0, y0, x1, y1 = pagebbox opaque
in
5335 let a,b = float x0, float y0 in
5336 let c,d = float x1, float y0 in
5337 let e,f = float x1, float y1 in
5338 let h,j
= float x0, float y1 in
5339 let rect = (a,b,c,d,e,f,h,j
) in
5341 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5343 G.postRedisplay "v";
5346 vlog "huh? %s" (Wsi.keyname
key)
5349 let linknavkeyboard key mask
linknav =
5350 let getpage pageno =
5351 let rec loop = function
5353 | l :: _ when l.pageno = pageno -> Some
l
5354 | _ :: rest
-> loop rest
5355 in loop state.layout
5357 let doexact (pageno, n) =
5358 match getopaque pageno, getpage pageno with
5359 | Some opaque
, Some
l ->
5360 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5362 let under = getlink opaque
n in
5363 G.postRedisplay "link gotounder";
5369 | 0xff50 -> (* home *)
5370 Some
(findlink opaque LDfirst
), -1
5372 | 0xff57 -> (* end *)
5373 Some
(findlink opaque LDlast
), 1
5375 | 0xff51 -> (* left *)
5376 Some
(findlink opaque
(LDleft
n)), -1
5378 | 0xff53 -> (* right *)
5379 Some
(findlink opaque
(LDright
n)), 1
5381 | 0xff52 -> (* up *)
5382 Some
(findlink opaque
(LDup
n)), -1
5384 | 0xff54 -> (* down *)
5385 Some
(findlink opaque
(LDdown
n)), 1
5390 begin match findpwl
l.pageno dir with
5394 state.mode <- LinkNav
(Ltgendir
dir);
5395 let y, h = getpageyh pageno in
5398 then y + h - conf.winh
5403 begin match getopaque pageno, getpage pageno with
5404 | Some opaque
, Some
_ ->
5406 let ld = if dir > 0 then LDfirst
else LDlast
in
5409 begin match link with
5411 showlinktype (getlink opaque
m);
5412 state.mode <- LinkNav
(Ltexact
(pageno, m));
5413 G.postRedisplay "linknav jpage";
5420 begin match opt with
5421 | Some Lnotfound
-> pwl l dir;
5422 | Some
(Lfound
m) ->
5426 let _, y0, _, y1 = getlinkrect opaque
m in
5428 then gotopage1 l.pageno y0
5430 let d = fstate.fontsize
+ 1 in
5431 if y1 - l.pagey > l.pagevh - d
5432 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5433 else G.postRedisplay "linknav";
5435 showlinktype (getlink opaque
m);
5436 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5439 | None
-> viewkeyboard key mask
5441 | _ -> viewkeyboard key mask
5446 G.postRedisplay "leave linknav"
5450 | Ltgendir
_ -> viewkeyboard key mask
5451 | Ltexact exact
-> doexact exact
5454 let keyboard key mask
=
5455 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5456 then wcmd "interrupt"
5457 else state.uioh <- state.uioh#
key key mask
5460 let birdseyekeyboard key mask
5461 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5463 match conf.columns
with
5465 | Cmulti
((c, _, _), _) -> c
5466 | Csplit
_ -> failwith
"bird's eye split mode"
5468 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) conf.winh
layout in
5470 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5471 let y, h = getpageyh pageno in
5472 let top = (conf.winh
- h) / 2 in
5473 gotoy (max
0 (y - top))
5474 | 0xff0d (* enter *)
5475 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5476 | 0xff1b -> leavebirdseye beye
true (* escape *)
5477 | 0xff52 -> upbirdseye incr beye
(* up *)
5478 | 0xff54 -> downbirdseye incr beye
(* down *)
5479 | 0xff51 -> upbirdseye 1 beye
(* left *)
5480 | 0xff53 -> downbirdseye 1 beye
(* right *)
5482 | 0xff55 -> (* prior *)
5483 begin match state.layout with
5487 state.mode <- Birdseye
(
5488 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5490 gotopage1 l.pageno 0;
5493 let layout = layout (state.y-conf.winh
) (pgh state.layout) in
5495 | [] -> gotoy (clamp (-conf.winh
))
5497 state.mode <- Birdseye
(
5498 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5500 gotopage1 l.pageno 0
5503 | [] -> gotoy (clamp (-conf.winh
))
5506 | 0xff56 -> (* next *)
5507 begin match List.rev
state.layout with
5509 let layout = layout (state.y + (pgh state.layout)) conf.winh
in
5510 begin match layout with
5512 let incr = l.pageh
- l.pagevh in
5517 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5519 G.postRedisplay "birdseye pagedown";
5521 else gotoy (clamp (incr + conf.interpagespace
*2));
5525 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5526 gotopage1 l.pageno 0;
5529 | [] -> gotoy (clamp conf.winh
)
5532 | 0xff50 -> (* home *)
5533 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5536 | 0xff57 -> (* end *)
5537 let pageno = state.pagecount
- 1 in
5538 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5539 if not
(pagevisible state.layout pageno)
5542 match List.rev
state.pdims
with
5544 | (_, _, h, _) :: _ -> h
5546 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace
)))
5547 else G.postRedisplay "birdseye end";
5548 | _ -> viewkeyboard key mask
5551 let drawpage l linkindexbase
=
5553 match state.mode with
5554 | Textentry
_ -> scalecolor 0.4
5556 | View
-> scalecolor 1.0
5557 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5558 if l.pageno = hooverpageno
5561 if l.pageno = pageno
5567 begin match getopaque l.pageno with
5569 if tileready l l.pagex
l.pagey
5571 let x = l.pagedispx - l.pagex
5572 and y = l.pagedispy - l.pagey in
5574 match conf.columns
with
5575 | Csingle
_ | Cmulti
_ ->
5576 (if conf.hlinks
then 1 else 0)
5578 && not
(isbirdseye state.mode) then 2 else 0)
5582 match state.mode with
5583 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5586 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5593 let scrollindicator () =
5594 let sbw, ph
, sh = state.uioh#
scrollph in
5595 let sbh, pw, sw = state.uioh#scrollpw
in
5597 GlDraw.color (0.64, 0.64, 0.64);
5599 (float (conf.winw
- sbw), 0.)
5600 (float conf.winw
, float conf.winh
)
5603 (0., float (conf.winh
- sbh))
5604 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5606 GlDraw.color (0.0, 0.0, 0.0);
5609 (float (conf.winw
- sbw), ph
)
5610 (float conf.winw
, ph
+. sh)
5613 (pw, float (conf.winh
- sbh))
5614 (pw +. sw, float conf.winh
)
5619 match state.mstate
with
5620 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5623 | Msel
((x0, y0), (x1, y1)) ->
5624 let rec loop = function
5626 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5627 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5628 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5629 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5631 match getopaque l.pageno with
5633 let x0, y0 = pagetranslatepoint l x0 y0 in
5634 let x1, y1 = pagetranslatepoint l x1 y1 in
5635 seltext opaque
(x0, y0, x1, y1);
5643 let showrects rects
=
5645 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5646 GlDraw.polygon_mode `both `fill
;
5647 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5649 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5651 if l.pageno = pageno
5653 let dx = float (l.pagedispx - l.pagex
) in
5654 let dy = float (l.pagedispy - l.pagey) in
5655 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5656 GlDraw.begins `quads
;
5658 GlDraw.vertex2
(x0+.dx, y0+.dy);
5659 GlDraw.vertex2
(x1+.dx, y1+.dy);
5660 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5661 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5672 GlClear.color (scalecolor2 conf.bgcolor
);
5673 GlClear.clear
[`
color];
5674 let rec loop linkindexbase
= function
5676 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5677 loop linkindexbase rest
5680 loop 0 state.layout;
5682 match state.mode with
5683 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5684 begin match getopaque pageno with
5686 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5693 | None
-> state.rects
5700 begin match state.mstate
with
5701 | Mzoomrect
((x0, y0), (x1, y1)) ->
5703 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5704 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5705 GlDraw.rect (float x0, float y0)
5706 (float x1, float y1);
5715 let zoomrect x y x1 y1 =
5718 and y0 = min
y y1 in
5719 gotoy (state.y + y0);
5720 state.anchor <- getanchor ();
5721 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5723 if state.w < conf.winw
- state.scrollw
5724 then (conf.winw
- state.scrollw
- state.w) / 2
5727 state.x <- (state.x + margin) - x0;
5729 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5730 state.mstate
<- Mnone
;
5734 let winw = conf.winw - state.scrollw
- 1 in
5735 let s = float x /. float winw in
5736 let destx = truncate
(float (state.w + winw) *. s) in
5737 state.x <- winw - destx;
5738 gotoy_and_clear_text state.y;
5739 state.mstate
<- Mscrollx
;
5743 let s = float y /. float conf.winh
in
5744 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5745 gotoy_and_clear_text desty;
5746 state.mstate
<- Mscrolly
;
5749 let viewmouse button down
x y mask
=
5751 | n when (n == 4 || n == 5) && not down
->
5752 if Wsi.withctrl mask
5754 match state.mstate
with
5755 | Mzoom
(oldn
, i
) ->
5763 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5765 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5767 let zoom = conf.zoom -. incr in
5769 state.mstate
<- Mzoom
(n, 0);
5771 state.mstate
<- Mzoom
(n, i
+1);
5773 else state.mstate
<- Mzoom
(n, 0)
5775 | _ -> state.mstate
<- Mzoom
(n, 0)
5778 match state.autoscroll
with
5779 | Some step
-> setautoscrollspeed step
(n=4)
5790 then -conf.scrollstep
5791 else conf.scrollstep
5793 let incr = incr * 2 in
5794 let y = clamp incr in
5795 gotoy_and_clear_text y
5798 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5799 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5800 gotoy_and_clear_text state.y
5802 | 1 when Wsi.withshift mask
->
5803 state.mstate
<- Mnone
;
5805 match unproject x y with
5806 | Some
(pageno, ux
, uy
) ->
5807 let cmd = Printf.sprintf
5809 conf.stcmd
state.path pageno ux uy
5815 | 1 when Wsi.withctrl mask
->
5818 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5819 state.mstate
<- Mpan
(x, y)
5822 state.mstate
<- Mnone
5827 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5829 state.mstate
<- Mzoomrect
(p, p)
5832 match state.mstate
with
5833 | Mzoomrect
((x0, y0), _) ->
5834 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5835 then zoomrect x0 y0 x y
5837 state.mstate
<- Mnone
;
5838 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5839 G.postRedisplay "kill accidental zoom rect";
5842 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5843 state.mstate
<- Mnone
5846 | 1 when x > conf.winw - state.scrollw
->
5849 let _, position, sh = state.uioh#
scrollph in
5850 if y > truncate
position && y < truncate
(position +. sh)
5851 then state.mstate
<- Mscrolly
5854 state.mstate
<- Mnone
5856 | 1 when y > conf.winh
- state.hscrollh ->
5859 let _, position, sw = state.uioh#scrollpw
in
5860 if x > truncate
position && x < truncate
(position +. sw)
5861 then state.mstate
<- Mscrollx
5864 state.mstate
<- Mnone
5867 let dest = if down
then getunder x y else Unone
in
5868 begin match dest with
5872 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5875 | Unone
when down
->
5876 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5877 state.mstate
<- Mpan
(x, y);
5879 | Unone
| Utext
_ ->
5882 if conf.angle
mod 360 = 0
5884 state.mstate
<- Msel
((x, y), (x, y));
5885 G.postRedisplay "mouse select";
5889 match state.mstate
with
5892 | Mzoom
_ | Mscrollx
| Mscrolly
->
5893 state.mstate
<- Mnone
5895 | Mzoomrect
((x0, y0), _) ->
5899 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5900 state.mstate
<- Mnone
5902 | Msel
((x0, y0), (x1, y1)) ->
5903 let rec loop = function
5907 let a0 = l.pagedispy in
5908 let a1 = a0 + l.pagevh in
5909 let b0 = l.pagedispx in
5910 let b1 = b0 + l.pagevw in
5911 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
5912 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
5916 match getopaque l.pageno with
5919 match Ne.pipe () with
5923 "can not create sel pipe: %s"
5924 (Printexc.to_string exn
));
5926 let doclose what fd
=
5927 Ne.clo fd
(fun msg
->
5928 dolog "%s close failed: %s" what msg
)
5931 popen conf.selcmd
[r, 0; w, -1];
5934 G.postRedisplay "copysel";
5936 dolog "can not execute %S: %s"
5937 conf.selcmd
(Printexc.to_string exn
);
5945 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5946 state.mstate
<- Mnone
;
5953 let birdseyemouse button down
x y mask
5954 (conf, leftx
, _, hooverpageno
, anchor) =
5957 let rec loop = function
5960 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5961 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5963 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5969 | _ -> viewmouse button down
x y mask
5972 let mouse button down
x y mask
=
5973 state.uioh <- state.uioh#button button down
x y mask
;
5977 state.uioh <- state.uioh#
motion x y
5981 state.uioh <- state.uioh#
pmotion x y;
5987 method key key mask
=
5988 begin match state.mode with
5989 | Textentry
textentry -> textentrykeyboard key mask
textentry
5990 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5991 | View
-> viewkeyboard key mask
5992 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5996 method button button bstate
x y mask
=
5997 begin match state.mode with
5999 | View
-> viewmouse button bstate
x y mask
6000 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6006 begin match state.mode with
6008 | View
| Birdseye
_ | LinkNav
_ ->
6009 match state.mstate
with
6010 | Mzoom
_ | Mnone
-> ()
6015 state.mstate
<- Mpan
(x, y);
6017 then state.x <- state.x + dx;
6019 gotoy_and_clear_text y
6022 state.mstate
<- Msel
(a, (x, y));
6023 G.postRedisplay "motion select";
6026 let y = min
conf.winh
(max
0 y) in
6030 let x = min
conf.winw (max
0 x) in
6033 | Mzoomrect
(p0
, _) ->
6034 state.mstate
<- Mzoomrect
(p0
, (x, y));
6035 G.postRedisplay "motion zoomrect";
6039 method pmotion x y =
6040 begin match state.mode with
6041 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6042 let rec loop = function
6044 if hooverpageno
!= -1
6046 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6047 G.postRedisplay "pmotion birdseye no hoover";
6050 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6051 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6053 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6054 G.postRedisplay "pmotion birdseye hoover";
6064 match state.mstate
with
6065 | Mnone
-> updateunder x y
6066 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6071 method infochanged
_ = ()
6074 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
6075 let p, h = scrollph state.y maxy in
6079 let winw = conf.winw - state.scrollw
- 1 in
6080 let fwinw = float winw in
6082 let sw = fwinw /. float state.w in
6083 let sw = fwinw *. sw in
6084 max
sw (float conf.scrollh
)
6087 let f = state.w+winw in
6088 let r = float (winw-state.x) /. float f in
6089 let p = fwinw *. r in
6093 if position +. sw > fwinw
6094 then fwinw -. position
6097 state.hscrollh, position, sw
6101 match state.mode with
6102 | LinkNav
_ -> "links"
6103 | Textentry
_ -> "textentry"
6104 | Birdseye
_ -> "birdseye"
6107 findkeyhash conf modename
6114 let fontpath = ref "";;
6117 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6120 let l = String.length
s in
6121 let b = Buffer.create
l in
6127 try Sys.getenv
"HOME"
6130 ("Can not determine home directory location: " ^
6131 Printexc.to_string exn
);
6135 let modifier_of_string = function
6136 | "alt" -> Wsi.altmask
6137 | "shift" -> Wsi.shiftmask
6138 | "ctrl" | "control" -> Wsi.ctrlmask
6139 | "meta" -> Wsi.metamask
6144 let r = Str.regexp
"-" in
6146 let elems = Str.full_split
r s in
6149 let m1 = modifier_of_string s in
6151 then (Wsi.namekey
s, m)
6154 | Str.Delim
s when n land 1 = 0 -> g s
6156 | Str.Delim
_ -> (k
, m)
6158 let rec loop n k
m = function
6161 let k, m = f n k m x in
6167 let keys_of_string =
6168 let r = Str.regexp
"[ \t]" in
6170 let elems = Str.split
r s in
6171 List.map
key_of_string elems
6174 let copykeyhashes c =
6175 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6178 let config_of c attrs
=
6182 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6183 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6184 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6185 | "preload" -> { c with preload = bool_of_string
v }
6186 | "page-bias" -> { c with pagebias
= int_of_string
v }
6187 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6188 | "horizontal-scroll-step" ->
6189 { c with hscrollstep
= max
(int_of_string
v) 1 }
6190 | "auto-scroll-step" ->
6191 { c with autoscrollstep
= max
0 (int_of_string
v) }
6192 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6193 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6196 match String.lowercase
v with
6197 | "true" -> Some infinity
6199 | f -> Some
(float_of_string
f)
6201 { c with maxwait
= mw}
6202 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6203 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6204 | "vertical-margin" ->
6205 { c with interpagespace
= max
0 (int_of_string
v) }
6207 let zoom = float_of_string
v /. 100. in
6208 let zoom = max
zoom 0.0 in
6209 { c with zoom = zoom }
6210 | "presentation" -> { c with presentation
= bool_of_string
v }
6211 | "rotation-angle" -> { c with angle
= int_of_string
v }
6212 | "width" -> { c with winw = max
20 (int_of_string
v) }
6213 | "height" -> { c with winh
= max
20 (int_of_string
v) }
6214 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6215 | "proportional-display" -> { c with proportional
= bool_of_string
v }
6216 | "pixmap-cache-size" ->
6217 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6218 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6219 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6220 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6221 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6222 | "background-color" -> { c with bgcolor
= color_of_string v }
6223 | "scrollbar-in-presentation" ->
6224 { c with scrollbarinpm
= bool_of_string
v }
6225 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6226 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6227 | "mupdf-store-size" ->
6228 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6229 | "checkers" -> { c with checkers
= bool_of_string
v }
6230 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6231 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6232 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6233 | "uri-launcher" -> { c with urilauncher
= unent v }
6234 | "path-launcher" -> { c with pathlauncher
= unent v }
6235 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6236 | "invert-colors" -> { c with invert
= bool_of_string
v }
6237 | "brightness" -> { c with colorscale
= float_of_string
v }
6238 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6240 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6242 let (n, _, _) as nab
= multicolumns_of_string v in
6244 then { c with columns
= Csplit
(-n, [||]) }
6245 else { c with columns
= Cmulti
(nab
, [||]) }
6246 | "birds-eye-columns" ->
6247 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6248 | "selection-command" -> { c with selcmd
= unent v }
6249 | "synctex-command" -> { c with stcmd
= unent v }
6250 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6251 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6252 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6253 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6254 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6257 prerr_endline
("Error processing attribute (`" ^
6258 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
6261 let rec fold c = function
6264 let c = apply c k v in
6267 fold { c with keyhashes
= copykeyhashes c } attrs
;
6270 let fromstring f pos
n v d =
6273 dolog "Error processing attribute (%S=%S) at %d\n%s"
6274 n v pos
(Printexc.to_string exn
)
6279 let bookmark_of attrs
=
6280 let rec fold title page
rely visy
= function
6281 | ("title", v) :: rest
-> fold v page
rely visy rest
6282 | ("page", v) :: rest
-> fold title v rely visy rest
6283 | ("rely", v) :: rest
-> fold title page
v visy rest
6284 | ("visy", v) :: rest
-> fold title page
rely v rest
6285 | _ :: rest
-> fold title page
rely visy rest
6286 | [] -> title, page
, rely, visy
6288 fold "invalid" "0" "0" "0" attrs
6292 let rec fold path page
rely pan visy
= function
6293 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6294 | ("page", v) :: rest
-> fold path v rely pan visy rest
6295 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6296 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6297 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6298 | _ :: rest
-> fold path page
rely pan visy rest
6299 | [] -> path, page
, rely, pan
, visy
6301 fold "" "0" "0" "0" "0" attrs
6305 let rec fold rs ls
= function
6306 | ("out", v) :: rest
-> fold v ls rest
6307 | ("in", v) :: rest
-> fold rs
v rest
6308 | _ :: rest
-> fold ls rs rest
6314 let setconf dst
src =
6315 dst
.scrollbw
<- src.scrollbw
;
6316 dst
.scrollh
<- src.scrollh
;
6317 dst
.icase
<- src.icase
;
6318 dst
.preload <- src.preload;
6319 dst
.pagebias
<- src.pagebias
;
6320 dst
.verbose
<- src.verbose
;
6321 dst
.scrollstep
<- src.scrollstep
;
6322 dst
.maxhfit
<- src.maxhfit
;
6323 dst
.crophack
<- src.crophack
;
6324 dst
.autoscrollstep
<- src.autoscrollstep
;
6325 dst
.maxwait
<- src.maxwait
;
6326 dst
.hlinks
<- src.hlinks
;
6327 dst
.underinfo
<- src.underinfo
;
6328 dst
.interpagespace
<- src.interpagespace
;
6329 dst
.zoom <- src.zoom;
6330 dst
.presentation
<- src.presentation
;
6331 dst
.angle
<- src.angle
;
6332 dst
.winw <- src.winw;
6333 dst
.winh
<- src.winh
;
6334 dst
.savebmarks
<- src.savebmarks
;
6335 dst
.memlimit
<- src.memlimit
;
6336 dst
.proportional
<- src.proportional
;
6337 dst
.texcount
<- src.texcount
;
6338 dst
.sliceheight
<- src.sliceheight
;
6339 dst
.thumbw
<- src.thumbw
;
6340 dst
.jumpback
<- src.jumpback
;
6341 dst
.bgcolor
<- src.bgcolor
;
6342 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6343 dst
.tilew
<- src.tilew
;
6344 dst
.tileh
<- src.tileh
;
6345 dst
.mustoresize
<- src.mustoresize
;
6346 dst
.checkers
<- src.checkers
;
6347 dst
.aalevel
<- src.aalevel
;
6348 dst
.trimmargins
<- src.trimmargins
;
6349 dst
.trimfuzz
<- src.trimfuzz
;
6350 dst
.urilauncher
<- src.urilauncher
;
6351 dst
.colorspace
<- src.colorspace
;
6352 dst
.invert
<- src.invert
;
6353 dst
.colorscale
<- src.colorscale
;
6354 dst
.redirectstderr <- src.redirectstderr;
6355 dst
.ghyllscroll
<- src.ghyllscroll
;
6356 dst
.columns
<- src.columns
;
6357 dst
.beyecolumns
<- src.beyecolumns
;
6358 dst
.selcmd
<- src.selcmd
;
6359 dst
.updatecurs
<- src.updatecurs
;
6360 dst
.pathlauncher
<- src.pathlauncher
;
6361 dst
.keyhashes
<- copykeyhashes src;
6362 dst
.hfsize
<- src.hfsize
;
6363 dst
.hscrollstep
<- src.hscrollstep
;
6364 dst
.pgscale <- src.pgscale;
6365 dst
.usepbo
<- src.usepbo
;
6366 dst
.wheelbypage
<- src.wheelbypage
;
6367 dst
.stcmd
<- src.stcmd
;
6371 let h = Hashtbl.create
10 in
6372 let dc = { defconf with angle
= defconf.angle
} in
6373 let rec toplevel v t spos
_ =
6375 | Vdata
| Vcdata
| Vend
-> v
6376 | Vopen
("llppconfig", _, closed
) ->
6379 else { v with f = llppconfig
}
6381 error
"unexpected subelement at top level" s spos
6382 | Vclose
_ -> error
"unexpected close at top level" s spos
6384 and llppconfig
v t spos
_ =
6386 | Vdata
| Vcdata
-> v
6387 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6388 | Vopen
("defaults", attrs
, closed
) ->
6389 let c = config_of dc attrs
in
6393 else { v with f = defaults
}
6395 | Vopen
("ui-font", attrs
, closed
) ->
6396 let rec getsize size
= function
6398 | ("size", v) :: rest
->
6400 fromstring int_of_string spos
"size" v fstate.fontsize
in
6402 | l -> getsize size l
6404 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6407 else { v with f = uifont
(Buffer.create
10) }
6409 | Vopen
("doc", attrs
, closed
) ->
6410 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6411 let path = unent pathent
6412 and pageno = fromstring int_of_string spos
"page" spage
0
6413 and rely = fromstring float_of_string spos
"rely" srely
0.0
6414 and pan
= fromstring int_of_string spos
"pan" span
0
6415 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6416 let c = config_of dc attrs
in
6417 let anchor = (pageno, rely, visy
) in
6419 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6420 else { v with f = doc
path pan
anchor c [] }
6423 error
"unexpected subelement in llppconfig" s spos
6425 | Vclose
"llppconfig" -> { v with f = toplevel }
6426 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6428 and defaults
v t spos
_ =
6430 | Vdata
| Vcdata
-> v
6431 | Vend
-> error
"unexpected end of input in defaults" s spos
6432 | Vopen
("keymap", attrs
, closed
) ->
6434 try List.assoc
"mode" attrs
6435 with Not_found
-> "global" in
6440 let h = findkeyhash dc modename in
6441 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6444 { v with f = pkeymap
ret KeyMap.empty }
6446 | Vopen
(_, _, _) ->
6447 error
"unexpected subelement in defaults" s spos
6449 | Vclose
"defaults" ->
6450 { v with f = llppconfig
}
6452 | Vclose
_ -> error
"unexpected close in defaults" s spos
6454 and uifont
b v t spos
epos =
6457 Buffer.add_substring
b s spos
(epos - spos
);
6459 | Vopen
(_, _, _) ->
6460 error
"unexpected subelement in ui-font" s spos
6461 | Vclose
"ui-font" ->
6462 if String.length
!fontpath = 0
6463 then fontpath := Buffer.contents
b;
6464 { v with f = llppconfig
}
6465 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6466 | Vend
-> error
"unexpected end of input in ui-font" s spos
6468 and doc
path pan
anchor c bookmarks
v t spos
_ =
6470 | Vdata
| Vcdata
-> v
6471 | Vend
-> error
"unexpected end of input in doc" s spos
6472 | Vopen
("bookmarks", _, closed
) ->
6475 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6477 | Vopen
("keymap", attrs
, closed
) ->
6479 try List.assoc
"mode" attrs
6480 with Not_found
-> "global"
6486 let h = findkeyhash c modename in
6487 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6488 doc
path pan
anchor c bookmarks
6490 { v with f = pkeymap
ret KeyMap.empty }
6492 | Vopen
(_, _, _) ->
6493 error
"unexpected subelement in doc" s spos
6496 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6497 { v with f = llppconfig
}
6499 | Vclose
_ -> error
"unexpected close in doc" s spos
6501 and pkeymap
ret keymap
v t spos
_ =
6503 | Vdata
| Vcdata
-> v
6504 | Vend
-> error
"unexpected end of input in keymap" s spos
6505 | Vopen
("map", attrs
, closed
) ->
6506 let r, l = map_of attrs
in
6507 let kss = fromstring keys_of_string spos
"in" r [] in
6508 let lss = fromstring keys_of_string spos
"out" l [] in
6512 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6513 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6516 then { v with f = pkeymap
ret keymap }
6519 { v with f = skip
"map" f }
6522 error
"unexpected subelement in keymap" s spos
6524 | Vclose
"keymap" ->
6525 { v with f = ret keymap }
6527 | Vclose
_ -> error
"unexpected close in keymap" s spos
6529 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6531 | Vdata
| Vcdata
-> v
6532 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6533 | Vopen
("item", attrs
, closed
) ->
6534 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6535 let page = fromstring int_of_string spos
"page" spage
0
6536 and rely = fromstring float_of_string spos
"rely" srely
0.0
6537 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6539 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6542 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6545 { v with f = skip
"item" f }
6548 error
"unexpected subelement in bookmarks" s spos
6550 | Vclose
"bookmarks" ->
6551 { v with f = doc
path pan
anchor c bookmarks }
6553 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6555 and skip tag
f v t spos
_ =
6557 | Vdata
| Vcdata
-> v
6559 error
("unexpected end of input in skipped " ^ tag
) s spos
6560 | Vopen
(tag'
, _, closed
) ->
6564 let f'
() = { v with f = skip tag
f } in
6565 { v with f = skip tag'
f'
}
6569 else error
("unexpected close in skipped " ^ tag
) s spos
6572 parse
{ f = toplevel; accu = () } s;
6578 let len = in_channel_length ic
in
6579 let s = String.create
len in
6580 really_input ic
s 0 len;
6583 | Parse_error
(msg
, s, pos
) ->
6584 let subs = subs s pos
in
6585 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6586 failwith
("parse error: " ^
s)
6589 failwith
("config load error: " ^
Printexc.to_string exn
)
6595 let dir = Filename.concat
home ".config" in
6596 if Sys.is_directory
dir then dir else home
6599 Filename.concat
dir "llpp.conf"
6602 let confpath = ref defconfpath;;
6605 if Sys.file_exists
!confpath
6608 (try Some
(open_in_bin
!confpath)
6611 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6612 Printexc.to_string exn
);
6622 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6623 Printexc.to_string exn
);
6631 f (Hashtbl.create
0, defconf)
6636 let pc, pb
, px, pa
=
6638 Hashtbl.find h (Filename.basename
state.path)
6639 with Not_found
-> dc, [], 0, emptyanchor
6643 state.bookmarks <- pb
;
6645 state.scrollw
<- conf.scrollbw
;
6647 then state.anchor <- pa
;
6648 cbput state.hists
.nav pa
;
6654 let add_attrs bb always
dc c =
6657 then Printf.bprintf bb
"\n %s='%b'" s a
6660 then Printf.bprintf bb
"\n %s='%d'" s a
6663 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6666 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6669 then Printf.bprintf bb
"\n %s='%f'" s a
6673 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6677 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6681 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6685 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6691 | Some
(_N
, _A
, _B
) ->
6692 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6702 else string_of_float
f
6704 Printf.bprintf bb
"\n %s='%s'" s v
6709 | Cmulti
((n, a, b), _) when n > 1 ->
6710 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6711 | Csplit
(n, _) when n > 1 ->
6712 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6718 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6723 then dc.winw, dc.winh
6725 match state.fullscreen
with
6727 | None
-> c.winw, c.winh
6729 oi
"width" w dc.winw;
6730 oi
"height" h dc.winh
;
6731 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6732 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6733 ob "case-insensitive-search" c.icase
dc.icase
;
6734 ob "preload" c.preload dc.preload;
6735 oi
"page-bias" c.pagebias
dc.pagebias
;
6736 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6737 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6738 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6739 ob "crop-hack" c.crophack
dc.crophack
;
6740 oW
"throttle" c.maxwait
dc.maxwait
;
6741 ob "highlight-links" c.hlinks
dc.hlinks
;
6742 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6743 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6744 oz
"zoom" c.zoom dc.zoom;
6745 ob "presentation" c.presentation
dc.presentation
;
6746 oi
"rotation-angle" c.angle
dc.angle
;
6747 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6748 ob "proportional-display" c.proportional
dc.proportional
;
6749 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6750 oi
"tex-count" c.texcount
dc.texcount
;
6751 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6752 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6753 ob "persistent-location" c.jumpback
dc.jumpback
;
6754 oc
"background-color" c.bgcolor
dc.bgcolor
;
6755 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6756 oi
"tile-width" c.tilew
dc.tilew
;
6757 oi
"tile-height" c.tileh
dc.tileh
;
6758 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6759 ob "checkers" c.checkers
dc.checkers
;
6760 oi
"aalevel" c.aalevel
dc.aalevel
;
6761 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6762 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6763 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6764 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6765 oC
"color-space" c.colorspace
dc.colorspace
;
6766 ob "invert-colors" c.invert
dc.invert
;
6767 oF
"brightness" c.colorscale
dc.colorscale
;
6768 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6769 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6770 oco
"columns" c.columns
dc.columns
;
6771 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6772 os
"selection-command" c.selcmd
dc.selcmd
;
6773 os
"synctex-command" c.stcmd
dc.stcmd
;
6774 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6775 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6776 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6777 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6778 ob "use-pbo" c.usepbo
dc.usepbo
;
6779 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6782 let keymapsbuf always
dc c =
6783 let bb = Buffer.create
16 in
6784 let rec loop = function
6786 | (modename, h) :: rest
->
6787 let dh = findkeyhash dc modename in
6788 if always
|| h <> dh
6790 if Hashtbl.length
h > 0
6792 if Buffer.length
bb > 0
6793 then Buffer.add_char
bb '
\n'
;
6794 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6795 Hashtbl.iter
(fun i
o ->
6796 let isdifferent = always
||
6798 let dO = Hashtbl.find dh i
in
6800 with Not_found
-> true
6805 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6806 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6807 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6808 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6809 Buffer.add_string
bb (Wsi.keyname
k);
6812 let rec loop = function
6814 | km
:: [] -> addkm km
6815 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6819 Buffer.add_string
bb "<map in='";
6823 Buffer.add_string
bb "' out='";
6825 Buffer.add_string
bb "'/>\n"
6828 Buffer.add_string
bb "' out='";
6830 Buffer.add_string
bb "'/>\n"
6832 | KMmulti
(ins, kms
) ->
6833 Buffer.add_char
bb ' '
;
6835 Buffer.add_string
bb "' out='";
6837 Buffer.add_string
bb "'/>\n"
6839 Buffer.add_string
bb "</keymap>";
6849 let uifontsize = fstate.fontsize
in
6850 let bb = Buffer.create
32768 in
6852 let dc = if conf.bedefault
then conf else dc in
6853 Buffer.add_string
bb "<llppconfig>\n";
6855 if String.length
!fontpath > 0
6857 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6863 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6866 Buffer.add_string
bb "<defaults ";
6867 add_attrs bb true dc dc;
6868 let kb = keymapsbuf true dc dc in
6869 if Buffer.length
kb > 0
6871 Buffer.add_string
bb ">\n";
6872 Buffer.add_buffer
bb kb;
6873 Buffer.add_string
bb "\n</defaults>\n";
6875 else Buffer.add_string
bb "/>\n";
6877 let adddoc path pan
anchor c bookmarks =
6878 if bookmarks == [] && c = dc && anchor = emptyanchor
6881 Printf.bprintf
bb "<doc path='%s'"
6882 (enent
path 0 (String.length
path));
6884 if anchor <> emptyanchor
6886 let n, rely, visy
= anchor in
6887 Printf.bprintf
bb " page='%d'" n;
6890 Printf.bprintf
bb " rely='%f'" rely
6892 if abs_float visy
> 1e-6
6894 Printf.bprintf
bb " visy='%f'" visy
6899 then Printf.bprintf
bb " pan='%d'" pan
;
6901 add_attrs bb false dc c;
6902 let kb = keymapsbuf false dc c in
6904 begin match bookmarks with
6906 if Buffer.length
kb > 0
6908 Buffer.add_string
bb ">\n";
6909 Buffer.add_buffer
bb kb;
6910 Buffer.add_string
bb "\n</doc>\n";
6912 else Buffer.add_string
bb "/>\n"
6914 Buffer.add_string
bb ">\n<bookmarks>\n";
6915 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
6917 "<item title='%s' page='%d'"
6918 (enent
title 0 (String.length
title))
6923 Printf.bprintf
bb " rely='%f'" rely
6925 if abs_float visy
> 1e-6
6927 Printf.bprintf
bb " visy='%f'" visy
6929 Buffer.add_string
bb "/>\n";
6931 Buffer.add_string
bb "</bookmarks>";
6932 if Buffer.length
kb > 0
6934 Buffer.add_string
bb "\n";
6935 Buffer.add_buffer
bb kb;
6937 Buffer.add_string
bb "\n</doc>\n";
6943 match state.mode with
6944 | Birdseye
(c, pan, _, _, _) ->
6946 match conf.columns
with
6947 | Cmulti
((c, _, _), _) -> Some
c
6951 match c.columns
with
6952 | Cmulti
(c, _) -> Cmulti
(c, [||])
6953 | Csingle
_ -> Csingle
[||]
6954 | Csplit
_ -> failwith
"quit from bird's eye while split"
6956 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6957 | _ -> state.x, conf
6959 let basename = Filename.basename state.path in
6960 adddoc basename pan (getanchor ())
6962 let autoscrollstep =
6963 match state.autoscroll
with
6965 | None
-> conf.autoscrollstep
6967 match state.mode with
6968 | Birdseye
(bc
, _, _, _, _) ->
6971 presentation
= bc
.presentation
;
6972 interpagespace
= bc
.interpagespace
;
6973 maxwait
= bc
.maxwait
;
6974 autoscrollstep = autoscrollstep }
6975 | _ -> { conf with autoscrollstep = autoscrollstep }
6977 (if conf.savebmarks
then state.bookmarks else []);
6979 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
6981 then adddoc path x anchor c bookmarks
6983 Buffer.add_string
bb "</llppconfig>\n";
6986 if load1 f && Buffer.length
bb > 0
6989 let tmp = !confpath ^
".tmp" in
6990 let oc = open_out_bin
tmp in
6991 Buffer.output_buffer
oc bb;
6993 Unix.rename
tmp !confpath;
6996 ("error while saving configuration: " ^
Printexc.to_string exn
)
7001 let trimcachepath = ref "" in
7004 [("-p", Arg.String
(fun s -> state.password
<- s) ,
7005 "<password> Set password");
7007 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7008 "<path> Set path to the user interface font");
7010 ("-c", Arg.String
(fun s -> Config.confpath := s),
7011 "<path> Set path to the configuration file");
7013 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7014 "<path> Set path to the trim cache file");
7016 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7017 "<named destination> Set named destination");
7019 ("-wtmode", Arg.Set
wtmode, "wt mode");
7021 ("-v", Arg.Unit
(fun () ->
7023 "%s\nconfiguration path: %s\n"
7027 exit
0), " Print version and exit");
7030 (fun s -> state.path <- s)
7031 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7033 if String.length
state.path = 0
7034 then (prerr_endline
"file name missing"; exit
1);
7036 if not
(Config.load ())
7037 then prerr_endline
"failed to load configuration";
7039 let globalkeyhash = findkeyhash conf "global" in
7040 let wsfd, winw, winh
= Wsi.init
(object
7042 state.wthack <- false;
7043 if nogeomcmds state.geomcmds
|| platform == Posx
7046 GlClear.color (scalecolor2 conf.bgcolor
);
7047 GlClear.clear
[`
color];
7049 method display = display ()
7050 method reshape w h = reshape w h
7051 method mouse b d x y m = mouse b d x y m
7052 method motion x y = state.mpos
<- (x, y); motion x y
7053 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7055 let mascm = m land (
7056 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7058 match state.keystate
with
7060 let km = k, mascm in
7063 let modehash = state.uioh#
modehash in
7064 try Hashtbl.find modehash km
7066 try Hashtbl.find globalkeyhash km
7067 with Not_found
-> KMinsrt
(k, m)
7069 | KMinsrt
(k, m) -> keyboard k m
7070 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7071 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7073 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7074 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7075 state.keystate
<- KSnone
7076 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7077 state.keystate
<- KSinto
(keys
, insrt
)
7079 state.keystate
<- KSnone
7081 method enter
x y = state.mpos
<- (x, y); pmotion x y
7082 method leave = state.mpos
<- (-1, -1)
7083 method quit
= raise Quit
7084 end) conf.winw conf.winh
(platform = Posx
) in
7089 List.exists
GlMisc.check_extension
7090 [ "GL_ARB_texture_rectangle"
7091 ; "GL_EXT_texture_recangle"
7092 ; "GL_NV_texture_rectangle" ]
7094 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7097 match Ne.pipe () with
7099 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
7103 match Ne.pipe () with
7105 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
7115 setcheckers conf.checkers
;
7119 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
7120 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7121 !Config.fontpath, !trimcachepath,
7122 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7126 state.text <- "Opening " ^
(mbtoutf8
state.path);
7128 opendoc state.path state.password
;
7131 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7133 let rec loop deadline
=
7135 match state.errfd
with
7136 | None
-> [state.sr
; state.wsfd]
7137 | Some fd
-> [state.sr
; state.wsfd; fd
]
7139 if state.redisplay
&& not
state.wthack
7141 state.redisplay
<- false;
7148 if deadline
= infinity
7150 else max
0.0 (deadline
-. now)
7155 try Unix.select
r [] [] timeout
7156 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7162 if state.ghyll
== noghyll
7164 match state.autoscroll
with
7165 | Some step
when step
!= 0 ->
7166 let y = state.y + step
in
7170 else if y >= state.maxy then 0 else y
7173 if state.mode = View
7174 then state.text <- "";
7177 else deadline
+. 0.01
7182 let rec checkfds = function
7184 | fd
:: rest
when fd
= state.sr
->
7185 let cmd = readcmd state.sr
in
7189 | fd
:: rest
when fd
= state.wsfd ->
7194 let s = String.create
80 in
7195 let n = tempfailureretry (Unix.read fd
s 0) 80 in
7196 if conf.redirectstderr
7198 Buffer.add_substring
state.errmsgs
s 0 n;
7199 state.newerrmsgs
<- true;
7200 state.redisplay
<- true;
7203 prerr_string
(String.sub
s 0 n);
7211 if deadline
= infinity
7215 match state.autoscroll
with
7216 | Some step
when step
!= 0 -> deadline1
7217 | _ -> if state.ghyll
== noghyll then infinity
else deadline1