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 bsearch 0 (state.pagecount
-1);
1375 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1376 let sh = sh - (hscrollh ()) in
1377 let rec fold accu
n =
1378 if n = Array.length
b
1381 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1384 || n = state.pagecount
- coverB
1385 || (n - coverA
) mod columns
= columns
- 1)
1391 let pagey = max
0 (y - vy) in
1392 let pagedispy = if pagey > 0 then 0 else vy - y in
1393 let pagedispx, pagex
=
1395 if n = coverA
- 1 || n = state.pagecount
- coverB
1396 then state.x + (wadjsb state.winw
- w
) / 2
1397 else dx + xoff
+ state.x
1404 let vw = wadjsb state.winw
- pagedispx in
1405 let pw = w
- pagex
in
1408 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1409 if pagevw > 0 && pagevh > 0
1413 ; pagedimno
= pdimno
1420 ; pagedispx = pagedispx
1421 ; pagedispy = pagedispy
1433 if Array.length
b = 0
1435 else List.rev
(fold [] (page_of_y y))
1438 let layoutS (columns
, b) y sh =
1439 let sh = sh - hscrollh () in
1440 let rec fold accu n =
1441 if n = Array.length
b
1444 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1451 let x = xoff
+ state.x in
1452 let pagey = max
0 (y - vy) in
1453 let pagedispy = if pagey > 0 then 0 else vy - y in
1454 let pagedispx, pagex
=
1468 let pagecolw = pagew
/columns
in
1470 if pagecolw < state.winw
1471 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1475 let vw = wadjsb state.winw
- pagedispx in
1476 let pw = pagew
- pagex
in
1479 let pagevw = min
pagevw pagecolw in
1480 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1481 if pagevw > 0 && pagevh > 0
1484 { pageno = n/columns
1485 ; pagedimno
= pdimno
1492 ; pagedispx = pagedispx
1493 ; pagedispy = pagedispy
1494 ; pagecol
= n mod columns
1505 List.rev
(fold [] 0)
1509 if nogeomcmds state.geomcmds
1511 match conf.columns
with
1512 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1513 | Cmulti
c -> layoutN c y sh
1514 | Csplit
s -> layoutS s y sh
1519 let y = state.y + incr
in
1521 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1526 let tilex = l.pagex
mod conf.tilew
in
1527 let tiley = l.pagey mod conf.tileh
in
1529 let col = l.pagex
/ conf.tilew
in
1530 let row = l.pagey / conf.tileh
in
1532 let rec rowloop row y0 dispy h
=
1536 let dh = conf.tileh
- y0 in
1537 let dh = min h
dh in
1538 let rec colloop col x0 dispx w
=
1542 let dw = conf.tilew
- x0 in
1543 let dw = min w
dw in
1545 f col row dispx dispy
x0 y0 dw dh;
1546 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1549 colloop col tilex l.pagedispx l.pagevw;
1550 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1553 if l.pagevw > 0 && l.pagevh > 0
1554 then rowloop row tiley l.pagedispy l.pagevh;
1557 let gettileopaque l col row =
1559 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1561 try Some
(Hashtbl.find state.tilemap
key)
1562 with Not_found
-> None
1565 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1566 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1567 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1570 let drawtiles l color
=
1572 let f col row x y tilex tiley w h
=
1573 match gettileopaque l col row with
1574 | Some
(opaque
, _, t
) ->
1575 let params = x, y, w
, h
, tilex, tiley in
1579 GlFunc.blend_func `zero `one_minus_src_color
;
1581 drawtile
params opaque
;
1583 then Gl.disable `blend
;
1586 let s = Printf.sprintf
1590 let w = measurestr
fstate.fontsize
s in
1591 GlMisc.push_attrib
[`current
];
1592 GlDraw.color
(0.0, 0.0, 0.0);
1594 (float (x-2), float (y-2))
1595 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1596 GlDraw.color
(1.0, 1.0, 1.0);
1597 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1598 GlMisc.pop_attrib
();
1603 let lw = wadjsb state.winw
- x in
1606 let lh = state.winh
- y in
1609 begin match state.texid
with
1611 Gl.enable `texture_2d
;
1612 GlTex.bind_texture `texture_2d id
;
1615 and x1 = float (x+w)
1616 and y1 = float (y+h
) in
1618 let tw = float w /. 16.0
1619 and th
= float h
/. 16.0 in
1620 let tx0 = float tilex /. 16.0
1621 and ty0
= float tiley /. 16.0 in
1623 and ty1
= ty0
+. th
in
1624 GlDraw.begins `quads
;
1625 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1626 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1627 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1628 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1631 Gl.disable `texture_2d
;
1633 GlDraw.color
(1.0, 1.0, 1.0);
1636 (float (x+w), float (y+h
));
1638 if w > 128 && h
> fstate.fontsize
+ 10
1640 GlDraw.color
(0.0, 0.0, 0.0);
1643 then (col*conf.tilew
, row*conf.tileh
)
1646 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1653 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1655 let tilevisible1 l x y =
1657 and ax1
= l.pagex
+ l.pagevw
1659 and ay1
= l.pagey + l.pagevh in
1663 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1664 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1666 let rx0 = max
ax0 bx0
1667 and ry0
= max ay0 by0
1668 and rx1
= min ax1
bx1
1669 and ry1
= min ay1 by1
in
1671 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1672 nonemptyintersection
1675 let tilevisible layout n x y =
1676 let rec findpageinlayout m
= function
1677 | l :: rest
when l.pageno = n ->
1678 tilevisible1 l x y || (
1679 match conf.columns
with
1680 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1683 | _ :: rest
-> findpageinlayout 0 rest
1686 findpageinlayout 0 layout;
1689 let tileready l x y =
1690 tilevisible1 l x y &&
1691 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1694 let tilepage n p
layout =
1695 let rec loop = function
1699 let f col row _ _ _ _ _ _ =
1700 if state.currently
= Idle
1702 match gettileopaque l col row with
1705 let x = col*conf.tilew
1706 and y = row*conf.tileh
in
1708 let w = l.pagew
- x in
1712 let h = l.pageh
- y in
1717 then getpbo
w h conf.colorspace
1720 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1723 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1724 conf.tilew
, conf.tileh
1733 if nogeomcmds state.geomcmds
1737 let preloadlayout y =
1738 let y = if y < state.winh
then 0 else y - state.winh
in
1739 let h = state.winh
*3 in
1744 let rec loop pages
=
1745 if state.currently
!= Idle
1750 begin match getopaque l.pageno with
1752 wcmd "page %d %d" l.pageno l.pagedimno
;
1753 state.currently
<- Loading
(l, state.gen
);
1755 tilepage l.pageno opaque pages
;
1760 if nogeomcmds state.geomcmds
1766 if conf.preload && state.currently
= Idle
1767 then load (preloadlayout state.y);
1770 let layoutready layout =
1771 let rec fold all ls
=
1772 all
&& match ls
with
1774 let seen = ref false in
1775 let allvisible = ref true in
1776 let foo col row _ _ _ _ _ _ =
1778 allvisible := !allvisible &&
1779 begin match gettileopaque l col row with
1785 fold (!seen && !allvisible) rest
1788 let alltilesvisible = fold true layout in
1793 let y = bound y 0 state.maxy
in
1794 let y, layout, proceed
=
1795 match conf.maxwait
with
1796 | Some time
when state.ghyll
== noghyll ->
1797 begin match state.throttle
with
1799 let layout = layout y state.winh
in
1800 let ready = layoutready layout in
1804 state.throttle
<- Some
(layout, y, now ());
1806 else G.postRedisplay "gotoy showall (None)";
1808 | Some
(_, _, started
) ->
1809 let dt = now () -. started
in
1812 state.throttle
<- None
;
1813 let layout = layout y state.winh
in
1815 G.postRedisplay "maxwait";
1822 let layout = layout y state.winh
in
1823 if not
!wtmode || layoutready layout
1824 then G.postRedisplay "gotoy ready";
1830 state.layout <- layout;
1831 begin match state.mode
with
1832 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1833 let rec loop = function
1835 state.mode
<- LinkNav
(Ltgendir
0)
1836 | l :: _ when l.pageno = pageno ->
1837 begin match getopaque pageno with
1839 state.mode
<- LinkNav
(Ltgendir
0)
1841 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1842 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1843 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1844 then state.mode
<- LinkNav
(Ltgendir
0)
1846 | _ :: rest
-> loop rest
1851 begin match state.mode
with
1852 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1853 if not
(pagevisible layout pageno)
1855 match state.layout with
1858 state.mode
<- Birdseye
(
1859 conf, leftx
, l.pageno, hooverpageno
, anchor
1862 | LinkNav
(Ltgendir dir
as lt
) ->
1864 let rec loop = function
1867 match getopaque l.pageno with
1873 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1875 if dir
> 0 then LDfirst
else LDlast
1881 | Lnotfound
-> loop rest
1883 showlinktype (getlink opaque
n);
1884 Ltexact
(l.pageno, n)
1888 state.mode
<- LinkNav
linknav
1893 state.ghyll
<- noghyll;
1896 let mx, my
= state.mpos
in
1901 let conttiling pageno opaque
=
1902 tilepage pageno opaque
1903 (if conf.preload then preloadlayout state.y else state.layout)
1906 let gotoy_and_clear_text y =
1907 if not
conf.verbose
then state.text <- "";
1913 let coloff = l.pagecol
* l.pageh
in
1914 float (l.pagey + coloff) /. float l.pageh
1921 if conf.presentation
1922 then float l.pagedispy /. float (calcips l.pageh
)
1923 else float l.pagedispy /. float conf.interpagespace
1926 (l.pageno, top, dtop)
1930 match state.layout with
1931 | l :: _ -> getanchor1 l
1933 let n = page_of_y state.y in
1937 let y, h = getpageyh n in
1938 let dy = y - state.y in
1940 if conf.presentation
1942 let ips = calcips h in
1943 float (dy + ips) /. float ips
1945 float dy /. float conf.interpagespace
1950 let getanchory (n, top, dtop) =
1951 let y, h = getpageyh n in
1952 if conf.presentation
1954 let ips = calcips h in
1955 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1957 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1960 let gotoanchor anchor
=
1961 gotoy (getanchory anchor
);
1965 cbput state.hists
.nav
(getanchor ());
1969 let anchor = cbgetc state.hists
.nav dir
in
1974 let scroll f n a
b =
1975 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1977 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1979 then s (float f /. float a
)
1982 then 1.0 -. s ((float (f-b) /. float (n-b)))
1988 let ins = float a
*. 0.5
1989 and outs
= float (n-b) *. 0.5 in
1991 ins +. outs
+. float ones
1993 let rec set (_N
, _A
, _B
) y sy
=
1994 let sum = summa _N _A _B
in
1995 let dy = float (y - sy
) in
1999 then state.ghyll
<- noghyll
2002 let s = scroll n _N _A _B
in
2003 let y1 = y1 +. ((s *. dy) /. sum) in
2004 gotoy_and_clear_text (truncate
y1);
2005 state.ghyll
<- gf (n+1) y1;
2009 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2011 gf 0 (float state.y)
2014 match conf.ghyllscroll
with
2016 gotoy_and_clear_text y
2018 if state.ghyll
== noghyll
2019 then set nab
y state.y
2020 else state.ghyll
(Some
y)
2023 let gotopage n top =
2024 let y, h = getpageyh n in
2025 let y = y + (truncate
(top *. float h)) in
2029 let gotopage1 n top =
2030 let y = getpagey n in
2035 let invalidate s f =
2040 match state.geomcmds
with
2041 | ps
, [] when emptystr ps
->
2043 state.geomcmds
<- s, [];
2046 state.geomcmds
<- ps
, [s, f];
2048 | ps
, (s'
, _) :: rest
when s'
= s ->
2049 state.geomcmds
<- ps
, ((s, f) :: rest
);
2052 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2056 Hashtbl.iter
(fun _ opaque
->
2057 wcmd "freepage %s" opaque
;
2059 Hashtbl.clear
state.pagemap
;
2063 if not
(Queue.is_empty
state.tilelru
)
2065 Queue.iter
(fun (k
, p
, s) ->
2066 wcmd "freetile %s" p
;
2067 state.memused
<- state.memused
- s;
2068 Hashtbl.remove
state.tilemap k
;
2070 state.uioh#infochanged Memused
;
2071 Queue.clear
state.tilelru
;
2077 let h = truncate
(float h*.conf.zoom
) in
2078 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2082 let opendoc path password
=
2084 state.password
<- password
;
2085 state.gen
<- state.gen
+ 1;
2086 state.docinfo
<- [];
2089 setaalevel
conf.aalevel
;
2091 if emptystr
state.origin
2095 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2096 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2097 invalidate "reqlayout"
2099 wcmd "reqlayout %d %d %d %s\000"
2100 conf.angle
(FMTE.to_int conf.fitmodel
)
2101 (stateh state.winh
) state.nameddest
2106 state.anchor <- getanchor ();
2107 opendoc state.path
state.password
;
2111 let c = c *. conf.colorscale
in
2115 let scalecolor2 (r
, g, b) =
2116 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2119 let docolumns = function
2121 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2122 let rec loop pageno pdimno pdim
y ph pdims
=
2123 if pageno = state.pagecount
2126 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2128 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2129 pdimno+1, pdim
, rest
2133 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2135 (if conf.presentation
2136 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2137 else (if pageno = 0 then 0 else conf.interpagespace
)
2140 a.(pageno) <- (pdimno, x, y, pdim
);
2141 loop (pageno+1) pdimno pdim
(y + h) h pdims
2143 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2144 conf.columns
<- Csingle
a;
2146 | Cmulti
((columns
, coverA
, coverB
), _) ->
2147 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2148 let rec loop pageno pdimno pdim
x y rowh pdims
=
2149 let rec fixrow m
= if m
= pageno then () else
2150 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2153 let y = y + (rowh
- h) / 2 in
2154 a.(m
) <- (pdimno, x, y, pdim
);
2158 if pageno = state.pagecount
2159 then fixrow (((pageno - 1) / columns
) * columns
)
2161 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2163 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2164 pdimno+1, pdim
, rest
2169 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2171 let x = (wadjsb state.winw
- w) / 2 in
2173 if conf.presentation
then calcips h else conf.interpagespace
in
2174 x, y + ips + rowh
, h
2177 if (pageno - coverA
) mod columns
= 0
2179 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2181 if conf.presentation
2183 let ips = calcips h in
2184 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2186 y + (if pageno = 0 then 0 else conf.interpagespace
)
2190 else x, y, max rowh
h
2194 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2197 if pageno = columns
&& conf.presentation
2199 let ips = calcips rowh
in
2200 for i
= 0 to pred columns
2202 let (pdimno, x, y, pdim
) = a.(i
) in
2203 a.(i
) <- (pdimno, x, y+ips, pdim
)
2209 fixrow (pageno - columns
);
2214 a.(pageno) <- (pdimno, x, y, pdim
);
2215 let x = x + w + xoff
*2 + conf.interpagespace
in
2216 loop (pageno+1) pdimno pdim
x y rowh' pdims
2218 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2219 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2222 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2223 let rec loop pageno pdimno pdim
y pdims
=
2224 if pageno = state.pagecount
2227 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2229 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2230 pdimno+1, pdim
, rest
2235 let rec loop1 n x y =
2236 if n = c then y else (
2237 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2238 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2241 let y = loop1 0 0 y in
2242 loop (pageno+1) pdimno pdim
y pdims
2244 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2245 conf.columns
<- Csplit
(c, a);
2249 docolumns conf.columns
;
2250 state.maxy
<- calcheight ();
2251 if state.reprf
== noreprf
2253 match state.mode
with
2254 | Birdseye
(_, _, pageno, _, _) ->
2255 let y, h = getpageyh pageno in
2256 let top = (state.winh
- h) / 2 in
2257 gotoy (max
0 (y - top))
2258 | _ -> gotoanchor state.anchor
2262 state.reprf
<- noreprf;
2267 GlDraw.viewport
0 0 w h;
2268 let firsttime = state.geomcmds
== firstgeomcmds in
2269 if not
firsttime && nogeomcmds state.geomcmds
2270 then state.anchor <- getanchor ();
2273 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2276 setfontsize fstate.fontsize
;
2277 GlMat.mode `modelview
;
2278 GlMat.load_identity
();
2280 GlMat.mode `projection
;
2281 GlMat.load_identity
();
2282 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2283 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2284 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2289 else float state.x /. float state.w
2291 invalidate "geometry"
2295 then state.x <- truncate
(relx *. float w);
2297 match conf.columns
with
2299 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2300 | Csplit
(c, _) -> w * c
2302 wcmd "geometry %d %d %d"
2303 w (stateh h) (FMTE.to_int conf.fitmodel
)
2308 let len = String.length
state.text in
2311 match state.mode
with
2312 | Textentry
_ | View
| LinkNav
_ ->
2313 let h, _, _ = state.uioh#scrollpw
in
2319 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2320 (x+.w, float (state.winh
- hscrollh))
2323 let w = float (wadjsb state.winw
- 1) in
2324 if state.progress
>= 0.0 && state.progress
< 1.0
2326 GlDraw.color
(0.3, 0.3, 0.3);
2327 let w1 = w *. state.progress
in
2329 GlDraw.color
(0.0, 0.0, 0.0);
2333 GlDraw.color
(0.0, 0.0, 0.0);
2337 GlDraw.color
(1.0, 1.0, 1.0);
2338 drawstring fstate.fontsize
2339 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2342 match state.mode
with
2343 | Textentry
((prefix
, text, _, _, _, _), _) ->
2347 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2349 Printf.sprintf
"%s%s_" prefix
text
2358 if not
(istextentry state.mode
) && state.uioh#eformsgs
2360 let s1 = "(press 'e' to review error messasges)" in
2361 if nonemptystr
s then s ^
" " ^
s1 else s1
2371 let len = Queue.length
state.tilelru
in
2373 match state.throttle
with
2376 then preloadlayout state.y
2378 | Some
(layout, _, _) ->
2382 if state.memused
<= conf.memlimit
2387 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2388 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2389 let (_, pw, ph
, _) = getpagedim n in
2392 && colorspace
= conf.colorspace
2393 && angle
= conf.angle
2397 let x = col*conf.tilew
2398 and y = row*conf.tileh
in
2399 tilevisible (Lazy.force_val
layout) n x y
2401 then Queue.push lruitem
state.tilelru
2404 wcmd "freetile %s" p
;
2405 state.memused
<- state.memused
- s;
2406 state.uioh#infochanged Memused
;
2407 Hashtbl.remove
state.tilemap k
;
2415 let logcurrently = function
2416 | Idle
-> dolog
"Idle"
2417 | Loading
(l, gen
) ->
2418 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2419 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2421 "Tiling %d[%d,%d] page=%s cs=%s angle"
2422 l.pageno col row pageopaque
2423 (CSTE.to_string colorspace
)
2425 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2426 angle gen
conf.angle
state.gen
2428 conf.tilew
conf.tileh
2435 let r = Str.regexp
" " in
2436 fun s -> Str.bounded_split
r s 2;
2439 let onpagerect pageno f =
2441 match conf.columns
with
2442 | Cmulti
(_, b) -> b
2444 | Csplit
(_, b) -> b
2446 if pageno >= 0 && pageno < Array.length
b
2448 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2452 let gotopagexy1 pageno x y =
2453 let _,w1,h1
,leftx
= getpagedim pageno in
2454 let top = y /. (float h1
) in
2455 let left = x /. (float w1) in
2456 let py, w, h = getpageywh pageno in
2457 let wh = state.winh
- hscrollh () in
2458 let x = left *. (float w) in
2459 let x = leftx
+ state.x + truncate
x in
2461 if x < 0 || x >= wadjsb state.winw
2465 let pdy = truncate
(top *. float h) in
2466 let y'
= py + pdy in
2467 let dy = y'
- state.y in
2469 if x != state.x || not
(dy > 0 && dy < wh)
2471 if conf.presentation
2473 if abs
(py - y'
) > wh
2480 if state.x != sx || state.y != sy
2485 let ww = wadjsb state.winw
in
2487 and qy
= pdy / wh in
2489 and y = py + qy
* wh in
2490 let x = if -x + ww > w1 then -(w1-ww) else x
2491 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2493 if conf.presentation
2495 if abs
(py - y'
) > wh
2505 gotoy_and_clear_text y;
2507 else gotoy_and_clear_text state.y;
2510 let gotopagexy pageno x y =
2511 match state.mode
with
2512 | Birdseye
_ -> gotopage pageno 0.0
2513 | _ -> gotopagexy1 pageno x y
2517 (* dolog "%S" cmds; *)
2518 let cl = splitatspace cmds
in
2520 try Scanf.sscanf
s fmt
f
2522 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2527 state.uioh#infochanged Pdim
;
2530 | "clearrects" :: [] ->
2531 state.rects
<- state.rects1
;
2532 G.postRedisplay "clearrects";
2534 | "continue" :: args :: [] ->
2535 let n = scan args "%u" (fun n -> n) in
2536 state.pagecount
<- n;
2537 begin match state.currently
with
2539 state.currently
<- Idle
;
2540 state.outlines
<- Array.of_list
(List.rev
l)
2544 let cur, cmds
= state.geomcmds
in
2546 then failwith
"umpossible";
2548 begin match List.rev cmds
with
2550 state.geomcmds
<- "", [];
2554 state.geomcmds
<- s, List.rev rest
;
2556 if conf.maxwait
= None
&& not
!wtmode
2557 then G.postRedisplay "continue";
2559 | "title" :: args :: [] ->
2562 | "msg" :: args :: [] ->
2565 | "vmsg" :: args :: [] ->
2567 then showtext ' '
args
2569 | "emsg" :: args :: [] ->
2570 Buffer.add_string
state.errmsgs
args;
2571 state.newerrmsgs
<- true;
2572 G.postRedisplay "error message"
2574 | "progress" :: args :: [] ->
2575 let progress, text =
2578 f, String.sub
args pos
(String.length
args - pos
))
2581 state.progress <- progress;
2582 G.postRedisplay "progress"
2584 | "firstmatch" :: args :: [] ->
2585 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2586 scan args "%u %d %f %f %f %f %f %f %f %f"
2587 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2588 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2590 let y = (getpagey pageno) + truncate
y0 in
2593 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2595 | "match" :: args :: [] ->
2596 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2597 scan args "%u %d %f %f %f %f %f %f %f %f"
2598 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2599 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2602 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2604 | "page" :: args :: [] ->
2605 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2606 begin match state.currently
with
2607 | Loading
(l, gen
) ->
2608 vlog "page %d took %f sec" l.pageno t
;
2609 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2610 begin match state.throttle
with
2612 let preloadedpages =
2614 then preloadlayout state.y
2619 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2620 IntSet.empty
preloadedpages
2623 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2624 if not
(IntSet.mem
pageno set)
2626 wcmd "freepage %s" opaque
;
2632 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2635 state.currently
<- Idle
;
2638 tilepage l.pageno pageopaque state.layout;
2640 load preloadedpages;
2641 if pagevisible state.layout l.pageno
2642 && layoutready state.layout
2643 then G.postRedisplay "page";
2646 | Some
(layout, _, _) ->
2647 state.currently
<- Idle
;
2648 tilepage l.pageno pageopaque layout;
2653 dolog
"Inconsistent loading state";
2654 logcurrently state.currently
;
2658 | "tile" :: args :: [] ->
2659 let (x, y, opaque
, size
, t
) =
2660 scan args "%u %u %s %u %f"
2661 (fun x y p size t
-> (x, y, p
, size
, t
))
2663 begin match state.currently
with
2664 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2665 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2668 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2670 wcmd "freetile %s" opaque
;
2671 state.currently
<- Idle
;
2675 puttileopaque l col row gen cs angle opaque size t
;
2676 state.memused
<- state.memused
+ size
;
2677 state.uioh#infochanged Memused
;
2679 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2680 opaque
, size
) state.tilelru
;
2683 match state.throttle
with
2684 | None
-> state.layout
2685 | Some
(layout, _, _) -> layout
2688 state.currently
<- Idle
;
2690 && conf.colorspace
= cs
2691 && conf.angle
= angle
2692 && tilevisible layout l.pageno x y
2693 then conttiling l.pageno pageopaque;
2695 begin match state.throttle
with
2697 preload state.layout;
2699 && conf.colorspace
= cs
2700 && conf.angle
= angle
2701 && tilevisible state.layout l.pageno x y
2702 && (not
!wtmode || layoutready state.layout)
2703 then G.postRedisplay "tile nothrottle";
2705 | Some
(layout, y, _) ->
2706 let ready = layoutready layout in
2710 state.layout <- layout;
2711 state.throttle
<- None
;
2712 G.postRedisplay "throttle";
2719 dolog
"Inconsistent tiling state";
2720 logcurrently state.currently
;
2724 | "pdim" :: args :: [] ->
2725 let (n, w, h, _) as pdim
=
2726 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2729 match conf.fitmodel
, conf.columns
with
2730 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2733 state.uioh#infochanged Pdim
;
2734 state.pdims
<- pdim :: state.pdims
2736 | "o" :: args :: [] ->
2737 let (l, n, t
, h, pos
) =
2738 scan args "%u %u %d %u %n"
2739 (fun l n t
h pos
-> l, n, t
, h, pos
)
2741 let s = String.sub
args pos
(String.length
args - pos
) in
2742 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2743 begin match state.currently
with
2744 | Outlining outlines
->
2745 state.currently
<- Outlining
(outline :: outlines
)
2747 state.currently
<- Outlining
[outline]
2749 dolog
"invalid outlining state";
2750 logcurrently currently
2753 | "a" :: args :: [] ->
2755 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2757 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2759 | "info" :: args :: [] ->
2760 state.docinfo
<- (1, args) :: state.docinfo
2762 | "infoend" :: [] ->
2763 state.uioh#infochanged Docinfo
;
2764 state.docinfo
<- List.rev
state.docinfo
2767 error
"unknown cmd `%S'" cmds
2772 let action = function
2773 | HCprev
-> cbget cb ~
-1
2774 | HCnext
-> cbget cb
1
2775 | HCfirst
-> cbget cb ~
-(cb
.rc)
2776 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2777 and cancel
() = cb
.rc <- rc
2781 let search pattern forward
=
2782 match conf.columns
with
2784 showtext '
!'
"searching does not work properly in split columns mode"
2786 if nonemptystr pattern
2789 match state.layout with
2792 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2794 wcmd "search %d %d %d %d,%s\000"
2795 (btod conf.icase
) pn py (btod forward
) pattern
;
2798 let intentry text key =
2800 if key >= 32 && key < 127
2806 let text = addchar text c in
2810 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2814 let linknentry text key =
2816 if key >= 32 && key < 127
2822 let text = addchar text c in
2826 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2834 let l = String.length
s in
2835 let rec loop pos
n = if pos
= l then n else
2836 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2837 loop (pos
+1) (n*26 + m)
2840 let rec loop n = function
2843 match getopaque l.pageno with
2844 | None
-> loop n rest
2846 let m = getlinkcount opaque
in
2849 let under = getlink opaque
n in
2852 else loop (n-m) rest
2854 loop n state.layout;
2858 let textentry text key =
2859 if key land 0xff00 = 0xff00
2861 else TEcont
(text ^ toutf8
key)
2864 let reqlayout angle fitmodel
=
2865 match state.throttle
with
2867 if nogeomcmds state.geomcmds
2868 then state.anchor <- getanchor ();
2869 conf.angle
<- angle
mod 360;
2872 match state.mode
with
2873 | LinkNav
_ -> state.mode
<- View
2876 conf.fitmodel
<- fitmodel
;
2877 invalidate "reqlayout"
2879 wcmd "reqlayout %d %d %d"
2880 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2885 let settrim trimmargins trimfuzz
=
2886 if nogeomcmds state.geomcmds
2887 then state.anchor <- getanchor ();
2888 conf.trimmargins
<- trimmargins
;
2889 conf.trimfuzz
<- trimfuzz
;
2890 let x0, y0, x1, y1 = trimfuzz
in
2891 invalidate "settrim"
2893 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2898 match state.throttle
with
2900 let zoom = max
0.0001 zoom in
2901 if zoom <> conf.zoom
2903 state.prevzoom
<- (conf.zoom, state.x);
2905 reshape state.winw
state.winh
;
2906 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2909 | Some
(layout, y, started
) ->
2911 match conf.maxwait
with
2915 let dt = now () -. started
in
2923 let setcolumns mode columns coverA coverB
=
2924 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2928 then showtext '
!'
"split mode doesn't work in bird's eye"
2930 conf.columns
<- Csplit
(-columns
, [||]);
2938 conf.columns
<- Csingle
[||];
2943 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2947 reshape state.winw
state.winh
;
2950 let enterbirdseye () =
2951 let zoom = float conf.thumbw
/. float state.winw
in
2952 let birdseyepageno =
2953 let cy = state.winh
/ 2 in
2957 let rec fold best
= function
2960 let d = cy - (l.pagedispy + l.pagevh/2)
2961 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2962 if abs
d < abs dbest
2969 state.mode
<- Birdseye
(
2970 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2973 conf.presentation
<- false;
2974 conf.interpagespace
<- 10;
2975 conf.hlinks
<- false;
2976 conf.fitmodel
<- FitProportional
;
2978 state.mstate
<- Mnone
;
2979 conf.maxwait
<- None
;
2981 match conf.beyecolumns
with
2984 Cmulti
((c, 0, 0), [||])
2985 | None
-> Csingle
[||]
2987 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2990 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2995 reshape state.winw
state.winh
;
2998 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3000 conf.zoom <- c.zoom;
3001 conf.presentation
<- c.presentation
;
3002 conf.interpagespace
<- c.interpagespace
;
3003 conf.maxwait
<- c.maxwait
;
3004 conf.hlinks
<- c.hlinks
;
3005 conf.fitmodel
<- c.fitmodel
;
3006 conf.beyecolumns
<- (
3007 match conf.columns
with
3008 | Cmulti
((c, _, _), _) -> Some
c
3010 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3013 match c.columns
with
3014 | Cmulti
(c, _) -> Cmulti
(c, [||])
3015 | Csingle
_ -> Csingle
[||]
3016 | Csplit
(c, _) -> Csplit
(c, [||])
3020 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3023 reshape state.winw
state.winh
;
3024 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3028 let togglebirdseye () =
3029 match state.mode
with
3030 | Birdseye vals
-> leavebirdseye vals
true
3031 | View
-> enterbirdseye ()
3035 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3036 let pageno = max
0 (pageno - incr
) in
3037 let rec loop = function
3038 | [] -> gotopage1 pageno 0
3039 | l :: _ when l.pageno = pageno ->
3040 if l.pagedispy >= 0 && l.pagey = 0
3041 then G.postRedisplay "upbirdseye"
3042 else gotopage1 pageno 0
3043 | _ :: rest
-> loop rest
3046 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3049 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3050 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3051 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3052 let rec loop = function
3054 let y, h = getpageyh pageno in
3055 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3057 | l :: _ when l.pageno = pageno ->
3058 if l.pagevh != l.pageh
3059 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3060 else G.postRedisplay "downbirdseye"
3061 | _ :: rest
-> loop rest
3066 let optentry mode
_ key =
3067 let btos b = if b then "on" else "off" in
3068 if key >= 32 && key < 127
3070 let c = Char.chr
key in
3074 try conf.scrollstep
<- int_of_string
s with exc
->
3075 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3077 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3082 conf.autoscrollstep
<- int_of_string
s;
3083 if state.autoscroll
<> None
3084 then state.autoscroll
<- Some
conf.autoscrollstep
3086 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3088 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3093 let n, a, b = multicolumns_of_string s in
3094 setcolumns mode
n a b;
3096 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3098 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3103 let zoom = float (int_of_string
s) /. 100.0 in
3106 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3108 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3113 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3115 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3116 begin match mode
with
3118 leavebirdseye beye
false;
3123 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3125 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3130 Some
(int_of_string
s)
3132 state.text <- Printf.sprintf
"bad integer `%s': %s"
3136 | Some angle
-> reqlayout angle
conf.fitmodel
3139 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3142 conf.icase
<- not
conf.icase
;
3143 TEdone
("case insensitive search " ^
(btos conf.icase
))
3146 conf.preload <- not
conf.preload;
3148 TEdone
("preload " ^
(btos conf.preload))
3151 conf.verbose
<- not
conf.verbose
;
3152 TEdone
("verbose " ^
(btos conf.verbose
))
3155 conf.debug
<- not
conf.debug
;
3156 TEdone
("debug " ^
(btos conf.debug
))
3159 conf.maxhfit
<- not
conf.maxhfit
;
3160 state.maxy
<- calcheight ();
3161 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3164 conf.crophack
<- not
conf.crophack
;
3165 TEdone
("crophack " ^
btos conf.crophack
)
3169 match conf.maxwait
with
3171 conf.maxwait
<- Some infinity
;
3172 "always wait for page to complete"
3174 conf.maxwait
<- None
;
3175 "show placeholder if page is not ready"
3180 conf.underinfo
<- not
conf.underinfo
;
3181 TEdone
("underinfo " ^
btos conf.underinfo
)
3184 conf.savebmarks
<- not
conf.savebmarks
;
3185 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3191 match state.layout with
3196 conf.interpagespace
<- int_of_string
s;
3197 docolumns conf.columns
;
3198 state.maxy
<- calcheight ();
3199 let y = getpagey pageno in
3202 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3204 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3208 match conf.fitmodel
with
3209 | FitProportional
-> FitWidth
3210 | _ -> FitProportional
3212 reqlayout conf.angle
fm;
3213 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3216 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3217 TEdone
("trim margins " ^
btos conf.trimmargins
)
3220 conf.invert
<- not
conf.invert
;
3221 TEdone
("invert colors " ^
btos conf.invert
)
3225 cbput state.hists
.sel
s;
3228 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3229 textentry, ondone, true)
3233 then conf.pax
<- Some
(ref (0.0, 0, 0))
3234 else conf.pax
<- None
;
3235 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3238 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3244 class type lvsource
= object
3245 method getitemcount
: int
3246 method getitem
: int -> (string * int)
3247 method hasaction
: int -> bool
3256 method getactive
: int
3257 method getfirst
: int
3258 method getqsearch
: string
3259 method setqsearch
: string -> unit
3263 class virtual lvsourcebase
= object
3264 val mutable m_active
= 0
3265 val mutable m_first
= 0
3266 val mutable m_qsearch
= ""
3267 val mutable m_pan
= 0
3268 method getactive
= m_active
3269 method getfirst
= m_first
3270 method getqsearch
= m_qsearch
3271 method getpan
= m_pan
3272 method setqsearch
s = m_qsearch
<- s
3275 let withoutlastutf8 s =
3276 let len = String.length
s in
3284 let b = Char.code
s.[pos
] in
3285 if b land 0b11000000 = 0b11000000
3290 if Char.code
s.[len-1] land 0x80 = 0
3294 String.sub
s 0 first;
3297 let textentrykeyboard
3298 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3300 if key >= 0xffb0 && key <= 0xffb9
3301 then key - 0xffb0 + 48 else key
3304 state.mode
<- Textentry
(te
, onleave
);
3307 G.postRedisplay "textentrykeyboard enttext";
3309 let histaction cmd
=
3312 | Some
(action, _) ->
3313 state.mode
<- Textentry
(
3314 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3316 G.postRedisplay "textentry histaction"
3319 | 0xff08 -> (* backspace *)
3320 if emptystr
text && cancelonempty
3323 G.postRedisplay "textentrykeyboard after cancel";
3326 let s = withoutlastutf8 text in
3327 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3329 | 0xff0d | 0xff8d -> (* (kp) enter *)
3332 G.postRedisplay "textentrykeyboard after confirm"
3334 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3335 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3336 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3337 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3339 | 0xff1b -> (* escape*)
3342 begin match opthist
with
3344 | Some
(_, onhistcancel
) -> onhistcancel
()
3348 G.postRedisplay "textentrykeyboard after cancel2"
3351 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3354 | 0xff9f | 0xffff -> () (* delete *)
3357 && key land 0xff00 != 0xff00 (* keyboard *)
3358 && key land 0xfe00 != 0xfe00 (* xkb *)
3359 && key land 0xfd00 != 0xfd00 (* 3270 *)
3361 begin match onkey
text key with
3365 G.postRedisplay "textentrykeyboard after confirm2";
3368 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3372 G.postRedisplay "textentrykeyboard after cancel3"
3375 state.mode
<- Textentry
(te
, onleave
);
3376 G.postRedisplay "textentrykeyboard switch";
3380 vlog "unhandled key %s" (Wsi.keyname
key)
3383 let firstof first active
=
3384 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3385 then max
0 (active
- (fstate.maxrows
/2))
3389 let calcfirst first active
=
3392 let rows = active
- first in
3393 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3397 let scrollph y maxy
=
3398 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3399 let sh = float state.winh
/. sh in
3400 let sh = max
sh (float conf.scrollh
) in
3402 let percent = float y /. float maxy
in
3403 let position = (float state.winh
-. sh) *. percent in
3406 if position +. sh > float state.winh
3407 then float state.winh
-. sh
3413 let coe s = (s :> uioh
);;
3415 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3417 val m_pan
= source#getpan
3418 val m_first
= source#getfirst
3419 val m_active
= source#getactive
3420 val m_qsearch
= source#getqsearch
3421 val m_prev_uioh
= state.uioh
3423 method private elemunder
y =
3424 let n = y / (fstate.fontsize
+1) in
3425 if m_first
+ n < source#getitemcount
3427 if source#hasaction
(m_first
+ n)
3428 then Some
(m_first
+ n)
3435 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3436 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3437 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3438 GlDraw.color
(1., 1., 1.);
3439 Gl.enable `texture_2d
;
3440 let fs = fstate.fontsize
in
3442 let ww = fstate.wwidth
in
3443 let tabw = 30.0*.ww in
3444 let itemcount = source#getitemcount
in
3446 if (row - m_first
) > fstate.maxrows
3449 if row >= 0 && row < itemcount
3451 let (s, level
) = source#getitem
row in
3452 let y = (row - m_first
) * nfs in
3453 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3456 Gl.disable `texture_2d
;
3457 GlDraw.polygon_mode `both `line
;
3458 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3459 GlDraw.color
(1., 1., 1.) ~
alpha;
3460 GlDraw.rect (1., float (y + 1))
3461 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3462 GlDraw.polygon_mode `both `fill
;
3463 GlDraw.color
(1., 1., 1.);
3464 Gl.enable `texture_2d
;
3467 let drawtabularstring s =
3468 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3471 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3474 let len = String.length
s - tabpos - 1 in
3475 let s1 = String.sub
s 0 tabpos
3476 and s2
= String.sub
s (tabpos + 1) len in
3477 let nx = drawstr x s1 in
3479 let x = x +. (max
tabw sw) in
3486 let _ = drawtabularstring s in
3493 Gl.disable `texture_2d
;
3495 method updownlevel incr
=
3496 let len = source#getitemcount
in
3498 if m_active
>= 0 && m_active
< len
3499 then snd
(source#getitem m_active
)
3503 if i
= len then i
-1 else if i
= -1 then 0 else
3504 let _, l = source#getitem i
in
3505 if l != curlevel then i
else flow (i
+incr
)
3507 let active = flow m_active
in
3508 let first = calcfirst m_first
active in
3509 G.postRedisplay "outline updownlevel";
3510 {< m_active
= active; m_first
= first >}
3512 method private key1
key mask
=
3513 let set1 active first qsearch
=
3514 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3516 let search active pattern incr
=
3517 let active = if active = -1 then m_first
else active in
3520 if n >= 0 && n < source#getitemcount
3522 let s, _ = source#getitem
n in
3524 (try ignore
(Str.search_forward
re s 0); true
3525 with Not_found
-> false)
3527 else loop (n + incr
)
3534 let re = Str.regexp_case_fold pattern
in
3540 let itemcount = source#getitemcount
in
3541 let find start incr
=
3543 if i
= -1 || i
= itemcount
3546 if source#hasaction i
3548 else find (i
+ incr
)
3553 let set active first =
3554 let first = bound first 0 (itemcount - fstate.maxrows
) in
3556 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3559 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3561 let incr1 = if incr
> 0 then 1 else -1 in
3562 if isvisible m_first m_active
3565 let next = m_active
+ incr
in
3567 if next < 0 || next >= itemcount
3569 else find next incr1
3571 if abs
(m_active
- next) > fstate.maxrows
3577 let first = m_first
+ incr
in
3578 let first = bound first 0 (itemcount - fstate.maxrows
) in
3580 let next = m_active
+ incr
in
3581 let next = bound next 0 (itemcount - 1) in
3588 if isvisible first next
3595 let first = min
next m_first
in
3597 if abs
(next - first) > fstate.maxrows
3603 let first = m_first
+ incr
in
3604 let first = bound first 0 (itemcount - 1) in
3606 let next = m_active
+ incr
in
3607 let next = bound next 0 (itemcount - 1) in
3608 let next = find next incr1 in
3610 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3612 let active = if m_active
= -1 then next else m_active
in
3617 if isvisible first active
3623 G.postRedisplay "listview navigate";
3627 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3628 let incr = if key = 0x72 then -1 else 1 in
3630 match search (m_active
+ incr) m_qsearch
incr with
3632 state.text <- m_qsearch ^
" [not found]";
3635 state.text <- m_qsearch
;
3636 active, firstof m_first
active
3638 G.postRedisplay "listview ctrl-r/s";
3639 set1 active first m_qsearch
;
3641 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3642 if m_active
>= 0 && m_active
< source#getitemcount
3644 let s, _ = source#getitem m_active
in
3649 | 0xff08 -> (* backspace *)
3650 if emptystr m_qsearch
3653 let qsearch = withoutlastutf8 m_qsearch
in
3657 G.postRedisplay "listview empty qsearch";
3658 set1 m_active m_first
"";
3662 match search m_active
qsearch ~
-1 with
3664 state.text <- qsearch ^
" [not found]";
3667 state.text <- qsearch;
3668 active, firstof m_first
active
3670 G.postRedisplay "listview backspace qsearch";
3671 set1 active first qsearch
3674 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3675 let pattern = m_qsearch ^ toutf8
key in
3677 match search m_active
pattern 1 with
3679 state.text <- pattern ^
" [not found]";
3682 state.text <- pattern;
3683 active, firstof m_first
active
3685 G.postRedisplay "listview qsearch add";
3686 set1 active first pattern;
3688 | 0xff1b -> (* escape *)
3690 if emptystr m_qsearch
3692 G.postRedisplay "list view escape";
3695 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3697 | None
-> m_prev_uioh
3702 G.postRedisplay "list view kill qsearch";
3703 source#setqsearch
"";
3704 coe {< m_qsearch
= "" >}
3707 | 0xff0d | 0xff8d -> (* (kp) enter *)
3709 let self = {< m_qsearch
= "" >} in
3710 source#setqsearch
"";
3712 G.postRedisplay "listview enter";
3713 if m_active
>= 0 && m_active
< source#getitemcount
3715 source#exit
(coe self) false m_active m_first m_pan
"";
3718 source#exit
(coe self) true m_active m_first m_pan
"";
3721 begin match opt with
3722 | None
-> m_prev_uioh
3726 | 0xff9f | 0xffff -> (* (kp) delete *)
3729 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3730 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3731 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3732 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3734 | 0xff53 | 0xff98 -> (* (kp) right *)
3736 G.postRedisplay "listview right";
3737 coe {< m_pan
= m_pan
- 1 >}
3739 | 0xff51 | 0xff96 -> (* (kp) left *)
3741 G.postRedisplay "listview left";
3742 coe {< m_pan
= m_pan
+ 1 >}
3744 | 0xff50 | 0xff95 -> (* (kp) home *)
3745 let active = find 0 1 in
3746 G.postRedisplay "listview home";
3749 | 0xff57 | 0xff9c -> (* (kp) end *)
3750 let first = max
0 (itemcount - fstate.maxrows
) in
3751 let active = find (itemcount - 1) ~
-1 in
3752 G.postRedisplay "listview end";
3755 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3759 dolog
"listview unknown key %#x" key; coe self
3761 method key key mask
=
3762 match state.mode
with
3763 | Textentry te
-> textentrykeyboard key mask te
; coe self
3764 | _ -> self#key1
key mask
3766 method button button down
x y _ =
3769 | 1 when x > state.winw
- conf.scrollbw
->
3770 G.postRedisplay "listview scroll";
3773 let _, position, sh = self#
scrollph in
3774 if y > truncate
position && y < truncate
(position +. sh)
3776 state.mstate
<- Mscrolly
;
3780 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3781 let first = truncate
(s *. float source#getitemcount
) in
3782 let first = min source#getitemcount
first in
3783 Some
(coe {< m_first
= first; m_active
= first >})
3785 state.mstate
<- Mnone
;
3788 | 1 when not down
->
3789 begin match self#elemunder
y with
3791 G.postRedisplay "listview click";
3793 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3797 | n when (n == 4 || n == 5) && not down
->
3798 let len = source#getitemcount
in
3800 if n = 5 && m_first
+ fstate.maxrows
>= len
3804 let first = m_first
+ (if n == 4 then -1 else 1) in
3805 bound first 0 (len - 1)
3807 G.postRedisplay "listview wheel";
3808 Some
(coe {< m_first
= first >})
3809 | n when (n = 6 || n = 7) && not down
->
3810 let inc = if n = 7 then -1 else 1 in
3811 G.postRedisplay "listview hwheel";
3812 Some
(coe {< m_pan
= m_pan
+ inc >})
3817 | None
-> m_prev_uioh
3821 match state.mstate
with
3823 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3824 let first = truncate
(s *. float source#getitemcount
) in
3825 let first = min source#getitemcount
first in
3826 G.postRedisplay "listview motion";
3827 coe {< m_first
= first; m_active
= first >}
3830 method pmotion
x y =
3831 if x < state.winw
- conf.scrollbw
3834 match self#elemunder
y with
3835 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3836 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3840 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3845 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3849 method infochanged
_ = ()
3851 method scrollpw
= (0, 0.0, 0.0)
3853 let nfs = fstate.fontsize
+ 1 in
3854 let y = m_first
* nfs in
3855 let itemcount = source#getitemcount
in
3856 let maxi = max
0 (itemcount - fstate.maxrows
) in
3857 let maxy = maxi * nfs in
3858 let p, h = scrollph y maxy in
3861 method modehash
= modehash
3862 method eformsgs
= false
3865 class outlinelistview ~source
=
3866 let settext autonarrow
s =
3868 then state.text <- "[" ^
s ^
"]"
3869 else state.text <- s
3873 ~source
:(source
:> lvsource
)
3875 ~modehash
:(findkeyhash conf "outline")
3878 val m_autonarrow
= false
3880 method key key mask
=
3882 if emptystr
state.text
3884 else fstate.maxrows - 2
3886 let calcfirst first active =
3889 let rows = active - first in
3890 if rows > maxrows then active - maxrows else first
3894 let active = m_active
+ incr in
3895 let active = bound active 0 (source#getitemcount
- 1) in
3896 let first = calcfirst m_first
active in
3897 G.postRedisplay "outline navigate";
3898 coe {< m_active
= active; m_first
= first >}
3900 let navscroll first =
3902 let dist = m_active
- first in
3908 else first + maxrows
3911 G.postRedisplay "outline navscroll";
3912 coe {< m_first
= first; m_active
= active >}
3914 let ctrl = Wsi.withctrl mask
in
3916 | 97 when ctrl -> (* ctrl-a *)
3918 then source#denarrow
3919 else source#narrow m_qsearch
;
3920 settext (not m_autonarrow
) m_qsearch
;
3921 G.postRedisplay "toggle auto narrowing";
3922 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3924 | 110 when ctrl -> (* ctrl-n *)
3925 source#narrow m_qsearch
;
3927 then source#add_narrow_pattern m_qsearch
;
3928 G.postRedisplay "outline ctrl-n";
3929 coe {< m_first
= 0; m_active
= 0 >}
3931 | 117 when ctrl -> (* ctrl-u *)
3932 source#del_narrow_pattern
;
3933 let pattern = source#renarrow
in
3934 G.postRedisplay "outline ctrl-u";
3936 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3938 settext m_autonarrow
text;
3939 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
3941 | 108 when ctrl -> (* ctrl-l *)
3942 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3943 G.postRedisplay "outline ctrl-l";
3944 coe {< m_first
= first >}
3946 | 0xff1b -> (* escape *)
3947 let o = super#
key key mask
in
3950 if nonemptystr m_qsearch
3952 source#add_narrow_pattern m_qsearch
;
3958 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
3959 if nonemptystr m_qsearch
3960 then source#add_narrow_pattern m_qsearch
;
3963 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
3964 let pattern = m_qsearch ^ toutf8
key in
3965 G.postRedisplay "outlinelistview autonarrow add";
3966 source#narrow
pattern;
3967 settext true pattern;
3968 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3970 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
3971 if emptystr m_qsearch
3974 let pattern = withoutlastutf8 m_qsearch
in
3975 G.postRedisplay "outlinelistview autonarrow backspace";
3976 ignore
(source#renarrow
);
3977 source#narrow
pattern;
3978 settext true pattern;
3979 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
3981 | 0xff9f | 0xffff -> (* (kp) delete *)
3982 source#remove m_active
;
3983 G.postRedisplay "outline delete";
3984 let active = max
0 (m_active
-1) in
3985 coe {< m_first
= firstof m_first
active;
3986 m_active
= active >}
3988 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3989 navscroll (max
0 (m_first
- 1))
3991 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3992 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3994 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3995 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3996 | 0xff55 | 0xff9a -> (* (kp) prior *)
3997 navigate ~
-(fstate.maxrows)
3998 | 0xff56 | 0xff9b -> (* (kp) next *)
3999 navigate fstate.maxrows
4001 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4005 G.postRedisplay "outline ctrl right";
4006 {< m_pan
= m_pan
+ 1 >}
4008 else self#updownlevel
1
4012 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4016 G.postRedisplay "outline ctrl left";
4017 {< m_pan
= m_pan
- 1 >}
4019 else self#updownlevel ~
-1
4023 | 0xff50 | 0xff95 -> (* (kp) home *)
4024 G.postRedisplay "outline home";
4025 coe {< m_first
= 0; m_active
= 0 >}
4027 | 0xff57 | 0xff9c -> (* (kp) end *)
4028 let active = source#getitemcount
- 1 in
4029 let first = max
0 (active - fstate.maxrows) in
4030 G.postRedisplay "outline end";
4031 coe {< m_active
= active; m_first
= first >}
4033 | _ -> super#
key key mask
4036 let outlinesource usebookmarks
=
4039 inherit lvsourcebase
4040 val mutable m_items
= empty
4041 val mutable m_orig_items
= empty
4042 val mutable m_narrow_patterns
= []
4043 val mutable m_hadremovals
= false
4045 method getitemcount
=
4046 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4049 if n == Array.length m_items
&& m_hadremovals
4051 ("[Confirm removal]", 0)
4053 let s, n, _ = m_items
.(n) in
4056 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4057 ignore
(uioh
, first, qsearch);
4058 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4060 if m_narrow_patterns
= []
4066 if not
confrimremoval
4068 let _, _, ((pageno, y, _) as anchor) = m_items
.(active) in
4070 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4076 state.bookmarks
<- Array.to_list m_items
;
4077 m_orig_items
<- m_items
;
4080 else m_items
<- items;
4084 method hasaction
_ = true
4087 if Array.length m_items
!= Array.length m_orig_items
4090 match m_narrow_patterns
with
4092 | many
-> String.concat
" --> " (List.rev many
)
4094 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4097 method narrow
pattern =
4098 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4102 let rec loop accu n =
4104 then m_items
<- Array.of_list
accu
4106 let (s, _, _) as o = m_items
.(n) in
4108 if (try ignore
(Str.search_forward
re s 0); true
4109 with Not_found
-> false)
4115 loop [] (Array.length m_items
- 1)
4120 then Array.of_list
state.bookmarks
4123 m_items
<- m_orig_items
4128 if m >= 0 && m < Array.length m_items
4130 m_hadremovals
<- true;
4131 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4132 let n = if n >= m then n+1 else n in
4137 method add_narrow_pattern
pattern =
4138 m_narrow_patterns
<- pattern :: m_narrow_patterns
4140 method del_narrow_pattern
=
4141 match m_narrow_patterns
with
4142 | _ :: rest
-> m_narrow_patterns
<- rest
4147 match m_narrow_patterns
with
4148 | pattern :: [] -> self#narrow
pattern; pattern
4150 List.fold_left
(fun accu pattern ->
4151 self#narrow
pattern;
4152 accu ^
" --> " ^
pattern) "" list
4154 method reset
anchor items =
4155 m_hadremovals
<- false;
4156 if m_orig_items
== empty
4158 m_orig_items
<- items;
4159 if m_narrow_patterns
== []
4160 then m_items
<- items;
4162 let rely = getanchory anchor in
4164 let rec loop n best bestd
=
4165 if n = Array.length m_items
4168 let (_, _, anchor) = m_items
.(n) in
4169 let orely = getanchory anchor in
4170 let d = abs
(orely - rely) in
4173 else loop (n+1) best bestd
4178 m_first
<- firstof m_first
active
4182 let enterselector usebookmarks
=
4183 let source = outlinesource usebookmarks
in
4187 then Array.of_list
state.bookmarks
4190 if Array.length
outlines = 0
4192 showtext ' ' errmsg
;
4195 state.text <- source#greetmsg
;
4196 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4197 let anchor = getanchor () in
4198 source#reset
anchor outlines;
4199 state.uioh
<- coe (new outlinelistview ~
source);
4200 G.postRedisplay "enter selector";
4204 let enteroutlinemode =
4205 let f = enterselector false in
4206 fun ()-> f "Document has no outline";
4209 let enterbookmarkmode =
4210 let f = enterselector true in
4211 fun () -> f "Document has no bookmarks (yet)";
4214 let color_of_string s =
4215 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4216 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4220 let color_to_string (r, g, b) =
4221 let r = truncate
(r *. 256.0)
4222 and g = truncate
(g *. 256.0)
4223 and b = truncate
(b *. 256.0) in
4224 Printf.sprintf
"%d/%d/%d" r g b
4227 let irect_of_string s =
4228 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4231 let irect_to_string (x0,y0,x1,y1) =
4232 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4235 let makecheckers () =
4236 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4238 converted by Issac Trotts. July 25, 2002 *)
4239 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4240 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4241 let id = GlTex.gen_texture
() in
4242 GlTex.bind_texture `texture_2d
id;
4243 GlPix.store
(`unpack_alignment
1);
4244 GlTex.image2d
image;
4245 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4246 [ `mag_filter `nearest
; `min_filter `nearest
];
4250 let setcheckers enabled
=
4251 match state.texid
with
4253 if enabled
then state.texid
<- Some
(makecheckers ())
4258 GlTex.delete_texture texid
;
4259 state.texid
<- None
;
4263 let int_of_string_with_suffix s =
4264 let l = String.length
s in
4268 let suffix = Char.lowercase
s.[l-1] in
4270 | 'k'
-> String.sub
s 0 (l-1), 10
4271 | '
m'
-> String.sub
s 0 (l-1), 20
4272 | '
g'
-> String.sub
s 0 (l-1), 30
4276 let n = int_of_string
s1 in
4277 let m = n lsl shift
in
4279 then raise
(Failure
"value too large")
4283 let string_with_suffix_of_int n =
4287 let units = [(30, "G"); (20, "M"); (10, "K")] in
4290 let h = n mod 1000 in
4293 then string_of_int
h ^
s
4295 let s = Printf.sprintf
"_%03d%s" h s in
4301 let rec find = function
4303 | (shift
, suffix) :: rest
->
4304 if (n land ((1 lsl shift
) - 1)) = 0
4305 then prettyint (n lsr shift
) ^
suffix
4311 let defghyllscroll = (40, 8, 32);;
4312 let ghyllscroll_of_string s =
4313 let (n, a, b) as nab
=
4316 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4318 if n <= a || n <= b || a >= b
4319 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4324 let ghyllscroll_to_string ((n, a, b) as nab
) =
4325 if nab
= defghyllscroll
4327 else Printf.sprintf
"%d,%d,%d" n a b;
4330 let describe_location () =
4331 let fn = page_of_y state.y in
4332 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4333 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4337 else (100. *. (float state.y /. float maxy))
4341 Printf.sprintf
"page %d of %d [%.2f%%]"
4342 (fn+1) state.pagecount
percent
4345 "pages %d-%d of %d [%.2f%%]"
4346 (fn+1) (ln+1) state.pagecount
percent
4349 let setpresentationmode v
=
4350 let n = page_of_y state.y in
4351 state.anchor <- (n, 0.0, 1.0);
4352 conf.presentation
<- v
;
4353 if conf.fitmodel
= FitPage
4354 then reqlayout conf.angle
conf.fitmodel
;
4359 let btos b = if b then "\xe2\x88\x9a" else "" in
4360 let showextended = ref false in
4361 let leave mode
= function
4362 | Confirm
-> state.mode
<- mode
4363 | Cancel
-> state.mode
<- mode
in
4366 val mutable m_first_time
= true
4367 val mutable m_l
= []
4368 val mutable m_a
= [||]
4369 val mutable m_prev_uioh
= nouioh
4370 val mutable m_prev_mode
= View
4372 inherit lvsourcebase
4374 method reset prev_mode prev_uioh
=
4375 m_a
<- Array.of_list
(List.rev m_l
);
4377 m_prev_mode
<- prev_mode
;
4378 m_prev_uioh
<- prev_uioh
;
4382 if n >= Array.length m_a
4386 | _, _, _, Action
_ -> m_active
<- n
4390 m_first_time
<- false;
4393 method int name get
set =
4395 (name, `
int get
, 1, Action
(
4398 try set (int_of_string
s)
4400 state.text <- Printf.sprintf
"bad integer `%s': %s"
4404 let te = name ^
": ", "", None
, intentry, ondone, true in
4405 state.mode
<- Textentry
(te, leave m_prev_mode
);
4409 method int_with_suffix
name get
set =
4411 (name, `intws get
, 1, Action
(
4414 try set (int_of_string_with_suffix s)
4416 state.text <- Printf.sprintf
"bad integer `%s': %s"
4421 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4423 state.mode
<- Textentry
(te, leave m_prev_mode
);
4427 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4429 (name, `
bool (btos, get
), offset
, Action
(
4436 method color
name get
set =
4438 (name, `color get
, 1, Action
(
4440 let invalid = (nan
, nan
, nan
) in
4443 try color_of_string s
4445 state.text <- Printf.sprintf
"bad color `%s': %s"
4452 let te = name ^
": ", "", None
, textentry, ondone, true in
4453 state.text <- color_to_string (get
());
4454 state.mode
<- Textentry
(te, leave m_prev_mode
);
4458 method string name get
set =
4460 (name, `
string get
, 1, Action
(
4462 let ondone s = set s in
4463 let te = name ^
": ", "", None
, textentry, ondone, true in
4464 state.mode
<- Textentry
(te, leave m_prev_mode
);
4468 method colorspace
name get
set =
4470 (name, `
string get
, 1, Action
(
4474 inherit lvsourcebase
4477 m_active
<- CSTE.to_int conf.colorspace
;
4480 method getitemcount
=
4481 Array.length
CSTE.names
4484 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4485 ignore
(uioh
, first, pan
, qsearch);
4486 if not cancel
then set active;
4488 method hasaction
_ = true
4492 let modehash = findkeyhash conf "info" in
4493 coe (new listview ~
source ~trusted
:true ~
modehash)
4496 method paxmark
name get
set =
4498 (name, `
string get
, 1, Action
(
4502 inherit lvsourcebase
4505 m_active
<- MTE.to_int conf.paxmark
;
4508 method getitemcount
= Array.length
MTE.names
4509 method getitem
n = (MTE.names.(n), 0)
4510 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4511 ignore
(uioh
, first, pan
, qsearch);
4512 if not cancel
then set active;
4514 method hasaction
_ = true
4518 let modehash = findkeyhash conf "info" in
4519 coe (new listview ~
source ~trusted
:true ~
modehash)
4522 method fitmodel
name get
set =
4524 (name, `
string get
, 1, Action
(
4528 inherit lvsourcebase
4531 m_active
<- FMTE.to_int conf.fitmodel
;
4534 method getitemcount
= Array.length
FMTE.names
4535 method getitem
n = (FMTE.names.(n), 0)
4536 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4537 ignore
(uioh
, first, pan
, qsearch);
4538 if not cancel
then set active;
4540 method hasaction
_ = true
4544 let modehash = findkeyhash conf "info" in
4545 coe (new listview ~
source ~trusted
:true ~
modehash)
4548 method caption
s offset
=
4549 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4551 method caption2
s f offset
=
4552 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4554 method getitemcount
= Array.length m_a
4557 let tostr = function
4558 | `
int f -> string_of_int
(f ())
4559 | `intws
f -> string_with_suffix_of_int (f ())
4561 | `color
f -> color_to_string (f ())
4562 | `
bool (btos, f) -> btos (f ())
4565 let name, t
, offset
, _ = m_a
.(n) in
4566 ((let s = tostr t
in
4568 then Printf.sprintf
"%s\t%s" name s
4572 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4576 m_qsearch
<- qsearch;
4578 match m_a
.(active) with
4579 | _, _, _, Action
f -> f uioh
4591 method hasaction
n =
4593 | _, _, _, Action
_ -> true
4597 let rec fillsrc prevmode prevuioh
=
4598 let sep () = src#caption
"" 0 in
4599 let colorp name get
set =
4601 (fun () -> color_to_string (get
()))
4604 let c = color_of_string v in
4607 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4610 let oldmode = state.mode
in
4611 let birdseye = isbirdseye state.mode
in
4613 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4615 src#
bool "presentation mode"
4616 (fun () -> conf.presentation
)
4617 (fun v -> setpresentationmode v);
4619 src#
bool "ignore case in searches"
4620 (fun () -> conf.icase
)
4621 (fun v -> conf.icase
<- v);
4624 (fun () -> conf.preload)
4625 (fun v -> conf.preload <- v);
4627 src#
bool "highlight links"
4628 (fun () -> conf.hlinks
)
4629 (fun v -> conf.hlinks
<- v);
4631 src#
bool "under info"
4632 (fun () -> conf.underinfo
)
4633 (fun v -> conf.underinfo
<- v);
4635 src#
bool "persistent bookmarks"
4636 (fun () -> conf.savebmarks
)
4637 (fun v -> conf.savebmarks
<- v);
4639 src#fitmodel
"fit model"
4640 (fun () -> FMTE.to_string conf.fitmodel
)
4641 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4643 src#
bool "trim margins"
4644 (fun () -> conf.trimmargins
)
4645 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4647 src#
bool "persistent location"
4648 (fun () -> conf.jumpback
)
4649 (fun v -> conf.jumpback
<- v);
4652 src#
int "inter-page space"
4653 (fun () -> conf.interpagespace
)
4655 conf.interpagespace
<- n;
4656 docolumns conf.columns
;
4658 match state.layout with
4663 state.maxy <- calcheight ();
4664 let y = getpagey pageno in
4669 (fun () -> conf.pagebias
)
4670 (fun v -> conf.pagebias
<- v);
4672 src#
int "scroll step"
4673 (fun () -> conf.scrollstep
)
4674 (fun n -> conf.scrollstep
<- n);
4676 src#
int "horizontal scroll step"
4677 (fun () -> conf.hscrollstep
)
4678 (fun v -> conf.hscrollstep
<- v);
4680 src#
int "auto scroll step"
4682 match state.autoscroll
with
4684 | _ -> conf.autoscrollstep
)
4686 if state.autoscroll
<> None
4687 then state.autoscroll
<- Some
n;
4688 conf.autoscrollstep
<- n);
4691 (fun () -> truncate
(conf.zoom *. 100.))
4692 (fun v -> setzoom ((float v) /. 100.));
4695 (fun () -> conf.angle
)
4696 (fun v -> reqlayout v conf.fitmodel
);
4698 src#
int "scroll bar width"
4699 (fun () -> conf.scrollbw
)
4702 reshape state.winw
state.winh
;
4705 src#
int "scroll handle height"
4706 (fun () -> conf.scrollh
)
4707 (fun v -> conf.scrollh
<- v;);
4709 src#
int "thumbnail width"
4710 (fun () -> conf.thumbw
)
4712 conf.thumbw
<- min
4096 v;
4715 leavebirdseye beye
false;
4720 let mode = state.mode in
4721 src#
string "columns"
4723 match conf.columns
with
4725 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4726 | Csplit
(count
, _) -> "-" ^ string_of_int count
4729 let n, a, b = multicolumns_of_string v in
4730 setcolumns mode n a b);
4733 src#caption
"Pixmap cache" 0;
4734 src#int_with_suffix
"size (advisory)"
4735 (fun () -> conf.memlimit
)
4736 (fun v -> conf.memlimit
<- v);
4739 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4740 (string_with_suffix_of_int state.memused
)
4741 (Hashtbl.length
state.tilemap
)) 1;
4744 src#caption
"Layout" 0;
4745 src#caption2
"Dimension"
4747 Printf.sprintf
"%dx%d (virtual %dx%d)"
4748 state.winw
state.winh
4753 src#caption2
"Position" (fun () ->
4754 Printf.sprintf
"%dx%d" state.x state.y
4757 src#caption2
"Position" (fun () -> describe_location ()) 1
4761 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4762 "Save these parameters as global defaults at exit"
4763 (fun () -> conf.bedefault
)
4764 (fun v -> conf.bedefault
<- v)
4768 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4769 src#
bool ~offset
:0 ~
btos "Extended parameters"
4770 (fun () -> !showextended)
4771 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4775 (fun () -> conf.checkers
)
4776 (fun v -> conf.checkers
<- v; setcheckers v);
4777 src#
bool "update cursor"
4778 (fun () -> conf.updatecurs
)
4779 (fun v -> conf.updatecurs
<- v);
4781 (fun () -> conf.verbose
)
4782 (fun v -> conf.verbose
<- v);
4783 src#
bool "invert colors"
4784 (fun () -> conf.invert
)
4785 (fun v -> conf.invert
<- v);
4787 (fun () -> conf.maxhfit
)
4788 (fun v -> conf.maxhfit
<- v);
4789 src#
bool "redirect stderr"
4790 (fun () -> conf.redirectstderr)
4791 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4793 (fun () -> conf.pax
!= None
)
4796 then conf.pax
<- Some
(ref (now (), 0, 0))
4797 else conf.pax
<- None
);
4798 src#
string "uri launcher"
4799 (fun () -> conf.urilauncher
)
4800 (fun v -> conf.urilauncher
<- v);
4801 src#
string "path launcher"
4802 (fun () -> conf.pathlauncher
)
4803 (fun v -> conf.pathlauncher
<- v);
4804 src#
string "tile size"
4805 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4808 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4809 conf.tilew
<- max
64 w;
4810 conf.tileh
<- max
64 h;
4813 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4816 src#
int "texture count"
4817 (fun () -> conf.texcount
)
4820 then conf.texcount
<- v
4821 else showtext '
!'
" Failed to set texture count please retry later"
4823 src#
int "slice height"
4824 (fun () -> conf.sliceheight
)
4826 conf.sliceheight
<- v;
4827 wcmd "sliceh %d" conf.sliceheight
;
4829 src#
int "anti-aliasing level"
4830 (fun () -> conf.aalevel
)
4832 conf.aalevel
<- bound v 0 8;
4833 state.anchor <- getanchor ();
4834 opendoc state.path
state.password
;
4836 src#
string "page scroll scaling factor"
4837 (fun () -> string_of_float
conf.pgscale)
4840 let s = float_of_string
v in
4843 state.text <- Printf.sprintf
4844 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4847 src#
int "ui font size"
4848 (fun () -> fstate.fontsize
)
4849 (fun v -> setfontsize (bound v 5 100));
4850 src#
int "hint font size"
4851 (fun () -> conf.hfsize
)
4852 (fun v -> conf.hfsize
<- bound v 5 100);
4853 colorp "background color"
4854 (fun () -> conf.bgcolor
)
4855 (fun v -> conf.bgcolor
<- v);
4856 src#
bool "crop hack"
4857 (fun () -> conf.crophack
)
4858 (fun v -> conf.crophack
<- v);
4859 src#
string "trim fuzz"
4860 (fun () -> irect_to_string conf.trimfuzz
)
4863 conf.trimfuzz
<- irect_of_string v;
4865 then settrim true conf.trimfuzz
;
4867 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4869 src#
string "throttle"
4871 match conf.maxwait
with
4872 | None
-> "show place holder if page is not ready"
4875 then "wait for page to fully render"
4877 "wait " ^ string_of_float
time
4878 ^
" seconds before showing placeholder"
4882 let f = float_of_string
v in
4884 then conf.maxwait
<- None
4885 else conf.maxwait
<- Some
f
4887 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4889 src#
string "ghyll scroll"
4891 match conf.ghyllscroll
with
4893 | Some nab
-> ghyllscroll_to_string nab
4900 else Some
(ghyllscroll_of_string v)
4902 conf.ghyllscroll
<- gs
4904 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4906 src#
string "selection command"
4907 (fun () -> conf.selcmd
)
4908 (fun v -> conf.selcmd
<- v);
4909 src#
string "synctex command"
4910 (fun () -> conf.stcmd
)
4911 (fun v -> conf.stcmd
<- v);
4912 src#
string "pax command"
4913 (fun () -> conf.paxcmd
)
4914 (fun v -> conf.paxcmd
<- v);
4915 src#colorspace
"color space"
4916 (fun () -> CSTE.to_string conf.colorspace
)
4918 conf.colorspace
<- CSTE.of_int v;
4922 src#paxmark
"pax mark method"
4923 (fun () -> MTE.to_string conf.paxmark
)
4924 (fun v -> conf.paxmark
<- MTE.of_int v);
4928 (fun () -> conf.usepbo
)
4929 (fun v -> conf.usepbo
<- v);
4930 src#
bool "mouse wheel scrolls pages"
4931 (fun () -> conf.wheelbypage
)
4932 (fun v -> conf.wheelbypage
<- v);
4933 src#
bool "open remote links in a new instance"
4934 (fun () -> conf.riani
)
4935 (fun v -> conf.riani
<- v);
4939 src#caption
"Document" 0;
4940 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4941 src#caption2
"Pages"
4942 (fun () -> string_of_int
state.pagecount
) 1;
4943 src#caption2
"Dimensions"
4944 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4948 src#caption
"Trimmed margins" 0;
4949 src#caption2
"Dimensions"
4950 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4954 src#caption
"OpenGL" 0;
4955 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4956 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4959 src#caption
"Location" 0;
4960 if nonemptystr
state.origin
4961 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4962 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4964 src#reset prevmode prevuioh
;
4968 let prevmode = state.mode
4969 and prevuioh
= state.uioh in
4970 fillsrc prevmode prevuioh
;
4971 let source = (src :> lvsource
) in
4972 let modehash = findkeyhash conf "info" in
4973 state.uioh <- coe (object (self)
4974 inherit listview ~
source ~trusted
:true ~
modehash as super
4975 val mutable m_prevmemused
= 0
4976 method infochanged
= function
4978 if m_prevmemused
!= state.memused
4980 m_prevmemused
<- state.memused
;
4981 G.postRedisplay "memusedchanged";
4983 | Pdim
-> G.postRedisplay "pdimchanged"
4984 | Docinfo
-> fillsrc prevmode prevuioh
4986 method key key mask
=
4987 if not
(Wsi.withctrl mask
)
4990 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4991 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4992 | _ -> super#
key key mask
4993 else super#
key key mask
4995 G.postRedisplay "info";
5001 inherit lvsourcebase
5002 method getitemcount
= Array.length
state.help
5004 let s, l, _ = state.help
.(n) in
5007 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5011 m_qsearch
<- qsearch;
5012 match state.help
.(active) with
5013 | _, _, Action
f -> Some
(f uioh)
5023 method hasaction
n =
5024 match state.help
.(n) with
5025 | _, _, Action
_ -> true
5032 let modehash = findkeyhash conf "help" in
5033 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5034 G.postRedisplay "help";
5039 let re = Str.regexp
"[\r\n]" in
5041 inherit lvsourcebase
5042 val mutable m_items
= [||]
5044 method getitemcount
= 1 + Array.length m_items
5049 else m_items
.(n-1), 0
5051 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5056 then Buffer.clear
state.errmsgs
;
5057 m_qsearch
<- qsearch;
5064 method hasaction
n =
5068 state.newerrmsgs
<- false;
5069 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5070 m_items
<- Array.of_list
l
5078 let source = (msgsource :> lvsource
) in
5079 let modehash = findkeyhash conf "listview" in
5080 state.uioh <- coe (object
5081 inherit listview ~
source ~trusted
:false ~
modehash as super
5084 then msgsource#reset
;
5087 G.postRedisplay "msgs";
5090 let quickbookmark ?title
() =
5091 match state.layout with
5097 let sec = Unix.gettimeofday
() in
5098 let tm = Unix.localtime
sec in
5099 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5103 (tm.Unix.tm_year
+ 1900)
5106 | Some
title -> title
5108 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5111 let setautoscrollspeed step goingdown
=
5112 let incr = max
1 ((abs step
) / 2) in
5113 let incr = if goingdown
then incr else -incr in
5114 let astep = step
+ incr in
5115 state.autoscroll
<- Some
astep;
5118 let gotounder under =
5119 let getpath filename
=
5121 if nonemptystr filename
5123 if Filename.is_relative filename
5125 let dir = Filename.dirname
state.path in
5127 if Filename.is_implicit
dir
5128 then Filename.concat
(Sys.getcwd
()) dir
5131 Filename.concat
dir filename
5135 if Sys.file_exists
path
5140 | Ulinkgoto
(pageno, top) ->
5144 gotopage1 pageno top;
5150 | Uremote
(filename
, pageno) ->
5151 let path = getpath filename
in
5156 let command = !selfexec ^
" " ^
path in
5157 try popen command []
5160 "failed to execute `%s': %s\n" command (exntos exn
);
5163 let anchor = getanchor () in
5164 let ranchor = state.path, state.password
, anchor, state.origin
in
5166 state.anchor <- (pageno, 0.0, 0.0);
5167 state.ranchors
<- ranchor :: state.ranchors
;
5170 else showtext '
!'
("Could not find " ^ filename
)
5172 | Uremotedest
(filename
, destname
) ->
5173 let path = getpath filename
in
5178 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
5179 try popen command []
5182 "failed to execute `%s': %s\n" command (exntos exn
);
5185 let anchor = getanchor () in
5186 let ranchor = state.path, state.password
, anchor, state.origin
in
5188 state.nameddest
<- destname
;
5189 state.ranchors
<- ranchor :: state.ranchors
;
5192 else showtext '
!'
("Could not find " ^ filename
)
5194 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5198 match conf.columns
with
5200 | _ -> state.x != 0 || conf.zoom > 1.0
5203 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5205 let existsinrow pageno (columns
, coverA
, coverB
) p =
5206 let last = ((pageno - coverA
) mod columns
) + columns
in
5207 let rec any = function
5210 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5214 then (if l.pageno = last then false else any rest
)
5222 match state.layout with
5224 let pageno = page_of_y state.y in
5225 gotoghyll (getpagey (pageno+1))
5227 match conf.columns
with
5229 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5231 let y = clamp (pgscale state.winh
) in
5234 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5235 gotoghyll (getpagey pageno)
5236 | Cmulti
((c, _, _) as cl, _) ->
5237 if conf.presentation
5238 && (existsinrow l.pageno cl
5239 (fun l -> l.pageh
> l.pagey + l.pagevh))
5241 let y = clamp (pgscale state.winh
) in
5244 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5245 gotoghyll (getpagey pageno)
5247 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5249 let pagey, pageh
= getpageyh l.pageno in
5250 let pagey = pagey + pageh
* l.pagecol
in
5251 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5252 gotoghyll (pagey + pageh
+ ips)
5256 match state.layout with
5258 let pageno = page_of_y state.y in
5259 gotoghyll (getpagey (pageno-1))
5261 match conf.columns
with
5263 if conf.presentation
&& l.pagey != 0
5265 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5267 let pageno = max
0 (l.pageno-1) in
5268 gotoghyll (getpagey pageno)
5269 | Cmulti
((c, _, coverB
) as cl, _) ->
5270 if conf.presentation
&&
5271 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5273 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5276 if l.pageno = state.pagecount
- coverB
5280 let pageno = max
0 (l.pageno-decr) in
5281 gotoghyll (getpagey pageno)
5289 let pageno = max
0 (l.pageno-1) in
5290 let pagey, pageh
= getpageyh pageno in
5293 let pagey, pageh
= getpageyh l.pageno in
5294 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5299 let viewkeyboard key mask
=
5301 let mode = state.mode in
5302 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5305 G.postRedisplay "view:enttext"
5307 let ctrl = Wsi.withctrl mask
in
5309 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5315 | 0xff63 -> (* insert *)
5316 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5318 state.mode <- LinkNav
(Ltgendir
0);
5321 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5323 | 0xff1b | 113 -> (* escape / q *)
5324 begin match state.mstate
with
5326 state.mstate
<- Mnone
;
5327 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5328 G.postRedisplay "kill zoom rect";
5330 begin match state.mode with
5333 G.postRedisplay "esc leave linknav"
5335 match state.ranchors
with
5337 | (path, password
, anchor, origin
) :: rest
->
5338 state.ranchors
<- rest
;
5339 state.anchor <- anchor;
5340 state.origin
<- origin
;
5341 state.nameddest
<- "";
5342 opendoc path password
5346 | 0xff08 -> (* backspace *)
5347 gotoghyll (getnav ~
-1)
5355 G.postRedisplay "dehighlight";
5357 | 47 | 63 -> (* / ? *)
5358 let ondone isforw
s =
5359 cbput state.hists
.pat
s;
5360 state.searchpattern
<- s;
5363 let s = String.create
1 in
5364 s.[0] <- Char.chr
key;
5365 enttext (s, "", Some
(onhist state.hists
.pat
),
5366 textentry, ondone (key = 47), true)
5368 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5369 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5370 setzoom (conf.zoom +. incr)
5372 | 43 | 0xffab -> (* + *)
5375 try int_of_string
s with exc
->
5376 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5382 state.text <- "page bias is now " ^ string_of_int
n;
5385 enttext ("page bias: ", "", None
, intentry, ondone, true)
5387 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5388 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5389 setzoom (max
0.01 (conf.zoom -. decr))
5391 | 45 | 0xffad -> (* - *)
5392 let ondone msg
= state.text <- msg
in
5394 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5395 optentry state.mode, ondone, true
5398 | 48 when ctrl -> (* ctrl-0 *)
5406 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5408 match conf.columns
with
5409 | Csingle
_ | Cmulti
_ -> 1
5410 | Csplit
(n, _) -> n
5412 let h = state.winh
-
5413 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5415 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5416 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5419 | 51 when ctrl -> (* ctrl-3 *)
5421 match conf.fitmodel
with
5422 | FitWidth
-> FitProportional
5423 | FitProportional
-> FitPage
5424 | FitPage
-> FitWidth
5426 state.text <- "fit model: " ^
FMTE.to_string fm;
5427 reqlayout conf.angle
fm
5429 | 0xffc6 -> (* f9 *)
5432 | 57 when ctrl -> (* ctrl-9 *)
5435 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5436 when not
ctrl -> (* 0..9 *)
5439 try int_of_string
s with exc
->
5440 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5446 cbput state.hists
.pag
(string_of_int
n);
5447 gotopage1 (n + conf.pagebias
- 1) 0;
5450 let pageentry text key =
5451 match Char.unsafe_chr
key with
5452 | '
g'
-> TEdone
text
5453 | _ -> intentry text key
5455 let text = "x" in text.[0] <- Char.chr
key;
5456 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5459 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5460 reshape state.winw
state.winh
;
5463 state.bzoom
<- not
state.bzoom
;
5465 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5468 conf.hlinks
<- not
conf.hlinks
;
5469 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5470 G.postRedisplay "toggle highlightlinks";
5473 state.glinks
<- true;
5474 let mode = state.mode in
5475 state.mode <- Textentry
(
5476 (":", "", None
, linknentry, linkndone gotounder, false),
5478 state.glinks
<- false;
5482 G.postRedisplay "view:linkent(F)"
5485 state.glinks
<- true;
5486 let mode = state.mode in
5487 state.mode <- Textentry
(
5489 ":", "", None
, linknentry, linkndone (fun under ->
5490 selstring (undertext under);
5494 state.glinks
<- false;
5498 G.postRedisplay "view:linkent"
5501 begin match state.autoscroll
with
5503 conf.autoscrollstep
<- step
;
5504 state.autoscroll
<- None
5506 if conf.autoscrollstep
= 0
5507 then state.autoscroll
<- Some
1
5508 else state.autoscroll
<- Some
conf.autoscrollstep
5511 | 112 when ctrl -> (* ctrl-p *)
5515 setpresentationmode (not
conf.presentation
);
5516 showtext ' '
("presentation mode " ^
5517 if conf.presentation
then "on" else "off");
5520 if List.mem
Wsi.Fullscreen
state.winstate
5521 then Wsi.reshape conf.cwinw
conf.cwinh
5522 else Wsi.fullscreen
()
5524 | 112 | 78 -> (* p|N *)
5525 search state.searchpattern
false
5527 | 110 | 0xffc0 -> (* n|F3 *)
5528 search state.searchpattern
true
5531 begin match state.layout with
5534 gotoghyll (getpagey l.pageno)
5540 | 0xff9f | 0xffff -> (* delete *)
5544 showtext ' '
(describe_location ());
5547 begin match state.layout with
5550 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5555 enterbookmarkmode ()
5557 | 104 | 0xffbe -> (* h|F1 *)
5563 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5568 match state.layout with
5572 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5575 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5579 showtext ' '
"Quick bookmark added";
5582 begin match state.layout with
5584 let rect = getpdimrect
l.pagedimno
in
5588 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5589 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5591 (truncate
(rect.(1) -. rect.(0)),
5592 truncate
(rect.(3) -. rect.(0)))
5594 let w = truncate
((float w)*.conf.zoom)
5595 and h = truncate
((float h)*.conf.zoom) in
5598 state.anchor <- getanchor ();
5599 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5601 G.postRedisplay "z";
5606 | 120 -> state.roam
() (* x *)
5607 | 60 | 62 -> (* < > *)
5608 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5610 | 91 | 93 -> (* [ ] *)
5612 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5614 G.postRedisplay "brightness";
5616 | 99 when state.mode = View
-> (* [alt-]c *)
5621 let m = (wadjsb state.winw
- state.w) / 2 in
5623 gotoy_and_clear_text state.y
5627 match state.prevcolumns
with
5628 | None
-> (1, 0, 0), 1.0
5629 | Some
(columns
, z
) ->
5632 | Csplit
(c, _) -> -c, 0, 0
5633 | Cmulti
((c, a, b), _) -> c, a, b
5634 | Csingle
_ -> 1, 0, 0
5638 setcolumns View
c a b;
5641 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5642 -> (* ctrl-shift- (kp) [up|down] *)
5643 let zoom, x = state.prevzoom
in
5647 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5648 begin match state.autoscroll
with
5650 begin match state.mode with
5651 | Birdseye beye
-> upbirdseye 1 beye
5654 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5656 if not
(Wsi.withshift mask
) && conf.presentation
5658 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5662 setautoscrollspeed n false
5665 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5666 begin match state.autoscroll
with
5668 begin match state.mode with
5669 | Birdseye beye
-> downbirdseye 1 beye
5672 then gotoy_and_clear_text (clamp (state.winh
/2))
5674 if not
(Wsi.withshift mask
) && conf.presentation
5676 else gotoy_and_clear_text (clamp conf.scrollstep
)
5680 setautoscrollspeed n true
5683 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5684 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5690 else conf.hscrollstep
5692 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5693 state.x <- panbound (state.x + dx);
5694 gotoy_and_clear_text state.y
5697 G.postRedisplay "left/right"
5700 | 0xff55 | 0xff9a -> (* (kp) prior *)
5704 match state.layout with
5706 | l :: _ -> state.y - l.pagey
5708 clamp (pgscale (-state.winh
))
5712 | 0xff56 | 0xff9b -> (* (kp) next *)
5716 match List.rev
state.layout with
5718 | l :: _ -> getpagey l.pageno
5720 clamp (pgscale state.winh
)
5724 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5726 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5727 gotoghyll (clamp state.maxy)
5730 when Wsi.withalt mask
-> (* alt-(kp) right *)
5731 gotoghyll (getnav 1)
5733 when Wsi.withalt mask
-> (* alt-(kp) left *)
5734 gotoghyll (getnav ~
-1)
5739 | 118 when conf.debug
-> (* v *)
5742 match getopaque l.pageno with
5745 let x0, y0, x1, y1 = pagebbox opaque
in
5746 let a,b = float x0, float y0 in
5747 let c,d = float x1, float y0 in
5748 let e,f = float x1, float y1 in
5749 let h,j
= float x0, float y1 in
5750 let rect = (a,b,c,d,e,f,h,j
) in
5752 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5754 G.postRedisplay "v";
5757 vlog "huh? %s" (Wsi.keyname
key)
5760 let linknavkeyboard key mask
linknav =
5761 let getpage pageno =
5762 let rec loop = function
5764 | l :: _ when l.pageno = pageno -> Some
l
5765 | _ :: rest
-> loop rest
5766 in loop state.layout
5768 let doexact (pageno, n) =
5769 match getopaque pageno, getpage pageno with
5770 | Some opaque
, Some
l ->
5771 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5773 let under = getlink opaque
n in
5774 G.postRedisplay "link gotounder";
5780 | 0xff50 -> (* home *)
5781 Some
(findlink opaque LDfirst
), -1
5783 | 0xff57 -> (* end *)
5784 Some
(findlink opaque LDlast
), 1
5786 | 0xff51 -> (* left *)
5787 Some
(findlink opaque
(LDleft
n)), -1
5789 | 0xff53 -> (* right *)
5790 Some
(findlink opaque
(LDright
n)), 1
5792 | 0xff52 -> (* up *)
5793 Some
(findlink opaque
(LDup
n)), -1
5795 | 0xff54 -> (* down *)
5796 Some
(findlink opaque
(LDdown
n)), 1
5801 begin match findpwl
l.pageno dir with
5805 state.mode <- LinkNav
(Ltgendir
dir);
5806 let y, h = getpageyh pageno in
5809 then y + h - state.winh
5814 begin match getopaque pageno, getpage pageno with
5815 | Some opaque
, Some
_ ->
5817 let ld = if dir > 0 then LDfirst
else LDlast
in
5820 begin match link with
5822 showlinktype (getlink opaque
m);
5823 state.mode <- LinkNav
(Ltexact
(pageno, m));
5824 G.postRedisplay "linknav jpage";
5831 begin match opt with
5832 | Some Lnotfound
-> pwl l dir;
5833 | Some
(Lfound
m) ->
5837 let _, y0, _, y1 = getlinkrect opaque
m in
5839 then gotopage1 l.pageno y0
5841 let d = fstate.fontsize
+ 1 in
5842 if y1 - l.pagey > l.pagevh - d
5843 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5844 else G.postRedisplay "linknav";
5846 showlinktype (getlink opaque
m);
5847 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5850 | None
-> viewkeyboard key mask
5852 | _ -> viewkeyboard key mask
5857 G.postRedisplay "leave linknav"
5861 | Ltgendir
_ -> viewkeyboard key mask
5862 | Ltexact exact
-> doexact exact
5865 let keyboard key mask
=
5866 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5867 then wcmd "interrupt"
5868 else state.uioh <- state.uioh#
key key mask
5871 let birdseyekeyboard key mask
5872 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5874 match conf.columns
with
5876 | Cmulti
((c, _, _), _) -> c
5877 | Csplit
_ -> failwith
"bird's eye split mode"
5879 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5881 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5882 let y, h = getpageyh pageno in
5883 let top = (state.winh
- h) / 2 in
5884 gotoy (max
0 (y - top))
5885 | 0xff0d (* enter *)
5886 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5887 | 0xff1b -> leavebirdseye beye
true (* escape *)
5888 | 0xff52 -> upbirdseye incr beye
(* up *)
5889 | 0xff54 -> downbirdseye incr beye
(* down *)
5890 | 0xff51 -> upbirdseye 1 beye
(* left *)
5891 | 0xff53 -> downbirdseye 1 beye
(* right *)
5893 | 0xff55 -> (* prior *)
5894 begin match state.layout with
5898 state.mode <- Birdseye
(
5899 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5901 gotopage1 l.pageno 0;
5904 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5906 | [] -> gotoy (clamp (-state.winh
))
5908 state.mode <- Birdseye
(
5909 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5911 gotopage1 l.pageno 0
5914 | [] -> gotoy (clamp (-state.winh
))
5917 | 0xff56 -> (* next *)
5918 begin match List.rev
state.layout with
5920 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5921 begin match layout with
5923 let incr = l.pageh
- l.pagevh in
5928 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5930 G.postRedisplay "birdseye pagedown";
5932 else gotoy (clamp (incr + conf.interpagespace
*2));
5936 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5937 gotopage1 l.pageno 0;
5940 | [] -> gotoy (clamp state.winh
)
5943 | 0xff50 -> (* home *)
5944 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5947 | 0xff57 -> (* end *)
5948 let pageno = state.pagecount
- 1 in
5949 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5950 if not
(pagevisible state.layout pageno)
5953 match List.rev
state.pdims
with
5955 | (_, _, h, _) :: _ -> h
5957 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5958 else G.postRedisplay "birdseye end";
5959 | _ -> viewkeyboard key mask
5964 match state.mode with
5965 | Textentry
_ -> scalecolor 0.4
5967 | View
-> scalecolor 1.0
5968 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5969 if l.pageno = hooverpageno
5972 if l.pageno = pageno
5980 let postdrawpage l linkindexbase
=
5981 match getopaque l.pageno with
5983 if tileready l l.pagex
l.pagey
5985 let x = l.pagedispx - l.pagex
5986 and y = l.pagedispy - l.pagey in
5988 match conf.columns
with
5989 | Csingle
_ | Cmulti
_ ->
5990 (if conf.hlinks
then 1 else 0)
5992 && not
(isbirdseye state.mode) then 2 else 0)
5996 match state.mode with
5997 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6000 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6005 let scrollindicator () =
6006 let sbw, ph
, sh = state.uioh#
scrollph in
6007 let sbh, pw, sw = state.uioh#scrollpw
in
6009 GlDraw.color (0.64, 0.64, 0.64);
6011 (float (state.winw
- sbw), 0.)
6012 (float state.winw
, float state.winh
)
6015 (0., float (state.winh
- sbh))
6016 (float (wadjsb state.winw
- 1), float state.winh
)
6018 GlDraw.color (0.0, 0.0, 0.0);
6021 (float (state.winw
- sbw), ph
)
6022 (float state.winw
, ph
+. sh)
6025 (pw, float (state.winh
- sbh))
6026 (pw +. sw, float state.winh
)
6031 match state.mstate
with
6032 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6035 | Msel
((x0, y0), (x1, y1)) ->
6036 let rec loop = function
6038 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6039 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6040 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6041 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6043 match getopaque l.pageno with
6045 let x0, y0 = pagetranslatepoint l x0 y0 in
6046 let x1, y1 = pagetranslatepoint l x1 y1 in
6047 seltext opaque
(x0, y0, x1, y1);
6055 let showrects = function [] -> () | rects
->
6057 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6058 GlDraw.polygon_mode `both `fill
;
6059 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6061 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6063 if l.pageno = pageno
6065 let dx = float (l.pagedispx - l.pagex
) in
6066 let dy = float (l.pagedispy - l.pagey) in
6067 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6068 GlDraw.begins `quads
;
6070 GlDraw.vertex2
(x0+.dx, y0+.dy);
6071 GlDraw.vertex2
(x1+.dx, y1+.dy);
6072 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
6073 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
6084 GlClear.color (scalecolor2 conf.bgcolor
);
6085 GlClear.clear
[`
color];
6086 List.iter
drawpage state.layout;
6088 match state.mode with
6089 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6090 begin match getopaque pageno with
6092 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6099 | None
-> state.rects
6104 let rec postloop linkindexbase
= function
6106 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6107 postloop linkindexbase rest
6111 postloop 0 state.layout;
6113 begin match state.mstate
with
6114 | Mzoomrect
((x0, y0), (x1, y1)) ->
6116 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6117 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6118 GlDraw.rect (float x0, float y0)
6119 (float x1, float y1);
6128 let zoomrect x y x1 y1 =
6131 and y0 = min
y y1 in
6132 gotoy (state.y + y0);
6133 state.anchor <- getanchor ();
6134 let zoom = (float state.w) /. float (x1 - x0) in
6136 match conf.fitmodel
, conf.columns
with
6137 | FitPage
, Csplit
_ ->
6138 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6141 let adjw = wadjsb state.winw
in
6143 then (adjw - state.w) / 2
6146 state.x <- (state.x + margin) - x0;
6148 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6149 state.mstate
<- Mnone
;
6153 let g opaque
l px py =
6154 match rectofblock opaque
px py with
6156 let x0 = a.(0) -. 20. in
6157 let x1 = a.(1) +. 20. in
6158 let y0 = a.(2) -. 20. in
6159 let zoom = (float state.w) /. (x1 -. x0) in
6160 let pagey = getpagey l.pageno in
6161 gotoy_and_clear_text (pagey + truncate
y0);
6162 state.anchor <- getanchor ();
6163 let margin = (state.w - l.pagew
)/2 in
6164 state.x <- -truncate
x0 - margin;
6169 match conf.columns
with
6171 showtext '
!'
"block zooming does not work properly in split columns mode"
6172 | _ -> onppundermouse g x y ()
6176 let winw = wadjsb state.winw - 1 in
6177 let s = float x /. float winw in
6178 let destx = truncate
(float (state.w + winw) *. s) in
6179 state.x <- winw - destx;
6180 gotoy_and_clear_text state.y;
6181 state.mstate
<- Mscrollx
;
6185 let s = float y /. float state.winh
in
6186 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6187 gotoy_and_clear_text desty;
6188 state.mstate
<- Mscrolly
;
6191 let viewmouse button down
x y mask
=
6193 | n when (n == 4 || n == 5) && not down
->
6194 if Wsi.withctrl mask
6196 match state.mstate
with
6197 | Mzoom
(oldn
, i
) ->
6205 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6207 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6209 let zoom = conf.zoom -. incr in
6211 state.mstate
<- Mzoom
(n, 0);
6213 state.mstate
<- Mzoom
(n, i
+1);
6215 else state.mstate
<- Mzoom
(n, 0)
6217 | _ -> state.mstate
<- Mzoom
(n, 0)
6220 match state.autoscroll
with
6221 | Some step
-> setautoscrollspeed step
(n=4)
6223 if conf.wheelbypage
|| conf.presentation
6232 then -conf.scrollstep
6233 else conf.scrollstep
6235 let incr = incr * 2 in
6236 let y = clamp incr in
6237 gotoy_and_clear_text y
6240 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6242 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6243 gotoy_and_clear_text state.y
6245 | 1 when Wsi.withshift mask
->
6246 state.mstate
<- Mnone
;
6249 match unproject x y with
6250 | Some
(pageno, ux
, uy
) ->
6251 let cmd = Printf.sprintf
6253 conf.stcmd
state.path pageno ux uy
6259 | 1 when Wsi.withctrl mask
->
6262 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6263 state.mstate
<- Mpan
(x, y)
6266 state.mstate
<- Mnone
6271 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6273 state.mstate
<- Mzoomrect
(p, p)
6276 match state.mstate
with
6277 | Mzoomrect
((x0, y0), _) ->
6278 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6279 then zoomrect x0 y0 x y
6281 state.mstate
<- Mnone
;
6282 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6283 G.postRedisplay "kill accidental zoom rect";
6286 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6287 state.mstate
<- Mnone
6290 | 1 when x > state.winw - vscrollw () ->
6293 let _, position, sh = state.uioh#
scrollph in
6294 if y > truncate
position && y < truncate
(position +. sh)
6295 then state.mstate
<- Mscrolly
6298 state.mstate
<- Mnone
6300 | 1 when y > state.winh
- hscrollh () ->
6303 let _, position, sw = state.uioh#scrollpw
in
6304 if x > truncate
position && x < truncate
(position +. sw)
6305 then state.mstate
<- Mscrollx
6308 state.mstate
<- Mnone
6310 | 1 when state.bzoom
-> if not down
then zoomblock x y
6313 let dest = if down
then getunder x y else Unone
in
6314 begin match dest with
6317 | Uremote
_ | Uremotedest
_
6318 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6321 | Unone
when down
->
6322 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6323 state.mstate
<- Mpan
(x, y);
6325 | Unone
| Utext
_ ->
6328 if conf.angle
mod 360 = 0
6330 state.mstate
<- Msel
((x, y), (x, y));
6331 G.postRedisplay "mouse select";
6335 match state.mstate
with
6338 | Mzoom
_ | Mscrollx
| Mscrolly
->
6339 state.mstate
<- Mnone
6341 | Mzoomrect
((x0, y0), _) ->
6345 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6346 state.mstate
<- Mnone
6348 | Msel
((x0, y0), (x1, y1)) ->
6349 let rec loop = function
6353 let a0 = l.pagedispy in
6354 let a1 = a0 + l.pagevh in
6355 let b0 = l.pagedispx in
6356 let b1 = b0 + l.pagevw in
6357 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6358 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6362 match getopaque l.pageno with
6365 match Ne.pipe () with
6369 "can not create sel pipe: %s"
6372 let doclose what fd
=
6373 Ne.clo fd
(fun msg
->
6374 dolog
"%s close failed: %s" what msg
)
6377 popen conf.selcmd
[r, 0; w, -1];
6378 copysel
w opaque
true;
6380 G.postRedisplay "copysel";
6382 dolog
"can not execute %S: %s"
6383 conf.selcmd
(exntos exn
);
6391 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6392 state.mstate
<- Mnone
;
6399 let birdseyemouse button down
x y mask
6400 (conf, leftx
, _, hooverpageno
, anchor) =
6403 let rec loop = function
6406 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6407 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6409 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6415 | _ -> viewmouse button down
x y mask
6421 method key key mask
=
6422 begin match state.mode with
6423 | Textentry
textentry -> textentrykeyboard key mask
textentry
6424 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6425 | View
-> viewkeyboard key mask
6426 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6430 method button button bstate
x y mask
=
6431 begin match state.mode with
6433 | View
-> viewmouse button bstate
x y mask
6434 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6440 begin match state.mode with
6442 | View
| Birdseye
_ | LinkNav
_ ->
6443 match state.mstate
with
6444 | Mzoom
_ | Mnone
-> ()
6449 state.mstate
<- Mpan
(x, y);
6451 then state.x <- panbound (state.x + dx);
6453 gotoy_and_clear_text y
6456 state.mstate
<- Msel
(a, (x, y));
6457 G.postRedisplay "motion select";
6460 let y = min
state.winh
(max
0 y) in
6464 let x = min
state.winw (max
0 x) in
6467 | Mzoomrect
(p0
, _) ->
6468 state.mstate
<- Mzoomrect
(p0
, (x, y));
6469 G.postRedisplay "motion zoomrect";
6473 method pmotion
x y =
6474 begin match state.mode with
6475 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6476 let rec loop = function
6478 if hooverpageno
!= -1
6480 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6481 G.postRedisplay "pmotion birdseye no hoover";
6484 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6485 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6487 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6488 G.postRedisplay "pmotion birdseye hoover";
6498 match state.mstate
with
6499 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6506 let past, _, _ = !r in
6508 let delta = now -. past in
6511 else r := (now, x, y)
6515 method infochanged
_ = ()
6518 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6521 then 0.0, float state.winh
6522 else scrollph state.y maxy
6527 let winw = wadjsb state.winw in
6528 let fwinw = float winw in
6530 let sw = fwinw /. float state.w in
6531 let sw = fwinw *. sw in
6532 max
sw (float conf.scrollh
)
6535 let maxx = state.w + winw in
6536 let x = winw - state.x in
6537 let percent = float x /. float maxx in
6538 (fwinw -. sw) *. percent
6540 hscrollh (), position, sw
6544 match state.mode with
6545 | LinkNav
_ -> "links"
6546 | Textentry
_ -> "textentry"
6547 | Birdseye
_ -> "birdseye"
6550 findkeyhash conf modename
6552 method eformsgs
= true
6559 let fontpath = ref "";;
6562 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6565 let l = String.length
s in
6566 let b = Buffer.create
l in
6572 try Sys.getenv
"HOME"
6575 ("Can not determine home directory location: " ^ exntos exn
);
6579 let modifier_of_string = function
6580 | "alt" -> Wsi.altmask
6581 | "shift" -> Wsi.shiftmask
6582 | "ctrl" | "control" -> Wsi.ctrlmask
6583 | "meta" -> Wsi.metamask
6588 let r = Str.regexp
"-" in
6590 let elems = Str.full_split
r s in
6593 let m1 = modifier_of_string s in
6595 then (Wsi.namekey
s, m)
6598 | Str.Delim
s when n land 1 = 0 -> g s
6600 | Str.Delim
_ -> (k
, m)
6602 let rec loop n k
m = function
6605 let k, m = f n k m x in
6611 let keys_of_string =
6612 let r = Str.regexp
"[ \t]" in
6614 let elems = Str.split
r s in
6615 List.map
key_of_string elems
6618 let copykeyhashes c =
6619 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6622 let config_of c attrs
=
6626 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6627 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6628 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6629 | "preload" -> { c with preload = bool_of_string
v }
6630 | "page-bias" -> { c with pagebias
= int_of_string
v }
6631 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6632 | "horizontal-scroll-step" ->
6633 { c with hscrollstep
= max
(int_of_string
v) 1 }
6634 | "auto-scroll-step" ->
6635 { c with autoscrollstep
= max
0 (int_of_string
v) }
6636 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6637 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6640 match String.lowercase
v with
6641 | "true" -> Some infinity
6643 | f -> Some
(float_of_string
f)
6645 { c with maxwait
= mw}
6646 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6647 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6648 | "vertical-margin" ->
6649 { c with interpagespace
= max
0 (int_of_string
v) }
6651 let zoom = float_of_string
v /. 100. in
6652 let zoom = max
zoom 0.0 in
6653 { c with zoom = zoom }
6654 | "presentation" -> { c with presentation
= bool_of_string
v }
6655 | "rotation-angle" -> { c with angle
= int_of_string
v }
6656 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6657 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6658 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6659 | "proportional-display" ->
6662 then FitProportional
6665 { c with fitmodel
= fm }
6666 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6667 | "pixmap-cache-size" ->
6668 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6669 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6670 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6671 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6672 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6673 | "background-color" -> { c with bgcolor
= color_of_string v }
6674 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6675 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6676 | "mupdf-store-size" ->
6677 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6678 | "checkers" -> { c with checkers
= bool_of_string
v }
6679 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6680 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6681 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6682 | "uri-launcher" -> { c with urilauncher
= unent v }
6683 | "path-launcher" -> { c with pathlauncher
= unent v }
6684 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6685 | "invert-colors" -> { c with invert
= bool_of_string
v }
6686 | "brightness" -> { c with colorscale
= float_of_string
v }
6687 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6689 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6691 let (n, _, _) as nab
= multicolumns_of_string v in
6693 then { c with columns
= Csplit
(-n, [||]) }
6694 else { c with columns
= Cmulti
(nab
, [||]) }
6695 | "birds-eye-columns" ->
6696 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6697 | "selection-command" -> { c with selcmd
= unent v }
6698 | "synctex-command" -> { c with stcmd
= unent v }
6699 | "pax-command" -> { c with paxcmd
= unent v }
6700 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6701 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6702 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6703 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6704 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6705 | "horizontal-scrollbar-visible" ->
6708 then c.scrollb
lor scrollbhv
6709 else c.scrollb
land (lnot
scrollbhv)
6711 { c with scrollb
= b }
6712 | "vertical-scrollbar-visible" ->
6715 then c.scrollb
lor scrollbvv
6716 else c.scrollb
land (lnot
scrollbvv)
6718 { c with scrollb
= b }
6719 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6723 then Some
(ref (0.0, 0, 0))
6725 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6728 prerr_endline
("Error processing attribute (`" ^
6729 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6732 let rec fold c = function
6735 let c = apply c k v in
6738 fold { c with keyhashes
= copykeyhashes c } attrs
;
6741 let fromstring f pos
n v d =
6744 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6745 n v pos
(exntos exn
)
6750 let bookmark_of attrs
=
6751 let rec fold title page
rely visy
= function
6752 | ("title", v) :: rest
-> fold v page
rely visy rest
6753 | ("page", v) :: rest
-> fold title v rely visy rest
6754 | ("rely", v) :: rest
-> fold title page
v visy rest
6755 | ("visy", v) :: rest
-> fold title page
rely v rest
6756 | _ :: rest
-> fold title page
rely visy rest
6757 | [] -> title, page
, rely, visy
6759 fold "invalid" "0" "0" "0" attrs
6763 let rec fold path page
rely pan visy
= function
6764 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6765 | ("page", v) :: rest
-> fold path v rely pan visy rest
6766 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6767 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6768 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6769 | _ :: rest
-> fold path page
rely pan visy rest
6770 | [] -> path, page
, rely, pan
, visy
6772 fold "" "0" "0" "0" "0" attrs
6776 let rec fold rs ls
= function
6777 | ("out", v) :: rest
-> fold v ls rest
6778 | ("in", v) :: rest
-> fold rs
v rest
6779 | _ :: rest
-> fold ls rs rest
6785 let setconf dst
src =
6786 dst
.scrollbw
<- src.scrollbw
;
6787 dst
.scrollh
<- src.scrollh
;
6788 dst
.icase
<- src.icase
;
6789 dst
.preload <- src.preload;
6790 dst
.pagebias
<- src.pagebias
;
6791 dst
.verbose
<- src.verbose
;
6792 dst
.scrollstep
<- src.scrollstep
;
6793 dst
.maxhfit
<- src.maxhfit
;
6794 dst
.crophack
<- src.crophack
;
6795 dst
.autoscrollstep
<- src.autoscrollstep
;
6796 dst
.maxwait
<- src.maxwait
;
6797 dst
.hlinks
<- src.hlinks
;
6798 dst
.underinfo
<- src.underinfo
;
6799 dst
.interpagespace
<- src.interpagespace
;
6800 dst
.zoom <- src.zoom;
6801 dst
.presentation
<- src.presentation
;
6802 dst
.angle
<- src.angle
;
6803 dst
.cwinw
<- src.cwinw
;
6804 dst
.cwinh
<- src.cwinh
;
6805 dst
.savebmarks
<- src.savebmarks
;
6806 dst
.memlimit
<- src.memlimit
;
6807 dst
.fitmodel
<- src.fitmodel
;
6808 dst
.texcount
<- src.texcount
;
6809 dst
.sliceheight
<- src.sliceheight
;
6810 dst
.thumbw
<- src.thumbw
;
6811 dst
.jumpback
<- src.jumpback
;
6812 dst
.bgcolor
<- src.bgcolor
;
6813 dst
.tilew
<- src.tilew
;
6814 dst
.tileh
<- src.tileh
;
6815 dst
.mustoresize
<- src.mustoresize
;
6816 dst
.checkers
<- src.checkers
;
6817 dst
.aalevel
<- src.aalevel
;
6818 dst
.trimmargins
<- src.trimmargins
;
6819 dst
.trimfuzz
<- src.trimfuzz
;
6820 dst
.urilauncher
<- src.urilauncher
;
6821 dst
.colorspace
<- src.colorspace
;
6822 dst
.invert
<- src.invert
;
6823 dst
.colorscale
<- src.colorscale
;
6824 dst
.redirectstderr <- src.redirectstderr;
6825 dst
.ghyllscroll
<- src.ghyllscroll
;
6826 dst
.columns
<- src.columns
;
6827 dst
.beyecolumns
<- src.beyecolumns
;
6828 dst
.selcmd
<- src.selcmd
;
6829 dst
.updatecurs
<- src.updatecurs
;
6830 dst
.pathlauncher
<- src.pathlauncher
;
6831 dst
.keyhashes
<- copykeyhashes src;
6832 dst
.hfsize
<- src.hfsize
;
6833 dst
.hscrollstep
<- src.hscrollstep
;
6834 dst
.pgscale <- src.pgscale;
6835 dst
.usepbo
<- src.usepbo
;
6836 dst
.wheelbypage
<- src.wheelbypage
;
6837 dst
.stcmd
<- src.stcmd
;
6838 dst
.paxcmd
<- src.paxcmd
;
6839 dst
.scrollb
<- src.scrollb
;
6840 dst
.riani
<- src.riani
;
6841 dst
.paxmark
<- src.paxmark
;
6845 else Some
((ref (0.0, 0, 0)));
6849 let h = Hashtbl.create
10 in
6850 let dc = { defconf with angle
= defconf.angle
} in
6851 let rec toplevel v t spos
_ =
6853 | Vdata
| Vcdata
| Vend
-> v
6854 | Vopen
("llppconfig", _, closed
) ->
6857 else { v with f = llppconfig
}
6859 error
"unexpected subelement at top level" s spos
6860 | Vclose
_ -> error
"unexpected close at top level" s spos
6862 and llppconfig
v t spos
_ =
6864 | Vdata
| Vcdata
-> v
6865 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6866 | Vopen
("defaults", attrs
, closed
) ->
6867 let c = config_of dc attrs
in
6871 else { v with f = defaults
}
6873 | Vopen
("ui-font", attrs
, closed
) ->
6874 let rec getsize size
= function
6876 | ("size", v) :: rest
->
6878 fromstring int_of_string spos
"size" v fstate.fontsize
in
6880 | l -> getsize size l
6882 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6885 else { v with f = uifont
(Buffer.create
10) }
6887 | Vopen
("doc", attrs
, closed
) ->
6888 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6889 let path = unent pathent
6890 and pageno = fromstring int_of_string spos
"page" spage
0
6891 and rely = fromstring float_of_string spos
"rely" srely
0.0
6892 and pan
= fromstring int_of_string spos
"pan" span
0
6893 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6894 let c = config_of dc attrs
in
6895 let anchor = (pageno, rely, visy
) in
6897 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6898 else { v with f = doc
path pan
anchor c [] }
6901 error
"unexpected subelement in llppconfig" s spos
6903 | Vclose
"llppconfig" -> { v with f = toplevel }
6904 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6906 and defaults
v t spos
_ =
6908 | Vdata
| Vcdata
-> v
6909 | Vend
-> error
"unexpected end of input in defaults" s spos
6910 | Vopen
("keymap", attrs
, closed
) ->
6912 try List.assoc
"mode" attrs
6913 with Not_found
-> "global" in
6918 let h = findkeyhash dc modename in
6919 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6922 { v with f = pkeymap
ret KeyMap.empty }
6924 | Vopen
(_, _, _) ->
6925 error
"unexpected subelement in defaults" s spos
6927 | Vclose
"defaults" ->
6928 { v with f = llppconfig
}
6930 | Vclose
_ -> error
"unexpected close in defaults" s spos
6932 and uifont
b v t spos
epos =
6935 Buffer.add_substring
b s spos
(epos - spos
);
6937 | Vopen
(_, _, _) ->
6938 error
"unexpected subelement in ui-font" s spos
6939 | Vclose
"ui-font" ->
6940 if emptystr
!fontpath
6941 then fontpath := Buffer.contents
b;
6942 { v with f = llppconfig
}
6943 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6944 | Vend
-> error
"unexpected end of input in ui-font" s spos
6946 and doc
path pan
anchor c bookmarks
v t spos
_ =
6948 | Vdata
| Vcdata
-> v
6949 | Vend
-> error
"unexpected end of input in doc" s spos
6950 | Vopen
("bookmarks", _, closed
) ->
6953 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6955 | Vopen
("keymap", attrs
, closed
) ->
6957 try List.assoc
"mode" attrs
6958 with Not_found
-> "global"
6964 let h = findkeyhash c modename in
6965 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6966 doc
path pan
anchor c bookmarks
6968 { v with f = pkeymap
ret KeyMap.empty }
6970 | Vopen
(_, _, _) ->
6971 error
"unexpected subelement in doc" s spos
6974 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6975 { v with f = llppconfig
}
6977 | Vclose
_ -> error
"unexpected close in doc" s spos
6979 and pkeymap
ret keymap
v t spos
_ =
6981 | Vdata
| Vcdata
-> v
6982 | Vend
-> error
"unexpected end of input in keymap" s spos
6983 | Vopen
("map", attrs
, closed
) ->
6984 let r, l = map_of attrs
in
6985 let kss = fromstring keys_of_string spos
"in" r [] in
6986 let lss = fromstring keys_of_string spos
"out" l [] in
6990 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6991 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6994 then { v with f = pkeymap
ret keymap }
6997 { v with f = skip
"map" f }
7000 error
"unexpected subelement in keymap" s spos
7002 | Vclose
"keymap" ->
7003 { v with f = ret keymap }
7005 | Vclose
_ -> error
"unexpected close in keymap" s spos
7007 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7009 | Vdata
| Vcdata
-> v
7010 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7011 | Vopen
("item", attrs
, closed
) ->
7012 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7013 let page = fromstring int_of_string spos
"page" spage
0
7014 and rely = fromstring float_of_string spos
"rely" srely
0.0
7015 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7017 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
7020 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7023 { v with f = skip
"item" f }
7026 error
"unexpected subelement in bookmarks" s spos
7028 | Vclose
"bookmarks" ->
7029 { v with f = doc
path pan
anchor c bookmarks }
7031 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7033 and skip tag
f v t spos
_ =
7035 | Vdata
| Vcdata
-> v
7037 error
("unexpected end of input in skipped " ^ tag
) s spos
7038 | Vopen
(tag'
, _, closed
) ->
7042 let f'
() = { v with f = skip tag
f } in
7043 { v with f = skip tag'
f'
}
7047 else error
("unexpected close in skipped " ^ tag
) s spos
7050 parse
{ f = toplevel; accu = () } s;
7056 let len = in_channel_length ic
in
7057 let s = String.create
len in
7058 really_input ic
s 0 len;
7061 | Parse_error
(msg
, s, pos
) ->
7062 let subs = subs s pos
in
7063 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7066 failwith
("config load error: " ^ exntos exn
)
7072 let dir = Filename.concat
home ".config" in
7073 if Sys.is_directory
dir then dir else home
7076 Filename.concat
dir "llpp.conf"
7079 let confpath = ref defconfpath;;
7082 if Sys.file_exists
!confpath
7085 (try Some
(open_in_bin
!confpath)
7088 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7099 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7108 f (Hashtbl.create
0, defconf)
7113 let pc, pb
, px, pa
=
7116 if emptystr
state.origin
7120 Hashtbl.find h (Filename.basename
key)
7121 with Not_found
-> dc, [], 0, emptyanchor
7125 state.bookmarks <- pb
;
7128 then state.anchor <- pa
;
7129 cbput state.hists
.nav pa
;
7135 let add_attrs bb always
dc c =
7138 then Printf.bprintf bb
"\n %s='%b'" s a
7141 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7144 then Printf.bprintf bb
"\n %s='%d'" s a
7147 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7150 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7153 then Printf.bprintf bb
"\n %s='%f'" s a
7157 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7161 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7165 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7169 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7175 | Some
(_N
, _A
, _B
) ->
7176 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7186 else string_of_float
f
7188 Printf.bprintf bb
"\n %s='%s'" s v
7193 | Cmulti
((n, a, b), _) when n > 1 ->
7194 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7195 | Csplit
(n, _) when n > 1 ->
7196 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7202 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7207 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7211 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7215 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7217 oi
"width" c.cwinw
dc.cwinw
;
7218 oi
"height" c.cwinh
dc.cwinh
;
7219 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7220 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7221 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7222 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7223 ob "case-insensitive-search" c.icase
dc.icase
;
7224 ob "preload" c.preload dc.preload;
7225 oi
"page-bias" c.pagebias
dc.pagebias
;
7226 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7227 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7228 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7229 ob "crop-hack" c.crophack
dc.crophack
;
7230 oW
"throttle" c.maxwait
dc.maxwait
;
7231 ob "highlight-links" c.hlinks
dc.hlinks
;
7232 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7233 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7234 oz
"zoom" c.zoom dc.zoom;
7235 ob "presentation" c.presentation
dc.presentation
;
7236 oi
"rotation-angle" c.angle
dc.angle
;
7237 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7238 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7239 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7240 oi
"tex-count" c.texcount
dc.texcount
;
7241 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7242 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7243 ob "persistent-location" c.jumpback
dc.jumpback
;
7244 oc
"background-color" c.bgcolor
dc.bgcolor
;
7245 oi
"tile-width" c.tilew
dc.tilew
;
7246 oi
"tile-height" c.tileh
dc.tileh
;
7247 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7248 ob "checkers" c.checkers
dc.checkers
;
7249 oi
"aalevel" c.aalevel
dc.aalevel
;
7250 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7251 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7252 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7253 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7254 oC
"color-space" c.colorspace
dc.colorspace
;
7255 ob "invert-colors" c.invert
dc.invert
;
7256 oF
"brightness" c.colorscale
dc.colorscale
;
7257 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7258 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7259 oco
"columns" c.columns
dc.columns
;
7260 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7261 os
"selection-command" c.selcmd
dc.selcmd
;
7262 os
"synctex-command" c.stcmd
dc.stcmd
;
7263 os
"pax-command" c.paxcmd
dc.paxcmd
;
7264 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7265 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7266 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7267 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7268 ob "use-pbo" c.usepbo
dc.usepbo
;
7269 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7270 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7271 op
"point-and-x" c.pax
dc.pax
;
7272 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7275 let keymapsbuf always
dc c =
7276 let bb = Buffer.create
16 in
7277 let rec loop = function
7279 | (modename, h) :: rest
->
7280 let dh = findkeyhash dc modename in
7281 if always
|| h <> dh
7283 if Hashtbl.length
h > 0
7285 if Buffer.length
bb > 0
7286 then Buffer.add_char
bb '
\n'
;
7287 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7288 Hashtbl.iter
(fun i
o ->
7289 let isdifferent = always
||
7291 let dO = Hashtbl.find dh i
in
7293 with Not_found
-> true
7298 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7299 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7300 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7301 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7302 Buffer.add_string
bb (Wsi.keyname
k);
7305 let rec loop = function
7307 | km
:: [] -> addkm km
7308 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7312 Buffer.add_string
bb "<map in='";
7316 Buffer.add_string
bb "' out='";
7318 Buffer.add_string
bb "'/>\n"
7321 Buffer.add_string
bb "' out='";
7323 Buffer.add_string
bb "'/>\n"
7325 | KMmulti
(ins, kms
) ->
7326 Buffer.add_char
bb ' '
;
7328 Buffer.add_string
bb "' out='";
7330 Buffer.add_string
bb "'/>\n"
7332 Buffer.add_string
bb "</keymap>";
7342 let uifontsize = fstate.fontsize
in
7343 let bb = Buffer.create
32768 in
7344 let relx = float state.x /. float state.winw in
7346 let cx w = truncate
(relx *. float w) in
7348 (fun (w, h, x) ws
->
7350 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7351 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7352 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7354 (state.winw, state.winh
, state.x) state.winstate
7359 let dc = if conf.bedefault
then conf else dc in
7360 Buffer.add_string
bb "<llppconfig>\n";
7362 if nonemptystr
!fontpath
7364 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7370 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7373 Buffer.add_string
bb "<defaults";
7374 add_attrs bb true dc dc;
7375 let kb = keymapsbuf true dc dc in
7376 if Buffer.length
kb > 0
7378 Buffer.add_string
bb ">\n";
7379 Buffer.add_buffer
bb kb;
7380 Buffer.add_string
bb "\n</defaults>\n";
7382 else Buffer.add_string
bb "/>\n";
7384 let adddoc path pan
anchor c bookmarks =
7385 if bookmarks == [] && c = dc && anchor = emptyanchor
7388 Printf.bprintf
bb "<doc path='%s'"
7389 (enent
path 0 (String.length
path));
7391 if anchor <> emptyanchor
7393 let n, rely, visy
= anchor in
7394 Printf.bprintf
bb " page='%d'" n;
7397 Printf.bprintf
bb " rely='%f'" rely
7399 if abs_float visy
> 1e-6
7401 Printf.bprintf
bb " visy='%f'" visy
7406 then Printf.bprintf
bb " pan='%d'" pan
;
7408 add_attrs bb false dc c;
7409 let kb = keymapsbuf false dc c in
7411 begin match bookmarks with
7413 if Buffer.length
kb > 0
7415 Buffer.add_string
bb ">\n";
7416 Buffer.add_buffer
bb kb;
7417 Buffer.add_string
bb "\n</doc>\n";
7419 else Buffer.add_string
bb "/>\n"
7421 Buffer.add_string
bb ">\n<bookmarks>\n";
7422 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7424 "<item title='%s' page='%d'"
7425 (enent
title 0 (String.length
title))
7430 Printf.bprintf
bb " rely='%f'" rely
7432 if abs_float visy
> 1e-6
7434 Printf.bprintf
bb " visy='%f'" visy
7436 Buffer.add_string
bb "/>\n";
7438 Buffer.add_string
bb "</bookmarks>";
7439 if Buffer.length
kb > 0
7441 Buffer.add_string
bb "\n";
7442 Buffer.add_buffer
bb kb;
7444 Buffer.add_string
bb "\n</doc>\n";
7450 match state.mode with
7451 | Birdseye
(c, pan, _, _, _) ->
7453 match conf.columns
with
7454 | Cmulti
((c, _, _), _) -> Some
c
7458 match c.columns
with
7459 | Cmulti
(c, _) -> Cmulti
(c, [||])
7460 | Csingle
_ -> Csingle
[||]
7461 | Csplit
_ -> failwith
"quit from bird's eye while split"
7463 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7466 let basename = Filename.basename
7467 (if emptystr
state.origin
then state.path else state.origin
)
7469 adddoc basename pan (getanchor ())
7471 let autoscrollstep =
7472 match state.autoscroll
with
7474 | None
-> conf.autoscrollstep
7476 match state.mode with
7477 | Birdseye
(bc
, _, _, _, _) ->
7480 presentation
= bc
.presentation
;
7481 interpagespace
= bc
.interpagespace
;
7482 maxwait
= bc
.maxwait
;
7483 autoscrollstep = autoscrollstep }
7484 | _ -> { conf with autoscrollstep = autoscrollstep }
7486 (if conf.savebmarks
then state.bookmarks else []);
7488 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7490 then adddoc path x anchor c bookmarks
7492 Buffer.add_string
bb "</llppconfig>\n";
7495 if load1 f && Buffer.length
bb > 0
7498 let tmp = !confpath ^
".tmp" in
7499 let oc = open_out_bin
tmp in
7500 Buffer.output_buffer
oc bb;
7502 Unix.rename
tmp !confpath;
7505 ("error while saving configuration: " ^ exntos exn
)
7509 let adderrmsg src msg
=
7510 Buffer.add_string
state.errmsgs msg
;
7511 state.newerrmsgs
<- true;
7515 let adderrfmt src fmt
=
7516 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7520 let cl = splitatspace cmds
in
7522 try Scanf.sscanf
s fmt
f
7524 adderrfmt "remote exec"
7525 "error processing '%S': %s\n" cmds
(exntos exn
)
7528 | "reload" :: [] -> reload ()
7529 | "goto" :: args :: [] ->
7530 scan args "%u %f %f"
7532 let cmd, _ = state.geomcmds
in
7534 then gotopagexy pageno x y
7537 gotopagexy pageno x y;
7540 state.reprf
<- f state.reprf
7542 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7543 | "rect" :: args :: [] ->
7544 scan args "%u %u %f %f %f %f"
7545 (fun pageno color x0 y0 x1 y1 ->
7546 onpagerect pageno (fun w h ->
7547 let _,w1,h1
,_ = getpagedim pageno in
7548 let sw = float w1 /. float w
7549 and sh = float h1
/. float h in
7553 and y1s
= y1 *. sh in
7554 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7556 state.rects <- (pageno, color, rect) :: state.rects;
7557 G.postRedisplay "rect";
7560 | "activatewin" :: [] -> Wsi.activatewin
()
7561 | "quit" :: [] -> raise Quit
7563 adderrfmt "remote command"
7564 "error processing remote command: %S\n" cmds
;
7568 let scratch = String.create
80 in
7569 let buf = Buffer.create
80 in
7572 try Some
(Unix.read fd
scratch 0 80)
7574 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7575 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7578 match tempfr () with
7584 if Buffer.length
buf > 0
7586 let s = Buffer.contents
buf in
7596 let pos = String.index_from
scratch ppos '
\n'
in
7597 if pos >= n then -1 else pos
7598 with Not_found
-> -1
7602 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7603 let s = Buffer.contents
buf in
7609 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7615 let remoteopen path =
7616 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7618 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7623 let trimcachepath = ref "" in
7624 let rcmdpath = ref "" in
7625 selfexec := Sys.executable_name
;
7628 [("-p", Arg.String
(fun s -> state.password
<- s),
7629 "<password> Set password");
7633 Config.fontpath := s;
7634 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7636 "<path> Set path to the user interface font");
7640 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7641 Config.confpath := s),
7642 "<path> Set path to the configuration file");
7644 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7645 "<path> Set path to the trim cache file");
7647 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7648 "<named-destination> Set named destination");
7650 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7651 ("-cxack", Arg.Set
cxack, " Cut corners");
7653 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7654 "<path> Set path to the remote commands source");
7656 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7657 "<original-path> Set original path");
7659 ("-v", Arg.Unit
(fun () ->
7661 "%s\nconfiguration path: %s\n"
7665 exit
0), " Print version and exit");
7668 (fun s -> state.path <- s)
7669 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7672 then selfexec := !selfexec ^
" -wtmode";
7674 if emptystr
state.path
7675 then (prerr_endline
"file name missing"; exit
1);
7677 if not
(Config.load ())
7678 then prerr_endline
"failed to load configuration";
7680 let wsfd, winw, winh
= Wsi.init
(object
7681 val mutable m_hack
= false
7682 method expose
= if not m_hack
then G.postRedisplay "expose"
7683 method visible
= G.postRedisplay "visible"
7684 method display = m_hack
<- false; display ()
7685 method reshape w h =
7686 m_hack
<- w < state.winw && h < state.winh
;
7688 method mouse
b d x y m = state.uioh <- state.uioh#button
b d x y m
7690 state.mpos
<- (x, y);
7691 state.uioh <- state.uioh#motion
x y
7692 method pmotion
x y =
7693 state.mpos
<- (x, y);
7694 state.uioh <- state.uioh#pmotion
x y
7696 let mascm = m land (
7697 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7699 match state.keystate
with
7701 let km = k, mascm in
7704 let modehash = state.uioh#
modehash in
7705 try Hashtbl.find modehash km
7707 try Hashtbl.find (findkeyhash conf "global") km
7708 with Not_found
-> KMinsrt
(k, m)
7710 | KMinsrt
(k, m) -> keyboard k m
7711 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7712 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7714 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7715 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7716 state.keystate
<- KSnone
7717 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7718 state.keystate
<- KSinto
(keys
, insrt
)
7720 state.keystate
<- KSnone
7723 state.mpos
<- (x, y);
7724 state.uioh <- state.uioh#pmotion
x y
7725 method leave = state.mpos
<- (-1, -1)
7726 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7727 method quit
= raise Quit
7728 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7733 List.exists
GlMisc.check_extension
7734 [ "GL_ARB_texture_rectangle"
7735 ; "GL_EXT_texture_recangle"
7736 ; "GL_NV_texture_rectangle" ]
7738 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7741 let r = GlMisc.get_string `renderer
in
7742 let p = "Mesa DRI Intel(" in
7743 let l = String.length
p in
7744 String.length
r > l && String.sub
r 0 l = p
7747 defconf.sliceheight
<- 1024;
7748 defconf.texcount
<- 32;
7749 defconf.usepbo
<- true;
7753 match Ne.pipe () with
7755 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7759 match Ne.pipe () with
7761 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7771 setcheckers conf.checkers
;
7773 if conf.redirectstderr
7776 let s = Buffer.contents
state.errmsgs ^
7777 (match state.errfd
with
7779 let s = String.create
(80*24) in
7782 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7784 then Unix.read fd
s 0 (String.length
s)
7790 else String.sub
s 0 n
7794 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7795 with exn
-> print_endline
(exntos exn
)
7800 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7801 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7802 !Config.fontpath, !trimcachepath,
7803 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7807 state.text <- "Opening " ^
(mbtoutf8
state.path);
7809 opendoc state.path state.password
;
7813 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7816 if nonemptystr
!rcmdpath
7817 then remoteopen !rcmdpath
7822 let rec loop deadline
=
7824 match state.errfd
with
7825 | None
-> [state.sr
; state.wsfd]
7826 | Some fd
-> [state.sr
; state.wsfd; fd
]
7831 | Some fd
-> fd
:: r
7835 state.redisplay
<- false;
7842 if deadline
= infinity
7844 else max
0.0 (deadline
-. now)
7849 try Unix.select
r [] [] timeout
7850 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7856 if state.ghyll
== noghyll
7858 match state.autoscroll
with
7859 | Some step
when step
!= 0 ->
7860 let y = state.y + step
in
7864 else if y >= state.maxy then 0 else y
7867 if state.mode = View
7868 then state.text <- "";
7871 else deadline
+. 0.01
7876 let rec checkfds = function
7878 | fd
:: rest
when fd
= state.sr
->
7879 let cmd = readcmd state.sr
in
7883 | fd
:: rest
when fd
= state.wsfd ->
7887 | fd
:: rest
when Some fd
= !optrfd ->
7888 begin match remote fd
with
7889 | None
-> optrfd := remoteopen !rcmdpath;
7890 | opt -> optrfd := opt
7895 let s = String.create
80 in
7896 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7897 if conf.redirectstderr
7899 Buffer.add_substring
state.errmsgs
s 0 n;
7900 state.newerrmsgs
<- true;
7901 state.redisplay
<- true;
7904 prerr_string
(String.sub
s 0 n);
7912 if deadline
= infinity
7916 match state.autoscroll
with
7917 | Some step
when step
!= 0 -> deadline1
7918 | _ -> if state.ghyll
== noghyll then infinity
else deadline1