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
128 let platform_to_string = function
129 | Punknown
-> "unknown"
133 | Pfreebsd
-> "FreeBSD"
134 | Pdragonflybsd
-> "DragonflyBSD"
135 | Popenbsd
-> "OpenBSD"
136 | Pnetbsd
-> "NetBSD"
137 | Pcygwin
-> "Cygwin"
140 let platform = platform ();;
142 let now = Unix.gettimeofday
;;
144 let selfexec = ref "";;
147 if platform = Pcygwin
149 let sh = "/bin/sh" in
150 let args = [|sh; "-c"; cmd
|] in
151 let rec std si so se
= function
153 | (fd
, 0) :: rest
-> std fd so se rest
154 | (fd
, -1) :: rest
->
155 Unix.set_close_on_exec fd
;
158 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
160 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
161 ignore
(Unix.create_process
sh args si so se
)
166 type mpos
= int * int
168 | Msel
of (mpos
* mpos
)
170 | Mscrolly
| Mscrollx
171 | Mzoom
of (int * int)
172 | Mzoomrect
of (mpos
* mpos
)
176 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
177 and onkey
= string -> int -> te
178 and ondone
= string -> unit
179 and histcancel
= unit -> unit
180 and onhist
= ((histcmd
-> string) * histcancel
)
181 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
182 and cancelonempty
= bool
187 | TEswitch
of textentry
198 let bound v minv maxv
=
199 max minv
(min maxv v
);
203 { store
= Array.create n v
210 let cbcap b
= Array.length b
.store
;;
215 b
.wc
<- (b
.wc
+ 1) mod cap;
217 b
.len
<- min
(b
.len
+ 1) cap;
220 let cbempty b
= b
.len
= 0;;
222 let cbgetg b circular dir
=
226 let rc = b
.rc + dir
in
238 else bound rc 0 (b
.len
-1)
244 let cbget b
= cbgetg b
false;;
245 let cbgetc b
= cbgetg b
true;;
247 let drawstring size x y s
=
249 Gl.enable `texture_2d
;
250 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
251 ignore
(drawstr size x y s
);
253 Gl.disable `texture_2d
;
256 let drawstring1 size x y s
=
260 let drawstring2 size x y fmt
=
261 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
280 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
281 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
282 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
283 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
284 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
285 dolog
" column %d" l
.pagecol
;
289 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
291 dolog
" x0,y0=(% f, % f)" x0 y0
;
292 dolog
" x1,y1=(% f, % f)" x1 y1
;
293 dolog
" x2,y2=(% f, % f)" x2 y2
;
294 dolog
" x3,y3=(% f, % f)" x3 y3
;
298 type multicolumns
= multicol
* pagegeom
299 and singlecolumn
= pagegeom
300 and splitcolumns
= columncount
* pagegeom
301 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
302 and multicol
= columncount
* covercount
* covercount
304 and columncount
= int
305 and covercount
= int;;
312 { mutable scrollbw
: int
313 ; mutable scrollh
: int
314 ; mutable scrollb
: scrollb
315 ; mutable icase
: bool
316 ; mutable preload
: bool
317 ; mutable pagebias
: int
318 ; mutable verbose
: bool
319 ; mutable debug
: bool
320 ; mutable scrollstep
: int
321 ; mutable hscrollstep
: int
322 ; mutable maxhfit
: bool
323 ; mutable crophack
: bool
324 ; mutable autoscrollstep
: int
325 ; mutable maxwait
: float option
326 ; mutable hlinks
: bool
327 ; mutable underinfo
: bool
328 ; mutable interpagespace
: interpagespace
329 ; mutable zoom
: float
330 ; mutable presentation
: bool
331 ; mutable angle
: angle
332 ; mutable cwinw
: int
333 ; mutable cwinh
: int
334 ; mutable savebmarks
: bool
335 ; mutable fitmodel
: fitmodel
336 ; mutable trimmargins
: trimmargins
337 ; mutable trimfuzz
: irect
338 ; mutable memlimit
: memsize
339 ; mutable texcount
: texcount
340 ; mutable sliceheight
: sliceheight
341 ; mutable thumbw
: width
342 ; mutable jumpback
: bool
343 ; mutable bgcolor
: (float * float * float)
344 ; mutable bedefault
: bool
345 ; mutable tilew
: int
346 ; mutable tileh
: int
347 ; mutable mustoresize
: memsize
348 ; mutable checkers
: bool
349 ; mutable aalevel
: int
350 ; mutable urilauncher
: string
351 ; mutable pathlauncher
: string
352 ; mutable colorspace
: colorspace
353 ; mutable invert
: bool
354 ; mutable colorscale
: float
355 ; mutable redirectstderr
: bool
356 ; mutable ghyllscroll
: (int * int * int) option
357 ; mutable columns
: columns
358 ; mutable beyecolumns
: columncount
option
359 ; mutable selcmd
: string
360 ; mutable paxcmd
: string
361 ; mutable updatecurs
: bool
362 ; mutable keyhashes
: (string * keyhash
) list
363 ; mutable hfsize
: int
364 ; mutable pgscale
: float
365 ; mutable usepbo
: bool
366 ; mutable wheelbypage
: bool
367 ; mutable stcmd
: string
368 ; mutable riani
: bool
369 ; mutable pax
: (float * int * int) ref option
370 ; mutable paxmark
: mark
373 | Csingle
of singlecolumn
374 | Cmulti
of multicolumns
375 | Csplit
of splitcolumns
378 type anchor
= pageno
* top
* dtop
;;
380 type outline
= string * int * anchor
;;
382 type rect
= float * float * float * float * float * float * float * float;;
384 type tile
= opaque
* pixmapsize
* elapsed
385 and elapsed
= float;;
386 type pagemapkey
= pageno
* gen
;;
387 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
391 let emptyanchor = (0, 0.0, 0.0);;
393 type infochange
= | Memused
| Docinfo
| Pdim
;;
395 class type uioh
= object
396 method display
: unit
397 method key
: int -> int -> uioh
398 method button
: int -> bool -> int -> int -> int -> uioh
399 method motion
: int -> int -> uioh
400 method pmotion
: int -> int -> uioh
401 method infochanged
: infochange
-> unit
402 method scrollpw
: (int * float * float)
403 method scrollph
: (int * float * float)
404 method modehash
: keyhash
405 method eformsgs
: bool
409 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
410 | Textentry
of (textentry
* onleave
)
412 | LinkNav
of linktarget
413 and onleave
= leavetextentrystatus
-> unit
414 and leavetextentrystatus
= | Cancel
| Confirm
415 and helpitem
= string * int * action
418 | Action
of (uioh
-> uioh
)
420 | Ltexact
of (pageno
* int)
424 let isbirdseye = function Birdseye _
-> true | _
-> false;;
425 let istextentry = function Textentry _
-> true | _
-> false;;
429 | Loading
of (page
* gen
)
431 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
433 | Outlining
of outline list
436 let emptykeyhash = Hashtbl.create
0;;
437 let nouioh : uioh
= object (self
)
439 method key _ _
= self
440 method button _ _ _ _ _
= self
441 method motion _ _
= self
442 method pmotion _ _
= self
443 method infochanged _
= ()
444 method scrollpw
= (0, nan
, nan
)
445 method scrollph
= (0, nan
, nan
)
446 method modehash
= emptykeyhash
447 method eformsgs
= false
451 { mutable sr
: Unix.file_descr
452 ; mutable sw
: Unix.file_descr
453 ; mutable wsfd
: Unix.file_descr
454 ; mutable errfd
: Unix.file_descr
option
455 ; mutable stderr
: Unix.file_descr
456 ; mutable errmsgs
: Buffer.t
457 ; mutable newerrmsgs
: bool
461 ; mutable anchor
: anchor
462 ; mutable ranchors
: (string * string * anchor
* string) list
464 ; mutable layout
: page list
465 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
466 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
467 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
468 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
469 ; mutable pagecount
: int
470 ; mutable currently
: currently
471 ; mutable mstate
: mstate
472 ; mutable searchpattern
: string
473 ; mutable rects
: (pageno
* recttype
* rect
) list
474 ; mutable rects1
: (pageno
* recttype
* rect
) list
475 ; mutable text
: string
476 ; mutable winstate
: Wsi.winstate list
477 ; mutable mode
: mode
478 ; mutable uioh
: uioh
479 ; mutable outlines
: outline array
480 ; mutable bookmarks
: outline list
481 ; mutable path
: string
482 ; mutable password
: string
483 ; mutable nameddest
: string
484 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
485 ; mutable memused
: memsize
487 ; mutable throttle
: (page list
* int * float) option
488 ; mutable autoscroll
: int option
489 ; mutable ghyll
: (int option -> unit)
490 ; mutable help
: helpitem array
491 ; mutable docinfo
: (int * string) list
492 ; mutable texid
: GlTex.texture_id
option
494 ; mutable prevzoom
: (float * int)
495 ; mutable progress
: float
496 ; mutable redisplay
: bool
497 ; mutable mpos
: mpos
498 ; mutable keystate
: keystate
499 ; mutable glinks
: bool
500 ; mutable prevcolumns
: (columns
* float) option
503 ; mutable reprf
: (unit -> unit)
504 ; mutable origin
: string
505 ; mutable roam
: (unit -> unit)
506 ; mutable bzoom
: bool
509 { pat
: string circbuf
510 ; pag
: string circbuf
511 ; nav
: anchor circbuf
512 ; sel
: string circbuf
519 ; scrollb
= scrollbhv lor scrollbvv
535 ; presentation
= false
540 ; fitmodel
= FitProportional
541 ; trimmargins
= false
542 ; trimfuzz
= (0,0,0,0)
543 ; memlimit
= 32 lsl 20
548 ; bgcolor
= (0.5, 0.5, 0.5)
552 ; mustoresize
= 256 lsl 20
557 | Plinux
| Pfreebsd
| Pdragonflybsd
558 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
559 | Posx
-> "open \"%s\""
560 | Pcygwin
-> "cygstart \"%s\""
561 | Punknown
-> "echo %s")
562 ; pathlauncher
= "lp \"%s\""
565 | Plinux
| Pfreebsd
| Pdragonflybsd
566 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
574 ; redirectstderr
= false
576 ; columns
= Csingle
[||]
582 ; wheelbypage
= false
583 ; stcmd
= "echo SyncTex"
586 ; paxmark
= Mark_word
588 let mk n
= (n
, Hashtbl.create
1) in
602 let wtmode = ref false;;
603 let cxack = ref false;;
605 let findkeyhash c name
=
606 try List.assoc name c
.keyhashes
607 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
610 let conf = { defconf with angle
= defconf.angle
};;
612 let pgscale h
= truncate
(float h
*. conf.pgscale);;
615 { mutable fontsize
: int
616 ; mutable wwidth
: float
617 ; mutable maxrows
: int
629 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
630 let len = String.length s
in
631 if colonpos >= 0 && colonpos + 3 < len
633 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
636 try String.rindex_from s
colonpos ' '
640 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
643 | "http" | "ftp" | "mailto" ->
645 try String.index_from s
colonpos ' '
646 with Not_found
-> len
648 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
656 if emptystr
conf.urilauncher
657 then print_endline uri
659 let url = geturl uri
in
661 then Printf.eprintf
"obtained empty url from uri %S" uri
663 let re = Str.regexp
"%s" in
664 let command = Str.global_replace
re url conf.urilauncher
in
668 "failed to execute `%s': %s\n" command (exntos exn
);
674 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
675 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
679 let strings = version () :: "" :: Help.keys
in
682 let url = geturl s
in
684 then (s
, 0, Action
(fun u
-> gotouri url; u
))
685 else (s
, 0, Noaction
)
690 let firstgeomcmds = "", [];;
691 let noreprf () = ();;
698 ; stderr
= Unix.stderr
699 ; errmsgs
= Buffer.create
0
704 ; anchor
= emptyanchor
708 ; tilelru
= Queue.create
()
709 ; pagemap
= Hashtbl.create
10
710 ; tilemap
= Hashtbl.create
10
726 ; geomcmds
= firstgeomcmds
728 { nav
= cbnew 10 emptyanchor
741 ; prevzoom
= (1.0, 0)
753 ; roam
= (fun () -> ())
759 if (conf.scrollb
land scrollbhv = 0)
760 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
766 if (conf.scrollb
land scrollbvv = 0)
771 let wadjsb w
= w
- vscrollw ();;
774 fstate.fontsize
<- n
;
775 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
776 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
782 Printf.kprintf prerr_endline fmt
784 Printf.kprintf ignore fmt
788 if emptystr
conf.pathlauncher
789 then print_endline
state.path
791 let re = Str.regexp
"%s" in
792 let command = Str.global_replace
re state.path
conf.pathlauncher
in
795 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
801 type 'a t
= | Res
of 'a
| Exn
of exn
;;
804 try Res
(Unix.pipe ())
809 try tempfailureretry
Unix.close fd
810 with exn
-> f
(exntos exn
)
814 try Res
(tempfailureretry
Unix.dup fd
)
819 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
824 let redirectstderr () =
825 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
826 if conf.redirectstderr
828 match Ne.pipe () with
830 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
833 begin match Ne.dup Unix.stderr
with
835 dolog
"failed to dup stderr: %s" (exntos exn
);
836 Ne.clo r
(clofail "pipe/r");
837 Ne.clo w
(clofail "pipe/w");
839 | Ne.Res dupstderr
->
840 begin match Ne.dup2 w
Unix.stderr
with
842 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
843 Ne.clo dupstderr
(clofail "stderr duplicate");
844 Ne.clo r
(clofail "redir pipe/r");
845 Ne.clo w
(clofail "redir pipe/w");
848 state.stderr
<- dupstderr
;
849 state.errfd
<- Some r
;
853 state.newerrmsgs
<- false;
854 begin match state.errfd
with
856 begin match Ne.dup2 state.stderr
Unix.stderr
with
858 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
860 Ne.clo fd
(clofail "dup of stderr");
865 prerr_string
(Buffer.contents
state.errmsgs
);
867 Buffer.clear
state.errmsgs
;
873 let postRedisplay who
=
875 then prerr_endline
("redisplay for " ^ who
);
876 state.redisplay
<- true;
880 let getopaque pageno
=
881 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
882 with Not_found
-> None
885 let putopaque pageno opaque
=
886 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
889 let pagetranslatepoint l x y
=
890 let dy = y
- l
.pagedispy
in
891 let y = dy + l
.pagey
in
892 let dx = x
- l
.pagedispx
in
893 let x = dx + l
.pagex
in
897 let onppundermouse g
x y d
=
900 begin match getopaque l
.pageno
with
902 let x0 = l
.pagedispx
in
903 let x1 = x0 + l
.pagevw
in
904 let y0 = l
.pagedispy
in
905 let y1 = y0 + l
.pagevh
in
906 if y >= y0 && y <= y1 && x >= x0 && x <= x1
908 let px, py
= pagetranslatepoint l
x y in
909 match g opaque l
px py
with
922 let g opaque l
px py
=
925 match rectofblock opaque
px py
with
927 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
928 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
929 G.postRedisplay "getunder";
932 match whatsunder opaque
px py
with
934 | under
-> Some under
936 onppundermouse g x y Unone
941 match unproject opaque
x y with
942 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
945 onppundermouse g x y None
;
949 state.text
<- Printf.sprintf
"%c%s" c s
;
950 G.postRedisplay "showtext";
954 let g opaque l
px py
=
955 if markunder opaque
px py
conf.paxmark
958 match getopaque l
.pageno
with
961 match Ne.pipe () with
965 "can not create mark pipe: %s"
968 let doclose what fd
=
969 Ne.clo fd
(fun msg
->
970 dolog
"%s close failed: %s" what msg
)
973 popen conf.paxcmd
[r
, 0; w
, -1];
974 copysel w opaque
false;
976 G.postRedisplay "paxunder";
978 dolog
"can not execute %S: %s"
979 conf.paxcmd
(exntos exn
);
986 G.postRedisplay "paxunder";
987 if conf.paxmark
= Mark_page
990 match getopaque l
.pageno
with
992 | Some opaque
-> clearmark opaque
) state.layout
;
994 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
998 match Ne.pipe () with
1000 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1003 try popen conf.selcmd
[r
, 0; w
, -1]; true
1006 (Printf.sprintf
"failed to execute %s: %s"
1007 conf.selcmd
(exntos exn
));
1011 Ne.clo fd
(fun msg
->
1012 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1018 let l = String.length s
in
1019 let n = tempfailureretry
(Unix.write w s
0) l in
1024 "failed to write %d characters to sel pipe, wrote %d"
1029 (Printf.sprintf
"failed to write to sel pipe: %s"
1038 let undertext = function
1041 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1042 | Utext s
-> "font: " ^ s
1043 | Uunexpected s
-> "unexpected: " ^ s
1044 | Ulaunch s
-> "launch: " ^ s
1045 | Unamed s
-> "named: " ^ s
1046 | Uremote
(filename
, pageno
) ->
1047 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1048 | Uremotedest
(filename
, destname
) ->
1049 Printf.sprintf
"%s: destination %S" filename destname
1052 let updateunder x y =
1053 match getunder x y with
1054 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1056 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1057 Wsi.setcursor
Wsi.CURSOR_INFO
1058 | Ulinkgoto
(pageno
, _
) ->
1060 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1061 Wsi.setcursor
Wsi.CURSOR_INFO
1063 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1064 Wsi.setcursor
Wsi.CURSOR_TEXT
1066 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1067 Wsi.setcursor
Wsi.CURSOR_INHERIT
1069 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1070 Wsi.setcursor
Wsi.CURSOR_INHERIT
1072 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1073 Wsi.setcursor
Wsi.CURSOR_INHERIT
1074 | Uremote
(filename
, pageno
) ->
1075 if conf.underinfo
then showtext 'r'
1076 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1077 Wsi.setcursor
Wsi.CURSOR_INFO
1078 | Uremotedest
(filename
, destname
) ->
1079 if conf.underinfo
then showtext 'r'
1080 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1081 Wsi.setcursor
Wsi.CURSOR_INFO
1084 let showlinktype under
=
1090 let s = undertext under
in
1095 let b = Buffer.create
(String.length
s + 1) in
1096 Buffer.add_string
b s;
1097 Buffer.add_char
b c
;
1101 module type TextEnumType
=
1105 val names
: string array
1108 module TextEnumMake
(Ten
: TextEnumType
) =
1110 let names = Ten.names;;
1111 let to_int (t
: Ten.t
) = Obj.magic t
;;
1112 let to_string t
= names.(to_int t
);;
1113 let of_int n : Ten.t
= Obj.magic
n;;
1116 if i
= Array.length
names
1117 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1119 if Ten.names.(i
) = s
1126 module CSTE
= TextEnumMake
(struct
1127 type t
= colorspace
;;
1128 let name = "colorspace";;
1129 let names = [|"rgb"; "bgr"; "gray"|];;
1132 module MTE
= TextEnumMake
(struct
1135 let names = [|"page"; "block"; "line"; "word"|];;
1138 module FMTE
= TextEnumMake
(struct
1140 let name = "fitmodel";;
1141 let names = [|"width"; "proportional"; "page"|];;
1144 let intentry_with_suffix text key
=
1146 if key
>= 32 && key
< 127
1150 match Char.lowercase
c with
1152 let text = addchar text c in
1155 | 'k'
| 'm'
| '
g'
->
1156 let text = addchar text c in
1160 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1164 let multicolumns_to_string (n, a
, b) =
1166 then Printf.sprintf
"%d" n
1167 else Printf.sprintf
"%d,%d,%d" n a
b;
1170 let multicolumns_of_string s =
1172 (int_of_string
s, 0, 0)
1174 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1176 then failwith
"subtly broken"; (n, a
, b)
1182 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1183 if n != 4 then error
"incomplete read(len) = %d" n;
1185 lor (Char.code
s.[0] lsl 24)
1186 lor (Char.code
s.[1] lsl 16)
1187 lor (Char.code
s.[2] lsl 8)
1188 lor (Char.code
s.[3] lsl 0)
1190 let s = String.create
len in
1191 let n = tempfailureretry
(Unix.read fd
s 0) len in
1192 if n != len then error
"incomplete read(data) %d vs %d" n len;
1196 let btod b = if b then 1 else 0;;
1199 let b = Buffer.create
16 in
1200 Buffer.add_string
b "llll";
1203 let s = Buffer.contents
b in
1204 let n = String.length
s in
1206 (* dolog "wcmd %S" (String.sub s 4 len); *)
1207 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1208 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1209 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1210 s.[3] <- Char.chr
(len land 0xff);
1211 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1212 if n'
!= n then error
"write failed %d vs %d" n'
n;
1217 let d = state.winh
- h
in
1218 max
conf.interpagespace
((d + 1) / 2)
1221 let rowyh (c, coverA
, coverB
) b n =
1222 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1224 let _, _, vy
, (_, _, h
, _) = b.(n) in
1227 let n'
= n - coverA
in
1230 let e = min
state.pagecount
(s + c) in
1231 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1232 let _, _, y, (_, _, h
, _) = b.(m
) in
1233 let miny = min
miny y in
1234 let maxh = max
maxh h
in
1235 find (m
+1) miny maxh
1240 match conf.columns
with
1241 | Cmulti
((_, _, _) as cl
, b) ->
1242 if Array.length
b > 0
1244 let y, h
= rowyh cl
b (Array.length
b - 1) in
1245 y + h
+ (if conf.presentation
then calcips h
else 0)
1248 if Array.length
b > 0
1250 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1251 y + h
+ (if conf.presentation
then calcips h
else 0)
1254 if Array.length
b > 0
1256 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1261 let getpageywh pageno
=
1262 let pageno = bound pageno 0 (state.pagecount
-1) in
1263 match conf.columns
with
1265 if Array.length
b = 0
1268 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1270 if conf.presentation
1276 if Array.length
b = 0
1279 let y, h
= rowyh cl
b pageno in
1280 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1282 if conf.presentation
1288 if Array.length
b = 0
1292 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1296 let getpageyh pageno =
1297 let y,_,h
= getpageywh pageno in
1301 let getpagedim pageno =
1304 | (n, _, _, _) as pdim
:: rest
->
1306 then (if n = pageno then pdim
else ppdim
)
1311 f (-1, -1, -1, -1) state.pdims
1314 let getpagey pageno = fst
(getpageyh pageno);;
1316 let nogeomcmds cmds
=
1318 | s, [] -> emptystr
s
1323 let ((c, coverA
, coverB
) as cl
), b =
1324 match conf.columns
with
1325 | Csingle
b -> (1, 0, 0), b
1326 | Cmulti
(c, b) -> c, b
1327 | Csplit
(_, b) -> (1, 0, 0), b
1329 if Array.length
b = 0
1332 let rec bsearch nmin nmax
=
1334 then bound nmin
0 (state.pagecount
-1)
1336 let n = (nmax
+ nmin
) / 2 in
1337 let vy, h
= rowyh cl
b n in
1339 if conf.presentation
1341 let ips = calcips h
in
1342 let y0 = vy - ips in
1343 let y1 = vy + h
+ ips in
1347 then 0, vy + h
+ conf.interpagespace
1349 let y0 = vy - conf.interpagespace
in
1350 y0, y0 + h
+ conf.interpagespace
1353 if y >= y0 && y < y1
1360 if n < state.pagecount
- coverB
1361 then ((n-coverA
)/c)*c + coverA
1368 then bsearch (n+1) nmax
1369 else bsearch nmin
(n-1)
1372 let r = bsearch 0 (state.pagecount
-1) in
1376 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1377 let sh = sh - (hscrollh ()) in
1378 let rec fold accu
n =
1379 if n = Array.length
b
1382 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1385 || n = state.pagecount
- coverB
1386 || (n - coverA
) mod columns
= columns
- 1)
1392 let pagey = max
0 (y - vy) in
1393 let pagedispy = if pagey > 0 then 0 else vy - y in
1394 let pagedispx, pagex
=
1396 if n = coverA
- 1 || n = state.pagecount
- coverB
1397 then state.x + (wadjsb state.winw
- w
) / 2
1398 else dx + xoff
+ state.x
1405 let vw = wadjsb state.winw
- pagedispx in
1406 let pw = w
- pagex
in
1409 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1410 if pagevw > 0 && pagevh > 0
1414 ; pagedimno
= pdimno
1421 ; pagedispx = pagedispx
1422 ; pagedispy = pagedispy
1434 if Array.length
b = 0
1436 else List.rev
(fold [] (page_of_y y))
1439 let layoutS (columns
, b) y sh =
1440 let sh = sh - hscrollh () in
1441 let rec fold accu n =
1442 if n = Array.length
b
1445 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1452 let x = xoff
+ state.x in
1453 let pagey = max
0 (y - vy) in
1454 let pagedispy = if pagey > 0 then 0 else vy - y in
1455 let pagedispx, pagex
=
1469 let pagecolw = pagew
/columns
in
1471 if pagecolw < state.winw
1472 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1476 let vw = wadjsb state.winw
- pagedispx in
1477 let pw = pagew
- pagex
in
1480 let pagevw = min
pagevw pagecolw in
1481 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1482 if pagevw > 0 && pagevh > 0
1485 { pageno = n/columns
1486 ; pagedimno
= pdimno
1493 ; pagedispx = pagedispx
1494 ; pagedispy = pagedispy
1495 ; pagecol
= n mod columns
1506 List.rev
(fold [] 0)
1510 if nogeomcmds state.geomcmds
1512 match conf.columns
with
1513 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1514 | Cmulti
c -> layoutN c y sh
1515 | Csplit
s -> layoutS s y sh
1520 let y = state.y + incr
in
1522 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1527 let tilex = l.pagex
mod conf.tilew
in
1528 let tiley = l.pagey mod conf.tileh
in
1530 let col = l.pagex
/ conf.tilew
in
1531 let row = l.pagey / conf.tileh
in
1533 let rec rowloop row y0 dispy h
=
1537 let dh = conf.tileh
- y0 in
1538 let dh = min h
dh in
1539 let rec colloop col x0 dispx w
=
1543 let dw = conf.tilew
- x0 in
1544 let dw = min w
dw in
1546 f col row dispx dispy
x0 y0 dw dh;
1547 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1550 colloop col tilex l.pagedispx l.pagevw;
1551 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1554 if l.pagevw > 0 && l.pagevh > 0
1555 then rowloop row tiley l.pagedispy l.pagevh;
1558 let gettileopaque l col row =
1560 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1562 try Some
(Hashtbl.find state.tilemap
key)
1563 with Not_found
-> None
1566 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1567 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1568 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1571 let drawtiles l color
=
1573 let f col row x y tilex tiley w h
=
1574 match gettileopaque l col row with
1575 | Some
(opaque
, _, t
) ->
1576 let params = x, y, w
, h
, tilex, tiley in
1580 GlFunc.blend_func `zero `one_minus_src_color
;
1582 drawtile
params opaque
;
1584 then Gl.disable `blend
;
1587 let s = Printf.sprintf
1591 let w = measurestr
fstate.fontsize
s in
1592 GlMisc.push_attrib
[`current
];
1593 GlDraw.color
(0.0, 0.0, 0.0);
1595 (float (x-2), float (y-2))
1596 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1597 GlDraw.color
(1.0, 1.0, 1.0);
1598 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1599 GlMisc.pop_attrib
();
1604 let lw = wadjsb state.winw
- x in
1607 let lh = state.winh
- y in
1610 begin match state.texid
with
1612 Gl.enable `texture_2d
;
1613 GlTex.bind_texture `texture_2d id
;
1616 and x1 = float (x+w)
1617 and y1 = float (y+h
) in
1619 let tw = float w /. 16.0
1620 and th
= float h
/. 16.0 in
1621 let tx0 = float tilex /. 16.0
1622 and ty0
= float tiley /. 16.0 in
1624 and ty1
= ty0
+. th
in
1625 GlDraw.begins `quads
;
1626 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1627 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1628 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1629 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1632 Gl.disable `texture_2d
;
1634 GlDraw.color
(1.0, 1.0, 1.0);
1637 (float (x+w), float (y+h
));
1639 if w > 128 && h
> fstate.fontsize
+ 10
1641 GlDraw.color
(0.0, 0.0, 0.0);
1644 then (col*conf.tilew
, row*conf.tileh
)
1647 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1654 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1656 let tilevisible1 l x y =
1658 and ax1
= l.pagex
+ l.pagevw
1660 and ay1
= l.pagey + l.pagevh in
1664 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1665 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1667 let rx0 = max
ax0 bx0
1668 and ry0
= max ay0 by0
1669 and rx1
= min ax1
bx1
1670 and ry1
= min ay1 by1
in
1672 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1673 nonemptyintersection
1676 let tilevisible layout n x y =
1677 let rec findpageinlayout m
= function
1678 | l :: rest
when l.pageno = n ->
1679 tilevisible1 l x y || (
1680 match conf.columns
with
1681 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1684 | _ :: rest
-> findpageinlayout 0 rest
1687 findpageinlayout 0 layout;
1690 let tileready l x y =
1691 tilevisible1 l x y &&
1692 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1695 let tilepage n p
layout =
1696 let rec loop = function
1700 let f col row _ _ _ _ _ _ =
1701 if state.currently
= Idle
1703 match gettileopaque l col row with
1706 let x = col*conf.tilew
1707 and y = row*conf.tileh
in
1709 let w = l.pagew
- x in
1713 let h = l.pageh
- y in
1718 then getpbo
w h conf.colorspace
1721 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1724 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1725 conf.tilew
, conf.tileh
1734 if nogeomcmds state.geomcmds
1738 let preloadlayout y =
1739 let y = if y < state.winh
then 0 else y - state.winh
in
1740 let h = state.winh
*3 in
1745 let rec loop pages
=
1746 if state.currently
!= Idle
1751 begin match getopaque l.pageno with
1753 wcmd "page %d %d" l.pageno l.pagedimno
;
1754 state.currently
<- Loading
(l, state.gen
);
1756 tilepage l.pageno opaque pages
;
1761 if nogeomcmds state.geomcmds
1767 if conf.preload && state.currently
= Idle
1768 then load (preloadlayout state.y);
1771 let layoutready layout =
1772 let rec fold all ls
=
1773 all
&& match ls
with
1775 let seen = ref false in
1776 let allvisible = ref true in
1777 let foo col row _ _ _ _ _ _ =
1779 allvisible := !allvisible &&
1780 begin match gettileopaque l col row with
1786 fold (!seen && !allvisible) rest
1789 let alltilesvisible = fold true layout in
1794 let y = bound y 0 state.maxy
in
1795 let y, layout, proceed
=
1796 match conf.maxwait
with
1797 | Some time
when state.ghyll
== noghyll ->
1798 begin match state.throttle
with
1800 let layout = layout y state.winh
in
1801 let ready = layoutready layout in
1805 state.throttle
<- Some
(layout, y, now ());
1807 else G.postRedisplay "gotoy showall (None)";
1809 | Some
(_, _, started
) ->
1810 let dt = now () -. started
in
1813 state.throttle
<- None
;
1814 let layout = layout y state.winh
in
1816 G.postRedisplay "maxwait";
1823 let layout = layout y state.winh
in
1824 if not
!wtmode || layoutready layout
1825 then G.postRedisplay "gotoy ready";
1831 state.layout <- layout;
1832 begin match state.mode
with
1833 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1834 let rec loop = function
1836 state.mode
<- LinkNav
(Ltgendir
0)
1837 | l :: _ when l.pageno = pageno ->
1838 begin match getopaque pageno with
1840 state.mode
<- LinkNav
(Ltgendir
0)
1842 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1843 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1844 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1845 then state.mode
<- LinkNav
(Ltgendir
0)
1847 | _ :: rest
-> loop rest
1852 begin match state.mode
with
1853 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1854 if not
(pagevisible layout pageno)
1856 match state.layout with
1859 state.mode
<- Birdseye
(
1860 conf, leftx
, l.pageno, hooverpageno
, anchor
1863 | LinkNav
(Ltgendir dir
as lt
) ->
1865 let rec loop = function
1868 match getopaque l.pageno with
1874 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1876 if dir
> 0 then LDfirst
else LDlast
1882 | Lnotfound
-> loop rest
1884 showlinktype (getlink opaque
n);
1885 Ltexact
(l.pageno, n)
1889 state.mode
<- LinkNav
linknav
1894 state.ghyll
<- noghyll;
1897 let mx, my
= state.mpos
in
1902 let conttiling pageno opaque
=
1903 tilepage pageno opaque
1904 (if conf.preload then preloadlayout state.y else state.layout)
1907 let gotoy_and_clear_text y =
1908 if not
conf.verbose
then state.text <- "";
1914 let coloff = l.pagecol
* l.pageh
in
1915 float (l.pagey + coloff) /. float l.pageh
1922 if conf.presentation
1923 then float l.pagedispy /. float (calcips l.pageh
)
1924 else float l.pagedispy /. float conf.interpagespace
1927 (l.pageno, top, dtop)
1931 match state.layout with
1932 | l :: _ -> getanchor1 l
1934 let n = page_of_y state.y in
1938 let y, h = getpageyh n in
1939 let dy = y - state.y in
1941 if conf.presentation
1943 let ips = calcips h in
1944 float (dy + ips) /. float ips
1946 float dy /. float conf.interpagespace
1951 let getanchory (n, top, dtop) =
1952 let y, h = getpageyh n in
1953 if conf.presentation
1955 let ips = calcips h in
1956 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1958 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1961 let gotoanchor anchor
=
1962 gotoy (getanchory anchor
);
1966 cbput state.hists
.nav
(getanchor ());
1970 let anchor = cbgetc state.hists
.nav dir
in
1975 let scroll f n a
b =
1976 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1978 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1980 then s (float f /. float a
)
1983 then 1.0 -. s ((float (f-b) /. float (n-b)))
1989 let ins = float a
*. 0.5
1990 and outs
= float (n-b) *. 0.5 in
1992 ins +. outs
+. float ones
1994 let rec set (_N
, _A
, _B
) y sy
=
1995 let sum = summa _N _A _B
in
1996 let dy = float (y - sy
) in
2000 then state.ghyll
<- noghyll
2003 let s = scroll n _N _A _B
in
2004 let y1 = y1 +. ((s *. dy) /. sum) in
2005 gotoy_and_clear_text (truncate
y1);
2006 state.ghyll
<- gf (n+1) y1;
2010 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2012 gf 0 (float state.y)
2015 match conf.ghyllscroll
with
2017 gotoy_and_clear_text y
2019 if state.ghyll
== noghyll
2020 then set nab
y state.y
2021 else state.ghyll
(Some
y)
2024 let gotopage n top =
2025 let y, h = getpageyh n in
2026 let y = y + (truncate
(top *. float h)) in
2030 let gotopage1 n top =
2031 let y = getpagey n in
2036 let invalidate s f =
2041 match state.geomcmds
with
2042 | ps
, [] when emptystr ps
->
2044 state.geomcmds
<- s, [];
2047 state.geomcmds
<- ps
, [s, f];
2049 | ps
, (s'
, _) :: rest
when s'
= s ->
2050 state.geomcmds
<- ps
, ((s, f) :: rest
);
2053 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2057 Hashtbl.iter
(fun _ opaque
->
2058 wcmd "freepage %s" opaque
;
2060 Hashtbl.clear
state.pagemap
;
2064 if not
(Queue.is_empty
state.tilelru
)
2066 Queue.iter
(fun (k
, p
, s) ->
2067 wcmd "freetile %s" p
;
2068 state.memused
<- state.memused
- s;
2069 Hashtbl.remove
state.tilemap k
;
2071 state.uioh#infochanged Memused
;
2072 Queue.clear
state.tilelru
;
2078 let h = truncate
(float h*.conf.zoom
) in
2079 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2083 let opendoc path password
=
2085 state.password
<- password
;
2086 state.gen
<- state.gen
+ 1;
2087 state.docinfo
<- [];
2090 setaalevel
conf.aalevel
;
2092 if emptystr
state.origin
2096 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2097 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2098 invalidate "reqlayout"
2100 wcmd "reqlayout %d %d %d %s\000"
2101 conf.angle
(FMTE.to_int conf.fitmodel
)
2102 (stateh state.winh
) state.nameddest
2107 state.anchor <- getanchor ();
2108 opendoc state.path
state.password
;
2112 let c = c *. conf.colorscale
in
2116 let scalecolor2 (r, g, b) =
2117 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2120 let docolumns = function
2122 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2123 let rec loop pageno pdimno pdim
y ph pdims
=
2124 if pageno = state.pagecount
2127 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2129 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2130 pdimno+1, pdim
, rest
2134 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2136 (if conf.presentation
2137 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2138 else (if pageno = 0 then 0 else conf.interpagespace
)
2141 a.(pageno) <- (pdimno, x, y, pdim
);
2142 loop (pageno+1) pdimno pdim
(y + h) h pdims
2144 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2145 conf.columns
<- Csingle
a;
2147 | Cmulti
((columns
, coverA
, coverB
), _) ->
2148 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2149 let rec loop pageno pdimno pdim
x y rowh pdims
=
2150 let rec fixrow m
= if m
= pageno then () else
2151 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2154 let y = y + (rowh
- h) / 2 in
2155 a.(m
) <- (pdimno, x, y, pdim
);
2159 if pageno = state.pagecount
2160 then fixrow (((pageno - 1) / columns
) * columns
)
2162 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2164 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2165 pdimno+1, pdim
, rest
2170 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2172 let x = (wadjsb state.winw
- w) / 2 in
2174 if conf.presentation
then calcips h else conf.interpagespace
in
2175 x, y + ips + rowh
, h
2178 if (pageno - coverA
) mod columns
= 0
2180 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2182 if conf.presentation
2184 let ips = calcips h in
2185 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2187 y + (if pageno = 0 then 0 else conf.interpagespace
)
2191 else x, y, max rowh
h
2195 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2198 if pageno = columns
&& conf.presentation
2200 let ips = calcips rowh
in
2201 for i
= 0 to pred columns
2203 let (pdimno, x, y, pdim
) = a.(i
) in
2204 a.(i
) <- (pdimno, x, y+ips, pdim
)
2210 fixrow (pageno - columns
);
2215 a.(pageno) <- (pdimno, x, y, pdim
);
2216 let x = x + w + xoff
*2 + conf.interpagespace
in
2217 loop (pageno+1) pdimno pdim
x y rowh' pdims
2219 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2220 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2223 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2224 let rec loop pageno pdimno pdim
y pdims
=
2225 if pageno = state.pagecount
2228 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2230 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2231 pdimno+1, pdim
, rest
2236 let rec loop1 n x y =
2237 if n = c then y else (
2238 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2239 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2242 let y = loop1 0 0 y in
2243 loop (pageno+1) pdimno pdim
y pdims
2245 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2246 conf.columns
<- Csplit
(c, a);
2250 docolumns conf.columns
;
2251 state.maxy
<- calcheight ();
2252 if state.reprf
== noreprf
2254 match state.mode
with
2255 | Birdseye
(_, _, pageno, _, _) ->
2256 let y, h = getpageyh pageno in
2257 let top = (state.winh
- h) / 2 in
2258 gotoy (max
0 (y - top))
2259 | _ -> gotoanchor state.anchor
2263 state.reprf
<- noreprf;
2268 GlDraw.viewport
0 0 w h;
2269 let firsttime = state.geomcmds
== firstgeomcmds in
2270 if not
firsttime && nogeomcmds state.geomcmds
2271 then state.anchor <- getanchor ();
2274 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2277 setfontsize fstate.fontsize
;
2278 GlMat.mode `modelview
;
2279 GlMat.load_identity
();
2281 GlMat.mode `projection
;
2282 GlMat.load_identity
();
2283 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2284 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2285 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2290 else float state.x /. float state.w
2292 invalidate "geometry"
2296 then state.x <- truncate
(relx *. float w);
2298 match conf.columns
with
2300 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2301 | Csplit
(c, _) -> w * c
2303 wcmd "geometry %d %d %d"
2304 w (stateh h) (FMTE.to_int conf.fitmodel
)
2309 let len = String.length
state.text in
2312 match state.mode
with
2313 | Textentry
_ | View
| LinkNav
_ ->
2314 let h, _, _ = state.uioh#scrollpw
in
2320 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2321 (x+.w, float (state.winh
- hscrollh))
2324 let w = float (wadjsb state.winw
- 1) in
2325 if state.progress
>= 0.0 && state.progress
< 1.0
2327 GlDraw.color
(0.3, 0.3, 0.3);
2328 let w1 = w *. state.progress
in
2330 GlDraw.color
(0.0, 0.0, 0.0);
2334 GlDraw.color
(0.0, 0.0, 0.0);
2338 GlDraw.color
(1.0, 1.0, 1.0);
2339 drawstring fstate.fontsize
2340 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2343 match state.mode
with
2344 | Textentry
((prefix
, text, _, _, _, _), _) ->
2348 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2350 Printf.sprintf
"%s%s_" prefix
text
2359 if not
(istextentry state.mode
) && state.uioh#eformsgs
2361 let s1 = "(press 'e' to review error messasges)" in
2362 if nonemptystr
s then s ^
" " ^
s1 else s1
2372 let len = Queue.length
state.tilelru
in
2374 match state.throttle
with
2377 then preloadlayout state.y
2379 | Some
(layout, _, _) ->
2383 if state.memused
<= conf.memlimit
2388 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2389 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2390 let (_, pw, ph
, _) = getpagedim n in
2393 && colorspace
= conf.colorspace
2394 && angle
= conf.angle
2398 let x = col*conf.tilew
2399 and y = row*conf.tileh
in
2400 tilevisible (Lazy.force_val
layout) n x y
2402 then Queue.push lruitem
state.tilelru
2405 wcmd "freetile %s" p
;
2406 state.memused
<- state.memused
- s;
2407 state.uioh#infochanged Memused
;
2408 Hashtbl.remove
state.tilemap k
;
2416 let logcurrently = function
2417 | Idle
-> dolog
"Idle"
2418 | Loading
(l, gen
) ->
2419 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2420 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2422 "Tiling %d[%d,%d] page=%s cs=%s angle"
2423 l.pageno col row pageopaque
2424 (CSTE.to_string colorspace
)
2426 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2427 angle gen
conf.angle
state.gen
2429 conf.tilew
conf.tileh
2436 let r = Str.regexp
" " in
2437 fun s -> Str.bounded_split
r s 2;
2440 let onpagerect pageno f =
2442 match conf.columns
with
2443 | Cmulti
(_, b) -> b
2445 | Csplit
(_, b) -> b
2447 if pageno >= 0 && pageno < Array.length
b
2449 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2453 let gotopagexy1 pageno x y =
2454 let _,w1,h1
,leftx
= getpagedim pageno in
2455 let top = y /. (float h1
) in
2456 let left = x /. (float w1) in
2457 let py, w, h = getpageywh pageno in
2458 let wh = state.winh
- hscrollh () in
2459 let x = left *. (float w) in
2460 let x = leftx
+ state.x + truncate
x in
2462 if x < 0 || x >= wadjsb state.winw
2466 let pdy = truncate
(top *. float h) in
2467 let y'
= py + pdy in
2468 let dy = y'
- state.y in
2470 if x != state.x || not
(dy > 0 && dy < wh)
2472 if conf.presentation
2474 if abs
(py - y'
) > wh
2481 if state.x != sx || state.y != sy
2486 let ww = wadjsb state.winw
in
2488 and qy
= pdy / wh in
2490 and y = py + qy
* wh in
2491 let x = if -x + ww > w1 then -(w1-ww) else x
2492 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2494 if conf.presentation
2496 if abs
(py - y'
) > wh
2506 gotoy_and_clear_text y;
2508 else gotoy_and_clear_text state.y;
2511 let gotopagexy pageno x y =
2512 match state.mode
with
2513 | Birdseye
_ -> gotopage pageno 0.0
2514 | _ -> gotopagexy1 pageno x y
2518 (* dolog "%S" cmds; *)
2519 let cl = splitatspace cmds
in
2521 try Scanf.sscanf
s fmt
f
2523 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2528 state.uioh#infochanged Pdim
;
2531 | "clearrects" :: [] ->
2532 state.rects
<- state.rects1
;
2533 G.postRedisplay "clearrects";
2535 | "continue" :: args :: [] ->
2536 let n = scan args "%u" (fun n -> n) in
2537 state.pagecount
<- n;
2538 begin match state.currently
with
2540 state.currently
<- Idle
;
2541 state.outlines
<- Array.of_list
(List.rev
l)
2545 let cur, cmds
= state.geomcmds
in
2547 then failwith
"umpossible";
2549 begin match List.rev cmds
with
2551 state.geomcmds
<- "", [];
2555 state.geomcmds
<- s, List.rev rest
;
2557 if conf.maxwait
= None
&& not
!wtmode
2558 then G.postRedisplay "continue";
2560 | "title" :: args :: [] ->
2563 | "msg" :: args :: [] ->
2566 | "vmsg" :: args :: [] ->
2568 then showtext ' '
args
2570 | "emsg" :: args :: [] ->
2571 Buffer.add_string
state.errmsgs
args;
2572 state.newerrmsgs
<- true;
2573 G.postRedisplay "error message"
2575 | "progress" :: args :: [] ->
2576 let progress, text =
2579 f, String.sub
args pos
(String.length
args - pos
))
2582 state.progress <- progress;
2583 G.postRedisplay "progress"
2585 | "firstmatch" :: args :: [] ->
2586 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2587 scan args "%u %d %f %f %f %f %f %f %f %f"
2588 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2589 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2591 let y = (getpagey pageno) + truncate
y0 in
2594 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2596 | "match" :: args :: [] ->
2597 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2598 scan args "%u %d %f %f %f %f %f %f %f %f"
2599 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2600 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2603 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2605 | "page" :: args :: [] ->
2606 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2607 begin match state.currently
with
2608 | Loading
(l, gen
) ->
2609 vlog "page %d took %f sec" l.pageno t
;
2610 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2611 begin match state.throttle
with
2613 let preloadedpages =
2615 then preloadlayout state.y
2620 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2621 IntSet.empty
preloadedpages
2624 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2625 if not
(IntSet.mem
pageno set)
2627 wcmd "freepage %s" opaque
;
2633 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2636 state.currently
<- Idle
;
2639 tilepage l.pageno pageopaque state.layout;
2641 load preloadedpages;
2642 if pagevisible state.layout l.pageno
2643 && layoutready state.layout
2644 then G.postRedisplay "page";
2647 | Some
(layout, _, _) ->
2648 state.currently
<- Idle
;
2649 tilepage l.pageno pageopaque layout;
2654 dolog
"Inconsistent loading state";
2655 logcurrently state.currently
;
2659 | "tile" :: args :: [] ->
2660 let (x, y, opaque
, size
, t
) =
2661 scan args "%u %u %s %u %f"
2662 (fun x y p size t
-> (x, y, p
, size
, t
))
2664 begin match state.currently
with
2665 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2666 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2669 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2671 wcmd "freetile %s" opaque
;
2672 state.currently
<- Idle
;
2676 puttileopaque l col row gen cs angle opaque size t
;
2677 state.memused
<- state.memused
+ size
;
2678 state.uioh#infochanged Memused
;
2680 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2681 opaque
, size
) state.tilelru
;
2684 match state.throttle
with
2685 | None
-> state.layout
2686 | Some
(layout, _, _) -> layout
2689 state.currently
<- Idle
;
2691 && conf.colorspace
= cs
2692 && conf.angle
= angle
2693 && tilevisible layout l.pageno x y
2694 then conttiling l.pageno pageopaque;
2696 begin match state.throttle
with
2698 preload state.layout;
2700 && conf.colorspace
= cs
2701 && conf.angle
= angle
2702 && tilevisible state.layout l.pageno x y
2703 && (not
!wtmode || layoutready state.layout)
2704 then G.postRedisplay "tile nothrottle";
2706 | Some
(layout, y, _) ->
2707 let ready = layoutready layout in
2711 state.layout <- layout;
2712 state.throttle
<- None
;
2713 G.postRedisplay "throttle";
2720 dolog
"Inconsistent tiling state";
2721 logcurrently state.currently
;
2725 | "pdim" :: args :: [] ->
2726 let (n, w, h, _) as pdim
=
2727 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2730 match conf.fitmodel
, conf.columns
with
2731 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2734 state.uioh#infochanged Pdim
;
2735 state.pdims
<- pdim :: state.pdims
2737 | "o" :: args :: [] ->
2738 let (l, n, t
, h, pos
) =
2739 scan args "%u %u %d %u %n"
2740 (fun l n t
h pos
-> l, n, t
, h, pos
)
2742 let s = String.sub
args pos
(String.length
args - pos
) in
2743 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2744 begin match state.currently
with
2745 | Outlining outlines
->
2746 state.currently
<- Outlining
(outline :: outlines
)
2748 state.currently
<- Outlining
[outline]
2750 dolog
"invalid outlining state";
2751 logcurrently currently
2754 | "a" :: args :: [] ->
2756 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2758 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2760 | "info" :: args :: [] ->
2761 state.docinfo
<- (1, args) :: state.docinfo
2763 | "infoend" :: [] ->
2764 state.uioh#infochanged Docinfo
;
2765 state.docinfo
<- List.rev
state.docinfo
2768 error
"unknown cmd `%S'" cmds
2773 let action = function
2774 | HCprev
-> cbget cb ~
-1
2775 | HCnext
-> cbget cb
1
2776 | HCfirst
-> cbget cb ~
-(cb
.rc)
2777 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2778 and cancel
() = cb
.rc <- rc
2782 let search pattern forward
=
2783 match conf.columns
with
2785 showtext '
!'
"searching does not work properly in split columns mode"
2787 if nonemptystr pattern
2790 match state.layout with
2793 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2795 wcmd "search %d %d %d %d,%s\000"
2796 (btod conf.icase
) pn py (btod forward
) pattern
;
2799 let intentry text key =
2801 if key >= 32 && key < 127
2807 let text = addchar text c in
2811 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2815 let linknentry text key =
2817 if key >= 32 && key < 127
2823 let text = addchar text c in
2827 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2835 let l = String.length
s in
2836 let rec loop pos
n = if pos
= l then n else
2837 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2838 loop (pos
+1) (n*26 + m)
2841 let rec loop n = function
2844 match getopaque l.pageno with
2845 | None
-> loop n rest
2847 let m = getlinkcount opaque
in
2850 let under = getlink opaque
n in
2853 else loop (n-m) rest
2855 loop n state.layout;
2859 let textentry text key =
2860 if key land 0xff00 = 0xff00
2862 else TEcont
(text ^ toutf8
key)
2865 let reqlayout angle fitmodel
=
2866 match state.throttle
with
2868 if nogeomcmds state.geomcmds
2869 then state.anchor <- getanchor ();
2870 conf.angle
<- angle
mod 360;
2873 match state.mode
with
2874 | LinkNav
_ -> state.mode
<- View
2877 conf.fitmodel
<- fitmodel
;
2878 invalidate "reqlayout"
2880 wcmd "reqlayout %d %d %d"
2881 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2886 let settrim trimmargins trimfuzz
=
2887 if nogeomcmds state.geomcmds
2888 then state.anchor <- getanchor ();
2889 conf.trimmargins
<- trimmargins
;
2890 conf.trimfuzz
<- trimfuzz
;
2891 let x0, y0, x1, y1 = trimfuzz
in
2892 invalidate "settrim"
2894 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2899 match state.throttle
with
2901 let zoom = max
0.0001 zoom in
2902 if zoom <> conf.zoom
2904 state.prevzoom
<- (conf.zoom, state.x);
2906 reshape state.winw
state.winh
;
2907 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2910 | Some
(layout, y, started
) ->
2912 match conf.maxwait
with
2916 let dt = now () -. started
in
2924 let setcolumns mode columns coverA coverB
=
2925 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2929 then showtext '
!'
"split mode doesn't work in bird's eye"
2931 conf.columns
<- Csplit
(-columns
, [||]);
2939 conf.columns
<- Csingle
[||];
2944 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2948 reshape state.winw
state.winh
;
2951 let enterbirdseye () =
2952 let zoom = float conf.thumbw
/. float state.winw
in
2953 let birdseyepageno =
2954 let cy = state.winh
/ 2 in
2958 let rec fold best
= function
2961 let d = cy - (l.pagedispy + l.pagevh/2)
2962 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2963 if abs
d < abs dbest
2970 state.mode
<- Birdseye
(
2971 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2974 conf.presentation
<- false;
2975 conf.interpagespace
<- 10;
2976 conf.hlinks
<- false;
2977 conf.fitmodel
<- FitProportional
;
2979 state.mstate
<- Mnone
;
2980 conf.maxwait
<- None
;
2982 match conf.beyecolumns
with
2985 Cmulti
((c, 0, 0), [||])
2986 | None
-> Csingle
[||]
2988 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2991 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2996 reshape state.winw
state.winh
;
2999 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3001 conf.zoom <- c.zoom;
3002 conf.presentation
<- c.presentation
;
3003 conf.interpagespace
<- c.interpagespace
;
3004 conf.maxwait
<- c.maxwait
;
3005 conf.hlinks
<- c.hlinks
;
3006 conf.fitmodel
<- c.fitmodel
;
3007 conf.beyecolumns
<- (
3008 match conf.columns
with
3009 | Cmulti
((c, _, _), _) -> Some
c
3011 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3014 match c.columns
with
3015 | Cmulti
(c, _) -> Cmulti
(c, [||])
3016 | Csingle
_ -> Csingle
[||]
3017 | Csplit
(c, _) -> Csplit
(c, [||])
3021 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3024 reshape state.winw
state.winh
;
3025 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3029 let togglebirdseye () =
3030 match state.mode
with
3031 | Birdseye vals
-> leavebirdseye vals
true
3032 | View
-> enterbirdseye ()
3036 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3037 let pageno = max
0 (pageno - incr
) in
3038 let rec loop = function
3039 | [] -> gotopage1 pageno 0
3040 | l :: _ when l.pageno = pageno ->
3041 if l.pagedispy >= 0 && l.pagey = 0
3042 then G.postRedisplay "upbirdseye"
3043 else gotopage1 pageno 0
3044 | _ :: rest
-> loop rest
3047 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3050 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3051 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3052 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3053 let rec loop = function
3055 let y, h = getpageyh pageno in
3056 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3058 | l :: _ when l.pageno = pageno ->
3059 if l.pagevh != l.pageh
3060 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3061 else G.postRedisplay "downbirdseye"
3062 | _ :: rest
-> loop rest
3067 let optentry mode
_ key =
3068 let btos b = if b then "on" else "off" in
3069 if key >= 32 && key < 127
3071 let c = Char.chr
key in
3075 try conf.scrollstep
<- int_of_string
s with exc
->
3076 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3078 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3083 conf.autoscrollstep
<- int_of_string
s;
3084 if state.autoscroll
<> None
3085 then state.autoscroll
<- Some
conf.autoscrollstep
3087 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3089 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3094 let n, a, b = multicolumns_of_string s in
3095 setcolumns mode
n a b;
3097 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3099 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3104 let zoom = float (int_of_string
s) /. 100.0 in
3107 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3109 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3114 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3116 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3117 begin match mode
with
3119 leavebirdseye beye
false;
3124 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3126 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3131 Some
(int_of_string
s)
3133 state.text <- Printf.sprintf
"bad integer `%s': %s"
3137 | Some angle
-> reqlayout angle
conf.fitmodel
3140 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3143 conf.icase
<- not
conf.icase
;
3144 TEdone
("case insensitive search " ^
(btos conf.icase
))
3147 conf.preload <- not
conf.preload;
3149 TEdone
("preload " ^
(btos conf.preload))
3152 conf.verbose
<- not
conf.verbose
;
3153 TEdone
("verbose " ^
(btos conf.verbose
))
3156 conf.debug
<- not
conf.debug
;
3157 TEdone
("debug " ^
(btos conf.debug
))
3160 conf.maxhfit
<- not
conf.maxhfit
;
3161 state.maxy
<- calcheight ();
3162 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3165 conf.crophack
<- not
conf.crophack
;
3166 TEdone
("crophack " ^
btos conf.crophack
)
3170 match conf.maxwait
with
3172 conf.maxwait
<- Some infinity
;
3173 "always wait for page to complete"
3175 conf.maxwait
<- None
;
3176 "show placeholder if page is not ready"
3181 conf.underinfo
<- not
conf.underinfo
;
3182 TEdone
("underinfo " ^
btos conf.underinfo
)
3185 conf.savebmarks
<- not
conf.savebmarks
;
3186 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3192 match state.layout with
3197 conf.interpagespace
<- int_of_string
s;
3198 docolumns conf.columns
;
3199 state.maxy
<- calcheight ();
3200 let y = getpagey pageno in
3203 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3205 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3209 match conf.fitmodel
with
3210 | FitProportional
-> FitWidth
3211 | _ -> FitProportional
3213 reqlayout conf.angle
fm;
3214 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3217 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3218 TEdone
("trim margins " ^
btos conf.trimmargins
)
3221 conf.invert
<- not
conf.invert
;
3222 TEdone
("invert colors " ^
btos conf.invert
)
3226 cbput state.hists
.sel
s;
3229 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3230 textentry, ondone, true)
3234 then conf.pax
<- Some
(ref (0.0, 0, 0))
3235 else conf.pax
<- None
;
3236 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3239 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3245 class type lvsource
= object
3246 method getitemcount
: int
3247 method getitem
: int -> (string * int)
3248 method hasaction
: int -> bool
3257 method getactive
: int
3258 method getfirst
: int
3259 method getqsearch
: string
3260 method setqsearch
: string -> unit
3264 class virtual lvsourcebase
= object
3265 val mutable m_active
= 0
3266 val mutable m_first
= 0
3267 val mutable m_qsearch
= ""
3268 val mutable m_pan
= 0
3269 method getactive
= m_active
3270 method getfirst
= m_first
3271 method getqsearch
= m_qsearch
3272 method getpan
= m_pan
3273 method setqsearch
s = m_qsearch
<- s
3276 let withoutlastutf8 s =
3277 let len = String.length
s in
3285 let b = Char.code
s.[pos
] in
3286 if b land 0b11000000 = 0b11000000
3291 if Char.code
s.[len-1] land 0x80 = 0
3295 String.sub
s 0 first;
3298 let textentrykeyboard
3299 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3301 if key >= 0xffb0 && key <= 0xffb9
3302 then key - 0xffb0 + 48 else key
3305 state.mode
<- Textentry
(te
, onleave
);
3308 G.postRedisplay "textentrykeyboard enttext";
3310 let histaction cmd
=
3313 | Some
(action, _) ->
3314 state.mode
<- Textentry
(
3315 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3317 G.postRedisplay "textentry histaction"
3320 | 0xff08 -> (* backspace *)
3321 let s = withoutlastutf8 text in
3322 let len = String.length
s in
3323 if cancelonempty
&& len = 0
3326 G.postRedisplay "textentrykeyboard after cancel";
3329 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3332 | 0xff0d | 0xff8d -> (* (kp) enter *)
3335 G.postRedisplay "textentrykeyboard after confirm"
3337 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3338 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3339 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3340 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3342 | 0xff1b -> (* escape*)
3345 begin match opthist
with
3347 | Some
(_, onhistcancel
) -> onhistcancel
()
3351 G.postRedisplay "textentrykeyboard after cancel2"
3354 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3357 | 0xff9f | 0xffff -> () (* delete *)
3360 && key land 0xff00 != 0xff00 (* keyboard *)
3361 && key land 0xfe00 != 0xfe00 (* xkb *)
3362 && key land 0xfd00 != 0xfd00 (* 3270 *)
3364 begin match onkey
text key with
3368 G.postRedisplay "textentrykeyboard after confirm2";
3371 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3375 G.postRedisplay "textentrykeyboard after cancel3"
3378 state.mode
<- Textentry
(te
, onleave
);
3379 G.postRedisplay "textentrykeyboard switch";
3383 vlog "unhandled key %s" (Wsi.keyname
key)
3386 let firstof first active
=
3387 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3388 then max
0 (active
- (fstate.maxrows
/2))
3392 let calcfirst first active
=
3395 let rows = active
- first in
3396 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3400 let scrollph y maxy
=
3401 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3402 let sh = float state.winh
/. sh in
3403 let sh = max
sh (float conf.scrollh
) in
3405 let percent = float y /. float maxy
in
3406 let position = (float state.winh
-. sh) *. percent in
3409 if position +. sh > float state.winh
3410 then float state.winh
-. sh
3416 let coe s = (s :> uioh
);;
3418 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3420 val m_pan
= source#getpan
3421 val m_first
= source#getfirst
3422 val m_active
= source#getactive
3423 val m_qsearch
= source#getqsearch
3424 val m_prev_uioh
= state.uioh
3426 method private elemunder
y =
3427 let n = y / (fstate.fontsize
+1) in
3428 if m_first
+ n < source#getitemcount
3430 if source#hasaction
(m_first
+ n)
3431 then Some
(m_first
+ n)
3438 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3439 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3440 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3441 GlDraw.color
(1., 1., 1.);
3442 Gl.enable `texture_2d
;
3443 let fs = fstate.fontsize
in
3445 let ww = fstate.wwidth
in
3446 let tabw = 30.0*.ww in
3447 let itemcount = source#getitemcount
in
3449 if (row - m_first
) > fstate.maxrows
3452 if row >= 0 && row < itemcount
3454 let (s, level
) = source#getitem
row in
3455 let y = (row - m_first
) * nfs in
3456 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3459 Gl.disable `texture_2d
;
3460 GlDraw.polygon_mode `both `line
;
3461 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3462 GlDraw.color
(1., 1., 1.) ~
alpha;
3463 GlDraw.rect (1., float (y + 1))
3464 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3465 GlDraw.polygon_mode `both `fill
;
3466 GlDraw.color
(1., 1., 1.);
3467 Gl.enable `texture_2d
;
3470 let drawtabularstring s =
3471 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3474 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3477 let len = String.length
s - tabpos - 1 in
3478 let s1 = String.sub
s 0 tabpos
3479 and s2
= String.sub
s (tabpos + 1) len in
3480 let nx = drawstr x s1 in
3482 let x = x +. (max
tabw sw) in
3489 let _ = drawtabularstring s in
3496 Gl.disable `texture_2d
;
3498 method updownlevel incr
=
3499 let len = source#getitemcount
in
3501 if m_active
>= 0 && m_active
< len
3502 then snd
(source#getitem m_active
)
3506 if i
= len then i
-1 else if i
= -1 then 0 else
3507 let _, l = source#getitem i
in
3508 if l != curlevel then i
else flow (i
+incr
)
3510 let active = flow m_active
in
3511 let first = calcfirst m_first
active in
3512 G.postRedisplay "outline updownlevel";
3513 {< m_active
= active; m_first
= first >}
3515 method private key1
key mask
=
3516 let set1 active first qsearch
=
3517 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3519 let search active pattern incr
=
3520 let active = if active = -1 then m_first
else active in
3523 if n >= 0 && n < source#getitemcount
3525 let s, _ = source#getitem
n in
3527 (try ignore
(Str.search_forward
re s 0); true
3528 with Not_found
-> false)
3530 else loop (n + incr
)
3537 let re = Str.regexp_case_fold pattern
in
3543 let itemcount = source#getitemcount
in
3544 let find start incr
=
3546 if i
= -1 || i
= itemcount
3549 if source#hasaction i
3551 else find (i
+ incr
)
3556 let set active first =
3557 let first = bound first 0 (itemcount - fstate.maxrows
) in
3559 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3562 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3564 let incr1 = if incr
> 0 then 1 else -1 in
3565 if isvisible m_first m_active
3568 let next = m_active
+ incr
in
3570 if next < 0 || next >= itemcount
3572 else find next incr1
3574 if abs
(m_active
- next) > fstate.maxrows
3580 let first = m_first
+ incr
in
3581 let first = bound first 0 (itemcount - fstate.maxrows
) in
3583 let next = m_active
+ incr
in
3584 let next = bound next 0 (itemcount - 1) in
3591 if isvisible first next
3598 let first = min
next m_first
in
3600 if abs
(next - first) > fstate.maxrows
3606 let first = m_first
+ incr
in
3607 let first = bound first 0 (itemcount - 1) in
3609 let next = m_active
+ incr
in
3610 let next = bound next 0 (itemcount - 1) in
3611 let next = find next incr1 in
3613 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3615 let active = if m_active
= -1 then next else m_active
in
3620 if isvisible first active
3626 G.postRedisplay "listview navigate";
3630 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3631 let incr = if key = 0x72 then -1 else 1 in
3633 match search (m_active
+ incr) m_qsearch
incr with
3635 state.text <- m_qsearch ^
" [not found]";
3638 state.text <- m_qsearch
;
3639 active, firstof m_first
active
3641 G.postRedisplay "listview ctrl-r/s";
3642 set1 active first m_qsearch
;
3644 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3645 if m_active
>= 0 && m_active
< source#getitemcount
3647 let s, _ = source#getitem m_active
in
3652 | 0xff08 -> (* backspace *)
3653 if emptystr m_qsearch
3656 let qsearch = withoutlastutf8 m_qsearch
in
3660 G.postRedisplay "listview empty qsearch";
3661 set1 m_active m_first
"";
3665 match search m_active
qsearch ~
-1 with
3667 state.text <- qsearch ^
" [not found]";
3670 state.text <- qsearch;
3671 active, firstof m_first
active
3673 G.postRedisplay "listview backspace qsearch";
3674 set1 active first qsearch
3677 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3678 let pattern = m_qsearch ^ toutf8
key in
3680 match search m_active
pattern 1 with
3682 state.text <- pattern ^
" [not found]";
3685 state.text <- pattern;
3686 active, firstof m_first
active
3688 G.postRedisplay "listview qsearch add";
3689 set1 active first pattern;
3691 | 0xff1b -> (* escape *)
3693 if emptystr m_qsearch
3695 G.postRedisplay "list view escape";
3698 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3700 | None
-> m_prev_uioh
3705 G.postRedisplay "list view kill qsearch";
3706 source#setqsearch
"";
3707 coe {< m_qsearch
= "" >}
3710 | 0xff0d | 0xff8d -> (* (kp) enter *)
3712 let self = {< m_qsearch
= "" >} in
3713 source#setqsearch
"";
3715 G.postRedisplay "listview enter";
3716 if m_active
>= 0 && m_active
< source#getitemcount
3718 source#exit
(coe self) false m_active m_first m_pan
"";
3721 source#exit
(coe self) true m_active m_first m_pan
"";
3724 begin match opt with
3725 | None
-> m_prev_uioh
3729 | 0xff9f | 0xffff -> (* (kp) delete *)
3732 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3733 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3734 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3735 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3737 | 0xff53 | 0xff98 -> (* (kp) right *)
3739 G.postRedisplay "listview right";
3740 coe {< m_pan
= m_pan
- 1 >}
3742 | 0xff51 | 0xff96 -> (* (kp) left *)
3744 G.postRedisplay "listview left";
3745 coe {< m_pan
= m_pan
+ 1 >}
3747 | 0xff50 | 0xff95 -> (* (kp) home *)
3748 let active = find 0 1 in
3749 G.postRedisplay "listview home";
3752 | 0xff57 | 0xff9c -> (* (kp) end *)
3753 let first = max
0 (itemcount - fstate.maxrows
) in
3754 let active = find (itemcount - 1) ~
-1 in
3755 G.postRedisplay "listview end";
3758 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3762 dolog
"listview unknown key %#x" key; coe self
3764 method key key mask
=
3765 match state.mode
with
3766 | Textentry te
-> textentrykeyboard key mask te
; coe self
3767 | _ -> self#key1
key mask
3769 method button button down
x y _ =
3772 | 1 when x > state.winw
- conf.scrollbw
->
3773 G.postRedisplay "listview scroll";
3776 let _, position, sh = self#
scrollph in
3777 if y > truncate
position && y < truncate
(position +. sh)
3779 state.mstate
<- Mscrolly
;
3783 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3784 let first = truncate
(s *. float source#getitemcount
) in
3785 let first = min source#getitemcount
first in
3786 Some
(coe {< m_first
= first; m_active
= first >})
3788 state.mstate
<- Mnone
;
3791 | 1 when not down
->
3792 begin match self#elemunder
y with
3794 G.postRedisplay "listview click";
3796 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3800 | n when (n == 4 || n == 5) && not down
->
3801 let len = source#getitemcount
in
3803 if n = 5 && m_first
+ fstate.maxrows
>= len
3807 let first = m_first
+ (if n == 4 then -1 else 1) in
3808 bound first 0 (len - 1)
3810 G.postRedisplay "listview wheel";
3811 Some
(coe {< m_first
= first >})
3812 | n when (n = 6 || n = 7) && not down
->
3813 let inc = if n = 7 then -1 else 1 in
3814 G.postRedisplay "listview hwheel";
3815 Some
(coe {< m_pan
= m_pan
+ inc >})
3820 | None
-> m_prev_uioh
3824 match state.mstate
with
3826 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3827 let first = truncate
(s *. float source#getitemcount
) in
3828 let first = min source#getitemcount
first in
3829 G.postRedisplay "listview motion";
3830 coe {< m_first
= first; m_active
= first >}
3833 method pmotion
x y =
3834 if x < state.winw
- conf.scrollbw
3837 match self#elemunder
y with
3838 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3839 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3843 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3848 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3852 method infochanged
_ = ()
3854 method scrollpw
= (0, 0.0, 0.0)
3856 let nfs = fstate.fontsize
+ 1 in
3857 let y = m_first
* nfs in
3858 let itemcount = source#getitemcount
in
3859 let maxi = max
0 (itemcount - fstate.maxrows
) in
3860 let maxy = maxi * nfs in
3861 let p, h = scrollph y maxy in
3864 method modehash
= modehash
3865 method eformsgs
= false
3868 class outlinelistview ~source
=
3869 let settext autonarrow
s =
3871 then state.text <- "[" ^
s ^
"]"
3872 else state.text <- s
3876 ~source
:(source
:> lvsource
)
3878 ~modehash
:(findkeyhash conf "outline")
3881 val m_autonarrow
= false
3883 method key key mask
=
3885 if emptystr
state.text
3887 else fstate.maxrows - 2
3889 let calcfirst first active =
3892 let rows = active - first in
3893 if rows > maxrows then active - maxrows else first
3897 let active = m_active
+ incr in
3898 let active = bound active 0 (source#getitemcount
- 1) in
3899 let first = calcfirst m_first
active in
3900 G.postRedisplay "outline navigate";
3901 coe {< m_active
= active; m_first
= first >}
3903 let navscroll first =
3905 let dist = m_active
- first in
3911 else first + maxrows
3914 G.postRedisplay "outline navscroll";
3915 coe {< m_first
= first; m_active
= active >}
3917 let ctrl = Wsi.withctrl mask
in
3919 | 97 when ctrl -> (* ctrl-a *)
3921 then source#denarrow
3922 else source#narrow m_qsearch
;
3923 settext (not m_autonarrow
) m_qsearch
;
3924 G.postRedisplay "toggle auto narrowing";
3925 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3927 | 110 when ctrl -> (* ctrl-n *)
3928 source#narrow m_qsearch
;
3930 then source#add_narrow_pattern m_qsearch
;
3931 G.postRedisplay "outline ctrl-n";
3932 coe {< m_first
= 0; m_active
= 0 >}
3934 | 117 when ctrl -> (* ctrl-u *)
3935 source#del_narrow_pattern
;
3936 let pattern = source#renarrow
in
3937 G.postRedisplay "outline ctrl-u";
3939 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3941 settext m_autonarrow
text;
3942 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3944 | 108 when ctrl -> (* ctrl-l *)
3945 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3946 G.postRedisplay "outline ctrl-l";
3947 coe {< m_first
= first >}
3949 | 0xff1b -> (* escape *)
3950 let o = super#
key key mask
in
3953 if nonemptystr m_qsearch
3955 source#add_narrow_pattern m_qsearch
;
3961 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3962 if nonemptystr m_qsearch
3963 then source#add_narrow_pattern m_qsearch
;
3966 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3967 let pattern = m_qsearch ^ toutf8
key in
3968 G.postRedisplay "outlinelistview autonarrow add";
3969 source#narrow
pattern;
3970 settext true pattern;
3971 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3973 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3974 if emptystr m_qsearch
3977 let pattern = withoutlastutf8 m_qsearch
in
3978 G.postRedisplay "outlinelistview autonarrow backspace";
3979 ignore
(source#renarrow
);
3980 source#narrow
pattern;
3981 settext true pattern;
3982 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3984 | 0xff9f | 0xffff -> (* (kp) delete *)
3985 source#remove m_active
;
3986 G.postRedisplay "outline delete";
3987 let active = max
0 (m_active
-1) in
3988 coe {< m_first
= firstof m_first
active;
3989 m_active
= active >}
3991 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3992 navscroll (max
0 (m_first
- 1))
3994 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3995 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3997 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3998 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3999 | 0xff55 | 0xff9a -> (* (kp) prior *)
4000 navigate ~
-(fstate.maxrows)
4001 | 0xff56 | 0xff9b -> (* (kp) next *)
4002 navigate fstate.maxrows
4004 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4008 G.postRedisplay "outline ctrl right";
4009 {< m_pan
= m_pan
+ 1 >}
4011 else self#updownlevel
1
4015 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4019 G.postRedisplay "outline ctrl left";
4020 {< m_pan
= m_pan
- 1 >}
4022 else self#updownlevel ~
-1
4026 | 0xff50 | 0xff95 -> (* (kp) home *)
4027 G.postRedisplay "outline home";
4028 coe {< m_first
= 0; m_active
= 0 >}
4030 | 0xff57 | 0xff9c -> (* (kp) end *)
4031 let active = source#getitemcount
- 1 in
4032 let first = max
0 (active - fstate.maxrows) in
4033 G.postRedisplay "outline end";
4034 coe {< m_active
= active; m_first
= first >}
4036 | _ -> super#
key key mask
4039 let outlinesource usebookmarks
=
4042 inherit lvsourcebase
4043 val mutable m_items
= empty
4044 val mutable m_orig_items
= empty
4045 val mutable m_narrow_patterns
= []
4046 val mutable m_hadremovals
= false
4048 method getitemcount
=
4049 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4052 if n == Array.length m_items
&& m_hadremovals
4054 ("[Confirm removal]", 0)
4056 let s, n, _ = m_items
.(n) in
4059 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4060 ignore
(uioh
, first, qsearch);
4061 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4063 if m_narrow_patterns
= []
4069 if not
confrimremoval
4071 let _, _, ((pageno, y, _) as anchor) = m_items
.(active) in
4073 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4079 state.bookmarks
<- Array.to_list m_items
;
4080 m_orig_items
<- m_items
;
4083 else m_items
<- items;
4087 method hasaction
_ = true
4090 if Array.length m_items
!= Array.length m_orig_items
4093 match m_narrow_patterns
with
4095 | many
-> String.concat
" --> " (List.rev many
)
4097 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4100 method narrow
pattern =
4101 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4105 let rec loop accu n =
4107 then m_items
<- Array.of_list
accu
4109 let (s, _, _) as o = m_items
.(n) in
4111 if (try ignore
(Str.search_forward
re s 0); true
4112 with Not_found
-> false)
4118 loop [] (Array.length m_items
- 1)
4123 then Array.of_list
state.bookmarks
4126 m_items
<- m_orig_items
4131 if m >= 0 && m < Array.length m_items
4133 m_hadremovals
<- true;
4134 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4135 let n = if n >= m then n+1 else n in
4140 method add_narrow_pattern
pattern =
4141 m_narrow_patterns
<- pattern :: m_narrow_patterns
4143 method del_narrow_pattern
=
4144 match m_narrow_patterns
with
4145 | _ :: rest
-> m_narrow_patterns
<- rest
4150 match m_narrow_patterns
with
4151 | pattern :: [] -> self#narrow
pattern; pattern
4153 List.fold_left
(fun accu pattern ->
4154 self#narrow
pattern;
4155 accu ^
" --> " ^
pattern) "" list
4157 method reset
anchor items =
4158 m_hadremovals
<- false;
4159 if m_orig_items
== empty
4161 m_orig_items
<- items;
4162 if m_narrow_patterns
== []
4163 then m_items
<- items;
4165 let rely = getanchory anchor in
4167 let rec loop n best bestd
=
4168 if n = Array.length m_items
4171 let (_, _, anchor) = m_items
.(n) in
4172 let orely = getanchory anchor in
4173 let d = abs
(orely - rely) in
4176 else loop (n+1) best bestd
4181 m_first
<- firstof m_first
active
4185 let enterselector usebookmarks
=
4186 let source = outlinesource usebookmarks
in
4190 then Array.of_list
state.bookmarks
4193 if Array.length
outlines = 0
4195 showtext ' ' errmsg
;
4198 state.text <- source#greetmsg
;
4199 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4200 let anchor = getanchor () in
4201 source#reset
anchor outlines;
4202 state.uioh
<- coe (new outlinelistview ~
source);
4203 G.postRedisplay "enter selector";
4207 let enteroutlinemode =
4208 let f = enterselector false in
4209 fun ()-> f "Document has no outline";
4212 let enterbookmarkmode =
4213 let f = enterselector true in
4214 fun () -> f "Document has no bookmarks (yet)";
4217 let color_of_string s =
4218 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4219 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4223 let color_to_string (r, g, b) =
4224 let r = truncate
(r *. 256.0)
4225 and g = truncate
(g *. 256.0)
4226 and b = truncate
(b *. 256.0) in
4227 Printf.sprintf
"%d/%d/%d" r g b
4230 let irect_of_string s =
4231 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4234 let irect_to_string (x0,y0,x1,y1) =
4235 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4238 let makecheckers () =
4239 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4241 converted by Issac Trotts. July 25, 2002 *)
4242 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4243 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4244 let id = GlTex.gen_texture
() in
4245 GlTex.bind_texture `texture_2d
id;
4246 GlPix.store
(`unpack_alignment
1);
4247 GlTex.image2d
image;
4248 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4249 [ `mag_filter `nearest
; `min_filter `nearest
];
4253 let setcheckers enabled
=
4254 match state.texid
with
4256 if enabled
then state.texid
<- Some
(makecheckers ())
4261 GlTex.delete_texture texid
;
4262 state.texid
<- None
;
4266 let int_of_string_with_suffix s =
4267 let l = String.length
s in
4271 let suffix = Char.lowercase
s.[l-1] in
4273 | 'k'
-> String.sub
s 0 (l-1), 10
4274 | '
m'
-> String.sub
s 0 (l-1), 20
4275 | '
g'
-> String.sub
s 0 (l-1), 30
4279 let n = int_of_string
s1 in
4280 let m = n lsl shift
in
4282 then raise
(Failure
"value too large")
4286 let string_with_suffix_of_int n =
4290 let units = [(30, "G"); (20, "M"); (10, "K")] in
4293 let h = n mod 1000 in
4296 then string_of_int
h ^
s
4298 let s = Printf.sprintf
"_%03d%s" h s in
4304 let rec find = function
4306 | (shift
, suffix) :: rest
->
4307 if (n land ((1 lsl shift
) - 1)) = 0
4308 then prettyint (n lsr shift
) ^
suffix
4314 let defghyllscroll = (40, 8, 32);;
4315 let ghyllscroll_of_string s =
4316 let (n, a, b) as nab
=
4319 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4321 if n <= a || n <= b || a >= b
4322 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4327 let ghyllscroll_to_string ((n, a, b) as nab
) =
4328 if nab
= defghyllscroll
4330 else Printf.sprintf
"%d,%d,%d" n a b;
4333 let describe_location () =
4334 let fn = page_of_y state.y in
4335 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4336 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4340 else (100. *. (float state.y /. float maxy))
4344 Printf.sprintf
"page %d of %d [%.2f%%]"
4345 (fn+1) state.pagecount
percent
4348 "pages %d-%d of %d [%.2f%%]"
4349 (fn+1) (ln+1) state.pagecount
percent
4352 let setpresentationmode v
=
4353 let n = page_of_y state.y in
4354 state.anchor <- (n, 0.0, 1.0);
4355 conf.presentation
<- v
;
4356 if conf.fitmodel
= FitPage
4357 then reqlayout conf.angle
conf.fitmodel
;
4362 let btos b = if b then "\xe2\x88\x9a" else "" in
4363 let showextended = ref false in
4364 let leave mode
= function
4365 | Confirm
-> state.mode
<- mode
4366 | Cancel
-> state.mode
<- mode
in
4369 val mutable m_first_time
= true
4370 val mutable m_l
= []
4371 val mutable m_a
= [||]
4372 val mutable m_prev_uioh
= nouioh
4373 val mutable m_prev_mode
= View
4375 inherit lvsourcebase
4377 method reset prev_mode prev_uioh
=
4378 m_a
<- Array.of_list
(List.rev m_l
);
4380 m_prev_mode
<- prev_mode
;
4381 m_prev_uioh
<- prev_uioh
;
4385 if n >= Array.length m_a
4389 | _, _, _, Action
_ -> m_active
<- n
4393 m_first_time
<- false;
4396 method int name get
set =
4398 (name, `
int get
, 1, Action
(
4401 try set (int_of_string
s)
4403 state.text <- Printf.sprintf
"bad integer `%s': %s"
4407 let te = name ^
": ", "", None
, intentry, ondone, true in
4408 state.mode
<- Textentry
(te, leave m_prev_mode
);
4412 method int_with_suffix
name get
set =
4414 (name, `intws get
, 1, Action
(
4417 try set (int_of_string_with_suffix s)
4419 state.text <- Printf.sprintf
"bad integer `%s': %s"
4424 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4426 state.mode
<- Textentry
(te, leave m_prev_mode
);
4430 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4432 (name, `
bool (btos, get
), offset
, Action
(
4439 method color
name get
set =
4441 (name, `color get
, 1, Action
(
4443 let invalid = (nan
, nan
, nan
) in
4446 try color_of_string s
4448 state.text <- Printf.sprintf
"bad color `%s': %s"
4455 let te = name ^
": ", "", None
, textentry, ondone, true in
4456 state.text <- color_to_string (get
());
4457 state.mode
<- Textentry
(te, leave m_prev_mode
);
4461 method string name get
set =
4463 (name, `
string get
, 1, Action
(
4465 let ondone s = set s in
4466 let te = name ^
": ", "", None
, textentry, ondone, true in
4467 state.mode
<- Textentry
(te, leave m_prev_mode
);
4471 method colorspace
name get
set =
4473 (name, `
string get
, 1, Action
(
4477 inherit lvsourcebase
4480 m_active
<- CSTE.to_int conf.colorspace
;
4483 method getitemcount
=
4484 Array.length
CSTE.names
4487 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4488 ignore
(uioh
, first, pan
, qsearch);
4489 if not cancel
then set active;
4491 method hasaction
_ = true
4495 let modehash = findkeyhash conf "info" in
4496 coe (new listview ~
source ~trusted
:true ~
modehash)
4499 method paxmark
name get
set =
4501 (name, `
string get
, 1, Action
(
4505 inherit lvsourcebase
4508 m_active
<- MTE.to_int conf.paxmark
;
4511 method getitemcount
= Array.length
MTE.names
4512 method getitem
n = (MTE.names.(n), 0)
4513 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4514 ignore
(uioh
, first, pan
, qsearch);
4515 if not cancel
then set active;
4517 method hasaction
_ = true
4521 let modehash = findkeyhash conf "info" in
4522 coe (new listview ~
source ~trusted
:true ~
modehash)
4525 method fitmodel
name get
set =
4527 (name, `
string get
, 1, Action
(
4531 inherit lvsourcebase
4534 m_active
<- FMTE.to_int conf.fitmodel
;
4537 method getitemcount
= Array.length
FMTE.names
4538 method getitem
n = (FMTE.names.(n), 0)
4539 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4540 ignore
(uioh
, first, pan
, qsearch);
4541 if not cancel
then set active;
4543 method hasaction
_ = true
4547 let modehash = findkeyhash conf "info" in
4548 coe (new listview ~
source ~trusted
:true ~
modehash)
4551 method caption
s offset
=
4552 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4554 method caption2
s f offset
=
4555 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4557 method getitemcount
= Array.length m_a
4560 let tostr = function
4561 | `
int f -> string_of_int
(f ())
4562 | `intws
f -> string_with_suffix_of_int (f ())
4564 | `color
f -> color_to_string (f ())
4565 | `
bool (btos, f) -> btos (f ())
4568 let name, t
, offset
, _ = m_a
.(n) in
4569 ((let s = tostr t
in
4571 then Printf.sprintf
"%s\t%s" name s
4575 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4579 m_qsearch
<- qsearch;
4581 match m_a
.(active) with
4582 | _, _, _, Action
f -> f uioh
4594 method hasaction
n =
4596 | _, _, _, Action
_ -> true
4600 let rec fillsrc prevmode prevuioh
=
4601 let sep () = src#caption
"" 0 in
4602 let colorp name get
set =
4604 (fun () -> color_to_string (get
()))
4607 let c = color_of_string v in
4610 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4613 let oldmode = state.mode
in
4614 let birdseye = isbirdseye state.mode
in
4616 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4618 src#
bool "presentation mode"
4619 (fun () -> conf.presentation
)
4620 (fun v -> setpresentationmode v);
4622 src#
bool "ignore case in searches"
4623 (fun () -> conf.icase
)
4624 (fun v -> conf.icase
<- v);
4627 (fun () -> conf.preload)
4628 (fun v -> conf.preload <- v);
4630 src#
bool "highlight links"
4631 (fun () -> conf.hlinks
)
4632 (fun v -> conf.hlinks
<- v);
4634 src#
bool "under info"
4635 (fun () -> conf.underinfo
)
4636 (fun v -> conf.underinfo
<- v);
4638 src#
bool "persistent bookmarks"
4639 (fun () -> conf.savebmarks
)
4640 (fun v -> conf.savebmarks
<- v);
4642 src#fitmodel
"fit model"
4643 (fun () -> FMTE.to_string conf.fitmodel
)
4644 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4646 src#
bool "trim margins"
4647 (fun () -> conf.trimmargins
)
4648 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4650 src#
bool "persistent location"
4651 (fun () -> conf.jumpback
)
4652 (fun v -> conf.jumpback
<- v);
4655 src#
int "inter-page space"
4656 (fun () -> conf.interpagespace
)
4658 conf.interpagespace
<- n;
4659 docolumns conf.columns
;
4661 match state.layout with
4666 state.maxy <- calcheight ();
4667 let y = getpagey pageno in
4672 (fun () -> conf.pagebias
)
4673 (fun v -> conf.pagebias
<- v);
4675 src#
int "scroll step"
4676 (fun () -> conf.scrollstep
)
4677 (fun n -> conf.scrollstep
<- n);
4679 src#
int "horizontal scroll step"
4680 (fun () -> conf.hscrollstep
)
4681 (fun v -> conf.hscrollstep
<- v);
4683 src#
int "auto scroll step"
4685 match state.autoscroll
with
4687 | _ -> conf.autoscrollstep
)
4689 if state.autoscroll
<> None
4690 then state.autoscroll
<- Some
n;
4691 conf.autoscrollstep
<- n);
4694 (fun () -> truncate
(conf.zoom *. 100.))
4695 (fun v -> setzoom ((float v) /. 100.));
4698 (fun () -> conf.angle
)
4699 (fun v -> reqlayout v conf.fitmodel
);
4701 src#
int "scroll bar width"
4702 (fun () -> conf.scrollbw
)
4705 reshape state.winw
state.winh
;
4708 src#
int "scroll handle height"
4709 (fun () -> conf.scrollh
)
4710 (fun v -> conf.scrollh
<- v;);
4712 src#
int "thumbnail width"
4713 (fun () -> conf.thumbw
)
4715 conf.thumbw
<- min
4096 v;
4718 leavebirdseye beye
false;
4723 let mode = state.mode in
4724 src#
string "columns"
4726 match conf.columns
with
4728 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4729 | Csplit
(count
, _) -> "-" ^ string_of_int count
4732 let n, a, b = multicolumns_of_string v in
4733 setcolumns mode n a b);
4736 src#caption
"Pixmap cache" 0;
4737 src#int_with_suffix
"size (advisory)"
4738 (fun () -> conf.memlimit
)
4739 (fun v -> conf.memlimit
<- v);
4742 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4743 (string_with_suffix_of_int state.memused
)
4744 (Hashtbl.length
state.tilemap
)) 1;
4747 src#caption
"Layout" 0;
4748 src#caption2
"Dimension"
4750 Printf.sprintf
"%dx%d (virtual %dx%d)"
4751 state.winw
state.winh
4756 src#caption2
"Position" (fun () ->
4757 Printf.sprintf
"%dx%d" state.x state.y
4760 src#caption2
"Position" (fun () -> describe_location ()) 1
4764 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4765 "Save these parameters as global defaults at exit"
4766 (fun () -> conf.bedefault
)
4767 (fun v -> conf.bedefault
<- v)
4771 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4772 src#
bool ~offset
:0 ~
btos "Extended parameters"
4773 (fun () -> !showextended)
4774 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4778 (fun () -> conf.checkers
)
4779 (fun v -> conf.checkers
<- v; setcheckers v);
4780 src#
bool "update cursor"
4781 (fun () -> conf.updatecurs
)
4782 (fun v -> conf.updatecurs
<- v);
4784 (fun () -> conf.verbose
)
4785 (fun v -> conf.verbose
<- v);
4786 src#
bool "invert colors"
4787 (fun () -> conf.invert
)
4788 (fun v -> conf.invert
<- v);
4790 (fun () -> conf.maxhfit
)
4791 (fun v -> conf.maxhfit
<- v);
4792 src#
bool "redirect stderr"
4793 (fun () -> conf.redirectstderr)
4794 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4796 (fun () -> conf.pax
!= None
)
4799 then conf.pax
<- Some
(ref (now (), 0, 0))
4800 else conf.pax
<- None
);
4801 src#
string "uri launcher"
4802 (fun () -> conf.urilauncher
)
4803 (fun v -> conf.urilauncher
<- v);
4804 src#
string "path launcher"
4805 (fun () -> conf.pathlauncher
)
4806 (fun v -> conf.pathlauncher
<- v);
4807 src#
string "tile size"
4808 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4811 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4812 conf.tilew
<- max
64 w;
4813 conf.tileh
<- max
64 h;
4816 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4819 src#
int "texture count"
4820 (fun () -> conf.texcount
)
4823 then conf.texcount
<- v
4824 else showtext '
!'
" Failed to set texture count please retry later"
4826 src#
int "slice height"
4827 (fun () -> conf.sliceheight
)
4829 conf.sliceheight
<- v;
4830 wcmd "sliceh %d" conf.sliceheight
;
4832 src#
int "anti-aliasing level"
4833 (fun () -> conf.aalevel
)
4835 conf.aalevel
<- bound v 0 8;
4836 state.anchor <- getanchor ();
4837 opendoc state.path
state.password
;
4839 src#
string "page scroll scaling factor"
4840 (fun () -> string_of_float
conf.pgscale)
4843 let s = float_of_string
v in
4846 state.text <- Printf.sprintf
4847 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4850 src#
int "ui font size"
4851 (fun () -> fstate.fontsize
)
4852 (fun v -> setfontsize (bound v 5 100));
4853 src#
int "hint font size"
4854 (fun () -> conf.hfsize
)
4855 (fun v -> conf.hfsize
<- bound v 5 100);
4856 colorp "background color"
4857 (fun () -> conf.bgcolor
)
4858 (fun v -> conf.bgcolor
<- v);
4859 src#
bool "crop hack"
4860 (fun () -> conf.crophack
)
4861 (fun v -> conf.crophack
<- v);
4862 src#
string "trim fuzz"
4863 (fun () -> irect_to_string conf.trimfuzz
)
4866 conf.trimfuzz
<- irect_of_string v;
4868 then settrim true conf.trimfuzz
;
4870 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4872 src#
string "throttle"
4874 match conf.maxwait
with
4875 | None
-> "show place holder if page is not ready"
4878 then "wait for page to fully render"
4880 "wait " ^ string_of_float
time
4881 ^
" seconds before showing placeholder"
4885 let f = float_of_string
v in
4887 then conf.maxwait
<- None
4888 else conf.maxwait
<- Some
f
4890 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4892 src#
string "ghyll scroll"
4894 match conf.ghyllscroll
with
4896 | Some nab
-> ghyllscroll_to_string nab
4903 else Some
(ghyllscroll_of_string v)
4905 conf.ghyllscroll
<- gs
4907 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4909 src#
string "selection command"
4910 (fun () -> conf.selcmd
)
4911 (fun v -> conf.selcmd
<- v);
4912 src#
string "synctex command"
4913 (fun () -> conf.stcmd
)
4914 (fun v -> conf.stcmd
<- v);
4915 src#
string "pax command"
4916 (fun () -> conf.paxcmd
)
4917 (fun v -> conf.paxcmd
<- v);
4918 src#colorspace
"color space"
4919 (fun () -> CSTE.to_string conf.colorspace
)
4921 conf.colorspace
<- CSTE.of_int v;
4925 src#paxmark
"pax mark method"
4926 (fun () -> MTE.to_string conf.paxmark
)
4927 (fun v -> conf.paxmark
<- MTE.of_int v);
4931 (fun () -> conf.usepbo
)
4932 (fun v -> conf.usepbo
<- v);
4933 src#
bool "mouse wheel scrolls pages"
4934 (fun () -> conf.wheelbypage
)
4935 (fun v -> conf.wheelbypage
<- v);
4936 src#
bool "open remote links in a new instance"
4937 (fun () -> conf.riani
)
4938 (fun v -> conf.riani
<- v);
4942 src#caption
"Document" 0;
4943 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4944 src#caption2
"Pages"
4945 (fun () -> string_of_int
state.pagecount
) 1;
4946 src#caption2
"Dimensions"
4947 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4951 src#caption
"Trimmed margins" 0;
4952 src#caption2
"Dimensions"
4953 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4957 src#caption
"OpenGL" 0;
4958 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4959 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4962 src#caption
"Location" 0;
4963 if nonemptystr
state.origin
4964 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4965 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4967 src#reset prevmode prevuioh
;
4971 let prevmode = state.mode
4972 and prevuioh
= state.uioh in
4973 fillsrc prevmode prevuioh
;
4974 let source = (src :> lvsource
) in
4975 let modehash = findkeyhash conf "info" in
4976 state.uioh <- coe (object (self)
4977 inherit listview ~
source ~trusted
:true ~
modehash as super
4978 val mutable m_prevmemused
= 0
4979 method infochanged
= function
4981 if m_prevmemused
!= state.memused
4983 m_prevmemused
<- state.memused
;
4984 G.postRedisplay "memusedchanged";
4986 | Pdim
-> G.postRedisplay "pdimchanged"
4987 | Docinfo
-> fillsrc prevmode prevuioh
4989 method key key mask
=
4990 if not
(Wsi.withctrl mask
)
4993 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4994 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4995 | _ -> super#
key key mask
4996 else super#
key key mask
4998 G.postRedisplay "info";
5004 inherit lvsourcebase
5005 method getitemcount
= Array.length
state.help
5007 let s, l, _ = state.help
.(n) in
5010 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5014 m_qsearch
<- qsearch;
5015 match state.help
.(active) with
5016 | _, _, Action
f -> Some
(f uioh)
5026 method hasaction
n =
5027 match state.help
.(n) with
5028 | _, _, Action
_ -> true
5035 let modehash = findkeyhash conf "help" in
5036 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5037 G.postRedisplay "help";
5042 let re = Str.regexp
"[\r\n]" in
5044 inherit lvsourcebase
5045 val mutable m_items
= [||]
5047 method getitemcount
= 1 + Array.length m_items
5052 else m_items
.(n-1), 0
5054 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5059 then Buffer.clear
state.errmsgs
;
5060 m_qsearch
<- qsearch;
5067 method hasaction
n =
5071 state.newerrmsgs
<- false;
5072 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5073 m_items
<- Array.of_list
l
5081 let source = (msgsource :> lvsource
) in
5082 let modehash = findkeyhash conf "listview" in
5083 state.uioh <- coe (object
5084 inherit listview ~
source ~trusted
:false ~
modehash as super
5087 then msgsource#reset
;
5090 G.postRedisplay "msgs";
5093 let quickbookmark ?title
() =
5094 match state.layout with
5100 let sec = Unix.gettimeofday
() in
5101 let tm = Unix.localtime
sec in
5102 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5106 (tm.Unix.tm_year
+ 1900)
5109 | Some
title -> title
5111 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5114 let setautoscrollspeed step goingdown
=
5115 let incr = max
1 ((abs step
) / 2) in
5116 let incr = if goingdown
then incr else -incr in
5117 let astep = step
+ incr in
5118 state.autoscroll
<- Some
astep;
5121 let gotounder under =
5122 let getpath filename
=
5124 if nonemptystr filename
5126 if Filename.is_relative filename
5128 let dir = Filename.dirname
state.path in
5130 if Filename.is_implicit
dir
5131 then Filename.concat
(Sys.getcwd
()) dir
5134 Filename.concat
dir filename
5138 if Sys.file_exists
path
5143 | Ulinkgoto
(pageno, top) ->
5147 gotopage1 pageno top;
5153 | Uremote
(filename
, pageno) ->
5154 let path = getpath filename
in
5159 let command = !selfexec ^
" " ^
path in
5160 try popen command []
5163 "failed to execute `%s': %s\n" command (exntos exn
);
5166 let anchor = getanchor () in
5167 let ranchor = state.path, state.password
, anchor, state.origin
in
5169 state.anchor <- (pageno, 0.0, 0.0);
5170 state.ranchors
<- ranchor :: state.ranchors
;
5173 else showtext '
!'
("Could not find " ^ filename
)
5175 | Uremotedest
(filename
, destname
) ->
5176 let path = getpath filename
in
5181 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
5182 try popen command []
5185 "failed to execute `%s': %s\n" command (exntos exn
);
5188 let anchor = getanchor () in
5189 let ranchor = state.path, state.password
, anchor, state.origin
in
5191 state.nameddest
<- destname
;
5192 state.ranchors
<- ranchor :: state.ranchors
;
5195 else showtext '
!'
("Could not find " ^ filename
)
5197 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5201 match conf.columns
with
5203 | _ -> state.x != 0 || conf.zoom > 1.0
5206 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5208 let existsinrow pageno (columns
, coverA
, coverB
) p =
5209 let last = ((pageno - coverA
) mod columns
) + columns
in
5210 let rec any = function
5213 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5217 then (if l.pageno = last then false else any rest
)
5225 match state.layout with
5227 let pageno = page_of_y state.y in
5228 gotoghyll (getpagey (pageno+1))
5230 match conf.columns
with
5232 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5234 let y = clamp (pgscale state.winh
) in
5237 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5238 gotoghyll (getpagey pageno)
5239 | Cmulti
((c, _, _) as cl, _) ->
5240 if conf.presentation
5241 && (existsinrow l.pageno cl
5242 (fun l -> l.pageh
> l.pagey + l.pagevh))
5244 let y = clamp (pgscale state.winh
) in
5247 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5248 gotoghyll (getpagey pageno)
5250 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5252 let pagey, pageh
= getpageyh l.pageno in
5253 let pagey = pagey + pageh
* l.pagecol
in
5254 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5255 gotoghyll (pagey + pageh
+ ips)
5259 match state.layout with
5261 let pageno = page_of_y state.y in
5262 gotoghyll (getpagey (pageno-1))
5264 match conf.columns
with
5266 if conf.presentation
&& l.pagey != 0
5268 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5270 let pageno = max
0 (l.pageno-1) in
5271 gotoghyll (getpagey pageno)
5272 | Cmulti
((c, _, coverB
) as cl, _) ->
5273 if conf.presentation
&&
5274 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5276 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5279 if l.pageno = state.pagecount
- coverB
5283 let pageno = max
0 (l.pageno-decr) in
5284 gotoghyll (getpagey pageno)
5292 let pageno = max
0 (l.pageno-1) in
5293 let pagey, pageh
= getpageyh pageno in
5296 let pagey, pageh
= getpageyh l.pageno in
5297 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5302 let viewkeyboard key mask
=
5304 let mode = state.mode in
5305 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5308 G.postRedisplay "view:enttext"
5310 let ctrl = Wsi.withctrl mask
in
5312 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5318 | 0xff63 -> (* insert *)
5319 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5321 state.mode <- LinkNav
(Ltgendir
0);
5324 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5326 | 0xff1b | 113 -> (* escape / q *)
5327 begin match state.mstate
with
5329 state.mstate
<- Mnone
;
5330 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5331 G.postRedisplay "kill zoom rect";
5333 begin match state.mode with
5336 G.postRedisplay "esc leave linknav"
5338 match state.ranchors
with
5340 | (path, password
, anchor, origin
) :: rest
->
5341 state.ranchors
<- rest
;
5342 state.anchor <- anchor;
5343 state.origin
<- origin
;
5344 state.nameddest
<- "";
5345 opendoc path password
5349 | 0xff08 -> (* backspace *)
5350 gotoghyll (getnav ~
-1)
5358 G.postRedisplay "dehighlight";
5360 | 47 | 63 -> (* / ? *)
5361 let ondone isforw
s =
5362 cbput state.hists
.pat
s;
5363 state.searchpattern
<- s;
5366 let s = String.create
1 in
5367 s.[0] <- Char.chr
key;
5368 enttext (s, "", Some
(onhist state.hists
.pat
),
5369 textentry, ondone (key = 47), true)
5371 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5372 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5373 setzoom (conf.zoom +. incr)
5375 | 43 | 0xffab -> (* + *)
5378 try int_of_string
s with exc
->
5379 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5385 state.text <- "page bias is now " ^ string_of_int
n;
5388 enttext ("page bias: ", "", None
, intentry, ondone, true)
5390 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5391 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5392 setzoom (max
0.01 (conf.zoom -. decr))
5394 | 45 | 0xffad -> (* - *)
5395 let ondone msg
= state.text <- msg
in
5397 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5398 optentry state.mode, ondone, true
5401 | 48 when ctrl -> (* ctrl-0 *)
5409 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5411 match conf.columns
with
5412 | Csingle
_ | Cmulti
_ -> 1
5413 | Csplit
(n, _) -> n
5415 let h = state.winh
-
5416 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5418 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5419 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5422 | 51 when ctrl -> (* ctrl-3 *)
5424 match conf.fitmodel
with
5425 | FitWidth
-> FitProportional
5426 | FitProportional
-> FitPage
5427 | FitPage
-> FitWidth
5429 state.text <- "fit model: " ^
FMTE.to_string fm;
5430 reqlayout conf.angle
fm
5432 | 0xffc6 -> (* f9 *)
5435 | 57 when ctrl -> (* ctrl-9 *)
5438 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5439 when not
ctrl -> (* 0..9 *)
5442 try int_of_string
s with exc
->
5443 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5449 cbput state.hists
.pag
(string_of_int
n);
5450 gotopage1 (n + conf.pagebias
- 1) 0;
5453 let pageentry text key =
5454 match Char.unsafe_chr
key with
5455 | '
g'
-> TEdone
text
5456 | _ -> intentry text key
5458 let text = "x" in text.[0] <- Char.chr
key;
5459 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5462 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5463 reshape state.winw
state.winh
;
5466 state.bzoom
<- not
state.bzoom
;
5468 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5471 conf.hlinks
<- not
conf.hlinks
;
5472 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5473 G.postRedisplay "toggle highlightlinks";
5476 state.glinks
<- true;
5477 let mode = state.mode in
5478 state.mode <- Textentry
(
5479 (":", "", None
, linknentry, linkndone gotounder, false),
5481 state.glinks
<- false;
5485 G.postRedisplay "view:linkent(F)"
5488 state.glinks
<- true;
5489 let mode = state.mode in
5490 state.mode <- Textentry
(
5492 ":", "", None
, linknentry, linkndone (fun under ->
5493 selstring (undertext under);
5497 state.glinks
<- false;
5501 G.postRedisplay "view:linkent"
5504 begin match state.autoscroll
with
5506 conf.autoscrollstep
<- step
;
5507 state.autoscroll
<- None
5509 if conf.autoscrollstep
= 0
5510 then state.autoscroll
<- Some
1
5511 else state.autoscroll
<- Some
conf.autoscrollstep
5514 | 112 when ctrl -> (* ctrl-p *)
5518 setpresentationmode (not
conf.presentation
);
5519 showtext ' '
("presentation mode " ^
5520 if conf.presentation
then "on" else "off");
5523 if List.mem
Wsi.Fullscreen
state.winstate
5524 then Wsi.reshape conf.cwinw
conf.cwinh
5525 else Wsi.fullscreen
()
5527 | 112 | 78 -> (* p|N *)
5528 search state.searchpattern
false
5530 | 110 | 0xffc0 -> (* n|F3 *)
5531 search state.searchpattern
true
5534 begin match state.layout with
5537 gotoghyll (getpagey l.pageno)
5543 | 0xff9f | 0xffff -> (* delete *)
5547 showtext ' '
(describe_location ());
5550 begin match state.layout with
5553 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5558 enterbookmarkmode ()
5560 | 104 | 0xffbe -> (* h|F1 *)
5566 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5571 match state.layout with
5575 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5578 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5582 showtext ' '
"Quick bookmark added";
5585 begin match state.layout with
5587 let rect = getpdimrect
l.pagedimno
in
5591 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5592 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5594 (truncate
(rect.(1) -. rect.(0)),
5595 truncate
(rect.(3) -. rect.(0)))
5597 let w = truncate
((float w)*.conf.zoom)
5598 and h = truncate
((float h)*.conf.zoom) in
5601 state.anchor <- getanchor ();
5602 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5604 G.postRedisplay "z";
5609 | 120 -> state.roam
()
5610 | 60 | 62 -> (* < > *)
5611 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5613 | 91 | 93 -> (* [ ] *)
5615 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5617 G.postRedisplay "brightness";
5619 | 99 when state.mode = View
-> (* [alt-]c *)
5624 let m = (wadjsb state.winw
- state.w) / 2 in
5626 gotoy_and_clear_text state.y
5630 match state.prevcolumns
with
5631 | None
-> (1, 0, 0), 1.0
5632 | Some
(columns
, z
) ->
5635 | Csplit
(c, _) -> -c, 0, 0
5636 | Cmulti
((c, a, b), _) -> c, a, b
5637 | Csingle
_ -> 1, 0, 0
5641 setcolumns View
c a b;
5644 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5645 -> (* ctrl-shift- (kp) [up|down] *)
5646 let zoom, x = state.prevzoom
in
5650 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5651 begin match state.autoscroll
with
5653 begin match state.mode with
5654 | Birdseye beye
-> upbirdseye 1 beye
5657 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5659 if not
(Wsi.withshift mask
) && conf.presentation
5661 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5665 setautoscrollspeed n false
5668 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5669 begin match state.autoscroll
with
5671 begin match state.mode with
5672 | Birdseye beye
-> downbirdseye 1 beye
5675 then gotoy_and_clear_text (clamp (state.winh
/2))
5677 if not
(Wsi.withshift mask
) && conf.presentation
5679 else gotoy_and_clear_text (clamp conf.scrollstep
)
5683 setautoscrollspeed n true
5686 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5687 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5693 else conf.hscrollstep
5695 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5696 state.x <- panbound (state.x + dx);
5697 gotoy_and_clear_text state.y
5700 G.postRedisplay "left/right"
5703 | 0xff55 | 0xff9a -> (* (kp) prior *)
5707 match state.layout with
5709 | l :: _ -> state.y - l.pagey
5711 clamp (pgscale (-state.winh
))
5715 | 0xff56 | 0xff9b -> (* (kp) next *)
5719 match List.rev
state.layout with
5721 | l :: _ -> getpagey l.pageno
5723 clamp (pgscale state.winh
)
5727 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5729 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5730 gotoghyll (clamp state.maxy)
5733 when Wsi.withalt mask
-> (* alt-(kp) right *)
5734 gotoghyll (getnav 1)
5736 when Wsi.withalt mask
-> (* alt-(kp) left *)
5737 gotoghyll (getnav ~
-1)
5742 | 118 when conf.debug
-> (* v *)
5745 match getopaque l.pageno with
5748 let x0, y0, x1, y1 = pagebbox opaque
in
5749 let a,b = float x0, float y0 in
5750 let c,d = float x1, float y0 in
5751 let e,f = float x1, float y1 in
5752 let h,j
= float x0, float y1 in
5753 let rect = (a,b,c,d,e,f,h,j
) in
5755 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5757 G.postRedisplay "v";
5760 vlog "huh? %s" (Wsi.keyname
key)
5763 let linknavkeyboard key mask
linknav =
5764 let getpage pageno =
5765 let rec loop = function
5767 | l :: _ when l.pageno = pageno -> Some
l
5768 | _ :: rest
-> loop rest
5769 in loop state.layout
5771 let doexact (pageno, n) =
5772 match getopaque pageno, getpage pageno with
5773 | Some opaque
, Some
l ->
5774 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5776 let under = getlink opaque
n in
5777 G.postRedisplay "link gotounder";
5783 | 0xff50 -> (* home *)
5784 Some
(findlink opaque LDfirst
), -1
5786 | 0xff57 -> (* end *)
5787 Some
(findlink opaque LDlast
), 1
5789 | 0xff51 -> (* left *)
5790 Some
(findlink opaque
(LDleft
n)), -1
5792 | 0xff53 -> (* right *)
5793 Some
(findlink opaque
(LDright
n)), 1
5795 | 0xff52 -> (* up *)
5796 Some
(findlink opaque
(LDup
n)), -1
5798 | 0xff54 -> (* down *)
5799 Some
(findlink opaque
(LDdown
n)), 1
5804 begin match findpwl
l.pageno dir with
5808 state.mode <- LinkNav
(Ltgendir
dir);
5809 let y, h = getpageyh pageno in
5812 then y + h - state.winh
5817 begin match getopaque pageno, getpage pageno with
5818 | Some opaque
, Some
_ ->
5820 let ld = if dir > 0 then LDfirst
else LDlast
in
5823 begin match link with
5825 showlinktype (getlink opaque
m);
5826 state.mode <- LinkNav
(Ltexact
(pageno, m));
5827 G.postRedisplay "linknav jpage";
5834 begin match opt with
5835 | Some Lnotfound
-> pwl l dir;
5836 | Some
(Lfound
m) ->
5840 let _, y0, _, y1 = getlinkrect opaque
m in
5842 then gotopage1 l.pageno y0
5844 let d = fstate.fontsize
+ 1 in
5845 if y1 - l.pagey > l.pagevh - d
5846 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5847 else G.postRedisplay "linknav";
5849 showlinktype (getlink opaque
m);
5850 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5853 | None
-> viewkeyboard key mask
5855 | _ -> viewkeyboard key mask
5860 G.postRedisplay "leave linknav"
5864 | Ltgendir
_ -> viewkeyboard key mask
5865 | Ltexact exact
-> doexact exact
5868 let keyboard key mask
=
5869 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5870 then wcmd "interrupt"
5871 else state.uioh <- state.uioh#
key key mask
5874 let birdseyekeyboard key mask
5875 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5877 match conf.columns
with
5879 | Cmulti
((c, _, _), _) -> c
5880 | Csplit
_ -> failwith
"bird's eye split mode"
5882 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5884 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5885 let y, h = getpageyh pageno in
5886 let top = (state.winh
- h) / 2 in
5887 gotoy (max
0 (y - top))
5888 | 0xff0d (* enter *)
5889 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5890 | 0xff1b -> leavebirdseye beye
true (* escape *)
5891 | 0xff52 -> upbirdseye incr beye
(* up *)
5892 | 0xff54 -> downbirdseye incr beye
(* down *)
5893 | 0xff51 -> upbirdseye 1 beye
(* left *)
5894 | 0xff53 -> downbirdseye 1 beye
(* right *)
5896 | 0xff55 -> (* prior *)
5897 begin match state.layout with
5901 state.mode <- Birdseye
(
5902 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5904 gotopage1 l.pageno 0;
5907 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5909 | [] -> gotoy (clamp (-state.winh
))
5911 state.mode <- Birdseye
(
5912 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5914 gotopage1 l.pageno 0
5917 | [] -> gotoy (clamp (-state.winh
))
5920 | 0xff56 -> (* next *)
5921 begin match List.rev
state.layout with
5923 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5924 begin match layout with
5926 let incr = l.pageh
- l.pagevh in
5931 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5933 G.postRedisplay "birdseye pagedown";
5935 else gotoy (clamp (incr + conf.interpagespace
*2));
5939 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5940 gotopage1 l.pageno 0;
5943 | [] -> gotoy (clamp state.winh
)
5946 | 0xff50 -> (* home *)
5947 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5950 | 0xff57 -> (* end *)
5951 let pageno = state.pagecount
- 1 in
5952 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5953 if not
(pagevisible state.layout pageno)
5956 match List.rev
state.pdims
with
5958 | (_, _, h, _) :: _ -> h
5960 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5961 else G.postRedisplay "birdseye end";
5962 | _ -> viewkeyboard key mask
5967 match state.mode with
5968 | Textentry
_ -> scalecolor 0.4
5970 | View
-> scalecolor 1.0
5971 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5972 if l.pageno = hooverpageno
5975 if l.pageno = pageno
5983 let postdrawpage l linkindexbase
=
5984 match getopaque l.pageno with
5986 if tileready l l.pagex
l.pagey
5988 let x = l.pagedispx - l.pagex
5989 and y = l.pagedispy - l.pagey in
5991 match conf.columns
with
5992 | Csingle
_ | Cmulti
_ ->
5993 (if conf.hlinks
then 1 else 0)
5995 && not
(isbirdseye state.mode) then 2 else 0)
5999 match state.mode with
6000 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6003 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6008 let scrollindicator () =
6009 let sbw, ph
, sh = state.uioh#
scrollph in
6010 let sbh, pw, sw = state.uioh#scrollpw
in
6012 GlDraw.color (0.64, 0.64, 0.64);
6014 (float (state.winw
- sbw), 0.)
6015 (float state.winw
, float state.winh
)
6018 (0., float (state.winh
- sbh))
6019 (float (wadjsb state.winw
- 1), float state.winh
)
6021 GlDraw.color (0.0, 0.0, 0.0);
6024 (float (state.winw
- sbw), ph
)
6025 (float state.winw
, ph
+. sh)
6028 (pw, float (state.winh
- sbh))
6029 (pw +. sw, float state.winh
)
6034 match state.mstate
with
6035 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6038 | Msel
((x0, y0), (x1, y1)) ->
6039 let rec loop = function
6041 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6042 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6043 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6044 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6046 match getopaque l.pageno with
6048 let x0, y0 = pagetranslatepoint l x0 y0 in
6049 let x1, y1 = pagetranslatepoint l x1 y1 in
6050 seltext opaque
(x0, y0, x1, y1);
6058 let showrects rects
=
6060 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6061 GlDraw.polygon_mode `both `fill
;
6062 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6064 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6066 if l.pageno = pageno
6068 let dx = float (l.pagedispx - l.pagex
) in
6069 let dy = float (l.pagedispy - l.pagey) in
6070 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6071 GlDraw.begins `quads
;
6073 GlDraw.vertex2
(x0+.dx, y0+.dy);
6074 GlDraw.vertex2
(x1+.dx, y1+.dy);
6075 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
6076 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
6087 GlClear.color (scalecolor2 conf.bgcolor
);
6088 GlClear.clear
[`
color];
6089 List.iter
drawpage state.layout;
6091 match state.mode with
6092 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6093 begin match getopaque pageno with
6095 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6102 | None
-> state.rects
6107 let rec postloop linkindexbase
= function
6109 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6110 postloop linkindexbase rest
6114 postloop 0 state.layout;
6116 begin match state.mstate
with
6117 | Mzoomrect
((x0, y0), (x1, y1)) ->
6119 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6120 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6121 GlDraw.rect (float x0, float y0)
6122 (float x1, float y1);
6131 let zoomrect x y x1 y1 =
6134 and y0 = min
y y1 in
6135 gotoy (state.y + y0);
6136 state.anchor <- getanchor ();
6137 let zoom = (float state.w) /. float (x1 - x0) in
6139 match conf.fitmodel
, conf.columns
with
6140 | FitPage
, Csplit
_ ->
6141 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6144 let adjw = wadjsb state.winw
in
6146 then (adjw - state.w) / 2
6149 state.x <- (state.x + margin) - x0;
6151 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6152 state.mstate
<- Mnone
;
6156 let g opaque
l px py =
6157 match rectofblock opaque
px py with
6159 let x0 = a.(0) -. 20. in
6160 let x1 = a.(1) +. 20. in
6161 let y0 = a.(2) -. 20. in
6162 let zoom = (float state.w) /. (x1 -. x0) in
6163 let pagey = getpagey l.pageno in
6164 gotoy_and_clear_text (pagey + truncate
y0);
6165 state.anchor <- getanchor ();
6166 let margin = (state.w - l.pagew
)/2 in
6167 state.x <- -truncate
x0 - margin;
6172 match conf.columns
with
6174 showtext '
!'
"block zooming does not work properly in split columns mode"
6175 | _ -> onppundermouse g x y ()
6179 let winw = wadjsb state.winw - 1 in
6180 let s = float x /. float winw in
6181 let destx = truncate
(float (state.w + winw) *. s) in
6182 state.x <- winw - destx;
6183 gotoy_and_clear_text state.y;
6184 state.mstate
<- Mscrollx
;
6188 let s = float y /. float state.winh
in
6189 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6190 gotoy_and_clear_text desty;
6191 state.mstate
<- Mscrolly
;
6194 let viewmouse button down
x y mask
=
6196 | n when (n == 4 || n == 5) && not down
->
6197 if Wsi.withctrl mask
6199 match state.mstate
with
6200 | Mzoom
(oldn
, i
) ->
6208 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6210 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6212 let zoom = conf.zoom -. incr in
6214 state.mstate
<- Mzoom
(n, 0);
6216 state.mstate
<- Mzoom
(n, i
+1);
6218 else state.mstate
<- Mzoom
(n, 0)
6220 | _ -> state.mstate
<- Mzoom
(n, 0)
6223 match state.autoscroll
with
6224 | Some step
-> setautoscrollspeed step
(n=4)
6226 if conf.wheelbypage
|| conf.presentation
6235 then -conf.scrollstep
6236 else conf.scrollstep
6238 let incr = incr * 2 in
6239 let y = clamp incr in
6240 gotoy_and_clear_text y
6243 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6245 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6246 gotoy_and_clear_text state.y
6248 | 1 when Wsi.withshift mask
->
6249 state.mstate
<- Mnone
;
6252 match unproject x y with
6253 | Some
(pageno, ux
, uy
) ->
6254 let cmd = Printf.sprintf
6256 conf.stcmd
state.path pageno ux uy
6262 | 1 when Wsi.withctrl mask
->
6265 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6266 state.mstate
<- Mpan
(x, y)
6269 state.mstate
<- Mnone
6274 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6276 state.mstate
<- Mzoomrect
(p, p)
6279 match state.mstate
with
6280 | Mzoomrect
((x0, y0), _) ->
6281 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6282 then zoomrect x0 y0 x y
6284 state.mstate
<- Mnone
;
6285 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6286 G.postRedisplay "kill accidental zoom rect";
6289 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6290 state.mstate
<- Mnone
6293 | 1 when x > state.winw - vscrollw () ->
6296 let _, position, sh = state.uioh#
scrollph in
6297 if y > truncate
position && y < truncate
(position +. sh)
6298 then state.mstate
<- Mscrolly
6301 state.mstate
<- Mnone
6303 | 1 when y > state.winh
- hscrollh () ->
6306 let _, position, sw = state.uioh#scrollpw
in
6307 if x > truncate
position && x < truncate
(position +. sw)
6308 then state.mstate
<- Mscrollx
6311 state.mstate
<- Mnone
6313 | 1 when state.bzoom
-> if not down
then zoomblock x y
6316 let dest = if down
then getunder x y else Unone
in
6317 begin match dest with
6320 | Uremote
_ | Uremotedest
_
6321 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6324 | Unone
when down
->
6325 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6326 state.mstate
<- Mpan
(x, y);
6328 | Unone
| Utext
_ ->
6331 if conf.angle
mod 360 = 0
6333 state.mstate
<- Msel
((x, y), (x, y));
6334 G.postRedisplay "mouse select";
6338 match state.mstate
with
6341 | Mzoom
_ | Mscrollx
| Mscrolly
->
6342 state.mstate
<- Mnone
6344 | Mzoomrect
((x0, y0), _) ->
6348 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6349 state.mstate
<- Mnone
6351 | Msel
((x0, y0), (x1, y1)) ->
6352 let rec loop = function
6356 let a0 = l.pagedispy in
6357 let a1 = a0 + l.pagevh in
6358 let b0 = l.pagedispx in
6359 let b1 = b0 + l.pagevw in
6360 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6361 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6365 match getopaque l.pageno with
6368 match Ne.pipe () with
6372 "can not create sel pipe: %s"
6375 let doclose what fd
=
6376 Ne.clo fd
(fun msg
->
6377 dolog
"%s close failed: %s" what msg
)
6380 popen conf.selcmd
[r, 0; w, -1];
6381 copysel
w opaque
true;
6383 G.postRedisplay "copysel";
6385 dolog
"can not execute %S: %s"
6386 conf.selcmd
(exntos exn
);
6394 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6395 state.mstate
<- Mnone
;
6402 let birdseyemouse button down
x y mask
6403 (conf, leftx
, _, hooverpageno
, anchor) =
6406 let rec loop = function
6409 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6410 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6412 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6418 | _ -> viewmouse button down
x y mask
6421 let mouse button down
x y mask
=
6422 state.uioh <- state.uioh#button button down
x y mask
;
6426 state.uioh <- state.uioh#
motion x y
6430 state.uioh <- state.uioh#
pmotion x y;
6436 method key key mask
=
6437 begin match state.mode with
6438 | Textentry
textentry -> textentrykeyboard key mask
textentry
6439 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6440 | View
-> viewkeyboard key mask
6441 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6445 method button button bstate
x y mask
=
6446 begin match state.mode with
6448 | View
-> viewmouse button bstate
x y mask
6449 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6455 begin match state.mode with
6457 | View
| Birdseye
_ | LinkNav
_ ->
6458 match state.mstate
with
6459 | Mzoom
_ | Mnone
-> ()
6464 state.mstate
<- Mpan
(x, y);
6466 then state.x <- panbound (state.x + dx);
6468 gotoy_and_clear_text y
6471 state.mstate
<- Msel
(a, (x, y));
6472 G.postRedisplay "motion select";
6475 let y = min
state.winh
(max
0 y) in
6479 let x = min
state.winw (max
0 x) in
6482 | Mzoomrect
(p0
, _) ->
6483 state.mstate
<- Mzoomrect
(p0
, (x, y));
6484 G.postRedisplay "motion zoomrect";
6488 method pmotion x y =
6489 begin match state.mode with
6490 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6491 let rec loop = function
6493 if hooverpageno
!= -1
6495 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6496 G.postRedisplay "pmotion birdseye no hoover";
6499 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6500 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6502 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6503 G.postRedisplay "pmotion birdseye hoover";
6513 match state.mstate
with
6514 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6521 let past, _, _ = !r in
6523 let delta = now -. past in
6526 else r := (now, x, y)
6530 method infochanged
_ = ()
6533 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6536 then 0.0, float state.winh
6537 else scrollph state.y maxy
6542 let winw = wadjsb state.winw in
6543 let fwinw = float winw in
6545 let sw = fwinw /. float state.w in
6546 let sw = fwinw *. sw in
6547 max
sw (float conf.scrollh
)
6550 let maxx = state.w + winw in
6551 let x = winw - state.x in
6552 let percent = float x /. float maxx in
6553 (fwinw -. sw) *. percent
6555 hscrollh (), position, sw
6559 match state.mode with
6560 | LinkNav
_ -> "links"
6561 | Textentry
_ -> "textentry"
6562 | Birdseye
_ -> "birdseye"
6565 findkeyhash conf modename
6567 method eformsgs
= true
6574 let fontpath = ref "";;
6577 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6580 let l = String.length
s in
6581 let b = Buffer.create
l in
6587 try Sys.getenv
"HOME"
6590 ("Can not determine home directory location: " ^ exntos exn
);
6594 let modifier_of_string = function
6595 | "alt" -> Wsi.altmask
6596 | "shift" -> Wsi.shiftmask
6597 | "ctrl" | "control" -> Wsi.ctrlmask
6598 | "meta" -> Wsi.metamask
6603 let r = Str.regexp
"-" in
6605 let elems = Str.full_split
r s in
6608 let m1 = modifier_of_string s in
6610 then (Wsi.namekey
s, m)
6613 | Str.Delim
s when n land 1 = 0 -> g s
6615 | Str.Delim
_ -> (k
, m)
6617 let rec loop n k
m = function
6620 let k, m = f n k m x in
6626 let keys_of_string =
6627 let r = Str.regexp
"[ \t]" in
6629 let elems = Str.split
r s in
6630 List.map
key_of_string elems
6633 let copykeyhashes c =
6634 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6637 let config_of c attrs
=
6641 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6642 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6643 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6644 | "preload" -> { c with preload = bool_of_string
v }
6645 | "page-bias" -> { c with pagebias
= int_of_string
v }
6646 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6647 | "horizontal-scroll-step" ->
6648 { c with hscrollstep
= max
(int_of_string
v) 1 }
6649 | "auto-scroll-step" ->
6650 { c with autoscrollstep
= max
0 (int_of_string
v) }
6651 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6652 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6655 match String.lowercase
v with
6656 | "true" -> Some infinity
6658 | f -> Some
(float_of_string
f)
6660 { c with maxwait
= mw}
6661 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6662 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6663 | "vertical-margin" ->
6664 { c with interpagespace
= max
0 (int_of_string
v) }
6666 let zoom = float_of_string
v /. 100. in
6667 let zoom = max
zoom 0.0 in
6668 { c with zoom = zoom }
6669 | "presentation" -> { c with presentation
= bool_of_string
v }
6670 | "rotation-angle" -> { c with angle
= int_of_string
v }
6671 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6672 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6673 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6674 | "proportional-display" ->
6677 then FitProportional
6680 { c with fitmodel
= fm }
6681 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6682 | "pixmap-cache-size" ->
6683 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6684 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6685 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6686 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6687 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6688 | "background-color" -> { c with bgcolor
= color_of_string v }
6689 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6690 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6691 | "mupdf-store-size" ->
6692 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6693 | "checkers" -> { c with checkers
= bool_of_string
v }
6694 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6695 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6696 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6697 | "uri-launcher" -> { c with urilauncher
= unent v }
6698 | "path-launcher" -> { c with pathlauncher
= unent v }
6699 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6700 | "invert-colors" -> { c with invert
= bool_of_string
v }
6701 | "brightness" -> { c with colorscale
= float_of_string
v }
6702 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6704 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6706 let (n, _, _) as nab
= multicolumns_of_string v in
6708 then { c with columns
= Csplit
(-n, [||]) }
6709 else { c with columns
= Cmulti
(nab
, [||]) }
6710 | "birds-eye-columns" ->
6711 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6712 | "selection-command" -> { c with selcmd
= unent v }
6713 | "synctex-command" -> { c with stcmd
= unent v }
6714 | "pax-command" -> { c with paxcmd
= unent v }
6715 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6716 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6717 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6718 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6719 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6720 | "horizontal-scrollbar-visible" ->
6723 then c.scrollb
lor scrollbhv
6724 else c.scrollb
land (lnot
scrollbhv)
6726 { c with scrollb
= b }
6727 | "vertical-scrollbar-visible" ->
6730 then c.scrollb
lor scrollbvv
6731 else c.scrollb
land (lnot
scrollbvv)
6733 { c with scrollb
= b }
6734 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6738 then Some
(ref (0.0, 0, 0))
6740 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6743 prerr_endline
("Error processing attribute (`" ^
6744 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6747 let rec fold c = function
6750 let c = apply c k v in
6753 fold { c with keyhashes
= copykeyhashes c } attrs
;
6756 let fromstring f pos
n v d =
6759 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6760 n v pos
(exntos exn
)
6765 let bookmark_of attrs
=
6766 let rec fold title page
rely visy
= function
6767 | ("title", v) :: rest
-> fold v page
rely visy rest
6768 | ("page", v) :: rest
-> fold title v rely visy rest
6769 | ("rely", v) :: rest
-> fold title page
v visy rest
6770 | ("visy", v) :: rest
-> fold title page
rely v rest
6771 | _ :: rest
-> fold title page
rely visy rest
6772 | [] -> title, page
, rely, visy
6774 fold "invalid" "0" "0" "0" attrs
6778 let rec fold path page
rely pan visy
= function
6779 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6780 | ("page", v) :: rest
-> fold path v rely pan visy rest
6781 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6782 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6783 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6784 | _ :: rest
-> fold path page
rely pan visy rest
6785 | [] -> path, page
, rely, pan
, visy
6787 fold "" "0" "0" "0" "0" attrs
6791 let rec fold rs ls
= function
6792 | ("out", v) :: rest
-> fold v ls rest
6793 | ("in", v) :: rest
-> fold rs
v rest
6794 | _ :: rest
-> fold ls rs rest
6800 let setconf dst
src =
6801 dst
.scrollbw
<- src.scrollbw
;
6802 dst
.scrollh
<- src.scrollh
;
6803 dst
.icase
<- src.icase
;
6804 dst
.preload <- src.preload;
6805 dst
.pagebias
<- src.pagebias
;
6806 dst
.verbose
<- src.verbose
;
6807 dst
.scrollstep
<- src.scrollstep
;
6808 dst
.maxhfit
<- src.maxhfit
;
6809 dst
.crophack
<- src.crophack
;
6810 dst
.autoscrollstep
<- src.autoscrollstep
;
6811 dst
.maxwait
<- src.maxwait
;
6812 dst
.hlinks
<- src.hlinks
;
6813 dst
.underinfo
<- src.underinfo
;
6814 dst
.interpagespace
<- src.interpagespace
;
6815 dst
.zoom <- src.zoom;
6816 dst
.presentation
<- src.presentation
;
6817 dst
.angle
<- src.angle
;
6818 dst
.cwinw
<- src.cwinw
;
6819 dst
.cwinh
<- src.cwinh
;
6820 dst
.savebmarks
<- src.savebmarks
;
6821 dst
.memlimit
<- src.memlimit
;
6822 dst
.fitmodel
<- src.fitmodel
;
6823 dst
.texcount
<- src.texcount
;
6824 dst
.sliceheight
<- src.sliceheight
;
6825 dst
.thumbw
<- src.thumbw
;
6826 dst
.jumpback
<- src.jumpback
;
6827 dst
.bgcolor
<- src.bgcolor
;
6828 dst
.tilew
<- src.tilew
;
6829 dst
.tileh
<- src.tileh
;
6830 dst
.mustoresize
<- src.mustoresize
;
6831 dst
.checkers
<- src.checkers
;
6832 dst
.aalevel
<- src.aalevel
;
6833 dst
.trimmargins
<- src.trimmargins
;
6834 dst
.trimfuzz
<- src.trimfuzz
;
6835 dst
.urilauncher
<- src.urilauncher
;
6836 dst
.colorspace
<- src.colorspace
;
6837 dst
.invert
<- src.invert
;
6838 dst
.colorscale
<- src.colorscale
;
6839 dst
.redirectstderr <- src.redirectstderr;
6840 dst
.ghyllscroll
<- src.ghyllscroll
;
6841 dst
.columns
<- src.columns
;
6842 dst
.beyecolumns
<- src.beyecolumns
;
6843 dst
.selcmd
<- src.selcmd
;
6844 dst
.updatecurs
<- src.updatecurs
;
6845 dst
.pathlauncher
<- src.pathlauncher
;
6846 dst
.keyhashes
<- copykeyhashes src;
6847 dst
.hfsize
<- src.hfsize
;
6848 dst
.hscrollstep
<- src.hscrollstep
;
6849 dst
.pgscale <- src.pgscale;
6850 dst
.usepbo
<- src.usepbo
;
6851 dst
.wheelbypage
<- src.wheelbypage
;
6852 dst
.stcmd
<- src.stcmd
;
6853 dst
.paxcmd
<- src.paxcmd
;
6854 dst
.scrollb
<- src.scrollb
;
6855 dst
.riani
<- src.riani
;
6856 dst
.paxmark
<- src.paxmark
;
6860 else Some
((ref (0.0, 0, 0)));
6864 let h = Hashtbl.create
10 in
6865 let dc = { defconf with angle
= defconf.angle
} in
6866 let rec toplevel v t spos
_ =
6868 | Vdata
| Vcdata
| Vend
-> v
6869 | Vopen
("llppconfig", _, closed
) ->
6872 else { v with f = llppconfig
}
6874 error
"unexpected subelement at top level" s spos
6875 | Vclose
_ -> error
"unexpected close at top level" s spos
6877 and llppconfig
v t spos
_ =
6879 | Vdata
| Vcdata
-> v
6880 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6881 | Vopen
("defaults", attrs
, closed
) ->
6882 let c = config_of dc attrs
in
6886 else { v with f = defaults
}
6888 | Vopen
("ui-font", attrs
, closed
) ->
6889 let rec getsize size
= function
6891 | ("size", v) :: rest
->
6893 fromstring int_of_string spos
"size" v fstate.fontsize
in
6895 | l -> getsize size l
6897 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6900 else { v with f = uifont
(Buffer.create
10) }
6902 | Vopen
("doc", attrs
, closed
) ->
6903 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6904 let path = unent pathent
6905 and pageno = fromstring int_of_string spos
"page" spage
0
6906 and rely = fromstring float_of_string spos
"rely" srely
0.0
6907 and pan
= fromstring int_of_string spos
"pan" span
0
6908 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6909 let c = config_of dc attrs
in
6910 let anchor = (pageno, rely, visy
) in
6912 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6913 else { v with f = doc
path pan
anchor c [] }
6916 error
"unexpected subelement in llppconfig" s spos
6918 | Vclose
"llppconfig" -> { v with f = toplevel }
6919 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6921 and defaults
v t spos
_ =
6923 | Vdata
| Vcdata
-> v
6924 | Vend
-> error
"unexpected end of input in defaults" s spos
6925 | Vopen
("keymap", attrs
, closed
) ->
6927 try List.assoc
"mode" attrs
6928 with Not_found
-> "global" in
6933 let h = findkeyhash dc modename in
6934 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6937 { v with f = pkeymap
ret KeyMap.empty }
6939 | Vopen
(_, _, _) ->
6940 error
"unexpected subelement in defaults" s spos
6942 | Vclose
"defaults" ->
6943 { v with f = llppconfig
}
6945 | Vclose
_ -> error
"unexpected close in defaults" s spos
6947 and uifont
b v t spos
epos =
6950 Buffer.add_substring
b s spos
(epos - spos
);
6952 | Vopen
(_, _, _) ->
6953 error
"unexpected subelement in ui-font" s spos
6954 | Vclose
"ui-font" ->
6955 if emptystr
!fontpath
6956 then fontpath := Buffer.contents
b;
6957 { v with f = llppconfig
}
6958 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6959 | Vend
-> error
"unexpected end of input in ui-font" s spos
6961 and doc
path pan
anchor c bookmarks
v t spos
_ =
6963 | Vdata
| Vcdata
-> v
6964 | Vend
-> error
"unexpected end of input in doc" s spos
6965 | Vopen
("bookmarks", _, closed
) ->
6968 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6970 | Vopen
("keymap", attrs
, closed
) ->
6972 try List.assoc
"mode" attrs
6973 with Not_found
-> "global"
6979 let h = findkeyhash c modename in
6980 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6981 doc
path pan
anchor c bookmarks
6983 { v with f = pkeymap
ret KeyMap.empty }
6985 | Vopen
(_, _, _) ->
6986 error
"unexpected subelement in doc" s spos
6989 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6990 { v with f = llppconfig
}
6992 | Vclose
_ -> error
"unexpected close in doc" s spos
6994 and pkeymap
ret keymap
v t spos
_ =
6996 | Vdata
| Vcdata
-> v
6997 | Vend
-> error
"unexpected end of input in keymap" s spos
6998 | Vopen
("map", attrs
, closed
) ->
6999 let r, l = map_of attrs
in
7000 let kss = fromstring keys_of_string spos
"in" r [] in
7001 let lss = fromstring keys_of_string spos
"out" l [] in
7005 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7006 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7009 then { v with f = pkeymap
ret keymap }
7012 { v with f = skip
"map" f }
7015 error
"unexpected subelement in keymap" s spos
7017 | Vclose
"keymap" ->
7018 { v with f = ret keymap }
7020 | Vclose
_ -> error
"unexpected close in keymap" s spos
7022 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7024 | Vdata
| Vcdata
-> v
7025 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7026 | Vopen
("item", attrs
, closed
) ->
7027 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7028 let page = fromstring int_of_string spos
"page" spage
0
7029 and rely = fromstring float_of_string spos
"rely" srely
0.0
7030 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7032 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
7035 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7038 { v with f = skip
"item" f }
7041 error
"unexpected subelement in bookmarks" s spos
7043 | Vclose
"bookmarks" ->
7044 { v with f = doc
path pan
anchor c bookmarks }
7046 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7048 and skip tag
f v t spos
_ =
7050 | Vdata
| Vcdata
-> v
7052 error
("unexpected end of input in skipped " ^ tag
) s spos
7053 | Vopen
(tag'
, _, closed
) ->
7057 let f'
() = { v with f = skip tag
f } in
7058 { v with f = skip tag'
f'
}
7062 else error
("unexpected close in skipped " ^ tag
) s spos
7065 parse
{ f = toplevel; accu = () } s;
7071 let len = in_channel_length ic
in
7072 let s = String.create
len in
7073 really_input ic
s 0 len;
7076 | Parse_error
(msg
, s, pos
) ->
7077 let subs = subs s pos
in
7078 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7081 failwith
("config load error: " ^ exntos exn
)
7087 let dir = Filename.concat
home ".config" in
7088 if Sys.is_directory
dir then dir else home
7091 Filename.concat
dir "llpp.conf"
7094 let confpath = ref defconfpath;;
7097 if Sys.file_exists
!confpath
7100 (try Some
(open_in_bin
!confpath)
7103 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7114 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7123 f (Hashtbl.create
0, defconf)
7128 let pc, pb
, px, pa
=
7131 if emptystr
state.origin
7135 Hashtbl.find h (Filename.basename
key)
7136 with Not_found
-> dc, [], 0, emptyanchor
7140 state.bookmarks <- pb
;
7143 then state.anchor <- pa
;
7144 cbput state.hists
.nav pa
;
7150 let add_attrs bb always
dc c =
7153 then Printf.bprintf bb
"\n %s='%b'" s a
7156 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7159 then Printf.bprintf bb
"\n %s='%d'" s a
7162 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7165 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7168 then Printf.bprintf bb
"\n %s='%f'" s a
7172 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7176 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7180 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7184 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7190 | Some
(_N
, _A
, _B
) ->
7191 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7201 else string_of_float
f
7203 Printf.bprintf bb
"\n %s='%s'" s v
7208 | Cmulti
((n, a, b), _) when n > 1 ->
7209 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7210 | Csplit
(n, _) when n > 1 ->
7211 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7217 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7222 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7226 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7230 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7232 oi
"width" c.cwinw
dc.cwinw
;
7233 oi
"height" c.cwinh
dc.cwinh
;
7234 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7235 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7236 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7237 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7238 ob "case-insensitive-search" c.icase
dc.icase
;
7239 ob "preload" c.preload dc.preload;
7240 oi
"page-bias" c.pagebias
dc.pagebias
;
7241 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7242 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7243 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7244 ob "crop-hack" c.crophack
dc.crophack
;
7245 oW
"throttle" c.maxwait
dc.maxwait
;
7246 ob "highlight-links" c.hlinks
dc.hlinks
;
7247 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7248 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7249 oz
"zoom" c.zoom dc.zoom;
7250 ob "presentation" c.presentation
dc.presentation
;
7251 oi
"rotation-angle" c.angle
dc.angle
;
7252 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7253 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7254 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7255 oi
"tex-count" c.texcount
dc.texcount
;
7256 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7257 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7258 ob "persistent-location" c.jumpback
dc.jumpback
;
7259 oc
"background-color" c.bgcolor
dc.bgcolor
;
7260 oi
"tile-width" c.tilew
dc.tilew
;
7261 oi
"tile-height" c.tileh
dc.tileh
;
7262 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7263 ob "checkers" c.checkers
dc.checkers
;
7264 oi
"aalevel" c.aalevel
dc.aalevel
;
7265 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7266 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7267 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7268 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7269 oC
"color-space" c.colorspace
dc.colorspace
;
7270 ob "invert-colors" c.invert
dc.invert
;
7271 oF
"brightness" c.colorscale
dc.colorscale
;
7272 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7273 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7274 oco
"columns" c.columns
dc.columns
;
7275 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7276 os
"selection-command" c.selcmd
dc.selcmd
;
7277 os
"synctex-command" c.stcmd
dc.stcmd
;
7278 os
"pax-command" c.paxcmd
dc.paxcmd
;
7279 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7280 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7281 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7282 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7283 ob "use-pbo" c.usepbo
dc.usepbo
;
7284 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7285 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7286 op
"point-and-x" c.pax
dc.pax
;
7287 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7290 let keymapsbuf always
dc c =
7291 let bb = Buffer.create
16 in
7292 let rec loop = function
7294 | (modename, h) :: rest
->
7295 let dh = findkeyhash dc modename in
7296 if always
|| h <> dh
7298 if Hashtbl.length
h > 0
7300 if Buffer.length
bb > 0
7301 then Buffer.add_char
bb '
\n'
;
7302 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7303 Hashtbl.iter
(fun i
o ->
7304 let isdifferent = always
||
7306 let dO = Hashtbl.find dh i
in
7308 with Not_found
-> true
7313 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7314 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7315 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7316 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7317 Buffer.add_string
bb (Wsi.keyname
k);
7320 let rec loop = function
7322 | km
:: [] -> addkm km
7323 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7327 Buffer.add_string
bb "<map in='";
7331 Buffer.add_string
bb "' out='";
7333 Buffer.add_string
bb "'/>\n"
7336 Buffer.add_string
bb "' out='";
7338 Buffer.add_string
bb "'/>\n"
7340 | KMmulti
(ins, kms
) ->
7341 Buffer.add_char
bb ' '
;
7343 Buffer.add_string
bb "' out='";
7345 Buffer.add_string
bb "'/>\n"
7347 Buffer.add_string
bb "</keymap>";
7357 let uifontsize = fstate.fontsize
in
7358 let bb = Buffer.create
32768 in
7359 let relx = float state.x /. float state.winw in
7361 let cx w = truncate
(relx *. float w) in
7363 (fun (w, h, x) ws
->
7365 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7366 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7367 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7369 (state.winw, state.winh
, state.x) state.winstate
7374 let dc = if conf.bedefault
then conf else dc in
7375 Buffer.add_string
bb "<llppconfig>\n";
7377 if nonemptystr
!fontpath
7379 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7385 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7388 Buffer.add_string
bb "<defaults ";
7389 add_attrs bb true dc dc;
7390 let kb = keymapsbuf true dc dc in
7391 if Buffer.length
kb > 0
7393 Buffer.add_string
bb ">\n";
7394 Buffer.add_buffer
bb kb;
7395 Buffer.add_string
bb "\n</defaults>\n";
7397 else Buffer.add_string
bb "/>\n";
7399 let adddoc path pan
anchor c bookmarks =
7400 if bookmarks == [] && c = dc && anchor = emptyanchor
7403 Printf.bprintf
bb "<doc path='%s'"
7404 (enent
path 0 (String.length
path));
7406 if anchor <> emptyanchor
7408 let n, rely, visy
= anchor in
7409 Printf.bprintf
bb " page='%d'" n;
7412 Printf.bprintf
bb " rely='%f'" rely
7414 if abs_float visy
> 1e-6
7416 Printf.bprintf
bb " visy='%f'" visy
7421 then Printf.bprintf
bb " pan='%d'" pan
;
7423 add_attrs bb false dc c;
7424 let kb = keymapsbuf false dc c in
7426 begin match bookmarks with
7428 if Buffer.length
kb > 0
7430 Buffer.add_string
bb ">\n";
7431 Buffer.add_buffer
bb kb;
7432 Buffer.add_string
bb "\n</doc>\n";
7434 else Buffer.add_string
bb "/>\n"
7436 Buffer.add_string
bb ">\n<bookmarks>\n";
7437 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7439 "<item title='%s' page='%d'"
7440 (enent
title 0 (String.length
title))
7445 Printf.bprintf
bb " rely='%f'" rely
7447 if abs_float visy
> 1e-6
7449 Printf.bprintf
bb " visy='%f'" visy
7451 Buffer.add_string
bb "/>\n";
7453 Buffer.add_string
bb "</bookmarks>";
7454 if Buffer.length
kb > 0
7456 Buffer.add_string
bb "\n";
7457 Buffer.add_buffer
bb kb;
7459 Buffer.add_string
bb "\n</doc>\n";
7465 match state.mode with
7466 | Birdseye
(c, pan, _, _, _) ->
7468 match conf.columns
with
7469 | Cmulti
((c, _, _), _) -> Some
c
7473 match c.columns
with
7474 | Cmulti
(c, _) -> Cmulti
(c, [||])
7475 | Csingle
_ -> Csingle
[||]
7476 | Csplit
_ -> failwith
"quit from bird's eye while split"
7478 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7481 let basename = Filename.basename
7482 (if emptystr
state.origin
then state.path else state.origin
)
7484 adddoc basename pan (getanchor ())
7486 let autoscrollstep =
7487 match state.autoscroll
with
7489 | None
-> conf.autoscrollstep
7491 match state.mode with
7492 | Birdseye
(bc
, _, _, _, _) ->
7495 presentation
= bc
.presentation
;
7496 interpagespace
= bc
.interpagespace
;
7497 maxwait
= bc
.maxwait
;
7498 autoscrollstep = autoscrollstep }
7499 | _ -> { conf with autoscrollstep = autoscrollstep }
7501 (if conf.savebmarks
then state.bookmarks else []);
7503 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7505 then adddoc path x anchor c bookmarks
7507 Buffer.add_string
bb "</llppconfig>\n";
7510 if load1 f && Buffer.length
bb > 0
7513 let tmp = !confpath ^
".tmp" in
7514 let oc = open_out_bin
tmp in
7515 Buffer.output_buffer
oc bb;
7517 Unix.rename
tmp !confpath;
7520 ("error while saving configuration: " ^ exntos exn
)
7524 let adderrmsg src msg
=
7525 Buffer.add_string
state.errmsgs msg
;
7526 state.newerrmsgs
<- true;
7530 let adderrfmt src fmt
=
7531 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7535 let cl = splitatspace cmds
in
7537 try Scanf.sscanf
s fmt
f
7539 adderrfmt "remote exec"
7540 "error processing '%S': %s\n" cmds
(exntos exn
)
7543 | "reload" :: [] -> reload ()
7544 | "goto" :: args :: [] ->
7545 scan args "%u %f %f"
7547 let cmd, _ = state.geomcmds
in
7549 then gotopagexy pageno x y
7552 gotopagexy pageno x y;
7555 state.reprf
<- f state.reprf
7557 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7558 | "rect" :: args :: [] ->
7559 scan args "%u %u %f %f %f %f"
7560 (fun pageno color x0 y0 x1 y1 ->
7561 onpagerect pageno (fun w h ->
7562 let _,w1,h1
,_ = getpagedim pageno in
7563 let sw = float w1 /. float w
7564 and sh = float h1
/. float h in
7568 and y1s
= y1 *. sh in
7569 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7571 state.rects <- (pageno, color, rect) :: state.rects;
7572 G.postRedisplay "rect";
7575 | "activatewin" :: [] -> Wsi.activatewin
()
7576 | "quit" :: [] -> raise Quit
7578 adderrfmt "remote command"
7579 "error processing remote command: %S\n" cmds
;
7583 let scratch = String.create
80 in
7584 let buf = Buffer.create
80 in
7587 try Some
(Unix.read fd
scratch 0 80)
7589 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7590 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7593 match tempfr () with
7599 if Buffer.length
buf > 0
7601 let s = Buffer.contents
buf in
7611 let pos = String.index_from
scratch ppos '
\n'
in
7612 if pos >= n then -1 else pos
7613 with Not_found
-> -1
7617 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7618 let s = Buffer.contents
buf in
7624 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7630 let remoteopen path =
7631 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7633 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7638 let trimcachepath = ref "" in
7639 let rcmdpath = ref "" in
7640 selfexec := Sys.executable_name
;
7643 [("-p", Arg.String
(fun s -> state.password
<- s),
7644 "<password> Set password");
7648 Config.fontpath := s;
7649 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7651 "<path> Set path to the user interface font");
7655 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7656 Config.confpath := s),
7657 "<path> Set path to the configuration file");
7659 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7660 "<path> Set path to the trim cache file");
7662 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7663 "<named-destination> Set named destination");
7665 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7666 ("-cxack", Arg.Set
cxack, " Cut corners");
7668 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7669 "<path> Set path to the remote commands source");
7671 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7672 "<original-path> Set original path");
7674 ("-v", Arg.Unit
(fun () ->
7676 "%s\nconfiguration path: %s\n"
7680 exit
0), " Print version and exit");
7683 (fun s -> state.path <- s)
7684 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7687 then selfexec := !selfexec ^
" -wtmode";
7689 if emptystr
state.path
7690 then (prerr_endline
"file name missing"; exit
1);
7692 if not
(Config.load ())
7693 then prerr_endline
"failed to load configuration";
7695 let wsfd, winw, winh
= Wsi.init
(object
7696 val mutable m_hack
= false
7697 method expose
= if not m_hack
then G.postRedisplay "expose"
7698 method visible
= G.postRedisplay "visible"
7699 method display = m_hack
<- false; display ()
7700 method reshape w h =
7701 m_hack
<- w < state.winw && h < state.winh
;
7703 method mouse b d x y m = mouse b d x y m
7704 method motion x y = state.mpos
<- (x, y); motion x y
7705 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7707 let mascm = m land (
7708 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7710 match state.keystate
with
7712 let km = k, mascm in
7715 let modehash = state.uioh#
modehash in
7716 try Hashtbl.find modehash km
7718 try Hashtbl.find (findkeyhash conf "global") km
7719 with Not_found
-> KMinsrt
(k, m)
7721 | KMinsrt
(k, m) -> keyboard k m
7722 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7723 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7725 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7726 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7727 state.keystate
<- KSnone
7728 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7729 state.keystate
<- KSinto
(keys
, insrt
)
7731 state.keystate
<- KSnone
7733 method enter
x y = state.mpos
<- (x, y); pmotion x y
7734 method leave = state.mpos
<- (-1, -1)
7735 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7736 method quit
= raise Quit
7737 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7742 List.exists
GlMisc.check_extension
7743 [ "GL_ARB_texture_rectangle"
7744 ; "GL_EXT_texture_recangle"
7745 ; "GL_NV_texture_rectangle" ]
7747 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7750 let r = GlMisc.get_string `renderer
in
7751 let p = "Mesa DRI Intel(" in
7752 let l = String.length
p in
7753 String.length
r > l && String.sub
r 0 l = p
7756 defconf.sliceheight
<- 1024;
7757 defconf.texcount
<- 32;
7758 defconf.usepbo
<- true;
7762 match Ne.pipe () with
7764 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7768 match Ne.pipe () with
7770 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7780 setcheckers conf.checkers
;
7782 if conf.redirectstderr
7785 let s = Buffer.contents
state.errmsgs ^
7786 (match state.errfd
with
7788 let s = String.create
(80*24) in
7791 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7793 then Unix.read fd
s 0 (String.length
s)
7799 else String.sub
s 0 n
7803 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7804 with exn
-> print_endline
(exntos exn
)
7809 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7810 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7811 !Config.fontpath, !trimcachepath,
7812 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7816 state.text <- "Opening " ^
(mbtoutf8
state.path);
7818 opendoc state.path state.password
;
7822 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7825 if nonemptystr
!rcmdpath
7826 then remoteopen !rcmdpath
7831 let rec loop deadline
=
7833 match state.errfd
with
7834 | None
-> [state.sr
; state.wsfd]
7835 | Some fd
-> [state.sr
; state.wsfd; fd
]
7840 | Some fd
-> fd
:: r
7844 state.redisplay
<- false;
7851 if deadline
= infinity
7853 else max
0.0 (deadline
-. now)
7858 try Unix.select
r [] [] timeout
7859 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7865 if state.ghyll
== noghyll
7867 match state.autoscroll
with
7868 | Some step
when step
!= 0 ->
7869 let y = state.y + step
in
7873 else if y >= state.maxy then 0 else y
7876 if state.mode = View
7877 then state.text <- "";
7880 else deadline
+. 0.01
7885 let rec checkfds = function
7887 | fd
:: rest
when fd
= state.sr
->
7888 let cmd = readcmd state.sr
in
7892 | fd
:: rest
when fd
= state.wsfd ->
7896 | fd
:: rest
when Some fd
= !optrfd ->
7897 begin match remote fd
with
7898 | None
-> optrfd := remoteopen !rcmdpath;
7899 | opt -> optrfd := opt
7904 let s = String.create
80 in
7905 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7906 if conf.redirectstderr
7908 Buffer.add_substring
state.errmsgs
s 0 n;
7909 state.newerrmsgs
<- true;
7910 state.redisplay
<- true;
7913 prerr_string
(String.sub
s 0 n);
7921 if deadline
= infinity
7925 match state.autoscroll
with
7926 | Some step
when step
!= 0 -> deadline1
7927 | _ -> if state.ghyll
== noghyll then infinity
else deadline1