8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
23 type params
= (angle
* fitmodel
* trimparams
24 * texcount
* sliceheight
* memsize
25 * colorspace
* fontpath
* trimcachepath
35 and trimmargins
= bool
36 and interpagespace
= int
43 and trimcachepath
= string
46 and irect
= (int * int * int * int)
47 and trimparams
= (trimmargins
* irect
)
48 and colorspace
= | Rgb
| Bgr
| Gray
49 and fitmodel
= | FitWidth
| FitProportional
| FitPage
57 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
66 | LDfirstvisible
of (int * int * int)
81 | KMmulti
of key list
* key list
83 and keyhash
= (key
, keymap
) Hashtbl.t
86 | KSinto
of (key list
* key list
)
89 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
90 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
92 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
94 external init
: pipe
-> params
-> unit = "ml_init";;
95 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
96 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
97 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
98 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
99 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
100 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
101 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
102 external measurestr
: int -> string -> float = "ml_measure_string";;
103 external postprocess
:
104 opaque
-> int -> int -> int -> (int * string * int) -> int
106 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
107 external platform
: unit -> platform
= "ml_platform";;
108 external setaalevel
: int -> unit = "ml_setaalevel";;
109 external realloctexts
: int -> bool = "ml_realloctexts";;
110 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
111 external getlink
: opaque
-> int -> under
= "ml_getlink";;
112 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
113 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
114 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
115 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
116 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
117 external freepbo
: string -> unit = "ml_freepbo";;
118 external unmappbo
: string -> unit = "ml_unmappbo";;
119 external pbousable
: unit -> bool = "ml_pbo_usable";;
120 external unproject
: opaque
-> int -> int -> (int * int) option
122 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
123 external rectofblock
: opaque
-> int -> int -> float array
option
126 let platform_to_string = function
127 | Punknown
-> "unknown"
131 | Pfreebsd
-> "FreeBSD"
132 | Pdragonflybsd
-> "DragonflyBSD"
133 | Popenbsd
-> "OpenBSD"
134 | Pnetbsd
-> "NetBSD"
135 | Pcygwin
-> "Cygwin"
138 let platform = platform ();;
140 let now = Unix.gettimeofday
;;
142 let selfexec = ref "";;
145 if platform = Pcygwin
147 let sh = "/bin/sh" in
148 let args = [|sh; "-c"; cmd
|] in
149 let rec std si so se
= function
151 | (fd
, 0) :: rest
-> std fd so se rest
152 | (fd
, -1) :: rest
->
153 Unix.set_close_on_exec fd
;
156 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
158 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
159 ignore
(Unix.create_process
sh args si so se
)
164 type mpos
= int * int
166 | Msel
of (mpos
* mpos
)
168 | Mscrolly
| Mscrollx
169 | Mzoom
of (int * int)
170 | Mzoomrect
of (mpos
* mpos
)
174 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
175 and onkey
= string -> int -> te
176 and ondone
= string -> unit
177 and histcancel
= unit -> unit
178 and onhist
= ((histcmd
-> string) * histcancel
)
179 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
180 and cancelonempty
= bool
185 | TEswitch
of textentry
196 let bound v minv maxv
=
197 max minv
(min maxv v
);
201 { store
= Array.create n v
208 let cbcap b
= Array.length b
.store
;;
213 b
.wc
<- (b
.wc
+ 1) mod cap;
215 b
.len
<- min
(b
.len
+ 1) cap;
218 let cbempty b
= b
.len
= 0;;
220 let cbgetg b circular dir
=
224 let rc = b
.rc + dir
in
236 else bound rc 0 (b
.len
-1)
242 let cbget b
= cbgetg b
false;;
243 let cbgetc b
= cbgetg b
true;;
245 let drawstring size x y s
=
247 Gl.enable `texture_2d
;
248 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
249 ignore
(drawstr size x y s
);
251 Gl.disable `texture_2d
;
254 let drawstring1 size x y s
=
258 let drawstring2 size x y fmt
=
259 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
278 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
279 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
280 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
281 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
282 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
283 dolog
" column %d" l
.pagecol
;
287 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
289 dolog
" x0,y0=(% f, % f)" x0 y0
;
290 dolog
" x1,y1=(% f, % f)" x1 y1
;
291 dolog
" x2,y2=(% f, % f)" x2 y2
;
292 dolog
" x3,y3=(% f, % f)" x3 y3
;
296 type multicolumns
= multicol
* pagegeom
297 and singlecolumn
= pagegeom
298 and splitcolumns
= columncount
* pagegeom
299 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
300 and multicol
= columncount
* covercount
* covercount
302 and columncount
= int
303 and covercount
= int;;
310 { mutable scrollbw
: int
311 ; mutable scrollh
: int
312 ; mutable scrollb
: scrollb
313 ; mutable icase
: bool
314 ; mutable preload
: bool
315 ; mutable pagebias
: int
316 ; mutable verbose
: bool
317 ; mutable debug
: bool
318 ; mutable scrollstep
: int
319 ; mutable hscrollstep
: int
320 ; mutable maxhfit
: bool
321 ; mutable crophack
: bool
322 ; mutable autoscrollstep
: int
323 ; mutable maxwait
: float option
324 ; mutable hlinks
: bool
325 ; mutable underinfo
: bool
326 ; mutable interpagespace
: interpagespace
327 ; mutable zoom
: float
328 ; mutable presentation
: bool
329 ; mutable angle
: angle
330 ; mutable cwinw
: int
331 ; mutable cwinh
: int
332 ; mutable savebmarks
: bool
333 ; mutable fitmodel
: fitmodel
334 ; mutable trimmargins
: trimmargins
335 ; mutable trimfuzz
: irect
336 ; mutable memlimit
: memsize
337 ; mutable texcount
: texcount
338 ; mutable sliceheight
: sliceheight
339 ; mutable thumbw
: width
340 ; mutable jumpback
: bool
341 ; mutable bgcolor
: (float * float * float)
342 ; mutable bedefault
: bool
343 ; mutable tilew
: int
344 ; mutable tileh
: int
345 ; mutable mustoresize
: memsize
346 ; mutable checkers
: bool
347 ; mutable aalevel
: int
348 ; mutable urilauncher
: string
349 ; mutable pathlauncher
: string
350 ; mutable colorspace
: colorspace
351 ; mutable invert
: bool
352 ; mutable colorscale
: float
353 ; mutable redirectstderr
: bool
354 ; mutable ghyllscroll
: (int * int * int) option
355 ; mutable columns
: columns
356 ; mutable beyecolumns
: columncount
option
357 ; mutable selcmd
: string
358 ; mutable paxcmd
: string
359 ; mutable updatecurs
: bool
360 ; mutable keyhashes
: (string * keyhash
) list
361 ; mutable hfsize
: int
362 ; mutable pgscale
: float
363 ; mutable usepbo
: bool
364 ; mutable wheelbypage
: bool
365 ; mutable stcmd
: string
366 ; mutable riani
: bool
367 ; mutable pax
: (float * int * int) ref option
368 ; mutable paxmark
: mark
371 | Csingle
of singlecolumn
372 | Cmulti
of multicolumns
373 | Csplit
of splitcolumns
376 type anchor
= pageno
* top
* dtop
;;
378 type outline
= string * int * anchor
;;
380 type rect
= float * float * float * float * float * float * float * float;;
382 type tile
= opaque
* pixmapsize
* elapsed
383 and elapsed
= float;;
384 type pagemapkey
= pageno
* gen
;;
385 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
389 let emptyanchor = (0, 0.0, 0.0);;
391 type infochange
= | Memused
| Docinfo
| Pdim
;;
393 class type uioh
= object
394 method display
: unit
395 method key
: int -> int -> uioh
396 method button
: int -> bool -> int -> int -> int -> uioh
397 method motion
: int -> int -> uioh
398 method pmotion
: int -> int -> uioh
399 method infochanged
: infochange
-> unit
400 method scrollpw
: (int * float * float)
401 method scrollph
: (int * float * float)
402 method modehash
: keyhash
403 method eformsgs
: bool
407 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
408 | Textentry
of (textentry
* onleave
)
410 | LinkNav
of linktarget
411 and onleave
= leavetextentrystatus
-> unit
412 and leavetextentrystatus
= | Cancel
| Confirm
413 and helpitem
= string * int * action
416 | Action
of (uioh
-> uioh
)
418 | Ltexact
of (pageno
* int)
422 let isbirdseye = function Birdseye _
-> true | _
-> false;;
423 let istextentry = function Textentry _
-> true | _
-> false;;
427 | Loading
of (page
* gen
)
429 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
431 | Outlining
of outline list
434 let emptykeyhash = Hashtbl.create
0;;
435 let nouioh : uioh
= object (self
)
437 method key _ _
= self
438 method button _ _ _ _ _
= self
439 method motion _ _
= self
440 method pmotion _ _
= self
441 method infochanged _
= ()
442 method scrollpw
= (0, nan
, nan
)
443 method scrollph
= (0, nan
, nan
)
444 method modehash
= emptykeyhash
445 method eformsgs
= false
449 { mutable sr
: Unix.file_descr
450 ; mutable sw
: Unix.file_descr
451 ; mutable wsfd
: Unix.file_descr
452 ; mutable errfd
: Unix.file_descr
option
453 ; mutable stderr
: Unix.file_descr
454 ; mutable errmsgs
: Buffer.t
455 ; mutable newerrmsgs
: bool
459 ; mutable anchor
: anchor
460 ; mutable ranchors
: (string * string * anchor
* string) list
462 ; mutable layout
: page list
463 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
464 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
465 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
466 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
467 ; mutable pagecount
: int
468 ; mutable currently
: currently
469 ; mutable mstate
: mstate
470 ; mutable searchpattern
: string
471 ; mutable rects
: (pageno
* recttype
* rect
) list
472 ; mutable rects1
: (pageno
* recttype
* rect
) list
473 ; mutable text
: string
474 ; mutable winstate
: Wsi.winstate list
475 ; mutable mode
: mode
476 ; mutable uioh
: uioh
477 ; mutable outlines
: outline array
478 ; mutable bookmarks
: outline list
479 ; mutable path
: string
480 ; mutable password
: string
481 ; mutable nameddest
: string
482 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
483 ; mutable memused
: memsize
485 ; mutable throttle
: (page list
* int * float) option
486 ; mutable autoscroll
: int option
487 ; mutable ghyll
: (int option -> unit)
488 ; mutable help
: helpitem array
489 ; mutable docinfo
: (int * string) list
490 ; mutable texid
: GlTex.texture_id
option
492 ; mutable prevzoom
: (float * int)
493 ; mutable progress
: float
494 ; mutable redisplay
: bool
495 ; mutable mpos
: mpos
496 ; mutable keystate
: keystate
497 ; mutable glinks
: bool
498 ; mutable prevcolumns
: (columns
* float) option
501 ; mutable reprf
: (unit -> unit)
502 ; mutable origin
: string
503 ; mutable roam
: (unit -> unit)
504 ; mutable bzoom
: bool
507 { pat
: string circbuf
508 ; pag
: string circbuf
509 ; nav
: anchor circbuf
510 ; sel
: string circbuf
517 ; scrollb
= scrollbhv lor scrollbvv
533 ; presentation
= false
538 ; fitmodel
= FitProportional
539 ; trimmargins
= false
540 ; trimfuzz
= (0,0,0,0)
541 ; memlimit
= 32 lsl 20
546 ; bgcolor
= (0.5, 0.5, 0.5)
550 ; mustoresize
= 256 lsl 20
555 | Plinux
| Pfreebsd
| Pdragonflybsd
556 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
557 | Posx
-> "open \"%s\""
558 | Pcygwin
-> "cygstart \"%s\""
559 | Punknown
-> "echo %s")
560 ; pathlauncher
= "lp \"%s\""
563 | Plinux
| Pfreebsd
| Pdragonflybsd
564 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
572 ; redirectstderr
= false
574 ; columns
= Csingle
[||]
580 ; wheelbypage
= false
581 ; stcmd
= "echo SyncTex"
584 ; paxmark
= Mark_word
586 let mk n
= (n
, Hashtbl.create
1) in
600 let wtmode = ref false;;
601 let cxack = ref false;;
603 let findkeyhash c name
=
604 try List.assoc name c
.keyhashes
605 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
608 let conf = { defconf with angle
= defconf.angle
};;
610 let pgscale h
= truncate
(float h
*. conf.pgscale);;
613 { mutable fontsize
: int
614 ; mutable wwidth
: float
615 ; mutable maxrows
: int
627 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
628 let len = String.length s
in
629 if colonpos >= 0 && colonpos + 3 < len
631 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
634 try String.rindex_from s
colonpos ' '
638 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
641 | "http" | "ftp" | "mailto" ->
643 try String.index_from s
colonpos ' '
644 with Not_found
-> len
646 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
654 if String.length
conf.urilauncher
= 0
655 then print_endline uri
657 let url = geturl uri
in
658 if String.length
url = 0
659 then Printf.eprintf
"obtained empty url from uri %S" uri
661 let re = Str.regexp
"%s" in
662 let command = Str.global_replace
re url conf.urilauncher
in
666 "failed to execute `%s': %s\n" command (exntos exn
);
672 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
673 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
677 let strings = version () :: "" :: Help.keys
in
680 let url = geturl s
in
681 if String.length
url > 0
682 then (s
, 0, Action
(fun u
-> gotouri url; u
))
683 else (s
, 0, Noaction
)
688 let firstgeomcmds = "", [];;
689 let noreprf () = ();;
696 ; stderr
= Unix.stderr
697 ; errmsgs
= Buffer.create
0
702 ; anchor
= emptyanchor
706 ; tilelru
= Queue.create
()
707 ; pagemap
= Hashtbl.create
10
708 ; tilemap
= Hashtbl.create
10
724 ; geomcmds
= firstgeomcmds
726 { nav
= cbnew 10 emptyanchor
739 ; prevzoom
= (1.0, 0)
751 ; roam
= (fun () -> ())
757 if (conf.scrollb
land scrollbhv = 0)
758 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
764 if (conf.scrollb
land scrollbvv = 0)
769 let wadjsb w
= w
- vscrollw ();;
772 fstate.fontsize
<- n
;
773 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
774 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
780 Printf.kprintf prerr_endline fmt
782 Printf.kprintf ignore fmt
786 if String.length
conf.pathlauncher
= 0
787 then print_endline
state.path
789 let re = Str.regexp
"%s" in
790 let command = Str.global_replace
re state.path
conf.pathlauncher
in
793 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
799 type 'a t
= | Res
of 'a
| Exn
of exn
;;
802 try Res
(Unix.pipe ())
807 try tempfailureretry
Unix.close fd
808 with exn
-> f
(exntos exn
)
812 try Res
(tempfailureretry
Unix.dup fd
)
817 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
822 let redirectstderr () =
823 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
824 if conf.redirectstderr
826 match Ne.pipe () with
828 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
831 begin match Ne.dup Unix.stderr
with
833 dolog
"failed to dup stderr: %s" (exntos exn
);
834 Ne.clo r
(clofail "pipe/r");
835 Ne.clo w
(clofail "pipe/w");
837 | Ne.Res dupstderr
->
838 begin match Ne.dup2 w
Unix.stderr
with
840 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
841 Ne.clo dupstderr
(clofail "stderr duplicate");
842 Ne.clo r
(clofail "redir pipe/r");
843 Ne.clo w
(clofail "redir pipe/w");
846 state.stderr
<- dupstderr
;
847 state.errfd
<- Some r
;
851 state.newerrmsgs
<- false;
852 begin match state.errfd
with
854 begin match Ne.dup2 state.stderr
Unix.stderr
with
856 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
858 Ne.clo fd
(clofail "dup of stderr");
863 prerr_string
(Buffer.contents
state.errmsgs
);
865 Buffer.clear
state.errmsgs
;
871 let postRedisplay who
=
873 then prerr_endline
("redisplay for " ^ who
);
874 state.redisplay
<- true;
878 let getopaque pageno
=
879 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
880 with Not_found
-> None
883 let putopaque pageno opaque
=
884 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
887 let pagetranslatepoint l x y
=
888 let dy = y
- l
.pagedispy
in
889 let y = dy + l
.pagey
in
890 let dx = x
- l
.pagedispx
in
891 let x = dx + l
.pagex
in
895 let onppundermouse g
x y d
=
898 begin match getopaque l
.pageno
with
900 let x0 = l
.pagedispx
in
901 let x1 = x0 + l
.pagevw
in
902 let y0 = l
.pagedispy
in
903 let y1 = y0 + l
.pagevh
in
904 if y >= y0 && y <= y1 && x >= x0 && x <= x1
906 let px, py
= pagetranslatepoint l
x y in
907 match g opaque l
px py
with
920 let g opaque l
px py
=
923 match rectofblock opaque
px py
with
925 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
926 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
927 G.postRedisplay "rectofblock";
930 match whatsunder opaque
px py
with
932 | under
-> Some under
934 onppundermouse g x y Unone
939 match unproject opaque
x y with
940 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
943 onppundermouse g x y None
;
947 state.text
<- Printf.sprintf
"%c%s" c s
;
948 G.postRedisplay "showtext";
952 let g opaque l
px py
=
953 if markunder opaque
px py
conf.paxmark
956 match getopaque l
.pageno
with
959 match Ne.pipe () with
963 "can not create mark pipe: %s"
966 let doclose what fd
=
967 Ne.clo fd
(fun msg
->
968 dolog
"%s close failed: %s" what msg
)
971 popen conf.paxcmd
[r
, 0; w
, -1];
972 copysel w opaque
false;
974 G.postRedisplay "paxunder";
976 dolog
"can not execute %S: %s"
977 conf.paxcmd
(exntos exn
);
984 G.postRedisplay "paxunder";
986 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
990 match Ne.pipe () with
992 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
995 try popen conf.selcmd
[r
, 0; w
, -1]; true
998 (Printf.sprintf
"failed to execute %s: %s"
999 conf.selcmd
(exntos exn
));
1003 Ne.clo fd
(fun msg
->
1004 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1010 let l = String.length s
in
1011 let n = tempfailureretry
(Unix.write w s
0) l in
1016 "failed to write %d characters to sel pipe, wrote %d"
1021 (Printf.sprintf
"failed to write to sel pipe: %s"
1030 let undertext = function
1033 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1034 | Utext s
-> "font: " ^ s
1035 | Uunexpected s
-> "unexpected: " ^ s
1036 | Ulaunch s
-> "launch: " ^ s
1037 | Unamed s
-> "named: " ^ s
1038 | Uremote
(filename
, pageno
) ->
1039 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1042 let updateunder x y =
1043 match getunder x y with
1044 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1046 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1047 Wsi.setcursor
Wsi.CURSOR_INFO
1048 | Ulinkgoto
(pageno
, _
) ->
1050 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1051 Wsi.setcursor
Wsi.CURSOR_INFO
1053 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1054 Wsi.setcursor
Wsi.CURSOR_TEXT
1056 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1057 Wsi.setcursor
Wsi.CURSOR_INHERIT
1059 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1060 Wsi.setcursor
Wsi.CURSOR_INHERIT
1062 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1063 Wsi.setcursor
Wsi.CURSOR_INHERIT
1064 | Uremote
(filename
, pageno
) ->
1065 if conf.underinfo
then showtext 'r'
1066 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1067 Wsi.setcursor
Wsi.CURSOR_INFO
1070 let showlinktype under
=
1076 let s = undertext under
in
1081 let b = Buffer.create
(String.length
s + 1) in
1082 Buffer.add_string
b s;
1083 Buffer.add_char
b c
;
1087 module type TextEnumType
=
1091 val names
: string array
1094 module TextEnumMake
(Ten
: TextEnumType
) =
1096 let names = Ten.names;;
1097 let to_int (t
: Ten.t
) = Obj.magic t
;;
1098 let to_string t
= names.(to_int t
);;
1099 let of_int n : Ten.t
= Obj.magic
n;;
1102 if i
= Array.length
names
1103 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1105 if Ten.names.(i
) = s
1112 module CSTE
= TextEnumMake
(struct
1113 type t
= colorspace
;;
1114 let name = "colorspace";;
1115 let names = [|"rgb"; "bgr"; "gray"|];;
1118 module MTE
= TextEnumMake
(struct
1121 let names = [|"page"; "block"; "line"; "word"|];;
1124 module FMTE
= TextEnumMake
(struct
1126 let name = "fitmodel";;
1127 let names = [|"width"; "proportional"; "page"|];;
1130 let intentry_with_suffix text key
=
1132 if key
>= 32 && key
< 127
1136 match Char.lowercase
c with
1138 let text = addchar text c in
1141 | 'k'
| 'm'
| '
g'
->
1142 let text = addchar text c in
1146 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1150 let multicolumns_to_string (n, a
, b) =
1152 then Printf.sprintf
"%d" n
1153 else Printf.sprintf
"%d,%d,%d" n a
b;
1156 let multicolumns_of_string s =
1158 (int_of_string
s, 0, 0)
1160 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1162 then failwith
"subtly broken"; (n, a
, b)
1168 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1169 if n != 4 then failwith
"incomplete read(len)";
1171 lor (Char.code
s.[0] lsl 24)
1172 lor (Char.code
s.[1] lsl 16)
1173 lor (Char.code
s.[2] lsl 8)
1174 lor (Char.code
s.[3] lsl 0)
1176 let s = String.create
len in
1177 let n = tempfailureretry
(Unix.read fd
s 0) len in
1178 if n != len then failwith
"incomplete read(data)";
1182 let btod b = if b then 1 else 0;;
1185 let b = Buffer.create
16 in
1186 Buffer.add_string
b "llll";
1189 let s = Buffer.contents
b in
1190 let n = String.length
s in
1192 (* dolog "wcmd %S" (String.sub s 4 len); *)
1193 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1194 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1195 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1196 s.[3] <- Char.chr
(len land 0xff);
1197 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1198 if n'
!= n then failwith
"write failed";
1203 let d = state.winh
- h
in
1204 max
conf.interpagespace
((d + 1) / 2)
1207 let rowyh (c, coverA
, coverB
) b n =
1208 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1210 let _, _, vy
, (_, _, h
, _) = b.(n) in
1213 let n'
= n - coverA
in
1216 let e = min
state.pagecount
(s + c) in
1217 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1218 let _, _, y, (_, _, h
, _) = b.(m
) in
1219 let miny = min
miny y in
1220 let maxh = max
maxh h
in
1221 find (m
+1) miny maxh
1226 match conf.columns
with
1227 | Cmulti
((_, _, _) as cl
, b) ->
1228 if Array.length
b > 0
1230 let y, h
= rowyh cl
b (Array.length
b - 1) in
1231 y + h
+ (if conf.presentation
then calcips h
else 0)
1234 if Array.length
b > 0
1236 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1237 y + h
+ (if conf.presentation
then calcips h
else 0)
1240 if Array.length
b > 0
1242 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1247 let getpageyh pageno
=
1248 let pageno = bound pageno 0 (state.pagecount
-1) in
1249 match conf.columns
with
1251 if Array.length
b = 0
1254 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1256 if conf.presentation
1262 if Array.length
b = 0
1265 let y, h
= rowyh cl
b pageno in
1267 if conf.presentation
1273 if Array.length
b = 0
1277 let (_, _, y, (_, _, h
, _)) = b.(n) in
1281 let getpagedim pageno =
1284 | (n, _, _, _) as pdim
:: rest
->
1286 then (if n = pageno then pdim
else ppdim
)
1291 f (-1, -1, -1, -1) state.pdims
1294 let getpagey pageno = fst
(getpageyh pageno);;
1296 let nogeomcmds cmds
=
1298 | s, [] -> String.length
s = 0
1303 let ((c, coverA
, coverB
) as cl
), b =
1304 match conf.columns
with
1305 | Csingle
b -> (1, 0, 0), b
1306 | Cmulti
(c, b) -> c, b
1307 | Csplit
(_, b) -> (1, 0, 0), b
1309 if Array.length
b = 0
1312 let rec bsearch nmin nmax
=
1314 then bound nmin
0 (state.pagecount
-1)
1316 let n = (nmax
+ nmin
) / 2 in
1317 let vy, h
= rowyh cl
b n in
1319 if conf.presentation
1321 let ips = calcips h
in
1322 let y0 = vy - ips in
1323 let y1 = vy + h
+ ips in
1327 then 0, vy + h
+ conf.interpagespace
1329 let y0 = vy - conf.interpagespace
in
1330 y0, y0 + h
+ conf.interpagespace
1333 if y >= y0 && y < y1
1340 if n < state.pagecount
- coverB
1341 then ((n-coverA
)/c)*c + coverA
1348 then bsearch (n+1) nmax
1349 else bsearch nmin
(n-1)
1352 let r = bsearch 0 (state.pagecount
-1) in
1356 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1357 let sh = sh - (hscrollh ()) in
1358 let rec fold accu
n =
1359 if n = Array.length
b
1362 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1365 || n = state.pagecount
- coverB
1366 || (n - coverA
) mod columns
= columns
- 1)
1372 let pagey = max
0 (y - vy) in
1373 let pagedispy = if pagey > 0 then 0 else vy - y in
1374 let pagedispx, pagex
=
1376 if n = coverA
- 1 || n = state.pagecount
- coverB
1377 then state.x + (wadjsb state.winw
- w
) / 2
1378 else dx + xoff
+ state.x
1385 let vw = wadjsb state.winw
- pagedispx in
1386 let pw = w
- pagex
in
1389 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1390 if pagevw > 0 && pagevh > 0
1394 ; pagedimno
= pdimno
1401 ; pagedispx = pagedispx
1402 ; pagedispy = pagedispy
1414 if Array.length
b = 0
1416 else List.rev
(fold [] (page_of_y y))
1419 let layoutS (columns
, b) y sh =
1420 let sh = sh - hscrollh () in
1421 let rec fold accu n =
1422 if n = Array.length
b
1425 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1432 let x = xoff
+ state.x in
1433 let pagey = max
0 (y - vy) in
1434 let pagedispy = if pagey > 0 then 0 else vy - y in
1435 let pagedispx, pagex
=
1449 let pagecolw = pagew
/columns
in
1451 if pagecolw < state.winw
1452 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1456 let vw = wadjsb state.winw
- pagedispx in
1457 let pw = pagew
- pagex
in
1460 let pagevw = min
pagevw pagecolw in
1461 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1462 if pagevw > 0 && pagevh > 0
1465 { pageno = n/columns
1466 ; pagedimno
= pdimno
1473 ; pagedispx = pagedispx
1474 ; pagedispy = pagedispy
1475 ; pagecol
= n mod columns
1486 List.rev
(fold [] 0)
1490 if nogeomcmds state.geomcmds
1492 match conf.columns
with
1493 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1494 | Cmulti
c -> layoutN c y sh
1495 | Csplit
s -> layoutS s y sh
1500 let y = state.y + incr
in
1502 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1507 let tilex = l.pagex
mod conf.tilew
in
1508 let tiley = l.pagey mod conf.tileh
in
1510 let col = l.pagex
/ conf.tilew
in
1511 let row = l.pagey / conf.tileh
in
1513 let rec rowloop row y0 dispy h
=
1517 let dh = conf.tileh
- y0 in
1518 let dh = min h
dh in
1519 let rec colloop col x0 dispx w
=
1523 let dw = conf.tilew
- x0 in
1524 let dw = min w
dw in
1526 f col row dispx dispy
x0 y0 dw dh;
1527 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1530 colloop col tilex l.pagedispx l.pagevw;
1531 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1534 if l.pagevw > 0 && l.pagevh > 0
1535 then rowloop row tiley l.pagedispy l.pagevh;
1538 let gettileopaque l col row =
1540 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1542 try Some
(Hashtbl.find state.tilemap
key)
1543 with Not_found
-> None
1546 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1547 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1548 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1551 let drawtiles l color
=
1553 let f col row x y tilex tiley w h
=
1554 match gettileopaque l col row with
1555 | Some
(opaque
, _, t
) ->
1556 let params = x, y, w
, h
, tilex, tiley in
1560 GlFunc.blend_func `zero `one_minus_src_color
;
1562 drawtile
params opaque
;
1564 then Gl.disable `blend
;
1567 let s = Printf.sprintf
1571 let w = measurestr
fstate.fontsize
s in
1572 GlMisc.push_attrib
[`current
];
1573 GlDraw.color
(0.0, 0.0, 0.0);
1575 (float (x-2), float (y-2))
1576 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1577 GlDraw.color
(1.0, 1.0, 1.0);
1578 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1579 GlMisc.pop_attrib
();
1584 let lw = wadjsb state.winw
- x in
1587 let lh = state.winh
- y in
1590 begin match state.texid
with
1592 Gl.enable `texture_2d
;
1593 GlTex.bind_texture `texture_2d id
;
1596 and x1 = float (x+w)
1597 and y1 = float (y+h
) in
1599 let tw = float w /. 16.0
1600 and th
= float h
/. 16.0 in
1601 let tx0 = float tilex /. 16.0
1602 and ty0
= float tiley /. 16.0 in
1604 and ty1
= ty0
+. th
in
1605 GlDraw.begins `quads
;
1606 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1607 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1608 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1609 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1612 Gl.disable `texture_2d
;
1614 GlDraw.color
(1.0, 1.0, 1.0);
1617 (float (x+w), float (y+h
));
1619 if w > 128 && h
> fstate.fontsize
+ 10
1621 GlDraw.color
(0.0, 0.0, 0.0);
1624 then (col*conf.tilew
, row*conf.tileh
)
1627 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1634 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1636 let tilevisible1 l x y =
1638 and ax1
= l.pagex
+ l.pagevw
1640 and ay1
= l.pagey + l.pagevh in
1644 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1645 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1647 let rx0 = max
ax0 bx0
1648 and ry0
= max ay0 by0
1649 and rx1
= min ax1
bx1
1650 and ry1
= min ay1 by1
in
1652 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1653 nonemptyintersection
1656 let tilevisible layout n x y =
1657 let rec findpageinlayout m
= function
1658 | l :: rest
when l.pageno = n ->
1659 tilevisible1 l x y || (
1660 match conf.columns
with
1661 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1664 | _ :: rest
-> findpageinlayout 0 rest
1667 findpageinlayout 0 layout;
1670 let tileready l x y =
1671 tilevisible1 l x y &&
1672 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1675 let tilepage n p
layout =
1676 let rec loop = function
1680 let f col row _ _ _ _ _ _ =
1681 if state.currently
= Idle
1683 match gettileopaque l col row with
1686 let x = col*conf.tilew
1687 and y = row*conf.tileh
in
1689 let w = l.pagew
- x in
1693 let h = l.pageh
- y in
1698 then getpbo
w h conf.colorspace
1701 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1704 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1705 conf.tilew
, conf.tileh
1714 if nogeomcmds state.geomcmds
1718 let preloadlayout y =
1719 let y = if y < state.winh
then 0 else y - state.winh
in
1720 let h = state.winh
*3 in
1725 let rec loop pages
=
1726 if state.currently
!= Idle
1731 begin match getopaque l.pageno with
1733 wcmd "page %d %d" l.pageno l.pagedimno
;
1734 state.currently
<- Loading
(l, state.gen
);
1736 tilepage l.pageno opaque pages
;
1741 if nogeomcmds state.geomcmds
1747 if conf.preload && state.currently
= Idle
1748 then load (preloadlayout state.y);
1751 let layoutready layout =
1752 let rec fold all ls
=
1753 all
&& match ls
with
1755 let seen = ref false in
1756 let allvisible = ref true in
1757 let foo col row _ _ _ _ _ _ =
1759 allvisible := !allvisible &&
1760 begin match gettileopaque l col row with
1766 fold (!seen && !allvisible) rest
1769 let alltilesvisible = fold true layout in
1774 let y = bound y 0 state.maxy
in
1775 let y, layout, proceed
=
1776 match conf.maxwait
with
1777 | Some time
when state.ghyll
== noghyll ->
1778 begin match state.throttle
with
1780 let layout = layout y state.winh
in
1781 let ready = layoutready layout in
1785 state.throttle
<- Some
(layout, y, now ());
1787 else G.postRedisplay "gotoy showall (None)";
1789 | Some
(_, _, started
) ->
1790 let dt = now () -. started
in
1793 state.throttle
<- None
;
1794 let layout = layout y state.winh
in
1796 G.postRedisplay "maxwait";
1803 let layout = layout y state.winh
in
1804 if not
!wtmode || layoutready layout
1805 then G.postRedisplay "gotoy ready";
1811 state.layout <- layout;
1812 begin match state.mode
with
1813 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1814 let rec loop = function
1816 state.mode
<- LinkNav
(Ltgendir
0)
1817 | l :: _ when l.pageno = pageno ->
1818 begin match getopaque pageno with
1820 state.mode
<- LinkNav
(Ltgendir
0)
1822 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1823 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1824 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1825 then state.mode
<- LinkNav
(Ltgendir
0)
1827 | _ :: rest
-> loop rest
1832 begin match state.mode
with
1833 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1834 if not
(pagevisible layout pageno)
1836 match state.layout with
1839 state.mode
<- Birdseye
(
1840 conf, leftx
, l.pageno, hooverpageno
, anchor
1843 | LinkNav
(Ltgendir dir
as lt
) ->
1845 let rec loop = function
1848 match getopaque l.pageno with
1854 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1856 if dir
> 0 then LDfirst
else LDlast
1862 | Lnotfound
-> loop rest
1864 showlinktype (getlink opaque
n);
1865 Ltexact
(l.pageno, n)
1869 state.mode
<- LinkNav
linknav
1874 state.ghyll
<- noghyll;
1877 let mx, my
= state.mpos
in
1882 let conttiling pageno opaque
=
1883 tilepage pageno opaque
1884 (if conf.preload then preloadlayout state.y else state.layout)
1887 let gotoy_and_clear_text y =
1888 if not
conf.verbose
then state.text <- "";
1894 let coloff = l.pagecol
* l.pageh
in
1895 float (l.pagey + coloff) /. float l.pageh
1902 if conf.presentation
1903 then float l.pagedispy /. float (calcips l.pageh
)
1904 else float l.pagedispy /. float conf.interpagespace
1907 (l.pageno, top, dtop)
1911 match state.layout with
1912 | l :: _ -> getanchor1 l
1914 let n = page_of_y state.y in
1918 let y, h = getpageyh n in
1919 let dy = y - state.y in
1921 if conf.presentation
1923 let ips = calcips h in
1924 float (dy + ips) /. float ips
1926 float dy /. float conf.interpagespace
1931 let getanchory (n, top, dtop) =
1932 let y, h = getpageyh n in
1933 if conf.presentation
1935 let ips = calcips h in
1936 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1938 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1941 let gotoanchor anchor
=
1942 gotoy (getanchory anchor
);
1946 cbput state.hists
.nav
(getanchor ());
1950 let anchor = cbgetc state.hists
.nav dir
in
1955 let scroll f n a
b =
1956 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1958 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1960 then s (float f /. float a
)
1963 then 1.0 -. s ((float (f-b) /. float (n-b)))
1969 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1970 let iv x = x**3.-.0.5*.x**4. in
1972 let ins = float a
*. iv1
1973 and outs
= float (n-b) *. iv1 in
1975 ins +. outs
+. float ones
1977 let rec set (_N
, _A
, _B
) y sy
=
1978 let sum = summa
1.0 _N _A _B
in
1979 let dy = float (y - sy
) in
1983 then state.ghyll
<- noghyll
1986 let s = scroll n _N _A _B
in
1987 let y1 = y1 +. ((s *. dy) /. sum) in
1988 gotoy_and_clear_text (truncate
y1);
1989 state.ghyll
<- gf (n+1) y1;
1993 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1995 gf 0 (float state.y)
1998 match conf.ghyllscroll
with
2000 gotoy_and_clear_text y
2002 if state.ghyll
== noghyll
2003 then set nab
y state.y
2004 else state.ghyll
(Some
y)
2007 let gotopage n top =
2008 let y, h = getpageyh n in
2009 let y = y + (truncate
(top *. float h)) in
2013 let gotopage1 n top =
2014 let y = getpagey n in
2019 let invalidate s f =
2024 match state.geomcmds
with
2025 | ps
, [] when String.length ps
= 0 ->
2027 state.geomcmds
<- s, [];
2030 state.geomcmds
<- ps
, [s, f];
2032 | ps
, (s'
, _) :: rest
when s'
= s ->
2033 state.geomcmds
<- ps
, ((s, f) :: rest
);
2036 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2040 Hashtbl.iter
(fun _ opaque
->
2041 wcmd "freepage %s" opaque
;
2043 Hashtbl.clear
state.pagemap
;
2047 if not
(Queue.is_empty
state.tilelru
)
2049 Queue.iter
(fun (k
, p
, s) ->
2050 wcmd "freetile %s" p
;
2051 state.memused
<- state.memused
- s;
2052 Hashtbl.remove
state.tilemap k
;
2054 state.uioh#infochanged Memused
;
2055 Queue.clear
state.tilelru
;
2061 let h = truncate
(float h*.conf.zoom
) in
2062 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2066 let opendoc path password
=
2068 state.password
<- password
;
2069 state.gen
<- state.gen
+ 1;
2070 state.docinfo
<- [];
2073 setaalevel
conf.aalevel
;
2075 if String.length
state.origin
= 0
2079 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2080 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2081 invalidate "reqlayout"
2083 wcmd "reqlayout %d %d %d %s\000"
2084 conf.angle
(FMTE.to_int conf.fitmodel
)
2085 (stateh state.winh
) state.nameddest
2090 state.anchor <- getanchor ();
2091 opendoc state.path
state.password
;
2095 let c = c *. conf.colorscale
in
2099 let scalecolor2 (r, g, b) =
2100 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2103 let docolumns = function
2105 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2106 let rec loop pageno pdimno pdim
y ph pdims
=
2107 if pageno = state.pagecount
2110 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2112 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2113 pdimno+1, pdim
, rest
2117 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2119 (if conf.presentation
2120 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2121 else (if pageno = 0 then 0 else conf.interpagespace
)
2124 a.(pageno) <- (pdimno, x, y, pdim
);
2125 loop (pageno+1) pdimno pdim
(y + h) h pdims
2127 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2128 conf.columns
<- Csingle
a;
2130 | Cmulti
((columns
, coverA
, coverB
), _) ->
2131 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2132 let rec loop pageno pdimno pdim
x y rowh pdims
=
2133 let rec fixrow m
= if m
= pageno then () else
2134 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2137 let y = y + (rowh
- h) / 2 in
2138 a.(m
) <- (pdimno, x, y, pdim
);
2142 if pageno = state.pagecount
2143 then fixrow (((pageno - 1) / columns
) * columns
)
2145 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2147 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2148 pdimno+1, pdim
, rest
2153 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2155 let x = (wadjsb state.winw
- w) / 2 in
2157 if conf.presentation
then calcips h else conf.interpagespace
in
2158 x, y + ips + rowh
, h
2161 if (pageno - coverA
) mod columns
= 0
2163 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2165 if conf.presentation
2167 let ips = calcips h in
2168 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2170 y + (if pageno = 0 then 0 else conf.interpagespace
)
2174 else x, y, max rowh
h
2178 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2181 if pageno = columns
&& conf.presentation
2183 let ips = calcips rowh
in
2184 for i
= 0 to pred columns
2186 let (pdimno, x, y, pdim
) = a.(i
) in
2187 a.(i
) <- (pdimno, x, y+ips, pdim
)
2193 fixrow (pageno - columns
);
2198 a.(pageno) <- (pdimno, x, y, pdim
);
2199 let x = x + w + xoff
*2 + conf.interpagespace
in
2200 loop (pageno+1) pdimno pdim
x y rowh' pdims
2202 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2203 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2206 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2207 let rec loop pageno pdimno pdim
y pdims
=
2208 if pageno = state.pagecount
2211 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2213 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2214 pdimno+1, pdim
, rest
2219 let rec loop1 n x y =
2220 if n = c then y else (
2221 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2222 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2225 let y = loop1 0 0 y in
2226 loop (pageno+1) pdimno pdim
y pdims
2228 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2229 conf.columns
<- Csplit
(c, a);
2233 docolumns conf.columns
;
2234 state.maxy
<- calcheight ();
2235 if state.reprf
== noreprf
2237 match state.mode
with
2238 | Birdseye
(_, _, pageno, _, _) ->
2239 let y, h = getpageyh pageno in
2240 let top = (state.winh
- h) / 2 in
2241 gotoy (max
0 (y - top))
2242 | _ -> gotoanchor state.anchor
2246 state.reprf
<- noreprf;
2251 GlDraw.viewport
0 0 w h;
2252 let firsttime = state.geomcmds
== firstgeomcmds in
2253 if not
firsttime && nogeomcmds state.geomcmds
2254 then state.anchor <- getanchor ();
2257 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2260 setfontsize fstate.fontsize
;
2261 GlMat.mode `modelview
;
2262 GlMat.load_identity
();
2264 GlMat.mode `projection
;
2265 GlMat.load_identity
();
2266 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2267 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2268 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2273 else float state.x /. float state.w
2275 invalidate "geometry"
2279 then state.x <- truncate
(relx *. float w);
2281 match conf.columns
with
2283 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2284 | Csplit
(c, _) -> w * c
2286 wcmd "geometry %d %d %d"
2287 w (stateh h) (FMTE.to_int conf.fitmodel
)
2292 let len = String.length
state.text in
2295 match state.mode
with
2296 | Textentry
_ | View
| LinkNav
_ ->
2297 let h, _, _ = state.uioh#scrollpw
in
2303 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2304 (x+.w, float (state.winh
- hscrollh))
2307 let w = float (wadjsb state.winw
- 1) in
2308 if state.progress
>= 0.0 && state.progress
< 1.0
2310 GlDraw.color
(0.3, 0.3, 0.3);
2311 let w1 = w *. state.progress
in
2313 GlDraw.color
(0.0, 0.0, 0.0);
2317 GlDraw.color
(0.0, 0.0, 0.0);
2321 GlDraw.color
(1.0, 1.0, 1.0);
2322 drawstring fstate.fontsize
2323 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2326 match state.mode
with
2327 | Textentry
((prefix
, text, _, _, _, _), _) ->
2331 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2333 Printf.sprintf
"%s%s_" prefix
text
2342 if not
(istextentry state.mode
) && state.uioh#eformsgs
2344 let s1 = "(press 'e' to review error messasges)" in
2345 if String.length
s > 0 then s ^
" " ^
s1 else s1
2350 if String.length
s > 0
2355 let len = Queue.length
state.tilelru
in
2357 match state.throttle
with
2360 then preloadlayout state.y
2362 | Some
(layout, _, _) ->
2366 if state.memused
<= conf.memlimit
2371 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2372 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2373 let (_, pw, ph
, _) = getpagedim n in
2376 && colorspace
= conf.colorspace
2377 && angle
= conf.angle
2381 let x = col*conf.tilew
2382 and y = row*conf.tileh
in
2383 tilevisible (Lazy.force_val
layout) n x y
2385 then Queue.push lruitem
state.tilelru
2388 wcmd "freetile %s" p
;
2389 state.memused
<- state.memused
- s;
2390 state.uioh#infochanged Memused
;
2391 Hashtbl.remove
state.tilemap k
;
2399 let logcurrently = function
2400 | Idle
-> dolog
"Idle"
2401 | Loading
(l, gen
) ->
2402 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2403 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2405 "Tiling %d[%d,%d] page=%s cs=%s angle"
2406 l.pageno col row pageopaque
2407 (CSTE.to_string colorspace
)
2409 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2410 angle gen
conf.angle
state.gen
2412 conf.tilew
conf.tileh
2419 let r = Str.regexp
" " in
2420 fun s -> Str.bounded_split
r s 2;
2423 let onpagerect pageno f =
2425 match conf.columns
with
2426 | Cmulti
(_, b) -> b
2428 | Csplit
(_, b) -> b
2430 if pageno >= 0 && pageno < Array.length
b
2432 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2433 let r = getpdimrect
pdimno in
2434 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2437 let gotopagexy1 pageno x y =
2438 onpagerect pageno (fun w h ->
2440 let _,w1,_,leftx
= getpagedim pageno in
2441 let wh = state.winh
- hscrollh () in
2442 let sw = float w1 /. w in
2444 let x = leftx
+ state.x + truncate
x in
2446 if x < 0 || x >= wadjsb state.winw
2450 let py, h = getpageyh pageno in
2451 let pdy = truncate
(top *. float h) in
2452 let y'
= py + pdy in
2453 let dy = y'
- state.y in
2455 if x != state.x || not
(dy > 0 && dy < wh)
2457 if conf.presentation
2459 if abs
(py - y'
) > wh
2466 if state.x != sx || state.y != sy
2471 let ww = wadjsb state.winw
in
2473 and qy
= pdy / wh in
2475 and y = py + qy
* wh in
2476 let x = if -x + ww > w1 then -(w1-ww) else x
2477 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2479 if conf.presentation
2481 if abs
(py - y'
) > wh
2491 gotoy_and_clear_text y;
2493 else gotoy_and_clear_text state.y;
2497 let gotopagexy pageno x y =
2498 match state.mode
with
2499 | Birdseye
_ -> gotopage pageno 0.0
2500 | _ -> gotopagexy1 pageno x y
2504 (* dolog "%S" cmds; *)
2505 let cl = splitatspace cmds
in
2507 try Scanf.sscanf
s fmt
f
2509 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2514 state.uioh#infochanged Pdim
;
2517 | "clearrects" :: [] ->
2518 state.rects
<- state.rects1
;
2519 G.postRedisplay "clearrects";
2521 | "continue" :: args :: [] ->
2522 let n = scan args "%u" (fun n -> n) in
2523 state.pagecount
<- n;
2524 begin match state.currently
with
2526 state.currently
<- Idle
;
2527 state.outlines
<- Array.of_list
(List.rev
l)
2531 let cur, cmds
= state.geomcmds
in
2532 if String.length
cur = 0
2533 then failwith
"umpossible";
2535 begin match List.rev cmds
with
2537 state.geomcmds
<- "", [];
2541 state.geomcmds
<- s, List.rev rest
;
2543 if conf.maxwait
= None
&& not
!wtmode
2544 then G.postRedisplay "continue";
2546 | "title" :: args :: [] ->
2549 | "msg" :: args :: [] ->
2552 | "vmsg" :: args :: [] ->
2554 then showtext ' '
args
2556 | "emsg" :: args :: [] ->
2557 Buffer.add_string
state.errmsgs
args;
2558 state.newerrmsgs
<- true;
2559 G.postRedisplay "error message"
2561 | "progress" :: args :: [] ->
2562 let progress, text =
2565 f, String.sub
args pos
(String.length
args - pos
))
2568 state.progress <- progress;
2569 G.postRedisplay "progress"
2571 | "firstmatch" :: args :: [] ->
2572 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2573 scan args "%u %d %f %f %f %f %f %f %f %f"
2574 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2575 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2577 let y = (getpagey pageno) + truncate
y0 in
2580 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2582 | "match" :: args :: [] ->
2583 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2584 scan args "%u %d %f %f %f %f %f %f %f %f"
2585 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2586 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2589 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2591 | "page" :: args :: [] ->
2592 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2593 begin match state.currently
with
2594 | Loading
(l, gen
) ->
2595 vlog "page %d took %f sec" l.pageno t
;
2596 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2597 begin match state.throttle
with
2599 let preloadedpages =
2601 then preloadlayout state.y
2606 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2607 IntSet.empty
preloadedpages
2610 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2611 if not
(IntSet.mem
pageno set)
2613 wcmd "freepage %s" opaque
;
2619 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2622 state.currently
<- Idle
;
2625 tilepage l.pageno pageopaque state.layout;
2627 load preloadedpages;
2628 if pagevisible state.layout l.pageno
2629 && layoutready state.layout
2630 then G.postRedisplay "page";
2633 | Some
(layout, _, _) ->
2634 state.currently
<- Idle
;
2635 tilepage l.pageno pageopaque layout;
2640 dolog
"Inconsistent loading state";
2641 logcurrently state.currently
;
2645 | "tile" :: args :: [] ->
2646 let (x, y, opaque
, size
, t
) =
2647 scan args "%u %u %s %u %f"
2648 (fun x y p size t
-> (x, y, p
, size
, t
))
2650 begin match state.currently
with
2651 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2652 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2655 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2657 wcmd "freetile %s" opaque
;
2658 state.currently
<- Idle
;
2662 puttileopaque l col row gen cs angle opaque size t
;
2663 state.memused
<- state.memused
+ size
;
2664 state.uioh#infochanged Memused
;
2666 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2667 opaque
, size
) state.tilelru
;
2670 match state.throttle
with
2671 | None
-> state.layout
2672 | Some
(layout, _, _) -> layout
2675 state.currently
<- Idle
;
2677 && conf.colorspace
= cs
2678 && conf.angle
= angle
2679 && tilevisible layout l.pageno x y
2680 then conttiling l.pageno pageopaque;
2682 begin match state.throttle
with
2684 preload state.layout;
2686 && conf.colorspace
= cs
2687 && conf.angle
= angle
2688 && tilevisible state.layout l.pageno x y
2689 && (not
!wtmode || layoutready state.layout)
2690 then G.postRedisplay "tile nothrottle";
2692 | Some
(layout, y, _) ->
2693 let ready = layoutready layout in
2697 state.layout <- layout;
2698 state.throttle
<- None
;
2699 G.postRedisplay "throttle";
2706 dolog
"Inconsistent tiling state";
2707 logcurrently state.currently
;
2711 | "pdim" :: args :: [] ->
2712 let (n, w, h, _) as pdim
=
2713 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2716 match conf.fitmodel
, conf.columns
with
2717 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2720 state.uioh#infochanged Pdim
;
2721 state.pdims
<- pdim :: state.pdims
2723 | "o" :: args :: [] ->
2724 let (l, n, t
, h, pos
) =
2725 scan args "%u %u %d %u %n"
2726 (fun l n t
h pos
-> l, n, t
, h, pos
)
2728 let s = String.sub
args pos
(String.length
args - pos
) in
2729 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2730 begin match state.currently
with
2731 | Outlining outlines
->
2732 state.currently
<- Outlining
(outline :: outlines
)
2734 state.currently
<- Outlining
[outline]
2736 dolog
"invalid outlining state";
2737 logcurrently currently
2740 | "a" :: args :: [] ->
2742 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2744 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2746 | "info" :: args :: [] ->
2747 state.docinfo
<- (1, args) :: state.docinfo
2749 | "infoend" :: [] ->
2750 state.uioh#infochanged Docinfo
;
2751 state.docinfo
<- List.rev
state.docinfo
2754 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2759 let action = function
2760 | HCprev
-> cbget cb ~
-1
2761 | HCnext
-> cbget cb
1
2762 | HCfirst
-> cbget cb ~
-(cb
.rc)
2763 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2764 and cancel
() = cb
.rc <- rc
2768 let search pattern forward
=
2769 match conf.columns
with
2771 showtext '
!'
"searching does not work properly in split columns mode"
2773 if String.length pattern
> 0
2776 match state.layout with
2779 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2781 wcmd "search %d %d %d %d,%s\000"
2782 (btod conf.icase
) pn py (btod forward
) pattern
;
2785 let intentry text key =
2787 if key >= 32 && key < 127
2793 let text = addchar text c in
2797 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2801 let linknentry text key =
2803 if key >= 32 && key < 127
2809 let text = addchar text c in
2813 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2818 if String.length
s > 0
2821 let l = String.length
s in
2822 let rec loop pos
n = if pos
= l then n else
2823 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2824 loop (pos
+1) (n*26 + m)
2827 let rec loop n = function
2830 match getopaque l.pageno with
2831 | None
-> loop n rest
2833 let m = getlinkcount opaque
in
2836 let under = getlink opaque
n in
2839 else loop (n-m) rest
2841 loop n state.layout;
2845 let textentry text key =
2846 if key land 0xff00 = 0xff00
2848 else TEcont
(text ^ toutf8
key)
2851 let reqlayout angle fitmodel
=
2852 match state.throttle
with
2854 if nogeomcmds state.geomcmds
2855 then state.anchor <- getanchor ();
2856 conf.angle
<- angle
mod 360;
2859 match state.mode
with
2860 | LinkNav
_ -> state.mode
<- View
2863 conf.fitmodel
<- fitmodel
;
2864 invalidate "reqlayout"
2866 wcmd "reqlayout %d %d %d"
2867 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2872 let settrim trimmargins trimfuzz
=
2873 if nogeomcmds state.geomcmds
2874 then state.anchor <- getanchor ();
2875 conf.trimmargins
<- trimmargins
;
2876 conf.trimfuzz
<- trimfuzz
;
2877 let x0, y0, x1, y1 = trimfuzz
in
2878 invalidate "settrim"
2880 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2885 match state.throttle
with
2887 let zoom = max
0.0001 zoom in
2888 if zoom <> conf.zoom
2890 state.prevzoom
<- (conf.zoom, state.x);
2892 reshape state.winw
state.winh
;
2893 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2896 | Some
(layout, y, started
) ->
2898 match conf.maxwait
with
2902 let dt = now () -. started
in
2910 let setcolumns mode columns coverA coverB
=
2911 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2915 then showtext '
!'
"split mode doesn't work in bird's eye"
2917 conf.columns
<- Csplit
(-columns
, [||]);
2925 conf.columns
<- Csingle
[||];
2930 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2934 reshape state.winw
state.winh
;
2937 let enterbirdseye () =
2938 let zoom = float conf.thumbw
/. float state.winw
in
2939 let birdseyepageno =
2940 let cy = state.winh
/ 2 in
2944 let rec fold best
= function
2947 let d = cy - (l.pagedispy + l.pagevh/2)
2948 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2949 if abs
d < abs dbest
2956 state.mode
<- Birdseye
(
2957 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2960 conf.presentation
<- false;
2961 conf.interpagespace
<- 10;
2962 conf.hlinks
<- false;
2963 conf.fitmodel
<- FitProportional
;
2965 state.mstate
<- Mnone
;
2966 conf.maxwait
<- None
;
2968 match conf.beyecolumns
with
2971 Cmulti
((c, 0, 0), [||])
2972 | None
-> Csingle
[||]
2974 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2977 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2982 reshape state.winw
state.winh
;
2985 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2987 conf.zoom <- c.zoom;
2988 conf.presentation
<- c.presentation
;
2989 conf.interpagespace
<- c.interpagespace
;
2990 conf.maxwait
<- c.maxwait
;
2991 conf.hlinks
<- c.hlinks
;
2992 conf.fitmodel
<- c.fitmodel
;
2993 conf.beyecolumns
<- (
2994 match conf.columns
with
2995 | Cmulti
((c, _, _), _) -> Some
c
2997 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3000 match c.columns
with
3001 | Cmulti
(c, _) -> Cmulti
(c, [||])
3002 | Csingle
_ -> Csingle
[||]
3003 | Csplit
(c, _) -> Csplit
(c, [||])
3008 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3011 reshape state.winw
state.winh
;
3012 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3015 let togglebirdseye () =
3016 match state.mode
with
3017 | Birdseye vals
-> leavebirdseye vals
true
3018 | View
-> enterbirdseye ()
3022 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3023 let pageno = max
0 (pageno - incr
) in
3024 let rec loop = function
3025 | [] -> gotopage1 pageno 0
3026 | l :: _ when l.pageno = pageno ->
3027 if l.pagedispy >= 0 && l.pagey = 0
3028 then G.postRedisplay "upbirdseye"
3029 else gotopage1 pageno 0
3030 | _ :: rest
-> loop rest
3033 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3036 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3037 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3038 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3039 let rec loop = function
3041 let y, h = getpageyh pageno in
3042 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3044 | l :: _ when l.pageno = pageno ->
3045 if l.pagevh != l.pageh
3046 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3047 else G.postRedisplay "downbirdseye"
3048 | _ :: rest
-> loop rest
3053 let optentry mode
_ key =
3054 let btos b = if b then "on" else "off" in
3055 if key >= 32 && key < 127
3057 let c = Char.chr
key in
3061 try conf.scrollstep
<- int_of_string
s with exc
->
3062 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3064 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3069 conf.autoscrollstep
<- int_of_string
s;
3070 if state.autoscroll
<> None
3071 then state.autoscroll
<- Some
conf.autoscrollstep
3073 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3075 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3080 let n, a, b = multicolumns_of_string s in
3081 setcolumns mode
n a b;
3083 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3085 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3090 let zoom = float (int_of_string
s) /. 100.0 in
3093 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3095 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3100 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3102 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3103 begin match mode
with
3105 leavebirdseye beye
false;
3110 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3112 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3117 Some
(int_of_string
s)
3119 state.text <- Printf.sprintf
"bad integer `%s': %s"
3123 | Some angle
-> reqlayout angle
conf.fitmodel
3126 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3129 conf.icase
<- not
conf.icase
;
3130 TEdone
("case insensitive search " ^
(btos conf.icase
))
3133 conf.preload <- not
conf.preload;
3135 TEdone
("preload " ^
(btos conf.preload))
3138 conf.verbose
<- not
conf.verbose
;
3139 TEdone
("verbose " ^
(btos conf.verbose
))
3142 conf.debug
<- not
conf.debug
;
3143 TEdone
("debug " ^
(btos conf.debug
))
3146 conf.maxhfit
<- not
conf.maxhfit
;
3147 state.maxy
<- calcheight ();
3148 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3151 conf.crophack
<- not
conf.crophack
;
3152 TEdone
("crophack " ^
btos conf.crophack
)
3156 match conf.maxwait
with
3158 conf.maxwait
<- Some infinity
;
3159 "always wait for page to complete"
3161 conf.maxwait
<- None
;
3162 "show placeholder if page is not ready"
3167 conf.underinfo
<- not
conf.underinfo
;
3168 TEdone
("underinfo " ^
btos conf.underinfo
)
3171 conf.savebmarks
<- not
conf.savebmarks
;
3172 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3178 match state.layout with
3183 conf.interpagespace
<- int_of_string
s;
3184 docolumns conf.columns
;
3185 state.maxy
<- calcheight ();
3186 let y = getpagey pageno in
3189 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3191 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3195 match conf.fitmodel
with
3196 | FitProportional
-> FitWidth
3197 | _ -> FitProportional
3199 reqlayout conf.angle
fm;
3200 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3203 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3204 TEdone
("trim margins " ^
btos conf.trimmargins
)
3207 conf.invert
<- not
conf.invert
;
3208 TEdone
("invert colors " ^
btos conf.invert
)
3212 cbput state.hists
.sel
s;
3215 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3216 textentry, ondone, true)
3220 then conf.pax
<- Some
(ref (0.0, 0, 0))
3221 else conf.pax
<- None
;
3222 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3225 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3231 class type lvsource
= object
3232 method getitemcount
: int
3233 method getitem
: int -> (string * int)
3234 method hasaction
: int -> bool
3243 method getactive
: int
3244 method getfirst
: int
3245 method getqsearch
: string
3246 method setqsearch
: string -> unit
3250 class virtual lvsourcebase
= object
3251 val mutable m_active
= 0
3252 val mutable m_first
= 0
3253 val mutable m_qsearch
= ""
3254 val mutable m_pan
= 0
3255 method getactive
= m_active
3256 method getfirst
= m_first
3257 method getqsearch
= m_qsearch
3258 method getpan
= m_pan
3259 method setqsearch
s = m_qsearch
<- s
3262 let withoutlastutf8 s =
3263 let len = String.length
s in
3271 let b = Char.code
s.[pos
] in
3272 if b land 0b11000000 = 0b11000000
3277 if Char.code
s.[len-1] land 0x80 = 0
3281 String.sub
s 0 first;
3284 let textentrykeyboard
3285 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3287 if key >= 0xffb0 && key <= 0xffb9
3288 then key - 0xffb0 + 48 else key
3291 state.mode
<- Textentry
(te
, onleave
);
3294 G.postRedisplay "textentrykeyboard enttext";
3296 let histaction cmd
=
3299 | Some
(action, _) ->
3300 state.mode
<- Textentry
(
3301 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3303 G.postRedisplay "textentry histaction"
3306 | 0xff08 -> (* backspace *)
3307 let s = withoutlastutf8 text in
3308 let len = String.length
s in
3309 if cancelonempty
&& len = 0
3312 G.postRedisplay "textentrykeyboard after cancel";
3315 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3318 | 0xff0d | 0xff8d -> (* (kp) enter *)
3321 G.postRedisplay "textentrykeyboard after confirm"
3323 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3324 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3325 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3326 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3328 | 0xff1b -> (* escape*)
3329 if String.length
text = 0
3331 begin match opthist
with
3333 | Some
(_, onhistcancel
) -> onhistcancel
()
3337 G.postRedisplay "textentrykeyboard after cancel2"
3340 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3343 | 0xff9f | 0xffff -> () (* delete *)
3346 && key land 0xff00 != 0xff00 (* keyboard *)
3347 && key land 0xfe00 != 0xfe00 (* xkb *)
3348 && key land 0xfd00 != 0xfd00 (* 3270 *)
3350 begin match onkey
text key with
3354 G.postRedisplay "textentrykeyboard after confirm2";
3357 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3361 G.postRedisplay "textentrykeyboard after cancel3"
3364 state.mode
<- Textentry
(te
, onleave
);
3365 G.postRedisplay "textentrykeyboard switch";
3369 vlog "unhandled key %s" (Wsi.keyname
key)
3372 let firstof first active
=
3373 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3374 then max
0 (active
- (fstate.maxrows
/2))
3378 let calcfirst first active
=
3381 let rows = active
- first in
3382 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3386 let scrollph y maxy
=
3387 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3388 let sh = float state.winh
/. sh in
3389 let sh = max
sh (float conf.scrollh
) in
3391 let percent = float y /. float maxy
in
3392 let position = (float state.winh
-. sh) *. percent in
3395 if position +. sh > float state.winh
3396 then float state.winh
-. sh
3402 let coe s = (s :> uioh
);;
3404 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3406 val m_pan
= source#getpan
3407 val m_first
= source#getfirst
3408 val m_active
= source#getactive
3409 val m_qsearch
= source#getqsearch
3410 val m_prev_uioh
= state.uioh
3412 method private elemunder
y =
3413 let n = y / (fstate.fontsize
+1) in
3414 if m_first
+ n < source#getitemcount
3416 if source#hasaction
(m_first
+ n)
3417 then Some
(m_first
+ n)
3424 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3425 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3426 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3427 GlDraw.color
(1., 1., 1.);
3428 Gl.enable `texture_2d
;
3429 let fs = fstate.fontsize
in
3431 let ww = fstate.wwidth
in
3432 let tabw = 30.0*.ww in
3433 let itemcount = source#getitemcount
in
3435 if (row - m_first
) > fstate.maxrows
3438 if row >= 0 && row < itemcount
3440 let (s, level
) = source#getitem
row in
3441 let y = (row - m_first
) * nfs in
3442 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3445 Gl.disable `texture_2d
;
3446 GlDraw.polygon_mode `both `line
;
3447 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3448 GlDraw.color
(1., 1., 1.) ~
alpha;
3449 GlDraw.rect (1., float (y + 1))
3450 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3451 GlDraw.polygon_mode `both `fill
;
3452 GlDraw.color
(1., 1., 1.);
3453 Gl.enable `texture_2d
;
3456 let drawtabularstring s =
3457 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3460 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3463 let len = String.length
s - tabpos - 1 in
3464 let s1 = String.sub
s 0 tabpos
3465 and s2
= String.sub
s (tabpos + 1) len in
3466 let nx = drawstr x s1 in
3468 let x = x +. (max
tabw sw) in
3475 let _ = drawtabularstring s in
3482 Gl.disable `texture_2d
;
3484 method updownlevel incr
=
3485 let len = source#getitemcount
in
3487 if m_active
>= 0 && m_active
< len
3488 then snd
(source#getitem m_active
)
3492 if i
= len then i
-1 else if i
= -1 then 0 else
3493 let _, l = source#getitem i
in
3494 if l != curlevel then i
else flow (i
+incr
)
3496 let active = flow m_active
in
3497 let first = calcfirst m_first
active in
3498 G.postRedisplay "outline updownlevel";
3499 {< m_active
= active; m_first
= first >}
3501 method private key1
key mask
=
3502 let set1 active first qsearch
=
3503 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3505 let search active pattern incr
=
3506 let active = if active = -1 then m_first
else active in
3509 if n >= 0 && n < source#getitemcount
3511 let s, _ = source#getitem
n in
3513 (try ignore
(Str.search_forward
re s 0); true
3514 with Not_found
-> false)
3516 else loop (n + incr
)
3523 let re = Str.regexp_case_fold pattern
in
3529 let itemcount = source#getitemcount
in
3530 let find start incr
=
3532 if i
= -1 || i
= itemcount
3535 if source#hasaction i
3537 else find (i
+ incr
)
3542 let set active first =
3543 let first = bound first 0 (itemcount - fstate.maxrows
) in
3545 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3548 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3550 let incr1 = if incr
> 0 then 1 else -1 in
3551 if isvisible m_first m_active
3554 let next = m_active
+ incr
in
3556 if next < 0 || next >= itemcount
3558 else find next incr1
3560 if abs
(m_active
- next) > fstate.maxrows
3566 let first = m_first
+ incr
in
3567 let first = bound first 0 (itemcount - fstate.maxrows
) in
3569 let next = m_active
+ incr
in
3570 let next = bound next 0 (itemcount - 1) in
3577 if isvisible first next
3584 let first = min
next m_first
in
3586 if abs
(next - first) > fstate.maxrows
3592 let first = m_first
+ incr
in
3593 let first = bound first 0 (itemcount - 1) in
3595 let next = m_active
+ incr
in
3596 let next = bound next 0 (itemcount - 1) in
3597 let next = find next incr1 in
3599 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3601 let active = if m_active
= -1 then next else m_active
in
3606 if isvisible first active
3612 G.postRedisplay "listview navigate";
3616 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3617 let incr = if key = 0x72 then -1 else 1 in
3619 match search (m_active
+ incr) m_qsearch
incr with
3621 state.text <- m_qsearch ^
" [not found]";
3624 state.text <- m_qsearch
;
3625 active, firstof m_first
active
3627 G.postRedisplay "listview ctrl-r/s";
3628 set1 active first m_qsearch
;
3630 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3631 if m_active
>= 0 && m_active
< source#getitemcount
3633 let s, _ = source#getitem m_active
in
3638 | 0xff08 -> (* backspace *)
3639 if String.length m_qsearch
= 0
3642 let qsearch = withoutlastutf8 m_qsearch
in
3643 let len = String.length
qsearch in
3647 G.postRedisplay "listview empty qsearch";
3648 set1 m_active m_first
"";
3652 match search m_active
qsearch ~
-1 with
3654 state.text <- qsearch ^
" [not found]";
3657 state.text <- qsearch;
3658 active, firstof m_first
active
3660 G.postRedisplay "listview backspace qsearch";
3661 set1 active first qsearch
3664 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3665 let pattern = m_qsearch ^ toutf8
key in
3667 match search m_active
pattern 1 with
3669 state.text <- pattern ^
" [not found]";
3672 state.text <- pattern;
3673 active, firstof m_first
active
3675 G.postRedisplay "listview qsearch add";
3676 set1 active first pattern;
3678 | 0xff1b -> (* escape *)
3680 if String.length m_qsearch
= 0
3682 G.postRedisplay "list view escape";
3685 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3687 | None
-> m_prev_uioh
3692 G.postRedisplay "list view kill qsearch";
3693 source#setqsearch
"";
3694 coe {< m_qsearch
= "" >}
3697 | 0xff0d | 0xff8d -> (* (kp) enter *)
3699 let self = {< m_qsearch
= "" >} in
3700 source#setqsearch
"";
3702 G.postRedisplay "listview enter";
3703 if m_active
>= 0 && m_active
< source#getitemcount
3705 source#exit
(coe self) false m_active m_first m_pan
"";
3708 source#exit
(coe self) true m_active m_first m_pan
"";
3711 begin match opt with
3712 | None
-> m_prev_uioh
3716 | 0xff9f | 0xffff -> (* (kp) delete *)
3719 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3720 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3721 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3722 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3724 | 0xff53 | 0xff98 -> (* (kp) right *)
3726 G.postRedisplay "listview right";
3727 coe {< m_pan
= m_pan
- 1 >}
3729 | 0xff51 | 0xff96 -> (* (kp) left *)
3731 G.postRedisplay "listview left";
3732 coe {< m_pan
= m_pan
+ 1 >}
3734 | 0xff50 | 0xff95 -> (* (kp) home *)
3735 let active = find 0 1 in
3736 G.postRedisplay "listview home";
3739 | 0xff57 | 0xff9c -> (* (kp) end *)
3740 let first = max
0 (itemcount - fstate.maxrows
) in
3741 let active = find (itemcount - 1) ~
-1 in
3742 G.postRedisplay "listview end";
3745 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3749 dolog
"listview unknown key %#x" key; coe self
3751 method key key mask
=
3752 match state.mode
with
3753 | Textentry te
-> textentrykeyboard key mask te
; coe self
3754 | _ -> self#key1
key mask
3756 method button button down
x y _ =
3759 | 1 when x > state.winw
- conf.scrollbw
->
3760 G.postRedisplay "listview scroll";
3763 let _, position, sh = self#
scrollph in
3764 if y > truncate
position && y < truncate
(position +. sh)
3766 state.mstate
<- Mscrolly
;
3770 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3771 let first = truncate
(s *. float source#getitemcount
) in
3772 let first = min source#getitemcount
first in
3773 Some
(coe {< m_first
= first; m_active
= first >})
3775 state.mstate
<- Mnone
;
3778 | 1 when not down
->
3779 begin match self#elemunder
y with
3781 G.postRedisplay "listview click";
3783 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3787 | n when (n == 4 || n == 5) && not down
->
3788 let len = source#getitemcount
in
3790 if n = 5 && m_first
+ fstate.maxrows
>= len
3794 let first = m_first
+ (if n == 4 then -1 else 1) in
3795 bound first 0 (len - 1)
3797 G.postRedisplay "listview wheel";
3798 Some
(coe {< m_first
= first >})
3799 | n when (n = 6 || n = 7) && not down
->
3800 let inc = if n = 7 then -1 else 1 in
3801 G.postRedisplay "listview hwheel";
3802 Some
(coe {< m_pan
= m_pan
+ inc >})
3807 | None
-> m_prev_uioh
3811 match state.mstate
with
3813 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3814 let first = truncate
(s *. float source#getitemcount
) in
3815 let first = min source#getitemcount
first in
3816 G.postRedisplay "listview motion";
3817 coe {< m_first
= first; m_active
= first >}
3820 method pmotion
x y =
3821 if x < state.winw
- conf.scrollbw
3824 match self#elemunder
y with
3825 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3826 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3830 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3835 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3839 method infochanged
_ = ()
3841 method scrollpw
= (0, 0.0, 0.0)
3843 let nfs = fstate.fontsize
+ 1 in
3844 let y = m_first
* nfs in
3845 let itemcount = source#getitemcount
in
3846 let maxi = max
0 (itemcount - fstate.maxrows
) in
3847 let maxy = maxi * nfs in
3848 let p, h = scrollph y maxy in
3851 method modehash
= modehash
3852 method eformsgs
= false
3855 class outlinelistview ~source
=
3858 ~source
:(source
:> lvsource
)
3860 ~modehash
:(findkeyhash conf "outline")
3863 method key key mask
=
3865 if String.length
state.text = 0
3867 else fstate.maxrows - 2
3869 let calcfirst first active =
3872 let rows = active - first in
3873 if rows > maxrows then active - maxrows else first
3877 let active = m_active
+ incr in
3878 let active = bound active 0 (source#getitemcount
- 1) in
3879 let first = calcfirst m_first
active in
3880 G.postRedisplay "outline navigate";
3881 coe {< m_active
= active; m_first
= first >}
3883 let navscroll first =
3885 let dist = m_active
- first in
3891 else first + maxrows
3894 G.postRedisplay "outline navscroll";
3895 coe {< m_first
= first; m_active
= active >}
3897 let ctrl = Wsi.withctrl mask
in
3899 | 110 when ctrl -> (* ctrl-n *)
3900 source#narrow m_qsearch
;
3901 G.postRedisplay "outline ctrl-n";
3902 coe {< m_first
= 0; m_active
= 0 >}
3904 | 117 when ctrl -> (* ctrl-u *)
3906 G.postRedisplay "outline ctrl-u";
3908 coe {< m_first
= 0; m_active
= 0 >}
3910 | 108 when ctrl -> (* ctrl-l *)
3911 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3912 G.postRedisplay "outline ctrl-l";
3913 coe {< m_first
= first >}
3915 | 0xff9f | 0xffff -> (* (kp) delete *)
3916 source#remove m_active
;
3917 G.postRedisplay "outline delete";
3918 let active = max
0 (m_active
-1) in
3919 coe {< m_first
= firstof m_first
active;
3920 m_active
= active >}
3922 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
3923 navscroll (max
0 (m_first
- 1))
3925 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
3926 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
3928 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3929 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3930 | 0xff55 | 0xff9a -> (* (kp) prior *)
3931 navigate ~
-(fstate.maxrows)
3932 | 0xff56 | 0xff9b -> (* (kp) next *)
3933 navigate fstate.maxrows
3935 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3939 G.postRedisplay "outline ctrl right";
3940 {< m_pan
= m_pan
+ 1 >}
3942 else self#updownlevel
1
3946 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3950 G.postRedisplay "outline ctrl left";
3951 {< m_pan
= m_pan
- 1 >}
3953 else self#updownlevel ~
-1
3957 | 0xff50 | 0xff95 -> (* (kp) home *)
3958 G.postRedisplay "outline home";
3959 coe {< m_first
= 0; m_active
= 0 >}
3961 | 0xff57 | 0xff9c -> (* (kp) end *)
3962 let active = source#getitemcount
- 1 in
3963 let first = max
0 (active - fstate.maxrows) in
3964 G.postRedisplay "outline end";
3965 coe {< m_active
= active; m_first
= first >}
3967 | _ -> super#
key key mask
3970 let outlinesource usebookmarks
=
3973 inherit lvsourcebase
3974 val mutable m_items
= empty
3975 val mutable m_orig_items
= empty
3976 val mutable m_prev_items
= empty
3977 val mutable m_narrow_pattern
= ""
3978 val mutable m_hadremovals
= false
3980 method getitemcount
=
3981 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3984 if n == Array.length m_items
&& m_hadremovals
3986 ("[Confirm removal]", 0)
3988 let s, n, _ = m_items
.(n) in
3991 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3992 ignore
(uioh
, first, qsearch);
3993 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3995 if String.length m_narrow_pattern
= 0
4001 if not
confrimremoval
4003 let _, _, anchor = m_items
.(active) in
4004 gotoghyll (getanchory anchor);
4008 state.bookmarks
<- Array.to_list m_items
;
4009 m_orig_items
<- m_items
;
4012 else m_items
<- items;
4016 method hasaction
_ = true
4019 if Array.length m_items
!= Array.length m_orig_items
4020 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
4023 method narrow
pattern =
4024 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4028 let rec loop accu n =
4031 m_narrow_pattern
<- pattern;
4032 m_items
<- Array.of_list
accu
4035 let (s, _, _) as o = m_items
.(n) in
4037 if (try ignore
(Str.search_forward
re s 0); true
4038 with Not_found
-> false)
4044 loop [] (Array.length m_items
- 1)
4049 then Array.of_list
state.bookmarks
4052 m_items
<- m_orig_items
4057 if m >= 0 && m < Array.length m_items
4059 m_hadremovals
<- true;
4060 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4061 let n = if n >= m then n+1 else n in
4066 method reset
anchor items =
4067 m_hadremovals
<- false;
4068 if m_orig_items
== empty || m_prev_items
!= items
4070 m_orig_items
<- items;
4071 if String.length m_narrow_pattern
= 0
4072 then m_items
<- items;
4074 m_prev_items
<- items;
4075 let rely = getanchory anchor in
4077 let rec loop n best bestd
=
4078 if n = Array.length m_items
4081 let (_, _, anchor) = m_items
.(n) in
4082 let orely = getanchory anchor in
4083 let d = abs
(orely - rely) in
4086 else loop (n+1) best bestd
4091 m_first
<- firstof m_first
active
4095 let enterselector usebookmarks
=
4096 let source = outlinesource usebookmarks
in
4100 then Array.of_list
state.bookmarks
4103 if Array.length
outlines = 0
4105 showtext ' ' errmsg
;
4108 state.text <- source#greetmsg
;
4109 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4110 let anchor = getanchor () in
4111 source#reset
anchor outlines;
4112 state.uioh
<- coe (new outlinelistview ~
source);
4113 G.postRedisplay "enter selector";
4117 let enteroutlinemode =
4118 let f = enterselector false in
4119 fun ()-> f "Document has no outline";
4122 let enterbookmarkmode =
4123 let f = enterselector true in
4124 fun () -> f "Document has no bookmarks (yet)";
4127 let color_of_string s =
4128 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4129 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4133 let color_to_string (r, g, b) =
4134 let r = truncate
(r *. 256.0)
4135 and g = truncate
(g *. 256.0)
4136 and b = truncate
(b *. 256.0) in
4137 Printf.sprintf
"%d/%d/%d" r g b
4140 let irect_of_string s =
4141 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4144 let irect_to_string (x0,y0,x1,y1) =
4145 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4148 let makecheckers () =
4149 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4151 converted by Issac Trotts. July 25, 2002 *)
4152 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4153 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4154 let id = GlTex.gen_texture
() in
4155 GlTex.bind_texture `texture_2d
id;
4156 GlPix.store
(`unpack_alignment
1);
4157 GlTex.image2d
image;
4158 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4159 [ `mag_filter `nearest
; `min_filter `nearest
];
4163 let setcheckers enabled
=
4164 match state.texid
with
4166 if enabled
then state.texid
<- Some
(makecheckers ())
4171 GlTex.delete_texture texid
;
4172 state.texid
<- None
;
4176 let int_of_string_with_suffix s =
4177 let l = String.length
s in
4181 let suffix = Char.lowercase
s.[l-1] in
4183 | 'k'
-> String.sub
s 0 (l-1), 10
4184 | '
m'
-> String.sub
s 0 (l-1), 20
4185 | '
g'
-> String.sub
s 0 (l-1), 30
4189 let n = int_of_string
s1 in
4190 let m = n lsl shift
in
4192 then raise
(Failure
"value too large")
4196 let string_with_suffix_of_int n =
4201 if n land ((1 lsl 30) - 1) = 0
4204 if n land ((1 lsl 20) - 1) = 0
4207 if n land ((1 lsl 10) - 1) = 0
4214 let h = n mod 1000 in
4217 then string_of_int
h ^
s
4219 let s = Printf.sprintf
"_%03d%s" h s in
4226 let defghyllscroll = (40, 8, 32);;
4227 let ghyllscroll_of_string s =
4228 let (n, a, b) as nab
=
4231 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4233 if n <= a || n <= b || a >= b
4234 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4238 let ghyllscroll_to_string ((n, a, b) as nab
) =
4239 if nab
= defghyllscroll
4241 else Printf.sprintf
"%d,%d,%d" n a b;
4244 let describe_location () =
4245 let fn = page_of_y state.y in
4246 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4247 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4251 else (100. *. (float state.y /. float maxy))
4255 Printf.sprintf
"page %d of %d [%.2f%%]"
4256 (fn+1) state.pagecount
percent
4259 "pages %d-%d of %d [%.2f%%]"
4260 (fn+1) (ln+1) state.pagecount
percent
4263 let setpresentationmode v
=
4264 let n = page_of_y state.y in
4265 state.anchor <- (n, 0.0, 1.0);
4266 conf.presentation
<- v
;
4267 if conf.fitmodel
= FitPage
4268 then reqlayout conf.angle
conf.fitmodel
;
4273 let btos b = if b then "\xe2\x88\x9a" else "" in
4274 let showextended = ref false in
4275 let leave mode
= function
4276 | Confirm
-> state.mode
<- mode
4277 | Cancel
-> state.mode
<- mode
in
4280 val mutable m_first_time
= true
4281 val mutable m_l
= []
4282 val mutable m_a
= [||]
4283 val mutable m_prev_uioh
= nouioh
4284 val mutable m_prev_mode
= View
4286 inherit lvsourcebase
4288 method reset prev_mode prev_uioh
=
4289 m_a
<- Array.of_list
(List.rev m_l
);
4291 m_prev_mode
<- prev_mode
;
4292 m_prev_uioh
<- prev_uioh
;
4296 if n >= Array.length m_a
4300 | _, _, _, Action
_ -> m_active
<- n
4304 m_first_time
<- false;
4307 method int name get
set =
4309 (name, `
int get
, 1, Action
(
4312 try set (int_of_string
s)
4314 state.text <- Printf.sprintf
"bad integer `%s': %s"
4318 let te = name ^
": ", "", None
, intentry, ondone, true in
4319 state.mode
<- Textentry
(te, leave m_prev_mode
);
4323 method int_with_suffix
name get
set =
4325 (name, `intws get
, 1, Action
(
4328 try set (int_of_string_with_suffix s)
4330 state.text <- Printf.sprintf
"bad integer `%s': %s"
4335 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4337 state.mode
<- Textentry
(te, leave m_prev_mode
);
4341 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4343 (name, `
bool (btos, get
), offset
, Action
(
4350 method color
name get
set =
4352 (name, `color get
, 1, Action
(
4354 let invalid = (nan
, nan
, nan
) in
4357 try color_of_string s
4359 state.text <- Printf.sprintf
"bad color `%s': %s"
4366 let te = name ^
": ", "", None
, textentry, ondone, true in
4367 state.text <- color_to_string (get
());
4368 state.mode
<- Textentry
(te, leave m_prev_mode
);
4372 method string name get
set =
4374 (name, `
string get
, 1, Action
(
4376 let ondone s = set s in
4377 let te = name ^
": ", "", None
, textentry, ondone, true in
4378 state.mode
<- Textentry
(te, leave m_prev_mode
);
4382 method colorspace
name get
set =
4384 (name, `
string get
, 1, Action
(
4388 inherit lvsourcebase
4391 m_active
<- CSTE.to_int conf.colorspace
;
4394 method getitemcount
=
4395 Array.length
CSTE.names
4398 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4399 ignore
(uioh
, first, pan
, qsearch);
4400 if not cancel
then set active;
4402 method hasaction
_ = true
4406 let modehash = findkeyhash conf "info" in
4407 coe (new listview ~
source ~trusted
:true ~
modehash)
4410 method paxmark
name get
set =
4412 (name, `
string get
, 1, Action
(
4416 inherit lvsourcebase
4419 m_active
<- MTE.to_int conf.paxmark
;
4422 method getitemcount
= Array.length
MTE.names
4423 method getitem
n = (MTE.names.(n), 0)
4424 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4425 ignore
(uioh
, first, pan
, qsearch);
4426 if not cancel
then set active;
4428 method hasaction
_ = true
4432 let modehash = findkeyhash conf "info" in
4433 coe (new listview ~
source ~trusted
:true ~
modehash)
4436 method fitmodel
name get
set =
4438 (name, `
string get
, 1, Action
(
4442 inherit lvsourcebase
4445 m_active
<- FMTE.to_int conf.fitmodel
;
4448 method getitemcount
= Array.length
FMTE.names
4449 method getitem
n = (FMTE.names.(n), 0)
4450 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4451 ignore
(uioh
, first, pan
, qsearch);
4452 if not cancel
then set active;
4454 method hasaction
_ = true
4458 let modehash = findkeyhash conf "info" in
4459 coe (new listview ~
source ~trusted
:true ~
modehash)
4462 method caption
s offset
=
4463 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4465 method caption2
s f offset
=
4466 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4468 method getitemcount
= Array.length m_a
4471 let tostr = function
4472 | `
int f -> string_of_int
(f ())
4473 | `intws
f -> string_with_suffix_of_int (f ())
4475 | `color
f -> color_to_string (f ())
4476 | `
bool (btos, f) -> btos (f ())
4479 let name, t
, offset
, _ = m_a
.(n) in
4480 ((let s = tostr t
in
4481 if String.length
s > 0
4482 then Printf.sprintf
"%s\t%s" name s
4486 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4490 m_qsearch
<- qsearch;
4492 match m_a
.(active) with
4493 | _, _, _, Action
f -> f uioh
4505 method hasaction
n =
4507 | _, _, _, Action
_ -> true
4511 let rec fillsrc prevmode prevuioh
=
4512 let sep () = src#caption
"" 0 in
4513 let colorp name get
set =
4515 (fun () -> color_to_string (get
()))
4518 let c = color_of_string v in
4521 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4524 let oldmode = state.mode
in
4525 let birdseye = isbirdseye state.mode
in
4527 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4529 src#
bool "presentation mode"
4530 (fun () -> conf.presentation
)
4531 (fun v -> setpresentationmode v);
4533 src#
bool "ignore case in searches"
4534 (fun () -> conf.icase
)
4535 (fun v -> conf.icase
<- v);
4538 (fun () -> conf.preload)
4539 (fun v -> conf.preload <- v);
4541 src#
bool "highlight links"
4542 (fun () -> conf.hlinks
)
4543 (fun v -> conf.hlinks
<- v);
4545 src#
bool "under info"
4546 (fun () -> conf.underinfo
)
4547 (fun v -> conf.underinfo
<- v);
4549 src#
bool "persistent bookmarks"
4550 (fun () -> conf.savebmarks
)
4551 (fun v -> conf.savebmarks
<- v);
4553 src#fitmodel
"fit model"
4554 (fun () -> FMTE.to_string conf.fitmodel
)
4555 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4557 src#
bool "trim margins"
4558 (fun () -> conf.trimmargins
)
4559 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4561 src#
bool "persistent location"
4562 (fun () -> conf.jumpback
)
4563 (fun v -> conf.jumpback
<- v);
4566 src#
int "inter-page space"
4567 (fun () -> conf.interpagespace
)
4569 conf.interpagespace
<- n;
4570 docolumns conf.columns
;
4572 match state.layout with
4577 state.maxy <- calcheight ();
4578 let y = getpagey pageno in
4583 (fun () -> conf.pagebias
)
4584 (fun v -> conf.pagebias
<- v);
4586 src#
int "scroll step"
4587 (fun () -> conf.scrollstep
)
4588 (fun n -> conf.scrollstep
<- n);
4590 src#
int "horizontal scroll step"
4591 (fun () -> conf.hscrollstep
)
4592 (fun v -> conf.hscrollstep
<- v);
4594 src#
int "auto scroll step"
4596 match state.autoscroll
with
4598 | _ -> conf.autoscrollstep
)
4600 if state.autoscroll
<> None
4601 then state.autoscroll
<- Some
n;
4602 conf.autoscrollstep
<- n);
4605 (fun () -> truncate
(conf.zoom *. 100.))
4606 (fun v -> setzoom ((float v) /. 100.));
4609 (fun () -> conf.angle
)
4610 (fun v -> reqlayout v conf.fitmodel
);
4612 src#
int "scroll bar width"
4613 (fun () -> conf.scrollbw
)
4616 reshape state.winw
state.winh
;
4619 src#
int "scroll handle height"
4620 (fun () -> conf.scrollh
)
4621 (fun v -> conf.scrollh
<- v;);
4623 src#
int "thumbnail width"
4624 (fun () -> conf.thumbw
)
4626 conf.thumbw
<- min
4096 v;
4629 leavebirdseye beye
false;
4634 let mode = state.mode in
4635 src#
string "columns"
4637 match conf.columns
with
4639 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4640 | Csplit
(count
, _) -> "-" ^ string_of_int count
4643 let n, a, b = multicolumns_of_string v in
4644 setcolumns mode n a b);
4647 src#caption
"Pixmap cache" 0;
4648 src#int_with_suffix
"size (advisory)"
4649 (fun () -> conf.memlimit
)
4650 (fun v -> conf.memlimit
<- v);
4653 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4654 (string_with_suffix_of_int state.memused
)
4655 (Hashtbl.length
state.tilemap
)) 1;
4658 src#caption
"Layout" 0;
4659 src#caption2
"Dimension"
4661 Printf.sprintf
"%dx%d (virtual %dx%d)"
4662 state.winw
state.winh
4667 src#caption2
"Position" (fun () ->
4668 Printf.sprintf
"%dx%d" state.x state.y
4671 src#caption2
"Position" (fun () -> describe_location ()) 1
4675 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4676 "Save these parameters as global defaults at exit"
4677 (fun () -> conf.bedefault
)
4678 (fun v -> conf.bedefault
<- v)
4682 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4683 src#
bool ~offset
:0 ~
btos "Extended parameters"
4684 (fun () -> !showextended)
4685 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4689 (fun () -> conf.checkers
)
4690 (fun v -> conf.checkers
<- v; setcheckers v);
4691 src#
bool "update cursor"
4692 (fun () -> conf.updatecurs
)
4693 (fun v -> conf.updatecurs
<- v);
4695 (fun () -> conf.verbose
)
4696 (fun v -> conf.verbose
<- v);
4697 src#
bool "invert colors"
4698 (fun () -> conf.invert
)
4699 (fun v -> conf.invert
<- v);
4701 (fun () -> conf.maxhfit
)
4702 (fun v -> conf.maxhfit
<- v);
4703 src#
bool "redirect stderr"
4704 (fun () -> conf.redirectstderr)
4705 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4707 (fun () -> conf.pax
!= None
)
4710 then conf.pax
<- Some
(ref (now (), 0, 0))
4711 else conf.pax
<- None
);
4712 src#
string "uri launcher"
4713 (fun () -> conf.urilauncher
)
4714 (fun v -> conf.urilauncher
<- v);
4715 src#
string "path launcher"
4716 (fun () -> conf.pathlauncher
)
4717 (fun v -> conf.pathlauncher
<- v);
4718 src#
string "tile size"
4719 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4722 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4723 conf.tilew
<- max
64 w;
4724 conf.tileh
<- max
64 h;
4727 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4730 src#
int "texture count"
4731 (fun () -> conf.texcount
)
4734 then conf.texcount
<- v
4735 else showtext '
!'
" Failed to set texture count please retry later"
4737 src#
int "slice height"
4738 (fun () -> conf.sliceheight
)
4740 conf.sliceheight
<- v;
4741 wcmd "sliceh %d" conf.sliceheight
;
4743 src#
int "anti-aliasing level"
4744 (fun () -> conf.aalevel
)
4746 conf.aalevel
<- bound v 0 8;
4747 state.anchor <- getanchor ();
4748 opendoc state.path
state.password
;
4750 src#
string "page scroll scaling factor"
4751 (fun () -> string_of_float
conf.pgscale)
4754 let s = float_of_string
v in
4757 state.text <- Printf.sprintf
4758 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4761 src#
int "ui font size"
4762 (fun () -> fstate.fontsize
)
4763 (fun v -> setfontsize (bound v 5 100));
4764 src#
int "hint font size"
4765 (fun () -> conf.hfsize
)
4766 (fun v -> conf.hfsize
<- bound v 5 100);
4767 colorp "background color"
4768 (fun () -> conf.bgcolor
)
4769 (fun v -> conf.bgcolor
<- v);
4770 src#
bool "crop hack"
4771 (fun () -> conf.crophack
)
4772 (fun v -> conf.crophack
<- v);
4773 src#
string "trim fuzz"
4774 (fun () -> irect_to_string conf.trimfuzz
)
4777 conf.trimfuzz
<- irect_of_string v;
4779 then settrim true conf.trimfuzz
;
4781 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4783 src#
string "throttle"
4785 match conf.maxwait
with
4786 | None
-> "show place holder if page is not ready"
4789 then "wait for page to fully render"
4791 "wait " ^ string_of_float
time
4792 ^
" seconds before showing placeholder"
4796 let f = float_of_string
v in
4798 then conf.maxwait
<- None
4799 else conf.maxwait
<- Some
f
4801 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4803 src#
string "ghyll scroll"
4805 match conf.ghyllscroll
with
4807 | Some nab
-> ghyllscroll_to_string nab
4812 if String.length
v = 0
4814 else Some
(ghyllscroll_of_string v)
4816 conf.ghyllscroll
<- gs
4818 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4820 src#
string "selection command"
4821 (fun () -> conf.selcmd
)
4822 (fun v -> conf.selcmd
<- v);
4823 src#
string "synctex command"
4824 (fun () -> conf.stcmd
)
4825 (fun v -> conf.stcmd
<- v);
4826 src#
string "pax command"
4827 (fun () -> conf.paxcmd
)
4828 (fun v -> conf.paxcmd
<- v);
4829 src#colorspace
"color space"
4830 (fun () -> CSTE.to_string conf.colorspace
)
4832 conf.colorspace
<- CSTE.of_int v;
4836 src#paxmark
"pax mark method"
4837 (fun () -> MTE.to_string conf.paxmark
)
4838 (fun v -> conf.paxmark
<- MTE.of_int v);
4842 (fun () -> conf.usepbo
)
4843 (fun v -> conf.usepbo
<- v);
4844 src#
bool "mouse wheel scrolls pages"
4845 (fun () -> conf.wheelbypage
)
4846 (fun v -> conf.wheelbypage
<- v);
4847 src#
bool "open remote links in a new instance"
4848 (fun () -> conf.riani
)
4849 (fun v -> conf.riani
<- v);
4853 src#caption
"Document" 0;
4854 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4855 src#caption2
"Pages"
4856 (fun () -> string_of_int
state.pagecount
) 1;
4857 src#caption2
"Dimensions"
4858 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4862 src#caption
"Trimmed margins" 0;
4863 src#caption2
"Dimensions"
4864 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4868 src#caption
"OpenGL" 0;
4869 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4870 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4873 src#caption
"Location" 0;
4874 if String.length
state.origin
> 0
4875 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4876 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4878 src#reset prevmode prevuioh
;
4882 let prevmode = state.mode
4883 and prevuioh
= state.uioh in
4884 fillsrc prevmode prevuioh
;
4885 let source = (src :> lvsource
) in
4886 let modehash = findkeyhash conf "info" in
4887 state.uioh <- coe (object (self)
4888 inherit listview ~
source ~trusted
:true ~
modehash as super
4889 val mutable m_prevmemused
= 0
4890 method infochanged
= function
4892 if m_prevmemused
!= state.memused
4894 m_prevmemused
<- state.memused
;
4895 G.postRedisplay "memusedchanged";
4897 | Pdim
-> G.postRedisplay "pdimchanged"
4898 | Docinfo
-> fillsrc prevmode prevuioh
4900 method key key mask
=
4901 if not
(Wsi.withctrl mask
)
4904 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4905 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4906 | _ -> super#
key key mask
4907 else super#
key key mask
4909 G.postRedisplay "info";
4915 inherit lvsourcebase
4916 method getitemcount
= Array.length
state.help
4918 let s, l, _ = state.help
.(n) in
4921 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4925 m_qsearch
<- qsearch;
4926 match state.help
.(active) with
4927 | _, _, Action
f -> Some
(f uioh)
4937 method hasaction
n =
4938 match state.help
.(n) with
4939 | _, _, Action
_ -> true
4946 let modehash = findkeyhash conf "help" in
4947 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4948 G.postRedisplay "help";
4953 let re = Str.regexp
"[\r\n]" in
4955 inherit lvsourcebase
4956 val mutable m_items
= [||]
4958 method getitemcount
= 1 + Array.length m_items
4963 else m_items
.(n-1), 0
4965 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4970 then Buffer.clear
state.errmsgs
;
4971 m_qsearch
<- qsearch;
4978 method hasaction
n =
4982 state.newerrmsgs
<- false;
4983 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4984 m_items
<- Array.of_list
l
4992 let source = (msgsource :> lvsource
) in
4993 let modehash = findkeyhash conf "listview" in
4994 state.uioh <- coe (object
4995 inherit listview ~
source ~trusted
:false ~
modehash as super
4998 then msgsource#reset
;
5001 G.postRedisplay "msgs";
5004 let quickbookmark ?title
() =
5005 match state.layout with
5011 let sec = Unix.gettimeofday
() in
5012 let tm = Unix.localtime
sec in
5013 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5017 (tm.Unix.tm_year
+ 1900)
5020 | Some
title -> title
5022 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
5025 let setautoscrollspeed step goingdown
=
5026 let incr = max
1 ((abs step
) / 2) in
5027 let incr = if goingdown
then incr else -incr in
5028 let astep = step
+ incr in
5029 state.autoscroll
<- Some
astep;
5032 let gotounder = function
5033 | Ulinkgoto
(pageno, top) ->
5037 gotopage1 pageno top;
5043 | Uremote
(filename
, pageno) ->
5045 if String.length filename
> 0
5047 if Filename.is_relative filename
5049 let dir = Filename.dirname
state.path in
5051 if Filename.is_implicit
dir
5052 then Filename.concat
(Sys.getcwd
()) dir
5055 Filename.concat
dir filename
5060 if Sys.file_exists
path
5064 if String.length
path > 0
5068 let command = !selfexec ^
" " ^
path in
5069 try popen command []
5072 "failed to execute `%s': %s\n" command (exntos exn
);
5075 let anchor = getanchor () in
5076 let ranchor = state.path, state.password
, anchor, state.origin
in
5078 state.anchor <- (pageno, 0.0, 0.0);
5079 state.ranchors
<- ranchor :: state.ranchors
;
5082 else showtext '
!'
("Could not find " ^ filename
)
5084 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
5088 match conf.columns
with
5090 | _ -> state.x != 0 || conf.zoom > 1.0
5093 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5095 let existsinrow pageno (columns
, coverA
, coverB
) p =
5096 let last = ((pageno - coverA
) mod columns
) + columns
in
5097 let rec any = function
5100 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5104 then (if l.pageno = last then false else any rest
)
5112 match state.layout with
5114 let pageno = page_of_y state.y in
5115 gotoghyll (getpagey (pageno+1))
5117 match conf.columns
with
5119 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5121 let y = clamp (pgscale state.winh
) in
5124 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5125 gotoghyll (getpagey pageno)
5126 | Cmulti
((c, _, _) as cl, _) ->
5127 if conf.presentation
5128 && (existsinrow l.pageno cl
5129 (fun l -> l.pageh
> l.pagey + l.pagevh))
5131 let y = clamp (pgscale state.winh
) in
5134 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5135 gotoghyll (getpagey pageno)
5137 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5139 let pagey, pageh
= getpageyh l.pageno in
5140 let pagey = pagey + pageh
* l.pagecol
in
5141 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5142 gotoghyll (pagey + pageh
+ ips)
5146 match state.layout with
5148 let pageno = page_of_y state.y in
5149 gotoghyll (getpagey (pageno-1))
5151 match conf.columns
with
5153 if conf.presentation
&& l.pagey != 0
5155 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5157 let pageno = max
0 (l.pageno-1) in
5158 gotoghyll (getpagey pageno)
5159 | Cmulti
((c, _, coverB
) as cl, _) ->
5160 if conf.presentation
&&
5161 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5163 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5166 if l.pageno = state.pagecount
- coverB
5170 let pageno = max
0 (l.pageno-decr) in
5171 gotoghyll (getpagey pageno)
5179 let pageno = max
0 (l.pageno-1) in
5180 let pagey, pageh
= getpageyh pageno in
5183 let pagey, pageh
= getpageyh l.pageno in
5184 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5189 let viewkeyboard key mask
=
5191 let mode = state.mode in
5192 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5195 G.postRedisplay "view:enttext"
5197 let ctrl = Wsi.withctrl mask
in
5199 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5205 | 0xff63 -> (* insert *)
5206 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5208 state.mode <- LinkNav
(Ltgendir
0);
5211 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5213 | 0xff1b | 113 -> (* escape / q *)
5214 begin match state.mstate
with
5216 state.mstate
<- Mnone
;
5217 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5218 G.postRedisplay "kill zoom rect";
5220 begin match state.mode with
5223 G.postRedisplay "esc leave linknav"
5225 match state.ranchors
with
5227 | (path, password
, anchor, origin
) :: rest
->
5228 state.ranchors
<- rest
;
5229 state.anchor <- anchor;
5230 state.origin
<- origin
;
5231 opendoc path password
5235 | 0xff08 -> (* backspace *)
5236 gotoghyll (getnav ~
-1)
5244 G.postRedisplay "dehighlight";
5246 | 47 | 63 -> (* / ? *)
5247 let ondone isforw
s =
5248 cbput state.hists
.pat
s;
5249 state.searchpattern
<- s;
5252 let s = String.create
1 in
5253 s.[0] <- Char.chr
key;
5254 enttext (s, "", Some
(onhist state.hists
.pat
),
5255 textentry, ondone (key = 47), true)
5257 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5258 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5259 setzoom (conf.zoom +. incr)
5261 | 43 | 0xffab -> (* + *)
5264 try int_of_string
s with exc
->
5265 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5271 state.text <- "page bias is now " ^ string_of_int
n;
5274 enttext ("page bias: ", "", None
, intentry, ondone, true)
5276 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5277 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5278 setzoom (max
0.01 (conf.zoom -. decr))
5280 | 45 | 0xffad -> (* - *)
5281 let ondone msg
= state.text <- msg
in
5283 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5284 optentry state.mode, ondone, true
5287 | 48 when ctrl -> (* ctrl-0 *)
5295 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5297 match conf.columns
with
5298 | Csingle
_ | Cmulti
_ -> 1
5299 | Csplit
(n, _) -> n
5301 let h = state.winh
-
5302 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5304 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5305 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5308 | 51 when ctrl -> (* ctrl-3 *)
5310 match conf.fitmodel
with
5311 | FitWidth
-> FitProportional
5312 | FitProportional
-> FitPage
5313 | FitPage
-> FitWidth
5315 state.text <- "fit model: " ^
FMTE.to_string fm;
5316 reqlayout conf.angle
fm
5318 | 0xffc6 -> (* f9 *)
5321 | 57 when ctrl -> (* ctrl-9 *)
5324 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5325 when not
ctrl -> (* 0..9 *)
5328 try int_of_string
s with exc
->
5329 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5335 cbput state.hists
.pag
(string_of_int
n);
5336 gotopage1 (n + conf.pagebias
- 1) 0;
5339 let pageentry text key =
5340 match Char.unsafe_chr
key with
5341 | '
g'
-> TEdone
text
5342 | _ -> intentry text key
5344 let text = "x" in text.[0] <- Char.chr
key;
5345 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5348 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5349 reshape state.winw
state.winh
;
5352 state.bzoom
<- not
state.bzoom
;
5354 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5357 conf.hlinks
<- not
conf.hlinks
;
5358 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5359 G.postRedisplay "toggle highlightlinks";
5362 state.glinks
<- true;
5363 let mode = state.mode in
5364 state.mode <- Textentry
(
5365 (":", "", None
, linknentry, linkndone gotounder, false),
5367 state.glinks
<- false;
5371 G.postRedisplay "view:linkent(F)"
5374 state.glinks
<- true;
5375 let mode = state.mode in
5376 state.mode <- Textentry
(
5378 ":", "", None
, linknentry, linkndone (fun under ->
5379 selstring (undertext under);
5383 state.glinks
<- false;
5387 G.postRedisplay "view:linkent"
5390 begin match state.autoscroll
with
5392 conf.autoscrollstep
<- step
;
5393 state.autoscroll
<- None
5395 if conf.autoscrollstep
= 0
5396 then state.autoscroll
<- Some
1
5397 else state.autoscroll
<- Some
conf.autoscrollstep
5400 | 112 when ctrl -> (* ctrl-p *)
5404 setpresentationmode (not
conf.presentation
);
5405 showtext ' '
("presentation mode " ^
5406 if conf.presentation
then "on" else "off");
5409 if List.mem
Wsi.Fullscreen
state.winstate
5410 then Wsi.reshape conf.cwinw
conf.cwinh
5411 else Wsi.fullscreen
()
5413 | 112 | 78 -> (* p|N *)
5414 search state.searchpattern
false
5416 | 110 | 0xffc0 -> (* n|F3 *)
5417 search state.searchpattern
true
5420 begin match state.layout with
5423 gotoghyll (getpagey l.pageno)
5429 | 0xff9f | 0xffff -> (* delete *)
5433 showtext ' '
(describe_location ());
5436 begin match state.layout with
5439 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5444 enterbookmarkmode ()
5446 | 104 | 0xffbe -> (* h|F1 *)
5452 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5457 match state.layout with
5459 if String.length
s > 0
5461 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5464 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5468 showtext ' '
"Quick bookmark added";
5471 begin match state.layout with
5473 let rect = getpdimrect
l.pagedimno
in
5477 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5478 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5480 (truncate
(rect.(1) -. rect.(0)),
5481 truncate
(rect.(3) -. rect.(0)))
5483 let w = truncate
((float w)*.conf.zoom)
5484 and h = truncate
((float h)*.conf.zoom) in
5487 state.anchor <- getanchor ();
5488 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5490 G.postRedisplay "z";
5495 | 120 -> state.roam
()
5496 | 60 | 62 -> (* < > *)
5497 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5499 | 91 | 93 -> (* [ ] *)
5501 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5503 G.postRedisplay "brightness";
5505 | 99 when state.mode = View
-> (* [alt-]c *)
5510 let m = (wadjsb state.winw
- state.w) / 2 in
5512 gotoy_and_clear_text state.y
5516 match state.prevcolumns
with
5517 | None
-> (1, 0, 0), 1.0
5518 | Some
(columns
, z
) ->
5521 | Csplit
(c, _) -> -c, 0, 0
5522 | Cmulti
((c, a, b), _) -> c, a, b
5523 | Csingle
_ -> 1, 0, 0
5527 setcolumns View
c a b;
5530 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5531 -> (* ctrl-shift- (kp) [up|down] *)
5532 let zoom, x = state.prevzoom
in
5536 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5537 begin match state.autoscroll
with
5539 begin match state.mode with
5540 | Birdseye beye
-> upbirdseye 1 beye
5543 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5545 if not
(Wsi.withshift mask
) && conf.presentation
5547 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5551 setautoscrollspeed n false
5554 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5555 begin match state.autoscroll
with
5557 begin match state.mode with
5558 | Birdseye beye
-> downbirdseye 1 beye
5561 then gotoy_and_clear_text (clamp (state.winh
/2))
5563 if not
(Wsi.withshift mask
) && conf.presentation
5565 else gotoy_and_clear_text (clamp conf.scrollstep
)
5569 setautoscrollspeed n true
5572 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5573 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5579 else conf.hscrollstep
5581 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5582 state.x <- panbound (state.x + dx);
5583 gotoy_and_clear_text state.y
5586 G.postRedisplay "left/right"
5589 | 0xff55 | 0xff9a -> (* (kp) prior *)
5593 match state.layout with
5595 | l :: _ -> state.y - l.pagey
5597 clamp (pgscale (-state.winh
))
5601 | 0xff56 | 0xff9b -> (* (kp) next *)
5605 match List.rev
state.layout with
5607 | l :: _ -> getpagey l.pageno
5609 clamp (pgscale state.winh
)
5613 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5615 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5616 gotoghyll (clamp state.maxy)
5619 when Wsi.withalt mask
-> (* alt-(kp) right *)
5620 gotoghyll (getnav 1)
5622 when Wsi.withalt mask
-> (* alt-(kp) left *)
5623 gotoghyll (getnav ~
-1)
5628 | 118 when conf.debug
-> (* v *)
5631 match getopaque l.pageno with
5634 let x0, y0, x1, y1 = pagebbox opaque
in
5635 let a,b = float x0, float y0 in
5636 let c,d = float x1, float y0 in
5637 let e,f = float x1, float y1 in
5638 let h,j
= float x0, float y1 in
5639 let rect = (a,b,c,d,e,f,h,j
) in
5641 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5643 G.postRedisplay "v";
5646 vlog "huh? %s" (Wsi.keyname
key)
5649 let linknavkeyboard key mask
linknav =
5650 let getpage pageno =
5651 let rec loop = function
5653 | l :: _ when l.pageno = pageno -> Some
l
5654 | _ :: rest
-> loop rest
5655 in loop state.layout
5657 let doexact (pageno, n) =
5658 match getopaque pageno, getpage pageno with
5659 | Some opaque
, Some
l ->
5660 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5662 let under = getlink opaque
n in
5663 G.postRedisplay "link gotounder";
5669 | 0xff50 -> (* home *)
5670 Some
(findlink opaque LDfirst
), -1
5672 | 0xff57 -> (* end *)
5673 Some
(findlink opaque LDlast
), 1
5675 | 0xff51 -> (* left *)
5676 Some
(findlink opaque
(LDleft
n)), -1
5678 | 0xff53 -> (* right *)
5679 Some
(findlink opaque
(LDright
n)), 1
5681 | 0xff52 -> (* up *)
5682 Some
(findlink opaque
(LDup
n)), -1
5684 | 0xff54 -> (* down *)
5685 Some
(findlink opaque
(LDdown
n)), 1
5690 begin match findpwl
l.pageno dir with
5694 state.mode <- LinkNav
(Ltgendir
dir);
5695 let y, h = getpageyh pageno in
5698 then y + h - state.winh
5703 begin match getopaque pageno, getpage pageno with
5704 | Some opaque
, Some
_ ->
5706 let ld = if dir > 0 then LDfirst
else LDlast
in
5709 begin match link with
5711 showlinktype (getlink opaque
m);
5712 state.mode <- LinkNav
(Ltexact
(pageno, m));
5713 G.postRedisplay "linknav jpage";
5720 begin match opt with
5721 | Some Lnotfound
-> pwl l dir;
5722 | Some
(Lfound
m) ->
5726 let _, y0, _, y1 = getlinkrect opaque
m in
5728 then gotopage1 l.pageno y0
5730 let d = fstate.fontsize
+ 1 in
5731 if y1 - l.pagey > l.pagevh - d
5732 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5733 else G.postRedisplay "linknav";
5735 showlinktype (getlink opaque
m);
5736 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5739 | None
-> viewkeyboard key mask
5741 | _ -> viewkeyboard key mask
5746 G.postRedisplay "leave linknav"
5750 | Ltgendir
_ -> viewkeyboard key mask
5751 | Ltexact exact
-> doexact exact
5754 let keyboard key mask
=
5755 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5756 then wcmd "interrupt"
5757 else state.uioh <- state.uioh#
key key mask
5760 let birdseyekeyboard key mask
5761 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5763 match conf.columns
with
5765 | Cmulti
((c, _, _), _) -> c
5766 | Csplit
_ -> failwith
"bird's eye split mode"
5768 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5770 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5771 let y, h = getpageyh pageno in
5772 let top = (state.winh
- h) / 2 in
5773 gotoy (max
0 (y - top))
5774 | 0xff0d (* enter *)
5775 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5776 | 0xff1b -> leavebirdseye beye
true (* escape *)
5777 | 0xff52 -> upbirdseye incr beye
(* up *)
5778 | 0xff54 -> downbirdseye incr beye
(* down *)
5779 | 0xff51 -> upbirdseye 1 beye
(* left *)
5780 | 0xff53 -> downbirdseye 1 beye
(* right *)
5782 | 0xff55 -> (* prior *)
5783 begin match state.layout with
5787 state.mode <- Birdseye
(
5788 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5790 gotopage1 l.pageno 0;
5793 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5795 | [] -> gotoy (clamp (-state.winh
))
5797 state.mode <- Birdseye
(
5798 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5800 gotopage1 l.pageno 0
5803 | [] -> gotoy (clamp (-state.winh
))
5806 | 0xff56 -> (* next *)
5807 begin match List.rev
state.layout with
5809 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5810 begin match layout with
5812 let incr = l.pageh
- l.pagevh in
5817 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5819 G.postRedisplay "birdseye pagedown";
5821 else gotoy (clamp (incr + conf.interpagespace
*2));
5825 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5826 gotopage1 l.pageno 0;
5829 | [] -> gotoy (clamp state.winh
)
5832 | 0xff50 -> (* home *)
5833 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5836 | 0xff57 -> (* end *)
5837 let pageno = state.pagecount
- 1 in
5838 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5839 if not
(pagevisible state.layout pageno)
5842 match List.rev
state.pdims
with
5844 | (_, _, h, _) :: _ -> h
5846 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5847 else G.postRedisplay "birdseye end";
5848 | _ -> viewkeyboard key mask
5853 match state.mode with
5854 | Textentry
_ -> scalecolor 0.4
5856 | View
-> scalecolor 1.0
5857 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5858 if l.pageno = hooverpageno
5861 if l.pageno = pageno
5869 let postdrawpage l linkindexbase
=
5870 match getopaque l.pageno with
5872 if tileready l l.pagex
l.pagey
5874 let x = l.pagedispx - l.pagex
5875 and y = l.pagedispy - l.pagey in
5877 match conf.columns
with
5878 | Csingle
_ | Cmulti
_ ->
5879 (if conf.hlinks
then 1 else 0)
5881 && not
(isbirdseye state.mode) then 2 else 0)
5885 match state.mode with
5886 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5889 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5894 let scrollindicator () =
5895 let sbw, ph
, sh = state.uioh#
scrollph in
5896 let sbh, pw, sw = state.uioh#scrollpw
in
5898 GlDraw.color (0.64, 0.64, 0.64);
5900 (float (state.winw
- sbw), 0.)
5901 (float state.winw
, float state.winh
)
5904 (0., float (state.winh
- sbh))
5905 (float (wadjsb state.winw
- 1), float state.winh
)
5907 GlDraw.color (0.0, 0.0, 0.0);
5910 (float (state.winw
- sbw), ph
)
5911 (float state.winw
, ph
+. sh)
5914 (pw, float (state.winh
- sbh))
5915 (pw +. sw, float state.winh
)
5920 match state.mstate
with
5921 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5924 | Msel
((x0, y0), (x1, y1)) ->
5925 let rec loop = function
5927 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5928 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5929 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5930 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5932 match getopaque l.pageno with
5934 let x0, y0 = pagetranslatepoint l x0 y0 in
5935 let x1, y1 = pagetranslatepoint l x1 y1 in
5936 seltext opaque
(x0, y0, x1, y1);
5944 let showrects rects
=
5946 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5947 GlDraw.polygon_mode `both `fill
;
5948 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5950 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5952 if l.pageno = pageno
5954 let dx = float (l.pagedispx - l.pagex
) in
5955 let dy = float (l.pagedispy - l.pagey) in
5956 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5957 GlDraw.begins `quads
;
5959 GlDraw.vertex2
(x0+.dx, y0+.dy);
5960 GlDraw.vertex2
(x1+.dx, y1+.dy);
5961 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5962 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5973 GlClear.color (scalecolor2 conf.bgcolor
);
5974 GlClear.clear
[`
color];
5975 List.iter
drawpage state.layout;
5977 match state.mode with
5978 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5979 begin match getopaque pageno with
5981 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5988 | None
-> state.rects
5993 let rec postloop linkindexbase
= function
5995 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5996 postloop linkindexbase rest
6000 postloop 0 state.layout;
6002 begin match state.mstate
with
6003 | Mzoomrect
((x0, y0), (x1, y1)) ->
6005 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6006 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6007 GlDraw.rect (float x0, float y0)
6008 (float x1, float y1);
6017 let zoomrect x y x1 y1 =
6020 and y0 = min
y y1 in
6021 gotoy (state.y + y0);
6022 state.anchor <- getanchor ();
6023 let zoom = (float state.w) /. float (x1 - x0) in
6025 match conf.fitmodel
, conf.columns
with
6026 | FitPage
, Csplit
_ ->
6027 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6030 let adjw = wadjsb state.winw
in
6032 then (adjw - state.w) / 2
6035 state.x <- (state.x + margin) - x0;
6037 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6038 state.mstate
<- Mnone
;
6042 let g opaque
l px py =
6043 match rectofblock opaque
px py with
6045 let x0 = a.(0) -. 20. in
6046 let x1 = a.(1) +. 20. in
6047 let y0 = a.(2) -. 20. in
6048 let zoom = (float state.w) /. (x1 -. x0) in
6049 let pagey = getpagey l.pageno in
6050 gotoy_and_clear_text (pagey + truncate
y0);
6051 state.anchor <- getanchor ();
6052 let margin = (state.w - l.pagew
)/2 in
6053 state.x <- -truncate
x0 - margin;
6058 match conf.columns
with
6060 showtext '
!'
"block zooming does not work properly in split columns mode"
6061 | _ -> onppundermouse g x y ()
6065 let winw = wadjsb state.winw - 1 in
6066 let s = float x /. float winw in
6067 let destx = truncate
(float (state.w + winw) *. s) in
6068 state.x <- winw - destx;
6069 gotoy_and_clear_text state.y;
6070 state.mstate
<- Mscrollx
;
6074 let s = float y /. float state.winh
in
6075 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6076 gotoy_and_clear_text desty;
6077 state.mstate
<- Mscrolly
;
6080 let viewmouse button down
x y mask
=
6082 | n when (n == 4 || n == 5) && not down
->
6083 if Wsi.withctrl mask
6085 match state.mstate
with
6086 | Mzoom
(oldn
, i
) ->
6094 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6096 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6098 let zoom = conf.zoom -. incr in
6100 state.mstate
<- Mzoom
(n, 0);
6102 state.mstate
<- Mzoom
(n, i
+1);
6104 else state.mstate
<- Mzoom
(n, 0)
6106 | _ -> state.mstate
<- Mzoom
(n, 0)
6109 match state.autoscroll
with
6110 | Some step
-> setautoscrollspeed step
(n=4)
6112 if conf.wheelbypage
|| conf.presentation
6121 then -conf.scrollstep
6122 else conf.scrollstep
6124 let incr = incr * 2 in
6125 let y = clamp incr in
6126 gotoy_and_clear_text y
6129 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6131 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6132 gotoy_and_clear_text state.y
6134 | 1 when Wsi.withshift mask
->
6135 state.mstate
<- Mnone
;
6138 match unproject x y with
6139 | Some
(pageno, ux
, uy
) ->
6140 let cmd = Printf.sprintf
6142 conf.stcmd
state.path pageno ux uy
6148 | 1 when Wsi.withctrl mask
->
6151 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6152 state.mstate
<- Mpan
(x, y)
6155 state.mstate
<- Mnone
6160 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6162 state.mstate
<- Mzoomrect
(p, p)
6165 match state.mstate
with
6166 | Mzoomrect
((x0, y0), _) ->
6167 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6168 then zoomrect x0 y0 x y
6170 state.mstate
<- Mnone
;
6171 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6172 G.postRedisplay "kill accidental zoom rect";
6175 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6176 state.mstate
<- Mnone
6179 | 1 when x > state.winw - vscrollw () ->
6182 let _, position, sh = state.uioh#
scrollph in
6183 if y > truncate
position && y < truncate
(position +. sh)
6184 then state.mstate
<- Mscrolly
6187 state.mstate
<- Mnone
6189 | 1 when y > state.winh
- hscrollh () ->
6192 let _, position, sw = state.uioh#scrollpw
in
6193 if x > truncate
position && x < truncate
(position +. sw)
6194 then state.mstate
<- Mscrollx
6197 state.mstate
<- Mnone
6199 | 1 when state.bzoom
-> if not down
then zoomblock x y
6202 let dest = if down
then getunder x y else Unone
in
6203 begin match dest with
6207 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6210 | Unone
when down
->
6211 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6212 state.mstate
<- Mpan
(x, y);
6214 | Unone
| Utext
_ ->
6217 if conf.angle
mod 360 = 0
6219 state.mstate
<- Msel
((x, y), (x, y));
6220 G.postRedisplay "mouse select";
6224 match state.mstate
with
6227 | Mzoom
_ | Mscrollx
| Mscrolly
->
6228 state.mstate
<- Mnone
6230 | Mzoomrect
((x0, y0), _) ->
6234 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6235 state.mstate
<- Mnone
6237 | Msel
((x0, y0), (x1, y1)) ->
6238 let rec loop = function
6242 let a0 = l.pagedispy in
6243 let a1 = a0 + l.pagevh in
6244 let b0 = l.pagedispx in
6245 let b1 = b0 + l.pagevw in
6246 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6247 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6251 match getopaque l.pageno with
6254 match Ne.pipe () with
6258 "can not create sel pipe: %s"
6261 let doclose what fd
=
6262 Ne.clo fd
(fun msg
->
6263 dolog
"%s close failed: %s" what msg
)
6266 popen conf.selcmd
[r, 0; w, -1];
6267 copysel
w opaque
true;
6269 G.postRedisplay "copysel";
6271 dolog
"can not execute %S: %s"
6272 conf.selcmd
(exntos exn
);
6280 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6281 state.mstate
<- Mnone
;
6288 let birdseyemouse button down
x y mask
6289 (conf, leftx
, _, hooverpageno
, anchor) =
6292 let rec loop = function
6295 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6296 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6298 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6304 | _ -> viewmouse button down
x y mask
6307 let mouse button down
x y mask
=
6308 state.uioh <- state.uioh#button button down
x y mask
;
6312 state.uioh <- state.uioh#
motion x y
6316 state.uioh <- state.uioh#
pmotion x y;
6322 method key key mask
=
6323 begin match state.mode with
6324 | Textentry
textentry -> textentrykeyboard key mask
textentry
6325 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6326 | View
-> viewkeyboard key mask
6327 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6331 method button button bstate
x y mask
=
6332 begin match state.mode with
6334 | View
-> viewmouse button bstate
x y mask
6335 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6341 begin match state.mode with
6343 | View
| Birdseye
_ | LinkNav
_ ->
6344 match state.mstate
with
6345 | Mzoom
_ | Mnone
-> ()
6350 state.mstate
<- Mpan
(x, y);
6352 then state.x <- panbound (state.x + dx);
6354 gotoy_and_clear_text y
6357 state.mstate
<- Msel
(a, (x, y));
6358 G.postRedisplay "motion select";
6361 let y = min
state.winh
(max
0 y) in
6365 let x = min
state.winw (max
0 x) in
6368 | Mzoomrect
(p0
, _) ->
6369 state.mstate
<- Mzoomrect
(p0
, (x, y));
6370 G.postRedisplay "motion zoomrect";
6374 method pmotion x y =
6375 begin match state.mode with
6376 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6377 let rec loop = function
6379 if hooverpageno
!= -1
6381 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6382 G.postRedisplay "pmotion birdseye no hoover";
6385 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6386 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6388 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6389 G.postRedisplay "pmotion birdseye hoover";
6399 match state.mstate
with
6400 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6407 let past, _, _ = !r in
6409 let delta = now -. past in
6412 else r := (now, x, y)
6416 method infochanged
_ = ()
6419 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6422 then 0.0, float state.winh
6423 else scrollph state.y maxy
6428 let winw = wadjsb state.winw in
6429 let fwinw = float winw in
6431 let sw = fwinw /. float state.w in
6432 let sw = fwinw *. sw in
6433 max
sw (float conf.scrollh
)
6436 let maxx = state.w + winw in
6437 let x = winw - state.x in
6438 let percent = float x /. float maxx in
6439 (fwinw -. sw) *. percent
6441 hscrollh (), position, sw
6445 match state.mode with
6446 | LinkNav
_ -> "links"
6447 | Textentry
_ -> "textentry"
6448 | Birdseye
_ -> "birdseye"
6451 findkeyhash conf modename
6453 method eformsgs
= true
6460 let fontpath = ref "";;
6463 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6466 let l = String.length
s in
6467 let b = Buffer.create
l in
6473 try Sys.getenv
"HOME"
6476 ("Can not determine home directory location: " ^ exntos exn
);
6480 let modifier_of_string = function
6481 | "alt" -> Wsi.altmask
6482 | "shift" -> Wsi.shiftmask
6483 | "ctrl" | "control" -> Wsi.ctrlmask
6484 | "meta" -> Wsi.metamask
6489 let r = Str.regexp
"-" in
6491 let elems = Str.full_split
r s in
6494 let m1 = modifier_of_string s in
6496 then (Wsi.namekey
s, m)
6499 | Str.Delim
s when n land 1 = 0 -> g s
6501 | Str.Delim
_ -> (k
, m)
6503 let rec loop n k
m = function
6506 let k, m = f n k m x in
6512 let keys_of_string =
6513 let r = Str.regexp
"[ \t]" in
6515 let elems = Str.split
r s in
6516 List.map
key_of_string elems
6519 let copykeyhashes c =
6520 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6523 let config_of c attrs
=
6527 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6528 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6529 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6530 | "preload" -> { c with preload = bool_of_string
v }
6531 | "page-bias" -> { c with pagebias
= int_of_string
v }
6532 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6533 | "horizontal-scroll-step" ->
6534 { c with hscrollstep
= max
(int_of_string
v) 1 }
6535 | "auto-scroll-step" ->
6536 { c with autoscrollstep
= max
0 (int_of_string
v) }
6537 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6538 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6541 match String.lowercase
v with
6542 | "true" -> Some infinity
6544 | f -> Some
(float_of_string
f)
6546 { c with maxwait
= mw}
6547 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6548 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6549 | "vertical-margin" ->
6550 { c with interpagespace
= max
0 (int_of_string
v) }
6552 let zoom = float_of_string
v /. 100. in
6553 let zoom = max
zoom 0.0 in
6554 { c with zoom = zoom }
6555 | "presentation" -> { c with presentation
= bool_of_string
v }
6556 | "rotation-angle" -> { c with angle
= int_of_string
v }
6557 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6558 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6559 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6560 | "proportional-display" ->
6563 then FitProportional
6566 { c with fitmodel
= fm }
6567 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6568 | "pixmap-cache-size" ->
6569 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6570 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6571 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6572 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6573 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6574 | "background-color" -> { c with bgcolor
= color_of_string v }
6575 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6576 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6577 | "mupdf-store-size" ->
6578 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6579 | "checkers" -> { c with checkers
= bool_of_string
v }
6580 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6581 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6582 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6583 | "uri-launcher" -> { c with urilauncher
= unent v }
6584 | "path-launcher" -> { c with pathlauncher
= unent v }
6585 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6586 | "invert-colors" -> { c with invert
= bool_of_string
v }
6587 | "brightness" -> { c with colorscale
= float_of_string
v }
6588 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6590 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6592 let (n, _, _) as nab
= multicolumns_of_string v in
6594 then { c with columns
= Csplit
(-n, [||]) }
6595 else { c with columns
= Cmulti
(nab
, [||]) }
6596 | "birds-eye-columns" ->
6597 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6598 | "selection-command" -> { c with selcmd
= unent v }
6599 | "synctex-command" -> { c with stcmd
= unent v }
6600 | "pax-command" -> { c with paxcmd
= unent v }
6601 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6602 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6603 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6604 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6605 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6606 | "horizontal-scrollbar-visible" ->
6609 then c.scrollb
lor scrollbhv
6610 else c.scrollb
land (lnot
scrollbhv)
6612 { c with scrollb
= b }
6613 | "vertical-scrollbar-visible" ->
6616 then c.scrollb
lor scrollbvv
6617 else c.scrollb
land (lnot
scrollbvv)
6619 { c with scrollb
= b }
6620 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6624 then Some
(ref (0.0, 0, 0))
6626 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6629 prerr_endline
("Error processing attribute (`" ^
6630 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6633 let rec fold c = function
6636 let c = apply c k v in
6639 fold { c with keyhashes
= copykeyhashes c } attrs
;
6642 let fromstring f pos
n v d =
6645 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6646 n v pos
(exntos exn
)
6651 let bookmark_of attrs
=
6652 let rec fold title page
rely visy
= function
6653 | ("title", v) :: rest
-> fold v page
rely visy rest
6654 | ("page", v) :: rest
-> fold title v rely visy rest
6655 | ("rely", v) :: rest
-> fold title page
v visy rest
6656 | ("visy", v) :: rest
-> fold title page
rely v rest
6657 | _ :: rest
-> fold title page
rely visy rest
6658 | [] -> title, page
, rely, visy
6660 fold "invalid" "0" "0" "0" attrs
6664 let rec fold path page
rely pan visy
= function
6665 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6666 | ("page", v) :: rest
-> fold path v rely pan visy rest
6667 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6668 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6669 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6670 | _ :: rest
-> fold path page
rely pan visy rest
6671 | [] -> path, page
, rely, pan
, visy
6673 fold "" "0" "0" "0" "0" attrs
6677 let rec fold rs ls
= function
6678 | ("out", v) :: rest
-> fold v ls rest
6679 | ("in", v) :: rest
-> fold rs
v rest
6680 | _ :: rest
-> fold ls rs rest
6686 let setconf dst
src =
6687 dst
.scrollbw
<- src.scrollbw
;
6688 dst
.scrollh
<- src.scrollh
;
6689 dst
.icase
<- src.icase
;
6690 dst
.preload <- src.preload;
6691 dst
.pagebias
<- src.pagebias
;
6692 dst
.verbose
<- src.verbose
;
6693 dst
.scrollstep
<- src.scrollstep
;
6694 dst
.maxhfit
<- src.maxhfit
;
6695 dst
.crophack
<- src.crophack
;
6696 dst
.autoscrollstep
<- src.autoscrollstep
;
6697 dst
.maxwait
<- src.maxwait
;
6698 dst
.hlinks
<- src.hlinks
;
6699 dst
.underinfo
<- src.underinfo
;
6700 dst
.interpagespace
<- src.interpagespace
;
6701 dst
.zoom <- src.zoom;
6702 dst
.presentation
<- src.presentation
;
6703 dst
.angle
<- src.angle
;
6704 dst
.cwinw
<- src.cwinw
;
6705 dst
.cwinh
<- src.cwinh
;
6706 dst
.savebmarks
<- src.savebmarks
;
6707 dst
.memlimit
<- src.memlimit
;
6708 dst
.fitmodel
<- src.fitmodel
;
6709 dst
.texcount
<- src.texcount
;
6710 dst
.sliceheight
<- src.sliceheight
;
6711 dst
.thumbw
<- src.thumbw
;
6712 dst
.jumpback
<- src.jumpback
;
6713 dst
.bgcolor
<- src.bgcolor
;
6714 dst
.tilew
<- src.tilew
;
6715 dst
.tileh
<- src.tileh
;
6716 dst
.mustoresize
<- src.mustoresize
;
6717 dst
.checkers
<- src.checkers
;
6718 dst
.aalevel
<- src.aalevel
;
6719 dst
.trimmargins
<- src.trimmargins
;
6720 dst
.trimfuzz
<- src.trimfuzz
;
6721 dst
.urilauncher
<- src.urilauncher
;
6722 dst
.colorspace
<- src.colorspace
;
6723 dst
.invert
<- src.invert
;
6724 dst
.colorscale
<- src.colorscale
;
6725 dst
.redirectstderr <- src.redirectstderr;
6726 dst
.ghyllscroll
<- src.ghyllscroll
;
6727 dst
.columns
<- src.columns
;
6728 dst
.beyecolumns
<- src.beyecolumns
;
6729 dst
.selcmd
<- src.selcmd
;
6730 dst
.updatecurs
<- src.updatecurs
;
6731 dst
.pathlauncher
<- src.pathlauncher
;
6732 dst
.keyhashes
<- copykeyhashes src;
6733 dst
.hfsize
<- src.hfsize
;
6734 dst
.hscrollstep
<- src.hscrollstep
;
6735 dst
.pgscale <- src.pgscale;
6736 dst
.usepbo
<- src.usepbo
;
6737 dst
.wheelbypage
<- src.wheelbypage
;
6738 dst
.stcmd
<- src.stcmd
;
6739 dst
.paxcmd
<- src.paxcmd
;
6740 dst
.scrollb
<- src.scrollb
;
6741 dst
.riani
<- src.riani
;
6742 dst
.paxmark
<- src.paxmark
;
6746 else Some
((ref (0.0, 0, 0)));
6750 let h = Hashtbl.create
10 in
6751 let dc = { defconf with angle
= defconf.angle
} in
6752 let rec toplevel v t spos
_ =
6754 | Vdata
| Vcdata
| Vend
-> v
6755 | Vopen
("llppconfig", _, closed
) ->
6758 else { v with f = llppconfig
}
6760 error
"unexpected subelement at top level" s spos
6761 | Vclose
_ -> error
"unexpected close at top level" s spos
6763 and llppconfig
v t spos
_ =
6765 | Vdata
| Vcdata
-> v
6766 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6767 | Vopen
("defaults", attrs
, closed
) ->
6768 let c = config_of dc attrs
in
6772 else { v with f = defaults
}
6774 | Vopen
("ui-font", attrs
, closed
) ->
6775 let rec getsize size
= function
6777 | ("size", v) :: rest
->
6779 fromstring int_of_string spos
"size" v fstate.fontsize
in
6781 | l -> getsize size l
6783 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6786 else { v with f = uifont
(Buffer.create
10) }
6788 | Vopen
("doc", attrs
, closed
) ->
6789 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6790 let path = unent pathent
6791 and pageno = fromstring int_of_string spos
"page" spage
0
6792 and rely = fromstring float_of_string spos
"rely" srely
0.0
6793 and pan
= fromstring int_of_string spos
"pan" span
0
6794 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6795 let c = config_of dc attrs
in
6796 let anchor = (pageno, rely, visy
) in
6798 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6799 else { v with f = doc
path pan
anchor c [] }
6802 error
"unexpected subelement in llppconfig" s spos
6804 | Vclose
"llppconfig" -> { v with f = toplevel }
6805 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6807 and defaults
v t spos
_ =
6809 | Vdata
| Vcdata
-> v
6810 | Vend
-> error
"unexpected end of input in defaults" s spos
6811 | Vopen
("keymap", attrs
, closed
) ->
6813 try List.assoc
"mode" attrs
6814 with Not_found
-> "global" in
6819 let h = findkeyhash dc modename in
6820 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6823 { v with f = pkeymap
ret KeyMap.empty }
6825 | Vopen
(_, _, _) ->
6826 error
"unexpected subelement in defaults" s spos
6828 | Vclose
"defaults" ->
6829 { v with f = llppconfig
}
6831 | Vclose
_ -> error
"unexpected close in defaults" s spos
6833 and uifont
b v t spos
epos =
6836 Buffer.add_substring
b s spos
(epos - spos
);
6838 | Vopen
(_, _, _) ->
6839 error
"unexpected subelement in ui-font" s spos
6840 | Vclose
"ui-font" ->
6841 if String.length
!fontpath = 0
6842 then fontpath := Buffer.contents
b;
6843 { v with f = llppconfig
}
6844 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6845 | Vend
-> error
"unexpected end of input in ui-font" s spos
6847 and doc
path pan
anchor c bookmarks
v t spos
_ =
6849 | Vdata
| Vcdata
-> v
6850 | Vend
-> error
"unexpected end of input in doc" s spos
6851 | Vopen
("bookmarks", _, closed
) ->
6854 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6856 | Vopen
("keymap", attrs
, closed
) ->
6858 try List.assoc
"mode" attrs
6859 with Not_found
-> "global"
6865 let h = findkeyhash c modename in
6866 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6867 doc
path pan
anchor c bookmarks
6869 { v with f = pkeymap
ret KeyMap.empty }
6871 | Vopen
(_, _, _) ->
6872 error
"unexpected subelement in doc" s spos
6875 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6876 { v with f = llppconfig
}
6878 | Vclose
_ -> error
"unexpected close in doc" s spos
6880 and pkeymap
ret keymap
v t spos
_ =
6882 | Vdata
| Vcdata
-> v
6883 | Vend
-> error
"unexpected end of input in keymap" s spos
6884 | Vopen
("map", attrs
, closed
) ->
6885 let r, l = map_of attrs
in
6886 let kss = fromstring keys_of_string spos
"in" r [] in
6887 let lss = fromstring keys_of_string spos
"out" l [] in
6891 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6892 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6895 then { v with f = pkeymap
ret keymap }
6898 { v with f = skip
"map" f }
6901 error
"unexpected subelement in keymap" s spos
6903 | Vclose
"keymap" ->
6904 { v with f = ret keymap }
6906 | Vclose
_ -> error
"unexpected close in keymap" s spos
6908 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6910 | Vdata
| Vcdata
-> v
6911 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6912 | Vopen
("item", attrs
, closed
) ->
6913 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6914 let page = fromstring int_of_string spos
"page" spage
0
6915 and rely = fromstring float_of_string spos
"rely" srely
0.0
6916 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6918 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6921 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6924 { v with f = skip
"item" f }
6927 error
"unexpected subelement in bookmarks" s spos
6929 | Vclose
"bookmarks" ->
6930 { v with f = doc
path pan
anchor c bookmarks }
6932 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6934 and skip tag
f v t spos
_ =
6936 | Vdata
| Vcdata
-> v
6938 error
("unexpected end of input in skipped " ^ tag
) s spos
6939 | Vopen
(tag'
, _, closed
) ->
6943 let f'
() = { v with f = skip tag
f } in
6944 { v with f = skip tag'
f'
}
6948 else error
("unexpected close in skipped " ^ tag
) s spos
6951 parse
{ f = toplevel; accu = () } s;
6957 let len = in_channel_length ic
in
6958 let s = String.create
len in
6959 really_input ic
s 0 len;
6962 | Parse_error
(msg
, s, pos
) ->
6963 let subs = subs s pos
in
6964 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6965 failwith
("parse error: " ^
s)
6968 failwith
("config load error: " ^ exntos exn
)
6974 let dir = Filename.concat
home ".config" in
6975 if Sys.is_directory
dir then dir else home
6978 Filename.concat
dir "llpp.conf"
6981 let confpath = ref defconfpath;;
6984 if Sys.file_exists
!confpath
6987 (try Some
(open_in_bin
!confpath)
6990 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7001 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7010 f (Hashtbl.create
0, defconf)
7015 let pc, pb
, px, pa
=
7018 if String.length
state.origin
= 0
7022 Hashtbl.find h (Filename.basename
key)
7023 with Not_found
-> dc, [], 0, emptyanchor
7027 state.bookmarks <- pb
;
7030 then state.anchor <- pa
;
7031 cbput state.hists
.nav pa
;
7037 let add_attrs bb always
dc c =
7040 then Printf.bprintf bb
"\n %s='%b'" s a
7043 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7046 then Printf.bprintf bb
"\n %s='%d'" s a
7049 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7052 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7055 then Printf.bprintf bb
"\n %s='%f'" s a
7059 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7063 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7067 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7071 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7077 | Some
(_N
, _A
, _B
) ->
7078 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7088 else string_of_float
f
7090 Printf.bprintf bb
"\n %s='%s'" s v
7095 | Cmulti
((n, a, b), _) when n > 1 ->
7096 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7097 | Csplit
(n, _) when n > 1 ->
7098 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7104 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7109 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7113 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7117 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7119 oi
"width" c.cwinw
dc.cwinw
;
7120 oi
"height" c.cwinh
dc.cwinh
;
7121 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7122 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7123 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7124 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7125 ob "case-insensitive-search" c.icase
dc.icase
;
7126 ob "preload" c.preload dc.preload;
7127 oi
"page-bias" c.pagebias
dc.pagebias
;
7128 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7129 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7130 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7131 ob "crop-hack" c.crophack
dc.crophack
;
7132 oW
"throttle" c.maxwait
dc.maxwait
;
7133 ob "highlight-links" c.hlinks
dc.hlinks
;
7134 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7135 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7136 oz
"zoom" c.zoom dc.zoom;
7137 ob "presentation" c.presentation
dc.presentation
;
7138 oi
"rotation-angle" c.angle
dc.angle
;
7139 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7140 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7141 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7142 oi
"tex-count" c.texcount
dc.texcount
;
7143 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7144 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7145 ob "persistent-location" c.jumpback
dc.jumpback
;
7146 oc
"background-color" c.bgcolor
dc.bgcolor
;
7147 oi
"tile-width" c.tilew
dc.tilew
;
7148 oi
"tile-height" c.tileh
dc.tileh
;
7149 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7150 ob "checkers" c.checkers
dc.checkers
;
7151 oi
"aalevel" c.aalevel
dc.aalevel
;
7152 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7153 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7154 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7155 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7156 oC
"color-space" c.colorspace
dc.colorspace
;
7157 ob "invert-colors" c.invert
dc.invert
;
7158 oF
"brightness" c.colorscale
dc.colorscale
;
7159 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7160 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7161 oco
"columns" c.columns
dc.columns
;
7162 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7163 os
"selection-command" c.selcmd
dc.selcmd
;
7164 os
"synctex-command" c.stcmd
dc.stcmd
;
7165 os
"pax-command" c.paxcmd
dc.paxcmd
;
7166 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7167 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7168 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7169 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7170 ob "use-pbo" c.usepbo
dc.usepbo
;
7171 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7172 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7173 op
"point-and-x" c.pax
dc.pax
;
7174 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7177 let keymapsbuf always
dc c =
7178 let bb = Buffer.create
16 in
7179 let rec loop = function
7181 | (modename, h) :: rest
->
7182 let dh = findkeyhash dc modename in
7183 if always
|| h <> dh
7185 if Hashtbl.length
h > 0
7187 if Buffer.length
bb > 0
7188 then Buffer.add_char
bb '
\n'
;
7189 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7190 Hashtbl.iter
(fun i
o ->
7191 let isdifferent = always
||
7193 let dO = Hashtbl.find dh i
in
7195 with Not_found
-> true
7200 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7201 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7202 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7203 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7204 Buffer.add_string
bb (Wsi.keyname
k);
7207 let rec loop = function
7209 | km
:: [] -> addkm km
7210 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7214 Buffer.add_string
bb "<map in='";
7218 Buffer.add_string
bb "' out='";
7220 Buffer.add_string
bb "'/>\n"
7223 Buffer.add_string
bb "' out='";
7225 Buffer.add_string
bb "'/>\n"
7227 | KMmulti
(ins, kms
) ->
7228 Buffer.add_char
bb ' '
;
7230 Buffer.add_string
bb "' out='";
7232 Buffer.add_string
bb "'/>\n"
7234 Buffer.add_string
bb "</keymap>";
7244 let uifontsize = fstate.fontsize
in
7245 let bb = Buffer.create
32768 in
7246 let relx = float state.x /. float state.winw in
7248 let cx w = truncate
(relx *. float w) in
7250 (fun (w, h, x) ws
->
7252 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7253 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7254 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7256 (state.winw, state.winh
, state.x) state.winstate
7261 let dc = if conf.bedefault
then conf else dc in
7262 Buffer.add_string
bb "<llppconfig>\n";
7264 if String.length
!fontpath > 0
7266 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7272 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7275 Buffer.add_string
bb "<defaults ";
7276 add_attrs bb true dc dc;
7277 let kb = keymapsbuf true dc dc in
7278 if Buffer.length
kb > 0
7280 Buffer.add_string
bb ">\n";
7281 Buffer.add_buffer
bb kb;
7282 Buffer.add_string
bb "\n</defaults>\n";
7284 else Buffer.add_string
bb "/>\n";
7286 let adddoc path pan
anchor c bookmarks =
7287 if bookmarks == [] && c = dc && anchor = emptyanchor
7290 Printf.bprintf
bb "<doc path='%s'"
7291 (enent
path 0 (String.length
path));
7293 if anchor <> emptyanchor
7295 let n, rely, visy
= anchor in
7296 Printf.bprintf
bb " page='%d'" n;
7299 Printf.bprintf
bb " rely='%f'" rely
7301 if abs_float visy
> 1e-6
7303 Printf.bprintf
bb " visy='%f'" visy
7308 then Printf.bprintf
bb " pan='%d'" pan
;
7310 add_attrs bb false dc c;
7311 let kb = keymapsbuf false dc c in
7313 begin match bookmarks with
7315 if Buffer.length
kb > 0
7317 Buffer.add_string
bb ">\n";
7318 Buffer.add_buffer
bb kb;
7319 Buffer.add_string
bb "\n</doc>\n";
7321 else Buffer.add_string
bb "/>\n"
7323 Buffer.add_string
bb ">\n<bookmarks>\n";
7324 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7326 "<item title='%s' page='%d'"
7327 (enent
title 0 (String.length
title))
7332 Printf.bprintf
bb " rely='%f'" rely
7334 if abs_float visy
> 1e-6
7336 Printf.bprintf
bb " visy='%f'" visy
7338 Buffer.add_string
bb "/>\n";
7340 Buffer.add_string
bb "</bookmarks>";
7341 if Buffer.length
kb > 0
7343 Buffer.add_string
bb "\n";
7344 Buffer.add_buffer
bb kb;
7346 Buffer.add_string
bb "\n</doc>\n";
7352 match state.mode with
7353 | Birdseye
(c, pan, _, _, _) ->
7355 match conf.columns
with
7356 | Cmulti
((c, _, _), _) -> Some
c
7360 match c.columns
with
7361 | Cmulti
(c, _) -> Cmulti
(c, [||])
7362 | Csingle
_ -> Csingle
[||]
7363 | Csplit
_ -> failwith
"quit from bird's eye while split"
7365 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7368 let basename = Filename.basename
7369 (if String.length
state.origin
= 0 then state.path else state.origin
)
7371 adddoc basename pan (getanchor ())
7373 let autoscrollstep =
7374 match state.autoscroll
with
7376 | None
-> conf.autoscrollstep
7378 match state.mode with
7379 | Birdseye
(bc
, _, _, _, _) ->
7382 presentation
= bc
.presentation
;
7383 interpagespace
= bc
.interpagespace
;
7384 maxwait
= bc
.maxwait
;
7385 autoscrollstep = autoscrollstep }
7386 | _ -> { conf with autoscrollstep = autoscrollstep }
7388 (if conf.savebmarks
then state.bookmarks else []);
7390 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7392 then adddoc path x anchor c bookmarks
7394 Buffer.add_string
bb "</llppconfig>\n";
7397 if load1 f && Buffer.length
bb > 0
7400 let tmp = !confpath ^
".tmp" in
7401 let oc = open_out_bin
tmp in
7402 Buffer.output_buffer
oc bb;
7404 Unix.rename
tmp !confpath;
7407 ("error while saving configuration: " ^ exntos exn
)
7411 let adderrmsg src msg
=
7412 Buffer.add_string
state.errmsgs msg
;
7413 state.newerrmsgs
<- true;
7417 let adderrfmt src fmt
=
7418 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7422 let cl = splitatspace cmds
in
7424 try Scanf.sscanf
s fmt
f
7426 adderrfmt "remote exec"
7427 "error processing '%S': %s\n" cmds
(exntos exn
)
7430 | "reload" :: [] -> reload ()
7431 | "goto" :: args :: [] ->
7432 scan args "%u %f %f"
7434 let cmd, _ = state.geomcmds
in
7435 if String.length
cmd = 0
7436 then gotopagexy pageno x y
7439 gotopagexy pageno x y;
7442 state.reprf
<- f state.reprf
7444 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7445 | "rect" :: args :: [] ->
7446 scan args "%u %u %f %f %f %f"
7447 (fun pageno color x0 y0 x1 y1 ->
7448 onpagerect pageno (fun w h ->
7449 let _,w1,h1
,_ = getpagedim pageno in
7450 let sw = float w1 /. w
7451 and sh = float h1
/. h in
7455 and y1s
= y1 *. sh in
7456 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7458 state.rects <- (pageno, color, rect) :: state.rects;
7459 G.postRedisplay "rect";
7462 | "activatewin" :: [] -> Wsi.activatewin
()
7463 | "quit" :: [] -> raise Quit
7465 adderrfmt "remote command"
7466 "error processing remote command: %S\n" cmds
;
7470 let scratch = String.create
80 in
7471 let buf = Buffer.create
80 in
7474 try Some
(Unix.read fd
scratch 0 80)
7476 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7477 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7480 match tempfr () with
7486 if Buffer.length
buf > 0
7488 let s = Buffer.contents
buf in
7498 let pos = String.index_from
scratch ppos '
\n'
in
7499 if pos >= n then -1 else pos
7500 with Not_found
-> -1
7504 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7505 let s = Buffer.contents
buf in
7511 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7517 let remoteopen path =
7518 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7520 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7525 let trimcachepath = ref "" in
7526 let rcmdpath = ref "" in
7527 selfexec := Sys.executable_name
;
7530 [("-p", Arg.String
(fun s -> state.password
<- s),
7531 "<password> Set password");
7535 Config.fontpath := s;
7536 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7538 "<path> Set path to the user interface font");
7542 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7543 Config.confpath := s),
7544 "<path> Set path to the configuration file");
7546 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7547 "<path> Set path to the trim cache file");
7549 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7550 "<named-destination> Set named destination");
7552 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7553 ("-cxack", Arg.Set
cxack, " Cut corners");
7555 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7556 "<path> Set path to the remote commands source");
7558 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7559 "<original-path> Set original path");
7561 ("-v", Arg.Unit
(fun () ->
7563 "%s\nconfiguration path: %s\n"
7567 exit
0), " Print version and exit");
7570 (fun s -> state.path <- s)
7571 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7574 then selfexec := !selfexec ^
" -wtmode";
7576 if String.length
state.path = 0
7577 then (prerr_endline
"file name missing"; exit
1);
7579 if not
(Config.load ())
7580 then prerr_endline
"failed to load configuration";
7582 let wsfd, winw, winh
= Wsi.init
(object
7583 val mutable m_hack
= false
7584 method expose
= if not m_hack
then G.postRedisplay "expose"
7585 method visible
= G.postRedisplay "visible"
7586 method display = m_hack
<- false; display ()
7587 method reshape w h =
7588 m_hack
<- w < state.winw && h < state.winh
;
7590 method mouse b d x y m = mouse b d x y m
7591 method motion x y = state.mpos
<- (x, y); motion x y
7592 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7594 let mascm = m land (
7595 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7597 match state.keystate
with
7599 let km = k, mascm in
7602 let modehash = state.uioh#
modehash in
7603 try Hashtbl.find modehash km
7605 try Hashtbl.find (findkeyhash conf "global") km
7606 with Not_found
-> KMinsrt
(k, m)
7608 | KMinsrt
(k, m) -> keyboard k m
7609 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7610 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7612 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7613 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7614 state.keystate
<- KSnone
7615 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7616 state.keystate
<- KSinto
(keys
, insrt
)
7618 state.keystate
<- KSnone
7620 method enter
x y = state.mpos
<- (x, y); pmotion x y
7621 method leave = state.mpos
<- (-1, -1)
7622 method winstate wsl
= state.winstate
<- wsl
7623 method quit
= raise Quit
7624 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7629 List.exists
GlMisc.check_extension
7630 [ "GL_ARB_texture_rectangle"
7631 ; "GL_EXT_texture_recangle"
7632 ; "GL_NV_texture_rectangle" ]
7634 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7637 let r = GlMisc.get_string `renderer
in
7638 let p = "Mesa DRI Intel(" in
7639 let l = String.length
p in
7640 String.length
r > l && String.sub
r 0 l = p
7643 defconf.sliceheight
<- 1024;
7644 defconf.texcount
<- 32;
7645 defconf.usepbo
<- true;
7649 match Ne.pipe () with
7651 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7655 match Ne.pipe () with
7657 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7667 setcheckers conf.checkers
;
7669 if conf.redirectstderr
7672 let s = Buffer.contents
state.errmsgs ^
7673 (match state.errfd
with
7675 let s = String.create
(80*24) in
7678 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7680 then Unix.read fd
s 0 (String.length
s)
7686 else String.sub
s 0 n
7690 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7691 with exn
-> print_endline
(exntos exn
)
7696 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7697 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7698 !Config.fontpath, !trimcachepath,
7699 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7703 state.text <- "Opening " ^
(mbtoutf8
state.path);
7705 opendoc state.path state.password
;
7709 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7712 if String.length
!rcmdpath > 0
7713 then remoteopen !rcmdpath
7718 let rec loop deadline
=
7720 match state.errfd
with
7721 | None
-> [state.sr
; state.wsfd]
7722 | Some fd
-> [state.sr
; state.wsfd; fd
]
7727 | Some fd
-> fd
:: r
7731 state.redisplay
<- false;
7738 if deadline
= infinity
7740 else max
0.0 (deadline
-. now)
7745 try Unix.select
r [] [] timeout
7746 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7752 if state.ghyll
== noghyll
7754 match state.autoscroll
with
7755 | Some step
when step
!= 0 ->
7756 let y = state.y + step
in
7760 else if y >= state.maxy then 0 else y
7763 if state.mode = View
7764 then state.text <- "";
7767 else deadline
+. 0.01
7772 let rec checkfds = function
7774 | fd
:: rest
when fd
= state.sr
->
7775 let cmd = readcmd state.sr
in
7779 | fd
:: rest
when fd
= state.wsfd ->
7783 | fd
:: rest
when Some fd
= !optrfd ->
7784 begin match remote fd
with
7785 | None
-> optrfd := remoteopen !rcmdpath;
7786 | opt -> optrfd := opt
7791 let s = String.create
80 in
7792 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7793 if conf.redirectstderr
7795 Buffer.add_substring
state.errmsgs
s 0 n;
7796 state.newerrmsgs
<- true;
7797 state.redisplay
<- true;
7800 prerr_string
(String.sub
s 0 n);
7808 if deadline
= infinity
7812 match state.autoscroll
with
7813 | Some step
when step
!= 0 -> deadline1
7814 | _ -> if state.ghyll
== noghyll then infinity
else deadline1