8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 | Uremotedest
of (string * string)
15 and facename
= string;;
24 type params
= (angle
* fitmodel
* trimparams
25 * texcount
* sliceheight
* memsize
26 * colorspace
* fontpath
* trimcachepath
36 and trimmargins
= bool
37 and interpagespace
= int
44 and trimcachepath
= string
47 and irect
= (int * int * int * int)
48 and trimparams
= (trimmargins
* irect
)
49 and colorspace
= | Rgb
| Bgr
| Gray
50 and fitmodel
= | FitWidth
| FitProportional
| FitPage
58 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
67 | LDfirstvisible
of (int * int * int)
82 | KMmulti
of key list
* key list
84 and keyhash
= (key
, keymap
) Hashtbl.t
87 | KSinto
of (key list
* key list
)
90 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
91 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
93 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
95 external init
: pipe
-> params
-> unit = "ml_init";;
96 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
97 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
98 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
99 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
100 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
101 external clearmark
: string -> unit = "ml_clearmark";;
102 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
103 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
104 external measurestr
: int -> string -> float = "ml_measure_string";;
105 external postprocess
:
106 opaque
-> int -> int -> int -> (int * string * int) -> int
108 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
109 external platform
: unit -> platform
= "ml_platform";;
110 external setaalevel
: int -> unit = "ml_setaalevel";;
111 external realloctexts
: int -> bool = "ml_realloctexts";;
112 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
113 external getlink
: opaque
-> int -> under
= "ml_getlink";;
114 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
115 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
116 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
117 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
118 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
119 external freepbo
: string -> unit = "ml_freepbo";;
120 external unmappbo
: string -> unit = "ml_unmappbo";;
121 external pbousable
: unit -> bool = "ml_pbo_usable";;
122 external unproject
: opaque
-> int -> int -> (int * int) option
124 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
125 external rectofblock
: opaque
-> int -> int -> float array
option
127 external fz_version
: unit -> string = "ml_fz_version";;
128 external begintiles
: unit -> unit = "ml_begintiles";;
129 external endtiles
: unit -> unit = "ml_endtiles";;
131 let platform_to_string = function
132 | Punknown
-> "unknown"
136 | Pfreebsd
-> "FreeBSD"
137 | Pdragonflybsd
-> "DragonflyBSD"
138 | Popenbsd
-> "OpenBSD"
139 | Pnetbsd
-> "NetBSD"
140 | Pcygwin
-> "Cygwin"
143 let platform = platform ();;
145 let now = Unix.gettimeofday
;;
147 let selfexec = ref "";;
150 if platform = Pcygwin
152 let sh = "/bin/sh" in
153 let args = [|sh; "-c"; cmd
|] in
154 let rec std si so se
= function
156 | (fd
, 0) :: rest
-> std fd so se rest
157 | (fd
, -1) :: rest
->
158 Unix.set_close_on_exec fd
;
161 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
163 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
164 ignore
(Unix.create_process
sh args si so se
)
169 type mpos
= int * int
171 | Msel
of (mpos
* mpos
)
173 | Mscrolly
| Mscrollx
174 | Mzoom
of (int * int)
175 | Mzoomrect
of (mpos
* mpos
)
179 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
180 and onkey
= string -> int -> te
181 and ondone
= string -> unit
182 and histcancel
= unit -> unit
183 and onhist
= ((histcmd
-> string) * histcancel
)
184 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
185 and cancelonempty
= bool
190 | TEswitch
of textentry
201 let bound v minv maxv
=
202 max minv
(min maxv v
);
206 { store
= Array.create n v
213 let cbcap b
= Array.length b
.store
;;
218 b
.wc
<- (b
.wc
+ 1) mod cap;
220 b
.len
<- min
(b
.len
+ 1) cap;
223 let cbempty b
= b
.len
= 0;;
225 let cbgetg b circular dir
=
229 let rc = b
.rc + dir
in
241 else bound rc 0 (b
.len
-1)
247 let cbget b
= cbgetg b
false;;
248 let cbgetc b
= cbgetg b
true;;
250 let drawstring size x y s
=
252 Gl.enable `texture_2d
;
253 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
254 ignore
(drawstr size x y s
);
256 Gl.disable `texture_2d
;
259 let drawstring1 size x y s
=
263 let drawstring2 size x y fmt
=
264 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
283 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
284 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
285 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
286 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
287 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
288 dolog
" column %d" l
.pagecol
;
292 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
294 dolog
" x0,y0=(% f, % f)" x0 y0
;
295 dolog
" x1,y1=(% f, % f)" x1 y1
;
296 dolog
" x2,y2=(% f, % f)" x2 y2
;
297 dolog
" x3,y3=(% f, % f)" x3 y3
;
301 type multicolumns
= multicol
* pagegeom
302 and singlecolumn
= pagegeom
303 and splitcolumns
= columncount
* pagegeom
304 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
305 and multicol
= columncount
* covercount
* covercount
307 and columncount
= int
308 and covercount
= int;;
315 { mutable scrollbw
: int
316 ; mutable scrollh
: int
317 ; mutable scrollb
: scrollb
318 ; mutable icase
: bool
319 ; mutable preload
: bool
320 ; mutable pagebias
: int
321 ; mutable verbose
: bool
322 ; mutable debug
: bool
323 ; mutable scrollstep
: int
324 ; mutable hscrollstep
: int
325 ; mutable maxhfit
: bool
326 ; mutable crophack
: bool
327 ; mutable autoscrollstep
: int
328 ; mutable maxwait
: float option
329 ; mutable hlinks
: bool
330 ; mutable underinfo
: bool
331 ; mutable interpagespace
: interpagespace
332 ; mutable zoom
: float
333 ; mutable presentation
: bool
334 ; mutable angle
: angle
335 ; mutable cwinw
: int
336 ; mutable cwinh
: int
337 ; mutable savebmarks
: bool
338 ; mutable fitmodel
: fitmodel
339 ; mutable trimmargins
: trimmargins
340 ; mutable trimfuzz
: irect
341 ; mutable memlimit
: memsize
342 ; mutable texcount
: texcount
343 ; mutable sliceheight
: sliceheight
344 ; mutable thumbw
: width
345 ; mutable jumpback
: bool
346 ; mutable bgcolor
: (float * float * float)
347 ; mutable bedefault
: bool
348 ; mutable tilew
: int
349 ; mutable tileh
: int
350 ; mutable mustoresize
: memsize
351 ; mutable checkers
: bool
352 ; mutable aalevel
: int
353 ; mutable urilauncher
: string
354 ; mutable pathlauncher
: string
355 ; mutable colorspace
: colorspace
356 ; mutable invert
: bool
357 ; mutable colorscale
: float
358 ; mutable redirectstderr
: bool
359 ; mutable ghyllscroll
: (int * int * int) option
360 ; mutable columns
: columns
361 ; mutable beyecolumns
: columncount
option
362 ; mutable selcmd
: string
363 ; mutable paxcmd
: string
364 ; mutable updatecurs
: bool
365 ; mutable keyhashes
: (string * keyhash
) list
366 ; mutable hfsize
: int
367 ; mutable pgscale
: float
368 ; mutable usepbo
: bool
369 ; mutable wheelbypage
: bool
370 ; mutable stcmd
: string
371 ; mutable riani
: bool
372 ; mutable pax
: (float * int * int) ref option
373 ; mutable paxmark
: mark
376 | Csingle
of singlecolumn
377 | Cmulti
of multicolumns
378 | Csplit
of splitcolumns
381 type anchor
= pageno
* top
* dtop
;;
383 type outline
= string * int * anchor
;;
385 type rect
= float * float * float * float * float * float * float * float;;
387 type tile
= opaque
* pixmapsize
* elapsed
388 and elapsed
= float;;
389 type pagemapkey
= pageno
* gen
;;
390 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
394 let emptyanchor = (0, 0.0, 0.0);;
396 type infochange
= | Memused
| Docinfo
| Pdim
;;
398 class type uioh
= object
399 method display
: unit
400 method key
: int -> int -> uioh
401 method button
: int -> bool -> int -> int -> int -> uioh
402 method motion
: int -> int -> uioh
403 method pmotion
: int -> int -> uioh
404 method infochanged
: infochange
-> unit
405 method scrollpw
: (int * float * float)
406 method scrollph
: (int * float * float)
407 method modehash
: keyhash
408 method eformsgs
: bool
412 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
413 | Textentry
of (textentry
* onleave
)
415 | LinkNav
of linktarget
416 and onleave
= leavetextentrystatus
-> unit
417 and leavetextentrystatus
= | Cancel
| Confirm
418 and helpitem
= string * int * action
421 | Action
of (uioh
-> uioh
)
423 | Ltexact
of (pageno
* int)
427 let isbirdseye = function Birdseye _
-> true | _
-> false;;
428 let istextentry = function Textentry _
-> true | _
-> false;;
432 | Loading
of (page
* gen
)
434 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
436 | Outlining
of outline list
439 let emptykeyhash = Hashtbl.create
0;;
440 let nouioh : uioh
= object (self
)
442 method key _ _
= self
443 method button _ _ _ _ _
= self
444 method motion _ _
= self
445 method pmotion _ _
= self
446 method infochanged _
= ()
447 method scrollpw
= (0, nan
, nan
)
448 method scrollph
= (0, nan
, nan
)
449 method modehash
= emptykeyhash
450 method eformsgs
= false
454 { mutable sr
: Unix.file_descr
455 ; mutable sw
: Unix.file_descr
456 ; mutable wsfd
: Unix.file_descr
457 ; mutable errfd
: Unix.file_descr
option
458 ; mutable stderr
: Unix.file_descr
459 ; mutable errmsgs
: Buffer.t
460 ; mutable newerrmsgs
: bool
464 ; mutable anchor
: anchor
465 ; mutable ranchors
: (string * string * anchor
* string) list
467 ; mutable layout
: page list
468 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
469 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
470 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
471 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
472 ; mutable pagecount
: int
473 ; mutable currently
: currently
474 ; mutable mstate
: mstate
475 ; mutable searchpattern
: string
476 ; mutable rects
: (pageno
* recttype
* rect
) list
477 ; mutable rects1
: (pageno
* recttype
* rect
) list
478 ; mutable text
: string
479 ; mutable winstate
: Wsi.winstate list
480 ; mutable mode
: mode
481 ; mutable uioh
: uioh
482 ; mutable outlines
: outline array
483 ; mutable bookmarks
: outline list
484 ; mutable path
: string
485 ; mutable password
: string
486 ; mutable nameddest
: string
487 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
488 ; mutable memused
: memsize
490 ; mutable throttle
: (page list
* int * float) option
491 ; mutable autoscroll
: int option
492 ; mutable ghyll
: (int option -> unit)
493 ; mutable help
: helpitem array
494 ; mutable docinfo
: (int * string) list
495 ; mutable texid
: GlTex.texture_id
option
497 ; mutable prevzoom
: (float * int)
498 ; mutable progress
: float
499 ; mutable redisplay
: bool
500 ; mutable mpos
: mpos
501 ; mutable keystate
: keystate
502 ; mutable glinks
: bool
503 ; mutable prevcolumns
: (columns
* float) option
506 ; mutable reprf
: (unit -> unit)
507 ; mutable origin
: string
508 ; mutable roam
: (unit -> unit)
509 ; mutable bzoom
: bool
510 ; mutable traw
: [`
float] Raw.t
511 ; mutable vraw
: [`
float] Raw.t
514 { pat
: string circbuf
515 ; pag
: string circbuf
516 ; nav
: anchor circbuf
517 ; sel
: string circbuf
524 ; scrollb
= scrollbhv lor scrollbvv
540 ; presentation
= false
545 ; fitmodel
= FitProportional
546 ; trimmargins
= false
547 ; trimfuzz
= (0,0,0,0)
548 ; memlimit
= 32 lsl 20
553 ; bgcolor
= (0.5, 0.5, 0.5)
557 ; mustoresize
= 256 lsl 20
562 | Plinux
| Pfreebsd
| Pdragonflybsd
563 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
564 | Posx
-> "open \"%s\""
565 | Pcygwin
-> "cygstart \"%s\""
566 | Punknown
-> "echo %s")
567 ; pathlauncher
= "lp \"%s\""
570 | Plinux
| Pfreebsd
| Pdragonflybsd
571 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
579 ; redirectstderr
= false
581 ; columns
= Csingle
[||]
587 ; wheelbypage
= false
588 ; stcmd
= "echo SyncTex"
591 ; paxmark
= Mark_word
593 let mk n
= (n
, Hashtbl.create
1) in
607 let wtmode = ref false;;
608 let cxack = ref false;;
610 let findkeyhash c name
=
611 try List.assoc name c
.keyhashes
612 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
615 let conf = { defconf with angle
= defconf.angle
};;
617 let pgscale h
= truncate
(float h
*. conf.pgscale);;
620 { mutable fontsize
: int
621 ; mutable wwidth
: float
622 ; mutable maxrows
: int
634 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
635 let len = String.length s
in
636 if colonpos >= 0 && colonpos + 3 < len
638 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
641 try String.rindex_from s
colonpos ' '
645 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
648 | "http" | "ftp" | "mailto" ->
650 try String.index_from s
colonpos ' '
651 with Not_found
-> len
653 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
661 if emptystr
conf.urilauncher
662 then print_endline uri
664 let url = geturl uri
in
666 then Printf.eprintf
"obtained empty url from uri %S" uri
668 let re = Str.regexp
"%s" in
669 let command = Str.global_replace
re url conf.urilauncher
in
673 "failed to execute `%s': %s\n" command (exntos exn
);
679 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
680 Help.version (fz_version
()) Sys.ocaml_version
681 (platform_to_string platform) Sys.word_size
685 let strings = version () :: "" :: Help.keys
in
688 let url = geturl s
in
690 then (s
, 0, Action
(fun u
-> gotouri url; u
))
691 else (s
, 0, Noaction
)
696 let firstgeomcmds = "", [];;
697 let noreprf () = ();;
704 ; stderr
= Unix.stderr
705 ; errmsgs
= Buffer.create
0
710 ; anchor
= emptyanchor
714 ; tilelru
= Queue.create
()
715 ; pagemap
= Hashtbl.create
10
716 ; tilemap
= Hashtbl.create
10
732 ; geomcmds
= firstgeomcmds
734 { nav
= cbnew 10 emptyanchor
747 ; prevzoom
= (1.0, 0)
759 ; roam
= (fun () -> ())
761 ; traw
= Raw.create_static `
float 8
762 ; vraw
= Raw.create_static `
float 8
767 if (conf.scrollb
land scrollbhv = 0)
768 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
774 if (conf.scrollb
land scrollbvv = 0)
779 let wadjsb w
= w
- vscrollw ();;
782 fstate.fontsize
<- n
;
783 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
784 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
790 Printf.kprintf prerr_endline fmt
792 Printf.kprintf ignore fmt
796 if emptystr
conf.pathlauncher
797 then print_endline
state.path
799 let re = Str.regexp
"%s" in
800 let command = Str.global_replace
re state.path
conf.pathlauncher
in
803 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
809 type 'a t
= | Res
of 'a
| Exn
of exn
;;
812 try Res
(Unix.pipe ())
817 try tempfailureretry
Unix.close fd
818 with exn
-> f
(exntos exn
)
822 try Res
(tempfailureretry
Unix.dup fd
)
827 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
832 let redirectstderr () =
833 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
834 if conf.redirectstderr
836 match Ne.pipe () with
838 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
841 begin match Ne.dup Unix.stderr
with
843 dolog
"failed to dup stderr: %s" (exntos exn
);
844 Ne.clo r
(clofail "pipe/r");
845 Ne.clo w
(clofail "pipe/w");
847 | Ne.Res dupstderr
->
848 begin match Ne.dup2 w
Unix.stderr
with
850 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
851 Ne.clo dupstderr
(clofail "stderr duplicate");
852 Ne.clo r
(clofail "redir pipe/r");
853 Ne.clo w
(clofail "redir pipe/w");
856 state.stderr
<- dupstderr
;
857 state.errfd
<- Some r
;
861 state.newerrmsgs
<- false;
862 begin match state.errfd
with
864 begin match Ne.dup2 state.stderr
Unix.stderr
with
866 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
868 Ne.clo fd
(clofail "dup of stderr");
873 prerr_string
(Buffer.contents
state.errmsgs
);
875 Buffer.clear
state.errmsgs
;
881 let postRedisplay who
=
883 then prerr_endline
("redisplay for " ^ who
);
884 state.redisplay
<- true;
888 let getopaque pageno
=
889 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
890 with Not_found
-> None
893 let putopaque pageno opaque
=
894 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
897 let pagetranslatepoint l x y
=
898 let dy = y
- l
.pagedispy
in
899 let y = dy + l
.pagey
in
900 let dx = x
- l
.pagedispx
in
901 let x = dx + l
.pagex
in
905 let onppundermouse g
x y d
=
908 begin match getopaque l
.pageno
with
910 let x0 = l
.pagedispx
in
911 let x1 = x0 + l
.pagevw
in
912 let y0 = l
.pagedispy
in
913 let y1 = y0 + l
.pagevh
in
914 if y >= y0 && y <= y1 && x >= x0 && x <= x1
916 let px, py
= pagetranslatepoint l
x y in
917 match g opaque l
px py
with
930 let g opaque l
px py
=
933 match rectofblock opaque
px py
with
935 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
936 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
937 G.postRedisplay "getunder";
940 match whatsunder opaque
px py
with
942 | under
-> Some under
944 onppundermouse g x y Unone
949 match unproject opaque
x y with
950 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
953 onppundermouse g x y None
;
957 state.text
<- Printf.sprintf
"%c%s" c s
;
958 G.postRedisplay "showtext";
962 let g opaque l
px py
=
963 if markunder opaque
px py
conf.paxmark
966 match getopaque l
.pageno
with
969 match Ne.pipe () with
973 "can not create mark pipe: %s"
976 let doclose what fd
=
977 Ne.clo fd
(fun msg
->
978 dolog
"%s close failed: %s" what msg
)
981 popen conf.paxcmd
[r
, 0; w
, -1];
982 copysel w opaque
false;
984 G.postRedisplay "paxunder";
986 dolog
"can not execute %S: %s"
987 conf.paxcmd
(exntos exn
);
994 G.postRedisplay "paxunder";
995 if conf.paxmark
= Mark_page
998 match getopaque l
.pageno
with
1000 | Some opaque
-> clearmark opaque
) state.layout
;
1002 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1006 match Ne.pipe () with
1008 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1011 try popen conf.selcmd
[r
, 0; w
, -1]; true
1014 (Printf.sprintf
"failed to execute %s: %s"
1015 conf.selcmd
(exntos exn
));
1019 Ne.clo fd
(fun msg
->
1020 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1026 let l = String.length s
in
1027 let n = tempfailureretry
(Unix.write w s
0) l in
1032 "failed to write %d characters to sel pipe, wrote %d"
1037 (Printf.sprintf
"failed to write to sel pipe: %s"
1046 let undertext = function
1049 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1050 | Utext s
-> "font: " ^ s
1051 | Uunexpected s
-> "unexpected: " ^ s
1052 | Ulaunch s
-> "launch: " ^ s
1053 | Unamed s
-> "named: " ^ s
1054 | Uremote
(filename
, pageno
) ->
1055 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1056 | Uremotedest
(filename
, destname
) ->
1057 Printf.sprintf
"%s: destination %S" filename destname
1060 let updateunder x y =
1061 match getunder x y with
1062 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1064 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1065 Wsi.setcursor
Wsi.CURSOR_INFO
1066 | Ulinkgoto
(pageno
, _
) ->
1068 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1069 Wsi.setcursor
Wsi.CURSOR_INFO
1071 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1072 Wsi.setcursor
Wsi.CURSOR_TEXT
1074 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1075 Wsi.setcursor
Wsi.CURSOR_INHERIT
1077 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1078 Wsi.setcursor
Wsi.CURSOR_INHERIT
1080 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1081 Wsi.setcursor
Wsi.CURSOR_INHERIT
1082 | Uremote
(filename
, pageno
) ->
1083 if conf.underinfo
then showtext 'r'
1084 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1085 Wsi.setcursor
Wsi.CURSOR_INFO
1086 | Uremotedest
(filename
, destname
) ->
1087 if conf.underinfo
then showtext 'r'
1088 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1089 Wsi.setcursor
Wsi.CURSOR_INFO
1092 let showlinktype under
=
1098 let s = undertext under
in
1103 let b = Buffer.create
(String.length
s + 1) in
1104 Buffer.add_string
b s;
1105 Buffer.add_char
b c
;
1109 module type TextEnumType
=
1113 val names
: string array
1116 module TextEnumMake
(Ten
: TextEnumType
) =
1118 let names = Ten.names;;
1119 let to_int (t
: Ten.t
) = Obj.magic t
;;
1120 let to_string t
= names.(to_int t
);;
1121 let of_int n : Ten.t
= Obj.magic
n;;
1124 if i
= Array.length
names
1125 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1127 if Ten.names.(i
) = s
1134 module CSTE
= TextEnumMake
(struct
1135 type t
= colorspace
;;
1136 let name = "colorspace";;
1137 let names = [|"rgb"; "bgr"; "gray"|];;
1140 module MTE
= TextEnumMake
(struct
1143 let names = [|"page"; "block"; "line"; "word"|];;
1146 module FMTE
= TextEnumMake
(struct
1148 let name = "fitmodel";;
1149 let names = [|"width"; "proportional"; "page"|];;
1152 let intentry_with_suffix text key
=
1154 if key
>= 32 && key
< 127
1158 match Char.lowercase
c with
1160 let text = addchar text c in
1163 | 'k'
| 'm'
| '
g'
->
1164 let text = addchar text c in
1168 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1172 let multicolumns_to_string (n, a
, b) =
1174 then Printf.sprintf
"%d" n
1175 else Printf.sprintf
"%d,%d,%d" n a
b;
1178 let multicolumns_of_string s =
1180 (int_of_string
s, 0, 0)
1182 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1184 then failwith
"subtly broken"; (n, a
, b)
1190 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1191 if n != 4 then error
"incomplete read(len) = %d" n;
1193 lor (Char.code
s.[0] lsl 24)
1194 lor (Char.code
s.[1] lsl 16)
1195 lor (Char.code
s.[2] lsl 8)
1196 lor (Char.code
s.[3] lsl 0)
1198 let s = String.create
len in
1199 let n = tempfailureretry
(Unix.read fd
s 0) len in
1200 if n != len then error
"incomplete read(data) %d vs %d" n len;
1204 let btod b = if b then 1 else 0;;
1207 let b = Buffer.create
16 in
1208 Buffer.add_string
b "llll";
1211 let s = Buffer.contents
b in
1212 let n = String.length
s in
1214 (* dolog "wcmd %S" (String.sub s 4 len); *)
1215 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1216 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1217 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1218 s.[3] <- Char.chr
(len land 0xff);
1219 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1220 if n'
!= n then error
"write failed %d vs %d" n'
n;
1225 let d = state.winh
- h
in
1226 max
conf.interpagespace
((d + 1) / 2)
1229 let rowyh (c, coverA
, coverB
) b n =
1230 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1232 let _, _, vy
, (_, _, h
, _) = b.(n) in
1235 let n'
= n - coverA
in
1238 let e = min
state.pagecount
(s + c) in
1239 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1240 let _, _, y, (_, _, h
, _) = b.(m
) in
1241 let miny = min
miny y in
1242 let maxh = max
maxh h
in
1243 find (m
+1) miny maxh
1248 match conf.columns
with
1249 | Cmulti
((_, _, _) as cl
, b) ->
1250 if Array.length
b > 0
1252 let y, h
= rowyh cl
b (Array.length
b - 1) in
1253 y + h
+ (if conf.presentation
then calcips h
else 0)
1256 if Array.length
b > 0
1258 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1259 y + h
+ (if conf.presentation
then calcips h
else 0)
1262 if Array.length
b > 0
1264 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1269 let getpageywh pageno
=
1270 let pageno = bound pageno 0 (state.pagecount
-1) in
1271 match conf.columns
with
1273 if Array.length
b = 0
1276 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1278 if conf.presentation
1284 if Array.length
b = 0
1287 let y, h
= rowyh cl
b pageno in
1288 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1290 if conf.presentation
1296 if Array.length
b = 0
1300 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1304 let getpageyh pageno =
1305 let y,_,h
= getpageywh pageno in
1309 let getpagedim pageno =
1312 | (n, _, _, _) as pdim
:: rest
->
1314 then (if n = pageno then pdim
else ppdim
)
1319 f (-1, -1, -1, -1) state.pdims
1322 let getpagey pageno = fst
(getpageyh pageno);;
1324 let nogeomcmds cmds
=
1326 | s, [] -> emptystr
s
1331 let ((c, coverA
, coverB
) as cl
), b =
1332 match conf.columns
with
1333 | Csingle
b -> (1, 0, 0), b
1334 | Cmulti
(c, b) -> c, b
1335 | Csplit
(_, b) -> (1, 0, 0), b
1337 if Array.length
b = 0
1340 let rec bsearch nmin nmax
=
1342 then bound nmin
0 (state.pagecount
-1)
1344 let n = (nmax
+ nmin
) / 2 in
1345 let vy, h
= rowyh cl
b n in
1347 if conf.presentation
1349 let ips = calcips h
in
1350 let y0 = vy - ips in
1351 let y1 = vy + h
+ ips in
1355 then 0, vy + h
+ conf.interpagespace
1357 let y0 = vy - conf.interpagespace
in
1358 y0, y0 + h
+ conf.interpagespace
1361 if y >= y0 && y < y1
1368 if n < state.pagecount
- coverB
1369 then ((n-coverA
)/c)*c + coverA
1376 then bsearch (n+1) nmax
1377 else bsearch nmin
(n-1)
1380 bsearch 0 (state.pagecount
-1);
1383 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1384 let sh = sh - (hscrollh ()) in
1385 let rec fold accu
n =
1386 if n = Array.length
b
1389 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1392 || n = state.pagecount
- coverB
1393 || (n - coverA
) mod columns
= columns
- 1)
1399 let pagey = max
0 (y - vy) in
1400 let pagedispy = if pagey > 0 then 0 else vy - y in
1401 let pagedispx, pagex
=
1403 if n = coverA
- 1 || n = state.pagecount
- coverB
1404 then state.x + (wadjsb state.winw
- w
) / 2
1405 else dx + xoff
+ state.x
1412 let vw = wadjsb state.winw
- pagedispx in
1413 let pw = w
- pagex
in
1416 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1417 if pagevw > 0 && pagevh > 0
1421 ; pagedimno
= pdimno
1428 ; pagedispx = pagedispx
1429 ; pagedispy = pagedispy
1441 if Array.length
b = 0
1443 else List.rev
(fold [] (page_of_y y))
1446 let layoutS (columns
, b) y sh =
1447 let sh = sh - hscrollh () in
1448 let rec fold accu n =
1449 if n = Array.length
b
1452 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1459 let x = xoff
+ state.x in
1460 let pagey = max
0 (y - vy) in
1461 let pagedispy = if pagey > 0 then 0 else vy - y in
1462 let pagedispx, pagex
=
1476 let pagecolw = pagew
/columns
in
1478 if pagecolw < state.winw
1479 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1483 let vw = wadjsb state.winw
- pagedispx in
1484 let pw = pagew
- pagex
in
1487 let pagevw = min
pagevw pagecolw in
1488 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1489 if pagevw > 0 && pagevh > 0
1492 { pageno = n/columns
1493 ; pagedimno
= pdimno
1500 ; pagedispx = pagedispx
1501 ; pagedispy = pagedispy
1502 ; pagecol
= n mod columns
1513 List.rev
(fold [] 0)
1517 if nogeomcmds state.geomcmds
1519 match conf.columns
with
1520 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1521 | Cmulti
c -> layoutN c y sh
1522 | Csplit
s -> layoutS s y sh
1527 let y = state.y + incr
in
1529 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1534 let tilex = l.pagex
mod conf.tilew
in
1535 let tiley = l.pagey mod conf.tileh
in
1537 let col = l.pagex
/ conf.tilew
in
1538 let row = l.pagey / conf.tileh
in
1540 let rec rowloop row y0 dispy h
=
1544 let dh = conf.tileh
- y0 in
1545 let dh = min h
dh in
1546 let rec colloop col x0 dispx w
=
1550 let dw = conf.tilew
- x0 in
1551 let dw = min w
dw in
1553 f col row dispx dispy
x0 y0 dw dh;
1554 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1557 colloop col tilex l.pagedispx l.pagevw;
1558 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1561 if l.pagevw > 0 && l.pagevh > 0
1562 then rowloop row tiley l.pagedispy l.pagevh;
1565 let gettileopaque l col row =
1567 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1569 try Some
(Hashtbl.find state.tilemap
key)
1570 with Not_found
-> None
1573 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1574 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1575 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1578 let filledrect x0 y0 x1 y1 =
1579 GlArray.disable `texture_coord
;
1580 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1581 GlArray.vertex `two
state.vraw
;
1582 GlArray.draw_arrays `triangle_strip
0 4;
1583 GlArray.enable `texture_coord
;
1586 let linerect x0 y0 x1 y1 =
1587 GlArray.disable `texture_coord
;
1588 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1589 GlArray.vertex `two
state.vraw
;
1590 GlArray.draw_arrays `line_loop
0 4;
1591 GlArray.enable `texture_coord
;
1594 let drawtiles l color
=
1597 let f col row x y tilex tiley w h
=
1598 match gettileopaque l col row with
1599 | Some
(opaque
, _, t
) ->
1600 let params = x, y, w
, h
, tilex, tiley in
1604 GlFunc.blend_func `zero `one_minus_src_color
;
1606 drawtile
params opaque
;
1608 then Gl.disable `blend
;
1611 let s = Printf.sprintf
1615 let w = measurestr
fstate.fontsize
s in
1616 GlDraw.color
(0.0, 0.0, 0.0);
1617 filledrect (float (x-2))
1620 (float (y + fstate.fontsize
+ 2));
1621 GlDraw.color
(1.0, 1.0, 1.0);
1622 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1628 let lw = wadjsb state.winw
- x in
1631 let lh = state.winh
- y in
1634 begin match state.texid
with
1636 Gl.enable `texture_2d
;
1637 GlTex.bind_texture `texture_2d id
;
1640 and x1 = float (x+w)
1641 and y1 = float (y+h
) in
1643 let tw = float w /. 16.0
1644 and th
= float h
/. 16.0 in
1645 let tx0 = float tilex /. 16.0
1646 and ty0
= float tiley /. 16.0 in
1648 and ty1
= ty0
+. th
in
1649 Raw.sets_float
state.vraw ~pos
:0
1650 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1651 Raw.sets_float
state.traw ~pos
:0
1652 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1653 GlArray.vertex `two
state.vraw
;
1654 GlArray.tex_coord `two
state.traw
;
1655 GlArray.draw_arrays `triangle_strip
0 4;
1658 GlDraw.color
(1.0, 1.0, 1.0);
1659 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1661 if w > 128 && h
> fstate.fontsize
+ 10
1663 GlDraw.color
(0.0, 0.0, 0.0);
1666 then (col*conf.tilew
, row*conf.tileh
)
1669 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1678 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1680 let tilevisible1 l x y =
1682 and ax1
= l.pagex
+ l.pagevw
1684 and ay1
= l.pagey + l.pagevh in
1688 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1689 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1691 let rx0 = max
ax0 bx0
1692 and ry0
= max ay0 by0
1693 and rx1
= min ax1
bx1
1694 and ry1
= min ay1 by1
in
1696 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1697 nonemptyintersection
1700 let tilevisible layout n x y =
1701 let rec findpageinlayout m
= function
1702 | l :: rest
when l.pageno = n ->
1703 tilevisible1 l x y || (
1704 match conf.columns
with
1705 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1708 | _ :: rest
-> findpageinlayout 0 rest
1711 findpageinlayout 0 layout;
1714 let tileready l x y =
1715 tilevisible1 l x y &&
1716 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1719 let tilepage n p
layout =
1720 let rec loop = function
1724 let f col row _ _ _ _ _ _ =
1725 if state.currently
= Idle
1727 match gettileopaque l col row with
1730 let x = col*conf.tilew
1731 and y = row*conf.tileh
in
1733 let w = l.pagew
- x in
1737 let h = l.pageh
- y in
1742 then getpbo
w h conf.colorspace
1745 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1748 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1749 conf.tilew
, conf.tileh
1758 if nogeomcmds state.geomcmds
1762 let preloadlayout y =
1763 let y = if y < state.winh
then 0 else y - state.winh
in
1764 let h = state.winh
*3 in
1769 let rec loop pages
=
1770 if state.currently
!= Idle
1775 begin match getopaque l.pageno with
1777 wcmd "page %d %d" l.pageno l.pagedimno
;
1778 state.currently
<- Loading
(l, state.gen
);
1780 tilepage l.pageno opaque pages
;
1785 if nogeomcmds state.geomcmds
1791 if conf.preload && state.currently
= Idle
1792 then load (preloadlayout state.y);
1795 let layoutready layout =
1796 let rec fold all ls
=
1797 all
&& match ls
with
1799 let seen = ref false in
1800 let allvisible = ref true in
1801 let foo col row _ _ _ _ _ _ =
1803 allvisible := !allvisible &&
1804 begin match gettileopaque l col row with
1810 fold (!seen && !allvisible) rest
1813 let alltilesvisible = fold true layout in
1818 let y = bound y 0 state.maxy
in
1819 let y, layout, proceed
=
1820 match conf.maxwait
with
1821 | Some time
when state.ghyll
== noghyll ->
1822 begin match state.throttle
with
1824 let layout = layout y state.winh
in
1825 let ready = layoutready layout in
1829 state.throttle
<- Some
(layout, y, now ());
1831 else G.postRedisplay "gotoy showall (None)";
1833 | Some
(_, _, started
) ->
1834 let dt = now () -. started
in
1837 state.throttle
<- None
;
1838 let layout = layout y state.winh
in
1840 G.postRedisplay "maxwait";
1847 let layout = layout y state.winh
in
1848 if not
!wtmode || layoutready layout
1849 then G.postRedisplay "gotoy ready";
1855 state.layout <- layout;
1856 begin match state.mode
with
1857 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1858 let rec loop = function
1860 state.mode
<- LinkNav
(Ltgendir
0)
1861 | l :: _ when l.pageno = pageno ->
1862 begin match getopaque pageno with
1864 state.mode
<- LinkNav
(Ltgendir
0)
1866 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1867 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1868 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1869 then state.mode
<- LinkNav
(Ltgendir
0)
1871 | _ :: rest
-> loop rest
1876 begin match state.mode
with
1877 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1878 if not
(pagevisible layout pageno)
1880 match state.layout with
1883 state.mode
<- Birdseye
(
1884 conf, leftx
, l.pageno, hooverpageno
, anchor
1887 | LinkNav
(Ltgendir dir
as lt
) ->
1889 let rec loop = function
1892 match getopaque l.pageno with
1898 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1900 if dir
> 0 then LDfirst
else LDlast
1906 | Lnotfound
-> loop rest
1908 showlinktype (getlink opaque
n);
1909 Ltexact
(l.pageno, n)
1913 state.mode
<- LinkNav
linknav
1918 state.ghyll
<- noghyll;
1921 let mx, my
= state.mpos
in
1926 let conttiling pageno opaque
=
1927 tilepage pageno opaque
1928 (if conf.preload then preloadlayout state.y else state.layout)
1931 let gotoy_and_clear_text y =
1932 if not
conf.verbose
then state.text <- "";
1938 let coloff = l.pagecol
* l.pageh
in
1939 float (l.pagey + coloff) /. float l.pageh
1946 if conf.presentation
1947 then float l.pagedispy /. float (calcips l.pageh
)
1948 else float l.pagedispy /. float conf.interpagespace
1951 (l.pageno, top, dtop)
1955 match state.layout with
1956 | l :: _ -> getanchor1 l
1958 let n = page_of_y state.y in
1962 let y, h = getpageyh n in
1963 let dy = y - state.y in
1965 if conf.presentation
1967 let ips = calcips h in
1968 float (dy + ips) /. float ips
1970 float dy /. float conf.interpagespace
1975 let getanchory (n, top, dtop) =
1976 let y, h = getpageyh n in
1977 if conf.presentation
1979 let ips = calcips h in
1980 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1982 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1985 let gotoanchor anchor
=
1986 gotoy (getanchory anchor
);
1990 cbput state.hists
.nav
(getanchor ());
1994 let anchor = cbgetc state.hists
.nav dir
in
1999 let scroll f n a
b =
2000 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2002 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2004 then s (float f /. float a
)
2007 then 1.0 -. s ((float (f-b) /. float (n-b)))
2013 let ins = float a
*. 0.5
2014 and outs
= float (n-b) *. 0.5 in
2016 ins +. outs
+. float ones
2018 let rec set (_N
, _A
, _B
) y sy
=
2019 let sum = summa _N _A _B
in
2020 let dy = float (y - sy
) in
2024 then state.ghyll
<- noghyll
2027 let s = scroll n _N _A _B
in
2028 let y1 = y1 +. ((s *. dy) /. sum) in
2029 gotoy_and_clear_text (truncate
y1);
2030 state.ghyll
<- gf (n+1) y1;
2034 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2036 gf 0 (float state.y)
2039 match conf.ghyllscroll
with
2041 gotoy_and_clear_text y
2043 if state.ghyll
== noghyll
2044 then set nab
y state.y
2045 else state.ghyll
(Some
y)
2048 let gotopage n top =
2049 let y, h = getpageyh n in
2050 let y = y + (truncate
(top *. float h)) in
2054 let gotopage1 n top =
2055 let y = getpagey n in
2060 let invalidate s f =
2065 match state.geomcmds
with
2066 | ps
, [] when emptystr ps
->
2068 state.geomcmds
<- s, [];
2071 state.geomcmds
<- ps
, [s, f];
2073 | ps
, (s'
, _) :: rest
when s'
= s ->
2074 state.geomcmds
<- ps
, ((s, f) :: rest
);
2077 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2081 Hashtbl.iter
(fun _ opaque
->
2082 wcmd "freepage %s" opaque
;
2084 Hashtbl.clear
state.pagemap
;
2088 if not
(Queue.is_empty
state.tilelru
)
2090 Queue.iter
(fun (k
, p
, s) ->
2091 wcmd "freetile %s" p
;
2092 state.memused
<- state.memused
- s;
2093 Hashtbl.remove
state.tilemap k
;
2095 state.uioh#infochanged Memused
;
2096 Queue.clear
state.tilelru
;
2102 let h = truncate
(float h*.conf.zoom
) in
2103 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2107 let opendoc path password
=
2109 state.password
<- password
;
2110 state.gen
<- state.gen
+ 1;
2111 state.docinfo
<- [];
2114 setaalevel
conf.aalevel
;
2116 if emptystr
state.origin
2120 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2121 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2122 invalidate "reqlayout"
2124 wcmd "reqlayout %d %d %d %s\000"
2125 conf.angle
(FMTE.to_int conf.fitmodel
)
2126 (stateh state.winh
) state.nameddest
2131 state.anchor <- getanchor ();
2132 opendoc state.path
state.password
;
2136 let c = c *. conf.colorscale
in
2140 let scalecolor2 (r
, g, b) =
2141 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2144 let docolumns = function
2146 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2147 let rec loop pageno pdimno pdim
y ph pdims
=
2148 if pageno = state.pagecount
2151 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2153 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2154 pdimno+1, pdim
, rest
2158 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2160 (if conf.presentation
2161 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2162 else (if pageno = 0 then 0 else conf.interpagespace
)
2165 a.(pageno) <- (pdimno, x, y, pdim
);
2166 loop (pageno+1) pdimno pdim
(y + h) h pdims
2168 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2169 conf.columns
<- Csingle
a;
2171 | Cmulti
((columns
, coverA
, coverB
), _) ->
2172 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2173 let rec loop pageno pdimno pdim
x y rowh pdims
=
2174 let rec fixrow m
= if m
= pageno then () else
2175 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2178 let y = y + (rowh
- h) / 2 in
2179 a.(m
) <- (pdimno, x, y, pdim
);
2183 if pageno = state.pagecount
2184 then fixrow (((pageno - 1) / columns
) * columns
)
2186 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2188 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2189 pdimno+1, pdim
, rest
2194 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2196 let x = (wadjsb state.winw
- w) / 2 in
2198 if conf.presentation
then calcips h else conf.interpagespace
in
2199 x, y + ips + rowh
, h
2202 if (pageno - coverA
) mod columns
= 0
2204 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2206 if conf.presentation
2208 let ips = calcips h in
2209 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2211 y + (if pageno = 0 then 0 else conf.interpagespace
)
2215 else x, y, max rowh
h
2219 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2222 if pageno = columns
&& conf.presentation
2224 let ips = calcips rowh
in
2225 for i
= 0 to pred columns
2227 let (pdimno, x, y, pdim
) = a.(i
) in
2228 a.(i
) <- (pdimno, x, y+ips, pdim
)
2234 fixrow (pageno - columns
);
2239 a.(pageno) <- (pdimno, x, y, pdim
);
2240 let x = x + w + xoff
*2 + conf.interpagespace
in
2241 loop (pageno+1) pdimno pdim
x y rowh' pdims
2243 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2244 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2247 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2248 let rec loop pageno pdimno pdim
y pdims
=
2249 if pageno = state.pagecount
2252 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2254 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2255 pdimno+1, pdim
, rest
2260 let rec loop1 n x y =
2261 if n = c then y else (
2262 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2263 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2266 let y = loop1 0 0 y in
2267 loop (pageno+1) pdimno pdim
y pdims
2269 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2270 conf.columns
<- Csplit
(c, a);
2274 docolumns conf.columns
;
2275 state.maxy
<- calcheight ();
2276 if state.reprf
== noreprf
2278 match state.mode
with
2279 | Birdseye
(_, _, pageno, _, _) ->
2280 let y, h = getpageyh pageno in
2281 let top = (state.winh
- h) / 2 in
2282 gotoy (max
0 (y - top))
2283 | _ -> gotoanchor state.anchor
2287 state.reprf
<- noreprf;
2292 GlDraw.viewport
0 0 w h;
2293 let firsttime = state.geomcmds
== firstgeomcmds in
2294 if not
firsttime && nogeomcmds state.geomcmds
2295 then state.anchor <- getanchor ();
2298 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2301 setfontsize fstate.fontsize
;
2302 GlMat.mode `modelview
;
2303 GlMat.load_identity
();
2305 GlMat.mode `projection
;
2306 GlMat.load_identity
();
2307 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2308 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2309 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2314 else float state.x /. float state.w
2316 invalidate "geometry"
2320 then state.x <- truncate
(relx *. float w);
2322 match conf.columns
with
2324 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2325 | Csplit
(c, _) -> w * c
2327 wcmd "geometry %d %d %d"
2328 w (stateh h) (FMTE.to_int conf.fitmodel
)
2333 let len = String.length
state.text in
2336 match state.mode
with
2337 | Textentry
_ | View
| LinkNav
_ ->
2338 let h, _, _ = state.uioh#scrollpw
in
2343 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2344 (x+.w) (float (state.winh
- hscrollh))
2347 let w = float (wadjsb state.winw
- 1) in
2348 if state.progress
>= 0.0 && state.progress
< 1.0
2350 GlDraw.color
(0.3, 0.3, 0.3);
2351 let w1 = w *. state.progress
in
2353 GlDraw.color
(0.0, 0.0, 0.0);
2357 GlDraw.color
(0.0, 0.0, 0.0);
2361 GlDraw.color
(1.0, 1.0, 1.0);
2362 drawstring fstate.fontsize
2363 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2366 match state.mode
with
2367 | Textentry
((prefix
, text, _, _, _, _), _) ->
2371 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2373 Printf.sprintf
"%s%s_" prefix
text
2382 if not
(istextentry state.mode
) && state.uioh#eformsgs
2384 let s1 = "(press 'e' to review error messasges)" in
2385 if nonemptystr
s then s ^
" " ^
s1 else s1
2395 let len = Queue.length
state.tilelru
in
2397 match state.throttle
with
2400 then preloadlayout state.y
2402 | Some
(layout, _, _) ->
2406 if state.memused
<= conf.memlimit
2411 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2412 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2413 let (_, pw, ph
, _) = getpagedim n in
2416 && colorspace
= conf.colorspace
2417 && angle
= conf.angle
2421 let x = col*conf.tilew
2422 and y = row*conf.tileh
in
2423 tilevisible (Lazy.force_val
layout) n x y
2425 then Queue.push lruitem
state.tilelru
2428 wcmd "freetile %s" p
;
2429 state.memused
<- state.memused
- s;
2430 state.uioh#infochanged Memused
;
2431 Hashtbl.remove
state.tilemap k
;
2439 let logcurrently = function
2440 | Idle
-> dolog
"Idle"
2441 | Loading
(l, gen
) ->
2442 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2443 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2445 "Tiling %d[%d,%d] page=%s cs=%s angle"
2446 l.pageno col row pageopaque
2447 (CSTE.to_string colorspace
)
2449 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2450 angle gen
conf.angle
state.gen
2452 conf.tilew
conf.tileh
2459 let r = Str.regexp
" " in
2460 fun s -> Str.bounded_split
r s 2;
2463 let onpagerect pageno f =
2465 match conf.columns
with
2466 | Cmulti
(_, b) -> b
2468 | Csplit
(_, b) -> b
2470 if pageno >= 0 && pageno < Array.length
b
2472 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2476 let gotopagexy1 pageno x y =
2477 let _,w1,h1
,leftx
= getpagedim pageno in
2478 let top = y /. (float h1
) in
2479 let left = x /. (float w1) in
2480 let py, w, h = getpageywh pageno in
2481 let wh = state.winh
- hscrollh () in
2482 let x = left *. (float w) in
2483 let x = leftx
+ state.x + truncate
x in
2485 if x < 0 || x >= wadjsb state.winw
2489 let pdy = truncate
(top *. float h) in
2490 let y'
= py + pdy in
2491 let dy = y'
- state.y in
2493 if x != state.x || not
(dy > 0 && dy < wh)
2495 if conf.presentation
2497 if abs
(py - y'
) > wh
2504 if state.x != sx || state.y != sy
2509 let ww = wadjsb state.winw
in
2511 and qy
= pdy / wh in
2513 and y = py + qy
* wh in
2514 let x = if -x + ww > w1 then -(w1-ww) else x
2515 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2517 if conf.presentation
2519 if abs
(py - y'
) > wh
2529 gotoy_and_clear_text y;
2531 else gotoy_and_clear_text state.y;
2534 let gotopagexy pageno x y =
2535 match state.mode
with
2536 | Birdseye
_ -> gotopage pageno 0.0
2537 | _ -> gotopagexy1 pageno x y
2541 (* dolog "%S" cmds; *)
2542 let cl = splitatspace cmds
in
2544 try Scanf.sscanf
s fmt
f
2546 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2551 state.uioh#infochanged Pdim
;
2554 | "clearrects" :: [] ->
2555 state.rects
<- state.rects1
;
2556 G.postRedisplay "clearrects";
2558 | "continue" :: args :: [] ->
2559 let n = scan args "%u" (fun n -> n) in
2560 state.pagecount
<- n;
2561 begin match state.currently
with
2563 state.currently
<- Idle
;
2564 state.outlines
<- Array.of_list
(List.rev
l)
2568 let cur, cmds
= state.geomcmds
in
2570 then failwith
"umpossible";
2572 begin match List.rev cmds
with
2574 state.geomcmds
<- "", [];
2578 state.geomcmds
<- s, List.rev rest
;
2580 if conf.maxwait
= None
&& not
!wtmode
2581 then G.postRedisplay "continue";
2583 | "title" :: args :: [] ->
2586 | "msg" :: args :: [] ->
2589 | "vmsg" :: args :: [] ->
2591 then showtext ' '
args
2593 | "emsg" :: args :: [] ->
2594 Buffer.add_string
state.errmsgs
args;
2595 state.newerrmsgs
<- true;
2596 G.postRedisplay "error message"
2598 | "progress" :: args :: [] ->
2599 let progress, text =
2602 f, String.sub
args pos
(String.length
args - pos
))
2605 state.progress <- progress;
2606 G.postRedisplay "progress"
2608 | "firstmatch" :: args :: [] ->
2609 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2610 scan args "%u %d %f %f %f %f %f %f %f %f"
2611 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2612 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2614 let y = (getpagey pageno) + truncate
y0 in
2617 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2619 | "match" :: args :: [] ->
2620 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2621 scan args "%u %d %f %f %f %f %f %f %f %f"
2622 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2623 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2626 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2628 | "page" :: args :: [] ->
2629 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2630 begin match state.currently
with
2631 | Loading
(l, gen
) ->
2632 vlog "page %d took %f sec" l.pageno t
;
2633 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2634 begin match state.throttle
with
2636 let preloadedpages =
2638 then preloadlayout state.y
2643 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2644 IntSet.empty
preloadedpages
2647 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2648 if not
(IntSet.mem
pageno set)
2650 wcmd "freepage %s" opaque
;
2656 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2659 state.currently
<- Idle
;
2662 tilepage l.pageno pageopaque state.layout;
2664 load preloadedpages;
2665 if pagevisible state.layout l.pageno
2666 && layoutready state.layout
2667 then G.postRedisplay "page";
2670 | Some
(layout, _, _) ->
2671 state.currently
<- Idle
;
2672 tilepage l.pageno pageopaque layout;
2677 dolog
"Inconsistent loading state";
2678 logcurrently state.currently
;
2682 | "tile" :: args :: [] ->
2683 let (x, y, opaque
, size
, t
) =
2684 scan args "%u %u %s %u %f"
2685 (fun x y p size t
-> (x, y, p
, size
, t
))
2687 begin match state.currently
with
2688 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2689 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2692 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2694 wcmd "freetile %s" opaque
;
2695 state.currently
<- Idle
;
2699 puttileopaque l col row gen cs angle opaque size t
;
2700 state.memused
<- state.memused
+ size
;
2701 state.uioh#infochanged Memused
;
2703 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2704 opaque
, size
) state.tilelru
;
2707 match state.throttle
with
2708 | None
-> state.layout
2709 | Some
(layout, _, _) -> layout
2712 state.currently
<- Idle
;
2714 && conf.colorspace
= cs
2715 && conf.angle
= angle
2716 && tilevisible layout l.pageno x y
2717 then conttiling l.pageno pageopaque;
2719 begin match state.throttle
with
2721 preload state.layout;
2723 && conf.colorspace
= cs
2724 && conf.angle
= angle
2725 && tilevisible state.layout l.pageno x y
2726 && (not
!wtmode || layoutready state.layout)
2727 then G.postRedisplay "tile nothrottle";
2729 | Some
(layout, y, _) ->
2730 let ready = layoutready layout in
2734 state.layout <- layout;
2735 state.throttle
<- None
;
2736 G.postRedisplay "throttle";
2743 dolog
"Inconsistent tiling state";
2744 logcurrently state.currently
;
2748 | "pdim" :: args :: [] ->
2749 let (n, w, h, _) as pdim
=
2750 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2753 match conf.fitmodel
, conf.columns
with
2754 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2757 state.uioh#infochanged Pdim
;
2758 state.pdims
<- pdim :: state.pdims
2760 | "o" :: args :: [] ->
2761 let (l, n, t
, h, pos
) =
2762 scan args "%u %u %d %u %n"
2763 (fun l n t
h pos
-> l, n, t
, h, pos
)
2765 let s = String.sub
args pos
(String.length
args - pos
) in
2766 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2767 begin match state.currently
with
2768 | Outlining outlines
->
2769 state.currently
<- Outlining
(outline :: outlines
)
2771 state.currently
<- Outlining
[outline]
2773 dolog
"invalid outlining state";
2774 logcurrently currently
2777 | "a" :: args :: [] ->
2779 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2781 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2783 | "info" :: args :: [] ->
2784 state.docinfo
<- (1, args) :: state.docinfo
2786 | "infoend" :: [] ->
2787 state.uioh#infochanged Docinfo
;
2788 state.docinfo
<- List.rev
state.docinfo
2791 error
"unknown cmd `%S'" cmds
2796 let action = function
2797 | HCprev
-> cbget cb ~
-1
2798 | HCnext
-> cbget cb
1
2799 | HCfirst
-> cbget cb ~
-(cb
.rc)
2800 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2801 and cancel
() = cb
.rc <- rc
2805 let search pattern forward
=
2806 match conf.columns
with
2808 showtext '
!'
"searching does not work properly in split columns mode"
2810 if nonemptystr pattern
2813 match state.layout with
2816 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2818 wcmd "search %d %d %d %d,%s\000"
2819 (btod conf.icase
) pn py (btod forward
) pattern
;
2822 let intentry text key =
2824 if key >= 32 && key < 127
2830 let text = addchar text c in
2834 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2838 let linknentry text key =
2840 if key >= 32 && key < 127
2846 let text = addchar text c in
2850 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2858 let l = String.length
s in
2859 let rec loop pos
n = if pos
= l then n else
2860 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2861 loop (pos
+1) (n*26 + m)
2864 let rec loop n = function
2867 match getopaque l.pageno with
2868 | None
-> loop n rest
2870 let m = getlinkcount opaque
in
2873 let under = getlink opaque
n in
2876 else loop (n-m) rest
2878 loop n state.layout;
2882 let textentry text key =
2883 if key land 0xff00 = 0xff00
2885 else TEcont
(text ^ toutf8
key)
2888 let reqlayout angle fitmodel
=
2889 match state.throttle
with
2891 if nogeomcmds state.geomcmds
2892 then state.anchor <- getanchor ();
2893 conf.angle
<- angle
mod 360;
2896 match state.mode
with
2897 | LinkNav
_ -> state.mode
<- View
2900 conf.fitmodel
<- fitmodel
;
2901 invalidate "reqlayout"
2903 wcmd "reqlayout %d %d %d"
2904 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2909 let settrim trimmargins trimfuzz
=
2910 if nogeomcmds state.geomcmds
2911 then state.anchor <- getanchor ();
2912 conf.trimmargins
<- trimmargins
;
2913 conf.trimfuzz
<- trimfuzz
;
2914 let x0, y0, x1, y1 = trimfuzz
in
2915 invalidate "settrim"
2917 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2922 match state.throttle
with
2924 let zoom = max
0.0001 zoom in
2925 if zoom <> conf.zoom
2927 state.prevzoom
<- (conf.zoom, state.x);
2929 reshape state.winw
state.winh
;
2930 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2933 | Some
(layout, y, started
) ->
2935 match conf.maxwait
with
2939 let dt = now () -. started
in
2947 let setcolumns mode columns coverA coverB
=
2948 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2952 then showtext '
!'
"split mode doesn't work in bird's eye"
2954 conf.columns
<- Csplit
(-columns
, [||]);
2962 conf.columns
<- Csingle
[||];
2967 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2971 reshape state.winw
state.winh
;
2974 let enterbirdseye () =
2975 let zoom = float conf.thumbw
/. float state.winw
in
2976 let birdseyepageno =
2977 let cy = state.winh
/ 2 in
2981 let rec fold best
= function
2984 let d = cy - (l.pagedispy + l.pagevh/2)
2985 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2986 if abs
d < abs dbest
2993 state.mode
<- Birdseye
(
2994 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2997 conf.presentation
<- false;
2998 conf.interpagespace
<- 10;
2999 conf.hlinks
<- false;
3000 conf.fitmodel
<- FitProportional
;
3002 state.mstate
<- Mnone
;
3003 conf.maxwait
<- None
;
3005 match conf.beyecolumns
with
3008 Cmulti
((c, 0, 0), [||])
3009 | None
-> Csingle
[||]
3011 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3014 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3019 reshape state.winw
state.winh
;
3022 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3024 conf.zoom <- c.zoom;
3025 conf.presentation
<- c.presentation
;
3026 conf.interpagespace
<- c.interpagespace
;
3027 conf.maxwait
<- c.maxwait
;
3028 conf.hlinks
<- c.hlinks
;
3029 conf.fitmodel
<- c.fitmodel
;
3030 conf.beyecolumns
<- (
3031 match conf.columns
with
3032 | Cmulti
((c, _, _), _) -> Some
c
3034 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3037 match c.columns
with
3038 | Cmulti
(c, _) -> Cmulti
(c, [||])
3039 | Csingle
_ -> Csingle
[||]
3040 | Csplit
(c, _) -> Csplit
(c, [||])
3044 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3047 reshape state.winw
state.winh
;
3048 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3052 let togglebirdseye () =
3053 match state.mode
with
3054 | Birdseye vals
-> leavebirdseye vals
true
3055 | View
-> enterbirdseye ()
3059 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3060 let pageno = max
0 (pageno - incr
) in
3061 let rec loop = function
3062 | [] -> gotopage1 pageno 0
3063 | l :: _ when l.pageno = pageno ->
3064 if l.pagedispy >= 0 && l.pagey = 0
3065 then G.postRedisplay "upbirdseye"
3066 else gotopage1 pageno 0
3067 | _ :: rest
-> loop rest
3070 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3073 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3074 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3075 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3076 let rec loop = function
3078 let y, h = getpageyh pageno in
3079 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3081 | l :: _ when l.pageno = pageno ->
3082 if l.pagevh != l.pageh
3083 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3084 else G.postRedisplay "downbirdseye"
3085 | _ :: rest
-> loop rest
3090 let optentry mode
_ key =
3091 let btos b = if b then "on" else "off" in
3092 if key >= 32 && key < 127
3094 let c = Char.chr
key in
3098 try conf.scrollstep
<- int_of_string
s with exc
->
3099 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3101 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3106 conf.autoscrollstep
<- int_of_string
s;
3107 if state.autoscroll
<> None
3108 then state.autoscroll
<- Some
conf.autoscrollstep
3110 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3112 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3117 let n, a, b = multicolumns_of_string s in
3118 setcolumns mode
n a b;
3120 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3122 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3127 let zoom = float (int_of_string
s) /. 100.0 in
3130 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3132 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3137 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3139 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3140 begin match mode
with
3142 leavebirdseye beye
false;
3147 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3149 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3154 Some
(int_of_string
s)
3156 state.text <- Printf.sprintf
"bad integer `%s': %s"
3160 | Some angle
-> reqlayout angle
conf.fitmodel
3163 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3166 conf.icase
<- not
conf.icase
;
3167 TEdone
("case insensitive search " ^
(btos conf.icase
))
3170 conf.preload <- not
conf.preload;
3172 TEdone
("preload " ^
(btos conf.preload))
3175 conf.verbose
<- not
conf.verbose
;
3176 TEdone
("verbose " ^
(btos conf.verbose
))
3179 conf.debug
<- not
conf.debug
;
3180 TEdone
("debug " ^
(btos conf.debug
))
3183 conf.maxhfit
<- not
conf.maxhfit
;
3184 state.maxy
<- calcheight ();
3185 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3188 conf.crophack
<- not
conf.crophack
;
3189 TEdone
("crophack " ^
btos conf.crophack
)
3193 match conf.maxwait
with
3195 conf.maxwait
<- Some infinity
;
3196 "always wait for page to complete"
3198 conf.maxwait
<- None
;
3199 "show placeholder if page is not ready"
3204 conf.underinfo
<- not
conf.underinfo
;
3205 TEdone
("underinfo " ^
btos conf.underinfo
)
3208 conf.savebmarks
<- not
conf.savebmarks
;
3209 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3215 match state.layout with
3220 conf.interpagespace
<- int_of_string
s;
3221 docolumns conf.columns
;
3222 state.maxy
<- calcheight ();
3223 let y = getpagey pageno in
3226 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3228 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3232 match conf.fitmodel
with
3233 | FitProportional
-> FitWidth
3234 | _ -> FitProportional
3236 reqlayout conf.angle
fm;
3237 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3240 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3241 TEdone
("trim margins " ^
btos conf.trimmargins
)
3244 conf.invert
<- not
conf.invert
;
3245 TEdone
("invert colors " ^
btos conf.invert
)
3249 cbput state.hists
.sel
s;
3252 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3253 textentry, ondone, true)
3257 then conf.pax
<- Some
(ref (0.0, 0, 0))
3258 else conf.pax
<- None
;
3259 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3262 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3268 class type lvsource
= object
3269 method getitemcount
: int
3270 method getitem
: int -> (string * int)
3271 method hasaction
: int -> bool
3280 method getactive
: int
3281 method getfirst
: int
3282 method getqsearch
: string
3283 method setqsearch
: string -> unit
3287 class virtual lvsourcebase
= object
3288 val mutable m_active
= 0
3289 val mutable m_first
= 0
3290 val mutable m_qsearch
= ""
3291 val mutable m_pan
= 0
3292 method getactive
= m_active
3293 method getfirst
= m_first
3294 method getqsearch
= m_qsearch
3295 method getpan
= m_pan
3296 method setqsearch
s = m_qsearch
<- s
3299 let withoutlastutf8 s =
3300 let len = String.length
s in
3308 let b = Char.code
s.[pos
] in
3309 if b land 0b11000000 = 0b11000000
3314 if Char.code
s.[len-1] land 0x80 = 0
3318 String.sub
s 0 first;
3321 let textentrykeyboard
3322 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3324 if key >= 0xffb0 && key <= 0xffb9
3325 then key - 0xffb0 + 48 else key
3328 state.mode
<- Textentry
(te
, onleave
);
3331 G.postRedisplay "textentrykeyboard enttext";
3333 let histaction cmd
=
3336 | Some
(action, _) ->
3337 state.mode
<- Textentry
(
3338 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3340 G.postRedisplay "textentry histaction"
3343 | 0xff08 -> (* backspace *)
3344 if emptystr
text && cancelonempty
3347 G.postRedisplay "textentrykeyboard after cancel";
3350 let s = withoutlastutf8 text in
3351 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3353 | 0xff0d | 0xff8d -> (* (kp) enter *)
3356 G.postRedisplay "textentrykeyboard after confirm"
3358 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3359 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3360 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3361 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3363 | 0xff1b -> (* escape*)
3366 begin match opthist
with
3368 | Some
(_, onhistcancel
) -> onhistcancel
()
3372 G.postRedisplay "textentrykeyboard after cancel2"
3375 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3378 | 0xff9f | 0xffff -> () (* delete *)
3381 && key land 0xff00 != 0xff00 (* keyboard *)
3382 && key land 0xfe00 != 0xfe00 (* xkb *)
3383 && key land 0xfd00 != 0xfd00 (* 3270 *)
3385 begin match onkey
text key with
3389 G.postRedisplay "textentrykeyboard after confirm2";
3392 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3396 G.postRedisplay "textentrykeyboard after cancel3"
3399 state.mode
<- Textentry
(te
, onleave
);
3400 G.postRedisplay "textentrykeyboard switch";
3404 vlog "unhandled key %s" (Wsi.keyname
key)
3407 let firstof first active
=
3408 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3409 then max
0 (active
- (fstate.maxrows
/2))
3413 let calcfirst first active
=
3416 let rows = active
- first in
3417 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3421 let scrollph y maxy
=
3422 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3423 let sh = float state.winh
/. sh in
3424 let sh = max
sh (float conf.scrollh
) in
3426 let percent = float y /. float maxy
in
3427 let position = (float state.winh
-. sh) *. percent in
3430 if position +. sh > float state.winh
3431 then float state.winh
-. sh
3437 let coe s = (s :> uioh
);;
3439 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3441 val m_pan
= source#getpan
3442 val m_first
= source#getfirst
3443 val m_active
= source#getactive
3444 val m_qsearch
= source#getqsearch
3445 val m_prev_uioh
= state.uioh
3447 method private elemunder
y =
3448 let n = y / (fstate.fontsize
+1) in
3449 if m_first
+ n < source#getitemcount
3451 if source#hasaction
(m_first
+ n)
3452 then Some
(m_first
+ n)
3459 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3460 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3461 filledrect 0. 0. (float state.winw
) (float state.winh
);
3462 GlDraw.color
(1., 1., 1.);
3463 Gl.enable `texture_2d
;
3464 let fs = fstate.fontsize
in
3466 let ww = fstate.wwidth
in
3467 let tabw = 30.0*.ww in
3468 let itemcount = source#getitemcount
in
3470 if (row - m_first
) > fstate.maxrows
3473 if row >= 0 && row < itemcount
3475 let (s, level
) = source#getitem
row in
3476 let y = (row - m_first
) * nfs in
3477 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3480 Gl.disable `texture_2d
;
3481 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3482 GlDraw.color
(1., 1., 1.) ~
alpha;
3483 linerect 1. (float (y + 1))
3484 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3485 GlDraw.color
(1., 1., 1.);
3486 Gl.enable `texture_2d
;
3489 let drawtabularstring s =
3490 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3493 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3496 let len = String.length
s - tabpos - 1 in
3497 let s1 = String.sub
s 0 tabpos
3498 and s2
= String.sub
s (tabpos + 1) len in
3499 let nx = drawstr x s1 in
3501 let x = x +. (max
tabw sw) in
3508 let _ = drawtabularstring s in
3515 Gl.disable `texture_2d
;
3517 method updownlevel incr
=
3518 let len = source#getitemcount
in
3520 if m_active
>= 0 && m_active
< len
3521 then snd
(source#getitem m_active
)
3525 if i
= len then i
-1 else if i
= -1 then 0 else
3526 let _, l = source#getitem i
in
3527 if l != curlevel then i
else flow (i
+incr
)
3529 let active = flow m_active
in
3530 let first = calcfirst m_first
active in
3531 G.postRedisplay "outline updownlevel";
3532 {< m_active
= active; m_first
= first >}
3534 method private key1
key mask
=
3535 let set1 active first qsearch
=
3536 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3538 let search active pattern incr
=
3539 let active = if active = -1 then m_first
else active in
3542 if n >= 0 && n < source#getitemcount
3544 let s, _ = source#getitem
n in
3546 (try ignore
(Str.search_forward
re s 0); true
3547 with Not_found
-> false)
3549 else loop (n + incr
)
3556 let re = Str.regexp_case_fold pattern
in
3562 let itemcount = source#getitemcount
in
3563 let find start incr
=
3565 if i
= -1 || i
= itemcount
3568 if source#hasaction i
3570 else find (i
+ incr
)
3575 let set active first =
3576 let first = bound first 0 (itemcount - fstate.maxrows
) in
3578 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3581 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3583 let incr1 = if incr
> 0 then 1 else -1 in
3584 if isvisible m_first m_active
3587 let next = m_active
+ incr
in
3589 if next < 0 || next >= itemcount
3591 else find next incr1
3593 if abs
(m_active
- next) > fstate.maxrows
3599 let first = m_first
+ incr
in
3600 let first = bound first 0 (itemcount - fstate.maxrows
) in
3602 let next = m_active
+ incr
in
3603 let next = bound next 0 (itemcount - 1) in
3610 if isvisible first next
3617 let first = min
next m_first
in
3619 if abs
(next - first) > fstate.maxrows
3625 let first = m_first
+ incr
in
3626 let first = bound first 0 (itemcount - 1) in
3628 let next = m_active
+ incr
in
3629 let next = bound next 0 (itemcount - 1) in
3630 let next = find next incr1 in
3632 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3634 let active = if m_active
= -1 then next else m_active
in
3639 if isvisible first active
3645 G.postRedisplay "listview navigate";
3649 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3650 let incr = if key = 0x72 then -1 else 1 in
3652 match search (m_active
+ incr) m_qsearch
incr with
3654 state.text <- m_qsearch ^
" [not found]";
3657 state.text <- m_qsearch
;
3658 active, firstof m_first
active
3660 G.postRedisplay "listview ctrl-r/s";
3661 set1 active first m_qsearch
;
3663 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3664 if m_active
>= 0 && m_active
< source#getitemcount
3666 let s, _ = source#getitem m_active
in
3671 | 0xff08 -> (* backspace *)
3672 if emptystr m_qsearch
3675 let qsearch = withoutlastutf8 m_qsearch
in
3679 G.postRedisplay "listview empty qsearch";
3680 set1 m_active m_first
"";
3684 match search m_active
qsearch ~
-1 with
3686 state.text <- qsearch ^
" [not found]";
3689 state.text <- qsearch;
3690 active, firstof m_first
active
3692 G.postRedisplay "listview backspace qsearch";
3693 set1 active first qsearch
3696 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3697 let pattern = m_qsearch ^ toutf8
key in
3699 match search m_active
pattern 1 with
3701 state.text <- pattern ^
" [not found]";
3704 state.text <- pattern;
3705 active, firstof m_first
active
3707 G.postRedisplay "listview qsearch add";
3708 set1 active first pattern;
3710 | 0xff1b -> (* escape *)
3712 if emptystr m_qsearch
3714 G.postRedisplay "list view escape";
3717 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3719 | None
-> m_prev_uioh
3724 G.postRedisplay "list view kill qsearch";
3725 source#setqsearch
"";
3726 coe {< m_qsearch
= "" >}
3729 | 0xff0d | 0xff8d -> (* (kp) enter *)
3731 let self = {< m_qsearch
= "" >} in
3732 source#setqsearch
"";
3734 G.postRedisplay "listview enter";
3735 if m_active
>= 0 && m_active
< source#getitemcount
3737 source#exit
(coe self) false m_active m_first m_pan
"";
3740 source#exit
(coe self) true m_active m_first m_pan
"";
3743 begin match opt with
3744 | None
-> m_prev_uioh
3748 | 0xff9f | 0xffff -> (* (kp) delete *)
3751 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3752 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3753 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3754 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3756 | 0xff53 | 0xff98 -> (* (kp) right *)
3758 G.postRedisplay "listview right";
3759 coe {< m_pan
= m_pan
- 1 >}
3761 | 0xff51 | 0xff96 -> (* (kp) left *)
3763 G.postRedisplay "listview left";
3764 coe {< m_pan
= m_pan
+ 1 >}
3766 | 0xff50 | 0xff95 -> (* (kp) home *)
3767 let active = find 0 1 in
3768 G.postRedisplay "listview home";
3771 | 0xff57 | 0xff9c -> (* (kp) end *)
3772 let first = max
0 (itemcount - fstate.maxrows
) in
3773 let active = find (itemcount - 1) ~
-1 in
3774 G.postRedisplay "listview end";
3777 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3781 dolog
"listview unknown key %#x" key; coe self
3783 method key key mask
=
3784 match state.mode
with
3785 | Textentry te
-> textentrykeyboard key mask te
; coe self
3786 | _ -> self#key1
key mask
3788 method button button down
x y _ =
3791 | 1 when x > state.winw
- conf.scrollbw
->
3792 G.postRedisplay "listview scroll";
3795 let _, position, sh = self#
scrollph in
3796 if y > truncate
position && y < truncate
(position +. sh)
3798 state.mstate
<- Mscrolly
;
3802 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3803 let first = truncate
(s *. float source#getitemcount
) in
3804 let first = min source#getitemcount
first in
3805 Some
(coe {< m_first
= first; m_active
= first >})
3807 state.mstate
<- Mnone
;
3810 | 1 when not down
->
3811 begin match self#elemunder
y with
3813 G.postRedisplay "listview click";
3815 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3819 | n when (n == 4 || n == 5) && not down
->
3820 let len = source#getitemcount
in
3822 if n = 5 && m_first
+ fstate.maxrows
>= len
3826 let first = m_first
+ (if n == 4 then -1 else 1) in
3827 bound first 0 (len - 1)
3829 G.postRedisplay "listview wheel";
3830 Some
(coe {< m_first
= first >})
3831 | n when (n = 6 || n = 7) && not down
->
3832 let inc = if n = 7 then -1 else 1 in
3833 G.postRedisplay "listview hwheel";
3834 Some
(coe {< m_pan
= m_pan
+ inc >})
3839 | None
-> m_prev_uioh
3843 match state.mstate
with
3845 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3846 let first = truncate
(s *. float source#getitemcount
) in
3847 let first = min source#getitemcount
first in
3848 G.postRedisplay "listview motion";
3849 coe {< m_first
= first; m_active
= first >}
3852 method pmotion
x y =
3853 if x < state.winw
- conf.scrollbw
3856 match self#elemunder
y with
3857 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3858 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3862 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3867 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3871 method infochanged
_ = ()
3873 method scrollpw
= (0, 0.0, 0.0)
3875 let nfs = fstate.fontsize
+ 1 in
3876 let y = m_first
* nfs in
3877 let itemcount = source#getitemcount
in
3878 let maxi = max
0 (itemcount - fstate.maxrows
) in
3879 let maxy = maxi * nfs in
3880 let p, h = scrollph y maxy in
3883 method modehash
= modehash
3884 method eformsgs
= false
3887 class outlinelistview ~source
=
3888 let settext autonarrow
s =
3890 then state.text <- "[" ^
s ^
"]"
3891 else state.text <- s
3895 ~source
:(source
:> lvsource
)
3897 ~modehash
:(findkeyhash conf "outline")
3900 val m_autonarrow
= false
3902 method key key mask
=
3904 if emptystr
state.text
3906 else fstate.maxrows - 2
3908 let calcfirst first active =
3911 let rows = active - first in
3912 if rows > maxrows then active - maxrows else first
3916 let active = m_active
+ incr in
3917 let active = bound active 0 (source#getitemcount
- 1) in
3918 let first = calcfirst m_first
active in
3919 G.postRedisplay "outline navigate";
3920 coe {< m_active
= active; m_first
= first >}
3922 let navscroll first =
3924 let dist = m_active
- first in
3930 else first + maxrows
3933 G.postRedisplay "outline navscroll";
3934 coe {< m_first
= first; m_active
= active >}
3936 let ctrl = Wsi.withctrl mask
in
3938 | 97 when ctrl -> (* ctrl-a *)
3940 then source#denarrow
3941 else source#narrow m_qsearch
;
3942 settext (not m_autonarrow
) m_qsearch
;
3943 G.postRedisplay "toggle auto narrowing";
3944 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3946 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3948 G.postRedisplay "toggle auto narrowing";
3949 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3951 | 110 when ctrl -> (* ctrl-n *)
3952 source#narrow m_qsearch
;
3954 then source#add_narrow_pattern m_qsearch
;
3955 G.postRedisplay "outline ctrl-n";
3956 coe {< m_first
= 0; m_active
= 0 >}
3958 | 117 when ctrl -> (* ctrl-u *)
3959 source#del_narrow_pattern
;
3960 let pattern = source#renarrow
in
3961 G.postRedisplay "outline ctrl-u";
3963 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3965 settext m_autonarrow
text;
3966 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3968 | 108 when ctrl -> (* ctrl-l *)
3969 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3970 G.postRedisplay "outline ctrl-l";
3971 coe {< m_first
= first >}
3973 | 0xff1b -> (* escape *)
3974 let o = super#
key key mask
in
3977 if nonemptystr m_qsearch
3979 source#add_narrow_pattern m_qsearch
;
3985 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3986 if nonemptystr m_qsearch
3987 then source#add_narrow_pattern m_qsearch
;
3990 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3991 let pattern = m_qsearch ^ toutf8
key in
3992 G.postRedisplay "outlinelistview autonarrow add";
3993 source#narrow
pattern;
3994 settext true pattern;
3995 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3997 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3998 if emptystr m_qsearch
4001 let pattern = withoutlastutf8 m_qsearch
in
4002 G.postRedisplay "outlinelistview autonarrow backspace";
4003 ignore
(source#renarrow
);
4004 source#narrow
pattern;
4005 settext true pattern;
4006 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4008 | 0xff9f | 0xffff -> (* (kp) delete *)
4009 source#remove m_active
;
4010 G.postRedisplay "outline delete";
4011 let active = max
0 (m_active
-1) in
4012 coe {< m_first
= firstof m_first
active;
4013 m_active
= active >}
4015 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4016 navscroll (max
0 (m_first
- 1))
4018 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4019 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4021 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4022 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4023 | 0xff55 | 0xff9a -> (* (kp) prior *)
4024 navigate ~
-(fstate.maxrows)
4025 | 0xff56 | 0xff9b -> (* (kp) next *)
4026 navigate fstate.maxrows
4028 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4032 G.postRedisplay "outline ctrl right";
4033 {< m_pan
= m_pan
+ 1 >}
4035 else self#updownlevel
1
4039 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4043 G.postRedisplay "outline ctrl left";
4044 {< m_pan
= m_pan
- 1 >}
4046 else self#updownlevel ~
-1
4050 | 0xff50 | 0xff95 -> (* (kp) home *)
4051 G.postRedisplay "outline home";
4052 coe {< m_first
= 0; m_active
= 0 >}
4054 | 0xff57 | 0xff9c -> (* (kp) end *)
4055 let active = source#getitemcount
- 1 in
4056 let first = max
0 (active - fstate.maxrows) in
4057 G.postRedisplay "outline end";
4058 coe {< m_active
= active; m_first
= first >}
4060 | _ -> super#
key key mask
4063 let outlinesource usebookmarks
=
4066 inherit lvsourcebase
4067 val mutable m_items
= empty
4068 val mutable m_orig_items
= empty
4069 val mutable m_narrow_patterns
= []
4070 val mutable m_hadremovals
= false
4072 method getitemcount
=
4073 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4076 if n == Array.length m_items
&& m_hadremovals
4078 ("[Confirm removal]", 0)
4080 let s, n, _ = m_items
.(n) in
4083 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4084 ignore
(uioh
, first, qsearch);
4085 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4087 if m_narrow_patterns
= []
4093 if not
confrimremoval
4095 let _, _, ((pageno, y, _) as anchor) = m_items
.(active) in
4097 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4103 state.bookmarks
<- Array.to_list m_items
;
4104 m_orig_items
<- m_items
;
4107 else m_items
<- items;
4111 method hasaction
_ = true
4114 if Array.length m_items
!= Array.length m_orig_items
4117 match m_narrow_patterns
with
4119 | many
-> String.concat
" --> " (List.rev many
)
4121 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4124 method narrow
pattern =
4125 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4129 let rec loop accu n =
4131 then m_items
<- Array.of_list
accu
4133 let (s, _, _) as o = m_items
.(n) in
4135 if (try ignore
(Str.search_forward
re s 0); true
4136 with Not_found
-> false)
4142 loop [] (Array.length m_items
- 1)
4147 then Array.of_list
state.bookmarks
4150 m_items
<- m_orig_items
4155 if m >= 0 && m < Array.length m_items
4157 m_hadremovals
<- true;
4158 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4159 let n = if n >= m then n+1 else n in
4164 method add_narrow_pattern
pattern =
4165 m_narrow_patterns
<- pattern :: m_narrow_patterns
4167 method del_narrow_pattern
=
4168 match m_narrow_patterns
with
4169 | _ :: rest
-> m_narrow_patterns
<- rest
4174 match m_narrow_patterns
with
4175 | pattern :: [] -> self#narrow
pattern; pattern
4177 List.fold_left
(fun accu pattern ->
4178 self#narrow
pattern;
4179 accu ^
" --> " ^
pattern) "" list
4181 method reset
anchor items =
4182 m_hadremovals
<- false;
4183 if m_orig_items
== empty
4185 m_orig_items
<- items;
4186 if m_narrow_patterns
== []
4187 then m_items
<- items;
4189 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
4205 m_first
<- firstof m_first
active
4209 let enterselector usebookmarks
=
4210 let source = outlinesource usebookmarks
in
4214 then Array.of_list
state.bookmarks
4217 if Array.length
outlines = 0
4219 showtext ' ' errmsg
;
4222 state.text <- source#greetmsg
;
4223 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4224 let anchor = getanchor () in
4225 source#reset
anchor outlines;
4226 state.uioh
<- coe (new outlinelistview ~
source);
4227 G.postRedisplay "enter selector";
4231 let enteroutlinemode =
4232 let f = enterselector false in
4233 fun ()-> f "Document has no outline";
4236 let enterbookmarkmode =
4237 let f = enterselector true in
4238 fun () -> f "Document has no bookmarks (yet)";
4241 let color_of_string s =
4242 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4243 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4247 let color_to_string (r, g, b) =
4248 let r = truncate
(r *. 256.0)
4249 and g = truncate
(g *. 256.0)
4250 and b = truncate
(b *. 256.0) in
4251 Printf.sprintf
"%d/%d/%d" r g b
4254 let irect_of_string s =
4255 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4258 let irect_to_string (x0,y0,x1,y1) =
4259 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4262 let makecheckers () =
4263 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4265 converted by Issac Trotts. July 25, 2002 *)
4266 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4267 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4268 let id = GlTex.gen_texture
() in
4269 GlTex.bind_texture `texture_2d
id;
4270 GlPix.store
(`unpack_alignment
1);
4271 GlTex.image2d
image;
4272 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4273 [ `mag_filter `nearest
; `min_filter `nearest
];
4277 let setcheckers enabled
=
4278 match state.texid
with
4280 if enabled
then state.texid
<- Some
(makecheckers ())
4285 GlTex.delete_texture texid
;
4286 state.texid
<- None
;
4290 let int_of_string_with_suffix s =
4291 let l = String.length
s in
4295 let suffix = Char.lowercase
s.[l-1] in
4297 | 'k'
-> String.sub
s 0 (l-1), 10
4298 | '
m'
-> String.sub
s 0 (l-1), 20
4299 | '
g'
-> String.sub
s 0 (l-1), 30
4303 let n = int_of_string
s1 in
4304 let m = n lsl shift
in
4306 then raise
(Failure
"value too large")
4310 let string_with_suffix_of_int n =
4314 let units = [(30, "G"); (20, "M"); (10, "K")] in
4317 let h = n mod 1000 in
4320 then string_of_int
h ^
s
4322 let s = Printf.sprintf
"_%03d%s" h s in
4328 let rec find = function
4330 | (shift
, suffix) :: rest
->
4331 if (n land ((1 lsl shift
) - 1)) = 0
4332 then prettyint (n lsr shift
) ^
suffix
4338 let defghyllscroll = (40, 8, 32);;
4339 let fastghyllscroll = (5,1,2);;
4340 let neatghyllscroll = (10,1,9);;
4341 let ghyllscroll_of_string s =
4343 | "default" -> Some
defghyllscroll
4344 | "fast" -> Some
(5,1,2)
4345 | "neat" -> Some
(10,1,9)
4346 | "" | "none" -> None
4348 let (n,a,b) as nab
=
4349 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4350 if n <= a || n <= b || a >= b
4351 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4356 let ghyllscroll_to_string ((n, a, b) as nab
) =
4357 (**) if nab
= defghyllscroll then "default"
4358 else if nab
= fastghyllscroll then "fast"
4359 else if nab
= neatghyllscroll then "neat"
4360 else Printf.sprintf
"%d,%d,%d" n a b;
4363 let describe_location () =
4364 let fn = page_of_y state.y in
4365 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4366 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4370 else (100. *. (float state.y /. float maxy))
4374 Printf.sprintf
"page %d of %d [%.2f%%]"
4375 (fn+1) state.pagecount
percent
4378 "pages %d-%d of %d [%.2f%%]"
4379 (fn+1) (ln+1) state.pagecount
percent
4382 let setpresentationmode v
=
4383 let n = page_of_y state.y in
4384 state.anchor <- (n, 0.0, 1.0);
4385 conf.presentation
<- v
;
4386 if conf.fitmodel
= FitPage
4387 then reqlayout conf.angle
conf.fitmodel
;
4392 let btos b = if b then "\xe2\x88\x9a" else "" in
4393 let showextended = ref false in
4394 let leave mode
= function
4395 | Confirm
-> state.mode
<- mode
4396 | Cancel
-> state.mode
<- mode
in
4399 val mutable m_first_time
= true
4400 val mutable m_l
= []
4401 val mutable m_a
= [||]
4402 val mutable m_prev_uioh
= nouioh
4403 val mutable m_prev_mode
= View
4405 inherit lvsourcebase
4407 method reset prev_mode prev_uioh
=
4408 m_a
<- Array.of_list
(List.rev m_l
);
4410 m_prev_mode
<- prev_mode
;
4411 m_prev_uioh
<- prev_uioh
;
4415 if n >= Array.length m_a
4419 | _, _, _, Action
_ -> m_active
<- n
4423 m_first_time
<- false;
4426 method int name get
set =
4428 (name, `
int get
, 1, Action
(
4431 try set (int_of_string
s)
4433 state.text <- Printf.sprintf
"bad integer `%s': %s"
4437 let te = name ^
": ", "", None
, intentry, ondone, true in
4438 state.mode
<- Textentry
(te, leave m_prev_mode
);
4442 method int_with_suffix
name get
set =
4444 (name, `intws get
, 1, Action
(
4447 try set (int_of_string_with_suffix s)
4449 state.text <- Printf.sprintf
"bad integer `%s': %s"
4454 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4456 state.mode
<- Textentry
(te, leave m_prev_mode
);
4460 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4462 (name, `
bool (btos, get
), offset
, Action
(
4469 method color
name get
set =
4471 (name, `color get
, 1, Action
(
4473 let invalid = (nan
, nan
, nan
) in
4476 try color_of_string s
4478 state.text <- Printf.sprintf
"bad color `%s': %s"
4485 let te = name ^
": ", "", None
, textentry, ondone, true in
4486 state.text <- color_to_string (get
());
4487 state.mode
<- Textentry
(te, leave m_prev_mode
);
4491 method string name get
set =
4493 (name, `
string get
, 1, Action
(
4495 let ondone s = set s in
4496 let te = name ^
": ", "", None
, textentry, ondone, true in
4497 state.mode
<- Textentry
(te, leave m_prev_mode
);
4501 method colorspace
name get
set =
4503 (name, `
string get
, 1, Action
(
4507 inherit lvsourcebase
4510 m_active
<- CSTE.to_int conf.colorspace
;
4513 method getitemcount
=
4514 Array.length
CSTE.names
4517 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4518 ignore
(uioh
, first, pan
, qsearch);
4519 if not cancel
then set active;
4521 method hasaction
_ = true
4525 let modehash = findkeyhash conf "info" in
4526 coe (new listview ~
source ~trusted
:true ~
modehash)
4529 method paxmark
name get
set =
4531 (name, `
string get
, 1, Action
(
4535 inherit lvsourcebase
4538 m_active
<- MTE.to_int conf.paxmark
;
4541 method getitemcount
= Array.length
MTE.names
4542 method getitem
n = (MTE.names.(n), 0)
4543 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4544 ignore
(uioh
, first, pan
, qsearch);
4545 if not cancel
then set active;
4547 method hasaction
_ = true
4551 let modehash = findkeyhash conf "info" in
4552 coe (new listview ~
source ~trusted
:true ~
modehash)
4555 method fitmodel
name get
set =
4557 (name, `
string get
, 1, Action
(
4561 inherit lvsourcebase
4564 m_active
<- FMTE.to_int conf.fitmodel
;
4567 method getitemcount
= Array.length
FMTE.names
4568 method getitem
n = (FMTE.names.(n), 0)
4569 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4570 ignore
(uioh
, first, pan
, qsearch);
4571 if not cancel
then set active;
4573 method hasaction
_ = true
4577 let modehash = findkeyhash conf "info" in
4578 coe (new listview ~
source ~trusted
:true ~
modehash)
4581 method caption
s offset
=
4582 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4584 method caption2
s f offset
=
4585 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4587 method getitemcount
= Array.length m_a
4590 let tostr = function
4591 | `
int f -> string_of_int
(f ())
4592 | `intws
f -> string_with_suffix_of_int (f ())
4594 | `color
f -> color_to_string (f ())
4595 | `
bool (btos, f) -> btos (f ())
4598 let name, t
, offset
, _ = m_a
.(n) in
4599 ((let s = tostr t
in
4601 then Printf.sprintf
"%s\t%s" name s
4605 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4609 m_qsearch
<- qsearch;
4611 match m_a
.(active) with
4612 | _, _, _, Action
f -> f uioh
4624 method hasaction
n =
4626 | _, _, _, Action
_ -> true
4630 let rec fillsrc prevmode prevuioh
=
4631 let sep () = src#caption
"" 0 in
4632 let colorp name get
set =
4634 (fun () -> color_to_string (get
()))
4637 let c = color_of_string v in
4640 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4643 let oldmode = state.mode
in
4644 let birdseye = isbirdseye state.mode
in
4646 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4648 src#
bool "presentation mode"
4649 (fun () -> conf.presentation
)
4650 (fun v -> setpresentationmode v);
4652 src#
bool "ignore case in searches"
4653 (fun () -> conf.icase
)
4654 (fun v -> conf.icase
<- v);
4657 (fun () -> conf.preload)
4658 (fun v -> conf.preload <- v);
4660 src#
bool "highlight links"
4661 (fun () -> conf.hlinks
)
4662 (fun v -> conf.hlinks
<- v);
4664 src#
bool "under info"
4665 (fun () -> conf.underinfo
)
4666 (fun v -> conf.underinfo
<- v);
4668 src#
bool "persistent bookmarks"
4669 (fun () -> conf.savebmarks
)
4670 (fun v -> conf.savebmarks
<- v);
4672 src#fitmodel
"fit model"
4673 (fun () -> FMTE.to_string conf.fitmodel
)
4674 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4676 src#
bool "trim margins"
4677 (fun () -> conf.trimmargins
)
4678 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4680 src#
bool "persistent location"
4681 (fun () -> conf.jumpback
)
4682 (fun v -> conf.jumpback
<- v);
4685 src#
int "inter-page space"
4686 (fun () -> conf.interpagespace
)
4688 conf.interpagespace
<- n;
4689 docolumns conf.columns
;
4691 match state.layout with
4696 state.maxy <- calcheight ();
4697 let y = getpagey pageno in
4702 (fun () -> conf.pagebias
)
4703 (fun v -> conf.pagebias
<- v);
4705 src#
int "scroll step"
4706 (fun () -> conf.scrollstep
)
4707 (fun n -> conf.scrollstep
<- n);
4709 src#
int "horizontal scroll step"
4710 (fun () -> conf.hscrollstep
)
4711 (fun v -> conf.hscrollstep
<- v);
4713 src#
int "auto scroll step"
4715 match state.autoscroll
with
4717 | _ -> conf.autoscrollstep
)
4719 if state.autoscroll
<> None
4720 then state.autoscroll
<- Some
n;
4721 conf.autoscrollstep
<- n);
4724 (fun () -> truncate
(conf.zoom *. 100.))
4725 (fun v -> setzoom ((float v) /. 100.));
4728 (fun () -> conf.angle
)
4729 (fun v -> reqlayout v conf.fitmodel
);
4731 src#
int "scroll bar width"
4732 (fun () -> conf.scrollbw
)
4735 reshape state.winw
state.winh
;
4738 src#
int "scroll handle height"
4739 (fun () -> conf.scrollh
)
4740 (fun v -> conf.scrollh
<- v;);
4742 src#
int "thumbnail width"
4743 (fun () -> conf.thumbw
)
4745 conf.thumbw
<- min
4096 v;
4748 leavebirdseye beye
false;
4753 let mode = state.mode in
4754 src#
string "columns"
4756 match conf.columns
with
4758 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4759 | Csplit
(count
, _) -> "-" ^ string_of_int count
4762 let n, a, b = multicolumns_of_string v in
4763 setcolumns mode n a b);
4766 src#caption
"Pixmap cache" 0;
4767 src#int_with_suffix
"size (advisory)"
4768 (fun () -> conf.memlimit
)
4769 (fun v -> conf.memlimit
<- v);
4772 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4773 (string_with_suffix_of_int state.memused
)
4774 (Hashtbl.length
state.tilemap
)) 1;
4777 src#caption
"Layout" 0;
4778 src#caption2
"Dimension"
4780 Printf.sprintf
"%dx%d (virtual %dx%d)"
4781 state.winw
state.winh
4786 src#caption2
"Position" (fun () ->
4787 Printf.sprintf
"%dx%d" state.x state.y
4790 src#caption2
"Position" (fun () -> describe_location ()) 1
4794 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4795 "Save these parameters as global defaults at exit"
4796 (fun () -> conf.bedefault
)
4797 (fun v -> conf.bedefault
<- v)
4801 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4802 src#
bool ~offset
:0 ~
btos "Extended parameters"
4803 (fun () -> !showextended)
4804 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4808 (fun () -> conf.checkers
)
4809 (fun v -> conf.checkers
<- v; setcheckers v);
4810 src#
bool "update cursor"
4811 (fun () -> conf.updatecurs
)
4812 (fun v -> conf.updatecurs
<- v);
4814 (fun () -> conf.verbose
)
4815 (fun v -> conf.verbose
<- v);
4816 src#
bool "invert colors"
4817 (fun () -> conf.invert
)
4818 (fun v -> conf.invert
<- v);
4820 (fun () -> conf.maxhfit
)
4821 (fun v -> conf.maxhfit
<- v);
4822 src#
bool "redirect stderr"
4823 (fun () -> conf.redirectstderr)
4824 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4826 (fun () -> conf.pax
!= None
)
4829 then conf.pax
<- Some
(ref (now (), 0, 0))
4830 else conf.pax
<- None
);
4831 src#
string "uri launcher"
4832 (fun () -> conf.urilauncher
)
4833 (fun v -> conf.urilauncher
<- v);
4834 src#
string "path launcher"
4835 (fun () -> conf.pathlauncher
)
4836 (fun v -> conf.pathlauncher
<- v);
4837 src#
string "tile size"
4838 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4841 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4842 conf.tilew
<- max
64 w;
4843 conf.tileh
<- max
64 h;
4846 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4849 src#
int "texture count"
4850 (fun () -> conf.texcount
)
4853 then conf.texcount
<- v
4854 else showtext '
!'
" Failed to set texture count please retry later"
4856 src#
int "slice height"
4857 (fun () -> conf.sliceheight
)
4859 conf.sliceheight
<- v;
4860 wcmd "sliceh %d" conf.sliceheight
;
4862 src#
int "anti-aliasing level"
4863 (fun () -> conf.aalevel
)
4865 conf.aalevel
<- bound v 0 8;
4866 state.anchor <- getanchor ();
4867 opendoc state.path
state.password
;
4869 src#
string "page scroll scaling factor"
4870 (fun () -> string_of_float
conf.pgscale)
4873 let s = float_of_string
v in
4876 state.text <- Printf.sprintf
4877 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4880 src#
int "ui font size"
4881 (fun () -> fstate.fontsize
)
4882 (fun v -> setfontsize (bound v 5 100));
4883 src#
int "hint font size"
4884 (fun () -> conf.hfsize
)
4885 (fun v -> conf.hfsize
<- bound v 5 100);
4886 colorp "background color"
4887 (fun () -> conf.bgcolor
)
4888 (fun v -> conf.bgcolor
<- v);
4889 src#
bool "crop hack"
4890 (fun () -> conf.crophack
)
4891 (fun v -> conf.crophack
<- v);
4892 src#
string "trim fuzz"
4893 (fun () -> irect_to_string conf.trimfuzz
)
4896 conf.trimfuzz
<- irect_of_string v;
4898 then settrim true conf.trimfuzz
;
4900 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4902 src#
string "throttle"
4904 match conf.maxwait
with
4905 | None
-> "show place holder if page is not ready"
4908 then "wait for page to fully render"
4910 "wait " ^ string_of_float
time
4911 ^
" seconds before showing placeholder"
4915 let f = float_of_string
v in
4917 then conf.maxwait
<- None
4918 else conf.maxwait
<- Some
f
4920 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4922 src#
string "ghyll scroll"
4924 match conf.ghyllscroll
with
4926 | Some nab
-> ghyllscroll_to_string nab
4929 try conf.ghyllscroll
<- ghyllscroll_of_string v
4931 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4933 src#
string "selection command"
4934 (fun () -> conf.selcmd
)
4935 (fun v -> conf.selcmd
<- v);
4936 src#
string "synctex command"
4937 (fun () -> conf.stcmd
)
4938 (fun v -> conf.stcmd
<- v);
4939 src#
string "pax command"
4940 (fun () -> conf.paxcmd
)
4941 (fun v -> conf.paxcmd
<- v);
4942 src#colorspace
"color space"
4943 (fun () -> CSTE.to_string conf.colorspace
)
4945 conf.colorspace
<- CSTE.of_int v;
4949 src#paxmark
"pax mark method"
4950 (fun () -> MTE.to_string conf.paxmark
)
4951 (fun v -> conf.paxmark
<- MTE.of_int v);
4955 (fun () -> conf.usepbo
)
4956 (fun v -> conf.usepbo
<- v);
4957 src#
bool "mouse wheel scrolls pages"
4958 (fun () -> conf.wheelbypage
)
4959 (fun v -> conf.wheelbypage
<- v);
4960 src#
bool "open remote links in a new instance"
4961 (fun () -> conf.riani
)
4962 (fun v -> conf.riani
<- v);
4966 src#caption
"Document" 0;
4967 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4968 src#caption2
"Pages"
4969 (fun () -> string_of_int
state.pagecount
) 1;
4970 src#caption2
"Dimensions"
4971 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4975 src#caption
"Trimmed margins" 0;
4976 src#caption2
"Dimensions"
4977 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4981 src#caption
"OpenGL" 0;
4982 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4983 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4986 src#caption
"Location" 0;
4987 if nonemptystr
state.origin
4988 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4989 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4991 src#reset prevmode prevuioh
;
4995 let prevmode = state.mode
4996 and prevuioh
= state.uioh in
4997 fillsrc prevmode prevuioh
;
4998 let source = (src :> lvsource
) in
4999 let modehash = findkeyhash conf "info" in
5000 state.uioh <- coe (object (self)
5001 inherit listview ~
source ~trusted
:true ~
modehash as super
5002 val mutable m_prevmemused
= 0
5003 method infochanged
= function
5005 if m_prevmemused
!= state.memused
5007 m_prevmemused
<- state.memused
;
5008 G.postRedisplay "memusedchanged";
5010 | Pdim
-> G.postRedisplay "pdimchanged"
5011 | Docinfo
-> fillsrc prevmode prevuioh
5013 method key key mask
=
5014 if not
(Wsi.withctrl mask
)
5017 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5018 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5019 | _ -> super#
key key mask
5020 else super#
key key mask
5022 G.postRedisplay "info";
5028 inherit lvsourcebase
5029 method getitemcount
= Array.length
state.help
5031 let s, l, _ = state.help
.(n) in
5034 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5038 m_qsearch
<- qsearch;
5039 match state.help
.(active) with
5040 | _, _, Action
f -> Some
(f uioh)
5050 method hasaction
n =
5051 match state.help
.(n) with
5052 | _, _, Action
_ -> true
5059 let modehash = findkeyhash conf "help" in
5060 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5061 G.postRedisplay "help";
5066 let re = Str.regexp
"[\r\n]" in
5068 inherit lvsourcebase
5069 val mutable m_items
= [||]
5071 method getitemcount
= 1 + Array.length m_items
5076 else m_items
.(n-1), 0
5078 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5083 then Buffer.clear
state.errmsgs
;
5084 m_qsearch
<- qsearch;
5091 method hasaction
n =
5095 state.newerrmsgs
<- false;
5096 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5097 m_items
<- Array.of_list
l
5105 let source = (msgsource :> lvsource
) in
5106 let modehash = findkeyhash conf "listview" in
5107 state.uioh <- coe (object
5108 inherit listview ~
source ~trusted
:false ~
modehash as super
5111 then msgsource#reset
;
5114 G.postRedisplay "msgs";
5117 let quickbookmark ?title
() =
5118 match state.layout with
5124 let sec = Unix.gettimeofday
() in
5125 let tm = Unix.localtime
sec in
5126 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5130 (tm.Unix.tm_year
+ 1900)
5133 | Some
title -> title
5135 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5138 let setautoscrollspeed step goingdown
=
5139 let incr = max
1 ((abs step
) / 2) in
5140 let incr = if goingdown
then incr else -incr in
5141 let astep = step
+ incr in
5142 state.autoscroll
<- Some
astep;
5145 let gotounder under =
5146 let getpath filename
=
5148 if nonemptystr filename
5150 if Filename.is_relative filename
5152 let dir = Filename.dirname
state.path in
5154 if Filename.is_implicit
dir
5155 then Filename.concat
(Sys.getcwd
()) dir
5158 Filename.concat
dir filename
5162 if Sys.file_exists
path
5167 | Ulinkgoto
(pageno, top) ->
5171 gotopage1 pageno top;
5177 | Uremote
(filename
, pageno) ->
5178 let path = getpath filename
in
5183 let command = !selfexec ^
" " ^
path in
5184 try popen command []
5187 "failed to execute `%s': %s\n" command (exntos exn
);
5190 let anchor = getanchor () in
5191 let ranchor = state.path, state.password
, anchor, state.origin
in
5193 state.anchor <- (pageno, 0.0, 0.0);
5194 state.ranchors
<- ranchor :: state.ranchors
;
5197 else showtext '
!'
("Could not find " ^ filename
)
5199 | Uremotedest
(filename
, destname
) ->
5200 let path = getpath filename
in
5205 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
5206 try popen command []
5209 "failed to execute `%s': %s\n" command (exntos exn
);
5212 let anchor = getanchor () in
5213 let ranchor = state.path, state.password
, anchor, state.origin
in
5215 state.nameddest
<- destname
;
5216 state.ranchors
<- ranchor :: state.ranchors
;
5219 else showtext '
!'
("Could not find " ^ filename
)
5221 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5225 match conf.columns
with
5227 | _ -> state.x != 0 || conf.zoom > 1.0
5230 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5232 let existsinrow pageno (columns
, coverA
, coverB
) p =
5233 let last = ((pageno - coverA
) mod columns
) + columns
in
5234 let rec any = function
5237 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5241 then (if l.pageno = last then false else any rest
)
5249 match state.layout with
5251 let pageno = page_of_y state.y in
5252 gotoghyll (getpagey (pageno+1))
5254 match conf.columns
with
5256 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5258 let y = clamp (pgscale state.winh
) in
5261 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5262 gotoghyll (getpagey pageno)
5263 | Cmulti
((c, _, _) as cl, _) ->
5264 if conf.presentation
5265 && (existsinrow l.pageno cl
5266 (fun l -> l.pageh
> l.pagey + l.pagevh))
5268 let y = clamp (pgscale state.winh
) in
5271 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5272 gotoghyll (getpagey pageno)
5274 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5276 let pagey, pageh
= getpageyh l.pageno in
5277 let pagey = pagey + pageh
* l.pagecol
in
5278 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5279 gotoghyll (pagey + pageh
+ ips)
5283 match state.layout with
5285 let pageno = page_of_y state.y in
5286 gotoghyll (getpagey (pageno-1))
5288 match conf.columns
with
5290 if conf.presentation
&& l.pagey != 0
5292 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5294 let pageno = max
0 (l.pageno-1) in
5295 gotoghyll (getpagey pageno)
5296 | Cmulti
((c, _, coverB
) as cl, _) ->
5297 if conf.presentation
&&
5298 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5300 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5303 if l.pageno = state.pagecount
- coverB
5307 let pageno = max
0 (l.pageno-decr) in
5308 gotoghyll (getpagey pageno)
5316 let pageno = max
0 (l.pageno-1) in
5317 let pagey, pageh
= getpageyh pageno in
5320 let pagey, pageh
= getpageyh l.pageno in
5321 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5326 let viewkeyboard key mask
=
5328 let mode = state.mode in
5329 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5332 G.postRedisplay "view:enttext"
5334 let ctrl = Wsi.withctrl mask
in
5336 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5342 | 0xff63 -> (* insert *)
5343 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5345 state.mode <- LinkNav
(Ltgendir
0);
5348 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5350 | 0xff1b | 113 -> (* escape / q *)
5351 begin match state.mstate
with
5353 state.mstate
<- Mnone
;
5354 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5355 G.postRedisplay "kill zoom rect";
5357 begin match state.mode with
5360 G.postRedisplay "esc leave linknav"
5362 match state.ranchors
with
5364 | (path, password
, anchor, origin
) :: rest
->
5365 state.ranchors
<- rest
;
5366 state.anchor <- anchor;
5367 state.origin
<- origin
;
5368 state.nameddest
<- "";
5369 opendoc path password
5373 | 0xff08 -> (* backspace *)
5374 gotoghyll (getnav ~
-1)
5382 G.postRedisplay "dehighlight";
5384 | 47 | 63 -> (* / ? *)
5385 let ondone isforw
s =
5386 cbput state.hists
.pat
s;
5387 state.searchpattern
<- s;
5390 let s = String.create
1 in
5391 s.[0] <- Char.chr
key;
5392 enttext (s, "", Some
(onhist state.hists
.pat
),
5393 textentry, ondone (key = 47), true)
5395 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5396 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5397 setzoom (conf.zoom +. incr)
5399 | 43 | 0xffab -> (* + *)
5402 try int_of_string
s with exc
->
5403 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5409 state.text <- "page bias is now " ^ string_of_int
n;
5412 enttext ("page bias: ", "", None
, intentry, ondone, true)
5414 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5415 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5416 setzoom (max
0.01 (conf.zoom -. decr))
5418 | 45 | 0xffad -> (* - *)
5419 let ondone msg
= state.text <- msg
in
5421 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5422 optentry state.mode, ondone, true
5425 | 48 when ctrl -> (* ctrl-0 *)
5433 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5435 match conf.columns
with
5436 | Csingle
_ | Cmulti
_ -> 1
5437 | Csplit
(n, _) -> n
5439 let h = state.winh
-
5440 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5442 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5443 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5446 | 51 when ctrl -> (* ctrl-3 *)
5448 match conf.fitmodel
with
5449 | FitWidth
-> FitProportional
5450 | FitProportional
-> FitPage
5451 | FitPage
-> FitWidth
5453 state.text <- "fit model: " ^
FMTE.to_string fm;
5454 reqlayout conf.angle
fm
5456 | 0xffc6 -> (* f9 *)
5459 | 57 when ctrl -> (* ctrl-9 *)
5462 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5463 when not
ctrl -> (* 0..9 *)
5466 try int_of_string
s with exc
->
5467 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5473 cbput state.hists
.pag
(string_of_int
n);
5474 gotopage1 (n + conf.pagebias
- 1) 0;
5477 let pageentry text key =
5478 match Char.unsafe_chr
key with
5479 | '
g'
-> TEdone
text
5480 | _ -> intentry text key
5482 let text = "x" in text.[0] <- Char.chr
key;
5483 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5486 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5487 reshape state.winw
state.winh
;
5490 state.bzoom
<- not
state.bzoom
;
5492 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5495 conf.hlinks
<- not
conf.hlinks
;
5496 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5497 G.postRedisplay "toggle highlightlinks";
5500 state.glinks
<- true;
5501 let mode = state.mode in
5502 state.mode <- Textentry
(
5503 (":", "", None
, linknentry, linkndone gotounder, false),
5505 state.glinks
<- false;
5509 G.postRedisplay "view:linkent(F)"
5512 state.glinks
<- true;
5513 let mode = state.mode in
5514 state.mode <- Textentry
(
5516 ":", "", None
, linknentry, linkndone (fun under ->
5517 selstring (undertext under);
5521 state.glinks
<- false;
5525 G.postRedisplay "view:linkent"
5528 begin match state.autoscroll
with
5530 conf.autoscrollstep
<- step
;
5531 state.autoscroll
<- None
5533 if conf.autoscrollstep
= 0
5534 then state.autoscroll
<- Some
1
5535 else state.autoscroll
<- Some
conf.autoscrollstep
5538 | 112 when ctrl -> (* ctrl-p *)
5542 setpresentationmode (not
conf.presentation
);
5543 showtext ' '
("presentation mode " ^
5544 if conf.presentation
then "on" else "off");
5547 if List.mem
Wsi.Fullscreen
state.winstate
5548 then Wsi.reshape conf.cwinw
conf.cwinh
5549 else Wsi.fullscreen
()
5551 | 112 | 78 -> (* p|N *)
5552 search state.searchpattern
false
5554 | 110 | 0xffc0 -> (* n|F3 *)
5555 search state.searchpattern
true
5558 begin match state.layout with
5561 gotoghyll (getpagey l.pageno)
5567 | 0xff9f | 0xffff -> (* delete *)
5571 showtext ' '
(describe_location ());
5574 begin match state.layout with
5577 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5582 enterbookmarkmode ()
5584 | 104 | 0xffbe -> (* h|F1 *)
5590 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5595 match state.layout with
5599 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5602 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5606 showtext ' '
"Quick bookmark added";
5609 begin match state.layout with
5611 let rect = getpdimrect
l.pagedimno
in
5615 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5616 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5618 (truncate
(rect.(1) -. rect.(0)),
5619 truncate
(rect.(3) -. rect.(0)))
5621 let w = truncate
((float w)*.conf.zoom)
5622 and h = truncate
((float h)*.conf.zoom) in
5625 state.anchor <- getanchor ();
5626 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5628 G.postRedisplay "z";
5633 | 120 -> state.roam
() (* x *)
5634 | 60 | 62 -> (* < > *)
5635 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5637 | 91 | 93 -> (* [ ] *)
5639 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5641 G.postRedisplay "brightness";
5643 | 99 when state.mode = View
-> (* [alt-]c *)
5648 let m = (wadjsb state.winw
- state.w) / 2 in
5650 gotoy_and_clear_text state.y
5654 match state.prevcolumns
with
5655 | None
-> (1, 0, 0), 1.0
5656 | Some
(columns
, z
) ->
5659 | Csplit
(c, _) -> -c, 0, 0
5660 | Cmulti
((c, a, b), _) -> c, a, b
5661 | Csingle
_ -> 1, 0, 0
5665 setcolumns View
c a b;
5668 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5669 -> (* ctrl-shift- (kp) [up|down] *)
5670 let zoom, x = state.prevzoom
in
5674 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5675 begin match state.autoscroll
with
5677 begin match state.mode with
5678 | Birdseye beye
-> upbirdseye 1 beye
5681 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5683 if not
(Wsi.withshift mask
) && conf.presentation
5685 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5689 setautoscrollspeed n false
5692 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5693 begin match state.autoscroll
with
5695 begin match state.mode with
5696 | Birdseye beye
-> downbirdseye 1 beye
5699 then gotoy_and_clear_text (clamp (state.winh
/2))
5701 if not
(Wsi.withshift mask
) && conf.presentation
5703 else gotoy_and_clear_text (clamp conf.scrollstep
)
5707 setautoscrollspeed n true
5710 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5711 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5717 else conf.hscrollstep
5719 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5720 state.x <- panbound (state.x + dx);
5721 gotoy_and_clear_text state.y
5724 G.postRedisplay "left/right"
5727 | 0xff55 | 0xff9a -> (* (kp) prior *)
5731 match state.layout with
5733 | l :: _ -> state.y - l.pagey
5735 clamp (pgscale (-state.winh
))
5739 | 0xff56 | 0xff9b -> (* (kp) next *)
5743 match List.rev
state.layout with
5745 | l :: _ -> getpagey l.pageno
5747 clamp (pgscale state.winh
)
5751 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5753 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5754 gotoghyll (clamp state.maxy)
5757 when Wsi.withalt mask
-> (* alt-(kp) right *)
5758 gotoghyll (getnav 1)
5760 when Wsi.withalt mask
-> (* alt-(kp) left *)
5761 gotoghyll (getnav ~
-1)
5766 | 118 when conf.debug
-> (* v *)
5769 match getopaque l.pageno with
5772 let x0, y0, x1, y1 = pagebbox opaque
in
5773 let a,b = float x0, float y0 in
5774 let c,d = float x1, float y0 in
5775 let e,f = float x1, float y1 in
5776 let h,j
= float x0, float y1 in
5777 let rect = (a,b,c,d,e,f,h,j
) in
5779 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5781 G.postRedisplay "v";
5784 vlog "huh? %s" (Wsi.keyname
key)
5787 let linknavkeyboard key mask
linknav =
5788 let getpage pageno =
5789 let rec loop = function
5791 | l :: _ when l.pageno = pageno -> Some
l
5792 | _ :: rest
-> loop rest
5793 in loop state.layout
5795 let doexact (pageno, n) =
5796 match getopaque pageno, getpage pageno with
5797 | Some opaque
, Some
l ->
5798 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5800 let under = getlink opaque
n in
5801 G.postRedisplay "link gotounder";
5807 | 0xff50 -> (* home *)
5808 Some
(findlink opaque LDfirst
), -1
5810 | 0xff57 -> (* end *)
5811 Some
(findlink opaque LDlast
), 1
5813 | 0xff51 -> (* left *)
5814 Some
(findlink opaque
(LDleft
n)), -1
5816 | 0xff53 -> (* right *)
5817 Some
(findlink opaque
(LDright
n)), 1
5819 | 0xff52 -> (* up *)
5820 Some
(findlink opaque
(LDup
n)), -1
5822 | 0xff54 -> (* down *)
5823 Some
(findlink opaque
(LDdown
n)), 1
5828 begin match findpwl
l.pageno dir with
5832 state.mode <- LinkNav
(Ltgendir
dir);
5833 let y, h = getpageyh pageno in
5836 then y + h - state.winh
5841 begin match getopaque pageno, getpage pageno with
5842 | Some opaque
, Some
_ ->
5844 let ld = if dir > 0 then LDfirst
else LDlast
in
5847 begin match link with
5849 showlinktype (getlink opaque
m);
5850 state.mode <- LinkNav
(Ltexact
(pageno, m));
5851 G.postRedisplay "linknav jpage";
5858 begin match opt with
5859 | Some Lnotfound
-> pwl l dir;
5860 | Some
(Lfound
m) ->
5864 let _, y0, _, y1 = getlinkrect opaque
m in
5866 then gotopage1 l.pageno y0
5868 let d = fstate.fontsize
+ 1 in
5869 if y1 - l.pagey > l.pagevh - d
5870 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5871 else G.postRedisplay "linknav";
5873 showlinktype (getlink opaque
m);
5874 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5877 | None
-> viewkeyboard key mask
5879 | _ -> viewkeyboard key mask
5884 G.postRedisplay "leave linknav"
5888 | Ltgendir
_ -> viewkeyboard key mask
5889 | Ltexact exact
-> doexact exact
5892 let keyboard key mask
=
5893 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5894 then wcmd "interrupt"
5895 else state.uioh <- state.uioh#
key key mask
5898 let birdseyekeyboard key mask
5899 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5901 match conf.columns
with
5903 | Cmulti
((c, _, _), _) -> c
5904 | Csplit
_ -> failwith
"bird's eye split mode"
5906 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5908 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5909 let y, h = getpageyh pageno in
5910 let top = (state.winh
- h) / 2 in
5911 gotoy (max
0 (y - top))
5912 | 0xff0d (* enter *)
5913 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5914 | 0xff1b -> leavebirdseye beye
true (* escape *)
5915 | 0xff52 -> upbirdseye incr beye
(* up *)
5916 | 0xff54 -> downbirdseye incr beye
(* down *)
5917 | 0xff51 -> upbirdseye 1 beye
(* left *)
5918 | 0xff53 -> downbirdseye 1 beye
(* right *)
5920 | 0xff55 -> (* prior *)
5921 begin match state.layout with
5925 state.mode <- Birdseye
(
5926 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5928 gotopage1 l.pageno 0;
5931 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5933 | [] -> gotoy (clamp (-state.winh
))
5935 state.mode <- Birdseye
(
5936 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5938 gotopage1 l.pageno 0
5941 | [] -> gotoy (clamp (-state.winh
))
5944 | 0xff56 -> (* next *)
5945 begin match List.rev
state.layout with
5947 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5948 begin match layout with
5950 let incr = l.pageh
- l.pagevh in
5955 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5957 G.postRedisplay "birdseye pagedown";
5959 else gotoy (clamp (incr + conf.interpagespace
*2));
5963 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5964 gotopage1 l.pageno 0;
5967 | [] -> gotoy (clamp state.winh
)
5970 | 0xff50 -> (* home *)
5971 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5974 | 0xff57 -> (* end *)
5975 let pageno = state.pagecount
- 1 in
5976 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5977 if not
(pagevisible state.layout pageno)
5980 match List.rev
state.pdims
with
5982 | (_, _, h, _) :: _ -> h
5984 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5985 else G.postRedisplay "birdseye end";
5986 | _ -> viewkeyboard key mask
5991 match state.mode with
5992 | Textentry
_ -> scalecolor 0.4
5994 | View
-> scalecolor 1.0
5995 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5996 if l.pageno = hooverpageno
5999 if l.pageno = pageno
6007 let postdrawpage l linkindexbase
=
6008 match getopaque l.pageno with
6010 if tileready l l.pagex
l.pagey
6012 let x = l.pagedispx - l.pagex
6013 and y = l.pagedispy - l.pagey in
6015 match conf.columns
with
6016 | Csingle
_ | Cmulti
_ ->
6017 (if conf.hlinks
then 1 else 0)
6019 && not
(isbirdseye state.mode) then 2 else 0)
6023 match state.mode with
6024 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6027 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6032 let scrollindicator () =
6033 let sbw, ph
, sh = state.uioh#
scrollph in
6034 let sbh, pw, sw = state.uioh#scrollpw
in
6036 GlDraw.color (0.64, 0.64, 0.64);
6038 (float (state.winw
- sbw)) 0.
6039 (float state.winw
) (float state.winh
)
6042 0. (float (state.winh
- sbh))
6043 (float (wadjsb state.winw
- 1)) (float state.winh
)
6045 GlDraw.color (0.0, 0.0, 0.0);
6048 (float (state.winw
- sbw)) ph
6049 (float state.winw
) (ph
+. sh)
6052 pw (float (state.winh
- sbh))
6053 (pw +. sw) (float state.winh
)
6058 match state.mstate
with
6059 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6062 | Msel
((x0, y0), (x1, y1)) ->
6063 let rec loop = function
6065 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6066 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6067 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6068 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6070 match getopaque l.pageno with
6072 let x0, y0 = pagetranslatepoint l x0 y0 in
6073 let x1, y1 = pagetranslatepoint l x1 y1 in
6074 seltext opaque
(x0, y0, x1, y1);
6082 let showrects = function [] -> () | rects
->
6084 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6085 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6087 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6089 if l.pageno = pageno
6091 let dx = float (l.pagedispx - l.pagex
) in
6092 let dy = float (l.pagedispy - l.pagey) in
6093 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6094 Raw.sets_float
state.vraw ~pos
:0
6099 GlArray.vertex `two
state.vraw
;
6100 GlArray.draw_arrays `triangle_strip
0 4;
6109 GlClear.color (scalecolor2 conf.bgcolor
);
6110 GlClear.clear
[`
color];
6111 List.iter
drawpage state.layout;
6113 match state.mode with
6114 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6115 begin match getopaque pageno with
6117 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6124 | None
-> state.rects
6129 let rec postloop linkindexbase
= function
6131 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6132 postloop linkindexbase rest
6136 postloop 0 state.layout;
6138 begin match state.mstate
with
6139 | Mzoomrect
((x0, y0), (x1, y1)) ->
6141 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6142 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6143 filledrect (float x0) (float y0) (float x1) (float y1);
6152 let zoomrect x y x1 y1 =
6155 and y0 = min
y y1 in
6156 gotoy (state.y + y0);
6157 state.anchor <- getanchor ();
6158 let zoom = (float state.w) /. float (x1 - x0) in
6160 match conf.fitmodel
, conf.columns
with
6161 | FitPage
, Csplit
_ ->
6162 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6165 let adjw = wadjsb state.winw
in
6167 then (adjw - state.w) / 2
6170 state.x <- (state.x + margin) - x0;
6172 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6173 state.mstate
<- Mnone
;
6177 let g opaque
l px py =
6178 match rectofblock opaque
px py with
6180 let x0 = a.(0) -. 20. in
6181 let x1 = a.(1) +. 20. in
6182 let y0 = a.(2) -. 20. in
6183 let zoom = (float state.w) /. (x1 -. x0) in
6184 let pagey = getpagey l.pageno in
6185 gotoy_and_clear_text (pagey + truncate
y0);
6186 state.anchor <- getanchor ();
6187 let margin = (state.w - l.pagew
)/2 in
6188 state.x <- -truncate
x0 - margin;
6193 match conf.columns
with
6195 showtext '
!'
"block zooming does not work properly in split columns mode"
6196 | _ -> onppundermouse g x y ()
6200 let winw = wadjsb state.winw - 1 in
6201 let s = float x /. float winw in
6202 let destx = truncate
(float (state.w + winw) *. s) in
6203 state.x <- winw - destx;
6204 gotoy_and_clear_text state.y;
6205 state.mstate
<- Mscrollx
;
6209 let s = float y /. float state.winh
in
6210 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6211 gotoy_and_clear_text desty;
6212 state.mstate
<- Mscrolly
;
6215 let viewmouse button down
x y mask
=
6217 | n when (n == 4 || n == 5) && not down
->
6218 if Wsi.withctrl mask
6220 match state.mstate
with
6221 | Mzoom
(oldn
, i
) ->
6229 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6231 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6233 let zoom = conf.zoom -. incr in
6235 state.mstate
<- Mzoom
(n, 0);
6237 state.mstate
<- Mzoom
(n, i
+1);
6239 else state.mstate
<- Mzoom
(n, 0)
6241 | _ -> state.mstate
<- Mzoom
(n, 0)
6244 match state.autoscroll
with
6245 | Some step
-> setautoscrollspeed step
(n=4)
6247 if conf.wheelbypage
|| conf.presentation
6256 then -conf.scrollstep
6257 else conf.scrollstep
6259 let incr = incr * 2 in
6260 let y = clamp incr in
6261 gotoy_and_clear_text y
6264 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6266 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6267 gotoy_and_clear_text state.y
6269 | 1 when Wsi.withshift mask
->
6270 state.mstate
<- Mnone
;
6273 match unproject x y with
6274 | Some
(pageno, ux
, uy
) ->
6275 let cmd = Printf.sprintf
6277 conf.stcmd
state.path pageno ux uy
6283 | 1 when Wsi.withctrl mask
->
6286 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6287 state.mstate
<- Mpan
(x, y)
6290 state.mstate
<- Mnone
6295 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6297 state.mstate
<- Mzoomrect
(p, p)
6300 match state.mstate
with
6301 | Mzoomrect
((x0, y0), _) ->
6302 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6303 then zoomrect x0 y0 x y
6305 state.mstate
<- Mnone
;
6306 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6307 G.postRedisplay "kill accidental zoom rect";
6310 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6311 state.mstate
<- Mnone
6314 | 1 when x > state.winw - vscrollw () ->
6317 let _, position, sh = state.uioh#
scrollph in
6318 if y > truncate
position && y < truncate
(position +. sh)
6319 then state.mstate
<- Mscrolly
6322 state.mstate
<- Mnone
6324 | 1 when y > state.winh
- hscrollh () ->
6327 let _, position, sw = state.uioh#scrollpw
in
6328 if x > truncate
position && x < truncate
(position +. sw)
6329 then state.mstate
<- Mscrollx
6332 state.mstate
<- Mnone
6334 | 1 when state.bzoom
-> if not down
then zoomblock x y
6337 let dest = if down
then getunder x y else Unone
in
6338 begin match dest with
6341 | Uremote
_ | Uremotedest
_
6342 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6345 | Unone
when down
->
6346 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6347 state.mstate
<- Mpan
(x, y);
6349 | Unone
| Utext
_ ->
6352 if conf.angle
mod 360 = 0
6354 state.mstate
<- Msel
((x, y), (x, y));
6355 G.postRedisplay "mouse select";
6359 match state.mstate
with
6362 | Mzoom
_ | Mscrollx
| Mscrolly
->
6363 state.mstate
<- Mnone
6365 | Mzoomrect
((x0, y0), _) ->
6369 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6370 state.mstate
<- Mnone
6372 | Msel
((x0, y0), (x1, y1)) ->
6373 let rec loop = function
6377 let a0 = l.pagedispy in
6378 let a1 = a0 + l.pagevh in
6379 let b0 = l.pagedispx in
6380 let b1 = b0 + l.pagevw in
6381 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6382 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6386 match getopaque l.pageno with
6389 match Ne.pipe () with
6393 "can not create sel pipe: %s"
6396 let doclose what fd
=
6397 Ne.clo fd
(fun msg
->
6398 dolog
"%s close failed: %s" what msg
)
6401 popen conf.selcmd
[r, 0; w, -1];
6402 copysel
w opaque
true;
6404 G.postRedisplay "copysel";
6406 dolog
"can not execute %S: %s"
6407 conf.selcmd
(exntos exn
);
6415 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6416 state.mstate
<- Mnone
;
6423 let birdseyemouse button down
x y mask
6424 (conf, leftx
, _, hooverpageno
, anchor) =
6427 let rec loop = function
6430 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6431 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6433 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6439 | _ -> viewmouse button down
x y mask
6445 method key key mask
=
6446 begin match state.mode with
6447 | Textentry
textentry -> textentrykeyboard key mask
textentry
6448 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6449 | View
-> viewkeyboard key mask
6450 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6454 method button button bstate
x y mask
=
6455 begin match state.mode with
6457 | View
-> viewmouse button bstate
x y mask
6458 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6464 begin match state.mode with
6466 | View
| Birdseye
_ | LinkNav
_ ->
6467 match state.mstate
with
6468 | Mzoom
_ | Mnone
-> ()
6473 state.mstate
<- Mpan
(x, y);
6475 then state.x <- panbound (state.x + dx);
6477 gotoy_and_clear_text y
6480 state.mstate
<- Msel
(a, (x, y));
6481 G.postRedisplay "motion select";
6484 let y = min
state.winh
(max
0 y) in
6488 let x = min
state.winw (max
0 x) in
6491 | Mzoomrect
(p0
, _) ->
6492 state.mstate
<- Mzoomrect
(p0
, (x, y));
6493 G.postRedisplay "motion zoomrect";
6497 method pmotion
x y =
6498 begin match state.mode with
6499 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6500 let rec loop = function
6502 if hooverpageno
!= -1
6504 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6505 G.postRedisplay "pmotion birdseye no hoover";
6508 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6509 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6511 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6512 G.postRedisplay "pmotion birdseye hoover";
6522 match state.mstate
with
6523 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6530 let past, _, _ = !r in
6532 let delta = now -. past in
6535 else r := (now, x, y)
6539 method infochanged
_ = ()
6542 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6545 then 0.0, float state.winh
6546 else scrollph state.y maxy
6551 let winw = wadjsb state.winw in
6552 let fwinw = float winw in
6554 let sw = fwinw /. float state.w in
6555 let sw = fwinw *. sw in
6556 max
sw (float conf.scrollh
)
6559 let maxx = state.w + winw in
6560 let x = winw - state.x in
6561 let percent = float x /. float maxx in
6562 (fwinw -. sw) *. percent
6564 hscrollh (), position, sw
6568 match state.mode with
6569 | LinkNav
_ -> "links"
6570 | Textentry
_ -> "textentry"
6571 | Birdseye
_ -> "birdseye"
6574 findkeyhash conf modename
6576 method eformsgs
= true
6583 let fontpath = ref "";;
6586 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6589 let l = String.length
s in
6590 let b = Buffer.create
l in
6596 try Sys.getenv
"HOME"
6599 ("Can not determine home directory location: " ^ exntos exn
);
6603 let modifier_of_string = function
6604 | "alt" -> Wsi.altmask
6605 | "shift" -> Wsi.shiftmask
6606 | "ctrl" | "control" -> Wsi.ctrlmask
6607 | "meta" -> Wsi.metamask
6612 let r = Str.regexp
"-" in
6614 let elems = Str.full_split
r s in
6617 let m1 = modifier_of_string s in
6619 then (Wsi.namekey
s, m)
6622 | Str.Delim
s when n land 1 = 0 -> g s
6624 | Str.Delim
_ -> (k
, m)
6626 let rec loop n k
m = function
6629 let k, m = f n k m x in
6635 let keys_of_string =
6636 let r = Str.regexp
"[ \t]" in
6638 let elems = Str.split
r s in
6639 List.map
key_of_string elems
6642 let copykeyhashes c =
6643 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6646 let config_of c attrs
=
6650 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6651 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6652 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6653 | "preload" -> { c with preload = bool_of_string
v }
6654 | "page-bias" -> { c with pagebias
= int_of_string
v }
6655 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6656 | "horizontal-scroll-step" ->
6657 { c with hscrollstep
= max
(int_of_string
v) 1 }
6658 | "auto-scroll-step" ->
6659 { c with autoscrollstep
= max
0 (int_of_string
v) }
6660 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6661 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6664 match String.lowercase
v with
6665 | "true" -> Some infinity
6667 | f -> Some
(float_of_string
f)
6669 { c with maxwait
= mw}
6670 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6671 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6672 | "vertical-margin" ->
6673 { c with interpagespace
= max
0 (int_of_string
v) }
6675 let zoom = float_of_string
v /. 100. in
6676 let zoom = max
zoom 0.0 in
6677 { c with zoom = zoom }
6678 | "presentation" -> { c with presentation
= bool_of_string
v }
6679 | "rotation-angle" -> { c with angle
= int_of_string
v }
6680 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6681 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6682 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6683 | "proportional-display" ->
6686 then FitProportional
6689 { c with fitmodel
= fm }
6690 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6691 | "pixmap-cache-size" ->
6692 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6693 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6694 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6695 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6696 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6697 | "background-color" -> { c with bgcolor
= color_of_string v }
6698 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6699 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6700 | "mupdf-store-size" ->
6701 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6702 | "checkers" -> { c with checkers
= bool_of_string
v }
6703 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6704 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6705 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6706 | "uri-launcher" -> { c with urilauncher
= unent v }
6707 | "path-launcher" -> { c with pathlauncher
= unent v }
6708 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6709 | "invert-colors" -> { c with invert
= bool_of_string
v }
6710 | "brightness" -> { c with colorscale
= float_of_string
v }
6711 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6712 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6714 let (n, _, _) as nab
= multicolumns_of_string v in
6716 then { c with columns
= Csplit
(-n, [||]) }
6717 else { c with columns
= Cmulti
(nab
, [||]) }
6718 | "birds-eye-columns" ->
6719 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6720 | "selection-command" -> { c with selcmd
= unent v }
6721 | "synctex-command" -> { c with stcmd
= unent v }
6722 | "pax-command" -> { c with paxcmd
= unent v }
6723 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6724 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6725 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6726 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6727 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6728 | "horizontal-scrollbar-visible" ->
6731 then c.scrollb
lor scrollbhv
6732 else c.scrollb
land (lnot
scrollbhv)
6734 { c with scrollb
= b }
6735 | "vertical-scrollbar-visible" ->
6738 then c.scrollb
lor scrollbvv
6739 else c.scrollb
land (lnot
scrollbvv)
6741 { c with scrollb
= b }
6742 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6746 then Some
(ref (0.0, 0, 0))
6748 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6751 prerr_endline
("Error processing attribute (`" ^
6752 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6755 let rec fold c = function
6758 let c = apply c k v in
6761 fold { c with keyhashes
= copykeyhashes c } attrs
;
6764 let fromstring f pos
n v d =
6767 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6768 n v pos
(exntos exn
)
6773 let bookmark_of attrs
=
6774 let rec fold title page
rely visy
= function
6775 | ("title", v) :: rest
-> fold v page
rely visy rest
6776 | ("page", v) :: rest
-> fold title v rely visy rest
6777 | ("rely", v) :: rest
-> fold title page
v visy rest
6778 | ("visy", v) :: rest
-> fold title page
rely v rest
6779 | _ :: rest
-> fold title page
rely visy rest
6780 | [] -> title, page
, rely, visy
6782 fold "invalid" "0" "0" "0" attrs
6786 let rec fold path page
rely pan visy
= function
6787 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6788 | ("page", v) :: rest
-> fold path v rely pan visy rest
6789 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6790 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6791 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6792 | _ :: rest
-> fold path page
rely pan visy rest
6793 | [] -> path, page
, rely, pan
, visy
6795 fold "" "0" "0" "0" "0" attrs
6799 let rec fold rs ls
= function
6800 | ("out", v) :: rest
-> fold v ls rest
6801 | ("in", v) :: rest
-> fold rs
v rest
6802 | _ :: rest
-> fold ls rs rest
6808 let setconf dst
src =
6809 dst
.scrollbw
<- src.scrollbw
;
6810 dst
.scrollh
<- src.scrollh
;
6811 dst
.icase
<- src.icase
;
6812 dst
.preload <- src.preload;
6813 dst
.pagebias
<- src.pagebias
;
6814 dst
.verbose
<- src.verbose
;
6815 dst
.scrollstep
<- src.scrollstep
;
6816 dst
.maxhfit
<- src.maxhfit
;
6817 dst
.crophack
<- src.crophack
;
6818 dst
.autoscrollstep
<- src.autoscrollstep
;
6819 dst
.maxwait
<- src.maxwait
;
6820 dst
.hlinks
<- src.hlinks
;
6821 dst
.underinfo
<- src.underinfo
;
6822 dst
.interpagespace
<- src.interpagespace
;
6823 dst
.zoom <- src.zoom;
6824 dst
.presentation
<- src.presentation
;
6825 dst
.angle
<- src.angle
;
6826 dst
.cwinw
<- src.cwinw
;
6827 dst
.cwinh
<- src.cwinh
;
6828 dst
.savebmarks
<- src.savebmarks
;
6829 dst
.memlimit
<- src.memlimit
;
6830 dst
.fitmodel
<- src.fitmodel
;
6831 dst
.texcount
<- src.texcount
;
6832 dst
.sliceheight
<- src.sliceheight
;
6833 dst
.thumbw
<- src.thumbw
;
6834 dst
.jumpback
<- src.jumpback
;
6835 dst
.bgcolor
<- src.bgcolor
;
6836 dst
.tilew
<- src.tilew
;
6837 dst
.tileh
<- src.tileh
;
6838 dst
.mustoresize
<- src.mustoresize
;
6839 dst
.checkers
<- src.checkers
;
6840 dst
.aalevel
<- src.aalevel
;
6841 dst
.trimmargins
<- src.trimmargins
;
6842 dst
.trimfuzz
<- src.trimfuzz
;
6843 dst
.urilauncher
<- src.urilauncher
;
6844 dst
.colorspace
<- src.colorspace
;
6845 dst
.invert
<- src.invert
;
6846 dst
.colorscale
<- src.colorscale
;
6847 dst
.redirectstderr <- src.redirectstderr;
6848 dst
.ghyllscroll
<- src.ghyllscroll
;
6849 dst
.columns
<- src.columns
;
6850 dst
.beyecolumns
<- src.beyecolumns
;
6851 dst
.selcmd
<- src.selcmd
;
6852 dst
.updatecurs
<- src.updatecurs
;
6853 dst
.pathlauncher
<- src.pathlauncher
;
6854 dst
.keyhashes
<- copykeyhashes src;
6855 dst
.hfsize
<- src.hfsize
;
6856 dst
.hscrollstep
<- src.hscrollstep
;
6857 dst
.pgscale <- src.pgscale;
6858 dst
.usepbo
<- src.usepbo
;
6859 dst
.wheelbypage
<- src.wheelbypage
;
6860 dst
.stcmd
<- src.stcmd
;
6861 dst
.paxcmd
<- src.paxcmd
;
6862 dst
.scrollb
<- src.scrollb
;
6863 dst
.riani
<- src.riani
;
6864 dst
.paxmark
<- src.paxmark
;
6868 else Some
((ref (0.0, 0, 0)));
6872 let h = Hashtbl.create
10 in
6873 let dc = { defconf with angle
= defconf.angle
} in
6874 let rec toplevel v t spos
_ =
6876 | Vdata
| Vcdata
| Vend
-> v
6877 | Vopen
("llppconfig", _, closed
) ->
6880 else { v with f = llppconfig
}
6882 error
"unexpected subelement at top level" s spos
6883 | Vclose
_ -> error
"unexpected close at top level" s spos
6885 and llppconfig
v t spos
_ =
6887 | Vdata
| Vcdata
-> v
6888 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6889 | Vopen
("defaults", attrs
, closed
) ->
6890 let c = config_of dc attrs
in
6894 else { v with f = defaults
}
6896 | Vopen
("ui-font", attrs
, closed
) ->
6897 let rec getsize size
= function
6899 | ("size", v) :: rest
->
6901 fromstring int_of_string spos
"size" v fstate.fontsize
in
6903 | l -> getsize size l
6905 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6908 else { v with f = uifont
(Buffer.create
10) }
6910 | Vopen
("doc", attrs
, closed
) ->
6911 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6912 let path = unent pathent
6913 and pageno = fromstring int_of_string spos
"page" spage
0
6914 and rely = fromstring float_of_string spos
"rely" srely
0.0
6915 and pan
= fromstring int_of_string spos
"pan" span
0
6916 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6917 let c = config_of dc attrs
in
6918 let anchor = (pageno, rely, visy
) in
6920 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6921 else { v with f = doc
path pan
anchor c [] }
6924 error
"unexpected subelement in llppconfig" s spos
6926 | Vclose
"llppconfig" -> { v with f = toplevel }
6927 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6929 and defaults
v t spos
_ =
6931 | Vdata
| Vcdata
-> v
6932 | Vend
-> error
"unexpected end of input in defaults" s spos
6933 | Vopen
("keymap", attrs
, closed
) ->
6935 try List.assoc
"mode" attrs
6936 with Not_found
-> "global" in
6941 let h = findkeyhash dc modename in
6942 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6945 { v with f = pkeymap
ret KeyMap.empty }
6947 | Vopen
(_, _, _) ->
6948 error
"unexpected subelement in defaults" s spos
6950 | Vclose
"defaults" ->
6951 { v with f = llppconfig
}
6953 | Vclose
_ -> error
"unexpected close in defaults" s spos
6955 and uifont
b v t spos
epos =
6958 Buffer.add_substring
b s spos
(epos - spos
);
6960 | Vopen
(_, _, _) ->
6961 error
"unexpected subelement in ui-font" s spos
6962 | Vclose
"ui-font" ->
6963 if emptystr
!fontpath
6964 then fontpath := Buffer.contents
b;
6965 { v with f = llppconfig
}
6966 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6967 | Vend
-> error
"unexpected end of input in ui-font" s spos
6969 and doc
path pan
anchor c bookmarks
v t spos
_ =
6971 | Vdata
| Vcdata
-> v
6972 | Vend
-> error
"unexpected end of input in doc" s spos
6973 | Vopen
("bookmarks", _, closed
) ->
6976 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6978 | Vopen
("keymap", attrs
, closed
) ->
6980 try List.assoc
"mode" attrs
6981 with Not_found
-> "global"
6987 let h = findkeyhash c modename in
6988 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6989 doc
path pan
anchor c bookmarks
6991 { v with f = pkeymap
ret KeyMap.empty }
6993 | Vopen
(_, _, _) ->
6994 error
"unexpected subelement in doc" s spos
6997 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6998 { v with f = llppconfig
}
7000 | Vclose
_ -> error
"unexpected close in doc" s spos
7002 and pkeymap
ret keymap
v t spos
_ =
7004 | Vdata
| Vcdata
-> v
7005 | Vend
-> error
"unexpected end of input in keymap" s spos
7006 | Vopen
("map", attrs
, closed
) ->
7007 let r, l = map_of attrs
in
7008 let kss = fromstring keys_of_string spos
"in" r [] in
7009 let lss = fromstring keys_of_string spos
"out" l [] in
7013 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7014 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7017 then { v with f = pkeymap
ret keymap }
7020 { v with f = skip
"map" f }
7023 error
"unexpected subelement in keymap" s spos
7025 | Vclose
"keymap" ->
7026 { v with f = ret keymap }
7028 | Vclose
_ -> error
"unexpected close in keymap" s spos
7030 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7032 | Vdata
| Vcdata
-> v
7033 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7034 | Vopen
("item", attrs
, closed
) ->
7035 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7036 let page = fromstring int_of_string spos
"page" spage
0
7037 and rely = fromstring float_of_string spos
"rely" srely
0.0
7038 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7040 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
7043 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7046 { v with f = skip
"item" f }
7049 error
"unexpected subelement in bookmarks" s spos
7051 | Vclose
"bookmarks" ->
7052 { v with f = doc
path pan
anchor c bookmarks }
7054 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7056 and skip tag
f v t spos
_ =
7058 | Vdata
| Vcdata
-> v
7060 error
("unexpected end of input in skipped " ^ tag
) s spos
7061 | Vopen
(tag'
, _, closed
) ->
7065 let f'
() = { v with f = skip tag
f } in
7066 { v with f = skip tag'
f'
}
7070 else error
("unexpected close in skipped " ^ tag
) s spos
7073 parse
{ f = toplevel; accu = () } s;
7079 let len = in_channel_length ic
in
7080 let s = String.create
len in
7081 really_input ic
s 0 len;
7084 | Parse_error
(msg
, s, pos
) ->
7085 let subs = subs s pos
in
7086 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7089 failwith
("config load error: " ^ exntos exn
)
7095 let dir = Filename.concat
home ".config" in
7096 if Sys.is_directory
dir then dir else home
7099 Filename.concat
dir "llpp.conf"
7102 let confpath = ref defconfpath;;
7105 if Sys.file_exists
!confpath
7108 (try Some
(open_in_bin
!confpath)
7111 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7122 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7131 f (Hashtbl.create
0, defconf)
7136 let pc, pb
, px, pa
=
7139 if emptystr
state.origin
7143 Hashtbl.find h (Filename.basename
key)
7144 with Not_found
-> dc, [], 0, emptyanchor
7148 state.bookmarks <- pb
;
7151 then state.anchor <- pa
;
7152 cbput state.hists
.nav pa
;
7158 let add_attrs bb always
dc c =
7161 then Printf.bprintf bb
"\n %s='%b'" s a
7164 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7167 then Printf.bprintf bb
"\n %s='%d'" s a
7170 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7173 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7176 then Printf.bprintf bb
"\n %s='%f'" s a
7180 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7184 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7188 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7192 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7197 | Some
(_N
, _A
, _B
) ->
7198 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7203 Printf.bprintf bb
"\n %s='none'" s
7213 else string_of_float
f
7215 Printf.bprintf bb
"\n %s='%s'" s v
7220 | Cmulti
((n, a, b), _) when n > 1 ->
7221 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7222 | Csplit
(n, _) when n > 1 ->
7223 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7229 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7234 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7238 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7242 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7244 oi
"width" c.cwinw
dc.cwinw
;
7245 oi
"height" c.cwinh
dc.cwinh
;
7246 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7247 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7248 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7249 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7250 ob "case-insensitive-search" c.icase
dc.icase
;
7251 ob "preload" c.preload dc.preload;
7252 oi
"page-bias" c.pagebias
dc.pagebias
;
7253 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7254 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7255 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7256 ob "crop-hack" c.crophack
dc.crophack
;
7257 oW
"throttle" c.maxwait
dc.maxwait
;
7258 ob "highlight-links" c.hlinks
dc.hlinks
;
7259 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7260 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7261 oz
"zoom" c.zoom dc.zoom;
7262 ob "presentation" c.presentation
dc.presentation
;
7263 oi
"rotation-angle" c.angle
dc.angle
;
7264 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7265 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7266 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7267 oi
"tex-count" c.texcount
dc.texcount
;
7268 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7269 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7270 ob "persistent-location" c.jumpback
dc.jumpback
;
7271 oc
"background-color" c.bgcolor
dc.bgcolor
;
7272 oi
"tile-width" c.tilew
dc.tilew
;
7273 oi
"tile-height" c.tileh
dc.tileh
;
7274 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7275 ob "checkers" c.checkers
dc.checkers
;
7276 oi
"aalevel" c.aalevel
dc.aalevel
;
7277 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7278 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7279 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7280 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7281 oC
"color-space" c.colorspace
dc.colorspace
;
7282 ob "invert-colors" c.invert
dc.invert
;
7283 oF
"brightness" c.colorscale
dc.colorscale
;
7284 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7285 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7286 oco
"columns" c.columns
dc.columns
;
7287 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7288 os
"selection-command" c.selcmd
dc.selcmd
;
7289 os
"synctex-command" c.stcmd
dc.stcmd
;
7290 os
"pax-command" c.paxcmd
dc.paxcmd
;
7291 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7292 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7293 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7294 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7295 ob "use-pbo" c.usepbo
dc.usepbo
;
7296 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7297 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7298 op
"point-and-x" c.pax
dc.pax
;
7299 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7302 let keymapsbuf always
dc c =
7303 let bb = Buffer.create
16 in
7304 let rec loop = function
7306 | (modename, h) :: rest
->
7307 let dh = findkeyhash dc modename in
7308 if always
|| h <> dh
7310 if Hashtbl.length
h > 0
7312 if Buffer.length
bb > 0
7313 then Buffer.add_char
bb '
\n'
;
7314 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7315 Hashtbl.iter
(fun i
o ->
7316 let isdifferent = always
||
7318 let dO = Hashtbl.find dh i
in
7320 with Not_found
-> true
7325 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7326 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7327 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7328 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7329 Buffer.add_string
bb (Wsi.keyname
k);
7332 let rec loop = function
7334 | km
:: [] -> addkm km
7335 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7339 Buffer.add_string
bb "<map in='";
7343 Buffer.add_string
bb "' out='";
7345 Buffer.add_string
bb "'/>\n"
7348 Buffer.add_string
bb "' out='";
7350 Buffer.add_string
bb "'/>\n"
7352 | KMmulti
(ins, kms
) ->
7353 Buffer.add_char
bb ' '
;
7355 Buffer.add_string
bb "' out='";
7357 Buffer.add_string
bb "'/>\n"
7359 Buffer.add_string
bb "</keymap>";
7369 let uifontsize = fstate.fontsize
in
7370 let bb = Buffer.create
32768 in
7371 let relx = float state.x /. float state.winw in
7373 let cx w = truncate
(relx *. float w) in
7375 (fun (w, h, x) ws
->
7377 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7378 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7379 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7381 (state.winw, state.winh
, state.x) state.winstate
7386 let dc = if conf.bedefault
then conf else dc in
7387 Buffer.add_string
bb "<llppconfig>\n";
7389 if nonemptystr
!fontpath
7391 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7397 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7400 Buffer.add_string
bb "<defaults";
7401 add_attrs bb true dc dc;
7402 let kb = keymapsbuf true dc dc in
7403 if Buffer.length
kb > 0
7405 Buffer.add_string
bb ">\n";
7406 Buffer.add_buffer
bb kb;
7407 Buffer.add_string
bb "\n</defaults>\n";
7409 else Buffer.add_string
bb "/>\n";
7411 let adddoc path pan
anchor c bookmarks =
7412 if bookmarks == [] && c = dc && anchor = emptyanchor
7415 Printf.bprintf
bb "<doc path='%s'"
7416 (enent
path 0 (String.length
path));
7418 if anchor <> emptyanchor
7420 let n, rely, visy
= anchor in
7421 Printf.bprintf
bb " page='%d'" n;
7424 Printf.bprintf
bb " rely='%f'" rely
7426 if abs_float visy
> 1e-6
7428 Printf.bprintf
bb " visy='%f'" visy
7433 then Printf.bprintf
bb " pan='%d'" pan
;
7435 add_attrs bb false dc c;
7436 let kb = keymapsbuf false dc c in
7438 begin match bookmarks with
7440 if Buffer.length
kb > 0
7442 Buffer.add_string
bb ">\n";
7443 Buffer.add_buffer
bb kb;
7444 Buffer.add_string
bb "\n</doc>\n";
7446 else Buffer.add_string
bb "/>\n"
7448 Buffer.add_string
bb ">\n<bookmarks>\n";
7449 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7451 "<item title='%s' page='%d'"
7452 (enent
title 0 (String.length
title))
7457 Printf.bprintf
bb " rely='%f'" rely
7459 if abs_float visy
> 1e-6
7461 Printf.bprintf
bb " visy='%f'" visy
7463 Buffer.add_string
bb "/>\n";
7465 Buffer.add_string
bb "</bookmarks>";
7466 if Buffer.length
kb > 0
7468 Buffer.add_string
bb "\n";
7469 Buffer.add_buffer
bb kb;
7471 Buffer.add_string
bb "\n</doc>\n";
7477 match state.mode with
7478 | Birdseye
(c, pan, _, _, _) ->
7480 match conf.columns
with
7481 | Cmulti
((c, _, _), _) -> Some
c
7485 match c.columns
with
7486 | Cmulti
(c, _) -> Cmulti
(c, [||])
7487 | Csingle
_ -> Csingle
[||]
7488 | Csplit
_ -> failwith
"quit from bird's eye while split"
7490 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7493 let basename = Filename.basename
7494 (if emptystr
state.origin
then state.path else state.origin
)
7496 adddoc basename pan (getanchor ())
7498 let autoscrollstep =
7499 match state.autoscroll
with
7501 | None
-> conf.autoscrollstep
7503 match state.mode with
7504 | Birdseye
(bc
, _, _, _, _) ->
7507 presentation
= bc
.presentation
;
7508 interpagespace
= bc
.interpagespace
;
7509 maxwait
= bc
.maxwait
;
7510 autoscrollstep = autoscrollstep }
7511 | _ -> { conf with autoscrollstep = autoscrollstep }
7513 (if conf.savebmarks
then state.bookmarks else []);
7515 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7517 then adddoc path x anchor c bookmarks
7519 Buffer.add_string
bb "</llppconfig>\n";
7522 if load1 f && Buffer.length
bb > 0
7525 let tmp = !confpath ^
".tmp" in
7526 let oc = open_out_bin
tmp in
7527 Buffer.output_buffer
oc bb;
7529 Unix.rename
tmp !confpath;
7532 ("error while saving configuration: " ^ exntos exn
)
7536 let adderrmsg src msg
=
7537 Buffer.add_string
state.errmsgs msg
;
7538 state.newerrmsgs
<- true;
7542 let adderrfmt src fmt
=
7543 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7547 let cl = splitatspace cmds
in
7549 try Scanf.sscanf
s fmt
f
7551 adderrfmt "remote exec"
7552 "error processing '%S': %s\n" cmds
(exntos exn
)
7555 | "reload" :: [] -> reload ()
7556 | "goto" :: args :: [] ->
7557 scan args "%u %f %f"
7559 let cmd, _ = state.geomcmds
in
7561 then gotopagexy pageno x y
7564 gotopagexy pageno x y;
7567 state.reprf
<- f state.reprf
7569 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7570 | "rect" :: args :: [] ->
7571 scan args "%u %u %f %f %f %f"
7572 (fun pageno color x0 y0 x1 y1 ->
7573 onpagerect pageno (fun w h ->
7574 let _,w1,h1
,_ = getpagedim pageno in
7575 let sw = float w1 /. float w
7576 and sh = float h1
/. float h in
7580 and y1s
= y1 *. sh in
7581 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7583 state.rects <- (pageno, color, rect) :: state.rects;
7584 G.postRedisplay "rect";
7587 | "activatewin" :: [] -> Wsi.activatewin
()
7588 | "quit" :: [] -> raise Quit
7590 adderrfmt "remote command"
7591 "error processing remote command: %S\n" cmds
;
7595 let scratch = String.create
80 in
7596 let buf = Buffer.create
80 in
7599 try Some
(Unix.read fd
scratch 0 80)
7601 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7602 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7605 match tempfr () with
7611 if Buffer.length
buf > 0
7613 let s = Buffer.contents
buf in
7623 let pos = String.index_from
scratch ppos '
\n'
in
7624 if pos >= n then -1 else pos
7625 with Not_found
-> -1
7629 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7630 let s = Buffer.contents
buf in
7636 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7642 let remoteopen path =
7643 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7645 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7650 let trimcachepath = ref "" in
7651 let rcmdpath = ref "" in
7652 selfexec := Sys.executable_name
;
7655 [("-p", Arg.String
(fun s -> state.password
<- s),
7656 "<password> Set password");
7660 Config.fontpath := s;
7661 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7663 "<path> Set path to the user interface font");
7667 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7668 Config.confpath := s),
7669 "<path> Set path to the configuration file");
7671 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7672 "<path> Set path to the trim cache file");
7674 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7675 "<named-destination> Set named destination");
7677 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7678 ("-cxack", Arg.Set
cxack, " Cut corners");
7680 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7681 "<path> Set path to the remote commands source");
7683 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7684 "<original-path> Set original path");
7686 ("-v", Arg.Unit
(fun () ->
7688 "%s\nconfiguration path: %s\n"
7692 exit
0), " Print version and exit");
7695 (fun s -> state.path <- s)
7696 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7699 then selfexec := !selfexec ^
" -wtmode";
7701 if emptystr
state.path
7702 then (prerr_endline
"file name missing"; exit
1);
7704 if not
(Config.load ())
7705 then prerr_endline
"failed to load configuration";
7707 let wsfd, winw, winh
= Wsi.init
(object
7708 val mutable m_hack
= false
7709 method expose
= if not m_hack
then G.postRedisplay "expose"
7710 method visible
= G.postRedisplay "visible"
7711 method display = m_hack
<- false; display ()
7712 method reshape w h =
7713 m_hack
<- w < state.winw && h < state.winh
;
7715 method mouse
b d x y m = state.uioh <- state.uioh#button
b d x y m
7717 state.mpos
<- (x, y);
7718 state.uioh <- state.uioh#motion
x y
7719 method pmotion
x y =
7720 state.mpos
<- (x, y);
7721 state.uioh <- state.uioh#pmotion
x y
7723 let mascm = m land (
7724 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7726 match state.keystate
with
7728 let km = k, mascm in
7731 let modehash = state.uioh#
modehash in
7732 try Hashtbl.find modehash km
7734 try Hashtbl.find (findkeyhash conf "global") km
7735 with Not_found
-> KMinsrt
(k, m)
7737 | KMinsrt
(k, m) -> keyboard k m
7738 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7739 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7741 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7742 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7743 state.keystate
<- KSnone
7744 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7745 state.keystate
<- KSinto
(keys
, insrt
)
7747 state.keystate
<- KSnone
7750 state.mpos
<- (x, y);
7751 state.uioh <- state.uioh#pmotion
x y
7752 method leave = state.mpos
<- (-1, -1)
7753 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7754 method quit
= raise Quit
7755 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7760 List.exists
GlMisc.check_extension
7761 [ "GL_ARB_texture_rectangle"
7762 ; "GL_EXT_texture_recangle"
7763 ; "GL_NV_texture_rectangle" ]
7765 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7768 let r = GlMisc.get_string `renderer
in
7769 let p = "Mesa DRI Intel(" in
7770 let l = String.length
p in
7771 String.length
r > l && String.sub
r 0 l = p
7774 defconf.sliceheight
<- 1024;
7775 defconf.texcount
<- 32;
7776 defconf.usepbo
<- true;
7780 match Ne.pipe () with
7782 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7786 match Ne.pipe () with
7788 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7798 setcheckers conf.checkers
;
7800 if conf.redirectstderr
7803 let s = Buffer.contents
state.errmsgs ^
7804 (match state.errfd
with
7806 let s = String.create
(80*24) in
7809 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7811 then Unix.read fd
s 0 (String.length
s)
7817 else String.sub
s 0 n
7821 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7822 with exn
-> print_endline
(exntos exn
)
7827 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7828 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7829 !Config.fontpath, !trimcachepath,
7830 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7832 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
7835 state.text <- "Opening " ^
(mbtoutf8
state.path);
7837 opendoc state.path state.password
;
7841 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7844 if nonemptystr
!rcmdpath
7845 then remoteopen !rcmdpath
7850 let rec loop deadline
=
7852 match state.errfd
with
7853 | None
-> [state.sr
; state.wsfd]
7854 | Some fd
-> [state.sr
; state.wsfd; fd
]
7859 | Some fd
-> fd
:: r
7863 state.redisplay
<- false;
7870 if deadline
= infinity
7872 else max
0.0 (deadline
-. now)
7877 try Unix.select
r [] [] timeout
7878 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7884 if state.ghyll
== noghyll
7886 match state.autoscroll
with
7887 | Some step
when step
!= 0 ->
7888 let y = state.y + step
in
7892 else if y >= state.maxy then 0 else y
7895 if state.mode = View
7896 then state.text <- "";
7899 else deadline
+. 0.01
7904 let rec checkfds = function
7906 | fd
:: rest
when fd
= state.sr
->
7907 let cmd = readcmd state.sr
in
7911 | fd
:: rest
when fd
= state.wsfd ->
7915 | fd
:: rest
when Some fd
= !optrfd ->
7916 begin match remote fd
with
7917 | None
-> optrfd := remoteopen !rcmdpath;
7918 | opt -> optrfd := opt
7923 let s = String.create
80 in
7924 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7925 if conf.redirectstderr
7927 Buffer.add_substring
state.errmsgs
s 0 n;
7928 state.newerrmsgs
<- true;
7929 state.redisplay
<- true;
7932 prerr_string
(String.sub
s 0 n);
7940 if deadline
= infinity
7944 match state.autoscroll
with
7945 | Some step
when step
!= 0 -> deadline1
7946 | _ -> if state.ghyll
== noghyll then infinity
else deadline1