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
;
1612 let s = Printf.sprintf
1616 let w = measurestr
fstate.fontsize
s in
1617 GlDraw.color
(0.0, 0.0, 0.0);
1618 filledrect (float (x-2))
1621 (float (y + fstate.fontsize
+ 2));
1622 GlDraw.color
(1.0, 1.0, 1.0);
1623 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1630 let lw = wadjsb state.winw
- x in
1633 let lh = state.winh
- y in
1636 begin match state.texid
with
1638 Gl.enable `texture_2d
;
1639 GlTex.bind_texture `texture_2d id
;
1642 and x1 = float (x+w)
1643 and y1 = float (y+h
) in
1645 let tw = float w /. 16.0
1646 and th
= float h
/. 16.0 in
1647 let tx0 = float tilex /. 16.0
1648 and ty0
= float tiley /. 16.0 in
1650 and ty1
= ty0
+. th
in
1651 Raw.sets_float
state.vraw ~pos
:0
1652 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1653 Raw.sets_float
state.traw ~pos
:0
1654 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1655 GlArray.vertex `two
state.vraw
;
1656 GlArray.tex_coord `two
state.traw
;
1657 GlArray.draw_arrays `triangle_strip
0 4;
1660 GlDraw.color
(1.0, 1.0, 1.0);
1661 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1663 if w > 128 && h
> fstate.fontsize
+ 10
1665 GlDraw.color
(0.0, 0.0, 0.0);
1668 then (col*conf.tilew
, row*conf.tileh
)
1671 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1680 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1682 let tilevisible1 l x y =
1684 and ax1
= l.pagex
+ l.pagevw
1686 and ay1
= l.pagey + l.pagevh in
1690 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1691 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1693 let rx0 = max
ax0 bx0
1694 and ry0
= max ay0 by0
1695 and rx1
= min ax1
bx1
1696 and ry1
= min ay1 by1
in
1698 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1699 nonemptyintersection
1702 let tilevisible layout n x y =
1703 let rec findpageinlayout m
= function
1704 | l :: rest
when l.pageno = n ->
1705 tilevisible1 l x y || (
1706 match conf.columns
with
1707 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1710 | _ :: rest
-> findpageinlayout 0 rest
1713 findpageinlayout 0 layout;
1716 let tileready l x y =
1717 tilevisible1 l x y &&
1718 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1721 let tilepage n p
layout =
1722 let rec loop = function
1726 let f col row _ _ _ _ _ _ =
1727 if state.currently
= Idle
1729 match gettileopaque l col row with
1732 let x = col*conf.tilew
1733 and y = row*conf.tileh
in
1735 let w = l.pagew
- x in
1739 let h = l.pageh
- y in
1744 then getpbo
w h conf.colorspace
1747 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1750 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1751 conf.tilew
, conf.tileh
1760 if nogeomcmds state.geomcmds
1764 let preloadlayout y =
1765 let y = if y < state.winh
then 0 else y - state.winh
in
1766 let h = state.winh
*3 in
1771 let rec loop pages
=
1772 if state.currently
!= Idle
1777 begin match getopaque l.pageno with
1779 wcmd "page %d %d" l.pageno l.pagedimno
;
1780 state.currently
<- Loading
(l, state.gen
);
1782 tilepage l.pageno opaque pages
;
1787 if nogeomcmds state.geomcmds
1793 if conf.preload && state.currently
= Idle
1794 then load (preloadlayout state.y);
1797 let layoutready layout =
1798 let rec fold all ls
=
1799 all
&& match ls
with
1801 let seen = ref false in
1802 let allvisible = ref true in
1803 let foo col row _ _ _ _ _ _ =
1805 allvisible := !allvisible &&
1806 begin match gettileopaque l col row with
1812 fold (!seen && !allvisible) rest
1815 let alltilesvisible = fold true layout in
1820 let y = bound y 0 state.maxy
in
1821 let y, layout, proceed
=
1822 match conf.maxwait
with
1823 | Some time
when state.ghyll
== noghyll ->
1824 begin match state.throttle
with
1826 let layout = layout y state.winh
in
1827 let ready = layoutready layout in
1831 state.throttle
<- Some
(layout, y, now ());
1833 else G.postRedisplay "gotoy showall (None)";
1835 | Some
(_, _, started
) ->
1836 let dt = now () -. started
in
1839 state.throttle
<- None
;
1840 let layout = layout y state.winh
in
1842 G.postRedisplay "maxwait";
1849 let layout = layout y state.winh
in
1850 if not
!wtmode || layoutready layout
1851 then G.postRedisplay "gotoy ready";
1857 state.layout <- layout;
1858 begin match state.mode
with
1859 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1860 let rec loop = function
1862 state.mode
<- LinkNav
(Ltgendir
0)
1863 | l :: _ when l.pageno = pageno ->
1864 begin match getopaque pageno with
1866 state.mode
<- LinkNav
(Ltgendir
0)
1868 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1869 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1870 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1871 then state.mode
<- LinkNav
(Ltgendir
0)
1873 | _ :: rest
-> loop rest
1878 begin match state.mode
with
1879 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1880 if not
(pagevisible layout pageno)
1882 match state.layout with
1885 state.mode
<- Birdseye
(
1886 conf, leftx
, l.pageno, hooverpageno
, anchor
1889 | LinkNav
(Ltgendir dir
as lt
) ->
1891 let rec loop = function
1894 match getopaque l.pageno with
1900 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1902 if dir
> 0 then LDfirst
else LDlast
1908 | Lnotfound
-> loop rest
1910 showlinktype (getlink opaque
n);
1911 Ltexact
(l.pageno, n)
1915 state.mode
<- LinkNav
linknav
1920 state.ghyll
<- noghyll;
1923 let mx, my
= state.mpos
in
1928 let conttiling pageno opaque
=
1929 tilepage pageno opaque
1930 (if conf.preload then preloadlayout state.y else state.layout)
1933 let gotoy_and_clear_text y =
1934 if not
conf.verbose
then state.text <- "";
1940 let coloff = l.pagecol
* l.pageh
in
1941 float (l.pagey + coloff) /. float l.pageh
1948 if conf.presentation
1949 then float l.pagedispy /. float (calcips l.pageh
)
1950 else float l.pagedispy /. float conf.interpagespace
1953 (l.pageno, top, dtop)
1957 match state.layout with
1958 | l :: _ -> getanchor1 l
1960 let n = page_of_y state.y in
1964 let y, h = getpageyh n in
1965 let dy = y - state.y in
1967 if conf.presentation
1969 let ips = calcips h in
1970 float (dy + ips) /. float ips
1972 float dy /. float conf.interpagespace
1977 let getanchory (n, top, dtop) =
1978 let y, h = getpageyh n in
1979 if conf.presentation
1981 let ips = calcips h in
1982 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1984 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1987 let gotoanchor anchor
=
1988 gotoy (getanchory anchor
);
1992 cbput state.hists
.nav
(getanchor ());
1996 let anchor = cbgetc state.hists
.nav dir
in
2001 let scroll f n a
b =
2002 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2004 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2006 then s (float f /. float a
)
2009 then 1.0 -. s ((float (f-b) /. float (n-b)))
2015 let ins = float a
*. 0.5
2016 and outs
= float (n-b) *. 0.5 in
2018 ins +. outs
+. float ones
2020 let rec set (_N
, _A
, _B
) y sy
=
2021 let sum = summa _N _A _B
in
2022 let dy = float (y - sy
) in
2026 then state.ghyll
<- noghyll
2029 let s = scroll n _N _A _B
in
2030 let y1 = y1 +. ((s *. dy) /. sum) in
2031 gotoy_and_clear_text (truncate
y1);
2032 state.ghyll
<- gf (n+1) y1;
2036 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2038 gf 0 (float state.y)
2041 match conf.ghyllscroll
with
2043 gotoy_and_clear_text y
2045 if state.ghyll
== noghyll
2046 then set nab
y state.y
2047 else state.ghyll
(Some
y)
2050 let gotopage n top =
2051 let y, h = getpageyh n in
2052 let y = y + (truncate
(top *. float h)) in
2056 let gotopage1 n top =
2057 let y = getpagey n in
2062 let invalidate s f =
2067 match state.geomcmds
with
2068 | ps
, [] when emptystr ps
->
2070 state.geomcmds
<- s, [];
2073 state.geomcmds
<- ps
, [s, f];
2075 | ps
, (s'
, _) :: rest
when s'
= s ->
2076 state.geomcmds
<- ps
, ((s, f) :: rest
);
2079 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2083 Hashtbl.iter
(fun _ opaque
->
2084 wcmd "freepage %s" opaque
;
2086 Hashtbl.clear
state.pagemap
;
2090 if not
(Queue.is_empty
state.tilelru
)
2092 Queue.iter
(fun (k
, p
, s) ->
2093 wcmd "freetile %s" p
;
2094 state.memused
<- state.memused
- s;
2095 Hashtbl.remove
state.tilemap k
;
2097 state.uioh#infochanged Memused
;
2098 Queue.clear
state.tilelru
;
2104 let h = truncate
(float h*.conf.zoom
) in
2105 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2109 let opendoc path password
=
2111 state.password
<- password
;
2112 state.gen
<- state.gen
+ 1;
2113 state.docinfo
<- [];
2116 setaalevel
conf.aalevel
;
2118 if emptystr
state.origin
2122 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2123 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2124 invalidate "reqlayout"
2126 wcmd "reqlayout %d %d %d %s\000"
2127 conf.angle
(FMTE.to_int conf.fitmodel
)
2128 (stateh state.winh
) state.nameddest
2133 state.anchor <- getanchor ();
2134 opendoc state.path
state.password
;
2138 let c = c *. conf.colorscale
in
2142 let scalecolor2 (r
, g, b) =
2143 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2146 let docolumns = function
2148 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2149 let rec loop pageno pdimno pdim
y ph pdims
=
2150 if pageno = state.pagecount
2153 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2155 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2156 pdimno+1, pdim
, rest
2160 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2162 (if conf.presentation
2163 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2164 else (if pageno = 0 then 0 else conf.interpagespace
)
2167 a.(pageno) <- (pdimno, x, y, pdim
);
2168 loop (pageno+1) pdimno pdim
(y + h) h pdims
2170 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2171 conf.columns
<- Csingle
a;
2173 | Cmulti
((columns
, coverA
, coverB
), _) ->
2174 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2175 let rec loop pageno pdimno pdim
x y rowh pdims
=
2176 let rec fixrow m
= if m
= pageno then () else
2177 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2180 let y = y + (rowh
- h) / 2 in
2181 a.(m
) <- (pdimno, x, y, pdim
);
2185 if pageno = state.pagecount
2186 then fixrow (((pageno - 1) / columns
) * columns
)
2188 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2190 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2191 pdimno+1, pdim
, rest
2196 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2198 let x = (wadjsb state.winw
- w) / 2 in
2200 if conf.presentation
then calcips h else conf.interpagespace
in
2201 x, y + ips + rowh
, h
2204 if (pageno - coverA
) mod columns
= 0
2206 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2208 if conf.presentation
2210 let ips = calcips h in
2211 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2213 y + (if pageno = 0 then 0 else conf.interpagespace
)
2217 else x, y, max rowh
h
2221 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2224 if pageno = columns
&& conf.presentation
2226 let ips = calcips rowh
in
2227 for i
= 0 to pred columns
2229 let (pdimno, x, y, pdim
) = a.(i
) in
2230 a.(i
) <- (pdimno, x, y+ips, pdim
)
2236 fixrow (pageno - columns
);
2241 a.(pageno) <- (pdimno, x, y, pdim
);
2242 let x = x + w + xoff
*2 + conf.interpagespace
in
2243 loop (pageno+1) pdimno pdim
x y rowh' pdims
2245 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2246 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2249 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2250 let rec loop pageno pdimno pdim
y pdims
=
2251 if pageno = state.pagecount
2254 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2256 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2257 pdimno+1, pdim
, rest
2262 let rec loop1 n x y =
2263 if n = c then y else (
2264 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2265 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2268 let y = loop1 0 0 y in
2269 loop (pageno+1) pdimno pdim
y pdims
2271 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2272 conf.columns
<- Csplit
(c, a);
2276 docolumns conf.columns
;
2277 state.maxy
<- calcheight ();
2278 if state.reprf
== noreprf
2280 match state.mode
with
2281 | Birdseye
(_, _, pageno, _, _) ->
2282 let y, h = getpageyh pageno in
2283 let top = (state.winh
- h) / 2 in
2284 gotoy (max
0 (y - top))
2285 | _ -> gotoanchor state.anchor
2289 state.reprf
<- noreprf;
2294 GlDraw.viewport
0 0 w h;
2295 let firsttime = state.geomcmds
== firstgeomcmds in
2296 if not
firsttime && nogeomcmds state.geomcmds
2297 then state.anchor <- getanchor ();
2300 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2303 setfontsize fstate.fontsize
;
2304 GlMat.mode `modelview
;
2305 GlMat.load_identity
();
2307 GlMat.mode `projection
;
2308 GlMat.load_identity
();
2309 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2310 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2311 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2316 else float state.x /. float state.w
2318 invalidate "geometry"
2322 then state.x <- truncate
(relx *. float w);
2324 match conf.columns
with
2326 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2327 | Csplit
(c, _) -> w * c
2329 wcmd "geometry %d %d %d"
2330 w (stateh h) (FMTE.to_int conf.fitmodel
)
2335 let len = String.length
state.text in
2338 match state.mode
with
2339 | Textentry
_ | View
| LinkNav
_ ->
2340 let h, _, _ = state.uioh#scrollpw
in
2345 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2346 (x+.w) (float (state.winh
- hscrollh))
2349 let w = float (wadjsb state.winw
- 1) in
2350 if state.progress
>= 0.0 && state.progress
< 1.0
2352 GlDraw.color
(0.3, 0.3, 0.3);
2353 let w1 = w *. state.progress
in
2355 GlDraw.color
(0.0, 0.0, 0.0);
2359 GlDraw.color
(0.0, 0.0, 0.0);
2363 GlDraw.color
(1.0, 1.0, 1.0);
2364 drawstring fstate.fontsize
2365 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2368 match state.mode
with
2369 | Textentry
((prefix
, text, _, _, _, _), _) ->
2373 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2375 Printf.sprintf
"%s%s_" prefix
text
2384 if not
(istextentry state.mode
) && state.uioh#eformsgs
2386 let s1 = "(press 'e' to review error messasges)" in
2387 if nonemptystr
s then s ^
" " ^
s1 else s1
2397 let len = Queue.length
state.tilelru
in
2399 match state.throttle
with
2402 then preloadlayout state.y
2404 | Some
(layout, _, _) ->
2408 if state.memused
<= conf.memlimit
2413 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2414 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2415 let (_, pw, ph
, _) = getpagedim n in
2418 && colorspace
= conf.colorspace
2419 && angle
= conf.angle
2423 let x = col*conf.tilew
2424 and y = row*conf.tileh
in
2425 tilevisible (Lazy.force_val
layout) n x y
2427 then Queue.push lruitem
state.tilelru
2430 wcmd "freetile %s" p
;
2431 state.memused
<- state.memused
- s;
2432 state.uioh#infochanged Memused
;
2433 Hashtbl.remove
state.tilemap k
;
2441 let logcurrently = function
2442 | Idle
-> dolog
"Idle"
2443 | Loading
(l, gen
) ->
2444 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2445 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2447 "Tiling %d[%d,%d] page=%s cs=%s angle"
2448 l.pageno col row pageopaque
2449 (CSTE.to_string colorspace
)
2451 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2452 angle gen
conf.angle
state.gen
2454 conf.tilew
conf.tileh
2461 let r = Str.regexp
" " in
2462 fun s -> Str.bounded_split
r s 2;
2465 let onpagerect pageno f =
2467 match conf.columns
with
2468 | Cmulti
(_, b) -> b
2470 | Csplit
(_, b) -> b
2472 if pageno >= 0 && pageno < Array.length
b
2474 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2478 let gotopagexy1 pageno x y =
2479 let _,w1,h1
,leftx
= getpagedim pageno in
2480 let top = y /. (float h1
) in
2481 let left = x /. (float w1) in
2482 let py, w, h = getpageywh pageno in
2483 let wh = state.winh
- hscrollh () in
2484 let x = left *. (float w) in
2485 let x = leftx
+ state.x + truncate
x in
2487 if x < 0 || x >= wadjsb state.winw
2491 let pdy = truncate
(top *. float h) in
2492 let y'
= py + pdy in
2493 let dy = y'
- state.y in
2495 if x != state.x || not
(dy > 0 && dy < wh)
2497 if conf.presentation
2499 if abs
(py - y'
) > wh
2506 if state.x != sx || state.y != sy
2511 let ww = wadjsb state.winw
in
2513 and qy
= pdy / wh in
2515 and y = py + qy
* wh in
2516 let x = if -x + ww > w1 then -(w1-ww) else x
2517 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2519 if conf.presentation
2521 if abs
(py - y'
) > wh
2531 gotoy_and_clear_text y;
2533 else gotoy_and_clear_text state.y;
2536 let gotopagexy pageno x y =
2537 match state.mode
with
2538 | Birdseye
_ -> gotopage pageno 0.0
2539 | _ -> gotopagexy1 pageno x y
2543 (* dolog "%S" cmds; *)
2544 let cl = splitatspace cmds
in
2546 try Scanf.sscanf
s fmt
f
2548 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2553 state.uioh#infochanged Pdim
;
2556 | "clearrects" :: [] ->
2557 state.rects
<- state.rects1
;
2558 G.postRedisplay "clearrects";
2560 | "continue" :: args :: [] ->
2561 let n = scan args "%u" (fun n -> n) in
2562 state.pagecount
<- n;
2563 begin match state.currently
with
2565 state.currently
<- Idle
;
2566 state.outlines
<- Array.of_list
(List.rev
l)
2570 let cur, cmds
= state.geomcmds
in
2572 then failwith
"umpossible";
2574 begin match List.rev cmds
with
2576 state.geomcmds
<- "", [];
2580 state.geomcmds
<- s, List.rev rest
;
2582 if conf.maxwait
= None
&& not
!wtmode
2583 then G.postRedisplay "continue";
2585 | "title" :: args :: [] ->
2588 | "msg" :: args :: [] ->
2591 | "vmsg" :: args :: [] ->
2593 then showtext ' '
args
2595 | "emsg" :: args :: [] ->
2596 Buffer.add_string
state.errmsgs
args;
2597 state.newerrmsgs
<- true;
2598 G.postRedisplay "error message"
2600 | "progress" :: args :: [] ->
2601 let progress, text =
2604 f, String.sub
args pos
(String.length
args - pos
))
2607 state.progress <- progress;
2608 G.postRedisplay "progress"
2610 | "firstmatch" :: args :: [] ->
2611 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2612 scan args "%u %d %f %f %f %f %f %f %f %f"
2613 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2614 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2616 let y = (getpagey pageno) + truncate
y0 in
2619 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2621 | "match" :: args :: [] ->
2622 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2623 scan args "%u %d %f %f %f %f %f %f %f %f"
2624 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2625 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2628 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2630 | "page" :: args :: [] ->
2631 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2632 begin match state.currently
with
2633 | Loading
(l, gen
) ->
2634 vlog "page %d took %f sec" l.pageno t
;
2635 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2636 begin match state.throttle
with
2638 let preloadedpages =
2640 then preloadlayout state.y
2645 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2646 IntSet.empty
preloadedpages
2649 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2650 if not
(IntSet.mem
pageno set)
2652 wcmd "freepage %s" opaque
;
2658 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2661 state.currently
<- Idle
;
2664 tilepage l.pageno pageopaque state.layout;
2666 load preloadedpages;
2667 if pagevisible state.layout l.pageno
2668 && layoutready state.layout
2669 then G.postRedisplay "page";
2672 | Some
(layout, _, _) ->
2673 state.currently
<- Idle
;
2674 tilepage l.pageno pageopaque layout;
2679 dolog
"Inconsistent loading state";
2680 logcurrently state.currently
;
2684 | "tile" :: args :: [] ->
2685 let (x, y, opaque
, size
, t
) =
2686 scan args "%u %u %s %u %f"
2687 (fun x y p size t
-> (x, y, p
, size
, t
))
2689 begin match state.currently
with
2690 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2691 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2694 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2696 wcmd "freetile %s" opaque
;
2697 state.currently
<- Idle
;
2701 puttileopaque l col row gen cs angle opaque size t
;
2702 state.memused
<- state.memused
+ size
;
2703 state.uioh#infochanged Memused
;
2705 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2706 opaque
, size
) state.tilelru
;
2709 match state.throttle
with
2710 | None
-> state.layout
2711 | Some
(layout, _, _) -> layout
2714 state.currently
<- Idle
;
2716 && conf.colorspace
= cs
2717 && conf.angle
= angle
2718 && tilevisible layout l.pageno x y
2719 then conttiling l.pageno pageopaque;
2721 begin match state.throttle
with
2723 preload state.layout;
2725 && conf.colorspace
= cs
2726 && conf.angle
= angle
2727 && tilevisible state.layout l.pageno x y
2728 && (not
!wtmode || layoutready state.layout)
2729 then G.postRedisplay "tile nothrottle";
2731 | Some
(layout, y, _) ->
2732 let ready = layoutready layout in
2736 state.layout <- layout;
2737 state.throttle
<- None
;
2738 G.postRedisplay "throttle";
2745 dolog
"Inconsistent tiling state";
2746 logcurrently state.currently
;
2750 | "pdim" :: args :: [] ->
2751 let (n, w, h, _) as pdim
=
2752 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2755 match conf.fitmodel
, conf.columns
with
2756 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2759 state.uioh#infochanged Pdim
;
2760 state.pdims
<- pdim :: state.pdims
2762 | "o" :: args :: [] ->
2763 let (l, n, t
, h, pos
) =
2764 scan args "%u %u %d %u %n"
2765 (fun l n t
h pos
-> l, n, t
, h, pos
)
2767 let s = String.sub
args pos
(String.length
args - pos
) in
2768 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2769 begin match state.currently
with
2770 | Outlining outlines
->
2771 state.currently
<- Outlining
(outline :: outlines
)
2773 state.currently
<- Outlining
[outline]
2775 dolog
"invalid outlining state";
2776 logcurrently currently
2779 | "a" :: args :: [] ->
2781 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2783 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2785 | "info" :: args :: [] ->
2786 state.docinfo
<- (1, args) :: state.docinfo
2788 | "infoend" :: [] ->
2789 state.uioh#infochanged Docinfo
;
2790 state.docinfo
<- List.rev
state.docinfo
2793 error
"unknown cmd `%S'" cmds
2798 let action = function
2799 | HCprev
-> cbget cb ~
-1
2800 | HCnext
-> cbget cb
1
2801 | HCfirst
-> cbget cb ~
-(cb
.rc)
2802 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2803 and cancel
() = cb
.rc <- rc
2807 let search pattern forward
=
2808 match conf.columns
with
2810 showtext '
!'
"searching does not work properly in split columns mode"
2812 if nonemptystr pattern
2815 match state.layout with
2818 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2820 wcmd "search %d %d %d %d,%s\000"
2821 (btod conf.icase
) pn py (btod forward
) pattern
;
2824 let intentry text key =
2826 if key >= 32 && key < 127
2832 let text = addchar text c in
2836 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2840 let linknentry text key =
2842 if key >= 32 && key < 127
2848 let text = addchar text c in
2852 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2860 let l = String.length
s in
2861 let rec loop pos
n = if pos
= l then n else
2862 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2863 loop (pos
+1) (n*26 + m)
2866 let rec loop n = function
2869 match getopaque l.pageno with
2870 | None
-> loop n rest
2872 let m = getlinkcount opaque
in
2875 let under = getlink opaque
n in
2878 else loop (n-m) rest
2880 loop n state.layout;
2884 let textentry text key =
2885 if key land 0xff00 = 0xff00
2887 else TEcont
(text ^ toutf8
key)
2890 let reqlayout angle fitmodel
=
2891 match state.throttle
with
2893 if nogeomcmds state.geomcmds
2894 then state.anchor <- getanchor ();
2895 conf.angle
<- angle
mod 360;
2898 match state.mode
with
2899 | LinkNav
_ -> state.mode
<- View
2902 conf.fitmodel
<- fitmodel
;
2903 invalidate "reqlayout"
2905 wcmd "reqlayout %d %d %d"
2906 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2911 let settrim trimmargins trimfuzz
=
2912 if nogeomcmds state.geomcmds
2913 then state.anchor <- getanchor ();
2914 conf.trimmargins
<- trimmargins
;
2915 conf.trimfuzz
<- trimfuzz
;
2916 let x0, y0, x1, y1 = trimfuzz
in
2917 invalidate "settrim"
2919 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2924 match state.throttle
with
2926 let zoom = max
0.0001 zoom in
2927 if zoom <> conf.zoom
2929 state.prevzoom
<- (conf.zoom, state.x);
2931 reshape state.winw
state.winh
;
2932 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2935 | Some
(layout, y, started
) ->
2937 match conf.maxwait
with
2941 let dt = now () -. started
in
2949 let setcolumns mode columns coverA coverB
=
2950 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2954 then showtext '
!'
"split mode doesn't work in bird's eye"
2956 conf.columns
<- Csplit
(-columns
, [||]);
2964 conf.columns
<- Csingle
[||];
2969 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2973 reshape state.winw
state.winh
;
2976 let enterbirdseye () =
2977 let zoom = float conf.thumbw
/. float state.winw
in
2978 let birdseyepageno =
2979 let cy = state.winh
/ 2 in
2983 let rec fold best
= function
2986 let d = cy - (l.pagedispy + l.pagevh/2)
2987 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2988 if abs
d < abs dbest
2995 state.mode
<- Birdseye
(
2996 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2999 conf.presentation
<- false;
3000 conf.interpagespace
<- 10;
3001 conf.hlinks
<- false;
3002 conf.fitmodel
<- FitProportional
;
3004 state.mstate
<- Mnone
;
3005 conf.maxwait
<- None
;
3007 match conf.beyecolumns
with
3010 Cmulti
((c, 0, 0), [||])
3011 | None
-> Csingle
[||]
3013 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3016 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3021 reshape state.winw
state.winh
;
3024 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3026 conf.zoom <- c.zoom;
3027 conf.presentation
<- c.presentation
;
3028 conf.interpagespace
<- c.interpagespace
;
3029 conf.maxwait
<- c.maxwait
;
3030 conf.hlinks
<- c.hlinks
;
3031 conf.fitmodel
<- c.fitmodel
;
3032 conf.beyecolumns
<- (
3033 match conf.columns
with
3034 | Cmulti
((c, _, _), _) -> Some
c
3036 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3039 match c.columns
with
3040 | Cmulti
(c, _) -> Cmulti
(c, [||])
3041 | Csingle
_ -> Csingle
[||]
3042 | Csplit
(c, _) -> Csplit
(c, [||])
3046 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3049 reshape state.winw
state.winh
;
3050 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3054 let togglebirdseye () =
3055 match state.mode
with
3056 | Birdseye vals
-> leavebirdseye vals
true
3057 | View
-> enterbirdseye ()
3061 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3062 let pageno = max
0 (pageno - incr
) in
3063 let rec loop = function
3064 | [] -> gotopage1 pageno 0
3065 | l :: _ when l.pageno = pageno ->
3066 if l.pagedispy >= 0 && l.pagey = 0
3067 then G.postRedisplay "upbirdseye"
3068 else gotopage1 pageno 0
3069 | _ :: rest
-> loop rest
3072 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3075 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3076 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3077 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3078 let rec loop = function
3080 let y, h = getpageyh pageno in
3081 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3083 | l :: _ when l.pageno = pageno ->
3084 if l.pagevh != l.pageh
3085 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3086 else G.postRedisplay "downbirdseye"
3087 | _ :: rest
-> loop rest
3092 let optentry mode
_ key =
3093 let btos b = if b then "on" else "off" in
3094 if key >= 32 && key < 127
3096 let c = Char.chr
key in
3100 try conf.scrollstep
<- int_of_string
s with exc
->
3101 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3103 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3108 conf.autoscrollstep
<- int_of_string
s;
3109 if state.autoscroll
<> None
3110 then state.autoscroll
<- Some
conf.autoscrollstep
3112 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3114 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3119 let n, a, b = multicolumns_of_string s in
3120 setcolumns mode
n a b;
3122 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3124 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3129 let zoom = float (int_of_string
s) /. 100.0 in
3132 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3134 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3139 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3141 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3142 begin match mode
with
3144 leavebirdseye beye
false;
3149 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3151 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3156 Some
(int_of_string
s)
3158 state.text <- Printf.sprintf
"bad integer `%s': %s"
3162 | Some angle
-> reqlayout angle
conf.fitmodel
3165 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3168 conf.icase
<- not
conf.icase
;
3169 TEdone
("case insensitive search " ^
(btos conf.icase
))
3172 conf.preload <- not
conf.preload;
3174 TEdone
("preload " ^
(btos conf.preload))
3177 conf.verbose
<- not
conf.verbose
;
3178 TEdone
("verbose " ^
(btos conf.verbose
))
3181 conf.debug
<- not
conf.debug
;
3182 TEdone
("debug " ^
(btos conf.debug
))
3185 conf.maxhfit
<- not
conf.maxhfit
;
3186 state.maxy
<- calcheight ();
3187 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3190 conf.crophack
<- not
conf.crophack
;
3191 TEdone
("crophack " ^
btos conf.crophack
)
3195 match conf.maxwait
with
3197 conf.maxwait
<- Some infinity
;
3198 "always wait for page to complete"
3200 conf.maxwait
<- None
;
3201 "show placeholder if page is not ready"
3206 conf.underinfo
<- not
conf.underinfo
;
3207 TEdone
("underinfo " ^
btos conf.underinfo
)
3210 conf.savebmarks
<- not
conf.savebmarks
;
3211 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3217 match state.layout with
3222 conf.interpagespace
<- int_of_string
s;
3223 docolumns conf.columns
;
3224 state.maxy
<- calcheight ();
3225 let y = getpagey pageno in
3228 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3230 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3234 match conf.fitmodel
with
3235 | FitProportional
-> FitWidth
3236 | _ -> FitProportional
3238 reqlayout conf.angle
fm;
3239 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3242 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3243 TEdone
("trim margins " ^
btos conf.trimmargins
)
3246 conf.invert
<- not
conf.invert
;
3247 TEdone
("invert colors " ^
btos conf.invert
)
3251 cbput state.hists
.sel
s;
3254 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3255 textentry, ondone, true)
3259 then conf.pax
<- Some
(ref (0.0, 0, 0))
3260 else conf.pax
<- None
;
3261 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3264 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3270 class type lvsource
= object
3271 method getitemcount
: int
3272 method getitem
: int -> (string * int)
3273 method hasaction
: int -> bool
3282 method getactive
: int
3283 method getfirst
: int
3284 method getqsearch
: string
3285 method setqsearch
: string -> unit
3289 class virtual lvsourcebase
= object
3290 val mutable m_active
= 0
3291 val mutable m_first
= 0
3292 val mutable m_qsearch
= ""
3293 val mutable m_pan
= 0
3294 method getactive
= m_active
3295 method getfirst
= m_first
3296 method getqsearch
= m_qsearch
3297 method getpan
= m_pan
3298 method setqsearch
s = m_qsearch
<- s
3301 let withoutlastutf8 s =
3302 let len = String.length
s in
3310 let b = Char.code
s.[pos
] in
3311 if b land 0b11000000 = 0b11000000
3316 if Char.code
s.[len-1] land 0x80 = 0
3320 String.sub
s 0 first;
3323 let textentrykeyboard
3324 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3326 if key >= 0xffb0 && key <= 0xffb9
3327 then key - 0xffb0 + 48 else key
3330 state.mode
<- Textentry
(te
, onleave
);
3333 G.postRedisplay "textentrykeyboard enttext";
3335 let histaction cmd
=
3338 | Some
(action, _) ->
3339 state.mode
<- Textentry
(
3340 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3342 G.postRedisplay "textentry histaction"
3345 | 0xff08 -> (* backspace *)
3346 if emptystr
text && cancelonempty
3349 G.postRedisplay "textentrykeyboard after cancel";
3352 let s = withoutlastutf8 text in
3353 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3355 | 0xff0d | 0xff8d -> (* (kp) enter *)
3358 G.postRedisplay "textentrykeyboard after confirm"
3360 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3361 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3362 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3363 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3365 | 0xff1b -> (* escape*)
3368 begin match opthist
with
3370 | Some
(_, onhistcancel
) -> onhistcancel
()
3374 G.postRedisplay "textentrykeyboard after cancel2"
3377 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3380 | 0xff9f | 0xffff -> () (* delete *)
3383 && key land 0xff00 != 0xff00 (* keyboard *)
3384 && key land 0xfe00 != 0xfe00 (* xkb *)
3385 && key land 0xfd00 != 0xfd00 (* 3270 *)
3387 begin match onkey
text key with
3391 G.postRedisplay "textentrykeyboard after confirm2";
3394 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3398 G.postRedisplay "textentrykeyboard after cancel3"
3401 state.mode
<- Textentry
(te
, onleave
);
3402 G.postRedisplay "textentrykeyboard switch";
3406 vlog "unhandled key %s" (Wsi.keyname
key)
3409 let firstof first active
=
3410 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3411 then max
0 (active
- (fstate.maxrows
/2))
3415 let calcfirst first active
=
3418 let rows = active
- first in
3419 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3423 let scrollph y maxy
=
3424 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3425 let sh = float state.winh
/. sh in
3426 let sh = max
sh (float conf.scrollh
) in
3428 let percent = float y /. float maxy
in
3429 let position = (float state.winh
-. sh) *. percent in
3432 if position +. sh > float state.winh
3433 then float state.winh
-. sh
3439 let coe s = (s :> uioh
);;
3441 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3443 val m_pan
= source#getpan
3444 val m_first
= source#getfirst
3445 val m_active
= source#getactive
3446 val m_qsearch
= source#getqsearch
3447 val m_prev_uioh
= state.uioh
3449 method private elemunder
y =
3450 let n = y / (fstate.fontsize
+1) in
3451 if m_first
+ n < source#getitemcount
3453 if source#hasaction
(m_first
+ n)
3454 then Some
(m_first
+ n)
3461 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3462 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3463 filledrect 0. 0. (float state.winw
) (float state.winh
);
3464 GlDraw.color
(1., 1., 1.);
3465 Gl.enable `texture_2d
;
3466 let fs = fstate.fontsize
in
3468 let ww = fstate.wwidth
in
3469 let tabw = 30.0*.ww in
3470 let itemcount = source#getitemcount
in
3472 if (row - m_first
) > fstate.maxrows
3475 if row >= 0 && row < itemcount
3477 let (s, level
) = source#getitem
row in
3478 let y = (row - m_first
) * nfs in
3479 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3482 Gl.disable `texture_2d
;
3483 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3484 GlDraw.color
(1., 1., 1.) ~
alpha;
3485 linerect 1. (float (y + 1))
3486 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3487 GlDraw.color
(1., 1., 1.);
3488 Gl.enable `texture_2d
;
3491 let drawtabularstring s =
3492 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3495 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3498 let len = String.length
s - tabpos - 1 in
3499 let s1 = String.sub
s 0 tabpos
3500 and s2
= String.sub
s (tabpos + 1) len in
3501 let nx = drawstr x s1 in
3503 let x = x +. (max
tabw sw) in
3510 let _ = drawtabularstring s in
3517 Gl.disable `texture_2d
;
3519 method updownlevel incr
=
3520 let len = source#getitemcount
in
3522 if m_active
>= 0 && m_active
< len
3523 then snd
(source#getitem m_active
)
3527 if i
= len then i
-1 else if i
= -1 then 0 else
3528 let _, l = source#getitem i
in
3529 if l != curlevel then i
else flow (i
+incr
)
3531 let active = flow m_active
in
3532 let first = calcfirst m_first
active in
3533 G.postRedisplay "outline updownlevel";
3534 {< m_active
= active; m_first
= first >}
3536 method private key1
key mask
=
3537 let set1 active first qsearch
=
3538 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3540 let search active pattern incr
=
3541 let active = if active = -1 then m_first
else active in
3544 if n >= 0 && n < source#getitemcount
3546 let s, _ = source#getitem
n in
3548 (try ignore
(Str.search_forward
re s 0); true
3549 with Not_found
-> false)
3551 else loop (n + incr
)
3558 let re = Str.regexp_case_fold pattern
in
3564 let itemcount = source#getitemcount
in
3565 let find start incr
=
3567 if i
= -1 || i
= itemcount
3570 if source#hasaction i
3572 else find (i
+ incr
)
3577 let set active first =
3578 let first = bound first 0 (itemcount - fstate.maxrows
) in
3580 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3583 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3585 let incr1 = if incr
> 0 then 1 else -1 in
3586 if isvisible m_first m_active
3589 let next = m_active
+ incr
in
3591 if next < 0 || next >= itemcount
3593 else find next incr1
3595 if abs
(m_active
- next) > fstate.maxrows
3601 let first = m_first
+ incr
in
3602 let first = bound first 0 (itemcount - fstate.maxrows
) in
3604 let next = m_active
+ incr
in
3605 let next = bound next 0 (itemcount - 1) in
3612 if isvisible first next
3619 let first = min
next m_first
in
3621 if abs
(next - first) > fstate.maxrows
3627 let first = m_first
+ incr
in
3628 let first = bound first 0 (itemcount - 1) in
3630 let next = m_active
+ incr
in
3631 let next = bound next 0 (itemcount - 1) in
3632 let next = find next incr1 in
3634 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3636 let active = if m_active
= -1 then next else m_active
in
3641 if isvisible first active
3647 G.postRedisplay "listview navigate";
3651 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3652 let incr = if key = 0x72 then -1 else 1 in
3654 match search (m_active
+ incr) m_qsearch
incr with
3656 state.text <- m_qsearch ^
" [not found]";
3659 state.text <- m_qsearch
;
3660 active, firstof m_first
active
3662 G.postRedisplay "listview ctrl-r/s";
3663 set1 active first m_qsearch
;
3665 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3666 if m_active
>= 0 && m_active
< source#getitemcount
3668 let s, _ = source#getitem m_active
in
3673 | 0xff08 -> (* backspace *)
3674 if emptystr m_qsearch
3677 let qsearch = withoutlastutf8 m_qsearch
in
3681 G.postRedisplay "listview empty qsearch";
3682 set1 m_active m_first
"";
3686 match search m_active
qsearch ~
-1 with
3688 state.text <- qsearch ^
" [not found]";
3691 state.text <- qsearch;
3692 active, firstof m_first
active
3694 G.postRedisplay "listview backspace qsearch";
3695 set1 active first qsearch
3698 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3699 let pattern = m_qsearch ^ toutf8
key in
3701 match search m_active
pattern 1 with
3703 state.text <- pattern ^
" [not found]";
3706 state.text <- pattern;
3707 active, firstof m_first
active
3709 G.postRedisplay "listview qsearch add";
3710 set1 active first pattern;
3712 | 0xff1b -> (* escape *)
3714 if emptystr m_qsearch
3716 G.postRedisplay "list view escape";
3719 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3721 | None
-> m_prev_uioh
3726 G.postRedisplay "list view kill qsearch";
3727 source#setqsearch
"";
3728 coe {< m_qsearch
= "" >}
3731 | 0xff0d | 0xff8d -> (* (kp) enter *)
3733 let self = {< m_qsearch
= "" >} in
3734 source#setqsearch
"";
3736 G.postRedisplay "listview enter";
3737 if m_active
>= 0 && m_active
< source#getitemcount
3739 source#exit
(coe self) false m_active m_first m_pan
"";
3742 source#exit
(coe self) true m_active m_first m_pan
"";
3745 begin match opt with
3746 | None
-> m_prev_uioh
3750 | 0xff9f | 0xffff -> (* (kp) delete *)
3753 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3754 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3755 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3756 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3758 | 0xff53 | 0xff98 -> (* (kp) right *)
3760 G.postRedisplay "listview right";
3761 coe {< m_pan
= m_pan
- 1 >}
3763 | 0xff51 | 0xff96 -> (* (kp) left *)
3765 G.postRedisplay "listview left";
3766 coe {< m_pan
= m_pan
+ 1 >}
3768 | 0xff50 | 0xff95 -> (* (kp) home *)
3769 let active = find 0 1 in
3770 G.postRedisplay "listview home";
3773 | 0xff57 | 0xff9c -> (* (kp) end *)
3774 let first = max
0 (itemcount - fstate.maxrows
) in
3775 let active = find (itemcount - 1) ~
-1 in
3776 G.postRedisplay "listview end";
3779 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3783 dolog
"listview unknown key %#x" key; coe self
3785 method key key mask
=
3786 match state.mode
with
3787 | Textentry te
-> textentrykeyboard key mask te
; coe self
3788 | _ -> self#key1
key mask
3790 method button button down
x y _ =
3793 | 1 when x > state.winw
- conf.scrollbw
->
3794 G.postRedisplay "listview scroll";
3797 let _, position, sh = self#
scrollph in
3798 if y > truncate
position && y < truncate
(position +. sh)
3800 state.mstate
<- Mscrolly
;
3804 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3805 let first = truncate
(s *. float source#getitemcount
) in
3806 let first = min source#getitemcount
first in
3807 Some
(coe {< m_first
= first; m_active
= first >})
3809 state.mstate
<- Mnone
;
3812 | 1 when not down
->
3813 begin match self#elemunder
y with
3815 G.postRedisplay "listview click";
3817 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3821 | n when (n == 4 || n == 5) && not down
->
3822 let len = source#getitemcount
in
3824 if n = 5 && m_first
+ fstate.maxrows
>= len
3828 let first = m_first
+ (if n == 4 then -1 else 1) in
3829 bound first 0 (len - 1)
3831 G.postRedisplay "listview wheel";
3832 Some
(coe {< m_first
= first >})
3833 | n when (n = 6 || n = 7) && not down
->
3834 let inc = if n = 7 then -1 else 1 in
3835 G.postRedisplay "listview hwheel";
3836 Some
(coe {< m_pan
= m_pan
+ inc >})
3841 | None
-> m_prev_uioh
3845 match state.mstate
with
3847 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3848 let first = truncate
(s *. float source#getitemcount
) in
3849 let first = min source#getitemcount
first in
3850 G.postRedisplay "listview motion";
3851 coe {< m_first
= first; m_active
= first >}
3854 method pmotion
x y =
3855 if x < state.winw
- conf.scrollbw
3858 match self#elemunder
y with
3859 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3860 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3864 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3869 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3873 method infochanged
_ = ()
3875 method scrollpw
= (0, 0.0, 0.0)
3877 let nfs = fstate.fontsize
+ 1 in
3878 let y = m_first
* nfs in
3879 let itemcount = source#getitemcount
in
3880 let maxi = max
0 (itemcount - fstate.maxrows
) in
3881 let maxy = maxi * nfs in
3882 let p, h = scrollph y maxy in
3885 method modehash
= modehash
3886 method eformsgs
= false
3889 class outlinelistview ~source
=
3890 let settext autonarrow
s =
3892 then state.text <- "[" ^
s ^
"]"
3893 else state.text <- s
3897 ~source
:(source
:> lvsource
)
3899 ~modehash
:(findkeyhash conf "outline")
3902 val m_autonarrow
= false
3904 method key key mask
=
3906 if emptystr
state.text
3908 else fstate.maxrows - 2
3910 let calcfirst first active =
3913 let rows = active - first in
3914 if rows > maxrows then active - maxrows else first
3918 let active = m_active
+ incr in
3919 let active = bound active 0 (source#getitemcount
- 1) in
3920 let first = calcfirst m_first
active in
3921 G.postRedisplay "outline navigate";
3922 coe {< m_active
= active; m_first
= first >}
3924 let navscroll first =
3926 let dist = m_active
- first in
3932 else first + maxrows
3935 G.postRedisplay "outline navscroll";
3936 coe {< m_first
= first; m_active
= active >}
3938 let ctrl = Wsi.withctrl mask
in
3940 | 97 when ctrl -> (* ctrl-a *)
3942 then source#denarrow
3943 else source#narrow m_qsearch
;
3944 settext (not m_autonarrow
) m_qsearch
;
3945 G.postRedisplay "toggle auto narrowing";
3946 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3948 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3950 G.postRedisplay "toggle auto narrowing";
3951 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3953 | 110 when ctrl -> (* ctrl-n *)
3954 source#narrow m_qsearch
;
3956 then source#add_narrow_pattern m_qsearch
;
3957 G.postRedisplay "outline ctrl-n";
3958 coe {< m_first
= 0; m_active
= 0 >}
3960 | 115 when ctrl -> (* ctrl-s *)
3961 let active = source#calcactive
(getanchor ()) in
3962 let first = firstof m_first
active in
3963 G.postRedisplay "outline ctrl-s";
3964 coe {< m_first
= first; m_active
= active >}
3966 | 117 when ctrl -> (* ctrl-u *)
3967 source#del_narrow_pattern
;
3968 let pattern = source#renarrow
in
3969 G.postRedisplay "outline ctrl-u";
3971 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3973 settext m_autonarrow
text;
3974 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3976 | 108 when ctrl -> (* ctrl-l *)
3977 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3978 G.postRedisplay "outline ctrl-l";
3979 coe {< m_first
= first >}
3981 | 0xff1b -> (* escape *)
3982 let o = super#
key key mask
in
3985 if nonemptystr m_qsearch
3987 source#add_narrow_pattern m_qsearch
;
3993 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3994 if nonemptystr m_qsearch
3995 then source#add_narrow_pattern m_qsearch
;
3998 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3999 let pattern = m_qsearch ^ toutf8
key in
4000 G.postRedisplay "outlinelistview autonarrow add";
4001 source#narrow
pattern;
4002 settext true pattern;
4003 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4005 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4006 if emptystr m_qsearch
4009 let pattern = withoutlastutf8 m_qsearch
in
4010 G.postRedisplay "outlinelistview autonarrow backspace";
4011 ignore
(source#renarrow
);
4012 source#narrow
pattern;
4013 settext true pattern;
4014 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4016 | 0xff9f | 0xffff -> (* (kp) delete *)
4017 source#remove m_active
;
4018 G.postRedisplay "outline delete";
4019 let active = max
0 (m_active
-1) in
4020 coe {< m_first
= firstof m_first
active;
4021 m_active
= active >}
4023 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4024 navscroll (max
0 (m_first
- 1))
4026 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4027 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4029 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4030 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4031 | 0xff55 | 0xff9a -> (* (kp) prior *)
4032 navigate ~
-(fstate.maxrows)
4033 | 0xff56 | 0xff9b -> (* (kp) next *)
4034 navigate fstate.maxrows
4036 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4040 G.postRedisplay "outline ctrl right";
4041 {< m_pan
= m_pan
+ 1 >}
4043 else self#updownlevel
1
4047 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4051 G.postRedisplay "outline ctrl left";
4052 {< m_pan
= m_pan
- 1 >}
4054 else self#updownlevel ~
-1
4058 | 0xff50 | 0xff95 -> (* (kp) home *)
4059 G.postRedisplay "outline home";
4060 coe {< m_first
= 0; m_active
= 0 >}
4062 | 0xff57 | 0xff9c -> (* (kp) end *)
4063 let active = source#getitemcount
- 1 in
4064 let first = max
0 (active - fstate.maxrows) in
4065 G.postRedisplay "outline end";
4066 coe {< m_active
= active; m_first
= first >}
4068 | _ -> super#
key key mask
4071 let outlinesource usebookmarks
=
4074 inherit lvsourcebase
4075 val mutable m_items
= empty
4076 val mutable m_orig_items
= empty
4077 val mutable m_narrow_patterns
= []
4078 val mutable m_hadremovals
= false
4080 method getitemcount
=
4081 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4084 if n == Array.length m_items
&& m_hadremovals
4086 ("[Confirm removal]", 0)
4088 let s, n, _ = m_items
.(n) in
4091 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4092 ignore
(uioh
, first, qsearch);
4093 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4095 if m_narrow_patterns
= []
4101 if not
confrimremoval
4103 let _, _, ((pageno, y, _) as anchor) = m_items
.(active) in
4105 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4111 state.bookmarks
<- Array.to_list m_items
;
4112 m_orig_items
<- m_items
;
4115 else m_items
<- items;
4119 method hasaction
_ = true
4122 if Array.length m_items
!= Array.length m_orig_items
4125 match m_narrow_patterns
with
4127 | many
-> String.concat
" --> " (List.rev many
)
4129 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4132 method narrow
pattern =
4133 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4137 let rec loop accu n =
4139 then m_items
<- Array.of_list
accu
4141 let (s, _, _) as o = m_items
.(n) in
4143 if (try ignore
(Str.search_forward
re s 0); true
4144 with Not_found
-> false)
4150 loop [] (Array.length m_items
- 1)
4155 then Array.of_list
state.bookmarks
4158 m_items
<- m_orig_items
4163 if m >= 0 && m < Array.length m_items
4165 m_hadremovals
<- true;
4166 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4167 let n = if n >= m then n+1 else n in
4172 method add_narrow_pattern
pattern =
4173 m_narrow_patterns
<- pattern :: m_narrow_patterns
4175 method del_narrow_pattern
=
4176 match m_narrow_patterns
with
4177 | _ :: rest
-> m_narrow_patterns
<- rest
4182 match m_narrow_patterns
with
4183 | pattern :: [] -> self#narrow
pattern; pattern
4185 List.fold_left
(fun accu pattern ->
4186 self#narrow
pattern;
4187 accu ^
" --> " ^
pattern) "" list
4189 method calcactive
anchor =
4190 let rely = getanchory anchor in
4191 let rec loop n best bestd
=
4192 if n = Array.length m_items
4195 let (_, _, anchor) = m_items
.(n) in
4196 let orely = getanchory anchor in
4197 let d = abs
(orely - rely) in
4200 else loop (n+1) best bestd
4204 method reset
anchor items =
4205 m_hadremovals
<- false;
4206 if m_orig_items
== empty
4208 m_orig_items
<- items;
4209 if m_narrow_patterns
== []
4210 then m_items
<- items;
4212 let active = self#calcactive
anchor in
4214 m_first
<- firstof m_first
active
4218 let enterselector usebookmarks
=
4219 let source = outlinesource usebookmarks
in
4223 then Array.of_list
state.bookmarks
4226 if Array.length
outlines = 0
4228 showtext ' ' errmsg
;
4231 state.text <- source#greetmsg
;
4232 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4233 let anchor = getanchor () in
4234 source#reset
anchor outlines;
4235 state.uioh
<- coe (new outlinelistview ~
source);
4236 G.postRedisplay "enter selector";
4240 let enteroutlinemode =
4241 let f = enterselector false in
4242 fun ()-> f "Document has no outline";
4245 let enterbookmarkmode =
4246 let f = enterselector true in
4247 fun () -> f "Document has no bookmarks (yet)";
4250 let color_of_string s =
4251 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4252 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4256 let color_to_string (r, g, b) =
4257 let r = truncate
(r *. 256.0)
4258 and g = truncate
(g *. 256.0)
4259 and b = truncate
(b *. 256.0) in
4260 Printf.sprintf
"%d/%d/%d" r g b
4263 let irect_of_string s =
4264 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4267 let irect_to_string (x0,y0,x1,y1) =
4268 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4271 let makecheckers () =
4272 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4274 converted by Issac Trotts. July 25, 2002 *)
4275 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4276 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4277 let id = GlTex.gen_texture
() in
4278 GlTex.bind_texture `texture_2d
id;
4279 GlPix.store
(`unpack_alignment
1);
4280 GlTex.image2d
image;
4281 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4282 [ `mag_filter `nearest
; `min_filter `nearest
];
4286 let setcheckers enabled
=
4287 match state.texid
with
4289 if enabled
then state.texid
<- Some
(makecheckers ())
4294 GlTex.delete_texture texid
;
4295 state.texid
<- None
;
4299 let int_of_string_with_suffix s =
4300 let l = String.length
s in
4304 let suffix = Char.lowercase
s.[l-1] in
4306 | 'k'
-> String.sub
s 0 (l-1), 10
4307 | '
m'
-> String.sub
s 0 (l-1), 20
4308 | '
g'
-> String.sub
s 0 (l-1), 30
4312 let n = int_of_string
s1 in
4313 let m = n lsl shift
in
4315 then raise
(Failure
"value too large")
4319 let string_with_suffix_of_int n =
4323 let units = [(30, "G"); (20, "M"); (10, "K")] in
4326 let h = n mod 1000 in
4329 then string_of_int
h ^
s
4331 let s = Printf.sprintf
"_%03d%s" h s in
4337 let rec find = function
4339 | (shift
, suffix) :: rest
->
4340 if (n land ((1 lsl shift
) - 1)) = 0
4341 then prettyint (n lsr shift
) ^
suffix
4347 let defghyllscroll = (40, 8, 32);;
4348 let fastghyllscroll = (5,1,2);;
4349 let neatghyllscroll = (10,1,9);;
4350 let ghyllscroll_of_string s =
4352 | "default" -> Some
defghyllscroll
4353 | "fast" -> Some
(5,1,2)
4354 | "neat" -> Some
(10,1,9)
4355 | "" | "none" -> None
4357 let (n,a,b) as nab
=
4358 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4359 if n <= a || n <= b || a >= b
4360 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4365 let ghyllscroll_to_string ((n, a, b) as nab
) =
4366 (**) if nab
= defghyllscroll then "default"
4367 else if nab
= fastghyllscroll then "fast"
4368 else if nab
= neatghyllscroll then "neat"
4369 else Printf.sprintf
"%d,%d,%d" n a b;
4372 let describe_location () =
4373 let fn = page_of_y state.y in
4374 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4375 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4379 else (100. *. (float state.y /. float maxy))
4383 Printf.sprintf
"page %d of %d [%.2f%%]"
4384 (fn+1) state.pagecount
percent
4387 "pages %d-%d of %d [%.2f%%]"
4388 (fn+1) (ln+1) state.pagecount
percent
4391 let setpresentationmode v
=
4392 let n = page_of_y state.y in
4393 state.anchor <- (n, 0.0, 1.0);
4394 conf.presentation
<- v
;
4395 if conf.fitmodel
= FitPage
4396 then reqlayout conf.angle
conf.fitmodel
;
4401 let btos b = if b then "\xe2\x88\x9a" else "" in
4402 let showextended = ref false in
4403 let leave mode
= function
4404 | Confirm
-> state.mode
<- mode
4405 | Cancel
-> state.mode
<- mode
in
4408 val mutable m_first_time
= true
4409 val mutable m_l
= []
4410 val mutable m_a
= [||]
4411 val mutable m_prev_uioh
= nouioh
4412 val mutable m_prev_mode
= View
4414 inherit lvsourcebase
4416 method reset prev_mode prev_uioh
=
4417 m_a
<- Array.of_list
(List.rev m_l
);
4419 m_prev_mode
<- prev_mode
;
4420 m_prev_uioh
<- prev_uioh
;
4424 if n >= Array.length m_a
4428 | _, _, _, Action
_ -> m_active
<- n
4432 m_first_time
<- false;
4435 method int name get
set =
4437 (name, `
int get
, 1, Action
(
4440 try set (int_of_string
s)
4442 state.text <- Printf.sprintf
"bad integer `%s': %s"
4446 let te = name ^
": ", "", None
, intentry, ondone, true in
4447 state.mode
<- Textentry
(te, leave m_prev_mode
);
4451 method int_with_suffix
name get
set =
4453 (name, `intws get
, 1, Action
(
4456 try set (int_of_string_with_suffix s)
4458 state.text <- Printf.sprintf
"bad integer `%s': %s"
4463 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4465 state.mode
<- Textentry
(te, leave m_prev_mode
);
4469 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4471 (name, `
bool (btos, get
), offset
, Action
(
4478 method color
name get
set =
4480 (name, `color get
, 1, Action
(
4482 let invalid = (nan
, nan
, nan
) in
4485 try color_of_string s
4487 state.text <- Printf.sprintf
"bad color `%s': %s"
4494 let te = name ^
": ", "", None
, textentry, ondone, true in
4495 state.text <- color_to_string (get
());
4496 state.mode
<- Textentry
(te, leave m_prev_mode
);
4500 method string name get
set =
4502 (name, `
string get
, 1, Action
(
4504 let ondone s = set s in
4505 let te = name ^
": ", "", None
, textentry, ondone, true in
4506 state.mode
<- Textentry
(te, leave m_prev_mode
);
4510 method colorspace
name get
set =
4512 (name, `
string get
, 1, Action
(
4516 inherit lvsourcebase
4519 m_active
<- CSTE.to_int conf.colorspace
;
4522 method getitemcount
=
4523 Array.length
CSTE.names
4526 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4527 ignore
(uioh
, first, pan
, qsearch);
4528 if not cancel
then set active;
4530 method hasaction
_ = true
4534 let modehash = findkeyhash conf "info" in
4535 coe (new listview ~
source ~trusted
:true ~
modehash)
4538 method paxmark
name get
set =
4540 (name, `
string get
, 1, Action
(
4544 inherit lvsourcebase
4547 m_active
<- MTE.to_int conf.paxmark
;
4550 method getitemcount
= Array.length
MTE.names
4551 method getitem
n = (MTE.names.(n), 0)
4552 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4553 ignore
(uioh
, first, pan
, qsearch);
4554 if not cancel
then set active;
4556 method hasaction
_ = true
4560 let modehash = findkeyhash conf "info" in
4561 coe (new listview ~
source ~trusted
:true ~
modehash)
4564 method fitmodel
name get
set =
4566 (name, `
string get
, 1, Action
(
4570 inherit lvsourcebase
4573 m_active
<- FMTE.to_int conf.fitmodel
;
4576 method getitemcount
= Array.length
FMTE.names
4577 method getitem
n = (FMTE.names.(n), 0)
4578 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4579 ignore
(uioh
, first, pan
, qsearch);
4580 if not cancel
then set active;
4582 method hasaction
_ = true
4586 let modehash = findkeyhash conf "info" in
4587 coe (new listview ~
source ~trusted
:true ~
modehash)
4590 method caption
s offset
=
4591 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4593 method caption2
s f offset
=
4594 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4596 method getitemcount
= Array.length m_a
4599 let tostr = function
4600 | `
int f -> string_of_int
(f ())
4601 | `intws
f -> string_with_suffix_of_int (f ())
4603 | `color
f -> color_to_string (f ())
4604 | `
bool (btos, f) -> btos (f ())
4607 let name, t
, offset
, _ = m_a
.(n) in
4608 ((let s = tostr t
in
4610 then Printf.sprintf
"%s\t%s" name s
4614 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4618 m_qsearch
<- qsearch;
4620 match m_a
.(active) with
4621 | _, _, _, Action
f -> f uioh
4633 method hasaction
n =
4635 | _, _, _, Action
_ -> true
4639 let rec fillsrc prevmode prevuioh
=
4640 let sep () = src#caption
"" 0 in
4641 let colorp name get
set =
4643 (fun () -> color_to_string (get
()))
4646 let c = color_of_string v in
4649 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4652 let oldmode = state.mode
in
4653 let birdseye = isbirdseye state.mode
in
4655 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4657 src#
bool "presentation mode"
4658 (fun () -> conf.presentation
)
4659 (fun v -> setpresentationmode v);
4661 src#
bool "ignore case in searches"
4662 (fun () -> conf.icase
)
4663 (fun v -> conf.icase
<- v);
4666 (fun () -> conf.preload)
4667 (fun v -> conf.preload <- v);
4669 src#
bool "highlight links"
4670 (fun () -> conf.hlinks
)
4671 (fun v -> conf.hlinks
<- v);
4673 src#
bool "under info"
4674 (fun () -> conf.underinfo
)
4675 (fun v -> conf.underinfo
<- v);
4677 src#
bool "persistent bookmarks"
4678 (fun () -> conf.savebmarks
)
4679 (fun v -> conf.savebmarks
<- v);
4681 src#fitmodel
"fit model"
4682 (fun () -> FMTE.to_string conf.fitmodel
)
4683 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4685 src#
bool "trim margins"
4686 (fun () -> conf.trimmargins
)
4687 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4689 src#
bool "persistent location"
4690 (fun () -> conf.jumpback
)
4691 (fun v -> conf.jumpback
<- v);
4694 src#
int "inter-page space"
4695 (fun () -> conf.interpagespace
)
4697 conf.interpagespace
<- n;
4698 docolumns conf.columns
;
4700 match state.layout with
4705 state.maxy <- calcheight ();
4706 let y = getpagey pageno in
4711 (fun () -> conf.pagebias
)
4712 (fun v -> conf.pagebias
<- v);
4714 src#
int "scroll step"
4715 (fun () -> conf.scrollstep
)
4716 (fun n -> conf.scrollstep
<- n);
4718 src#
int "horizontal scroll step"
4719 (fun () -> conf.hscrollstep
)
4720 (fun v -> conf.hscrollstep
<- v);
4722 src#
int "auto scroll step"
4724 match state.autoscroll
with
4726 | _ -> conf.autoscrollstep
)
4728 if state.autoscroll
<> None
4729 then state.autoscroll
<- Some
n;
4730 conf.autoscrollstep
<- n);
4733 (fun () -> truncate
(conf.zoom *. 100.))
4734 (fun v -> setzoom ((float v) /. 100.));
4737 (fun () -> conf.angle
)
4738 (fun v -> reqlayout v conf.fitmodel
);
4740 src#
int "scroll bar width"
4741 (fun () -> conf.scrollbw
)
4744 reshape state.winw
state.winh
;
4747 src#
int "scroll handle height"
4748 (fun () -> conf.scrollh
)
4749 (fun v -> conf.scrollh
<- v;);
4751 src#
int "thumbnail width"
4752 (fun () -> conf.thumbw
)
4754 conf.thumbw
<- min
4096 v;
4757 leavebirdseye beye
false;
4762 let mode = state.mode in
4763 src#
string "columns"
4765 match conf.columns
with
4767 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4768 | Csplit
(count
, _) -> "-" ^ string_of_int count
4771 let n, a, b = multicolumns_of_string v in
4772 setcolumns mode n a b);
4775 src#caption
"Pixmap cache" 0;
4776 src#int_with_suffix
"size (advisory)"
4777 (fun () -> conf.memlimit
)
4778 (fun v -> conf.memlimit
<- v);
4781 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4782 (string_with_suffix_of_int state.memused
)
4783 (Hashtbl.length
state.tilemap
)) 1;
4786 src#caption
"Layout" 0;
4787 src#caption2
"Dimension"
4789 Printf.sprintf
"%dx%d (virtual %dx%d)"
4790 state.winw
state.winh
4795 src#caption2
"Position" (fun () ->
4796 Printf.sprintf
"%dx%d" state.x state.y
4799 src#caption2
"Position" (fun () -> describe_location ()) 1
4803 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4804 "Save these parameters as global defaults at exit"
4805 (fun () -> conf.bedefault
)
4806 (fun v -> conf.bedefault
<- v)
4810 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4811 src#
bool ~offset
:0 ~
btos "Extended parameters"
4812 (fun () -> !showextended)
4813 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4817 (fun () -> conf.checkers
)
4818 (fun v -> conf.checkers
<- v; setcheckers v);
4819 src#
bool "update cursor"
4820 (fun () -> conf.updatecurs
)
4821 (fun v -> conf.updatecurs
<- v);
4823 (fun () -> conf.verbose
)
4824 (fun v -> conf.verbose
<- v);
4825 src#
bool "invert colors"
4826 (fun () -> conf.invert
)
4827 (fun v -> conf.invert
<- v);
4829 (fun () -> conf.maxhfit
)
4830 (fun v -> conf.maxhfit
<- v);
4831 src#
bool "redirect stderr"
4832 (fun () -> conf.redirectstderr)
4833 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4835 (fun () -> conf.pax
!= None
)
4838 then conf.pax
<- Some
(ref (now (), 0, 0))
4839 else conf.pax
<- None
);
4840 src#
string "uri launcher"
4841 (fun () -> conf.urilauncher
)
4842 (fun v -> conf.urilauncher
<- v);
4843 src#
string "path launcher"
4844 (fun () -> conf.pathlauncher
)
4845 (fun v -> conf.pathlauncher
<- v);
4846 src#
string "tile size"
4847 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4850 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4851 conf.tilew
<- max
64 w;
4852 conf.tileh
<- max
64 h;
4855 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4858 src#
int "texture count"
4859 (fun () -> conf.texcount
)
4862 then conf.texcount
<- v
4863 else showtext '
!'
" Failed to set texture count please retry later"
4865 src#
int "slice height"
4866 (fun () -> conf.sliceheight
)
4868 conf.sliceheight
<- v;
4869 wcmd "sliceh %d" conf.sliceheight
;
4871 src#
int "anti-aliasing level"
4872 (fun () -> conf.aalevel
)
4874 conf.aalevel
<- bound v 0 8;
4875 state.anchor <- getanchor ();
4876 opendoc state.path
state.password
;
4878 src#
string "page scroll scaling factor"
4879 (fun () -> string_of_float
conf.pgscale)
4882 let s = float_of_string
v in
4885 state.text <- Printf.sprintf
4886 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4889 src#
int "ui font size"
4890 (fun () -> fstate.fontsize
)
4891 (fun v -> setfontsize (bound v 5 100));
4892 src#
int "hint font size"
4893 (fun () -> conf.hfsize
)
4894 (fun v -> conf.hfsize
<- bound v 5 100);
4895 colorp "background color"
4896 (fun () -> conf.bgcolor
)
4897 (fun v -> conf.bgcolor
<- v);
4898 src#
bool "crop hack"
4899 (fun () -> conf.crophack
)
4900 (fun v -> conf.crophack
<- v);
4901 src#
string "trim fuzz"
4902 (fun () -> irect_to_string conf.trimfuzz
)
4905 conf.trimfuzz
<- irect_of_string v;
4907 then settrim true conf.trimfuzz
;
4909 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4911 src#
string "throttle"
4913 match conf.maxwait
with
4914 | None
-> "show place holder if page is not ready"
4917 then "wait for page to fully render"
4919 "wait " ^ string_of_float
time
4920 ^
" seconds before showing placeholder"
4924 let f = float_of_string
v in
4926 then conf.maxwait
<- None
4927 else conf.maxwait
<- Some
f
4929 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4931 src#
string "ghyll scroll"
4933 match conf.ghyllscroll
with
4935 | Some nab
-> ghyllscroll_to_string nab
4938 try conf.ghyllscroll
<- ghyllscroll_of_string v
4940 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4942 src#
string "selection command"
4943 (fun () -> conf.selcmd
)
4944 (fun v -> conf.selcmd
<- v);
4945 src#
string "synctex command"
4946 (fun () -> conf.stcmd
)
4947 (fun v -> conf.stcmd
<- v);
4948 src#
string "pax command"
4949 (fun () -> conf.paxcmd
)
4950 (fun v -> conf.paxcmd
<- v);
4951 src#colorspace
"color space"
4952 (fun () -> CSTE.to_string conf.colorspace
)
4954 conf.colorspace
<- CSTE.of_int v;
4958 src#paxmark
"pax mark method"
4959 (fun () -> MTE.to_string conf.paxmark
)
4960 (fun v -> conf.paxmark
<- MTE.of_int v);
4964 (fun () -> conf.usepbo
)
4965 (fun v -> conf.usepbo
<- v);
4966 src#
bool "mouse wheel scrolls pages"
4967 (fun () -> conf.wheelbypage
)
4968 (fun v -> conf.wheelbypage
<- v);
4969 src#
bool "open remote links in a new instance"
4970 (fun () -> conf.riani
)
4971 (fun v -> conf.riani
<- v);
4975 src#caption
"Document" 0;
4976 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4977 src#caption2
"Pages"
4978 (fun () -> string_of_int
state.pagecount
) 1;
4979 src#caption2
"Dimensions"
4980 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4984 src#caption
"Trimmed margins" 0;
4985 src#caption2
"Dimensions"
4986 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4990 src#caption
"OpenGL" 0;
4991 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4992 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4995 src#caption
"Location" 0;
4996 if nonemptystr
state.origin
4997 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4998 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
5000 src#reset prevmode prevuioh
;
5004 let prevmode = state.mode
5005 and prevuioh
= state.uioh in
5006 fillsrc prevmode prevuioh
;
5007 let source = (src :> lvsource
) in
5008 let modehash = findkeyhash conf "info" in
5009 state.uioh <- coe (object (self)
5010 inherit listview ~
source ~trusted
:true ~
modehash as super
5011 val mutable m_prevmemused
= 0
5012 method infochanged
= function
5014 if m_prevmemused
!= state.memused
5016 m_prevmemused
<- state.memused
;
5017 G.postRedisplay "memusedchanged";
5019 | Pdim
-> G.postRedisplay "pdimchanged"
5020 | Docinfo
-> fillsrc prevmode prevuioh
5022 method key key mask
=
5023 if not
(Wsi.withctrl mask
)
5026 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5027 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5028 | _ -> super#
key key mask
5029 else super#
key key mask
5031 G.postRedisplay "info";
5037 inherit lvsourcebase
5038 method getitemcount
= Array.length
state.help
5040 let s, l, _ = state.help
.(n) in
5043 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5047 m_qsearch
<- qsearch;
5048 match state.help
.(active) with
5049 | _, _, Action
f -> Some
(f uioh)
5059 method hasaction
n =
5060 match state.help
.(n) with
5061 | _, _, Action
_ -> true
5068 let modehash = findkeyhash conf "help" in
5069 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5070 G.postRedisplay "help";
5075 let re = Str.regexp
"[\r\n]" in
5077 inherit lvsourcebase
5078 val mutable m_items
= [||]
5080 method getitemcount
= 1 + Array.length m_items
5085 else m_items
.(n-1), 0
5087 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5092 then Buffer.clear
state.errmsgs
;
5093 m_qsearch
<- qsearch;
5100 method hasaction
n =
5104 state.newerrmsgs
<- false;
5105 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5106 m_items
<- Array.of_list
l
5114 let source = (msgsource :> lvsource
) in
5115 let modehash = findkeyhash conf "listview" in
5116 state.uioh <- coe (object
5117 inherit listview ~
source ~trusted
:false ~
modehash as super
5120 then msgsource#reset
;
5123 G.postRedisplay "msgs";
5126 let quickbookmark ?title
() =
5127 match state.layout with
5133 let sec = Unix.gettimeofday
() in
5134 let tm = Unix.localtime
sec in
5135 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5139 (tm.Unix.tm_year
+ 1900)
5142 | Some
title -> title
5144 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5147 let setautoscrollspeed step goingdown
=
5148 let incr = max
1 ((abs step
) / 2) in
5149 let incr = if goingdown
then incr else -incr in
5150 let astep = step
+ incr in
5151 state.autoscroll
<- Some
astep;
5154 let gotounder under =
5155 let getpath filename
=
5157 if nonemptystr filename
5159 if Filename.is_relative filename
5161 let dir = Filename.dirname
state.path in
5163 if Filename.is_implicit
dir
5164 then Filename.concat
(Sys.getcwd
()) dir
5167 Filename.concat
dir filename
5171 if Sys.file_exists
path
5176 | Ulinkgoto
(pageno, top) ->
5180 gotopage1 pageno top;
5186 | Uremote
(filename
, pageno) ->
5187 let path = getpath filename
in
5192 let command = !selfexec ^
" " ^
path in
5193 try popen command []
5196 "failed to execute `%s': %s\n" command (exntos exn
);
5199 let anchor = getanchor () in
5200 let ranchor = state.path, state.password
, anchor, state.origin
in
5202 state.anchor <- (pageno, 0.0, 0.0);
5203 state.ranchors
<- ranchor :: state.ranchors
;
5206 else showtext '
!'
("Could not find " ^ filename
)
5208 | Uremotedest
(filename
, destname
) ->
5209 let path = getpath filename
in
5214 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
5215 try popen command []
5218 "failed to execute `%s': %s\n" command (exntos exn
);
5221 let anchor = getanchor () in
5222 let ranchor = state.path, state.password
, anchor, state.origin
in
5224 state.nameddest
<- destname
;
5225 state.ranchors
<- ranchor :: state.ranchors
;
5228 else showtext '
!'
("Could not find " ^ filename
)
5230 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5234 match conf.columns
with
5236 | _ -> state.x != 0 || conf.zoom > 1.0
5239 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5241 let existsinrow pageno (columns
, coverA
, coverB
) p =
5242 let last = ((pageno - coverA
) mod columns
) + columns
in
5243 let rec any = function
5246 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5250 then (if l.pageno = last then false else any rest
)
5258 match state.layout with
5260 let pageno = page_of_y state.y in
5261 gotoghyll (getpagey (pageno+1))
5263 match conf.columns
with
5265 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5267 let y = clamp (pgscale state.winh
) in
5270 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5271 gotoghyll (getpagey pageno)
5272 | Cmulti
((c, _, _) as cl, _) ->
5273 if conf.presentation
5274 && (existsinrow l.pageno cl
5275 (fun l -> l.pageh
> l.pagey + l.pagevh))
5277 let y = clamp (pgscale state.winh
) in
5280 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5281 gotoghyll (getpagey pageno)
5283 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5285 let pagey, pageh
= getpageyh l.pageno in
5286 let pagey = pagey + pageh
* l.pagecol
in
5287 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5288 gotoghyll (pagey + pageh
+ ips)
5292 match state.layout with
5294 let pageno = page_of_y state.y in
5295 gotoghyll (getpagey (pageno-1))
5297 match conf.columns
with
5299 if conf.presentation
&& l.pagey != 0
5301 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5303 let pageno = max
0 (l.pageno-1) in
5304 gotoghyll (getpagey pageno)
5305 | Cmulti
((c, _, coverB
) as cl, _) ->
5306 if conf.presentation
&&
5307 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5309 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5312 if l.pageno = state.pagecount
- coverB
5316 let pageno = max
0 (l.pageno-decr) in
5317 gotoghyll (getpagey pageno)
5325 let pageno = max
0 (l.pageno-1) in
5326 let pagey, pageh
= getpageyh pageno in
5329 let pagey, pageh
= getpageyh l.pageno in
5330 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5335 let viewkeyboard key mask
=
5337 let mode = state.mode in
5338 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5341 G.postRedisplay "view:enttext"
5343 let ctrl = Wsi.withctrl mask
in
5345 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5351 | 0xff63 -> (* insert *)
5352 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5354 state.mode <- LinkNav
(Ltgendir
0);
5357 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5359 | 0xff1b | 113 -> (* escape / q *)
5360 begin match state.mstate
with
5362 state.mstate
<- Mnone
;
5363 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5364 G.postRedisplay "kill zoom rect";
5366 begin match state.mode with
5369 G.postRedisplay "esc leave linknav"
5371 match state.ranchors
with
5373 | (path, password
, anchor, origin
) :: rest
->
5374 state.ranchors
<- rest
;
5375 state.anchor <- anchor;
5376 state.origin
<- origin
;
5377 state.nameddest
<- "";
5378 opendoc path password
5382 | 0xff08 -> (* backspace *)
5383 gotoghyll (getnav ~
-1)
5391 G.postRedisplay "dehighlight";
5393 | 47 | 63 -> (* / ? *)
5394 let ondone isforw
s =
5395 cbput state.hists
.pat
s;
5396 state.searchpattern
<- s;
5399 let s = String.create
1 in
5400 s.[0] <- Char.chr
key;
5401 enttext (s, "", Some
(onhist state.hists
.pat
),
5402 textentry, ondone (key = 47), true)
5404 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5405 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5406 setzoom (conf.zoom +. incr)
5408 | 43 | 0xffab -> (* + *)
5411 try int_of_string
s with exc
->
5412 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5418 state.text <- "page bias is now " ^ string_of_int
n;
5421 enttext ("page bias: ", "", None
, intentry, ondone, true)
5423 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5424 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5425 setzoom (max
0.01 (conf.zoom -. decr))
5427 | 45 | 0xffad -> (* - *)
5428 let ondone msg
= state.text <- msg
in
5430 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5431 optentry state.mode, ondone, true
5434 | 48 when ctrl -> (* ctrl-0 *)
5442 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5444 match conf.columns
with
5445 | Csingle
_ | Cmulti
_ -> 1
5446 | Csplit
(n, _) -> n
5448 let h = state.winh
-
5449 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5451 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5452 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5455 | 51 when ctrl -> (* ctrl-3 *)
5457 match conf.fitmodel
with
5458 | FitWidth
-> FitProportional
5459 | FitProportional
-> FitPage
5460 | FitPage
-> FitWidth
5462 state.text <- "fit model: " ^
FMTE.to_string fm;
5463 reqlayout conf.angle
fm
5465 | 0xffc6 -> (* f9 *)
5468 | 57 when ctrl -> (* ctrl-9 *)
5471 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5472 when not
ctrl -> (* 0..9 *)
5475 try int_of_string
s with exc
->
5476 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5482 cbput state.hists
.pag
(string_of_int
n);
5483 gotopage1 (n + conf.pagebias
- 1) 0;
5486 let pageentry text key =
5487 match Char.unsafe_chr
key with
5488 | '
g'
-> TEdone
text
5489 | _ -> intentry text key
5491 let text = "x" in text.[0] <- Char.chr
key;
5492 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5495 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5496 reshape state.winw
state.winh
;
5499 state.bzoom
<- not
state.bzoom
;
5501 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5504 conf.hlinks
<- not
conf.hlinks
;
5505 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5506 G.postRedisplay "toggle highlightlinks";
5509 state.glinks
<- true;
5510 let mode = state.mode in
5511 state.mode <- Textentry
(
5512 (":", "", None
, linknentry, linkndone gotounder, false),
5514 state.glinks
<- false;
5518 G.postRedisplay "view:linkent(F)"
5521 state.glinks
<- true;
5522 let mode = state.mode in
5523 state.mode <- Textentry
(
5525 ":", "", None
, linknentry, linkndone (fun under ->
5526 selstring (undertext under);
5530 state.glinks
<- false;
5534 G.postRedisplay "view:linkent"
5537 begin match state.autoscroll
with
5539 conf.autoscrollstep
<- step
;
5540 state.autoscroll
<- None
5542 if conf.autoscrollstep
= 0
5543 then state.autoscroll
<- Some
1
5544 else state.autoscroll
<- Some
conf.autoscrollstep
5547 | 112 when ctrl -> (* ctrl-p *)
5551 setpresentationmode (not
conf.presentation
);
5552 showtext ' '
("presentation mode " ^
5553 if conf.presentation
then "on" else "off");
5556 if List.mem
Wsi.Fullscreen
state.winstate
5557 then Wsi.reshape conf.cwinw
conf.cwinh
5558 else Wsi.fullscreen
()
5560 | 112 | 78 -> (* p|N *)
5561 search state.searchpattern
false
5563 | 110 | 0xffc0 -> (* n|F3 *)
5564 search state.searchpattern
true
5567 begin match state.layout with
5570 gotoghyll (getpagey l.pageno)
5576 | 0xff9f | 0xffff -> (* delete *)
5580 showtext ' '
(describe_location ());
5583 begin match state.layout with
5586 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5591 enterbookmarkmode ()
5593 | 104 | 0xffbe -> (* h|F1 *)
5599 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5604 match state.layout with
5608 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5611 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5615 showtext ' '
"Quick bookmark added";
5618 begin match state.layout with
5620 let rect = getpdimrect
l.pagedimno
in
5624 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5625 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5627 (truncate
(rect.(1) -. rect.(0)),
5628 truncate
(rect.(3) -. rect.(0)))
5630 let w = truncate
((float w)*.conf.zoom)
5631 and h = truncate
((float h)*.conf.zoom) in
5634 state.anchor <- getanchor ();
5635 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5637 G.postRedisplay "z";
5642 | 120 -> state.roam
() (* x *)
5643 | 60 | 62 -> (* < > *)
5644 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5646 | 91 | 93 -> (* [ ] *)
5648 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5650 G.postRedisplay "brightness";
5652 | 99 when state.mode = View
-> (* [alt-]c *)
5657 let m = (wadjsb state.winw
- state.w) / 2 in
5659 gotoy_and_clear_text state.y
5663 match state.prevcolumns
with
5664 | None
-> (1, 0, 0), 1.0
5665 | Some
(columns
, z
) ->
5668 | Csplit
(c, _) -> -c, 0, 0
5669 | Cmulti
((c, a, b), _) -> c, a, b
5670 | Csingle
_ -> 1, 0, 0
5674 setcolumns View
c a b;
5677 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5678 -> (* ctrl-shift- (kp) [up|down] *)
5679 let zoom, x = state.prevzoom
in
5683 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5684 begin match state.autoscroll
with
5686 begin match state.mode with
5687 | Birdseye beye
-> upbirdseye 1 beye
5690 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5692 if not
(Wsi.withshift mask
) && conf.presentation
5694 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5698 setautoscrollspeed n false
5701 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5702 begin match state.autoscroll
with
5704 begin match state.mode with
5705 | Birdseye beye
-> downbirdseye 1 beye
5708 then gotoy_and_clear_text (clamp (state.winh
/2))
5710 if not
(Wsi.withshift mask
) && conf.presentation
5712 else gotoy_and_clear_text (clamp conf.scrollstep
)
5716 setautoscrollspeed n true
5719 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5720 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5726 else conf.hscrollstep
5728 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5729 state.x <- panbound (state.x + dx);
5730 gotoy_and_clear_text state.y
5733 G.postRedisplay "left/right"
5736 | 0xff55 | 0xff9a -> (* (kp) prior *)
5740 match state.layout with
5742 | l :: _ -> state.y - l.pagey
5744 clamp (pgscale (-state.winh
))
5748 | 0xff56 | 0xff9b -> (* (kp) next *)
5752 match List.rev
state.layout with
5754 | l :: _ -> getpagey l.pageno
5756 clamp (pgscale state.winh
)
5760 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5762 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5763 gotoghyll (clamp state.maxy)
5766 when Wsi.withalt mask
-> (* alt-(kp) right *)
5767 gotoghyll (getnav 1)
5769 when Wsi.withalt mask
-> (* alt-(kp) left *)
5770 gotoghyll (getnav ~
-1)
5775 | 118 when conf.debug
-> (* v *)
5778 match getopaque l.pageno with
5781 let x0, y0, x1, y1 = pagebbox opaque
in
5782 let a,b = float x0, float y0 in
5783 let c,d = float x1, float y0 in
5784 let e,f = float x1, float y1 in
5785 let h,j
= float x0, float y1 in
5786 let rect = (a,b,c,d,e,f,h,j
) in
5788 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5790 G.postRedisplay "v";
5793 vlog "huh? %s" (Wsi.keyname
key)
5796 let linknavkeyboard key mask
linknav =
5797 let getpage pageno =
5798 let rec loop = function
5800 | l :: _ when l.pageno = pageno -> Some
l
5801 | _ :: rest
-> loop rest
5802 in loop state.layout
5804 let doexact (pageno, n) =
5805 match getopaque pageno, getpage pageno with
5806 | Some opaque
, Some
l ->
5807 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5809 let under = getlink opaque
n in
5810 G.postRedisplay "link gotounder";
5816 | 0xff50 -> (* home *)
5817 Some
(findlink opaque LDfirst
), -1
5819 | 0xff57 -> (* end *)
5820 Some
(findlink opaque LDlast
), 1
5822 | 0xff51 -> (* left *)
5823 Some
(findlink opaque
(LDleft
n)), -1
5825 | 0xff53 -> (* right *)
5826 Some
(findlink opaque
(LDright
n)), 1
5828 | 0xff52 -> (* up *)
5829 Some
(findlink opaque
(LDup
n)), -1
5831 | 0xff54 -> (* down *)
5832 Some
(findlink opaque
(LDdown
n)), 1
5837 begin match findpwl
l.pageno dir with
5841 state.mode <- LinkNav
(Ltgendir
dir);
5842 let y, h = getpageyh pageno in
5845 then y + h - state.winh
5850 begin match getopaque pageno, getpage pageno with
5851 | Some opaque
, Some
_ ->
5853 let ld = if dir > 0 then LDfirst
else LDlast
in
5856 begin match link with
5858 showlinktype (getlink opaque
m);
5859 state.mode <- LinkNav
(Ltexact
(pageno, m));
5860 G.postRedisplay "linknav jpage";
5867 begin match opt with
5868 | Some Lnotfound
-> pwl l dir;
5869 | Some
(Lfound
m) ->
5873 let _, y0, _, y1 = getlinkrect opaque
m in
5875 then gotopage1 l.pageno y0
5877 let d = fstate.fontsize
+ 1 in
5878 if y1 - l.pagey > l.pagevh - d
5879 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5880 else G.postRedisplay "linknav";
5882 showlinktype (getlink opaque
m);
5883 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5886 | None
-> viewkeyboard key mask
5888 | _ -> viewkeyboard key mask
5893 G.postRedisplay "leave linknav"
5897 | Ltgendir
_ -> viewkeyboard key mask
5898 | Ltexact exact
-> doexact exact
5901 let keyboard key mask
=
5902 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5903 then wcmd "interrupt"
5904 else state.uioh <- state.uioh#
key key mask
5907 let birdseyekeyboard key mask
5908 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5910 match conf.columns
with
5912 | Cmulti
((c, _, _), _) -> c
5913 | Csplit
_ -> failwith
"bird's eye split mode"
5915 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5917 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5918 let y, h = getpageyh pageno in
5919 let top = (state.winh
- h) / 2 in
5920 gotoy (max
0 (y - top))
5921 | 0xff0d (* enter *)
5922 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5923 | 0xff1b -> leavebirdseye beye
true (* escape *)
5924 | 0xff52 -> upbirdseye incr beye
(* up *)
5925 | 0xff54 -> downbirdseye incr beye
(* down *)
5926 | 0xff51 -> upbirdseye 1 beye
(* left *)
5927 | 0xff53 -> downbirdseye 1 beye
(* right *)
5929 | 0xff55 -> (* prior *)
5930 begin match state.layout with
5934 state.mode <- Birdseye
(
5935 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5937 gotopage1 l.pageno 0;
5940 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5942 | [] -> gotoy (clamp (-state.winh
))
5944 state.mode <- Birdseye
(
5945 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5947 gotopage1 l.pageno 0
5950 | [] -> gotoy (clamp (-state.winh
))
5953 | 0xff56 -> (* next *)
5954 begin match List.rev
state.layout with
5956 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5957 begin match layout with
5959 let incr = l.pageh
- l.pagevh in
5964 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5966 G.postRedisplay "birdseye pagedown";
5968 else gotoy (clamp (incr + conf.interpagespace
*2));
5972 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5973 gotopage1 l.pageno 0;
5976 | [] -> gotoy (clamp state.winh
)
5979 | 0xff50 -> (* home *)
5980 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5983 | 0xff57 -> (* end *)
5984 let pageno = state.pagecount
- 1 in
5985 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5986 if not
(pagevisible state.layout pageno)
5989 match List.rev
state.pdims
with
5991 | (_, _, h, _) :: _ -> h
5993 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5994 else G.postRedisplay "birdseye end";
5995 | _ -> viewkeyboard key mask
6000 match state.mode with
6001 | Textentry
_ -> scalecolor 0.4
6003 | View
-> scalecolor 1.0
6004 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6005 if l.pageno = hooverpageno
6008 if l.pageno = pageno
6016 let postdrawpage l linkindexbase
=
6017 match getopaque l.pageno with
6019 if tileready l l.pagex
l.pagey
6021 let x = l.pagedispx - l.pagex
6022 and y = l.pagedispy - l.pagey in
6024 match conf.columns
with
6025 | Csingle
_ | Cmulti
_ ->
6026 (if conf.hlinks
then 1 else 0)
6028 && not
(isbirdseye state.mode) then 2 else 0)
6032 match state.mode with
6033 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6036 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6041 let scrollindicator () =
6042 let sbw, ph
, sh = state.uioh#
scrollph in
6043 let sbh, pw, sw = state.uioh#scrollpw
in
6045 GlDraw.color (0.64, 0.64, 0.64);
6047 (float (state.winw
- sbw)) 0.
6048 (float state.winw
) (float state.winh
)
6051 0. (float (state.winh
- sbh))
6052 (float (wadjsb state.winw
- 1)) (float state.winh
)
6054 GlDraw.color (0.0, 0.0, 0.0);
6057 (float (state.winw
- sbw)) ph
6058 (float state.winw
) (ph
+. sh)
6061 pw (float (state.winh
- sbh))
6062 (pw +. sw) (float state.winh
)
6067 match state.mstate
with
6068 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6071 | Msel
((x0, y0), (x1, y1)) ->
6072 let rec loop = function
6074 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6075 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6076 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6077 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6079 match getopaque l.pageno with
6081 let x0, y0 = pagetranslatepoint l x0 y0 in
6082 let x1, y1 = pagetranslatepoint l x1 y1 in
6083 seltext opaque
(x0, y0, x1, y1);
6091 let showrects = function [] -> () | rects
->
6093 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6094 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6096 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6098 if l.pageno = pageno
6100 let dx = float (l.pagedispx - l.pagex
) in
6101 let dy = float (l.pagedispy - l.pagey) in
6102 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6103 Raw.sets_float
state.vraw ~pos
:0
6108 GlArray.vertex `two
state.vraw
;
6109 GlArray.draw_arrays `triangle_strip
0 4;
6118 GlClear.color (scalecolor2 conf.bgcolor
);
6119 GlClear.clear
[`
color];
6120 List.iter
drawpage state.layout;
6122 match state.mode with
6123 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6124 begin match getopaque pageno with
6126 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6133 | None
-> state.rects
6138 let rec postloop linkindexbase
= function
6140 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6141 postloop linkindexbase rest
6145 postloop 0 state.layout;
6147 begin match state.mstate
with
6148 | Mzoomrect
((x0, y0), (x1, y1)) ->
6150 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6151 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6152 filledrect (float x0) (float y0) (float x1) (float y1);
6161 let zoomrect x y x1 y1 =
6164 and y0 = min
y y1 in
6165 gotoy (state.y + y0);
6166 state.anchor <- getanchor ();
6167 let zoom = (float state.w) /. float (x1 - x0) in
6169 match conf.fitmodel
, conf.columns
with
6170 | FitPage
, Csplit
_ ->
6171 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6174 let adjw = wadjsb state.winw
in
6176 then (adjw - state.w) / 2
6179 state.x <- (state.x + margin) - x0;
6181 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6182 state.mstate
<- Mnone
;
6186 let g opaque
l px py =
6187 match rectofblock opaque
px py with
6189 let x0 = a.(0) -. 20. in
6190 let x1 = a.(1) +. 20. in
6191 let y0 = a.(2) -. 20. in
6192 let zoom = (float state.w) /. (x1 -. x0) in
6193 let pagey = getpagey l.pageno in
6194 gotoy_and_clear_text (pagey + truncate
y0);
6195 state.anchor <- getanchor ();
6196 let margin = (state.w - l.pagew
)/2 in
6197 state.x <- -truncate
x0 - margin;
6202 match conf.columns
with
6204 showtext '
!'
"block zooming does not work properly in split columns mode"
6205 | _ -> onppundermouse g x y ()
6209 let winw = wadjsb state.winw - 1 in
6210 let s = float x /. float winw in
6211 let destx = truncate
(float (state.w + winw) *. s) in
6212 state.x <- winw - destx;
6213 gotoy_and_clear_text state.y;
6214 state.mstate
<- Mscrollx
;
6218 let s = float y /. float state.winh
in
6219 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6220 gotoy_and_clear_text desty;
6221 state.mstate
<- Mscrolly
;
6224 let viewmouse button down
x y mask
=
6226 | n when (n == 4 || n == 5) && not down
->
6227 if Wsi.withctrl mask
6229 match state.mstate
with
6230 | Mzoom
(oldn
, i
) ->
6238 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6240 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6242 let zoom = conf.zoom -. incr in
6244 state.mstate
<- Mzoom
(n, 0);
6246 state.mstate
<- Mzoom
(n, i
+1);
6248 else state.mstate
<- Mzoom
(n, 0)
6250 | _ -> state.mstate
<- Mzoom
(n, 0)
6253 match state.autoscroll
with
6254 | Some step
-> setautoscrollspeed step
(n=4)
6256 if conf.wheelbypage
|| conf.presentation
6265 then -conf.scrollstep
6266 else conf.scrollstep
6268 let incr = incr * 2 in
6269 let y = clamp incr in
6270 gotoy_and_clear_text y
6273 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6275 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6276 gotoy_and_clear_text state.y
6278 | 1 when Wsi.withshift mask
->
6279 state.mstate
<- Mnone
;
6282 match unproject x y with
6283 | Some
(pageno, ux
, uy
) ->
6284 let cmd = Printf.sprintf
6286 conf.stcmd
state.path pageno ux uy
6292 | 1 when Wsi.withctrl mask
->
6295 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6296 state.mstate
<- Mpan
(x, y)
6299 state.mstate
<- Mnone
6304 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6306 state.mstate
<- Mzoomrect
(p, p)
6309 match state.mstate
with
6310 | Mzoomrect
((x0, y0), _) ->
6311 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6312 then zoomrect x0 y0 x y
6314 state.mstate
<- Mnone
;
6315 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6316 G.postRedisplay "kill accidental zoom rect";
6319 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6320 state.mstate
<- Mnone
6323 | 1 when x > state.winw - vscrollw () ->
6326 let _, position, sh = state.uioh#
scrollph in
6327 if y > truncate
position && y < truncate
(position +. sh)
6328 then state.mstate
<- Mscrolly
6331 state.mstate
<- Mnone
6333 | 1 when y > state.winh
- hscrollh () ->
6336 let _, position, sw = state.uioh#scrollpw
in
6337 if x > truncate
position && x < truncate
(position +. sw)
6338 then state.mstate
<- Mscrollx
6341 state.mstate
<- Mnone
6343 | 1 when state.bzoom
-> if not down
then zoomblock x y
6346 let dest = if down
then getunder x y else Unone
in
6347 begin match dest with
6350 | Uremote
_ | Uremotedest
_
6351 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6354 | Unone
when down
->
6355 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6356 state.mstate
<- Mpan
(x, y);
6358 | Unone
| Utext
_ ->
6361 if conf.angle
mod 360 = 0
6363 state.mstate
<- Msel
((x, y), (x, y));
6364 G.postRedisplay "mouse select";
6368 match state.mstate
with
6371 | Mzoom
_ | Mscrollx
| Mscrolly
->
6372 state.mstate
<- Mnone
6374 | Mzoomrect
((x0, y0), _) ->
6378 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6379 state.mstate
<- Mnone
6381 | Msel
((x0, y0), (x1, y1)) ->
6382 let rec loop = function
6386 let a0 = l.pagedispy in
6387 let a1 = a0 + l.pagevh in
6388 let b0 = l.pagedispx in
6389 let b1 = b0 + l.pagevw in
6390 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6391 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6395 match getopaque l.pageno with
6398 match Ne.pipe () with
6402 "can not create sel pipe: %s"
6405 let doclose what fd
=
6406 Ne.clo fd
(fun msg
->
6407 dolog
"%s close failed: %s" what msg
)
6410 popen conf.selcmd
[r, 0; w, -1];
6411 copysel
w opaque
true;
6413 G.postRedisplay "copysel";
6415 dolog
"can not execute %S: %s"
6416 conf.selcmd
(exntos exn
);
6424 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6425 state.mstate
<- Mnone
;
6432 let birdseyemouse button down
x y mask
6433 (conf, leftx
, _, hooverpageno
, anchor) =
6436 let rec loop = function
6439 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6440 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6442 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6448 | _ -> viewmouse button down
x y mask
6454 method key key mask
=
6455 begin match state.mode with
6456 | Textentry
textentry -> textentrykeyboard key mask
textentry
6457 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6458 | View
-> viewkeyboard key mask
6459 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6463 method button button bstate
x y mask
=
6464 begin match state.mode with
6466 | View
-> viewmouse button bstate
x y mask
6467 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6473 begin match state.mode with
6475 | View
| Birdseye
_ | LinkNav
_ ->
6476 match state.mstate
with
6477 | Mzoom
_ | Mnone
-> ()
6482 state.mstate
<- Mpan
(x, y);
6484 then state.x <- panbound (state.x + dx);
6486 gotoy_and_clear_text y
6489 state.mstate
<- Msel
(a, (x, y));
6490 G.postRedisplay "motion select";
6493 let y = min
state.winh
(max
0 y) in
6497 let x = min
state.winw (max
0 x) in
6500 | Mzoomrect
(p0
, _) ->
6501 state.mstate
<- Mzoomrect
(p0
, (x, y));
6502 G.postRedisplay "motion zoomrect";
6506 method pmotion
x y =
6507 begin match state.mode with
6508 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6509 let rec loop = function
6511 if hooverpageno
!= -1
6513 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6514 G.postRedisplay "pmotion birdseye no hoover";
6517 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6518 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6520 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6521 G.postRedisplay "pmotion birdseye hoover";
6531 match state.mstate
with
6532 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6539 let past, _, _ = !r in
6541 let delta = now -. past in
6544 else r := (now, x, y)
6548 method infochanged
_ = ()
6551 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6554 then 0.0, float state.winh
6555 else scrollph state.y maxy
6560 let winw = wadjsb state.winw in
6561 let fwinw = float winw in
6563 let sw = fwinw /. float state.w in
6564 let sw = fwinw *. sw in
6565 max
sw (float conf.scrollh
)
6568 let maxx = state.w + winw in
6569 let x = winw - state.x in
6570 let percent = float x /. float maxx in
6571 (fwinw -. sw) *. percent
6573 hscrollh (), position, sw
6577 match state.mode with
6578 | LinkNav
_ -> "links"
6579 | Textentry
_ -> "textentry"
6580 | Birdseye
_ -> "birdseye"
6583 findkeyhash conf modename
6585 method eformsgs
= true
6592 let fontpath = ref "";;
6595 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6598 let l = String.length
s in
6599 let b = Buffer.create
l in
6605 try Sys.getenv
"HOME"
6608 ("Can not determine home directory location: " ^ exntos exn
);
6612 let modifier_of_string = function
6613 | "alt" -> Wsi.altmask
6614 | "shift" -> Wsi.shiftmask
6615 | "ctrl" | "control" -> Wsi.ctrlmask
6616 | "meta" -> Wsi.metamask
6621 let r = Str.regexp
"-" in
6623 let elems = Str.full_split
r s in
6626 let m1 = modifier_of_string s in
6628 then (Wsi.namekey
s, m)
6631 | Str.Delim
s when n land 1 = 0 -> g s
6633 | Str.Delim
_ -> (k
, m)
6635 let rec loop n k
m = function
6638 let k, m = f n k m x in
6644 let keys_of_string =
6645 let r = Str.regexp
"[ \t]" in
6647 let elems = Str.split
r s in
6648 List.map
key_of_string elems
6651 let copykeyhashes c =
6652 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6655 let config_of c attrs
=
6659 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6660 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6661 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6662 | "preload" -> { c with preload = bool_of_string
v }
6663 | "page-bias" -> { c with pagebias
= int_of_string
v }
6664 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6665 | "horizontal-scroll-step" ->
6666 { c with hscrollstep
= max
(int_of_string
v) 1 }
6667 | "auto-scroll-step" ->
6668 { c with autoscrollstep
= max
0 (int_of_string
v) }
6669 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6670 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6673 match String.lowercase
v with
6674 | "true" -> Some infinity
6676 | f -> Some
(float_of_string
f)
6678 { c with maxwait
= mw}
6679 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6680 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6681 | "vertical-margin" ->
6682 { c with interpagespace
= max
0 (int_of_string
v) }
6684 let zoom = float_of_string
v /. 100. in
6685 let zoom = max
zoom 0.0 in
6686 { c with zoom = zoom }
6687 | "presentation" -> { c with presentation
= bool_of_string
v }
6688 | "rotation-angle" -> { c with angle
= int_of_string
v }
6689 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6690 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6691 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6692 | "proportional-display" ->
6695 then FitProportional
6698 { c with fitmodel
= fm }
6699 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6700 | "pixmap-cache-size" ->
6701 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6702 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6703 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6704 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6705 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6706 | "background-color" -> { c with bgcolor
= color_of_string v }
6707 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6708 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6709 | "mupdf-store-size" ->
6710 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6711 | "checkers" -> { c with checkers
= bool_of_string
v }
6712 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6713 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6714 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6715 | "uri-launcher" -> { c with urilauncher
= unent v }
6716 | "path-launcher" -> { c with pathlauncher
= unent v }
6717 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6718 | "invert-colors" -> { c with invert
= bool_of_string
v }
6719 | "brightness" -> { c with colorscale
= float_of_string
v }
6720 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6721 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6723 let (n, _, _) as nab
= multicolumns_of_string v in
6725 then { c with columns
= Csplit
(-n, [||]) }
6726 else { c with columns
= Cmulti
(nab
, [||]) }
6727 | "birds-eye-columns" ->
6728 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6729 | "selection-command" -> { c with selcmd
= unent v }
6730 | "synctex-command" -> { c with stcmd
= unent v }
6731 | "pax-command" -> { c with paxcmd
= unent v }
6732 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6733 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6734 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6735 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6736 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6737 | "horizontal-scrollbar-visible" ->
6740 then c.scrollb
lor scrollbhv
6741 else c.scrollb
land (lnot
scrollbhv)
6743 { c with scrollb
= b }
6744 | "vertical-scrollbar-visible" ->
6747 then c.scrollb
lor scrollbvv
6748 else c.scrollb
land (lnot
scrollbvv)
6750 { c with scrollb
= b }
6751 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6755 then Some
(ref (0.0, 0, 0))
6757 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6760 prerr_endline
("Error processing attribute (`" ^
6761 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6764 let rec fold c = function
6767 let c = apply c k v in
6770 fold { c with keyhashes
= copykeyhashes c } attrs
;
6773 let fromstring f pos
n v d =
6776 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6777 n v pos
(exntos exn
)
6782 let bookmark_of attrs
=
6783 let rec fold title page
rely visy
= function
6784 | ("title", v) :: rest
-> fold v page
rely visy rest
6785 | ("page", v) :: rest
-> fold title v rely visy rest
6786 | ("rely", v) :: rest
-> fold title page
v visy rest
6787 | ("visy", v) :: rest
-> fold title page
rely v rest
6788 | _ :: rest
-> fold title page
rely visy rest
6789 | [] -> title, page
, rely, visy
6791 fold "invalid" "0" "0" "0" attrs
6795 let rec fold path page
rely pan visy
= function
6796 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6797 | ("page", v) :: rest
-> fold path v rely pan visy rest
6798 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6799 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6800 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6801 | _ :: rest
-> fold path page
rely pan visy rest
6802 | [] -> path, page
, rely, pan
, visy
6804 fold "" "0" "0" "0" "0" attrs
6808 let rec fold rs ls
= function
6809 | ("out", v) :: rest
-> fold v ls rest
6810 | ("in", v) :: rest
-> fold rs
v rest
6811 | _ :: rest
-> fold ls rs rest
6817 let setconf dst
src =
6818 dst
.scrollbw
<- src.scrollbw
;
6819 dst
.scrollh
<- src.scrollh
;
6820 dst
.icase
<- src.icase
;
6821 dst
.preload <- src.preload;
6822 dst
.pagebias
<- src.pagebias
;
6823 dst
.verbose
<- src.verbose
;
6824 dst
.scrollstep
<- src.scrollstep
;
6825 dst
.maxhfit
<- src.maxhfit
;
6826 dst
.crophack
<- src.crophack
;
6827 dst
.autoscrollstep
<- src.autoscrollstep
;
6828 dst
.maxwait
<- src.maxwait
;
6829 dst
.hlinks
<- src.hlinks
;
6830 dst
.underinfo
<- src.underinfo
;
6831 dst
.interpagespace
<- src.interpagespace
;
6832 dst
.zoom <- src.zoom;
6833 dst
.presentation
<- src.presentation
;
6834 dst
.angle
<- src.angle
;
6835 dst
.cwinw
<- src.cwinw
;
6836 dst
.cwinh
<- src.cwinh
;
6837 dst
.savebmarks
<- src.savebmarks
;
6838 dst
.memlimit
<- src.memlimit
;
6839 dst
.fitmodel
<- src.fitmodel
;
6840 dst
.texcount
<- src.texcount
;
6841 dst
.sliceheight
<- src.sliceheight
;
6842 dst
.thumbw
<- src.thumbw
;
6843 dst
.jumpback
<- src.jumpback
;
6844 dst
.bgcolor
<- src.bgcolor
;
6845 dst
.tilew
<- src.tilew
;
6846 dst
.tileh
<- src.tileh
;
6847 dst
.mustoresize
<- src.mustoresize
;
6848 dst
.checkers
<- src.checkers
;
6849 dst
.aalevel
<- src.aalevel
;
6850 dst
.trimmargins
<- src.trimmargins
;
6851 dst
.trimfuzz
<- src.trimfuzz
;
6852 dst
.urilauncher
<- src.urilauncher
;
6853 dst
.colorspace
<- src.colorspace
;
6854 dst
.invert
<- src.invert
;
6855 dst
.colorscale
<- src.colorscale
;
6856 dst
.redirectstderr <- src.redirectstderr;
6857 dst
.ghyllscroll
<- src.ghyllscroll
;
6858 dst
.columns
<- src.columns
;
6859 dst
.beyecolumns
<- src.beyecolumns
;
6860 dst
.selcmd
<- src.selcmd
;
6861 dst
.updatecurs
<- src.updatecurs
;
6862 dst
.pathlauncher
<- src.pathlauncher
;
6863 dst
.keyhashes
<- copykeyhashes src;
6864 dst
.hfsize
<- src.hfsize
;
6865 dst
.hscrollstep
<- src.hscrollstep
;
6866 dst
.pgscale <- src.pgscale;
6867 dst
.usepbo
<- src.usepbo
;
6868 dst
.wheelbypage
<- src.wheelbypage
;
6869 dst
.stcmd
<- src.stcmd
;
6870 dst
.paxcmd
<- src.paxcmd
;
6871 dst
.scrollb
<- src.scrollb
;
6872 dst
.riani
<- src.riani
;
6873 dst
.paxmark
<- src.paxmark
;
6877 else Some
((ref (0.0, 0, 0)));
6881 let h = Hashtbl.create
10 in
6882 let dc = { defconf with angle
= defconf.angle
} in
6883 let rec toplevel v t spos
_ =
6885 | Vdata
| Vcdata
| Vend
-> v
6886 | Vopen
("llppconfig", _, closed
) ->
6889 else { v with f = llppconfig
}
6891 error
"unexpected subelement at top level" s spos
6892 | Vclose
_ -> error
"unexpected close at top level" s spos
6894 and llppconfig
v t spos
_ =
6896 | Vdata
| Vcdata
-> v
6897 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6898 | Vopen
("defaults", attrs
, closed
) ->
6899 let c = config_of dc attrs
in
6903 else { v with f = defaults
}
6905 | Vopen
("ui-font", attrs
, closed
) ->
6906 let rec getsize size
= function
6908 | ("size", v) :: rest
->
6910 fromstring int_of_string spos
"size" v fstate.fontsize
in
6912 | l -> getsize size l
6914 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6917 else { v with f = uifont
(Buffer.create
10) }
6919 | Vopen
("doc", attrs
, closed
) ->
6920 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6921 let path = unent pathent
6922 and pageno = fromstring int_of_string spos
"page" spage
0
6923 and rely = fromstring float_of_string spos
"rely" srely
0.0
6924 and pan
= fromstring int_of_string spos
"pan" span
0
6925 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6926 let c = config_of dc attrs
in
6927 let anchor = (pageno, rely, visy
) in
6929 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6930 else { v with f = doc
path pan
anchor c [] }
6933 error
"unexpected subelement in llppconfig" s spos
6935 | Vclose
"llppconfig" -> { v with f = toplevel }
6936 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6938 and defaults
v t spos
_ =
6940 | Vdata
| Vcdata
-> v
6941 | Vend
-> error
"unexpected end of input in defaults" s spos
6942 | Vopen
("keymap", attrs
, closed
) ->
6944 try List.assoc
"mode" attrs
6945 with Not_found
-> "global" in
6950 let h = findkeyhash dc modename in
6951 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6954 { v with f = pkeymap
ret KeyMap.empty }
6956 | Vopen
(_, _, _) ->
6957 error
"unexpected subelement in defaults" s spos
6959 | Vclose
"defaults" ->
6960 { v with f = llppconfig
}
6962 | Vclose
_ -> error
"unexpected close in defaults" s spos
6964 and uifont
b v t spos
epos =
6967 Buffer.add_substring
b s spos
(epos - spos
);
6969 | Vopen
(_, _, _) ->
6970 error
"unexpected subelement in ui-font" s spos
6971 | Vclose
"ui-font" ->
6972 if emptystr
!fontpath
6973 then fontpath := Buffer.contents
b;
6974 { v with f = llppconfig
}
6975 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6976 | Vend
-> error
"unexpected end of input in ui-font" s spos
6978 and doc
path pan
anchor c bookmarks
v t spos
_ =
6980 | Vdata
| Vcdata
-> v
6981 | Vend
-> error
"unexpected end of input in doc" s spos
6982 | Vopen
("bookmarks", _, closed
) ->
6985 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6987 | Vopen
("keymap", attrs
, closed
) ->
6989 try List.assoc
"mode" attrs
6990 with Not_found
-> "global"
6996 let h = findkeyhash c modename in
6997 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6998 doc
path pan
anchor c bookmarks
7000 { v with f = pkeymap
ret KeyMap.empty }
7002 | Vopen
(_, _, _) ->
7003 error
"unexpected subelement in doc" s spos
7006 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7007 { v with f = llppconfig
}
7009 | Vclose
_ -> error
"unexpected close in doc" s spos
7011 and pkeymap
ret keymap
v t spos
_ =
7013 | Vdata
| Vcdata
-> v
7014 | Vend
-> error
"unexpected end of input in keymap" s spos
7015 | Vopen
("map", attrs
, closed
) ->
7016 let r, l = map_of attrs
in
7017 let kss = fromstring keys_of_string spos
"in" r [] in
7018 let lss = fromstring keys_of_string spos
"out" l [] in
7022 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7023 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7026 then { v with f = pkeymap
ret keymap }
7029 { v with f = skip
"map" f }
7032 error
"unexpected subelement in keymap" s spos
7034 | Vclose
"keymap" ->
7035 { v with f = ret keymap }
7037 | Vclose
_ -> error
"unexpected close in keymap" s spos
7039 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7041 | Vdata
| Vcdata
-> v
7042 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7043 | Vopen
("item", attrs
, closed
) ->
7044 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7045 let page = fromstring int_of_string spos
"page" spage
0
7046 and rely = fromstring float_of_string spos
"rely" srely
0.0
7047 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7049 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
7052 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7055 { v with f = skip
"item" f }
7058 error
"unexpected subelement in bookmarks" s spos
7060 | Vclose
"bookmarks" ->
7061 { v with f = doc
path pan
anchor c bookmarks }
7063 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7065 and skip tag
f v t spos
_ =
7067 | Vdata
| Vcdata
-> v
7069 error
("unexpected end of input in skipped " ^ tag
) s spos
7070 | Vopen
(tag'
, _, closed
) ->
7074 let f'
() = { v with f = skip tag
f } in
7075 { v with f = skip tag'
f'
}
7079 else error
("unexpected close in skipped " ^ tag
) s spos
7082 parse
{ f = toplevel; accu = () } s;
7088 let len = in_channel_length ic
in
7089 let s = String.create
len in
7090 really_input ic
s 0 len;
7093 | Parse_error
(msg
, s, pos
) ->
7094 let subs = subs s pos
in
7095 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7098 failwith
("config load error: " ^ exntos exn
)
7104 let dir = Filename.concat
home ".config" in
7105 if Sys.is_directory
dir then dir else home
7108 Filename.concat
dir "llpp.conf"
7111 let confpath = ref defconfpath;;
7114 if Sys.file_exists
!confpath
7117 (try Some
(open_in_bin
!confpath)
7120 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7131 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7140 f (Hashtbl.create
0, defconf)
7145 let pc, pb
, px, pa
=
7148 if emptystr
state.origin
7152 Hashtbl.find h (Filename.basename
key)
7153 with Not_found
-> dc, [], 0, emptyanchor
7157 state.bookmarks <- pb
;
7160 then state.anchor <- pa
;
7161 cbput state.hists
.nav pa
;
7167 let add_attrs bb always
dc c =
7170 then Printf.bprintf bb
"\n %s='%b'" s a
7173 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7176 then Printf.bprintf bb
"\n %s='%d'" s a
7179 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7182 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7185 then Printf.bprintf bb
"\n %s='%f'" s a
7189 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7193 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7197 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7201 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7206 | Some
(_N
, _A
, _B
) ->
7207 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7212 Printf.bprintf bb
"\n %s='none'" s
7222 else string_of_float
f
7224 Printf.bprintf bb
"\n %s='%s'" s v
7229 | Cmulti
((n, a, b), _) when n > 1 ->
7230 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7231 | Csplit
(n, _) when n > 1 ->
7232 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7238 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7243 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7247 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7251 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7253 oi
"width" c.cwinw
dc.cwinw
;
7254 oi
"height" c.cwinh
dc.cwinh
;
7255 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7256 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7257 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7258 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7259 ob "case-insensitive-search" c.icase
dc.icase
;
7260 ob "preload" c.preload dc.preload;
7261 oi
"page-bias" c.pagebias
dc.pagebias
;
7262 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7263 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7264 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7265 ob "crop-hack" c.crophack
dc.crophack
;
7266 oW
"throttle" c.maxwait
dc.maxwait
;
7267 ob "highlight-links" c.hlinks
dc.hlinks
;
7268 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7269 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7270 oz
"zoom" c.zoom dc.zoom;
7271 ob "presentation" c.presentation
dc.presentation
;
7272 oi
"rotation-angle" c.angle
dc.angle
;
7273 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7274 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7275 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7276 oi
"tex-count" c.texcount
dc.texcount
;
7277 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7278 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7279 ob "persistent-location" c.jumpback
dc.jumpback
;
7280 oc
"background-color" c.bgcolor
dc.bgcolor
;
7281 oi
"tile-width" c.tilew
dc.tilew
;
7282 oi
"tile-height" c.tileh
dc.tileh
;
7283 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7284 ob "checkers" c.checkers
dc.checkers
;
7285 oi
"aalevel" c.aalevel
dc.aalevel
;
7286 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7287 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7288 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7289 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7290 oC
"color-space" c.colorspace
dc.colorspace
;
7291 ob "invert-colors" c.invert
dc.invert
;
7292 oF
"brightness" c.colorscale
dc.colorscale
;
7293 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7294 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7295 oco
"columns" c.columns
dc.columns
;
7296 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7297 os
"selection-command" c.selcmd
dc.selcmd
;
7298 os
"synctex-command" c.stcmd
dc.stcmd
;
7299 os
"pax-command" c.paxcmd
dc.paxcmd
;
7300 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7301 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7302 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7303 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7304 ob "use-pbo" c.usepbo
dc.usepbo
;
7305 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7306 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7307 op
"point-and-x" c.pax
dc.pax
;
7308 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7311 let keymapsbuf always
dc c =
7312 let bb = Buffer.create
16 in
7313 let rec loop = function
7315 | (modename, h) :: rest
->
7316 let dh = findkeyhash dc modename in
7317 if always
|| h <> dh
7319 if Hashtbl.length
h > 0
7321 if Buffer.length
bb > 0
7322 then Buffer.add_char
bb '
\n'
;
7323 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7324 Hashtbl.iter
(fun i
o ->
7325 let isdifferent = always
||
7327 let dO = Hashtbl.find dh i
in
7329 with Not_found
-> true
7334 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7335 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7336 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7337 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7338 Buffer.add_string
bb (Wsi.keyname
k);
7341 let rec loop = function
7343 | km
:: [] -> addkm km
7344 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7348 Buffer.add_string
bb "<map in='";
7352 Buffer.add_string
bb "' out='";
7354 Buffer.add_string
bb "'/>\n"
7357 Buffer.add_string
bb "' out='";
7359 Buffer.add_string
bb "'/>\n"
7361 | KMmulti
(ins, kms
) ->
7362 Buffer.add_char
bb ' '
;
7364 Buffer.add_string
bb "' out='";
7366 Buffer.add_string
bb "'/>\n"
7368 Buffer.add_string
bb "</keymap>";
7378 let uifontsize = fstate.fontsize
in
7379 let bb = Buffer.create
32768 in
7380 let relx = float state.x /. float state.winw in
7382 let cx w = truncate
(relx *. float w) in
7384 (fun (w, h, x) ws
->
7386 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7387 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7388 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7390 (state.winw, state.winh
, state.x) state.winstate
7395 let dc = if conf.bedefault
then conf else dc in
7396 Buffer.add_string
bb "<llppconfig>\n";
7398 if nonemptystr
!fontpath
7400 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7406 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7409 Buffer.add_string
bb "<defaults";
7410 add_attrs bb true dc dc;
7411 let kb = keymapsbuf true dc dc in
7412 if Buffer.length
kb > 0
7414 Buffer.add_string
bb ">\n";
7415 Buffer.add_buffer
bb kb;
7416 Buffer.add_string
bb "\n</defaults>\n";
7418 else Buffer.add_string
bb "/>\n";
7420 let adddoc path pan
anchor c bookmarks =
7421 if bookmarks == [] && c = dc && anchor = emptyanchor
7424 Printf.bprintf
bb "<doc path='%s'"
7425 (enent
path 0 (String.length
path));
7427 if anchor <> emptyanchor
7429 let n, rely, visy
= anchor in
7430 Printf.bprintf
bb " page='%d'" n;
7433 Printf.bprintf
bb " rely='%f'" rely
7435 if abs_float visy
> 1e-6
7437 Printf.bprintf
bb " visy='%f'" visy
7442 then Printf.bprintf
bb " pan='%d'" pan
;
7444 add_attrs bb false dc c;
7445 let kb = keymapsbuf false dc c in
7447 begin match bookmarks with
7449 if Buffer.length
kb > 0
7451 Buffer.add_string
bb ">\n";
7452 Buffer.add_buffer
bb kb;
7453 Buffer.add_string
bb "\n</doc>\n";
7455 else Buffer.add_string
bb "/>\n"
7457 Buffer.add_string
bb ">\n<bookmarks>\n";
7458 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7460 "<item title='%s' page='%d'"
7461 (enent
title 0 (String.length
title))
7466 Printf.bprintf
bb " rely='%f'" rely
7468 if abs_float visy
> 1e-6
7470 Printf.bprintf
bb " visy='%f'" visy
7472 Buffer.add_string
bb "/>\n";
7474 Buffer.add_string
bb "</bookmarks>";
7475 if Buffer.length
kb > 0
7477 Buffer.add_string
bb "\n";
7478 Buffer.add_buffer
bb kb;
7480 Buffer.add_string
bb "\n</doc>\n";
7486 match state.mode with
7487 | Birdseye
(c, pan, _, _, _) ->
7489 match conf.columns
with
7490 | Cmulti
((c, _, _), _) -> Some
c
7494 match c.columns
with
7495 | Cmulti
(c, _) -> Cmulti
(c, [||])
7496 | Csingle
_ -> Csingle
[||]
7497 | Csplit
_ -> failwith
"quit from bird's eye while split"
7499 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7502 let basename = Filename.basename
7503 (if emptystr
state.origin
then state.path else state.origin
)
7505 adddoc basename pan (getanchor ())
7507 let autoscrollstep =
7508 match state.autoscroll
with
7510 | None
-> conf.autoscrollstep
7512 match state.mode with
7513 | Birdseye
(bc
, _, _, _, _) ->
7516 presentation
= bc
.presentation
;
7517 interpagespace
= bc
.interpagespace
;
7518 maxwait
= bc
.maxwait
;
7519 autoscrollstep = autoscrollstep }
7520 | _ -> { conf with autoscrollstep = autoscrollstep }
7522 (if conf.savebmarks
then state.bookmarks else []);
7524 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7526 then adddoc path x anchor c bookmarks
7528 Buffer.add_string
bb "</llppconfig>\n";
7531 if load1 f && Buffer.length
bb > 0
7534 let tmp = !confpath ^
".tmp" in
7535 let oc = open_out_bin
tmp in
7536 Buffer.output_buffer
oc bb;
7538 Unix.rename
tmp !confpath;
7541 ("error while saving configuration: " ^ exntos exn
)
7545 let adderrmsg src msg
=
7546 Buffer.add_string
state.errmsgs msg
;
7547 state.newerrmsgs
<- true;
7551 let adderrfmt src fmt
=
7552 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7556 let cl = splitatspace cmds
in
7558 try Scanf.sscanf
s fmt
f
7560 adderrfmt "remote exec"
7561 "error processing '%S': %s\n" cmds
(exntos exn
)
7564 | "reload" :: [] -> reload ()
7565 | "goto" :: args :: [] ->
7566 scan args "%u %f %f"
7568 let cmd, _ = state.geomcmds
in
7570 then gotopagexy pageno x y
7573 gotopagexy pageno x y;
7576 state.reprf
<- f state.reprf
7578 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7579 | "rect" :: args :: [] ->
7580 scan args "%u %u %f %f %f %f"
7581 (fun pageno color x0 y0 x1 y1 ->
7582 onpagerect pageno (fun w h ->
7583 let _,w1,h1
,_ = getpagedim pageno in
7584 let sw = float w1 /. float w
7585 and sh = float h1
/. float h in
7589 and y1s
= y1 *. sh in
7590 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7592 state.rects <- (pageno, color, rect) :: state.rects;
7593 G.postRedisplay "rect";
7596 | "activatewin" :: [] -> Wsi.activatewin
()
7597 | "quit" :: [] -> raise Quit
7599 adderrfmt "remote command"
7600 "error processing remote command: %S\n" cmds
;
7604 let scratch = String.create
80 in
7605 let buf = Buffer.create
80 in
7608 try Some
(Unix.read fd
scratch 0 80)
7610 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7611 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7614 match tempfr () with
7620 if Buffer.length
buf > 0
7622 let s = Buffer.contents
buf in
7632 let pos = String.index_from
scratch ppos '
\n'
in
7633 if pos >= n then -1 else pos
7634 with Not_found
-> -1
7638 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7639 let s = Buffer.contents
buf in
7645 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7651 let remoteopen path =
7652 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7654 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7659 let trimcachepath = ref "" in
7660 let rcmdpath = ref "" in
7661 selfexec := Sys.executable_name
;
7664 [("-p", Arg.String
(fun s -> state.password
<- s),
7665 "<password> Set password");
7669 Config.fontpath := s;
7670 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7672 "<path> Set path to the user interface font");
7676 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7677 Config.confpath := s),
7678 "<path> Set path to the configuration file");
7680 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7681 "<path> Set path to the trim cache file");
7683 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7684 "<named-destination> Set named destination");
7686 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7687 ("-cxack", Arg.Set
cxack, " Cut corners");
7689 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7690 "<path> Set path to the remote commands source");
7692 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7693 "<original-path> Set original path");
7695 ("-v", Arg.Unit
(fun () ->
7697 "%s\nconfiguration path: %s\n"
7701 exit
0), " Print version and exit");
7704 (fun s -> state.path <- s)
7705 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7708 then selfexec := !selfexec ^
" -wtmode";
7710 if emptystr
state.path
7711 then (prerr_endline
"file name missing"; exit
1);
7713 if not
(Config.load ())
7714 then prerr_endline
"failed to load configuration";
7716 let wsfd, winw, winh
= Wsi.init
(object
7717 val mutable m_hack
= false
7718 method expose
= if not m_hack
then G.postRedisplay "expose"
7719 method visible
= G.postRedisplay "visible"
7720 method display = m_hack
<- false; display ()
7721 method reshape w h =
7722 m_hack
<- w < state.winw && h < state.winh
;
7724 method mouse
b d x y m = state.uioh <- state.uioh#button
b d x y m
7726 state.mpos
<- (x, y);
7727 state.uioh <- state.uioh#motion
x y
7728 method pmotion
x y =
7729 state.mpos
<- (x, y);
7730 state.uioh <- state.uioh#pmotion
x y
7732 let mascm = m land (
7733 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7735 match state.keystate
with
7737 let km = k, mascm in
7740 let modehash = state.uioh#
modehash in
7741 try Hashtbl.find modehash km
7743 try Hashtbl.find (findkeyhash conf "global") km
7744 with Not_found
-> KMinsrt
(k, m)
7746 | KMinsrt
(k, m) -> keyboard k m
7747 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7748 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7750 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7751 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7752 state.keystate
<- KSnone
7753 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7754 state.keystate
<- KSinto
(keys
, insrt
)
7756 state.keystate
<- KSnone
7759 state.mpos
<- (x, y);
7760 state.uioh <- state.uioh#pmotion
x y
7761 method leave = state.mpos
<- (-1, -1)
7762 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7763 method quit
= raise Quit
7764 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7769 List.exists
GlMisc.check_extension
7770 [ "GL_ARB_texture_rectangle"
7771 ; "GL_EXT_texture_recangle"
7772 ; "GL_NV_texture_rectangle" ]
7774 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7777 let r = GlMisc.get_string `renderer
in
7778 let p = "Mesa DRI Intel(" in
7779 let l = String.length
p in
7780 String.length
r > l && String.sub
r 0 l = p
7783 defconf.sliceheight
<- 1024;
7784 defconf.texcount
<- 32;
7785 defconf.usepbo
<- true;
7789 match Ne.pipe () with
7791 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7795 match Ne.pipe () with
7797 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7807 setcheckers conf.checkers
;
7809 if conf.redirectstderr
7812 let s = Buffer.contents
state.errmsgs ^
7813 (match state.errfd
with
7815 let s = String.create
(80*24) in
7818 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7820 then Unix.read fd
s 0 (String.length
s)
7826 else String.sub
s 0 n
7830 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7831 with exn
-> print_endline
(exntos exn
)
7836 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7837 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7838 !Config.fontpath, !trimcachepath,
7839 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7841 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
7844 state.text <- "Opening " ^
(mbtoutf8
state.path);
7846 opendoc state.path state.password
;
7850 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7853 if nonemptystr
!rcmdpath
7854 then remoteopen !rcmdpath
7859 let rec loop deadline
=
7861 match state.errfd
with
7862 | None
-> [state.sr
; state.wsfd]
7863 | Some fd
-> [state.sr
; state.wsfd; fd
]
7868 | Some fd
-> fd
:: r
7872 state.redisplay
<- false;
7879 if deadline
= infinity
7881 else max
0.0 (deadline
-. now)
7886 try Unix.select
r [] [] timeout
7887 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7893 if state.ghyll
== noghyll
7895 match state.autoscroll
with
7896 | Some step
when step
!= 0 ->
7897 let y = state.y + step
in
7901 else if y >= state.maxy then 0 else y
7904 if state.mode = View
7905 then state.text <- "";
7908 else deadline
+. 0.01
7913 let rec checkfds = function
7915 | fd
:: rest
when fd
= state.sr
->
7916 let cmd = readcmd state.sr
in
7920 | fd
:: rest
when fd
= state.wsfd ->
7924 | fd
:: rest
when Some fd
= !optrfd ->
7925 begin match remote fd
with
7926 | None
-> optrfd := remoteopen !rcmdpath;
7927 | opt -> optrfd := opt
7932 let s = String.create
80 in
7933 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7934 if conf.redirectstderr
7936 Buffer.add_substring
state.errmsgs
s 0 n;
7937 state.newerrmsgs
<- true;
7938 state.redisplay
<- true;
7941 prerr_string
(String.sub
s 0 n);
7949 if deadline
= infinity
7953 match state.autoscroll
with
7954 | Some step
when step
!= 0 -> deadline1
7955 | _ -> if state.ghyll
== noghyll then infinity
else deadline1