8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 | Uremotedest
of (string * string)
15 and facename
= string;;
24 type params
= (angle
* fitmodel
* trimparams
25 * texcount
* sliceheight
* memsize
26 * colorspace
* fontpath
* trimcachepath
36 and trimmargins
= bool
37 and interpagespace
= int
44 and trimcachepath
= string
47 and irect
= (int * int * int * int)
48 and trimparams
= (trimmargins
* irect
)
49 and colorspace
= | Rgb
| Bgr
| Gray
50 and fitmodel
= | FitWidth
| FitProportional
| FitPage
58 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
67 | LDfirstvisible
of (int * int * int)
82 | KMmulti
of key list
* key list
84 and keyhash
= (key
, keymap
) Hashtbl.t
87 | KSinto
of (key list
* key list
)
90 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
91 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
93 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
95 external init
: pipe
-> params
-> unit = "ml_init";;
96 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
97 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
98 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
99 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
100 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
101 external clearmark
: string -> unit = "ml_clearmark";;
102 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
103 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
104 external measurestr
: int -> string -> float = "ml_measure_string";;
105 external postprocess
:
106 opaque
-> int -> int -> int -> (int * string * int) -> int
108 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
109 external platform
: unit -> platform
= "ml_platform";;
110 external setaalevel
: int -> unit = "ml_setaalevel";;
111 external realloctexts
: int -> bool = "ml_realloctexts";;
112 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
113 external getlink
: opaque
-> int -> under
= "ml_getlink";;
114 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
115 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
116 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
117 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
118 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
119 external freepbo
: string -> unit = "ml_freepbo";;
120 external unmappbo
: string -> unit = "ml_unmappbo";;
121 external pbousable
: unit -> bool = "ml_pbo_usable";;
122 external unproject
: opaque
-> int -> int -> (int * int) option
124 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
125 external rectofblock
: opaque
-> int -> int -> float array
option
127 external fz_version
: unit -> string = "ml_fz_version";;
128 external begintiles
: unit -> unit = "ml_begintiles";;
129 external endtiles
: unit -> unit = "ml_endtiles";;
131 let platform_to_string = function
132 | Punknown
-> "unknown"
136 | Pfreebsd
-> "FreeBSD"
137 | Pdragonflybsd
-> "DragonflyBSD"
138 | Popenbsd
-> "OpenBSD"
139 | Pnetbsd
-> "NetBSD"
140 | Pcygwin
-> "Cygwin"
143 let platform = platform ();;
145 let now = Unix.gettimeofday
;;
147 let selfexec = ref "";;
150 if platform = Pcygwin
152 let sh = "/bin/sh" in
153 let args = [|sh; "-c"; cmd
|] in
154 let rec std si so se
= function
156 | (fd
, 0) :: rest
-> std fd so se rest
157 | (fd
, -1) :: rest
->
158 Unix.set_close_on_exec fd
;
161 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
163 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
164 ignore
(Unix.create_process
sh args si so se
)
169 type mpos
= int * int
171 | Msel
of (mpos
* mpos
)
173 | Mscrolly
| Mscrollx
174 | Mzoom
of (int * int)
175 | Mzoomrect
of (mpos
* mpos
)
179 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
180 and onkey
= string -> int -> te
181 and ondone
= string -> unit
182 and histcancel
= unit -> unit
183 and onhist
= ((histcmd
-> string) * histcancel
)
184 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
185 and cancelonempty
= bool
190 | TEswitch
of textentry
201 let bound v minv maxv
=
202 max minv
(min maxv v
);
206 { store
= Array.create n v
213 let cbcap b
= Array.length b
.store
;;
218 b
.wc
<- (b
.wc
+ 1) mod cap;
220 b
.len
<- min
(b
.len
+ 1) cap;
223 let cbempty b
= b
.len
= 0;;
225 let cbgetg b circular dir
=
229 let rc = b
.rc + dir
in
241 else bound rc 0 (b
.len
-1)
247 let cbget b
= cbgetg b
false;;
248 let cbgetc b
= cbgetg b
true;;
250 let drawstring size x y s
=
252 Gl.enable `texture_2d
;
253 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
254 ignore
(drawstr size x y s
);
256 Gl.disable `texture_2d
;
259 let drawstring1 size x y s
=
263 let drawstring2 size x y fmt
=
264 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
283 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
284 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
285 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
286 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
287 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
288 dolog
" column %d" l
.pagecol
;
292 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
294 dolog
" x0,y0=(% f, % f)" x0 y0
;
295 dolog
" x1,y1=(% f, % f)" x1 y1
;
296 dolog
" x2,y2=(% f, % f)" x2 y2
;
297 dolog
" x3,y3=(% f, % f)" x3 y3
;
301 type multicolumns
= multicol
* pagegeom
302 and singlecolumn
= pagegeom
303 and splitcolumns
= columncount
* pagegeom
304 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
305 and multicol
= columncount
* covercount
* covercount
307 and columncount
= int
308 and covercount
= int;;
315 { mutable scrollbw
: int
316 ; mutable scrollh
: int
317 ; mutable scrollb
: scrollb
318 ; mutable icase
: bool
319 ; mutable preload
: bool
320 ; mutable pagebias
: int
321 ; mutable verbose
: bool
322 ; mutable debug
: bool
323 ; mutable scrollstep
: int
324 ; mutable hscrollstep
: int
325 ; mutable maxhfit
: bool
326 ; mutable crophack
: bool
327 ; mutable autoscrollstep
: int
328 ; mutable maxwait
: float option
329 ; mutable hlinks
: bool
330 ; mutable underinfo
: bool
331 ; mutable interpagespace
: interpagespace
332 ; mutable zoom
: float
333 ; mutable presentation
: bool
334 ; mutable angle
: angle
335 ; mutable cwinw
: int
336 ; mutable cwinh
: int
337 ; mutable savebmarks
: bool
338 ; mutable fitmodel
: fitmodel
339 ; mutable trimmargins
: trimmargins
340 ; mutable trimfuzz
: irect
341 ; mutable memlimit
: memsize
342 ; mutable texcount
: texcount
343 ; mutable sliceheight
: sliceheight
344 ; mutable thumbw
: width
345 ; mutable jumpback
: bool
346 ; mutable bgcolor
: (float * float * float)
347 ; mutable bedefault
: bool
348 ; mutable tilew
: int
349 ; mutable tileh
: int
350 ; mutable mustoresize
: memsize
351 ; mutable checkers
: bool
352 ; mutable aalevel
: int
353 ; mutable urilauncher
: string
354 ; mutable pathlauncher
: string
355 ; mutable colorspace
: colorspace
356 ; mutable invert
: bool
357 ; mutable colorscale
: float
358 ; mutable redirectstderr
: bool
359 ; mutable ghyllscroll
: (int * int * int) option
360 ; mutable columns
: columns
361 ; mutable beyecolumns
: columncount
option
362 ; mutable selcmd
: string
363 ; mutable paxcmd
: string
364 ; mutable updatecurs
: bool
365 ; mutable keyhashes
: (string * keyhash
) list
366 ; mutable hfsize
: int
367 ; mutable pgscale
: float
368 ; mutable usepbo
: bool
369 ; mutable wheelbypage
: bool
370 ; mutable stcmd
: string
371 ; mutable riani
: bool
372 ; mutable pax
: (float * int * int) ref option
373 ; mutable paxmark
: mark
376 | Csingle
of singlecolumn
377 | Cmulti
of multicolumns
378 | Csplit
of splitcolumns
381 type anchor
= pageno
* top
* dtop
;;
383 type outline
= string * int * anchor
;;
385 type rect
= float * float * float * float * float * float * float * float;;
387 type tile
= opaque
* pixmapsize
* elapsed
388 and elapsed
= float;;
389 type pagemapkey
= pageno
* gen
;;
390 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
394 let emptyanchor = (0, 0.0, 0.0);;
396 type infochange
= | Memused
| Docinfo
| Pdim
;;
398 class type uioh
= object
399 method display
: unit
400 method key
: int -> int -> uioh
401 method button
: int -> bool -> int -> int -> int -> uioh
402 method motion
: int -> int -> uioh
403 method pmotion
: int -> int -> uioh
404 method infochanged
: infochange
-> unit
405 method scrollpw
: (int * float * float)
406 method scrollph
: (int * float * float)
407 method modehash
: keyhash
408 method eformsgs
: bool
412 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
413 | Textentry
of (textentry
* onleave
)
415 | LinkNav
of linktarget
416 and onleave
= leavetextentrystatus
-> unit
417 and leavetextentrystatus
= | Cancel
| Confirm
418 and helpitem
= string * int * action
421 | Action
of (uioh
-> uioh
)
423 | Ltexact
of (pageno
* int)
427 let isbirdseye = function Birdseye _
-> true | _
-> false;;
428 let istextentry = function Textentry _
-> true | _
-> false;;
432 | Loading
of (page
* gen
)
434 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
436 | Outlining
of outline list
439 let emptykeyhash = Hashtbl.create
0;;
440 let nouioh : uioh
= object (self
)
442 method key _ _
= self
443 method button _ _ _ _ _
= self
444 method motion _ _
= self
445 method pmotion _ _
= self
446 method infochanged _
= ()
447 method scrollpw
= (0, nan
, nan
)
448 method scrollph
= (0, nan
, nan
)
449 method modehash
= emptykeyhash
450 method eformsgs
= false
454 { mutable sr
: Unix.file_descr
455 ; mutable sw
: Unix.file_descr
456 ; mutable wsfd
: Unix.file_descr
457 ; mutable errfd
: Unix.file_descr
option
458 ; mutable stderr
: Unix.file_descr
459 ; mutable errmsgs
: Buffer.t
460 ; mutable newerrmsgs
: bool
464 ; mutable anchor
: anchor
465 ; mutable ranchors
: (string * string * anchor
* string) list
467 ; mutable layout
: page list
468 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
469 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
470 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
471 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
472 ; mutable pagecount
: int
473 ; mutable currently
: currently
474 ; mutable mstate
: mstate
475 ; mutable searchpattern
: string
476 ; mutable rects
: (pageno
* recttype
* rect
) list
477 ; mutable rects1
: (pageno
* recttype
* rect
) list
478 ; mutable text
: string
479 ; mutable winstate
: Wsi.winstate list
480 ; mutable mode
: mode
481 ; mutable uioh
: uioh
482 ; mutable outlines
: outline array
483 ; mutable bookmarks
: outline list
484 ; mutable path
: string
485 ; mutable password
: string
486 ; mutable nameddest
: string
487 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
488 ; mutable memused
: memsize
490 ; mutable throttle
: (page list
* int * float) option
491 ; mutable autoscroll
: int option
492 ; mutable ghyll
: (int option -> unit)
493 ; mutable help
: helpitem array
494 ; mutable docinfo
: (int * string) list
495 ; mutable texid
: GlTex.texture_id
option
497 ; mutable prevzoom
: (float * int)
498 ; mutable progress
: float
499 ; mutable redisplay
: bool
500 ; mutable mpos
: mpos
501 ; mutable keystate
: keystate
502 ; mutable glinks
: bool
503 ; mutable prevcolumns
: (columns
* float) option
506 ; mutable reprf
: (unit -> unit)
507 ; mutable origin
: string
508 ; mutable roam
: (unit -> unit)
509 ; mutable bzoom
: bool
510 ; mutable traw
: [`
float] Raw.t
511 ; mutable vraw
: [`
float] Raw.t
514 { pat
: string circbuf
515 ; pag
: string circbuf
516 ; nav
: anchor circbuf
517 ; sel
: string circbuf
524 ; scrollb
= scrollbhv lor scrollbvv
540 ; presentation
= false
545 ; fitmodel
= FitProportional
546 ; trimmargins
= false
547 ; trimfuzz
= (0,0,0,0)
548 ; memlimit
= 32 lsl 20
553 ; bgcolor
= (0.5, 0.5, 0.5)
557 ; mustoresize
= 256 lsl 20
562 | Plinux
| Pfreebsd
| Pdragonflybsd
563 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
564 | Posx
-> "open \"%s\""
565 | Pcygwin
-> "cygstart \"%s\""
566 | Punknown
-> "echo %s")
567 ; pathlauncher
= "lp \"%s\""
570 | Plinux
| Pfreebsd
| Pdragonflybsd
571 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
579 ; redirectstderr
= false
581 ; columns
= Csingle
[||]
587 ; wheelbypage
= false
588 ; stcmd
= "echo SyncTex"
591 ; paxmark
= Mark_word
593 let mk n
= (n
, Hashtbl.create
1) in
607 let wtmode = ref false;;
608 let cxack = ref false;;
610 let findkeyhash c name
=
611 try List.assoc name c
.keyhashes
612 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
615 let conf = { defconf with angle
= defconf.angle
};;
617 let pgscale h
= truncate
(float h
*. conf.pgscale);;
620 { mutable fontsize
: int
621 ; mutable wwidth
: float
622 ; mutable maxrows
: int
634 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
635 let len = String.length s
in
636 if colonpos >= 0 && colonpos + 3 < len
638 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
641 try String.rindex_from s
colonpos ' '
645 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
648 | "http" | "ftp" | "mailto" ->
650 try String.index_from s
colonpos ' '
651 with Not_found
-> len
653 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
661 if emptystr
conf.urilauncher
662 then print_endline uri
664 let url = geturl uri
in
666 then Printf.eprintf
"obtained empty url from uri %S" uri
668 let re = Str.regexp
"%s" in
669 let command = Str.global_replace
re url conf.urilauncher
in
673 "failed to execute `%s': %s\n" command (exntos exn
);
679 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
680 Help.version (fz_version
()) Sys.ocaml_version
681 (platform_to_string platform) Sys.word_size
685 let strings = version () :: "" :: Help.keys
in
688 let url = geturl s
in
690 then (s
, 0, Action
(fun u
-> gotouri url; u
))
691 else (s
, 0, Noaction
)
696 let firstgeomcmds = "", [];;
697 let noreprf () = ();;
704 ; stderr
= Unix.stderr
705 ; errmsgs
= Buffer.create
0
710 ; anchor
= emptyanchor
714 ; tilelru
= Queue.create
()
715 ; pagemap
= Hashtbl.create
10
716 ; tilemap
= Hashtbl.create
10
732 ; geomcmds
= firstgeomcmds
734 { nav
= cbnew 10 emptyanchor
747 ; prevzoom
= (1.0, 0)
759 ; roam
= (fun () -> ())
761 ; traw
= Raw.create_static `
float 8
762 ; vraw
= Raw.create_static `
float 8
767 if (conf.scrollb
land scrollbhv = 0)
768 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
774 if (conf.scrollb
land scrollbvv = 0)
779 let wadjsb w
= w
- vscrollw ();;
782 fstate.fontsize
<- n
;
783 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
784 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
790 Printf.kprintf prerr_endline fmt
792 Printf.kprintf ignore fmt
796 if emptystr
conf.pathlauncher
797 then print_endline
state.path
799 let re = Str.regexp
"%s" in
800 let command = Str.global_replace
re state.path
conf.pathlauncher
in
803 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
809 type 'a t
= | Res
of 'a
| Exn
of exn
;;
812 try Res
(Unix.pipe ())
817 try tempfailureretry
Unix.close fd
818 with exn
-> f
(exntos exn
)
822 try Res
(tempfailureretry
Unix.dup fd
)
827 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
832 let redirectstderr () =
833 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
834 if conf.redirectstderr
836 match Ne.pipe () with
838 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
841 begin match Ne.dup Unix.stderr
with
843 dolog
"failed to dup stderr: %s" (exntos exn
);
844 Ne.clo r
(clofail "pipe/r");
845 Ne.clo w
(clofail "pipe/w");
847 | Ne.Res dupstderr
->
848 begin match Ne.dup2 w
Unix.stderr
with
850 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
851 Ne.clo dupstderr
(clofail "stderr duplicate");
852 Ne.clo r
(clofail "redir pipe/r");
853 Ne.clo w
(clofail "redir pipe/w");
856 state.stderr
<- dupstderr
;
857 state.errfd
<- Some r
;
861 state.newerrmsgs
<- false;
862 begin match state.errfd
with
864 begin match Ne.dup2 state.stderr
Unix.stderr
with
866 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
868 Ne.clo fd
(clofail "dup of stderr");
873 prerr_string
(Buffer.contents
state.errmsgs
);
875 Buffer.clear
state.errmsgs
;
881 let postRedisplay who
=
883 then prerr_endline
("redisplay for " ^ who
);
884 state.redisplay
<- true;
888 let getopaque pageno
=
889 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
890 with Not_found
-> None
893 let putopaque pageno opaque
=
894 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
897 let pagetranslatepoint l x y
=
898 let dy = y
- l
.pagedispy
in
899 let y = dy + l
.pagey
in
900 let dx = x
- l
.pagedispx
in
901 let x = dx + l
.pagex
in
905 let onppundermouse g
x y d
=
908 begin match getopaque l
.pageno
with
910 let x0 = l
.pagedispx
in
911 let x1 = x0 + l
.pagevw
in
912 let y0 = l
.pagedispy
in
913 let y1 = y0 + l
.pagevh
in
914 if y >= y0 && y <= y1 && x >= x0 && x <= x1
916 let px, py
= pagetranslatepoint l
x y in
917 match g opaque l
px py
with
930 let g opaque l
px py
=
933 match rectofblock opaque
px py
with
935 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
936 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
937 G.postRedisplay "getunder";
940 match whatsunder opaque
px py
with
942 | under
-> Some under
944 onppundermouse g x y Unone
949 match unproject opaque
x y with
950 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
953 onppundermouse g x y None
;
957 state.text
<- Printf.sprintf
"%c%s" c s
;
958 G.postRedisplay "showtext";
962 let g opaque l
px py
=
963 if markunder opaque
px py
conf.paxmark
966 match getopaque l
.pageno
with
969 match Ne.pipe () with
973 "can not create mark pipe: %s"
976 let doclose what fd
=
977 Ne.clo fd
(fun msg
->
978 dolog
"%s close failed: %s" what msg
)
981 popen conf.paxcmd
[r
, 0; w
, -1];
982 copysel w opaque
false;
984 G.postRedisplay "paxunder";
986 dolog
"can not execute %S: %s"
987 conf.paxcmd
(exntos exn
);
994 G.postRedisplay "paxunder";
995 if conf.paxmark
= Mark_page
998 match getopaque l
.pageno
with
1000 | Some opaque
-> clearmark opaque
) state.layout
;
1002 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1006 match Ne.pipe () with
1008 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1011 try popen conf.selcmd
[r
, 0; w
, -1]; true
1014 (Printf.sprintf
"failed to execute %s: %s"
1015 conf.selcmd
(exntos exn
));
1019 Ne.clo fd
(fun msg
->
1020 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1026 let l = String.length s
in
1027 let n = tempfailureretry
(Unix.write w s
0) l in
1032 "failed to write %d characters to sel pipe, wrote %d"
1037 (Printf.sprintf
"failed to write to sel pipe: %s"
1046 let undertext = function
1049 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1050 | Utext s
-> "font: " ^ s
1051 | Uunexpected s
-> "unexpected: " ^ s
1052 | Ulaunch s
-> "launch: " ^ s
1053 | Unamed s
-> "named: " ^ s
1054 | Uremote
(filename
, pageno
) ->
1055 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1056 | Uremotedest
(filename
, destname
) ->
1057 Printf.sprintf
"%s: destination %S" filename destname
1060 let updateunder x y =
1061 match getunder x y with
1062 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1064 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1065 Wsi.setcursor
Wsi.CURSOR_INFO
1066 | Ulinkgoto
(pageno
, _
) ->
1068 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1069 Wsi.setcursor
Wsi.CURSOR_INFO
1071 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1072 Wsi.setcursor
Wsi.CURSOR_TEXT
1074 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1075 Wsi.setcursor
Wsi.CURSOR_INHERIT
1077 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1078 Wsi.setcursor
Wsi.CURSOR_INHERIT
1080 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1081 Wsi.setcursor
Wsi.CURSOR_INHERIT
1082 | Uremote
(filename
, pageno
) ->
1083 if conf.underinfo
then showtext 'r'
1084 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1085 Wsi.setcursor
Wsi.CURSOR_INFO
1086 | Uremotedest
(filename
, destname
) ->
1087 if conf.underinfo
then showtext 'r'
1088 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1089 Wsi.setcursor
Wsi.CURSOR_INFO
1092 let showlinktype under
=
1098 let s = undertext under
in
1103 let b = Buffer.create
(String.length
s + 1) in
1104 Buffer.add_string
b s;
1105 Buffer.add_char
b c
;
1109 module type TextEnumType
=
1113 val names
: string array
1116 module TextEnumMake
(Ten
: TextEnumType
) =
1118 let names = Ten.names;;
1119 let to_int (t
: Ten.t
) = Obj.magic t
;;
1120 let to_string t
= names.(to_int t
);;
1121 let of_int n : Ten.t
= Obj.magic
n;;
1124 if i
= Array.length
names
1125 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1127 if Ten.names.(i
) = s
1134 module CSTE
= TextEnumMake
(struct
1135 type t
= colorspace
;;
1136 let name = "colorspace";;
1137 let names = [|"rgb"; "bgr"; "gray"|];;
1140 module MTE
= TextEnumMake
(struct
1143 let names = [|"page"; "block"; "line"; "word"|];;
1146 module FMTE
= TextEnumMake
(struct
1148 let name = "fitmodel";;
1149 let names = [|"width"; "proportional"; "page"|];;
1152 let intentry_with_suffix text key
=
1154 if key
>= 32 && key
< 127
1158 match Char.lowercase
c with
1160 let text = addchar text c in
1163 | 'k'
| 'm'
| '
g'
->
1164 let text = addchar text c in
1168 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1172 let multicolumns_to_string (n, a
, b) =
1174 then Printf.sprintf
"%d" n
1175 else Printf.sprintf
"%d,%d,%d" n a
b;
1178 let multicolumns_of_string s =
1180 (int_of_string
s, 0, 0)
1182 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1184 then failwith
"subtly broken"; (n, a
, b)
1190 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1191 if n != 4 then error
"incomplete read(len) = %d" n;
1193 lor (Char.code
s.[0] lsl 24)
1194 lor (Char.code
s.[1] lsl 16)
1195 lor (Char.code
s.[2] lsl 8)
1196 lor (Char.code
s.[3] lsl 0)
1198 let s = String.create
len in
1199 let n = tempfailureretry
(Unix.read fd
s 0) len in
1200 if n != len then error
"incomplete read(data) %d vs %d" n len;
1204 let btod b = if b then 1 else 0;;
1207 let b = Buffer.create
16 in
1208 Buffer.add_string
b "llll";
1211 let s = Buffer.contents
b in
1212 let n = String.length
s in
1214 (* dolog "wcmd %S" (String.sub s 4 len); *)
1215 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1216 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1217 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1218 s.[3] <- Char.chr
(len land 0xff);
1219 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1220 if n'
!= n then error
"write failed %d vs %d" n'
n;
1225 let d = state.winh
- h
in
1226 max
conf.interpagespace
((d + 1) / 2)
1229 let rowyh (c, coverA
, coverB
) b n =
1230 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1232 let _, _, vy
, (_, _, h
, _) = b.(n) in
1235 let n'
= n - coverA
in
1238 let e = min
state.pagecount
(s + c) in
1239 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1240 let _, _, y, (_, _, h
, _) = b.(m
) in
1241 let miny = min
miny y in
1242 let maxh = max
maxh h
in
1243 find (m
+1) miny maxh
1248 match conf.columns
with
1249 | Cmulti
((_, _, _) as cl
, b) ->
1250 if Array.length
b > 0
1252 let y, h
= rowyh cl
b (Array.length
b - 1) in
1253 y + h
+ (if conf.presentation
then calcips h
else 0)
1256 if Array.length
b > 0
1258 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1259 y + h
+ (if conf.presentation
then calcips h
else 0)
1262 if Array.length
b > 0
1264 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1269 let getpageywh pageno
=
1270 let pageno = bound pageno 0 (state.pagecount
-1) in
1271 match conf.columns
with
1273 if Array.length
b = 0
1276 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1278 if conf.presentation
1284 if Array.length
b = 0
1287 let y, h
= rowyh cl
b pageno in
1288 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1290 if conf.presentation
1296 if Array.length
b = 0
1300 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1304 let getpageyh pageno =
1305 let y,_,h
= getpageywh pageno in
1309 let getpagedim pageno =
1312 | (n, _, _, _) as pdim
:: rest
->
1314 then (if n = pageno then pdim
else ppdim
)
1319 f (-1, -1, -1, -1) state.pdims
1322 let getpagey pageno = fst
(getpageyh pageno);;
1324 let nogeomcmds cmds
=
1326 | s, [] -> emptystr
s
1331 let ((c, coverA
, coverB
) as cl
), b =
1332 match conf.columns
with
1333 | Csingle
b -> (1, 0, 0), b
1334 | Cmulti
(c, b) -> c, b
1335 | Csplit
(_, b) -> (1, 0, 0), b
1337 if Array.length
b = 0
1340 let rec bsearch nmin nmax
=
1342 then bound nmin
0 (state.pagecount
-1)
1344 let n = (nmax
+ nmin
) / 2 in
1345 let vy, h
= rowyh cl
b n in
1347 if conf.presentation
1349 let ips = calcips h
in
1350 let y0 = vy - ips in
1351 let y1 = vy + h
+ ips in
1355 then 0, vy + h
+ conf.interpagespace
1357 let y0 = vy - conf.interpagespace
in
1358 y0, y0 + h
+ conf.interpagespace
1361 if y >= y0 && y < y1
1368 if n < state.pagecount
- coverB
1369 then ((n-coverA
)/c)*c + coverA
1376 then bsearch (n+1) nmax
1377 else bsearch nmin
(n-1)
1380 bsearch 0 (state.pagecount
-1);
1383 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1384 let sh = sh - (hscrollh ()) in
1385 let rec fold accu
n =
1386 if n = Array.length
b
1389 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1392 || n = state.pagecount
- coverB
1393 || (n - coverA
) mod columns
= columns
- 1)
1399 let pagey = max
0 (y - vy) in
1400 let pagedispy = if pagey > 0 then 0 else vy - y in
1401 let pagedispx, pagex
=
1403 if n = coverA
- 1 || n = state.pagecount
- coverB
1404 then state.x + (wadjsb state.winw
- w
) / 2
1405 else dx + xoff
+ state.x
1412 let vw = wadjsb state.winw
- pagedispx in
1413 let pw = w
- pagex
in
1416 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1417 if pagevw > 0 && pagevh > 0
1421 ; pagedimno
= pdimno
1428 ; pagedispx = pagedispx
1429 ; pagedispy = pagedispy
1441 if Array.length
b = 0
1443 else List.rev
(fold [] (page_of_y y))
1446 let layoutS (columns
, b) y sh =
1447 let sh = sh - hscrollh () in
1448 let rec fold accu n =
1449 if n = Array.length
b
1452 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1459 let x = xoff
+ state.x in
1460 let pagey = max
0 (y - vy) in
1461 let pagedispy = if pagey > 0 then 0 else vy - y in
1462 let pagedispx, pagex
=
1476 let pagecolw = pagew
/columns
in
1478 if pagecolw < state.winw
1479 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1483 let vw = wadjsb state.winw
- pagedispx in
1484 let pw = pagew
- pagex
in
1487 let pagevw = min
pagevw pagecolw in
1488 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1489 if pagevw > 0 && pagevh > 0
1492 { pageno = n/columns
1493 ; pagedimno
= pdimno
1500 ; pagedispx = pagedispx
1501 ; pagedispy = pagedispy
1502 ; pagecol
= n mod columns
1513 List.rev
(fold [] 0)
1517 if nogeomcmds state.geomcmds
1519 match conf.columns
with
1520 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1521 | Cmulti
c -> layoutN c y sh
1522 | Csplit
s -> layoutS s y sh
1527 let y = state.y + incr
in
1529 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1534 let tilex = l.pagex
mod conf.tilew
in
1535 let tiley = l.pagey mod conf.tileh
in
1537 let col = l.pagex
/ conf.tilew
in
1538 let row = l.pagey / conf.tileh
in
1540 let rec rowloop row y0 dispy h
=
1544 let dh = conf.tileh
- y0 in
1545 let dh = min h
dh in
1546 let rec colloop col x0 dispx w
=
1550 let dw = conf.tilew
- x0 in
1551 let dw = min w
dw in
1553 f col row dispx dispy
x0 y0 dw dh;
1554 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1557 colloop col tilex l.pagedispx l.pagevw;
1558 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1561 if l.pagevw > 0 && l.pagevh > 0
1562 then rowloop row tiley l.pagedispy l.pagevh;
1565 let gettileopaque l col row =
1567 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1569 try Some
(Hashtbl.find state.tilemap
key)
1570 with Not_found
-> None
1573 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1574 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1575 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1578 let filledrect x0 y0 x1 y1 =
1579 GlArray.disable `texture_coord
;
1580 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1581 GlArray.vertex `two
state.vraw
;
1582 GlArray.draw_arrays `triangle_strip
0 4;
1583 GlArray.enable `texture_coord
;
1586 let linerect x0 y0 x1 y1 =
1587 GlArray.disable `texture_coord
;
1588 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1589 GlArray.vertex `two
state.vraw
;
1590 GlArray.draw_arrays `line_loop
0 4;
1591 GlArray.enable `texture_coord
;
1594 let drawtiles l color
=
1597 let f col row x y tilex tiley w h
=
1598 match gettileopaque l col row with
1599 | Some
(opaque
, _, t
) ->
1600 let params = x, y, w
, h
, tilex, tiley in
1604 GlFunc.blend_func `zero `one_minus_src_color
;
1606 drawtile
params opaque
;
1608 then Gl.disable `blend
;
1611 let s = Printf.sprintf
1615 let w = measurestr
fstate.fontsize
s in
1616 GlDraw.color
(0.0, 0.0, 0.0);
1617 filledrect (float (x-2))
1620 (float (y + fstate.fontsize
+ 2));
1621 GlDraw.color
(1.0, 1.0, 1.0);
1622 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1628 let lw = wadjsb state.winw
- x in
1631 let lh = state.winh
- y in
1634 begin match state.texid
with
1636 Gl.enable `texture_2d
;
1637 GlTex.bind_texture `texture_2d id
;
1640 and x1 = float (x+w)
1641 and y1 = float (y+h
) in
1643 let tw = float w /. 16.0
1644 and th
= float h
/. 16.0 in
1645 let tx0 = float tilex /. 16.0
1646 and ty0
= float tiley /. 16.0 in
1648 and ty1
= ty0
+. th
in
1649 Raw.sets_float
state.vraw ~pos
:0
1650 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1651 Raw.sets_float
state.traw ~pos
:0
1652 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1653 GlArray.vertex `two
state.vraw
;
1654 GlArray.tex_coord `two
state.traw
;
1655 GlArray.draw_arrays `triangle_strip
0 4;
1658 GlDraw.color
(1.0, 1.0, 1.0);
1659 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1661 if w > 128 && h
> fstate.fontsize
+ 10
1663 GlDraw.color
(0.0, 0.0, 0.0);
1666 then (col*conf.tilew
, row*conf.tileh
)
1669 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1678 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1680 let tilevisible1 l x y =
1682 and ax1
= l.pagex
+ l.pagevw
1684 and ay1
= l.pagey + l.pagevh in
1688 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1689 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1691 let rx0 = max
ax0 bx0
1692 and ry0
= max ay0 by0
1693 and rx1
= min ax1
bx1
1694 and ry1
= min ay1 by1
in
1696 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1697 nonemptyintersection
1700 let tilevisible layout n x y =
1701 let rec findpageinlayout m
= function
1702 | l :: rest
when l.pageno = n ->
1703 tilevisible1 l x y || (
1704 match conf.columns
with
1705 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1708 | _ :: rest
-> findpageinlayout 0 rest
1711 findpageinlayout 0 layout;
1714 let tileready l x y =
1715 tilevisible1 l x y &&
1716 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1719 let tilepage n p
layout =
1720 let rec loop = function
1724 let f col row _ _ _ _ _ _ =
1725 if state.currently
= Idle
1727 match gettileopaque l col row with
1730 let x = col*conf.tilew
1731 and y = row*conf.tileh
in
1733 let w = l.pagew
- x in
1737 let h = l.pageh
- y in
1742 then getpbo
w h conf.colorspace
1745 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1748 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1749 conf.tilew
, conf.tileh
1758 if nogeomcmds state.geomcmds
1762 let preloadlayout y =
1763 let y = if y < state.winh
then 0 else y - state.winh
in
1764 let h = state.winh
*3 in
1769 let rec loop pages
=
1770 if state.currently
!= Idle
1775 begin match getopaque l.pageno with
1777 wcmd "page %d %d" l.pageno l.pagedimno
;
1778 state.currently
<- Loading
(l, state.gen
);
1780 tilepage l.pageno opaque pages
;
1785 if nogeomcmds state.geomcmds
1791 if conf.preload && state.currently
= Idle
1792 then load (preloadlayout state.y);
1795 let layoutready layout =
1796 let rec fold all ls
=
1797 all
&& match ls
with
1799 let seen = ref false in
1800 let allvisible = ref true in
1801 let foo col row _ _ _ _ _ _ =
1803 allvisible := !allvisible &&
1804 begin match gettileopaque l col row with
1810 fold (!seen && !allvisible) rest
1813 let alltilesvisible = fold true layout in
1818 let y = bound y 0 state.maxy
in
1819 let y, layout, proceed
=
1820 match conf.maxwait
with
1821 | Some time
when state.ghyll
== noghyll ->
1822 begin match state.throttle
with
1824 let layout = layout y state.winh
in
1825 let ready = layoutready layout in
1829 state.throttle
<- Some
(layout, y, now ());
1831 else G.postRedisplay "gotoy showall (None)";
1833 | Some
(_, _, started
) ->
1834 let dt = now () -. started
in
1837 state.throttle
<- None
;
1838 let layout = layout y state.winh
in
1840 G.postRedisplay "maxwait";
1847 let layout = layout y state.winh
in
1848 if not
!wtmode || layoutready layout
1849 then G.postRedisplay "gotoy ready";
1855 state.layout <- layout;
1856 begin match state.mode
with
1857 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1858 let rec loop = function
1860 state.mode
<- LinkNav
(Ltgendir
0)
1861 | l :: _ when l.pageno = pageno ->
1862 begin match getopaque pageno with
1864 state.mode
<- LinkNav
(Ltgendir
0)
1866 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1867 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1868 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1869 then state.mode
<- LinkNav
(Ltgendir
0)
1871 | _ :: rest
-> loop rest
1876 begin match state.mode
with
1877 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1878 if not
(pagevisible layout pageno)
1880 match state.layout with
1883 state.mode
<- Birdseye
(
1884 conf, leftx
, l.pageno, hooverpageno
, anchor
1887 | LinkNav
(Ltgendir dir
as lt
) ->
1889 let rec loop = function
1892 match getopaque l.pageno with
1898 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1900 if dir
> 0 then LDfirst
else LDlast
1906 | Lnotfound
-> loop rest
1908 showlinktype (getlink opaque
n);
1909 Ltexact
(l.pageno, n)
1913 state.mode
<- LinkNav
linknav
1918 state.ghyll
<- noghyll;
1921 let mx, my
= state.mpos
in
1926 let conttiling pageno opaque
=
1927 tilepage pageno opaque
1928 (if conf.preload then preloadlayout state.y else state.layout)
1931 let gotoy_and_clear_text y =
1932 if not
conf.verbose
then state.text <- "";
1938 let coloff = l.pagecol
* l.pageh
in
1939 float (l.pagey + coloff) /. float l.pageh
1946 if conf.presentation
1947 then float l.pagedispy /. float (calcips l.pageh
)
1948 else float l.pagedispy /. float conf.interpagespace
1951 (l.pageno, top, dtop)
1955 match state.layout with
1956 | l :: _ -> getanchor1 l
1958 let n = page_of_y state.y in
1962 let y, h = getpageyh n in
1963 let dy = y - state.y in
1965 if conf.presentation
1967 let ips = calcips h in
1968 float (dy + ips) /. float ips
1970 float dy /. float conf.interpagespace
1975 let getanchory (n, top, dtop) =
1976 let y, h = getpageyh n in
1977 if conf.presentation
1979 let ips = calcips h in
1980 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1982 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1985 let gotoanchor anchor
=
1986 gotoy (getanchory anchor
);
1990 cbput state.hists
.nav
(getanchor ());
1994 let anchor = cbgetc state.hists
.nav dir
in
1999 let scroll f n a
b =
2000 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2002 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2004 then s (float f /. float a
)
2007 then 1.0 -. s ((float (f-b) /. float (n-b)))
2013 let ins = float a
*. 0.5
2014 and outs
= float (n-b) *. 0.5 in
2016 ins +. outs
+. float ones
2018 let rec set (_N
, _A
, _B
) y sy
=
2019 let sum = summa _N _A _B
in
2020 let dy = float (y - sy
) in
2024 then state.ghyll
<- noghyll
2027 let s = scroll n _N _A _B
in
2028 let y1 = y1 +. ((s *. dy) /. sum) in
2029 gotoy_and_clear_text (truncate
y1);
2030 state.ghyll
<- gf (n+1) y1;
2034 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2036 gf 0 (float state.y)
2039 match conf.ghyllscroll
with
2041 gotoy_and_clear_text y
2043 if state.ghyll
== noghyll
2044 then set nab
y state.y
2045 else state.ghyll
(Some
y)
2048 let gotopage n top =
2049 let y, h = getpageyh n in
2050 let y = y + (truncate
(top *. float h)) in
2054 let gotopage1 n top =
2055 let y = getpagey n in
2060 let invalidate s f =
2065 match state.geomcmds
with
2066 | ps
, [] when emptystr ps
->
2068 state.geomcmds
<- s, [];
2071 state.geomcmds
<- ps
, [s, f];
2073 | ps
, (s'
, _) :: rest
when s'
= s ->
2074 state.geomcmds
<- ps
, ((s, f) :: rest
);
2077 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2081 Hashtbl.iter
(fun _ opaque
->
2082 wcmd "freepage %s" opaque
;
2084 Hashtbl.clear
state.pagemap
;
2088 if not
(Queue.is_empty
state.tilelru
)
2090 Queue.iter
(fun (k
, p
, s) ->
2091 wcmd "freetile %s" p
;
2092 state.memused
<- state.memused
- s;
2093 Hashtbl.remove
state.tilemap k
;
2095 state.uioh#infochanged Memused
;
2096 Queue.clear
state.tilelru
;
2102 let h = truncate
(float h*.conf.zoom
) in
2103 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2107 let opendoc path password
=
2109 state.password
<- password
;
2110 state.gen
<- state.gen
+ 1;
2111 state.docinfo
<- [];
2114 setaalevel
conf.aalevel
;
2116 if emptystr
state.origin
2120 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2121 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2122 invalidate "reqlayout"
2124 wcmd "reqlayout %d %d %d %s\000"
2125 conf.angle
(FMTE.to_int conf.fitmodel
)
2126 (stateh state.winh
) state.nameddest
2131 state.anchor <- getanchor ();
2132 opendoc state.path
state.password
;
2136 let c = c *. conf.colorscale
in
2140 let scalecolor2 (r
, g, b) =
2141 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2144 let docolumns = function
2146 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2147 let rec loop pageno pdimno pdim
y ph pdims
=
2148 if pageno = state.pagecount
2151 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2153 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2154 pdimno+1, pdim
, rest
2158 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2160 (if conf.presentation
2161 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2162 else (if pageno = 0 then 0 else conf.interpagespace
)
2165 a.(pageno) <- (pdimno, x, y, pdim
);
2166 loop (pageno+1) pdimno pdim
(y + h) h pdims
2168 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2169 conf.columns
<- Csingle
a;
2171 | Cmulti
((columns
, coverA
, coverB
), _) ->
2172 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2173 let rec loop pageno pdimno pdim
x y rowh pdims
=
2174 let rec fixrow m
= if m
= pageno then () else
2175 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2178 let y = y + (rowh
- h) / 2 in
2179 a.(m
) <- (pdimno, x, y, pdim
);
2183 if pageno = state.pagecount
2184 then fixrow (((pageno - 1) / columns
) * columns
)
2186 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2188 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2189 pdimno+1, pdim
, rest
2194 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2196 let x = (wadjsb state.winw
- w) / 2 in
2198 if conf.presentation
then calcips h else conf.interpagespace
in
2199 x, y + ips + rowh
, h
2202 if (pageno - coverA
) mod columns
= 0
2204 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2206 if conf.presentation
2208 let ips = calcips h in
2209 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2211 y + (if pageno = 0 then 0 else conf.interpagespace
)
2215 else x, y, max rowh
h
2219 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2222 if pageno = columns
&& conf.presentation
2224 let ips = calcips rowh
in
2225 for i
= 0 to pred columns
2227 let (pdimno, x, y, pdim
) = a.(i
) in
2228 a.(i
) <- (pdimno, x, y+ips, pdim
)
2234 fixrow (pageno - columns
);
2239 a.(pageno) <- (pdimno, x, y, pdim
);
2240 let x = x + w + xoff
*2 + conf.interpagespace
in
2241 loop (pageno+1) pdimno pdim
x y rowh' pdims
2243 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2244 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2247 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2248 let rec loop pageno pdimno pdim
y pdims
=
2249 if pageno = state.pagecount
2252 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2254 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2255 pdimno+1, pdim
, rest
2260 let rec loop1 n x y =
2261 if n = c then y else (
2262 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2263 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2266 let y = loop1 0 0 y in
2267 loop (pageno+1) pdimno pdim
y pdims
2269 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2270 conf.columns
<- Csplit
(c, a);
2274 docolumns conf.columns
;
2275 state.maxy
<- calcheight ();
2276 if state.reprf
== noreprf
2278 match state.mode
with
2279 | Birdseye
(_, _, pageno, _, _) ->
2280 let y, h = getpageyh pageno in
2281 let top = (state.winh
- h) / 2 in
2282 gotoy (max
0 (y - top))
2283 | _ -> gotoanchor state.anchor
2287 state.reprf
<- noreprf;
2292 GlDraw.viewport
0 0 w h;
2293 let firsttime = state.geomcmds
== firstgeomcmds in
2294 if not
firsttime && nogeomcmds state.geomcmds
2295 then state.anchor <- getanchor ();
2298 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2301 setfontsize fstate.fontsize
;
2302 GlMat.mode `modelview
;
2303 GlMat.load_identity
();
2305 GlMat.mode `projection
;
2306 GlMat.load_identity
();
2307 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2308 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2309 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2314 else float state.x /. float state.w
2316 invalidate "geometry"
2320 then state.x <- truncate
(relx *. float w);
2322 match conf.columns
with
2324 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2325 | Csplit
(c, _) -> w * c
2327 wcmd "geometry %d %d %d"
2328 w (stateh h) (FMTE.to_int conf.fitmodel
)
2333 let len = String.length
state.text in
2336 match state.mode
with
2337 | Textentry
_ | View
| LinkNav
_ ->
2338 let h, _, _ = state.uioh#scrollpw
in
2343 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2344 (x+.w) (float (state.winh
- hscrollh))
2347 let w = float (wadjsb state.winw
- 1) in
2348 if state.progress
>= 0.0 && state.progress
< 1.0
2350 GlDraw.color
(0.3, 0.3, 0.3);
2351 let w1 = w *. state.progress
in
2353 GlDraw.color
(0.0, 0.0, 0.0);
2357 GlDraw.color
(0.0, 0.0, 0.0);
2361 GlDraw.color
(1.0, 1.0, 1.0);
2362 drawstring fstate.fontsize
2363 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2366 match state.mode
with
2367 | Textentry
((prefix
, text, _, _, _, _), _) ->
2371 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2373 Printf.sprintf
"%s%s_" prefix
text
2382 if not
(istextentry state.mode
) && state.uioh#eformsgs
2384 let s1 = "(press 'e' to review error messasges)" in
2385 if nonemptystr
s then s ^
" " ^
s1 else s1
2395 let len = Queue.length
state.tilelru
in
2397 match state.throttle
with
2400 then preloadlayout state.y
2402 | Some
(layout, _, _) ->
2406 if state.memused
<= conf.memlimit
2411 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2412 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2413 let (_, pw, ph
, _) = getpagedim n in
2416 && colorspace
= conf.colorspace
2417 && angle
= conf.angle
2421 let x = col*conf.tilew
2422 and y = row*conf.tileh
in
2423 tilevisible (Lazy.force_val
layout) n x y
2425 then Queue.push lruitem
state.tilelru
2428 wcmd "freetile %s" p
;
2429 state.memused
<- state.memused
- s;
2430 state.uioh#infochanged Memused
;
2431 Hashtbl.remove
state.tilemap k
;
2439 let logcurrently = function
2440 | Idle
-> dolog
"Idle"
2441 | Loading
(l, gen
) ->
2442 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2443 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2445 "Tiling %d[%d,%d] page=%s cs=%s angle"
2446 l.pageno col row pageopaque
2447 (CSTE.to_string colorspace
)
2449 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2450 angle gen
conf.angle
state.gen
2452 conf.tilew
conf.tileh
2459 let r = Str.regexp
" " in
2460 fun s -> Str.bounded_split
r s 2;
2463 let onpagerect pageno f =
2465 match conf.columns
with
2466 | Cmulti
(_, b) -> b
2468 | Csplit
(_, b) -> b
2470 if pageno >= 0 && pageno < Array.length
b
2472 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2476 let gotopagexy1 pageno x y =
2477 let _,w1,h1
,leftx
= getpagedim pageno in
2478 let top = y /. (float h1
) in
2479 let left = x /. (float w1) in
2480 let py, w, h = getpageywh pageno in
2481 let wh = state.winh
- hscrollh () in
2482 let x = left *. (float w) in
2483 let x = leftx
+ state.x + truncate
x in
2485 if x < 0 || x >= wadjsb state.winw
2489 let pdy = truncate
(top *. float h) in
2490 let y'
= py + pdy in
2491 let dy = y'
- state.y in
2493 if x != state.x || not
(dy > 0 && dy < wh)
2495 if conf.presentation
2497 if abs
(py - y'
) > wh
2504 if state.x != sx || state.y != sy
2509 let ww = wadjsb state.winw
in
2511 and qy
= pdy / wh in
2513 and y = py + qy
* wh in
2514 let x = if -x + ww > w1 then -(w1-ww) else x
2515 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2517 if conf.presentation
2519 if abs
(py - y'
) > wh
2529 gotoy_and_clear_text y;
2531 else gotoy_and_clear_text state.y;
2534 let gotopagexy pageno x y =
2535 match state.mode
with
2536 | Birdseye
_ -> gotopage pageno 0.0
2537 | _ -> gotopagexy1 pageno x y
2541 (* dolog "%S" cmds; *)
2542 let cl = splitatspace cmds
in
2544 try Scanf.sscanf
s fmt
f
2546 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2551 state.uioh#infochanged Pdim
;
2554 | "clearrects" :: [] ->
2555 state.rects
<- state.rects1
;
2556 G.postRedisplay "clearrects";
2558 | "continue" :: args :: [] ->
2559 let n = scan args "%u" (fun n -> n) in
2560 state.pagecount
<- n;
2561 begin match state.currently
with
2563 state.currently
<- Idle
;
2564 state.outlines
<- Array.of_list
(List.rev
l)
2568 let cur, cmds
= state.geomcmds
in
2570 then failwith
"umpossible";
2572 begin match List.rev cmds
with
2574 state.geomcmds
<- "", [];
2578 state.geomcmds
<- s, List.rev rest
;
2580 if conf.maxwait
= None
&& not
!wtmode
2581 then G.postRedisplay "continue";
2583 | "title" :: args :: [] ->
2586 | "msg" :: args :: [] ->
2589 | "vmsg" :: args :: [] ->
2591 then showtext ' '
args
2593 | "emsg" :: args :: [] ->
2594 Buffer.add_string
state.errmsgs
args;
2595 state.newerrmsgs
<- true;
2596 G.postRedisplay "error message"
2598 | "progress" :: args :: [] ->
2599 let progress, text =
2602 f, String.sub
args pos
(String.length
args - pos
))
2605 state.progress <- progress;
2606 G.postRedisplay "progress"
2608 | "firstmatch" :: args :: [] ->
2609 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2610 scan args "%u %d %f %f %f %f %f %f %f %f"
2611 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2612 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2614 let y = (getpagey pageno) + truncate
y0 in
2617 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2619 | "match" :: args :: [] ->
2620 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2621 scan args "%u %d %f %f %f %f %f %f %f %f"
2622 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2623 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2626 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2628 | "page" :: args :: [] ->
2629 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2630 begin match state.currently
with
2631 | Loading
(l, gen
) ->
2632 vlog "page %d took %f sec" l.pageno t
;
2633 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2634 begin match state.throttle
with
2636 let preloadedpages =
2638 then preloadlayout state.y
2643 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2644 IntSet.empty
preloadedpages
2647 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2648 if not
(IntSet.mem
pageno set)
2650 wcmd "freepage %s" opaque
;
2656 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2659 state.currently
<- Idle
;
2662 tilepage l.pageno pageopaque state.layout;
2664 load preloadedpages;
2665 if pagevisible state.layout l.pageno
2666 && layoutready state.layout
2667 then G.postRedisplay "page";
2670 | Some
(layout, _, _) ->
2671 state.currently
<- Idle
;
2672 tilepage l.pageno pageopaque layout;
2677 dolog
"Inconsistent loading state";
2678 logcurrently state.currently
;
2682 | "tile" :: args :: [] ->
2683 let (x, y, opaque
, size
, t
) =
2684 scan args "%u %u %s %u %f"
2685 (fun x y p size t
-> (x, y, p
, size
, t
))
2687 begin match state.currently
with
2688 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2689 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2692 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2694 wcmd "freetile %s" opaque
;
2695 state.currently
<- Idle
;
2699 puttileopaque l col row gen cs angle opaque size t
;
2700 state.memused
<- state.memused
+ size
;
2701 state.uioh#infochanged Memused
;
2703 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2704 opaque
, size
) state.tilelru
;
2707 match state.throttle
with
2708 | None
-> state.layout
2709 | Some
(layout, _, _) -> layout
2712 state.currently
<- Idle
;
2714 && conf.colorspace
= cs
2715 && conf.angle
= angle
2716 && tilevisible layout l.pageno x y
2717 then conttiling l.pageno pageopaque;
2719 begin match state.throttle
with
2721 preload state.layout;
2723 && conf.colorspace
= cs
2724 && conf.angle
= angle
2725 && tilevisible state.layout l.pageno x y
2726 && (not
!wtmode || layoutready state.layout)
2727 then G.postRedisplay "tile nothrottle";
2729 | Some
(layout, y, _) ->
2730 let ready = layoutready layout in
2734 state.layout <- layout;
2735 state.throttle
<- None
;
2736 G.postRedisplay "throttle";
2743 dolog
"Inconsistent tiling state";
2744 logcurrently state.currently
;
2748 | "pdim" :: args :: [] ->
2749 let (n, w, h, _) as pdim
=
2750 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2753 match conf.fitmodel
, conf.columns
with
2754 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2757 state.uioh#infochanged Pdim
;
2758 state.pdims
<- pdim :: state.pdims
2760 | "o" :: args :: [] ->
2761 let (l, n, t
, h, pos
) =
2762 scan args "%u %u %d %u %n"
2763 (fun l n t
h pos
-> l, n, t
, h, pos
)
2765 let s = String.sub
args pos
(String.length
args - pos
) in
2766 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2767 begin match state.currently
with
2768 | Outlining outlines
->
2769 state.currently
<- Outlining
(outline :: outlines
)
2771 state.currently
<- Outlining
[outline]
2773 dolog
"invalid outlining state";
2774 logcurrently currently
2777 | "a" :: args :: [] ->
2779 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2781 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2783 | "info" :: args :: [] ->
2784 state.docinfo
<- (1, args) :: state.docinfo
2786 | "infoend" :: [] ->
2787 state.uioh#infochanged Docinfo
;
2788 state.docinfo
<- List.rev
state.docinfo
2791 error
"unknown cmd `%S'" cmds
2796 let action = function
2797 | HCprev
-> cbget cb ~
-1
2798 | HCnext
-> cbget cb
1
2799 | HCfirst
-> cbget cb ~
-(cb
.rc)
2800 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2801 and cancel
() = cb
.rc <- rc
2805 let search pattern forward
=
2806 match conf.columns
with
2808 showtext '
!'
"searching does not work properly in split columns mode"
2810 if nonemptystr pattern
2813 match state.layout with
2816 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2818 wcmd "search %d %d %d %d,%s\000"
2819 (btod conf.icase
) pn py (btod forward
) pattern
;
2822 let intentry text key =
2824 if key >= 32 && key < 127
2830 let text = addchar text c in
2834 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2838 let linknentry text key =
2840 if key >= 32 && key < 127
2846 let text = addchar text c in
2850 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2858 let l = String.length
s in
2859 let rec loop pos
n = if pos
= l then n else
2860 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2861 loop (pos
+1) (n*26 + m)
2864 let rec loop n = function
2867 match getopaque l.pageno with
2868 | None
-> loop n rest
2870 let m = getlinkcount opaque
in
2873 let under = getlink opaque
n in
2876 else loop (n-m) rest
2878 loop n state.layout;
2882 let textentry text key =
2883 if key land 0xff00 = 0xff00
2885 else TEcont
(text ^ toutf8
key)
2888 let reqlayout angle fitmodel
=
2889 match state.throttle
with
2891 if nogeomcmds state.geomcmds
2892 then state.anchor <- getanchor ();
2893 conf.angle
<- angle
mod 360;
2896 match state.mode
with
2897 | LinkNav
_ -> state.mode
<- View
2900 conf.fitmodel
<- fitmodel
;
2901 invalidate "reqlayout"
2903 wcmd "reqlayout %d %d %d"
2904 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2909 let settrim trimmargins trimfuzz
=
2910 if nogeomcmds state.geomcmds
2911 then state.anchor <- getanchor ();
2912 conf.trimmargins
<- trimmargins
;
2913 conf.trimfuzz
<- trimfuzz
;
2914 let x0, y0, x1, y1 = trimfuzz
in
2915 invalidate "settrim"
2917 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2922 match state.throttle
with
2924 let zoom = max
0.0001 zoom in
2925 if zoom <> conf.zoom
2927 state.prevzoom
<- (conf.zoom, state.x);
2929 reshape state.winw
state.winh
;
2930 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2933 | Some
(layout, y, started
) ->
2935 match conf.maxwait
with
2939 let dt = now () -. started
in
2947 let setcolumns mode columns coverA coverB
=
2948 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2952 then showtext '
!'
"split mode doesn't work in bird's eye"
2954 conf.columns
<- Csplit
(-columns
, [||]);
2962 conf.columns
<- Csingle
[||];
2967 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2971 reshape state.winw
state.winh
;
2974 let enterbirdseye () =
2975 let zoom = float conf.thumbw
/. float state.winw
in
2976 let birdseyepageno =
2977 let cy = state.winh
/ 2 in
2981 let rec fold best
= function
2984 let d = cy - (l.pagedispy + l.pagevh/2)
2985 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2986 if abs
d < abs dbest
2993 state.mode
<- Birdseye
(
2994 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2997 conf.presentation
<- false;
2998 conf.interpagespace
<- 10;
2999 conf.hlinks
<- false;
3000 conf.fitmodel
<- FitProportional
;
3002 state.mstate
<- Mnone
;
3003 conf.maxwait
<- None
;
3005 match conf.beyecolumns
with
3008 Cmulti
((c, 0, 0), [||])
3009 | None
-> Csingle
[||]
3011 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3014 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3019 reshape state.winw
state.winh
;
3022 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3024 conf.zoom <- c.zoom;
3025 conf.presentation
<- c.presentation
;
3026 conf.interpagespace
<- c.interpagespace
;
3027 conf.maxwait
<- c.maxwait
;
3028 conf.hlinks
<- c.hlinks
;
3029 conf.fitmodel
<- c.fitmodel
;
3030 conf.beyecolumns
<- (
3031 match conf.columns
with
3032 | Cmulti
((c, _, _), _) -> Some
c
3034 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3037 match c.columns
with
3038 | Cmulti
(c, _) -> Cmulti
(c, [||])
3039 | Csingle
_ -> Csingle
[||]
3040 | Csplit
(c, _) -> Csplit
(c, [||])
3044 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3047 reshape state.winw
state.winh
;
3048 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3052 let togglebirdseye () =
3053 match state.mode
with
3054 | Birdseye vals
-> leavebirdseye vals
true
3055 | View
-> enterbirdseye ()
3059 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3060 let pageno = max
0 (pageno - incr
) in
3061 let rec loop = function
3062 | [] -> gotopage1 pageno 0
3063 | l :: _ when l.pageno = pageno ->
3064 if l.pagedispy >= 0 && l.pagey = 0
3065 then G.postRedisplay "upbirdseye"
3066 else gotopage1 pageno 0
3067 | _ :: rest
-> loop rest
3070 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3073 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3074 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3075 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3076 let rec loop = function
3078 let y, h = getpageyh pageno in
3079 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3081 | l :: _ when l.pageno = pageno ->
3082 if l.pagevh != l.pageh
3083 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3084 else G.postRedisplay "downbirdseye"
3085 | _ :: rest
-> loop rest
3090 let optentry mode
_ key =
3091 let btos b = if b then "on" else "off" in
3092 if key >= 32 && key < 127
3094 let c = Char.chr
key in
3098 try conf.scrollstep
<- int_of_string
s with exc
->
3099 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3101 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3106 conf.autoscrollstep
<- int_of_string
s;
3107 if state.autoscroll
<> None
3108 then state.autoscroll
<- Some
conf.autoscrollstep
3110 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3112 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3117 let n, a, b = multicolumns_of_string s in
3118 setcolumns mode
n a b;
3120 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3122 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3127 let zoom = float (int_of_string
s) /. 100.0 in
3130 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3132 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3137 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3139 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3140 begin match mode
with
3142 leavebirdseye beye
false;
3147 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3149 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3154 Some
(int_of_string
s)
3156 state.text <- Printf.sprintf
"bad integer `%s': %s"
3160 | Some angle
-> reqlayout angle
conf.fitmodel
3163 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3166 conf.icase
<- not
conf.icase
;
3167 TEdone
("case insensitive search " ^
(btos conf.icase
))
3170 conf.preload <- not
conf.preload;
3172 TEdone
("preload " ^
(btos conf.preload))
3175 conf.verbose
<- not
conf.verbose
;
3176 TEdone
("verbose " ^
(btos conf.verbose
))
3179 conf.debug
<- not
conf.debug
;
3180 TEdone
("debug " ^
(btos conf.debug
))
3183 conf.maxhfit
<- not
conf.maxhfit
;
3184 state.maxy
<- calcheight ();
3185 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3188 conf.crophack
<- not
conf.crophack
;
3189 TEdone
("crophack " ^
btos conf.crophack
)
3193 match conf.maxwait
with
3195 conf.maxwait
<- Some infinity
;
3196 "always wait for page to complete"
3198 conf.maxwait
<- None
;
3199 "show placeholder if page is not ready"
3204 conf.underinfo
<- not
conf.underinfo
;
3205 TEdone
("underinfo " ^
btos conf.underinfo
)
3208 conf.savebmarks
<- not
conf.savebmarks
;
3209 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3215 match state.layout with
3220 conf.interpagespace
<- int_of_string
s;
3221 docolumns conf.columns
;
3222 state.maxy
<- calcheight ();
3223 let y = getpagey pageno in
3226 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3228 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3232 match conf.fitmodel
with
3233 | FitProportional
-> FitWidth
3234 | _ -> FitProportional
3236 reqlayout conf.angle
fm;
3237 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3240 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3241 TEdone
("trim margins " ^
btos conf.trimmargins
)
3244 conf.invert
<- not
conf.invert
;
3245 TEdone
("invert colors " ^
btos conf.invert
)
3249 cbput state.hists
.sel
s;
3252 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3253 textentry, ondone, true)
3257 then conf.pax
<- Some
(ref (0.0, 0, 0))
3258 else conf.pax
<- None
;
3259 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3262 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3268 class type lvsource
= object
3269 method getitemcount
: int
3270 method getitem
: int -> (string * int)
3271 method hasaction
: int -> bool
3280 method getactive
: int
3281 method getfirst
: int
3282 method getqsearch
: string
3283 method setqsearch
: string -> unit
3287 class virtual lvsourcebase
= object
3288 val mutable m_active
= 0
3289 val mutable m_first
= 0
3290 val mutable m_qsearch
= ""
3291 val mutable m_pan
= 0
3292 method getactive
= m_active
3293 method getfirst
= m_first
3294 method getqsearch
= m_qsearch
3295 method getpan
= m_pan
3296 method setqsearch
s = m_qsearch
<- s
3299 let withoutlastutf8 s =
3300 let len = String.length
s in
3308 let b = Char.code
s.[pos
] in
3309 if b land 0b11000000 = 0b11000000
3314 if Char.code
s.[len-1] land 0x80 = 0
3318 String.sub
s 0 first;
3321 let textentrykeyboard
3322 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3324 if key >= 0xffb0 && key <= 0xffb9
3325 then key - 0xffb0 + 48 else key
3328 state.mode
<- Textentry
(te
, onleave
);
3331 G.postRedisplay "textentrykeyboard enttext";
3333 let histaction cmd
=
3336 | Some
(action, _) ->
3337 state.mode
<- Textentry
(
3338 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3340 G.postRedisplay "textentry histaction"
3343 | 0xff08 -> (* backspace *)
3344 if emptystr
text && cancelonempty
3347 G.postRedisplay "textentrykeyboard after cancel";
3350 let s = withoutlastutf8 text in
3351 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3353 | 0xff0d | 0xff8d -> (* (kp) enter *)
3356 G.postRedisplay "textentrykeyboard after confirm"
3358 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3359 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3360 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3361 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3363 | 0xff1b -> (* escape*)
3366 begin match opthist
with
3368 | Some
(_, onhistcancel
) -> onhistcancel
()
3372 G.postRedisplay "textentrykeyboard after cancel2"
3375 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3378 | 0xff9f | 0xffff -> () (* delete *)
3381 && key land 0xff00 != 0xff00 (* keyboard *)
3382 && key land 0xfe00 != 0xfe00 (* xkb *)
3383 && key land 0xfd00 != 0xfd00 (* 3270 *)
3385 begin match onkey
text key with
3389 G.postRedisplay "textentrykeyboard after confirm2";
3392 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3396 G.postRedisplay "textentrykeyboard after cancel3"
3399 state.mode
<- Textentry
(te
, onleave
);
3400 G.postRedisplay "textentrykeyboard switch";
3404 vlog "unhandled key %s" (Wsi.keyname
key)
3407 let firstof first active
=
3408 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3409 then max
0 (active
- (fstate.maxrows
/2))
3413 let calcfirst first active
=
3416 let rows = active
- first in
3417 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3421 let scrollph y maxy
=
3422 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3423 let sh = float state.winh
/. sh in
3424 let sh = max
sh (float conf.scrollh
) in
3426 let percent = float y /. float maxy
in
3427 let position = (float state.winh
-. sh) *. percent in
3430 if position +. sh > float state.winh
3431 then float state.winh
-. sh
3437 let coe s = (s :> uioh
);;
3439 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3441 val m_pan
= source#getpan
3442 val m_first
= source#getfirst
3443 val m_active
= source#getactive
3444 val m_qsearch
= source#getqsearch
3445 val m_prev_uioh
= state.uioh
3447 method private elemunder
y =
3448 let n = y / (fstate.fontsize
+1) in
3449 if m_first
+ n < source#getitemcount
3451 if source#hasaction
(m_first
+ n)
3452 then Some
(m_first
+ n)
3459 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3460 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3461 filledrect 0. 0. (float state.winw
) (float state.winh
);
3462 GlDraw.color
(1., 1., 1.);
3463 Gl.enable `texture_2d
;
3464 let fs = fstate.fontsize
in
3466 let ww = fstate.wwidth
in
3467 let tabw = 30.0*.ww in
3468 let itemcount = source#getitemcount
in
3470 if (row - m_first
) > fstate.maxrows
3473 if row >= 0 && row < itemcount
3475 let (s, level
) = source#getitem
row in
3476 let y = (row - m_first
) * nfs in
3477 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3480 Gl.disable `texture_2d
;
3481 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3482 GlDraw.color
(1., 1., 1.) ~
alpha;
3483 linerect 1. (float (y + 1))
3484 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3485 GlDraw.color
(1., 1., 1.);
3486 Gl.enable `texture_2d
;
3489 let drawtabularstring s =
3490 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3493 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3496 let len = String.length
s - tabpos - 1 in
3497 let s1 = String.sub
s 0 tabpos
3498 and s2
= String.sub
s (tabpos + 1) len in
3499 let nx = drawstr x s1 in
3501 let x = x +. (max
tabw sw) in
3508 let _ = drawtabularstring s in
3515 Gl.disable `texture_2d
;
3517 method updownlevel incr
=
3518 let len = source#getitemcount
in
3520 if m_active
>= 0 && m_active
< len
3521 then snd
(source#getitem m_active
)
3525 if i
= len then i
-1 else if i
= -1 then 0 else
3526 let _, l = source#getitem i
in
3527 if l != curlevel then i
else flow (i
+incr
)
3529 let active = flow m_active
in
3530 let first = calcfirst m_first
active in
3531 G.postRedisplay "outline updownlevel";
3532 {< m_active
= active; m_first
= first >}
3534 method private key1
key mask
=
3535 let set1 active first qsearch
=
3536 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3538 let search active pattern incr
=
3539 let active = if active = -1 then m_first
else active in
3542 if n >= 0 && n < source#getitemcount
3544 let s, _ = source#getitem
n in
3546 (try ignore
(Str.search_forward
re s 0); true
3547 with Not_found
-> false)
3549 else loop (n + incr
)
3556 let re = Str.regexp_case_fold pattern
in
3562 let itemcount = source#getitemcount
in
3563 let find start incr
=
3565 if i
= -1 || i
= itemcount
3568 if source#hasaction i
3570 else find (i
+ incr
)
3575 let set active first =
3576 let first = bound first 0 (itemcount - fstate.maxrows
) in
3578 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3581 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3583 let incr1 = if incr
> 0 then 1 else -1 in
3584 if isvisible m_first m_active
3587 let next = m_active
+ incr
in
3589 if next < 0 || next >= itemcount
3591 else find next incr1
3593 if abs
(m_active
- next) > fstate.maxrows
3599 let first = m_first
+ incr
in
3600 let first = bound first 0 (itemcount - fstate.maxrows
) in
3602 let next = m_active
+ incr
in
3603 let next = bound next 0 (itemcount - 1) in
3610 if isvisible first next
3617 let first = min
next m_first
in
3619 if abs
(next - first) > fstate.maxrows
3625 let first = m_first
+ incr
in
3626 let first = bound first 0 (itemcount - 1) in
3628 let next = m_active
+ incr
in
3629 let next = bound next 0 (itemcount - 1) in
3630 let next = find next incr1 in
3632 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3634 let active = if m_active
= -1 then next else m_active
in
3639 if isvisible first active
3645 G.postRedisplay "listview navigate";
3649 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3650 let incr = if key = 0x72 then -1 else 1 in
3652 match search (m_active
+ incr) m_qsearch
incr with
3654 state.text <- m_qsearch ^
" [not found]";
3657 state.text <- m_qsearch
;
3658 active, firstof m_first
active
3660 G.postRedisplay "listview ctrl-r/s";
3661 set1 active first m_qsearch
;
3663 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3664 if m_active
>= 0 && m_active
< source#getitemcount
3666 let s, _ = source#getitem m_active
in
3671 | 0xff08 -> (* backspace *)
3672 if emptystr m_qsearch
3675 let qsearch = withoutlastutf8 m_qsearch
in
3679 G.postRedisplay "listview empty qsearch";
3680 set1 m_active m_first
"";
3684 match search m_active
qsearch ~
-1 with
3686 state.text <- qsearch ^
" [not found]";
3689 state.text <- qsearch;
3690 active, firstof m_first
active
3692 G.postRedisplay "listview backspace qsearch";
3693 set1 active first qsearch
3696 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3697 let pattern = m_qsearch ^ toutf8
key in
3699 match search m_active
pattern 1 with
3701 state.text <- pattern ^
" [not found]";
3704 state.text <- pattern;
3705 active, firstof m_first
active
3707 G.postRedisplay "listview qsearch add";
3708 set1 active first pattern;
3710 | 0xff1b -> (* escape *)
3712 if emptystr m_qsearch
3714 G.postRedisplay "list view escape";
3717 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3719 | None
-> m_prev_uioh
3724 G.postRedisplay "list view kill qsearch";
3725 source#setqsearch
"";
3726 coe {< m_qsearch
= "" >}
3729 | 0xff0d | 0xff8d -> (* (kp) enter *)
3731 let self = {< m_qsearch
= "" >} in
3732 source#setqsearch
"";
3734 G.postRedisplay "listview enter";
3735 if m_active
>= 0 && m_active
< source#getitemcount
3737 source#exit
(coe self) false m_active m_first m_pan
"";
3740 source#exit
(coe self) true m_active m_first m_pan
"";
3743 begin match opt with
3744 | None
-> m_prev_uioh
3748 | 0xff9f | 0xffff -> (* (kp) delete *)
3751 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3752 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3753 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3754 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3756 | 0xff53 | 0xff98 -> (* (kp) right *)
3758 G.postRedisplay "listview right";
3759 coe {< m_pan
= m_pan
- 1 >}
3761 | 0xff51 | 0xff96 -> (* (kp) left *)
3763 G.postRedisplay "listview left";
3764 coe {< m_pan
= m_pan
+ 1 >}
3766 | 0xff50 | 0xff95 -> (* (kp) home *)
3767 let active = find 0 1 in
3768 G.postRedisplay "listview home";
3771 | 0xff57 | 0xff9c -> (* (kp) end *)
3772 let first = max
0 (itemcount - fstate.maxrows
) in
3773 let active = find (itemcount - 1) ~
-1 in
3774 G.postRedisplay "listview end";
3777 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3781 dolog
"listview unknown key %#x" key; coe self
3783 method key key mask
=
3784 match state.mode
with
3785 | Textentry te
-> textentrykeyboard key mask te
; coe self
3786 | _ -> self#key1
key mask
3788 method button button down
x y _ =
3791 | 1 when x > state.winw
- conf.scrollbw
->
3792 G.postRedisplay "listview scroll";
3795 let _, position, sh = self#
scrollph in
3796 if y > truncate
position && y < truncate
(position +. sh)
3798 state.mstate
<- Mscrolly
;
3802 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3803 let first = truncate
(s *. float source#getitemcount
) in
3804 let first = min source#getitemcount
first in
3805 Some
(coe {< m_first
= first; m_active
= first >})
3807 state.mstate
<- Mnone
;
3810 | 1 when not down
->
3811 begin match self#elemunder
y with
3813 G.postRedisplay "listview click";
3815 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3819 | n when (n == 4 || n == 5) && not down
->
3820 let len = source#getitemcount
in
3822 if n = 5 && m_first
+ fstate.maxrows
>= len
3826 let first = m_first
+ (if n == 4 then -1 else 1) in
3827 bound first 0 (len - 1)
3829 G.postRedisplay "listview wheel";
3830 Some
(coe {< m_first
= first >})
3831 | n when (n = 6 || n = 7) && not down
->
3832 let inc = if n = 7 then -1 else 1 in
3833 G.postRedisplay "listview hwheel";
3834 Some
(coe {< m_pan
= m_pan
+ inc >})
3839 | None
-> m_prev_uioh
3843 match state.mstate
with
3845 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3846 let first = truncate
(s *. float source#getitemcount
) in
3847 let first = min source#getitemcount
first in
3848 G.postRedisplay "listview motion";
3849 coe {< m_first
= first; m_active
= first >}
3852 method pmotion
x y =
3853 if x < state.winw
- conf.scrollbw
3856 match self#elemunder
y with
3857 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3858 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3862 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3867 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3871 method infochanged
_ = ()
3873 method scrollpw
= (0, 0.0, 0.0)
3875 let nfs = fstate.fontsize
+ 1 in
3876 let y = m_first
* nfs in
3877 let itemcount = source#getitemcount
in
3878 let maxi = max
0 (itemcount - fstate.maxrows
) in
3879 let maxy = maxi * nfs in
3880 let p, h = scrollph y maxy in
3883 method modehash
= modehash
3884 method eformsgs
= false
3887 class outlinelistview ~source
=
3888 let settext autonarrow
s =
3890 then state.text <- "[" ^
s ^
"]"
3891 else state.text <- s
3895 ~source
:(source
:> lvsource
)
3897 ~modehash
:(findkeyhash conf "outline")
3900 val m_autonarrow
= false
3902 method key key mask
=
3904 if emptystr
state.text
3906 else fstate.maxrows - 2
3908 let calcfirst first active =
3911 let rows = active - first in
3912 if rows > maxrows then active - maxrows else first
3916 let active = m_active
+ incr in
3917 let active = bound active 0 (source#getitemcount
- 1) in
3918 let first = calcfirst m_first
active in
3919 G.postRedisplay "outline navigate";
3920 coe {< m_active
= active; m_first
= first >}
3922 let navscroll first =
3924 let dist = m_active
- first in
3930 else first + maxrows
3933 G.postRedisplay "outline navscroll";
3934 coe {< m_first
= first; m_active
= active >}
3936 let ctrl = Wsi.withctrl mask
in
3938 | 97 when ctrl -> (* ctrl-a *)
3940 then source#denarrow
3941 else source#narrow m_qsearch
;
3942 settext (not m_autonarrow
) m_qsearch
;
3943 G.postRedisplay "toggle auto narrowing";
3944 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3946 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3948 G.postRedisplay "toggle auto narrowing";
3949 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3951 | 110 when ctrl -> (* ctrl-n *)
3952 source#narrow m_qsearch
;
3954 then source#add_narrow_pattern m_qsearch
;
3955 G.postRedisplay "outline ctrl-n";
3956 coe {< m_first
= 0; m_active
= 0 >}
3958 | 115 when ctrl -> (* ctrl-s *)
3959 let active = source#calcactive
(getanchor ()) in
3960 let first = firstof m_first
active in
3961 G.postRedisplay "outline ctrl-s";
3962 coe {< m_first
= first; m_active
= active >}
3964 | 117 when ctrl -> (* ctrl-u *)
3965 source#del_narrow_pattern
;
3966 let pattern = source#renarrow
in
3967 G.postRedisplay "outline ctrl-u";
3969 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3971 settext m_autonarrow
text;
3972 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3974 | 108 when ctrl -> (* ctrl-l *)
3975 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3976 G.postRedisplay "outline ctrl-l";
3977 coe {< m_first
= first >}
3979 | 0xff1b -> (* escape *)
3980 let o = super#
key key mask
in
3983 if nonemptystr m_qsearch
3985 source#add_narrow_pattern m_qsearch
;
3991 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3992 if nonemptystr m_qsearch
3993 then source#add_narrow_pattern m_qsearch
;
3996 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3997 let pattern = m_qsearch ^ toutf8
key in
3998 G.postRedisplay "outlinelistview autonarrow add";
3999 source#narrow
pattern;
4000 settext true pattern;
4001 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4003 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4004 if emptystr m_qsearch
4007 let pattern = withoutlastutf8 m_qsearch
in
4008 G.postRedisplay "outlinelistview autonarrow backspace";
4009 ignore
(source#renarrow
);
4010 source#narrow
pattern;
4011 settext true pattern;
4012 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4014 | 0xff9f | 0xffff -> (* (kp) delete *)
4015 source#remove m_active
;
4016 G.postRedisplay "outline delete";
4017 let active = max
0 (m_active
-1) in
4018 coe {< m_first
= firstof m_first
active;
4019 m_active
= active >}
4021 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4022 navscroll (max
0 (m_first
- 1))
4024 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4025 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4027 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4028 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4029 | 0xff55 | 0xff9a -> (* (kp) prior *)
4030 navigate ~
-(fstate.maxrows)
4031 | 0xff56 | 0xff9b -> (* (kp) next *)
4032 navigate fstate.maxrows
4034 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4038 G.postRedisplay "outline ctrl right";
4039 {< m_pan
= m_pan
+ 1 >}
4041 else self#updownlevel
1
4045 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4049 G.postRedisplay "outline ctrl left";
4050 {< m_pan
= m_pan
- 1 >}
4052 else self#updownlevel ~
-1
4056 | 0xff50 | 0xff95 -> (* (kp) home *)
4057 G.postRedisplay "outline home";
4058 coe {< m_first
= 0; m_active
= 0 >}
4060 | 0xff57 | 0xff9c -> (* (kp) end *)
4061 let active = source#getitemcount
- 1 in
4062 let first = max
0 (active - fstate.maxrows) in
4063 G.postRedisplay "outline end";
4064 coe {< m_active
= active; m_first
= first >}
4066 | _ -> super#
key key mask
4069 let outlinesource usebookmarks
=
4072 inherit lvsourcebase
4073 val mutable m_items
= empty
4074 val mutable m_orig_items
= empty
4075 val mutable m_narrow_patterns
= []
4076 val mutable m_hadremovals
= false
4078 method getitemcount
=
4079 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4082 if n == Array.length m_items
&& m_hadremovals
4084 ("[Confirm removal]", 0)
4086 let s, n, _ = m_items
.(n) in
4089 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4090 ignore
(uioh
, first, qsearch);
4091 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4093 if m_narrow_patterns
= []
4099 if not
confrimremoval
4101 let _, _, ((pageno, y, _) as anchor) = m_items
.(active) in
4103 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4109 state.bookmarks
<- Array.to_list m_items
;
4110 m_orig_items
<- m_items
;
4113 else m_items
<- items;
4117 method hasaction
_ = true
4120 if Array.length m_items
!= Array.length m_orig_items
4123 match m_narrow_patterns
with
4125 | many
-> String.concat
" --> " (List.rev many
)
4127 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4130 method narrow
pattern =
4131 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4135 let rec loop accu n =
4137 then m_items
<- Array.of_list
accu
4139 let (s, _, _) as o = m_items
.(n) in
4141 if (try ignore
(Str.search_forward
re s 0); true
4142 with Not_found
-> false)
4148 loop [] (Array.length m_items
- 1)
4153 then Array.of_list
state.bookmarks
4156 m_items
<- m_orig_items
4161 if m >= 0 && m < Array.length m_items
4163 m_hadremovals
<- true;
4164 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4165 let n = if n >= m then n+1 else n in
4170 method add_narrow_pattern
pattern =
4171 m_narrow_patterns
<- pattern :: m_narrow_patterns
4173 method del_narrow_pattern
=
4174 match m_narrow_patterns
with
4175 | _ :: rest
-> m_narrow_patterns
<- rest
4180 match m_narrow_patterns
with
4181 | pattern :: [] -> self#narrow
pattern; pattern
4183 List.fold_left
(fun accu pattern ->
4184 self#narrow
pattern;
4185 accu ^
" --> " ^
pattern) "" list
4187 method calcactive
anchor =
4188 let rely = getanchory anchor in
4189 let rec loop n best bestd
=
4190 if n = Array.length m_items
4193 let (_, _, anchor) = m_items
.(n) in
4194 let orely = getanchory anchor in
4195 let d = abs
(orely - rely) in
4198 else loop (n+1) best bestd
4202 method reset
anchor items =
4203 m_hadremovals
<- false;
4204 if m_orig_items
== empty
4206 m_orig_items
<- items;
4207 if m_narrow_patterns
== []
4208 then m_items
<- items;
4210 let active = self#calcactive
anchor in
4212 m_first
<- firstof m_first
active
4216 let enterselector usebookmarks
=
4217 let source = outlinesource usebookmarks
in
4221 then Array.of_list
state.bookmarks
4224 if Array.length
outlines = 0
4226 showtext ' ' errmsg
;
4229 state.text <- source#greetmsg
;
4230 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4231 let anchor = getanchor () in
4232 source#reset
anchor outlines;
4233 state.uioh
<- coe (new outlinelistview ~
source);
4234 G.postRedisplay "enter selector";
4238 let enteroutlinemode =
4239 let f = enterselector false in
4240 fun ()-> f "Document has no outline";
4243 let enterbookmarkmode =
4244 let f = enterselector true in
4245 fun () -> f "Document has no bookmarks (yet)";
4248 let color_of_string s =
4249 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4250 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4254 let color_to_string (r, g, b) =
4255 let r = truncate
(r *. 256.0)
4256 and g = truncate
(g *. 256.0)
4257 and b = truncate
(b *. 256.0) in
4258 Printf.sprintf
"%d/%d/%d" r g b
4261 let irect_of_string s =
4262 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4265 let irect_to_string (x0,y0,x1,y1) =
4266 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4269 let makecheckers () =
4270 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4272 converted by Issac Trotts. July 25, 2002 *)
4273 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4274 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4275 let id = GlTex.gen_texture
() in
4276 GlTex.bind_texture `texture_2d
id;
4277 GlPix.store
(`unpack_alignment
1);
4278 GlTex.image2d
image;
4279 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4280 [ `mag_filter `nearest
; `min_filter `nearest
];
4284 let setcheckers enabled
=
4285 match state.texid
with
4287 if enabled
then state.texid
<- Some
(makecheckers ())
4292 GlTex.delete_texture texid
;
4293 state.texid
<- None
;
4297 let int_of_string_with_suffix s =
4298 let l = String.length
s in
4302 let suffix = Char.lowercase
s.[l-1] in
4304 | 'k'
-> String.sub
s 0 (l-1), 10
4305 | '
m'
-> String.sub
s 0 (l-1), 20
4306 | '
g'
-> String.sub
s 0 (l-1), 30
4310 let n = int_of_string
s1 in
4311 let m = n lsl shift
in
4313 then raise
(Failure
"value too large")
4317 let string_with_suffix_of_int n =
4321 let units = [(30, "G"); (20, "M"); (10, "K")] in
4324 let h = n mod 1000 in
4327 then string_of_int
h ^
s
4329 let s = Printf.sprintf
"_%03d%s" h s in
4335 let rec find = function
4337 | (shift
, suffix) :: rest
->
4338 if (n land ((1 lsl shift
) - 1)) = 0
4339 then prettyint (n lsr shift
) ^
suffix
4345 let defghyllscroll = (40, 8, 32);;
4346 let fastghyllscroll = (5,1,2);;
4347 let neatghyllscroll = (10,1,9);;
4348 let ghyllscroll_of_string s =
4350 | "default" -> Some
defghyllscroll
4351 | "fast" -> Some
(5,1,2)
4352 | "neat" -> Some
(10,1,9)
4353 | "" | "none" -> None
4355 let (n,a,b) as nab
=
4356 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4357 if n <= a || n <= b || a >= b
4358 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4363 let ghyllscroll_to_string ((n, a, b) as nab
) =
4364 (**) if nab
= defghyllscroll then "default"
4365 else if nab
= fastghyllscroll then "fast"
4366 else if nab
= neatghyllscroll then "neat"
4367 else Printf.sprintf
"%d,%d,%d" n a b;
4370 let describe_location () =
4371 let fn = page_of_y state.y in
4372 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4373 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4377 else (100. *. (float state.y /. float maxy))
4381 Printf.sprintf
"page %d of %d [%.2f%%]"
4382 (fn+1) state.pagecount
percent
4385 "pages %d-%d of %d [%.2f%%]"
4386 (fn+1) (ln+1) state.pagecount
percent
4389 let setpresentationmode v
=
4390 let n = page_of_y state.y in
4391 state.anchor <- (n, 0.0, 1.0);
4392 conf.presentation
<- v
;
4393 if conf.fitmodel
= FitPage
4394 then reqlayout conf.angle
conf.fitmodel
;
4399 let btos b = if b then "\xe2\x88\x9a" else "" in
4400 let showextended = ref false in
4401 let leave mode
= function
4402 | Confirm
-> state.mode
<- mode
4403 | Cancel
-> state.mode
<- mode
in
4406 val mutable m_first_time
= true
4407 val mutable m_l
= []
4408 val mutable m_a
= [||]
4409 val mutable m_prev_uioh
= nouioh
4410 val mutable m_prev_mode
= View
4412 inherit lvsourcebase
4414 method reset prev_mode prev_uioh
=
4415 m_a
<- Array.of_list
(List.rev m_l
);
4417 m_prev_mode
<- prev_mode
;
4418 m_prev_uioh
<- prev_uioh
;
4422 if n >= Array.length m_a
4426 | _, _, _, Action
_ -> m_active
<- n
4430 m_first_time
<- false;
4433 method int name get
set =
4435 (name, `
int get
, 1, Action
(
4438 try set (int_of_string
s)
4440 state.text <- Printf.sprintf
"bad integer `%s': %s"
4444 let te = name ^
": ", "", None
, intentry, ondone, true in
4445 state.mode
<- Textentry
(te, leave m_prev_mode
);
4449 method int_with_suffix
name get
set =
4451 (name, `intws get
, 1, Action
(
4454 try set (int_of_string_with_suffix s)
4456 state.text <- Printf.sprintf
"bad integer `%s': %s"
4461 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4463 state.mode
<- Textentry
(te, leave m_prev_mode
);
4467 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4469 (name, `
bool (btos, get
), offset
, Action
(
4476 method color
name get
set =
4478 (name, `color get
, 1, Action
(
4480 let invalid = (nan
, nan
, nan
) in
4483 try color_of_string s
4485 state.text <- Printf.sprintf
"bad color `%s': %s"
4492 let te = name ^
": ", "", None
, textentry, ondone, true in
4493 state.text <- color_to_string (get
());
4494 state.mode
<- Textentry
(te, leave m_prev_mode
);
4498 method string name get
set =
4500 (name, `
string get
, 1, Action
(
4502 let ondone s = set s in
4503 let te = name ^
": ", "", None
, textentry, ondone, true in
4504 state.mode
<- Textentry
(te, leave m_prev_mode
);
4508 method colorspace
name get
set =
4510 (name, `
string get
, 1, Action
(
4514 inherit lvsourcebase
4517 m_active
<- CSTE.to_int conf.colorspace
;
4520 method getitemcount
=
4521 Array.length
CSTE.names
4524 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4525 ignore
(uioh
, first, pan
, qsearch);
4526 if not cancel
then set active;
4528 method hasaction
_ = true
4532 let modehash = findkeyhash conf "info" in
4533 coe (new listview ~
source ~trusted
:true ~
modehash)
4536 method paxmark
name get
set =
4538 (name, `
string get
, 1, Action
(
4542 inherit lvsourcebase
4545 m_active
<- MTE.to_int conf.paxmark
;
4548 method getitemcount
= Array.length
MTE.names
4549 method getitem
n = (MTE.names.(n), 0)
4550 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4551 ignore
(uioh
, first, pan
, qsearch);
4552 if not cancel
then set active;
4554 method hasaction
_ = true
4558 let modehash = findkeyhash conf "info" in
4559 coe (new listview ~
source ~trusted
:true ~
modehash)
4562 method fitmodel
name get
set =
4564 (name, `
string get
, 1, Action
(
4568 inherit lvsourcebase
4571 m_active
<- FMTE.to_int conf.fitmodel
;
4574 method getitemcount
= Array.length
FMTE.names
4575 method getitem
n = (FMTE.names.(n), 0)
4576 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4577 ignore
(uioh
, first, pan
, qsearch);
4578 if not cancel
then set active;
4580 method hasaction
_ = true
4584 let modehash = findkeyhash conf "info" in
4585 coe (new listview ~
source ~trusted
:true ~
modehash)
4588 method caption
s offset
=
4589 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4591 method caption2
s f offset
=
4592 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4594 method getitemcount
= Array.length m_a
4597 let tostr = function
4598 | `
int f -> string_of_int
(f ())
4599 | `intws
f -> string_with_suffix_of_int (f ())
4601 | `color
f -> color_to_string (f ())
4602 | `
bool (btos, f) -> btos (f ())
4605 let name, t
, offset
, _ = m_a
.(n) in
4606 ((let s = tostr t
in
4608 then Printf.sprintf
"%s\t%s" name s
4612 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4616 m_qsearch
<- qsearch;
4618 match m_a
.(active) with
4619 | _, _, _, Action
f -> f uioh
4631 method hasaction
n =
4633 | _, _, _, Action
_ -> true
4637 let rec fillsrc prevmode prevuioh
=
4638 let sep () = src#caption
"" 0 in
4639 let colorp name get
set =
4641 (fun () -> color_to_string (get
()))
4644 let c = color_of_string v in
4647 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4650 let oldmode = state.mode
in
4651 let birdseye = isbirdseye state.mode
in
4653 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4655 src#
bool "presentation mode"
4656 (fun () -> conf.presentation
)
4657 (fun v -> setpresentationmode v);
4659 src#
bool "ignore case in searches"
4660 (fun () -> conf.icase
)
4661 (fun v -> conf.icase
<- v);
4664 (fun () -> conf.preload)
4665 (fun v -> conf.preload <- v);
4667 src#
bool "highlight links"
4668 (fun () -> conf.hlinks
)
4669 (fun v -> conf.hlinks
<- v);
4671 src#
bool "under info"
4672 (fun () -> conf.underinfo
)
4673 (fun v -> conf.underinfo
<- v);
4675 src#
bool "persistent bookmarks"
4676 (fun () -> conf.savebmarks
)
4677 (fun v -> conf.savebmarks
<- v);
4679 src#fitmodel
"fit model"
4680 (fun () -> FMTE.to_string conf.fitmodel
)
4681 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4683 src#
bool "trim margins"
4684 (fun () -> conf.trimmargins
)
4685 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4687 src#
bool "persistent location"
4688 (fun () -> conf.jumpback
)
4689 (fun v -> conf.jumpback
<- v);
4692 src#
int "inter-page space"
4693 (fun () -> conf.interpagespace
)
4695 conf.interpagespace
<- n;
4696 docolumns conf.columns
;
4698 match state.layout with
4703 state.maxy <- calcheight ();
4704 let y = getpagey pageno in
4709 (fun () -> conf.pagebias
)
4710 (fun v -> conf.pagebias
<- v);
4712 src#
int "scroll step"
4713 (fun () -> conf.scrollstep
)
4714 (fun n -> conf.scrollstep
<- n);
4716 src#
int "horizontal scroll step"
4717 (fun () -> conf.hscrollstep
)
4718 (fun v -> conf.hscrollstep
<- v);
4720 src#
int "auto scroll step"
4722 match state.autoscroll
with
4724 | _ -> conf.autoscrollstep
)
4726 if state.autoscroll
<> None
4727 then state.autoscroll
<- Some
n;
4728 conf.autoscrollstep
<- n);
4731 (fun () -> truncate
(conf.zoom *. 100.))
4732 (fun v -> setzoom ((float v) /. 100.));
4735 (fun () -> conf.angle
)
4736 (fun v -> reqlayout v conf.fitmodel
);
4738 src#
int "scroll bar width"
4739 (fun () -> conf.scrollbw
)
4742 reshape state.winw
state.winh
;
4745 src#
int "scroll handle height"
4746 (fun () -> conf.scrollh
)
4747 (fun v -> conf.scrollh
<- v;);
4749 src#
int "thumbnail width"
4750 (fun () -> conf.thumbw
)
4752 conf.thumbw
<- min
4096 v;
4755 leavebirdseye beye
false;
4760 let mode = state.mode in
4761 src#
string "columns"
4763 match conf.columns
with
4765 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4766 | Csplit
(count
, _) -> "-" ^ string_of_int count
4769 let n, a, b = multicolumns_of_string v in
4770 setcolumns mode n a b);
4773 src#caption
"Pixmap cache" 0;
4774 src#int_with_suffix
"size (advisory)"
4775 (fun () -> conf.memlimit
)
4776 (fun v -> conf.memlimit
<- v);
4779 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4780 (string_with_suffix_of_int state.memused
)
4781 (Hashtbl.length
state.tilemap
)) 1;
4784 src#caption
"Layout" 0;
4785 src#caption2
"Dimension"
4787 Printf.sprintf
"%dx%d (virtual %dx%d)"
4788 state.winw
state.winh
4793 src#caption2
"Position" (fun () ->
4794 Printf.sprintf
"%dx%d" state.x state.y
4797 src#caption2
"Position" (fun () -> describe_location ()) 1
4801 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4802 "Save these parameters as global defaults at exit"
4803 (fun () -> conf.bedefault
)
4804 (fun v -> conf.bedefault
<- v)
4808 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4809 src#
bool ~offset
:0 ~
btos "Extended parameters"
4810 (fun () -> !showextended)
4811 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4815 (fun () -> conf.checkers
)
4816 (fun v -> conf.checkers
<- v; setcheckers v);
4817 src#
bool "update cursor"
4818 (fun () -> conf.updatecurs
)
4819 (fun v -> conf.updatecurs
<- v);
4821 (fun () -> conf.verbose
)
4822 (fun v -> conf.verbose
<- v);
4823 src#
bool "invert colors"
4824 (fun () -> conf.invert
)
4825 (fun v -> conf.invert
<- v);
4827 (fun () -> conf.maxhfit
)
4828 (fun v -> conf.maxhfit
<- v);
4829 src#
bool "redirect stderr"
4830 (fun () -> conf.redirectstderr)
4831 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4833 (fun () -> conf.pax
!= None
)
4836 then conf.pax
<- Some
(ref (now (), 0, 0))
4837 else conf.pax
<- None
);
4838 src#
string "uri launcher"
4839 (fun () -> conf.urilauncher
)
4840 (fun v -> conf.urilauncher
<- v);
4841 src#
string "path launcher"
4842 (fun () -> conf.pathlauncher
)
4843 (fun v -> conf.pathlauncher
<- v);
4844 src#
string "tile size"
4845 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4848 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4849 conf.tilew
<- max
64 w;
4850 conf.tileh
<- max
64 h;
4853 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4856 src#
int "texture count"
4857 (fun () -> conf.texcount
)
4860 then conf.texcount
<- v
4861 else showtext '
!'
" Failed to set texture count please retry later"
4863 src#
int "slice height"
4864 (fun () -> conf.sliceheight
)
4866 conf.sliceheight
<- v;
4867 wcmd "sliceh %d" conf.sliceheight
;
4869 src#
int "anti-aliasing level"
4870 (fun () -> conf.aalevel
)
4872 conf.aalevel
<- bound v 0 8;
4873 state.anchor <- getanchor ();
4874 opendoc state.path
state.password
;
4876 src#
string "page scroll scaling factor"
4877 (fun () -> string_of_float
conf.pgscale)
4880 let s = float_of_string
v in
4883 state.text <- Printf.sprintf
4884 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4887 src#
int "ui font size"
4888 (fun () -> fstate.fontsize
)
4889 (fun v -> setfontsize (bound v 5 100));
4890 src#
int "hint font size"
4891 (fun () -> conf.hfsize
)
4892 (fun v -> conf.hfsize
<- bound v 5 100);
4893 colorp "background color"
4894 (fun () -> conf.bgcolor
)
4895 (fun v -> conf.bgcolor
<- v);
4896 src#
bool "crop hack"
4897 (fun () -> conf.crophack
)
4898 (fun v -> conf.crophack
<- v);
4899 src#
string "trim fuzz"
4900 (fun () -> irect_to_string conf.trimfuzz
)
4903 conf.trimfuzz
<- irect_of_string v;
4905 then settrim true conf.trimfuzz
;
4907 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4909 src#
string "throttle"
4911 match conf.maxwait
with
4912 | None
-> "show place holder if page is not ready"
4915 then "wait for page to fully render"
4917 "wait " ^ string_of_float
time
4918 ^
" seconds before showing placeholder"
4922 let f = float_of_string
v in
4924 then conf.maxwait
<- None
4925 else conf.maxwait
<- Some
f
4927 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4929 src#
string "ghyll scroll"
4931 match conf.ghyllscroll
with
4933 | Some nab
-> ghyllscroll_to_string nab
4936 try conf.ghyllscroll
<- ghyllscroll_of_string v
4938 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4940 src#
string "selection command"
4941 (fun () -> conf.selcmd
)
4942 (fun v -> conf.selcmd
<- v);
4943 src#
string "synctex command"
4944 (fun () -> conf.stcmd
)
4945 (fun v -> conf.stcmd
<- v);
4946 src#
string "pax command"
4947 (fun () -> conf.paxcmd
)
4948 (fun v -> conf.paxcmd
<- v);
4949 src#colorspace
"color space"
4950 (fun () -> CSTE.to_string conf.colorspace
)
4952 conf.colorspace
<- CSTE.of_int v;
4956 src#paxmark
"pax mark method"
4957 (fun () -> MTE.to_string conf.paxmark
)
4958 (fun v -> conf.paxmark
<- MTE.of_int v);
4962 (fun () -> conf.usepbo
)
4963 (fun v -> conf.usepbo
<- v);
4964 src#
bool "mouse wheel scrolls pages"
4965 (fun () -> conf.wheelbypage
)
4966 (fun v -> conf.wheelbypage
<- v);
4967 src#
bool "open remote links in a new instance"
4968 (fun () -> conf.riani
)
4969 (fun v -> conf.riani
<- v);
4973 src#caption
"Document" 0;
4974 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4975 src#caption2
"Pages"
4976 (fun () -> string_of_int
state.pagecount
) 1;
4977 src#caption2
"Dimensions"
4978 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4982 src#caption
"Trimmed margins" 0;
4983 src#caption2
"Dimensions"
4984 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4988 src#caption
"OpenGL" 0;
4989 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4990 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4993 src#caption
"Location" 0;
4994 if nonemptystr
state.origin
4995 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4996 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4998 src#reset prevmode prevuioh
;
5002 let prevmode = state.mode
5003 and prevuioh
= state.uioh in
5004 fillsrc prevmode prevuioh
;
5005 let source = (src :> lvsource
) in
5006 let modehash = findkeyhash conf "info" in
5007 state.uioh <- coe (object (self)
5008 inherit listview ~
source ~trusted
:true ~
modehash as super
5009 val mutable m_prevmemused
= 0
5010 method infochanged
= function
5012 if m_prevmemused
!= state.memused
5014 m_prevmemused
<- state.memused
;
5015 G.postRedisplay "memusedchanged";
5017 | Pdim
-> G.postRedisplay "pdimchanged"
5018 | Docinfo
-> fillsrc prevmode prevuioh
5020 method key key mask
=
5021 if not
(Wsi.withctrl mask
)
5024 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5025 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5026 | _ -> super#
key key mask
5027 else super#
key key mask
5029 G.postRedisplay "info";
5035 inherit lvsourcebase
5036 method getitemcount
= Array.length
state.help
5038 let s, l, _ = state.help
.(n) in
5041 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5045 m_qsearch
<- qsearch;
5046 match state.help
.(active) with
5047 | _, _, Action
f -> Some
(f uioh)
5057 method hasaction
n =
5058 match state.help
.(n) with
5059 | _, _, Action
_ -> true
5066 let modehash = findkeyhash conf "help" in
5067 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5068 G.postRedisplay "help";
5073 let re = Str.regexp
"[\r\n]" in
5075 inherit lvsourcebase
5076 val mutable m_items
= [||]
5078 method getitemcount
= 1 + Array.length m_items
5083 else m_items
.(n-1), 0
5085 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5090 then Buffer.clear
state.errmsgs
;
5091 m_qsearch
<- qsearch;
5098 method hasaction
n =
5102 state.newerrmsgs
<- false;
5103 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5104 m_items
<- Array.of_list
l
5112 let source = (msgsource :> lvsource
) in
5113 let modehash = findkeyhash conf "listview" in
5114 state.uioh <- coe (object
5115 inherit listview ~
source ~trusted
:false ~
modehash as super
5118 then msgsource#reset
;
5121 G.postRedisplay "msgs";
5124 let quickbookmark ?title
() =
5125 match state.layout with
5131 let sec = Unix.gettimeofday
() in
5132 let tm = Unix.localtime
sec in
5133 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5137 (tm.Unix.tm_year
+ 1900)
5140 | Some
title -> title
5142 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5145 let setautoscrollspeed step goingdown
=
5146 let incr = max
1 ((abs step
) / 2) in
5147 let incr = if goingdown
then incr else -incr in
5148 let astep = step
+ incr in
5149 state.autoscroll
<- Some
astep;
5152 let gotounder under =
5153 let getpath filename
=
5155 if nonemptystr filename
5157 if Filename.is_relative filename
5159 let dir = Filename.dirname
state.path in
5161 if Filename.is_implicit
dir
5162 then Filename.concat
(Sys.getcwd
()) dir
5165 Filename.concat
dir filename
5169 if Sys.file_exists
path
5174 | Ulinkgoto
(pageno, top) ->
5178 gotopage1 pageno top;
5184 | Uremote
(filename
, pageno) ->
5185 let path = getpath filename
in
5190 let command = !selfexec ^
" " ^
path in
5191 try popen command []
5194 "failed to execute `%s': %s\n" command (exntos exn
);
5197 let anchor = getanchor () in
5198 let ranchor = state.path, state.password
, anchor, state.origin
in
5200 state.anchor <- (pageno, 0.0, 0.0);
5201 state.ranchors
<- ranchor :: state.ranchors
;
5204 else showtext '
!'
("Could not find " ^ filename
)
5206 | Uremotedest
(filename
, destname
) ->
5207 let path = getpath filename
in
5212 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
5213 try popen command []
5216 "failed to execute `%s': %s\n" command (exntos exn
);
5219 let anchor = getanchor () in
5220 let ranchor = state.path, state.password
, anchor, state.origin
in
5222 state.nameddest
<- destname
;
5223 state.ranchors
<- ranchor :: state.ranchors
;
5226 else showtext '
!'
("Could not find " ^ filename
)
5228 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5232 match conf.columns
with
5234 | _ -> state.x != 0 || conf.zoom > 1.0
5237 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5239 let existsinrow pageno (columns
, coverA
, coverB
) p =
5240 let last = ((pageno - coverA
) mod columns
) + columns
in
5241 let rec any = function
5244 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5248 then (if l.pageno = last then false else any rest
)
5256 match state.layout with
5258 let pageno = page_of_y state.y in
5259 gotoghyll (getpagey (pageno+1))
5261 match conf.columns
with
5263 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5265 let y = clamp (pgscale state.winh
) in
5268 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5269 gotoghyll (getpagey pageno)
5270 | Cmulti
((c, _, _) as cl, _) ->
5271 if conf.presentation
5272 && (existsinrow l.pageno cl
5273 (fun l -> l.pageh
> l.pagey + l.pagevh))
5275 let y = clamp (pgscale state.winh
) in
5278 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5279 gotoghyll (getpagey pageno)
5281 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5283 let pagey, pageh
= getpageyh l.pageno in
5284 let pagey = pagey + pageh
* l.pagecol
in
5285 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5286 gotoghyll (pagey + pageh
+ ips)
5290 match state.layout with
5292 let pageno = page_of_y state.y in
5293 gotoghyll (getpagey (pageno-1))
5295 match conf.columns
with
5297 if conf.presentation
&& l.pagey != 0
5299 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5301 let pageno = max
0 (l.pageno-1) in
5302 gotoghyll (getpagey pageno)
5303 | Cmulti
((c, _, coverB
) as cl, _) ->
5304 if conf.presentation
&&
5305 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5307 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5310 if l.pageno = state.pagecount
- coverB
5314 let pageno = max
0 (l.pageno-decr) in
5315 gotoghyll (getpagey pageno)
5323 let pageno = max
0 (l.pageno-1) in
5324 let pagey, pageh
= getpageyh pageno in
5327 let pagey, pageh
= getpageyh l.pageno in
5328 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5333 let viewkeyboard key mask
=
5335 let mode = state.mode in
5336 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5339 G.postRedisplay "view:enttext"
5341 let ctrl = Wsi.withctrl mask
in
5343 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5349 | 0xff63 -> (* insert *)
5350 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5352 state.mode <- LinkNav
(Ltgendir
0);
5355 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5357 | 0xff1b | 113 -> (* escape / q *)
5358 begin match state.mstate
with
5360 state.mstate
<- Mnone
;
5361 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5362 G.postRedisplay "kill zoom rect";
5364 begin match state.mode with
5367 G.postRedisplay "esc leave linknav"
5369 match state.ranchors
with
5371 | (path, password
, anchor, origin
) :: rest
->
5372 state.ranchors
<- rest
;
5373 state.anchor <- anchor;
5374 state.origin
<- origin
;
5375 state.nameddest
<- "";
5376 opendoc path password
5380 | 0xff08 -> (* backspace *)
5381 gotoghyll (getnav ~
-1)
5389 G.postRedisplay "dehighlight";
5391 | 47 | 63 -> (* / ? *)
5392 let ondone isforw
s =
5393 cbput state.hists
.pat
s;
5394 state.searchpattern
<- s;
5397 let s = String.create
1 in
5398 s.[0] <- Char.chr
key;
5399 enttext (s, "", Some
(onhist state.hists
.pat
),
5400 textentry, ondone (key = 47), true)
5402 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5403 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5404 setzoom (conf.zoom +. incr)
5406 | 43 | 0xffab -> (* + *)
5409 try int_of_string
s with exc
->
5410 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5416 state.text <- "page bias is now " ^ string_of_int
n;
5419 enttext ("page bias: ", "", None
, intentry, ondone, true)
5421 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5422 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5423 setzoom (max
0.01 (conf.zoom -. decr))
5425 | 45 | 0xffad -> (* - *)
5426 let ondone msg
= state.text <- msg
in
5428 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5429 optentry state.mode, ondone, true
5432 | 48 when ctrl -> (* ctrl-0 *)
5440 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5442 match conf.columns
with
5443 | Csingle
_ | Cmulti
_ -> 1
5444 | Csplit
(n, _) -> n
5446 let h = state.winh
-
5447 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5449 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5450 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5453 | 51 when ctrl -> (* ctrl-3 *)
5455 match conf.fitmodel
with
5456 | FitWidth
-> FitProportional
5457 | FitProportional
-> FitPage
5458 | FitPage
-> FitWidth
5460 state.text <- "fit model: " ^
FMTE.to_string fm;
5461 reqlayout conf.angle
fm
5463 | 0xffc6 -> (* f9 *)
5466 | 57 when ctrl -> (* ctrl-9 *)
5469 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5470 when not
ctrl -> (* 0..9 *)
5473 try int_of_string
s with exc
->
5474 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5480 cbput state.hists
.pag
(string_of_int
n);
5481 gotopage1 (n + conf.pagebias
- 1) 0;
5484 let pageentry text key =
5485 match Char.unsafe_chr
key with
5486 | '
g'
-> TEdone
text
5487 | _ -> intentry text key
5489 let text = "x" in text.[0] <- Char.chr
key;
5490 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5493 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5494 reshape state.winw
state.winh
;
5497 state.bzoom
<- not
state.bzoom
;
5499 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5502 conf.hlinks
<- not
conf.hlinks
;
5503 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5504 G.postRedisplay "toggle highlightlinks";
5507 state.glinks
<- true;
5508 let mode = state.mode in
5509 state.mode <- Textentry
(
5510 (":", "", None
, linknentry, linkndone gotounder, false),
5512 state.glinks
<- false;
5516 G.postRedisplay "view:linkent(F)"
5519 state.glinks
<- true;
5520 let mode = state.mode in
5521 state.mode <- Textentry
(
5523 ":", "", None
, linknentry, linkndone (fun under ->
5524 selstring (undertext under);
5528 state.glinks
<- false;
5532 G.postRedisplay "view:linkent"
5535 begin match state.autoscroll
with
5537 conf.autoscrollstep
<- step
;
5538 state.autoscroll
<- None
5540 if conf.autoscrollstep
= 0
5541 then state.autoscroll
<- Some
1
5542 else state.autoscroll
<- Some
conf.autoscrollstep
5545 | 112 when ctrl -> (* ctrl-p *)
5549 setpresentationmode (not
conf.presentation
);
5550 showtext ' '
("presentation mode " ^
5551 if conf.presentation
then "on" else "off");
5554 if List.mem
Wsi.Fullscreen
state.winstate
5555 then Wsi.reshape conf.cwinw
conf.cwinh
5556 else Wsi.fullscreen
()
5558 | 112 | 78 -> (* p|N *)
5559 search state.searchpattern
false
5561 | 110 | 0xffc0 -> (* n|F3 *)
5562 search state.searchpattern
true
5565 begin match state.layout with
5568 gotoghyll (getpagey l.pageno)
5574 | 0xff9f | 0xffff -> (* delete *)
5578 showtext ' '
(describe_location ());
5581 begin match state.layout with
5584 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5589 enterbookmarkmode ()
5591 | 104 | 0xffbe -> (* h|F1 *)
5597 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5602 match state.layout with
5606 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5609 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5613 showtext ' '
"Quick bookmark added";
5616 begin match state.layout with
5618 let rect = getpdimrect
l.pagedimno
in
5622 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5623 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5625 (truncate
(rect.(1) -. rect.(0)),
5626 truncate
(rect.(3) -. rect.(0)))
5628 let w = truncate
((float w)*.conf.zoom)
5629 and h = truncate
((float h)*.conf.zoom) in
5632 state.anchor <- getanchor ();
5633 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5635 G.postRedisplay "z";
5640 | 120 -> state.roam
() (* x *)
5641 | 60 | 62 -> (* < > *)
5642 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5644 | 91 | 93 -> (* [ ] *)
5646 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5648 G.postRedisplay "brightness";
5650 | 99 when state.mode = View
-> (* [alt-]c *)
5655 let m = (wadjsb state.winw
- state.w) / 2 in
5657 gotoy_and_clear_text state.y
5661 match state.prevcolumns
with
5662 | None
-> (1, 0, 0), 1.0
5663 | Some
(columns
, z
) ->
5666 | Csplit
(c, _) -> -c, 0, 0
5667 | Cmulti
((c, a, b), _) -> c, a, b
5668 | Csingle
_ -> 1, 0, 0
5672 setcolumns View
c a b;
5675 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5676 -> (* ctrl-shift- (kp) [up|down] *)
5677 let zoom, x = state.prevzoom
in
5681 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5682 begin match state.autoscroll
with
5684 begin match state.mode with
5685 | Birdseye beye
-> upbirdseye 1 beye
5688 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5690 if not
(Wsi.withshift mask
) && conf.presentation
5692 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5696 setautoscrollspeed n false
5699 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5700 begin match state.autoscroll
with
5702 begin match state.mode with
5703 | Birdseye beye
-> downbirdseye 1 beye
5706 then gotoy_and_clear_text (clamp (state.winh
/2))
5708 if not
(Wsi.withshift mask
) && conf.presentation
5710 else gotoy_and_clear_text (clamp conf.scrollstep
)
5714 setautoscrollspeed n true
5717 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5718 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5724 else conf.hscrollstep
5726 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5727 state.x <- panbound (state.x + dx);
5728 gotoy_and_clear_text state.y
5731 G.postRedisplay "left/right"
5734 | 0xff55 | 0xff9a -> (* (kp) prior *)
5738 match state.layout with
5740 | l :: _ -> state.y - l.pagey
5742 clamp (pgscale (-state.winh
))
5746 | 0xff56 | 0xff9b -> (* (kp) next *)
5750 match List.rev
state.layout with
5752 | l :: _ -> getpagey l.pageno
5754 clamp (pgscale state.winh
)
5758 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5760 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5761 gotoghyll (clamp state.maxy)
5764 when Wsi.withalt mask
-> (* alt-(kp) right *)
5765 gotoghyll (getnav 1)
5767 when Wsi.withalt mask
-> (* alt-(kp) left *)
5768 gotoghyll (getnav ~
-1)
5773 | 118 when conf.debug
-> (* v *)
5776 match getopaque l.pageno with
5779 let x0, y0, x1, y1 = pagebbox opaque
in
5780 let a,b = float x0, float y0 in
5781 let c,d = float x1, float y0 in
5782 let e,f = float x1, float y1 in
5783 let h,j
= float x0, float y1 in
5784 let rect = (a,b,c,d,e,f,h,j
) in
5786 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5788 G.postRedisplay "v";
5791 vlog "huh? %s" (Wsi.keyname
key)
5794 let linknavkeyboard key mask
linknav =
5795 let getpage pageno =
5796 let rec loop = function
5798 | l :: _ when l.pageno = pageno -> Some
l
5799 | _ :: rest
-> loop rest
5800 in loop state.layout
5802 let doexact (pageno, n) =
5803 match getopaque pageno, getpage pageno with
5804 | Some opaque
, Some
l ->
5805 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5807 let under = getlink opaque
n in
5808 G.postRedisplay "link gotounder";
5814 | 0xff50 -> (* home *)
5815 Some
(findlink opaque LDfirst
), -1
5817 | 0xff57 -> (* end *)
5818 Some
(findlink opaque LDlast
), 1
5820 | 0xff51 -> (* left *)
5821 Some
(findlink opaque
(LDleft
n)), -1
5823 | 0xff53 -> (* right *)
5824 Some
(findlink opaque
(LDright
n)), 1
5826 | 0xff52 -> (* up *)
5827 Some
(findlink opaque
(LDup
n)), -1
5829 | 0xff54 -> (* down *)
5830 Some
(findlink opaque
(LDdown
n)), 1
5835 begin match findpwl
l.pageno dir with
5839 state.mode <- LinkNav
(Ltgendir
dir);
5840 let y, h = getpageyh pageno in
5843 then y + h - state.winh
5848 begin match getopaque pageno, getpage pageno with
5849 | Some opaque
, Some
_ ->
5851 let ld = if dir > 0 then LDfirst
else LDlast
in
5854 begin match link with
5856 showlinktype (getlink opaque
m);
5857 state.mode <- LinkNav
(Ltexact
(pageno, m));
5858 G.postRedisplay "linknav jpage";
5865 begin match opt with
5866 | Some Lnotfound
-> pwl l dir;
5867 | Some
(Lfound
m) ->
5871 let _, y0, _, y1 = getlinkrect opaque
m in
5873 then gotopage1 l.pageno y0
5875 let d = fstate.fontsize
+ 1 in
5876 if y1 - l.pagey > l.pagevh - d
5877 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5878 else G.postRedisplay "linknav";
5880 showlinktype (getlink opaque
m);
5881 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5884 | None
-> viewkeyboard key mask
5886 | _ -> viewkeyboard key mask
5891 G.postRedisplay "leave linknav"
5895 | Ltgendir
_ -> viewkeyboard key mask
5896 | Ltexact exact
-> doexact exact
5899 let keyboard key mask
=
5900 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5901 then wcmd "interrupt"
5902 else state.uioh <- state.uioh#
key key mask
5905 let birdseyekeyboard key mask
5906 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5908 match conf.columns
with
5910 | Cmulti
((c, _, _), _) -> c
5911 | Csplit
_ -> failwith
"bird's eye split mode"
5913 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5915 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5916 let y, h = getpageyh pageno in
5917 let top = (state.winh
- h) / 2 in
5918 gotoy (max
0 (y - top))
5919 | 0xff0d (* enter *)
5920 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5921 | 0xff1b -> leavebirdseye beye
true (* escape *)
5922 | 0xff52 -> upbirdseye incr beye
(* up *)
5923 | 0xff54 -> downbirdseye incr beye
(* down *)
5924 | 0xff51 -> upbirdseye 1 beye
(* left *)
5925 | 0xff53 -> downbirdseye 1 beye
(* right *)
5927 | 0xff55 -> (* prior *)
5928 begin match state.layout with
5932 state.mode <- Birdseye
(
5933 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5935 gotopage1 l.pageno 0;
5938 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5940 | [] -> gotoy (clamp (-state.winh
))
5942 state.mode <- Birdseye
(
5943 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5945 gotopage1 l.pageno 0
5948 | [] -> gotoy (clamp (-state.winh
))
5951 | 0xff56 -> (* next *)
5952 begin match List.rev
state.layout with
5954 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5955 begin match layout with
5957 let incr = l.pageh
- l.pagevh in
5962 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5964 G.postRedisplay "birdseye pagedown";
5966 else gotoy (clamp (incr + conf.interpagespace
*2));
5970 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5971 gotopage1 l.pageno 0;
5974 | [] -> gotoy (clamp state.winh
)
5977 | 0xff50 -> (* home *)
5978 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5981 | 0xff57 -> (* end *)
5982 let pageno = state.pagecount
- 1 in
5983 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5984 if not
(pagevisible state.layout pageno)
5987 match List.rev
state.pdims
with
5989 | (_, _, h, _) :: _ -> h
5991 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5992 else G.postRedisplay "birdseye end";
5993 | _ -> viewkeyboard key mask
5998 match state.mode with
5999 | Textentry
_ -> scalecolor 0.4
6001 | View
-> scalecolor 1.0
6002 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6003 if l.pageno = hooverpageno
6006 if l.pageno = pageno
6014 let postdrawpage l linkindexbase
=
6015 match getopaque l.pageno with
6017 if tileready l l.pagex
l.pagey
6019 let x = l.pagedispx - l.pagex
6020 and y = l.pagedispy - l.pagey in
6022 match conf.columns
with
6023 | Csingle
_ | Cmulti
_ ->
6024 (if conf.hlinks
then 1 else 0)
6026 && not
(isbirdseye state.mode) then 2 else 0)
6030 match state.mode with
6031 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6034 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6039 let scrollindicator () =
6040 let sbw, ph
, sh = state.uioh#
scrollph in
6041 let sbh, pw, sw = state.uioh#scrollpw
in
6043 GlDraw.color (0.64, 0.64, 0.64);
6045 (float (state.winw
- sbw)) 0.
6046 (float state.winw
) (float state.winh
)
6049 0. (float (state.winh
- sbh))
6050 (float (wadjsb state.winw
- 1)) (float state.winh
)
6052 GlDraw.color (0.0, 0.0, 0.0);
6055 (float (state.winw
- sbw)) ph
6056 (float state.winw
) (ph
+. sh)
6059 pw (float (state.winh
- sbh))
6060 (pw +. sw) (float state.winh
)
6065 match state.mstate
with
6066 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6069 | Msel
((x0, y0), (x1, y1)) ->
6070 let rec loop = function
6072 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6073 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6074 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6075 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6077 match getopaque l.pageno with
6079 let x0, y0 = pagetranslatepoint l x0 y0 in
6080 let x1, y1 = pagetranslatepoint l x1 y1 in
6081 seltext opaque
(x0, y0, x1, y1);
6089 let showrects = function [] -> () | rects
->
6091 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6092 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6094 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6096 if l.pageno = pageno
6098 let dx = float (l.pagedispx - l.pagex
) in
6099 let dy = float (l.pagedispy - l.pagey) in
6100 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6101 Raw.sets_float
state.vraw ~pos
:0
6106 GlArray.vertex `two
state.vraw
;
6107 GlArray.draw_arrays `triangle_strip
0 4;
6116 GlClear.color (scalecolor2 conf.bgcolor
);
6117 GlClear.clear
[`
color];
6118 List.iter
drawpage state.layout;
6120 match state.mode with
6121 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6122 begin match getopaque pageno with
6124 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6131 | None
-> state.rects
6136 let rec postloop linkindexbase
= function
6138 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6139 postloop linkindexbase rest
6143 postloop 0 state.layout;
6145 begin match state.mstate
with
6146 | Mzoomrect
((x0, y0), (x1, y1)) ->
6148 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6149 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6150 filledrect (float x0) (float y0) (float x1) (float y1);
6159 let zoomrect x y x1 y1 =
6162 and y0 = min
y y1 in
6163 gotoy (state.y + y0);
6164 state.anchor <- getanchor ();
6165 let zoom = (float state.w) /. float (x1 - x0) in
6167 match conf.fitmodel
, conf.columns
with
6168 | FitPage
, Csplit
_ ->
6169 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6172 let adjw = wadjsb state.winw
in
6174 then (adjw - state.w) / 2
6177 state.x <- (state.x + margin) - x0;
6179 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6180 state.mstate
<- Mnone
;
6184 let g opaque
l px py =
6185 match rectofblock opaque
px py with
6187 let x0 = a.(0) -. 20. in
6188 let x1 = a.(1) +. 20. in
6189 let y0 = a.(2) -. 20. in
6190 let zoom = (float state.w) /. (x1 -. x0) in
6191 let pagey = getpagey l.pageno in
6192 gotoy_and_clear_text (pagey + truncate
y0);
6193 state.anchor <- getanchor ();
6194 let margin = (state.w - l.pagew
)/2 in
6195 state.x <- -truncate
x0 - margin;
6200 match conf.columns
with
6202 showtext '
!'
"block zooming does not work properly in split columns mode"
6203 | _ -> onppundermouse g x y ()
6207 let winw = wadjsb state.winw - 1 in
6208 let s = float x /. float winw in
6209 let destx = truncate
(float (state.w + winw) *. s) in
6210 state.x <- winw - destx;
6211 gotoy_and_clear_text state.y;
6212 state.mstate
<- Mscrollx
;
6216 let s = float y /. float state.winh
in
6217 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6218 gotoy_and_clear_text desty;
6219 state.mstate
<- Mscrolly
;
6222 let viewmouse button down
x y mask
=
6224 | n when (n == 4 || n == 5) && not down
->
6225 if Wsi.withctrl mask
6227 match state.mstate
with
6228 | Mzoom
(oldn
, i
) ->
6236 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6238 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6240 let zoom = conf.zoom -. incr in
6242 state.mstate
<- Mzoom
(n, 0);
6244 state.mstate
<- Mzoom
(n, i
+1);
6246 else state.mstate
<- Mzoom
(n, 0)
6248 | _ -> state.mstate
<- Mzoom
(n, 0)
6251 match state.autoscroll
with
6252 | Some step
-> setautoscrollspeed step
(n=4)
6254 if conf.wheelbypage
|| conf.presentation
6263 then -conf.scrollstep
6264 else conf.scrollstep
6266 let incr = incr * 2 in
6267 let y = clamp incr in
6268 gotoy_and_clear_text y
6271 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6273 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6274 gotoy_and_clear_text state.y
6276 | 1 when Wsi.withshift mask
->
6277 state.mstate
<- Mnone
;
6280 match unproject x y with
6281 | Some
(pageno, ux
, uy
) ->
6282 let cmd = Printf.sprintf
6284 conf.stcmd
state.path pageno ux uy
6290 | 1 when Wsi.withctrl mask
->
6293 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6294 state.mstate
<- Mpan
(x, y)
6297 state.mstate
<- Mnone
6302 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6304 state.mstate
<- Mzoomrect
(p, p)
6307 match state.mstate
with
6308 | Mzoomrect
((x0, y0), _) ->
6309 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6310 then zoomrect x0 y0 x y
6312 state.mstate
<- Mnone
;
6313 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6314 G.postRedisplay "kill accidental zoom rect";
6317 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6318 state.mstate
<- Mnone
6321 | 1 when x > state.winw - vscrollw () ->
6324 let _, position, sh = state.uioh#
scrollph in
6325 if y > truncate
position && y < truncate
(position +. sh)
6326 then state.mstate
<- Mscrolly
6329 state.mstate
<- Mnone
6331 | 1 when y > state.winh
- hscrollh () ->
6334 let _, position, sw = state.uioh#scrollpw
in
6335 if x > truncate
position && x < truncate
(position +. sw)
6336 then state.mstate
<- Mscrollx
6339 state.mstate
<- Mnone
6341 | 1 when state.bzoom
-> if not down
then zoomblock x y
6344 let dest = if down
then getunder x y else Unone
in
6345 begin match dest with
6348 | Uremote
_ | Uremotedest
_
6349 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6352 | Unone
when down
->
6353 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6354 state.mstate
<- Mpan
(x, y);
6356 | Unone
| Utext
_ ->
6359 if conf.angle
mod 360 = 0
6361 state.mstate
<- Msel
((x, y), (x, y));
6362 G.postRedisplay "mouse select";
6366 match state.mstate
with
6369 | Mzoom
_ | Mscrollx
| Mscrolly
->
6370 state.mstate
<- Mnone
6372 | Mzoomrect
((x0, y0), _) ->
6376 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6377 state.mstate
<- Mnone
6379 | Msel
((x0, y0), (x1, y1)) ->
6380 let rec loop = function
6384 let a0 = l.pagedispy in
6385 let a1 = a0 + l.pagevh in
6386 let b0 = l.pagedispx in
6387 let b1 = b0 + l.pagevw in
6388 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6389 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6393 match getopaque l.pageno with
6396 match Ne.pipe () with
6400 "can not create sel pipe: %s"
6403 let doclose what fd
=
6404 Ne.clo fd
(fun msg
->
6405 dolog
"%s close failed: %s" what msg
)
6408 popen conf.selcmd
[r, 0; w, -1];
6409 copysel
w opaque
true;
6411 G.postRedisplay "copysel";
6413 dolog
"can not execute %S: %s"
6414 conf.selcmd
(exntos exn
);
6422 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6423 state.mstate
<- Mnone
;
6430 let birdseyemouse button down
x y mask
6431 (conf, leftx
, _, hooverpageno
, anchor) =
6434 let rec loop = function
6437 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6438 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6440 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6446 | _ -> viewmouse button down
x y mask
6452 method key key mask
=
6453 begin match state.mode with
6454 | Textentry
textentry -> textentrykeyboard key mask
textentry
6455 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6456 | View
-> viewkeyboard key mask
6457 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6461 method button button bstate
x y mask
=
6462 begin match state.mode with
6464 | View
-> viewmouse button bstate
x y mask
6465 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6471 begin match state.mode with
6473 | View
| Birdseye
_ | LinkNav
_ ->
6474 match state.mstate
with
6475 | Mzoom
_ | Mnone
-> ()
6480 state.mstate
<- Mpan
(x, y);
6482 then state.x <- panbound (state.x + dx);
6484 gotoy_and_clear_text y
6487 state.mstate
<- Msel
(a, (x, y));
6488 G.postRedisplay "motion select";
6491 let y = min
state.winh
(max
0 y) in
6495 let x = min
state.winw (max
0 x) in
6498 | Mzoomrect
(p0
, _) ->
6499 state.mstate
<- Mzoomrect
(p0
, (x, y));
6500 G.postRedisplay "motion zoomrect";
6504 method pmotion
x y =
6505 begin match state.mode with
6506 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6507 let rec loop = function
6509 if hooverpageno
!= -1
6511 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6512 G.postRedisplay "pmotion birdseye no hoover";
6515 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6516 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6518 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6519 G.postRedisplay "pmotion birdseye hoover";
6529 match state.mstate
with
6530 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6537 let past, _, _ = !r in
6539 let delta = now -. past in
6542 else r := (now, x, y)
6546 method infochanged
_ = ()
6549 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6552 then 0.0, float state.winh
6553 else scrollph state.y maxy
6558 let winw = wadjsb state.winw in
6559 let fwinw = float winw in
6561 let sw = fwinw /. float state.w in
6562 let sw = fwinw *. sw in
6563 max
sw (float conf.scrollh
)
6566 let maxx = state.w + winw in
6567 let x = winw - state.x in
6568 let percent = float x /. float maxx in
6569 (fwinw -. sw) *. percent
6571 hscrollh (), position, sw
6575 match state.mode with
6576 | LinkNav
_ -> "links"
6577 | Textentry
_ -> "textentry"
6578 | Birdseye
_ -> "birdseye"
6581 findkeyhash conf modename
6583 method eformsgs
= true
6590 let fontpath = ref "";;
6593 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6596 let l = String.length
s in
6597 let b = Buffer.create
l in
6603 try Sys.getenv
"HOME"
6606 ("Can not determine home directory location: " ^ exntos exn
);
6610 let modifier_of_string = function
6611 | "alt" -> Wsi.altmask
6612 | "shift" -> Wsi.shiftmask
6613 | "ctrl" | "control" -> Wsi.ctrlmask
6614 | "meta" -> Wsi.metamask
6619 let r = Str.regexp
"-" in
6621 let elems = Str.full_split
r s in
6624 let m1 = modifier_of_string s in
6626 then (Wsi.namekey
s, m)
6629 | Str.Delim
s when n land 1 = 0 -> g s
6631 | Str.Delim
_ -> (k
, m)
6633 let rec loop n k
m = function
6636 let k, m = f n k m x in
6642 let keys_of_string =
6643 let r = Str.regexp
"[ \t]" in
6645 let elems = Str.split
r s in
6646 List.map
key_of_string elems
6649 let copykeyhashes c =
6650 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6653 let config_of c attrs
=
6657 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6658 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6659 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6660 | "preload" -> { c with preload = bool_of_string
v }
6661 | "page-bias" -> { c with pagebias
= int_of_string
v }
6662 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6663 | "horizontal-scroll-step" ->
6664 { c with hscrollstep
= max
(int_of_string
v) 1 }
6665 | "auto-scroll-step" ->
6666 { c with autoscrollstep
= max
0 (int_of_string
v) }
6667 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6668 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6671 match String.lowercase
v with
6672 | "true" -> Some infinity
6674 | f -> Some
(float_of_string
f)
6676 { c with maxwait
= mw}
6677 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6678 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6679 | "vertical-margin" ->
6680 { c with interpagespace
= max
0 (int_of_string
v) }
6682 let zoom = float_of_string
v /. 100. in
6683 let zoom = max
zoom 0.0 in
6684 { c with zoom = zoom }
6685 | "presentation" -> { c with presentation
= bool_of_string
v }
6686 | "rotation-angle" -> { c with angle
= int_of_string
v }
6687 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6688 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6689 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6690 | "proportional-display" ->
6693 then FitProportional
6696 { c with fitmodel
= fm }
6697 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6698 | "pixmap-cache-size" ->
6699 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6700 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6701 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6702 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6703 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6704 | "background-color" -> { c with bgcolor
= color_of_string v }
6705 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6706 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6707 | "mupdf-store-size" ->
6708 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6709 | "checkers" -> { c with checkers
= bool_of_string
v }
6710 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6711 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6712 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6713 | "uri-launcher" -> { c with urilauncher
= unent v }
6714 | "path-launcher" -> { c with pathlauncher
= unent v }
6715 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6716 | "invert-colors" -> { c with invert
= bool_of_string
v }
6717 | "brightness" -> { c with colorscale
= float_of_string
v }
6718 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6719 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6721 let (n, _, _) as nab
= multicolumns_of_string v in
6723 then { c with columns
= Csplit
(-n, [||]) }
6724 else { c with columns
= Cmulti
(nab
, [||]) }
6725 | "birds-eye-columns" ->
6726 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6727 | "selection-command" -> { c with selcmd
= unent v }
6728 | "synctex-command" -> { c with stcmd
= unent v }
6729 | "pax-command" -> { c with paxcmd
= unent v }
6730 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6731 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6732 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6733 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6734 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6735 | "horizontal-scrollbar-visible" ->
6738 then c.scrollb
lor scrollbhv
6739 else c.scrollb
land (lnot
scrollbhv)
6741 { c with scrollb
= b }
6742 | "vertical-scrollbar-visible" ->
6745 then c.scrollb
lor scrollbvv
6746 else c.scrollb
land (lnot
scrollbvv)
6748 { c with scrollb
= b }
6749 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6753 then Some
(ref (0.0, 0, 0))
6755 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6758 prerr_endline
("Error processing attribute (`" ^
6759 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6762 let rec fold c = function
6765 let c = apply c k v in
6768 fold { c with keyhashes
= copykeyhashes c } attrs
;
6771 let fromstring f pos
n v d =
6774 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6775 n v pos
(exntos exn
)
6780 let bookmark_of attrs
=
6781 let rec fold title page
rely visy
= function
6782 | ("title", v) :: rest
-> fold v page
rely visy rest
6783 | ("page", v) :: rest
-> fold title v rely visy rest
6784 | ("rely", v) :: rest
-> fold title page
v visy rest
6785 | ("visy", v) :: rest
-> fold title page
rely v rest
6786 | _ :: rest
-> fold title page
rely visy rest
6787 | [] -> title, page
, rely, visy
6789 fold "invalid" "0" "0" "0" attrs
6793 let rec fold path page
rely pan visy
= function
6794 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6795 | ("page", v) :: rest
-> fold path v rely pan visy rest
6796 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6797 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6798 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6799 | _ :: rest
-> fold path page
rely pan visy rest
6800 | [] -> path, page
, rely, pan
, visy
6802 fold "" "0" "0" "0" "0" attrs
6806 let rec fold rs ls
= function
6807 | ("out", v) :: rest
-> fold v ls rest
6808 | ("in", v) :: rest
-> fold rs
v rest
6809 | _ :: rest
-> fold ls rs rest
6815 let setconf dst
src =
6816 dst
.scrollbw
<- src.scrollbw
;
6817 dst
.scrollh
<- src.scrollh
;
6818 dst
.icase
<- src.icase
;
6819 dst
.preload <- src.preload;
6820 dst
.pagebias
<- src.pagebias
;
6821 dst
.verbose
<- src.verbose
;
6822 dst
.scrollstep
<- src.scrollstep
;
6823 dst
.maxhfit
<- src.maxhfit
;
6824 dst
.crophack
<- src.crophack
;
6825 dst
.autoscrollstep
<- src.autoscrollstep
;
6826 dst
.maxwait
<- src.maxwait
;
6827 dst
.hlinks
<- src.hlinks
;
6828 dst
.underinfo
<- src.underinfo
;
6829 dst
.interpagespace
<- src.interpagespace
;
6830 dst
.zoom <- src.zoom;
6831 dst
.presentation
<- src.presentation
;
6832 dst
.angle
<- src.angle
;
6833 dst
.cwinw
<- src.cwinw
;
6834 dst
.cwinh
<- src.cwinh
;
6835 dst
.savebmarks
<- src.savebmarks
;
6836 dst
.memlimit
<- src.memlimit
;
6837 dst
.fitmodel
<- src.fitmodel
;
6838 dst
.texcount
<- src.texcount
;
6839 dst
.sliceheight
<- src.sliceheight
;
6840 dst
.thumbw
<- src.thumbw
;
6841 dst
.jumpback
<- src.jumpback
;
6842 dst
.bgcolor
<- src.bgcolor
;
6843 dst
.tilew
<- src.tilew
;
6844 dst
.tileh
<- src.tileh
;
6845 dst
.mustoresize
<- src.mustoresize
;
6846 dst
.checkers
<- src.checkers
;
6847 dst
.aalevel
<- src.aalevel
;
6848 dst
.trimmargins
<- src.trimmargins
;
6849 dst
.trimfuzz
<- src.trimfuzz
;
6850 dst
.urilauncher
<- src.urilauncher
;
6851 dst
.colorspace
<- src.colorspace
;
6852 dst
.invert
<- src.invert
;
6853 dst
.colorscale
<- src.colorscale
;
6854 dst
.redirectstderr <- src.redirectstderr;
6855 dst
.ghyllscroll
<- src.ghyllscroll
;
6856 dst
.columns
<- src.columns
;
6857 dst
.beyecolumns
<- src.beyecolumns
;
6858 dst
.selcmd
<- src.selcmd
;
6859 dst
.updatecurs
<- src.updatecurs
;
6860 dst
.pathlauncher
<- src.pathlauncher
;
6861 dst
.keyhashes
<- copykeyhashes src;
6862 dst
.hfsize
<- src.hfsize
;
6863 dst
.hscrollstep
<- src.hscrollstep
;
6864 dst
.pgscale <- src.pgscale;
6865 dst
.usepbo
<- src.usepbo
;
6866 dst
.wheelbypage
<- src.wheelbypage
;
6867 dst
.stcmd
<- src.stcmd
;
6868 dst
.paxcmd
<- src.paxcmd
;
6869 dst
.scrollb
<- src.scrollb
;
6870 dst
.riani
<- src.riani
;
6871 dst
.paxmark
<- src.paxmark
;
6875 else Some
((ref (0.0, 0, 0)));
6879 let h = Hashtbl.create
10 in
6880 let dc = { defconf with angle
= defconf.angle
} in
6881 let rec toplevel v t spos
_ =
6883 | Vdata
| Vcdata
| Vend
-> v
6884 | Vopen
("llppconfig", _, closed
) ->
6887 else { v with f = llppconfig
}
6889 error
"unexpected subelement at top level" s spos
6890 | Vclose
_ -> error
"unexpected close at top level" s spos
6892 and llppconfig
v t spos
_ =
6894 | Vdata
| Vcdata
-> v
6895 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6896 | Vopen
("defaults", attrs
, closed
) ->
6897 let c = config_of dc attrs
in
6901 else { v with f = defaults
}
6903 | Vopen
("ui-font", attrs
, closed
) ->
6904 let rec getsize size
= function
6906 | ("size", v) :: rest
->
6908 fromstring int_of_string spos
"size" v fstate.fontsize
in
6910 | l -> getsize size l
6912 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6915 else { v with f = uifont
(Buffer.create
10) }
6917 | Vopen
("doc", attrs
, closed
) ->
6918 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6919 let path = unent pathent
6920 and pageno = fromstring int_of_string spos
"page" spage
0
6921 and rely = fromstring float_of_string spos
"rely" srely
0.0
6922 and pan
= fromstring int_of_string spos
"pan" span
0
6923 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6924 let c = config_of dc attrs
in
6925 let anchor = (pageno, rely, visy
) in
6927 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6928 else { v with f = doc
path pan
anchor c [] }
6931 error
"unexpected subelement in llppconfig" s spos
6933 | Vclose
"llppconfig" -> { v with f = toplevel }
6934 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6936 and defaults
v t spos
_ =
6938 | Vdata
| Vcdata
-> v
6939 | Vend
-> error
"unexpected end of input in defaults" s spos
6940 | Vopen
("keymap", attrs
, closed
) ->
6942 try List.assoc
"mode" attrs
6943 with Not_found
-> "global" in
6948 let h = findkeyhash dc modename in
6949 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6952 { v with f = pkeymap
ret KeyMap.empty }
6954 | Vopen
(_, _, _) ->
6955 error
"unexpected subelement in defaults" s spos
6957 | Vclose
"defaults" ->
6958 { v with f = llppconfig
}
6960 | Vclose
_ -> error
"unexpected close in defaults" s spos
6962 and uifont
b v t spos
epos =
6965 Buffer.add_substring
b s spos
(epos - spos
);
6967 | Vopen
(_, _, _) ->
6968 error
"unexpected subelement in ui-font" s spos
6969 | Vclose
"ui-font" ->
6970 if emptystr
!fontpath
6971 then fontpath := Buffer.contents
b;
6972 { v with f = llppconfig
}
6973 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6974 | Vend
-> error
"unexpected end of input in ui-font" s spos
6976 and doc
path pan
anchor c bookmarks
v t spos
_ =
6978 | Vdata
| Vcdata
-> v
6979 | Vend
-> error
"unexpected end of input in doc" s spos
6980 | Vopen
("bookmarks", _, closed
) ->
6983 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6985 | Vopen
("keymap", attrs
, closed
) ->
6987 try List.assoc
"mode" attrs
6988 with Not_found
-> "global"
6994 let h = findkeyhash c modename in
6995 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6996 doc
path pan
anchor c bookmarks
6998 { v with f = pkeymap
ret KeyMap.empty }
7000 | Vopen
(_, _, _) ->
7001 error
"unexpected subelement in doc" s spos
7004 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7005 { v with f = llppconfig
}
7007 | Vclose
_ -> error
"unexpected close in doc" s spos
7009 and pkeymap
ret keymap
v t spos
_ =
7011 | Vdata
| Vcdata
-> v
7012 | Vend
-> error
"unexpected end of input in keymap" s spos
7013 | Vopen
("map", attrs
, closed
) ->
7014 let r, l = map_of attrs
in
7015 let kss = fromstring keys_of_string spos
"in" r [] in
7016 let lss = fromstring keys_of_string spos
"out" l [] in
7020 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7021 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7024 then { v with f = pkeymap
ret keymap }
7027 { v with f = skip
"map" f }
7030 error
"unexpected subelement in keymap" s spos
7032 | Vclose
"keymap" ->
7033 { v with f = ret keymap }
7035 | Vclose
_ -> error
"unexpected close in keymap" s spos
7037 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7039 | Vdata
| Vcdata
-> v
7040 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7041 | Vopen
("item", attrs
, closed
) ->
7042 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7043 let page = fromstring int_of_string spos
"page" spage
0
7044 and rely = fromstring float_of_string spos
"rely" srely
0.0
7045 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7047 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
7050 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7053 { v with f = skip
"item" f }
7056 error
"unexpected subelement in bookmarks" s spos
7058 | Vclose
"bookmarks" ->
7059 { v with f = doc
path pan
anchor c bookmarks }
7061 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7063 and skip tag
f v t spos
_ =
7065 | Vdata
| Vcdata
-> v
7067 error
("unexpected end of input in skipped " ^ tag
) s spos
7068 | Vopen
(tag'
, _, closed
) ->
7072 let f'
() = { v with f = skip tag
f } in
7073 { v with f = skip tag'
f'
}
7077 else error
("unexpected close in skipped " ^ tag
) s spos
7080 parse
{ f = toplevel; accu = () } s;
7086 let len = in_channel_length ic
in
7087 let s = String.create
len in
7088 really_input ic
s 0 len;
7091 | Parse_error
(msg
, s, pos
) ->
7092 let subs = subs s pos
in
7093 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7096 failwith
("config load error: " ^ exntos exn
)
7102 let dir = Filename.concat
home ".config" in
7103 if Sys.is_directory
dir then dir else home
7106 Filename.concat
dir "llpp.conf"
7109 let confpath = ref defconfpath;;
7112 if Sys.file_exists
!confpath
7115 (try Some
(open_in_bin
!confpath)
7118 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7129 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7138 f (Hashtbl.create
0, defconf)
7143 let pc, pb
, px, pa
=
7146 if emptystr
state.origin
7150 Hashtbl.find h (Filename.basename
key)
7151 with Not_found
-> dc, [], 0, emptyanchor
7155 state.bookmarks <- pb
;
7158 then state.anchor <- pa
;
7159 cbput state.hists
.nav pa
;
7165 let add_attrs bb always
dc c =
7168 then Printf.bprintf bb
"\n %s='%b'" s a
7171 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7174 then Printf.bprintf bb
"\n %s='%d'" s a
7177 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7180 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7183 then Printf.bprintf bb
"\n %s='%f'" s a
7187 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7191 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7195 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7199 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7204 | Some
(_N
, _A
, _B
) ->
7205 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7210 Printf.bprintf bb
"\n %s='none'" s
7220 else string_of_float
f
7222 Printf.bprintf bb
"\n %s='%s'" s v
7227 | Cmulti
((n, a, b), _) when n > 1 ->
7228 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7229 | Csplit
(n, _) when n > 1 ->
7230 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7236 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7241 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7245 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7249 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7251 oi
"width" c.cwinw
dc.cwinw
;
7252 oi
"height" c.cwinh
dc.cwinh
;
7253 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7254 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7255 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7256 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7257 ob "case-insensitive-search" c.icase
dc.icase
;
7258 ob "preload" c.preload dc.preload;
7259 oi
"page-bias" c.pagebias
dc.pagebias
;
7260 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7261 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7262 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7263 ob "crop-hack" c.crophack
dc.crophack
;
7264 oW
"throttle" c.maxwait
dc.maxwait
;
7265 ob "highlight-links" c.hlinks
dc.hlinks
;
7266 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7267 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7268 oz
"zoom" c.zoom dc.zoom;
7269 ob "presentation" c.presentation
dc.presentation
;
7270 oi
"rotation-angle" c.angle
dc.angle
;
7271 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7272 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7273 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7274 oi
"tex-count" c.texcount
dc.texcount
;
7275 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7276 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7277 ob "persistent-location" c.jumpback
dc.jumpback
;
7278 oc
"background-color" c.bgcolor
dc.bgcolor
;
7279 oi
"tile-width" c.tilew
dc.tilew
;
7280 oi
"tile-height" c.tileh
dc.tileh
;
7281 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7282 ob "checkers" c.checkers
dc.checkers
;
7283 oi
"aalevel" c.aalevel
dc.aalevel
;
7284 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7285 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7286 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7287 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7288 oC
"color-space" c.colorspace
dc.colorspace
;
7289 ob "invert-colors" c.invert
dc.invert
;
7290 oF
"brightness" c.colorscale
dc.colorscale
;
7291 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7292 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7293 oco
"columns" c.columns
dc.columns
;
7294 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7295 os
"selection-command" c.selcmd
dc.selcmd
;
7296 os
"synctex-command" c.stcmd
dc.stcmd
;
7297 os
"pax-command" c.paxcmd
dc.paxcmd
;
7298 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7299 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7300 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7301 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7302 ob "use-pbo" c.usepbo
dc.usepbo
;
7303 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7304 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7305 op
"point-and-x" c.pax
dc.pax
;
7306 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7309 let keymapsbuf always
dc c =
7310 let bb = Buffer.create
16 in
7311 let rec loop = function
7313 | (modename, h) :: rest
->
7314 let dh = findkeyhash dc modename in
7315 if always
|| h <> dh
7317 if Hashtbl.length
h > 0
7319 if Buffer.length
bb > 0
7320 then Buffer.add_char
bb '
\n'
;
7321 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7322 Hashtbl.iter
(fun i
o ->
7323 let isdifferent = always
||
7325 let dO = Hashtbl.find dh i
in
7327 with Not_found
-> true
7332 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7333 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7334 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7335 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7336 Buffer.add_string
bb (Wsi.keyname
k);
7339 let rec loop = function
7341 | km
:: [] -> addkm km
7342 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7346 Buffer.add_string
bb "<map in='";
7350 Buffer.add_string
bb "' out='";
7352 Buffer.add_string
bb "'/>\n"
7355 Buffer.add_string
bb "' out='";
7357 Buffer.add_string
bb "'/>\n"
7359 | KMmulti
(ins, kms
) ->
7360 Buffer.add_char
bb ' '
;
7362 Buffer.add_string
bb "' out='";
7364 Buffer.add_string
bb "'/>\n"
7366 Buffer.add_string
bb "</keymap>";
7376 let uifontsize = fstate.fontsize
in
7377 let bb = Buffer.create
32768 in
7378 let relx = float state.x /. float state.winw in
7380 let cx w = truncate
(relx *. float w) in
7382 (fun (w, h, x) ws
->
7384 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7385 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7386 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7388 (state.winw, state.winh
, state.x) state.winstate
7393 let dc = if conf.bedefault
then conf else dc in
7394 Buffer.add_string
bb "<llppconfig>\n";
7396 if nonemptystr
!fontpath
7398 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7404 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7407 Buffer.add_string
bb "<defaults";
7408 add_attrs bb true dc dc;
7409 let kb = keymapsbuf true dc dc in
7410 if Buffer.length
kb > 0
7412 Buffer.add_string
bb ">\n";
7413 Buffer.add_buffer
bb kb;
7414 Buffer.add_string
bb "\n</defaults>\n";
7416 else Buffer.add_string
bb "/>\n";
7418 let adddoc path pan
anchor c bookmarks =
7419 if bookmarks == [] && c = dc && anchor = emptyanchor
7422 Printf.bprintf
bb "<doc path='%s'"
7423 (enent
path 0 (String.length
path));
7425 if anchor <> emptyanchor
7427 let n, rely, visy
= anchor in
7428 Printf.bprintf
bb " page='%d'" n;
7431 Printf.bprintf
bb " rely='%f'" rely
7433 if abs_float visy
> 1e-6
7435 Printf.bprintf
bb " visy='%f'" visy
7440 then Printf.bprintf
bb " pan='%d'" pan
;
7442 add_attrs bb false dc c;
7443 let kb = keymapsbuf false dc c in
7445 begin match bookmarks with
7447 if Buffer.length
kb > 0
7449 Buffer.add_string
bb ">\n";
7450 Buffer.add_buffer
bb kb;
7451 Buffer.add_string
bb "\n</doc>\n";
7453 else Buffer.add_string
bb "/>\n"
7455 Buffer.add_string
bb ">\n<bookmarks>\n";
7456 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7458 "<item title='%s' page='%d'"
7459 (enent
title 0 (String.length
title))
7464 Printf.bprintf
bb " rely='%f'" rely
7466 if abs_float visy
> 1e-6
7468 Printf.bprintf
bb " visy='%f'" visy
7470 Buffer.add_string
bb "/>\n";
7472 Buffer.add_string
bb "</bookmarks>";
7473 if Buffer.length
kb > 0
7475 Buffer.add_string
bb "\n";
7476 Buffer.add_buffer
bb kb;
7478 Buffer.add_string
bb "\n</doc>\n";
7484 match state.mode with
7485 | Birdseye
(c, pan, _, _, _) ->
7487 match conf.columns
with
7488 | Cmulti
((c, _, _), _) -> Some
c
7492 match c.columns
with
7493 | Cmulti
(c, _) -> Cmulti
(c, [||])
7494 | Csingle
_ -> Csingle
[||]
7495 | Csplit
_ -> failwith
"quit from bird's eye while split"
7497 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7500 let basename = Filename.basename
7501 (if emptystr
state.origin
then state.path else state.origin
)
7503 adddoc basename pan (getanchor ())
7505 let autoscrollstep =
7506 match state.autoscroll
with
7508 | None
-> conf.autoscrollstep
7510 match state.mode with
7511 | Birdseye
(bc
, _, _, _, _) ->
7514 presentation
= bc
.presentation
;
7515 interpagespace
= bc
.interpagespace
;
7516 maxwait
= bc
.maxwait
;
7517 autoscrollstep = autoscrollstep }
7518 | _ -> { conf with autoscrollstep = autoscrollstep }
7520 (if conf.savebmarks
then state.bookmarks else []);
7522 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7524 then adddoc path x anchor c bookmarks
7526 Buffer.add_string
bb "</llppconfig>\n";
7529 if load1 f && Buffer.length
bb > 0
7532 let tmp = !confpath ^
".tmp" in
7533 let oc = open_out_bin
tmp in
7534 Buffer.output_buffer
oc bb;
7536 Unix.rename
tmp !confpath;
7539 ("error while saving configuration: " ^ exntos exn
)
7543 let adderrmsg src msg
=
7544 Buffer.add_string
state.errmsgs msg
;
7545 state.newerrmsgs
<- true;
7549 let adderrfmt src fmt
=
7550 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7554 let cl = splitatspace cmds
in
7556 try Scanf.sscanf
s fmt
f
7558 adderrfmt "remote exec"
7559 "error processing '%S': %s\n" cmds
(exntos exn
)
7562 | "reload" :: [] -> reload ()
7563 | "goto" :: args :: [] ->
7564 scan args "%u %f %f"
7566 let cmd, _ = state.geomcmds
in
7568 then gotopagexy pageno x y
7571 gotopagexy pageno x y;
7574 state.reprf
<- f state.reprf
7576 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7577 | "rect" :: args :: [] ->
7578 scan args "%u %u %f %f %f %f"
7579 (fun pageno color x0 y0 x1 y1 ->
7580 onpagerect pageno (fun w h ->
7581 let _,w1,h1
,_ = getpagedim pageno in
7582 let sw = float w1 /. float w
7583 and sh = float h1
/. float h in
7587 and y1s
= y1 *. sh in
7588 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7590 state.rects <- (pageno, color, rect) :: state.rects;
7591 G.postRedisplay "rect";
7594 | "activatewin" :: [] -> Wsi.activatewin
()
7595 | "quit" :: [] -> raise Quit
7597 adderrfmt "remote command"
7598 "error processing remote command: %S\n" cmds
;
7602 let scratch = String.create
80 in
7603 let buf = Buffer.create
80 in
7606 try Some
(Unix.read fd
scratch 0 80)
7608 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7609 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7612 match tempfr () with
7618 if Buffer.length
buf > 0
7620 let s = Buffer.contents
buf in
7630 let pos = String.index_from
scratch ppos '
\n'
in
7631 if pos >= n then -1 else pos
7632 with Not_found
-> -1
7636 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7637 let s = Buffer.contents
buf in
7643 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7649 let remoteopen path =
7650 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7652 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7657 let trimcachepath = ref "" in
7658 let rcmdpath = ref "" in
7659 selfexec := Sys.executable_name
;
7662 [("-p", Arg.String
(fun s -> state.password
<- s),
7663 "<password> Set password");
7667 Config.fontpath := s;
7668 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7670 "<path> Set path to the user interface font");
7674 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7675 Config.confpath := s),
7676 "<path> Set path to the configuration file");
7678 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7679 "<path> Set path to the trim cache file");
7681 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7682 "<named-destination> Set named destination");
7684 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7685 ("-cxack", Arg.Set
cxack, " Cut corners");
7687 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7688 "<path> Set path to the remote commands source");
7690 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7691 "<original-path> Set original path");
7693 ("-v", Arg.Unit
(fun () ->
7695 "%s\nconfiguration path: %s\n"
7699 exit
0), " Print version and exit");
7702 (fun s -> state.path <- s)
7703 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7706 then selfexec := !selfexec ^
" -wtmode";
7708 if emptystr
state.path
7709 then (prerr_endline
"file name missing"; exit
1);
7711 if not
(Config.load ())
7712 then prerr_endline
"failed to load configuration";
7714 let wsfd, winw, winh
= Wsi.init
(object
7715 val mutable m_hack
= false
7716 method expose
= if not m_hack
then G.postRedisplay "expose"
7717 method visible
= G.postRedisplay "visible"
7718 method display = m_hack
<- false; display ()
7719 method reshape w h =
7720 m_hack
<- w < state.winw && h < state.winh
;
7722 method mouse
b d x y m = state.uioh <- state.uioh#button
b d x y m
7724 state.mpos
<- (x, y);
7725 state.uioh <- state.uioh#motion
x y
7726 method pmotion
x y =
7727 state.mpos
<- (x, y);
7728 state.uioh <- state.uioh#pmotion
x y
7730 let mascm = m land (
7731 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7733 match state.keystate
with
7735 let km = k, mascm in
7738 let modehash = state.uioh#
modehash in
7739 try Hashtbl.find modehash km
7741 try Hashtbl.find (findkeyhash conf "global") km
7742 with Not_found
-> KMinsrt
(k, m)
7744 | KMinsrt
(k, m) -> keyboard k m
7745 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7746 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7748 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7749 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7750 state.keystate
<- KSnone
7751 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7752 state.keystate
<- KSinto
(keys
, insrt
)
7754 state.keystate
<- KSnone
7757 state.mpos
<- (x, y);
7758 state.uioh <- state.uioh#pmotion
x y
7759 method leave = state.mpos
<- (-1, -1)
7760 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7761 method quit
= raise Quit
7762 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7767 List.exists
GlMisc.check_extension
7768 [ "GL_ARB_texture_rectangle"
7769 ; "GL_EXT_texture_recangle"
7770 ; "GL_NV_texture_rectangle" ]
7772 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7775 let r = GlMisc.get_string `renderer
in
7776 let p = "Mesa DRI Intel(" in
7777 let l = String.length
p in
7778 String.length
r > l && String.sub
r 0 l = p
7781 defconf.sliceheight
<- 1024;
7782 defconf.texcount
<- 32;
7783 defconf.usepbo
<- true;
7787 match Ne.pipe () with
7789 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7793 match Ne.pipe () with
7795 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7805 setcheckers conf.checkers
;
7807 if conf.redirectstderr
7810 let s = Buffer.contents
state.errmsgs ^
7811 (match state.errfd
with
7813 let s = String.create
(80*24) in
7816 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7818 then Unix.read fd
s 0 (String.length
s)
7824 else String.sub
s 0 n
7828 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7829 with exn
-> print_endline
(exntos exn
)
7834 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7835 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7836 !Config.fontpath, !trimcachepath,
7837 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7839 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
7842 state.text <- "Opening " ^
(mbtoutf8
state.path);
7844 opendoc state.path state.password
;
7848 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7851 if nonemptystr
!rcmdpath
7852 then remoteopen !rcmdpath
7857 let rec loop deadline
=
7859 match state.errfd
with
7860 | None
-> [state.sr
; state.wsfd]
7861 | Some fd
-> [state.sr
; state.wsfd; fd
]
7866 | Some fd
-> fd
:: r
7870 state.redisplay
<- false;
7877 if deadline
= infinity
7879 else max
0.0 (deadline
-. now)
7884 try Unix.select
r [] [] timeout
7885 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7891 if state.ghyll
== noghyll
7893 match state.autoscroll
with
7894 | Some step
when step
!= 0 ->
7895 let y = state.y + step
in
7899 else if y >= state.maxy then 0 else y
7902 if state.mode = View
7903 then state.text <- "";
7906 else deadline
+. 0.01
7911 let rec checkfds = function
7913 | fd
:: rest
when fd
= state.sr
->
7914 let cmd = readcmd state.sr
in
7918 | fd
:: rest
when fd
= state.wsfd ->
7922 | fd
:: rest
when Some fd
= !optrfd ->
7923 begin match remote fd
with
7924 | None
-> optrfd := remoteopen !rcmdpath;
7925 | opt -> optrfd := opt
7930 let s = String.create
80 in
7931 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7932 if conf.redirectstderr
7934 Buffer.add_substring
state.errmsgs
s 0 n;
7935 state.newerrmsgs
<- true;
7936 state.redisplay
<- true;
7939 prerr_string
(String.sub
s 0 n);
7947 if deadline
= infinity
7951 match state.autoscroll
with
7952 | Some step
when step
!= 0 -> deadline1
7953 | _ -> if state.ghyll
== noghyll then infinity
else deadline1