8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
11 | Ulaunch
of launchcommand
13 | Uremote
of (filename
* pageno
)
14 | Uremotedest
of (filename
* destname
)
16 and launchcommand
= string
19 and destname
= string;;
28 type params
= (angle
* fitmodel
* trimparams
29 * texcount
* sliceheight
* memsize
30 * colorspace
* fontpath
* trimcachepath
39 and trimmargins
= bool
40 and interpagespace
= int
47 and trimcachepath
= string
50 and irect
= (int * int * int * int)
51 and trimparams
= (trimmargins
* irect
)
52 and colorspace
= | Rgb
| Bgr
| Gray
53 and fitmodel
= | FitWidth
| FitProportional
| FitPage
63 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
72 | LDfirstvisible
of (int * int * int)
87 | KMmulti
of key list
* key list
89 and keyhash
= (key
, keymap
) Hashtbl.t
92 | KSinto
of (key list
* key list
)
95 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
96 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
98 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
100 external init
: pipe
-> params
-> unit = "ml_init";;
101 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
102 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
103 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
104 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
105 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
106 external clearmark
: string -> unit = "ml_clearmark";;
107 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
108 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
109 external measurestr
: int -> string -> float = "ml_measure_string";;
110 external postprocess
:
111 opaque
-> int -> int -> int -> (int * string * int) -> int
113 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
114 external platform
: unit -> platform
= "ml_platform";;
115 external setaalevel
: int -> unit = "ml_setaalevel";;
116 external realloctexts
: int -> bool = "ml_realloctexts";;
117 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
118 external getlink
: opaque
-> int -> under
= "ml_getlink";;
119 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
120 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
121 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
122 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
123 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
124 external freepbo
: string -> unit = "ml_freepbo";;
125 external unmappbo
: string -> unit = "ml_unmappbo";;
126 external pbousable
: unit -> bool = "ml_pbo_usable";;
127 external unproject
: opaque
-> int -> int -> (int * int) option
129 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
130 external rectofblock
: opaque
-> int -> int -> float array
option
132 external fz_version
: unit -> string = "ml_fz_version";;
133 external begintiles
: unit -> unit = "ml_begintiles";;
134 external endtiles
: unit -> unit = "ml_endtiles";;
136 let platform_to_string = function
137 | Punknown
-> "unknown"
141 | Pfreebsd
-> "FreeBSD"
142 | Pdragonflybsd
-> "DragonflyBSD"
143 | Popenbsd
-> "OpenBSD"
144 | Pnetbsd
-> "NetBSD"
145 | Pcygwin
-> "Cygwin"
148 let platform = platform ();;
150 let now = Unix.gettimeofday
;;
152 let selfexec = ref "";;
155 if platform = Pcygwin
157 let sh = "/bin/sh" in
158 let args = [|sh; "-c"; cmd
|] in
159 let rec std si so se
= function
161 | (fd
, 0) :: rest
-> std fd so se rest
162 | (fd
, -1) :: rest
->
163 Unix.set_close_on_exec fd
;
166 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
168 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
169 ignore
(Unix.create_process
sh args si so se
)
174 type mpos
= int * int
176 | Msel
of (mpos
* mpos
)
178 | Mscrolly
| Mscrollx
179 | Mzoom
of (int * int)
180 | Mzoomrect
of (mpos
* mpos
)
184 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
185 and onkey
= string -> int -> te
186 and ondone
= string -> unit
187 and histcancel
= unit -> unit
188 and onhist
= ((histcmd
-> string) * histcancel
)
189 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
190 and cancelonempty
= bool
195 | TEswitch
of textentry
206 let bound v minv maxv
=
207 max minv
(min maxv v
);
211 { store
= Array.create n v
218 let cbcap b
= Array.length b
.store
;;
223 b
.wc
<- (b
.wc
+ 1) mod cap;
225 b
.len
<- min
(b
.len
+ 1) cap;
228 let cbempty b
= b
.len
= 0;;
230 let cbgetg b circular dir
=
234 let rc = b
.rc + dir
in
246 else bound rc 0 (b
.len
-1)
252 let cbget b
= cbgetg b
false;;
253 let cbgetc b
= cbgetg b
true;;
255 let drawstring size x y s
=
257 Gl.enable `texture_2d
;
258 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
259 ignore
(drawstr size x y s
);
261 Gl.disable `texture_2d
;
264 let drawstring1 size x y s
=
268 let drawstring2 size x y fmt
=
269 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
288 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
289 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
290 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
291 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
292 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
293 dolog
" column %d" l
.pagecol
;
297 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
299 dolog
" x0,y0=(% f, % f)" x0 y0
;
300 dolog
" x1,y1=(% f, % f)" x1 y1
;
301 dolog
" x2,y2=(% f, % f)" x2 y2
;
302 dolog
" x3,y3=(% f, % f)" x3 y3
;
306 type multicolumns
= multicol
* pagegeom
307 and singlecolumn
= pagegeom
308 and splitcolumns
= columncount
* pagegeom
309 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
310 and multicol
= columncount
* covercount
* covercount
312 and columncount
= int
313 and covercount
= int;;
320 { mutable scrollbw
: int
321 ; mutable scrollh
: int
322 ; mutable scrollb
: scrollb
323 ; mutable icase
: bool
324 ; mutable preload
: bool
325 ; mutable pagebias
: int
326 ; mutable verbose
: bool
327 ; mutable debug
: bool
328 ; mutable scrollstep
: int
329 ; mutable hscrollstep
: int
330 ; mutable maxhfit
: bool
331 ; mutable crophack
: bool
332 ; mutable autoscrollstep
: int
333 ; mutable maxwait
: float option
334 ; mutable hlinks
: bool
335 ; mutable underinfo
: bool
336 ; mutable interpagespace
: interpagespace
337 ; mutable zoom
: float
338 ; mutable presentation
: bool
339 ; mutable angle
: angle
340 ; mutable cwinw
: int
341 ; mutable cwinh
: int
342 ; mutable savebmarks
: bool
343 ; mutable fitmodel
: fitmodel
344 ; mutable trimmargins
: trimmargins
345 ; mutable trimfuzz
: irect
346 ; mutable memlimit
: memsize
347 ; mutable texcount
: texcount
348 ; mutable sliceheight
: sliceheight
349 ; mutable thumbw
: width
350 ; mutable jumpback
: bool
351 ; mutable bgcolor
: (float * float * float)
352 ; mutable bedefault
: bool
353 ; mutable tilew
: int
354 ; mutable tileh
: int
355 ; mutable mustoresize
: memsize
356 ; mutable checkers
: bool
357 ; mutable aalevel
: int
358 ; mutable urilauncher
: string
359 ; mutable pathlauncher
: string
360 ; mutable colorspace
: colorspace
361 ; mutable invert
: bool
362 ; mutable colorscale
: float
363 ; mutable redirectstderr
: bool
364 ; mutable ghyllscroll
: (int * int * int) option
365 ; mutable columns
: columns
366 ; mutable beyecolumns
: columncount
option
367 ; mutable selcmd
: string
368 ; mutable paxcmd
: string
369 ; mutable updatecurs
: bool
370 ; mutable keyhashes
: (string * keyhash
) list
371 ; mutable hfsize
: int
372 ; mutable pgscale
: float
373 ; mutable usepbo
: bool
374 ; mutable wheelbypage
: bool
375 ; mutable stcmd
: string
376 ; mutable riani
: bool
377 ; mutable pax
: (float * int * int) ref option
378 ; mutable paxmark
: mark
381 | Csingle
of singlecolumn
382 | Cmulti
of multicolumns
383 | Csplit
of splitcolumns
386 type anchor
= pageno
* top
* dtop
;;
392 | Olaunch
of launchcommand
393 | Oremote
of (filename
* pageno
)
394 | Oremotedest
of (filename
* destname
)
395 and outline
= (caption
* outlinelevel
* outlinekind
)
396 and outlinelevel
= int
399 type rect
= float * float * float * float * float * float * float * float;;
401 type tile
= opaque
* pixmapsize
* elapsed
402 and elapsed
= float;;
403 type pagemapkey
= pageno
* gen
;;
404 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
408 let emptyanchor = (0, 0.0, 0.0);;
410 type infochange
= | Memused
| Docinfo
| Pdim
;;
412 class type uioh
= object
413 method display
: unit
414 method key
: int -> int -> uioh
415 method button
: int -> bool -> int -> int -> int -> uioh
416 method multiclick
: int -> int -> int -> int -> uioh
417 method motion
: int -> int -> uioh
418 method pmotion
: int -> int -> uioh
419 method infochanged
: infochange
-> unit
420 method scrollpw
: (int * float * float)
421 method scrollph
: (int * float * float)
422 method modehash
: keyhash
423 method eformsgs
: bool
427 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
428 | Textentry
of (textentry
* onleave
)
430 | LinkNav
of linktarget
431 and onleave
= leavetextentrystatus
-> unit
432 and leavetextentrystatus
= | Cancel
| Confirm
433 and helpitem
= string * int * action
436 | Action
of (uioh
-> uioh
)
438 | Ltexact
of (pageno
* int)
442 let isbirdseye = function Birdseye _
-> true | _
-> false;;
443 let istextentry = function Textentry _
-> true | _
-> false;;
447 | Loading
of (page
* gen
)
449 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
451 | Outlining
of outline list
454 let emptykeyhash = Hashtbl.create
0;;
455 let nouioh : uioh
= object (self
)
457 method key _ _
= self
458 method multiclick _ _ _ _
= self
459 method button _ _ _ _ _
= self
460 method motion _ _
= self
461 method pmotion _ _
= self
462 method infochanged _
= ()
463 method scrollpw
= (0, nan
, nan
)
464 method scrollph
= (0, nan
, nan
)
465 method modehash
= emptykeyhash
466 method eformsgs
= false
470 { mutable sr
: Unix.file_descr
471 ; mutable sw
: Unix.file_descr
472 ; mutable wsfd
: Unix.file_descr
473 ; mutable errfd
: Unix.file_descr
option
474 ; mutable stderr
: Unix.file_descr
475 ; mutable errmsgs
: Buffer.t
476 ; mutable newerrmsgs
: bool
480 ; mutable anchor
: anchor
481 ; mutable ranchors
: (string * string * anchor
* string) list
483 ; mutable layout
: page list
484 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
485 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
486 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
487 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
488 ; mutable pagecount
: int
489 ; mutable currently
: currently
490 ; mutable mstate
: mstate
491 ; mutable searchpattern
: string
492 ; mutable rects
: (pageno
* recttype
* rect
) list
493 ; mutable rects1
: (pageno
* recttype
* rect
) list
494 ; mutable text
: string
495 ; mutable winstate
: Wsi.winstate list
496 ; mutable mode
: mode
497 ; mutable uioh
: uioh
498 ; mutable outlines
: outline array
499 ; mutable bookmarks
: outline list
500 ; mutable path
: string
501 ; mutable password
: string
502 ; mutable nameddest
: string
503 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
504 ; mutable memused
: memsize
506 ; mutable throttle
: (page list
* int * float) option
507 ; mutable autoscroll
: int option
508 ; mutable ghyll
: (int option -> unit)
509 ; mutable help
: helpitem array
510 ; mutable docinfo
: (int * string) list
511 ; mutable texid
: GlTex.texture_id
option
513 ; mutable prevzoom
: (float * int)
514 ; mutable progress
: float
515 ; mutable redisplay
: bool
516 ; mutable mpos
: mpos
517 ; mutable keystate
: keystate
518 ; mutable glinks
: bool
519 ; mutable prevcolumns
: (columns
* float) option
522 ; mutable reprf
: (unit -> unit)
523 ; mutable origin
: string
524 ; mutable roam
: (unit -> unit)
525 ; mutable bzoom
: bool
526 ; mutable traw
: [`
float] Raw.t
527 ; mutable vraw
: [`
float] Raw.t
530 { pat
: string circbuf
531 ; pag
: string circbuf
532 ; nav
: anchor circbuf
533 ; sel
: string circbuf
540 ; scrollb
= scrollbhv lor scrollbvv
556 ; presentation
= false
561 ; fitmodel
= FitProportional
562 ; trimmargins
= false
563 ; trimfuzz
= (0,0,0,0)
564 ; memlimit
= 32 lsl 20
569 ; bgcolor
= (0.5, 0.5, 0.5)
573 ; mustoresize
= 256 lsl 20
578 | Plinux
| Pfreebsd
| Pdragonflybsd
579 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
580 | Posx
-> "open \"%s\""
581 | Pcygwin
-> "cygstart \"%s\""
582 | Punknown
-> "echo %s")
583 ; pathlauncher
= "lp \"%s\""
586 | Plinux
| Pfreebsd
| Pdragonflybsd
587 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
595 ; redirectstderr
= false
597 ; columns
= Csingle
[||]
603 ; wheelbypage
= false
604 ; stcmd
= "echo SyncTex"
607 ; paxmark
= Mark_word
609 let mk n
= (n
, Hashtbl.create
1) in
623 let wtmode = ref false;;
624 let cxack = ref false;;
626 let findkeyhash c name
=
627 try List.assoc name c
.keyhashes
628 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
631 let conf = { defconf with angle
= defconf.angle
};;
633 let pgscale h
= truncate
(float h
*. conf.pgscale);;
636 { mutable fontsize
: int
637 ; mutable wwidth
: float
638 ; mutable maxrows
: int
650 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
651 let len = String.length s
in
652 if colonpos >= 0 && colonpos + 3 < len
654 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
657 try String.rindex_from s
colonpos ' '
661 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
664 | "http" | "ftp" | "mailto" ->
666 try String.index_from s
colonpos ' '
667 with Not_found
-> len
669 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
677 if emptystr
conf.urilauncher
678 then print_endline uri
680 let url = geturl uri
in
682 then Printf.eprintf
"obtained empty url from uri %S" uri
684 let re = Str.regexp
"%s" in
685 let command = Str.global_replace
re url conf.urilauncher
in
689 "failed to execute `%s': %s\n" command (exntos exn
);
695 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
696 Help.version (fz_version
()) Sys.ocaml_version
697 (platform_to_string platform) Sys.word_size
701 let strings = version () :: "" :: Help.keys
in
704 let url = geturl s
in
706 then (s
, 0, Action
(fun u
-> gotouri url; u
))
707 else (s
, 0, Noaction
)
712 let firstgeomcmds = "", [];;
713 let noreprf () = ();;
721 ; stderr
= Unix.stderr
722 ; errmsgs
= Buffer.create
0
727 ; anchor
= emptyanchor
731 ; tilelru
= Queue.create
()
732 ; pagemap
= Hashtbl.create
10
733 ; tilemap
= Hashtbl.create
10
749 ; geomcmds
= firstgeomcmds
751 { nav
= cbnew 10 emptyanchor
764 ; prevzoom
= (1.0, 0)
778 ; traw
= Raw.create_static `
float 8
779 ; vraw
= Raw.create_static `
float 8
784 if (conf.scrollb
land scrollbhv = 0)
785 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
791 if (conf.scrollb
land scrollbvv = 0)
796 let wadjsb w
= w
- vscrollw ();;
799 fstate.fontsize
<- n
;
800 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
801 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
807 Printf.kprintf prerr_endline fmt
809 Printf.kprintf ignore fmt
813 if emptystr
conf.pathlauncher
814 then print_endline
state.path
816 let re = Str.regexp
"%s" in
817 let command = Str.global_replace
re state.path
conf.pathlauncher
in
820 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
826 type 'a t
= | Res
of 'a
| Exn
of exn
;;
829 try Res
(Unix.pipe ())
834 try tempfailureretry
Unix.close fd
835 with exn
-> f
(exntos exn
)
839 try Res
(tempfailureretry
Unix.dup fd
)
844 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
849 let redirectstderr () =
850 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
851 if conf.redirectstderr
853 match Ne.pipe () with
855 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
858 begin match Ne.dup Unix.stderr
with
860 dolog
"failed to dup stderr: %s" (exntos exn
);
861 Ne.clo r
(clofail "pipe/r");
862 Ne.clo w
(clofail "pipe/w");
864 | Ne.Res dupstderr
->
865 begin match Ne.dup2 w
Unix.stderr
with
867 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
868 Ne.clo dupstderr
(clofail "stderr duplicate");
869 Ne.clo r
(clofail "redir pipe/r");
870 Ne.clo w
(clofail "redir pipe/w");
873 state.stderr
<- dupstderr
;
874 state.errfd
<- Some r
;
878 state.newerrmsgs
<- false;
879 begin match state.errfd
with
881 begin match Ne.dup2 state.stderr
Unix.stderr
with
883 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
885 Ne.clo fd
(clofail "dup of stderr");
890 prerr_string
(Buffer.contents
state.errmsgs
);
892 Buffer.clear
state.errmsgs
;
898 let postRedisplay who
=
900 then prerr_endline
("redisplay for " ^ who
);
901 state.redisplay
<- true;
905 let getopaque pageno
=
906 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
907 with Not_found
-> None
910 let putopaque pageno opaque
=
911 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
914 let pagetranslatepoint l x y
=
915 let dy = y
- l
.pagedispy
in
916 let y = dy + l
.pagey
in
917 let dx = x
- l
.pagedispx
in
918 let x = dx + l
.pagex
in
922 let onppundermouse g
x y d
=
925 begin match getopaque l
.pageno
with
927 let x0 = l
.pagedispx
in
928 let x1 = x0 + l
.pagevw
in
929 let y0 = l
.pagedispy
in
930 let y1 = y0 + l
.pagevh
in
931 if y >= y0 && y <= y1 && x >= x0 && x <= x1
933 let px, py
= pagetranslatepoint l
x y in
934 match g opaque l
px py
with
947 let g opaque l
px py
=
950 match rectofblock opaque
px py
with
952 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
953 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
954 G.postRedisplay "getunder";
957 match whatsunder opaque
px py
with
959 | under
-> Some under
961 onppundermouse g x y Unone
966 match unproject opaque
x y with
967 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
970 onppundermouse g x y None
;
974 state.text
<- Printf.sprintf
"%c%s" c s
;
975 G.postRedisplay "showtext";
979 let g opaque l
px py
=
980 if markunder opaque
px py
conf.paxmark
983 match getopaque l
.pageno
with
986 match Ne.pipe () with
990 "can not create mark pipe: %s"
993 let doclose what fd
=
994 Ne.clo fd
(fun msg
->
995 dolog
"%s close failed: %s" what msg
)
998 popen conf.paxcmd
[r
, 0; w
, -1];
999 copysel w opaque
false;
1001 G.postRedisplay "paxunder";
1003 dolog
"can not execute %S: %s"
1004 conf.paxcmd
(exntos exn
);
1011 G.postRedisplay "paxunder";
1012 if conf.paxmark
= Mark_page
1015 match getopaque l
.pageno
with
1017 | Some opaque
-> clearmark opaque
) state.layout
;
1019 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1023 match Ne.pipe () with
1025 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1028 try popen conf.selcmd
[r
, 0; w
, -1]; true
1031 (Printf.sprintf
"failed to execute %s: %s"
1032 conf.selcmd
(exntos exn
));
1036 Ne.clo fd
(fun msg
->
1037 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1043 let l = String.length s
in
1044 let n = tempfailureretry
(Unix.write w s
0) l in
1049 "failed to write %d characters to sel pipe, wrote %d"
1054 (Printf.sprintf
"failed to write to sel pipe: %s"
1063 let undertext = function
1066 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1067 | Utext s
-> "font: " ^ s
1068 | Uunexpected s
-> "unexpected: " ^ s
1069 | Ulaunch s
-> "launch: " ^ s
1070 | Unamed s
-> "named: " ^ s
1071 | Uremote
(filename
, pageno
) ->
1072 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1073 | Uremotedest
(filename
, destname
) ->
1074 Printf.sprintf
"%s: destination %S" filename destname
1077 let updateunder x y =
1078 match getunder x y with
1079 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1081 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1082 Wsi.setcursor
Wsi.CURSOR_INFO
1083 | Ulinkgoto
(pageno
, _
) ->
1085 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1086 Wsi.setcursor
Wsi.CURSOR_INFO
1088 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1089 Wsi.setcursor
Wsi.CURSOR_TEXT
1091 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1092 Wsi.setcursor
Wsi.CURSOR_INHERIT
1094 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1095 Wsi.setcursor
Wsi.CURSOR_INHERIT
1097 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1098 Wsi.setcursor
Wsi.CURSOR_INHERIT
1099 | Uremote
(filename
, pageno
) ->
1100 if conf.underinfo
then showtext 'r'
1101 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1102 Wsi.setcursor
Wsi.CURSOR_INFO
1103 | Uremotedest
(filename
, destname
) ->
1104 if conf.underinfo
then showtext 'r'
1105 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1106 Wsi.setcursor
Wsi.CURSOR_INFO
1109 let showlinktype under
=
1115 let s = undertext under
in
1120 let b = Buffer.create
(String.length
s + 1) in
1121 Buffer.add_string
b s;
1122 Buffer.add_char
b c
;
1126 module type TextEnumType
=
1130 val names
: string array
1133 module TextEnumMake
(Ten
: TextEnumType
) =
1135 let names = Ten.names;;
1136 let to_int (t
: Ten.t
) = Obj.magic t
;;
1137 let to_string t
= names.(to_int t
);;
1138 let of_int n : Ten.t
= Obj.magic
n;;
1141 if i
= Array.length
names
1142 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1144 if Ten.names.(i
) = s
1151 module CSTE
= TextEnumMake
(struct
1152 type t
= colorspace
;;
1153 let name = "colorspace";;
1154 let names = [|"rgb"; "bgr"; "gray"|];;
1157 module MTE
= TextEnumMake
(struct
1160 let names = [|"page"; "block"; "line"; "word"|];;
1163 module FMTE
= TextEnumMake
(struct
1165 let name = "fitmodel";;
1166 let names = [|"width"; "proportional"; "page"|];;
1169 let intentry_with_suffix text key
=
1171 if key
>= 32 && key
< 127
1175 match Char.lowercase
c with
1177 let text = addchar text c in
1180 | 'k'
| 'm'
| '
g'
->
1181 let text = addchar text c in
1185 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1189 let multicolumns_to_string (n, a
, b) =
1191 then Printf.sprintf
"%d" n
1192 else Printf.sprintf
"%d,%d,%d" n a
b;
1195 let multicolumns_of_string s =
1197 (int_of_string
s, 0, 0)
1199 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1201 then failwith
"subtly broken"; (n, a
, b)
1207 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1208 if n != 4 then error
"incomplete read(len) = %d" n;
1210 lor (Char.code
s.[0] lsl 24)
1211 lor (Char.code
s.[1] lsl 16)
1212 lor (Char.code
s.[2] lsl 8)
1213 lor (Char.code
s.[3] lsl 0)
1215 let s = String.create
len in
1216 let n = tempfailureretry
(Unix.read fd
s 0) len in
1217 if n != len then error
"incomplete read(data) %d vs %d" n len;
1221 let btod b = if b then 1 else 0;;
1224 let b = Buffer.create
16 in
1225 Buffer.add_string
b "llll";
1228 let s = Buffer.contents
b in
1229 let n = String.length
s in
1231 (* dolog "wcmd %S" (String.sub s 4 len); *)
1232 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1233 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1234 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1235 s.[3] <- Char.chr
(len land 0xff);
1236 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1237 if n'
!= n then error
"write failed %d vs %d" n'
n;
1242 let d = state.winh
- h
in
1243 max
conf.interpagespace
((d + 1) / 2)
1246 let rowyh (c, coverA
, coverB
) b n =
1247 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1249 let _, _, vy
, (_, _, h
, _) = b.(n) in
1252 let n'
= n - coverA
in
1255 let e = min
state.pagecount
(s + c) in
1256 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1257 let _, _, y, (_, _, h
, _) = b.(m
) in
1258 let miny = min
miny y in
1259 let maxh = max
maxh h
in
1260 find (m
+1) miny maxh
1265 match conf.columns
with
1266 | Cmulti
((_, _, _) as cl
, b) ->
1267 if Array.length
b > 0
1269 let y, h
= rowyh cl
b (Array.length
b - 1) in
1270 y + h
+ (if conf.presentation
then calcips h
else 0)
1273 if Array.length
b > 0
1275 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1276 y + h
+ (if conf.presentation
then calcips h
else 0)
1279 if Array.length
b > 0
1281 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1286 let getpageywh pageno
=
1287 let pageno = bound pageno 0 (state.pagecount
-1) in
1288 match conf.columns
with
1290 if Array.length
b = 0
1293 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1295 if conf.presentation
1301 if Array.length
b = 0
1304 let y, h
= rowyh cl
b pageno in
1305 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1307 if conf.presentation
1313 if Array.length
b = 0
1317 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1321 let getpageyh pageno =
1322 let y,_,h
= getpageywh pageno in
1326 let getpagedim pageno =
1329 | (n, _, _, _) as pdim
:: rest
->
1331 then (if n = pageno then pdim
else ppdim
)
1336 f (-1, -1, -1, -1) state.pdims
1339 let getpagey pageno = fst
(getpageyh pageno);;
1341 let nogeomcmds cmds
=
1343 | s, [] -> emptystr
s
1348 let ((c, coverA
, coverB
) as cl
), b =
1349 match conf.columns
with
1350 | Csingle
b -> (1, 0, 0), b
1351 | Cmulti
(c, b) -> c, b
1352 | Csplit
(_, b) -> (1, 0, 0), b
1354 if Array.length
b = 0
1357 let rec bsearch nmin nmax
=
1359 then bound nmin
0 (state.pagecount
-1)
1361 let n = (nmax
+ nmin
) / 2 in
1362 let vy, h
= rowyh cl
b n in
1364 if conf.presentation
1366 let ips = calcips h
in
1367 let y0 = vy - ips in
1368 let y1 = vy + h
+ ips in
1372 then 0, vy + h
+ conf.interpagespace
1374 let y0 = vy - conf.interpagespace
in
1375 y0, y0 + h
+ conf.interpagespace
1378 if y >= y0 && y < y1
1385 if n < state.pagecount
- coverB
1386 then ((n-coverA
)/c)*c + coverA
1393 then bsearch (n+1) nmax
1394 else bsearch nmin
(n-1)
1397 bsearch 0 (state.pagecount
-1);
1400 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1401 let sh = sh - (hscrollh ()) in
1402 let rec fold accu
n =
1403 if n = Array.length
b
1406 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1409 || n = state.pagecount
- coverB
1410 || (n - coverA
) mod columns
= columns
- 1)
1416 let pagey = max
0 (y - vy) in
1417 let pagedispy = if pagey > 0 then 0 else vy - y in
1418 let pagedispx, pagex
=
1420 if n = coverA
- 1 || n = state.pagecount
- coverB
1421 then state.x + (wadjsb state.winw
- w
) / 2
1422 else dx + xoff
+ state.x
1429 let vw = wadjsb state.winw
- pagedispx in
1430 let pw = w
- pagex
in
1433 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1434 if pagevw > 0 && pagevh > 0
1438 ; pagedimno
= pdimno
1445 ; pagedispx = pagedispx
1446 ; pagedispy = pagedispy
1458 if Array.length
b = 0
1460 else List.rev
(fold [] (page_of_y y))
1463 let layoutS (columns
, b) y sh =
1464 let sh = sh - hscrollh () in
1465 let rec fold accu n =
1466 if n = Array.length
b
1469 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1476 let x = xoff
+ state.x in
1477 let pagey = max
0 (y - vy) in
1478 let pagedispy = if pagey > 0 then 0 else vy - y in
1479 let pagedispx, pagex
=
1493 let pagecolw = pagew
/columns
in
1495 if pagecolw < state.winw
1496 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1500 let vw = wadjsb state.winw
- pagedispx in
1501 let pw = pagew
- pagex
in
1504 let pagevw = min
pagevw pagecolw in
1505 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1506 if pagevw > 0 && pagevh > 0
1509 { pageno = n/columns
1510 ; pagedimno
= pdimno
1517 ; pagedispx = pagedispx
1518 ; pagedispy = pagedispy
1519 ; pagecol
= n mod columns
1530 List.rev
(fold [] 0)
1534 if nogeomcmds state.geomcmds
1536 match conf.columns
with
1537 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1538 | Cmulti
c -> layoutN c y sh
1539 | Csplit
s -> layoutS s y sh
1544 let y = state.y + incr
in
1546 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1551 let tilex = l.pagex
mod conf.tilew
in
1552 let tiley = l.pagey mod conf.tileh
in
1554 let col = l.pagex
/ conf.tilew
in
1555 let row = l.pagey / conf.tileh
in
1557 let rec rowloop row y0 dispy h
=
1561 let dh = conf.tileh
- y0 in
1562 let dh = min h
dh in
1563 let rec colloop col x0 dispx w
=
1567 let dw = conf.tilew
- x0 in
1568 let dw = min w
dw in
1570 f col row dispx dispy
x0 y0 dw dh;
1571 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1574 colloop col tilex l.pagedispx l.pagevw;
1575 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1578 if l.pagevw > 0 && l.pagevh > 0
1579 then rowloop row tiley l.pagedispy l.pagevh;
1582 let gettileopaque l col row =
1584 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1586 try Some
(Hashtbl.find state.tilemap
key)
1587 with Not_found
-> None
1590 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1591 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1592 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1595 let filledrect x0 y0 x1 y1 =
1596 GlArray.disable `texture_coord
;
1597 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1598 GlArray.vertex `two
state.vraw
;
1599 GlArray.draw_arrays `triangle_strip
0 4;
1600 GlArray.enable `texture_coord
;
1603 let linerect x0 y0 x1 y1 =
1604 GlArray.disable `texture_coord
;
1605 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1606 GlArray.vertex `two
state.vraw
;
1607 GlArray.draw_arrays `line_loop
0 4;
1608 GlArray.enable `texture_coord
;
1611 let drawtiles l color
=
1614 let f col row x y tilex tiley w h
=
1615 match gettileopaque l col row with
1616 | Some
(opaque
, _, t
) ->
1617 let params = x, y, w
, h
, tilex, tiley in
1621 GlFunc.blend_func `zero `one_minus_src_color
;
1623 drawtile
params opaque
;
1625 then Gl.disable `blend
;
1629 let s = Printf.sprintf
1633 let w = measurestr
fstate.fontsize
s in
1634 GlDraw.color
(0.0, 0.0, 0.0);
1635 filledrect (float (x-2))
1638 (float (y + fstate.fontsize
+ 2));
1639 GlDraw.color
(1.0, 1.0, 1.0);
1640 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1647 let lw = wadjsb state.winw
- x in
1650 let lh = state.winh
- y in
1656 GlFunc.blend_func `zero `one_minus_src_color
;
1658 begin match state.texid
with
1660 Gl.enable `texture_2d
;
1661 GlTex.bind_texture `texture_2d id
;
1664 and x1 = float (x+w)
1665 and y1 = float (y+h
) in
1667 let tw = float w /. 16.0
1668 and th
= float h
/. 16.0 in
1669 let tx0 = float tilex /. 16.0
1670 and ty0
= float tiley /. 16.0 in
1672 and ty1
= ty0
+. th
in
1673 Raw.sets_float
state.vraw ~pos
:0
1674 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1675 Raw.sets_float
state.traw ~pos
:0
1676 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1677 GlArray.vertex `two
state.vraw
;
1678 GlArray.tex_coord `two
state.traw
;
1679 GlArray.draw_arrays `triangle_strip
0 4;
1682 GlDraw.color
(1.0, 1.0, 1.0);
1683 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1685 if w > 128 && h
> fstate.fontsize
+ 10
1687 let c = if conf.invert
then 1.0 else 0.0 in
1688 GlDraw.color
(c, c, c);
1691 then (col*conf.tilew
, row*conf.tileh
)
1694 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1703 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1705 let tilevisible1 l x y =
1707 and ax1
= l.pagex
+ l.pagevw
1709 and ay1
= l.pagey + l.pagevh in
1713 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1714 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1716 let rx0 = max
ax0 bx0
1717 and ry0
= max ay0 by0
1718 and rx1
= min ax1
bx1
1719 and ry1
= min ay1 by1
in
1721 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1722 nonemptyintersection
1725 let tilevisible layout n x y =
1726 let rec findpageinlayout m
= function
1727 | l :: rest
when l.pageno = n ->
1728 tilevisible1 l x y || (
1729 match conf.columns
with
1730 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1733 | _ :: rest
-> findpageinlayout 0 rest
1736 findpageinlayout 0 layout;
1739 let tileready l x y =
1740 tilevisible1 l x y &&
1741 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1744 let tilepage n p
layout =
1745 let rec loop = function
1749 let f col row _ _ _ _ _ _ =
1750 if state.currently
= Idle
1752 match gettileopaque l col row with
1755 let x = col*conf.tilew
1756 and y = row*conf.tileh
in
1758 let w = l.pagew
- x in
1762 let h = l.pageh
- y in
1767 then getpbo
w h conf.colorspace
1770 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1773 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1774 conf.tilew
, conf.tileh
1783 if nogeomcmds state.geomcmds
1787 let preloadlayout y =
1788 let y = if y < state.winh
then 0 else y - state.winh
in
1789 let h = state.winh
*3 in
1794 let rec loop pages
=
1795 if state.currently
!= Idle
1800 begin match getopaque l.pageno with
1802 wcmd "page %d %d" l.pageno l.pagedimno
;
1803 state.currently
<- Loading
(l, state.gen
);
1805 tilepage l.pageno opaque pages
;
1810 if nogeomcmds state.geomcmds
1816 if conf.preload && state.currently
= Idle
1817 then load (preloadlayout state.y);
1820 let layoutready layout =
1821 let rec fold all ls
=
1822 all
&& match ls
with
1824 let seen = ref false in
1825 let allvisible = ref true in
1826 let foo col row _ _ _ _ _ _ =
1828 allvisible := !allvisible &&
1829 begin match gettileopaque l col row with
1835 fold (!seen && !allvisible) rest
1838 let alltilesvisible = fold true layout in
1843 let y = bound y 0 state.maxy
in
1844 let y, layout, proceed
=
1845 match conf.maxwait
with
1846 | Some time
when state.ghyll
== noghyll ->
1847 begin match state.throttle
with
1849 let layout = layout y state.winh
in
1850 let ready = layoutready layout in
1854 state.throttle
<- Some
(layout, y, now ());
1856 else G.postRedisplay "gotoy showall (None)";
1858 | Some
(_, _, started
) ->
1859 let dt = now () -. started
in
1862 state.throttle
<- None
;
1863 let layout = layout y state.winh
in
1865 G.postRedisplay "maxwait";
1872 let layout = layout y state.winh
in
1873 if not
!wtmode || layoutready layout
1874 then G.postRedisplay "gotoy ready";
1880 state.layout <- layout;
1881 begin match state.mode
with
1882 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1883 let rec loop = function
1885 state.mode
<- LinkNav
(Ltgendir
0)
1886 | l :: _ when l.pageno = pageno ->
1887 begin match getopaque pageno with
1889 state.mode
<- LinkNav
(Ltgendir
0)
1891 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1892 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1893 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1894 then state.mode
<- LinkNav
(Ltgendir
0)
1896 | _ :: rest
-> loop rest
1901 begin match state.mode
with
1902 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1903 if not
(pagevisible layout pageno)
1905 match state.layout with
1908 state.mode
<- Birdseye
(
1909 conf, leftx
, l.pageno, hooverpageno
, anchor
1912 | LinkNav
(Ltgendir dir
as lt
) ->
1914 let rec loop = function
1917 match getopaque l.pageno with
1923 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1925 if dir
> 0 then LDfirst
else LDlast
1931 | Lnotfound
-> loop rest
1933 showlinktype (getlink opaque
n);
1934 Ltexact
(l.pageno, n)
1938 state.mode
<- LinkNav
linknav
1943 state.ghyll
<- noghyll;
1946 let mx, my
= state.mpos
in
1951 let conttiling pageno opaque
=
1952 tilepage pageno opaque
1953 (if conf.preload then preloadlayout state.y else state.layout)
1956 let gotoy_and_clear_text y =
1957 if not
conf.verbose
then state.text <- "";
1963 let coloff = l.pagecol
* l.pageh
in
1964 float (l.pagey + coloff) /. float l.pageh
1971 if conf.presentation
1972 then float l.pagedispy /. float (calcips l.pageh
)
1973 else float l.pagedispy /. float conf.interpagespace
1976 (l.pageno, top, dtop)
1980 match state.layout with
1981 | l :: _ -> getanchor1 l
1983 let n = page_of_y state.y in
1987 let y, h = getpageyh n in
1988 let dy = y - state.y in
1990 if conf.presentation
1992 let ips = calcips h in
1993 float (dy + ips) /. float ips
1995 float dy /. float conf.interpagespace
2000 let getanchory (n, top, dtop) =
2001 let y, h = getpageyh n in
2002 if conf.presentation
2004 let ips = calcips h in
2005 y + truncate
(top*.float h -. dtop*.float ips) + ips;
2007 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
2010 let gotoanchor anchor
=
2011 gotoy (getanchory anchor
);
2015 cbput state.hists
.nav
(getanchor ());
2019 let anchor = cbgetc state.hists
.nav dir
in
2024 let scroll f n a
b =
2025 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2027 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2029 then s (float f /. float a
)
2032 then 1.0 -. s ((float (f-b) /. float (n-b)))
2038 let ins = float a
*. 0.5
2039 and outs
= float (n-b) *. 0.5 in
2041 ins +. outs
+. float ones
2043 let rec set (_N
, _A
, _B
) y sy
=
2044 let sum = summa _N _A _B
in
2045 let dy = float (y - sy
) in
2049 then state.ghyll
<- noghyll
2052 let s = scroll n _N _A _B
in
2053 let y1 = y1 +. ((s *. dy) /. sum) in
2054 gotoy_and_clear_text (truncate
y1);
2055 state.ghyll
<- gf (n+1) y1;
2059 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2061 gf 0 (float state.y)
2064 match conf.ghyllscroll
with
2066 gotoy_and_clear_text y
2068 if state.ghyll
== noghyll
2069 then set nab
y state.y
2070 else state.ghyll
(Some
y)
2073 let gotopage n top =
2074 let y, h = getpageyh n in
2075 let y = y + (truncate
(top *. float h)) in
2079 let gotopage1 n top =
2080 let y = getpagey n in
2085 let invalidate s f =
2090 match state.geomcmds
with
2091 | ps
, [] when emptystr ps
->
2093 state.geomcmds
<- s, [];
2096 state.geomcmds
<- ps
, [s, f];
2098 | ps
, (s'
, _) :: rest
when s'
= s ->
2099 state.geomcmds
<- ps
, ((s, f) :: rest
);
2102 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2106 Hashtbl.iter
(fun _ opaque
->
2107 wcmd "freepage %s" opaque
;
2109 Hashtbl.clear
state.pagemap
;
2113 if not
(Queue.is_empty
state.tilelru
)
2115 Queue.iter
(fun (k
, p
, s) ->
2116 wcmd "freetile %s" p
;
2117 state.memused
<- state.memused
- s;
2118 Hashtbl.remove
state.tilemap k
;
2120 state.uioh#infochanged Memused
;
2121 Queue.clear
state.tilelru
;
2127 let h = truncate
(float h*.conf.zoom
) in
2128 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2132 let opendoc path password
=
2134 state.password
<- password
;
2135 state.gen
<- state.gen
+ 1;
2136 state.docinfo
<- [];
2139 setaalevel
conf.aalevel
;
2141 if emptystr
state.origin
2145 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2146 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2147 invalidate "reqlayout"
2149 wcmd "reqlayout %d %d %d %s\000"
2150 conf.angle
(FMTE.to_int conf.fitmodel
)
2151 (stateh state.winh
) state.nameddest
2156 state.anchor <- getanchor ();
2157 opendoc state.path
state.password
;
2161 let c = c *. conf.colorscale
in
2165 let scalecolor2 (r
, g, b) =
2166 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2169 let docolumns = function
2171 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2172 let rec loop pageno pdimno pdim
y ph pdims
=
2173 if pageno = state.pagecount
2176 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2178 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2179 pdimno+1, pdim
, rest
2183 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2185 (if conf.presentation
2186 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2187 else (if pageno = 0 then 0 else conf.interpagespace
)
2190 a.(pageno) <- (pdimno, x, y, pdim
);
2191 loop (pageno+1) pdimno pdim
(y + h) h pdims
2193 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2194 conf.columns
<- Csingle
a;
2196 | Cmulti
((columns
, coverA
, coverB
), _) ->
2197 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2198 let rec loop pageno pdimno pdim
x y rowh pdims
=
2199 let rec fixrow m
= if m
= pageno then () else
2200 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2203 let y = y + (rowh
- h) / 2 in
2204 a.(m
) <- (pdimno, x, y, pdim
);
2208 if pageno = state.pagecount
2209 then fixrow (((pageno - 1) / columns
) * columns
)
2211 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2213 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2214 pdimno+1, pdim
, rest
2219 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2221 let x = (wadjsb state.winw
- w) / 2 in
2223 if conf.presentation
then calcips h else conf.interpagespace
in
2224 x, y + ips + rowh
, h
2227 if (pageno - coverA
) mod columns
= 0
2229 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2231 if conf.presentation
2233 let ips = calcips h in
2234 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2236 y + (if pageno = 0 then 0 else conf.interpagespace
)
2240 else x, y, max rowh
h
2244 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2247 if pageno = columns
&& conf.presentation
2249 let ips = calcips rowh
in
2250 for i
= 0 to pred columns
2252 let (pdimno, x, y, pdim
) = a.(i
) in
2253 a.(i
) <- (pdimno, x, y+ips, pdim
)
2259 fixrow (pageno - columns
);
2264 a.(pageno) <- (pdimno, x, y, pdim
);
2265 let x = x + w + xoff
*2 + conf.interpagespace
in
2266 loop (pageno+1) pdimno pdim
x y rowh' pdims
2268 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2269 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2272 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2273 let rec loop pageno pdimno pdim
y pdims
=
2274 if pageno = state.pagecount
2277 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2279 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2280 pdimno+1, pdim
, rest
2285 let rec loop1 n x y =
2286 if n = c then y else (
2287 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2288 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2291 let y = loop1 0 0 y in
2292 loop (pageno+1) pdimno pdim
y pdims
2294 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2295 conf.columns
<- Csplit
(c, a);
2299 docolumns conf.columns
;
2300 state.maxy
<- calcheight ();
2301 if state.reprf
== noreprf
2303 match state.mode
with
2304 | Birdseye
(_, _, pageno, _, _) ->
2305 let y, h = getpageyh pageno in
2306 let top = (state.winh
- h) / 2 in
2307 gotoy (max
0 (y - top))
2308 | _ -> gotoanchor state.anchor
2312 state.reprf
<- noreprf;
2317 GlDraw.viewport
0 0 w h;
2318 let firsttime = state.geomcmds
== firstgeomcmds in
2319 if not
firsttime && nogeomcmds state.geomcmds
2320 then state.anchor <- getanchor ();
2323 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2326 setfontsize fstate.fontsize
;
2327 GlMat.mode `modelview
;
2328 GlMat.load_identity
();
2330 GlMat.mode `projection
;
2331 GlMat.load_identity
();
2332 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2333 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2334 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2339 else float state.x /. float state.w
2341 invalidate "geometry"
2345 then state.x <- truncate
(relx *. float w);
2347 match conf.columns
with
2349 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2350 | Csplit
(c, _) -> w * c
2352 wcmd "geometry %d %d %d"
2353 w (stateh h) (FMTE.to_int conf.fitmodel
)
2358 let len = String.length
state.text in
2361 match state.mode
with
2362 | Textentry
_ | View
| LinkNav
_ ->
2363 let h, _, _ = state.uioh#scrollpw
in
2368 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2369 (x+.w) (float (state.winh
- hscrollh))
2372 let w = float (wadjsb state.winw
- 1) in
2373 if state.progress
>= 0.0 && state.progress
< 1.0
2375 GlDraw.color
(0.3, 0.3, 0.3);
2376 let w1 = w *. state.progress
in
2378 GlDraw.color
(0.0, 0.0, 0.0);
2382 GlDraw.color
(0.0, 0.0, 0.0);
2386 GlDraw.color
(1.0, 1.0, 1.0);
2387 drawstring fstate.fontsize
2388 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2391 match state.mode
with
2392 | Textentry
((prefix
, text, _, _, _, _), _) ->
2396 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2398 Printf.sprintf
"%s%s_" prefix
text
2407 if not
(istextentry state.mode
) && state.uioh#eformsgs
2409 let s1 = "(press 'e' to review error messasges)" in
2410 if nonemptystr
s then s ^
" " ^
s1 else s1
2420 let len = Queue.length
state.tilelru
in
2422 match state.throttle
with
2425 then preloadlayout state.y
2427 | Some
(layout, _, _) ->
2431 if state.memused
<= conf.memlimit
2436 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2437 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2438 let (_, pw, ph
, _) = getpagedim n in
2441 && colorspace
= conf.colorspace
2442 && angle
= conf.angle
2446 let x = col*conf.tilew
2447 and y = row*conf.tileh
in
2448 tilevisible (Lazy.force_val
layout) n x y
2450 then Queue.push lruitem
state.tilelru
2453 wcmd "freetile %s" p
;
2454 state.memused
<- state.memused
- s;
2455 state.uioh#infochanged Memused
;
2456 Hashtbl.remove
state.tilemap k
;
2464 let logcurrently = function
2465 | Idle
-> dolog
"Idle"
2466 | Loading
(l, gen
) ->
2467 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2468 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2470 "Tiling %d[%d,%d] page=%s cs=%s angle"
2471 l.pageno col row pageopaque
2472 (CSTE.to_string colorspace
)
2474 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2475 angle gen
conf.angle
state.gen
2477 conf.tilew
conf.tileh
2484 let r = Str.regexp
" " in
2485 fun s -> Str.bounded_split
r s 2;
2488 let onpagerect pageno f =
2490 match conf.columns
with
2491 | Cmulti
(_, b) -> b
2493 | Csplit
(_, b) -> b
2495 if pageno >= 0 && pageno < Array.length
b
2497 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2501 let gotopagexy1 pageno x y =
2502 let _,w1,h1
,leftx
= getpagedim pageno in
2503 let top = y /. (float h1
) in
2504 let left = x /. (float w1) in
2505 let py, w, h = getpageywh pageno in
2506 let wh = state.winh
- hscrollh () in
2507 let x = left *. (float w) in
2508 let x = leftx
+ state.x + truncate
x in
2510 if x < 0 || x >= wadjsb state.winw
2514 let pdy = truncate
(top *. float h) in
2515 let y'
= py + pdy in
2516 let dy = y'
- state.y in
2518 if x != state.x || not
(dy > 0 && dy < wh)
2520 if conf.presentation
2522 if abs
(py - y'
) > wh
2529 if state.x != sx || state.y != sy
2534 let ww = wadjsb state.winw
in
2536 and qy
= pdy / wh in
2538 and y = py + qy
* wh in
2539 let x = if -x + ww > w1 then -(w1-ww) else x
2540 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2542 if conf.presentation
2544 if abs
(py - y'
) > wh
2554 gotoy_and_clear_text y;
2556 else gotoy_and_clear_text state.y;
2559 let gotopagexy pageno x y =
2560 match state.mode
with
2561 | Birdseye
_ -> gotopage pageno 0.0
2562 | _ -> gotopagexy1 pageno x y
2566 (* dolog "%S" cmds; *)
2567 let cl = splitatspace cmds
in
2569 try Scanf.sscanf
s fmt
f
2571 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2574 let addoutline outline
=
2575 match state.currently
with
2576 | Outlining outlines
->
2577 state.currently
<- Outlining
(outline
:: outlines
)
2578 | Idle
-> state.currently
<- Outlining
[outline
]
2580 dolog
"invalid outlining state";
2581 logcurrently currently
2585 state.uioh#infochanged Pdim
;
2588 | "clearrects" :: [] ->
2589 state.rects
<- state.rects1
;
2590 G.postRedisplay "clearrects";
2592 | "continue" :: args :: [] ->
2593 let n = scan args "%u" (fun n -> n) in
2594 state.pagecount
<- n;
2595 begin match state.currently
with
2597 state.currently
<- Idle
;
2598 state.outlines
<- Array.of_list
(List.rev
l)
2602 let cur, cmds
= state.geomcmds
in
2604 then failwith
"umpossible";
2606 begin match List.rev cmds
with
2608 state.geomcmds
<- "", [];
2612 state.geomcmds
<- s, List.rev rest
;
2614 if conf.maxwait
= None
&& not
!wtmode
2615 then G.postRedisplay "continue";
2617 | "title" :: args :: [] ->
2620 | "msg" :: args :: [] ->
2623 | "vmsg" :: args :: [] ->
2625 then showtext ' '
args
2627 | "emsg" :: args :: [] ->
2628 Buffer.add_string
state.errmsgs
args;
2629 state.newerrmsgs
<- true;
2630 G.postRedisplay "error message"
2632 | "progress" :: args :: [] ->
2633 let progress, text =
2636 f, String.sub
args pos
(String.length
args - pos
))
2639 state.progress <- progress;
2640 G.postRedisplay "progress"
2642 | "firstmatch" :: args :: [] ->
2643 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2644 scan args "%u %d %f %f %f %f %f %f %f %f"
2645 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2646 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2648 let y = (getpagey pageno) + truncate
y0 in
2651 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2653 | "match" :: args :: [] ->
2654 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2655 scan args "%u %d %f %f %f %f %f %f %f %f"
2656 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2657 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2660 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2662 | "page" :: args :: [] ->
2663 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2664 begin match state.currently
with
2665 | Loading
(l, gen
) ->
2666 vlog "page %d took %f sec" l.pageno t
;
2667 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2668 begin match state.throttle
with
2670 let preloadedpages =
2672 then preloadlayout state.y
2677 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2678 IntSet.empty
preloadedpages
2681 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2682 if not
(IntSet.mem
pageno set)
2684 wcmd "freepage %s" opaque
;
2690 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2693 state.currently
<- Idle
;
2696 tilepage l.pageno pageopaque state.layout;
2698 load preloadedpages;
2699 if pagevisible state.layout l.pageno
2700 && layoutready state.layout
2701 then G.postRedisplay "page";
2704 | Some
(layout, _, _) ->
2705 state.currently
<- Idle
;
2706 tilepage l.pageno pageopaque layout;
2711 dolog
"Inconsistent loading state";
2712 logcurrently state.currently
;
2716 | "tile" :: args :: [] ->
2717 let (x, y, opaque
, size
, t
) =
2718 scan args "%u %u %s %u %f"
2719 (fun x y p size t
-> (x, y, p
, size
, t
))
2721 begin match state.currently
with
2722 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2723 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2726 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2728 wcmd "freetile %s" opaque
;
2729 state.currently
<- Idle
;
2733 puttileopaque l col row gen cs angle opaque size t
;
2734 state.memused
<- state.memused
+ size
;
2735 state.uioh#infochanged Memused
;
2737 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2738 opaque
, size
) state.tilelru
;
2741 match state.throttle
with
2742 | None
-> state.layout
2743 | Some
(layout, _, _) -> layout
2746 state.currently
<- Idle
;
2748 && conf.colorspace
= cs
2749 && conf.angle
= angle
2750 && tilevisible layout l.pageno x y
2751 then conttiling l.pageno pageopaque;
2753 begin match state.throttle
with
2755 preload state.layout;
2757 && conf.colorspace
= cs
2758 && conf.angle
= angle
2759 && tilevisible state.layout l.pageno x y
2760 && (not
!wtmode || layoutready state.layout)
2761 then G.postRedisplay "tile nothrottle";
2763 | Some
(layout, y, _) ->
2764 let ready = layoutready layout in
2768 state.layout <- layout;
2769 state.throttle
<- None
;
2770 G.postRedisplay "throttle";
2777 dolog
"Inconsistent tiling state";
2778 logcurrently state.currently
;
2782 | "pdim" :: args :: [] ->
2783 let (n, w, h, _) as pdim
=
2784 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2787 match conf.fitmodel
, conf.columns
with
2788 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2791 state.uioh#infochanged Pdim
;
2792 state.pdims
<- pdim :: state.pdims
2794 | "o" :: args :: [] ->
2795 let (l, n, t
, h, pos
) =
2796 scan args "%u %u %d %u %n"
2797 (fun l n t
h pos
-> l, n, t
, h, pos
)
2799 let s = String.sub
args pos
(String.length
args - pos
) in
2800 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
2802 | "ou" :: args :: [] ->
2803 let (l, len, pos
) = scan args "%u %u %n" (fun l len pos
-> l, len, pos
) in
2804 let s = String.sub
args pos
len in
2805 let pos2 = pos
+ len + 1 in
2806 let uri = String.sub
args pos2 (String.length
args - pos2) in
2807 addoutline (s, l, Ouri
uri)
2809 | "on" :: args :: [] ->
2810 let (l, pos
) = scan args "%u %n" (fun l pos
-> l, pos
) in
2811 let s = String.sub
args pos
(String.length
args - pos
) in
2812 addoutline (s, l, Onone
)
2814 | "a" :: args :: [] ->
2816 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2818 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2820 | "info" :: args :: [] ->
2821 state.docinfo
<- (1, args) :: state.docinfo
2823 | "infoend" :: [] ->
2824 state.uioh#infochanged Docinfo
;
2825 state.docinfo
<- List.rev
state.docinfo
2828 error
"unknown cmd `%S'" cmds
2833 let action = function
2834 | HCprev
-> cbget cb ~
-1
2835 | HCnext
-> cbget cb
1
2836 | HCfirst
-> cbget cb ~
-(cb
.rc)
2837 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2838 and cancel
() = cb
.rc <- rc
2842 let search pattern forward
=
2843 match conf.columns
with
2845 showtext '
!'
"searching does not work properly in split columns mode"
2847 if nonemptystr pattern
2850 match state.layout with
2853 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2855 wcmd "search %d %d %d %d,%s\000"
2856 (btod conf.icase
) pn py (btod forward
) pattern
;
2859 let intentry text key =
2861 if key >= 32 && key < 127
2867 let text = addchar text c in
2871 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2875 let linknentry text key =
2877 if key >= 32 && key < 127
2883 let text = addchar text c in
2887 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2895 let l = String.length
s in
2896 let rec loop pos
n = if pos
= l then n else
2897 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2898 loop (pos
+1) (n*26 + m)
2901 let rec loop n = function
2904 match getopaque l.pageno with
2905 | None
-> loop n rest
2907 let m = getlinkcount opaque
in
2910 let under = getlink opaque
n in
2913 else loop (n-m) rest
2915 loop n state.layout;
2919 let textentry text key =
2920 if key land 0xff00 = 0xff00
2922 else TEcont
(text ^ toutf8
key)
2925 let reqlayout angle fitmodel
=
2926 match state.throttle
with
2928 if nogeomcmds state.geomcmds
2929 then state.anchor <- getanchor ();
2930 conf.angle
<- angle
mod 360;
2933 match state.mode
with
2934 | LinkNav
_ -> state.mode
<- View
2937 conf.fitmodel
<- fitmodel
;
2938 invalidate "reqlayout"
2940 wcmd "reqlayout %d %d %d"
2941 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2946 let settrim trimmargins trimfuzz
=
2947 if nogeomcmds state.geomcmds
2948 then state.anchor <- getanchor ();
2949 conf.trimmargins
<- trimmargins
;
2950 conf.trimfuzz
<- trimfuzz
;
2951 let x0, y0, x1, y1 = trimfuzz
in
2952 invalidate "settrim"
2954 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2959 match state.throttle
with
2961 let zoom = max
0.0001 zoom in
2962 if zoom <> conf.zoom
2964 state.prevzoom
<- (conf.zoom, state.x);
2966 reshape state.winw
state.winh
;
2967 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2970 | Some
(layout, y, started
) ->
2972 match conf.maxwait
with
2976 let dt = now () -. started
in
2984 let setcolumns mode columns coverA coverB
=
2985 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2989 then showtext '
!'
"split mode doesn't work in bird's eye"
2991 conf.columns
<- Csplit
(-columns
, [||]);
2999 conf.columns
<- Csingle
[||];
3004 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
3008 reshape state.winw
state.winh
;
3011 let enterbirdseye () =
3012 let zoom = float conf.thumbw
/. float state.winw
in
3013 let birdseyepageno =
3014 let cy = state.winh
/ 2 in
3018 let rec fold best
= function
3021 let d = cy - (l.pagedispy + l.pagevh/2)
3022 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
3023 if abs
d < abs dbest
3030 state.mode
<- Birdseye
(
3031 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
3034 conf.presentation
<- false;
3035 conf.interpagespace
<- 10;
3036 conf.hlinks
<- false;
3037 conf.fitmodel
<- FitProportional
;
3039 state.mstate
<- Mnone
;
3040 conf.maxwait
<- None
;
3042 match conf.beyecolumns
with
3045 Cmulti
((c, 0, 0), [||])
3046 | None
-> Csingle
[||]
3048 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3051 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3056 reshape state.winw
state.winh
;
3059 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3061 conf.zoom <- c.zoom;
3062 conf.presentation
<- c.presentation
;
3063 conf.interpagespace
<- c.interpagespace
;
3064 conf.maxwait
<- c.maxwait
;
3065 conf.hlinks
<- c.hlinks
;
3066 conf.fitmodel
<- c.fitmodel
;
3067 conf.beyecolumns
<- (
3068 match conf.columns
with
3069 | Cmulti
((c, _, _), _) -> Some
c
3071 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3074 match c.columns
with
3075 | Cmulti
(c, _) -> Cmulti
(c, [||])
3076 | Csingle
_ -> Csingle
[||]
3077 | Csplit
(c, _) -> Csplit
(c, [||])
3081 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3084 reshape state.winw
state.winh
;
3085 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3089 let togglebirdseye () =
3090 match state.mode
with
3091 | Birdseye vals
-> leavebirdseye vals
true
3092 | View
-> enterbirdseye ()
3096 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3097 let pageno = max
0 (pageno - incr
) in
3098 let rec loop = function
3099 | [] -> gotopage1 pageno 0
3100 | l :: _ when l.pageno = pageno ->
3101 if l.pagedispy >= 0 && l.pagey = 0
3102 then G.postRedisplay "upbirdseye"
3103 else gotopage1 pageno 0
3104 | _ :: rest
-> loop rest
3107 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3110 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3111 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3112 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3113 let rec loop = function
3115 let y, h = getpageyh pageno in
3116 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3118 | l :: _ when l.pageno = pageno ->
3119 if l.pagevh != l.pageh
3120 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3121 else G.postRedisplay "downbirdseye"
3122 | _ :: rest
-> loop rest
3127 let boundastep h step
=
3129 then bound step ~
-h 0
3133 let optentry mode
_ key =
3134 let btos b = if b then "on" else "off" in
3135 if key >= 32 && key < 127
3137 let c = Char.chr
key in
3141 try conf.scrollstep
<- int_of_string
s with exc
->
3142 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3144 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3149 conf.autoscrollstep
<- boundastep state.winh
(int_of_string
s);
3150 if state.autoscroll
<> None
3151 then state.autoscroll
<- Some
conf.autoscrollstep
3153 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3155 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3160 let n, a, b = multicolumns_of_string s in
3161 setcolumns mode
n a b;
3163 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3165 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3170 let zoom = float (int_of_string
s) /. 100.0 in
3173 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3175 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3180 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3182 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3183 begin match mode
with
3185 leavebirdseye beye
false;
3190 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3192 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3197 Some
(int_of_string
s)
3199 state.text <- Printf.sprintf
"bad integer `%s': %s"
3203 | Some angle
-> reqlayout angle
conf.fitmodel
3206 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3209 conf.icase
<- not
conf.icase
;
3210 TEdone
("case insensitive search " ^
(btos conf.icase
))
3213 conf.preload <- not
conf.preload;
3215 TEdone
("preload " ^
(btos conf.preload))
3218 conf.verbose
<- not
conf.verbose
;
3219 TEdone
("verbose " ^
(btos conf.verbose
))
3222 conf.debug
<- not
conf.debug
;
3223 TEdone
("debug " ^
(btos conf.debug
))
3226 conf.maxhfit
<- not
conf.maxhfit
;
3227 state.maxy
<- calcheight ();
3228 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3231 conf.crophack
<- not
conf.crophack
;
3232 TEdone
("crophack " ^
btos conf.crophack
)
3236 match conf.maxwait
with
3238 conf.maxwait
<- Some infinity
;
3239 "always wait for page to complete"
3241 conf.maxwait
<- None
;
3242 "show placeholder if page is not ready"
3247 conf.underinfo
<- not
conf.underinfo
;
3248 TEdone
("underinfo " ^
btos conf.underinfo
)
3251 conf.savebmarks
<- not
conf.savebmarks
;
3252 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3258 match state.layout with
3263 conf.interpagespace
<- int_of_string
s;
3264 docolumns conf.columns
;
3265 state.maxy
<- calcheight ();
3266 let y = getpagey pageno in
3269 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3271 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3275 match conf.fitmodel
with
3276 | FitProportional
-> FitWidth
3277 | _ -> FitProportional
3279 reqlayout conf.angle
fm;
3280 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3283 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3284 TEdone
("trim margins " ^
btos conf.trimmargins
)
3287 conf.invert
<- not
conf.invert
;
3288 TEdone
("invert colors " ^
btos conf.invert
)
3292 cbput state.hists
.sel
s;
3295 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3296 textentry, ondone, true)
3300 then conf.pax
<- Some
(ref (0.0, 0, 0))
3301 else conf.pax
<- None
;
3302 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3305 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3311 class type lvsource
= object
3312 method getitemcount
: int
3313 method getitem
: int -> (string * int)
3314 method hasaction
: int -> bool
3323 method getactive
: int
3324 method getfirst
: int
3325 method getqsearch
: string
3326 method setqsearch
: string -> unit
3330 class virtual lvsourcebase
= object
3331 val mutable m_active
= 0
3332 val mutable m_first
= 0
3333 val mutable m_qsearch
= ""
3334 val mutable m_pan
= 0
3335 method getactive
= m_active
3336 method getfirst
= m_first
3337 method getqsearch
= m_qsearch
3338 method getpan
= m_pan
3339 method setqsearch
s = m_qsearch
<- s
3342 let withoutlastutf8 s =
3343 let len = String.length
s in
3351 let b = Char.code
s.[pos
] in
3352 if b land 0b11000000 = 0b11000000
3357 if Char.code
s.[len-1] land 0x80 = 0
3361 String.sub
s 0 first;
3364 let textentrykeyboard
3365 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3367 if key >= 0xffb0 && key <= 0xffb9
3368 then key - 0xffb0 + 48 else key
3371 state.mode
<- Textentry
(te
, onleave
);
3374 G.postRedisplay "textentrykeyboard enttext";
3376 let histaction cmd
=
3379 | Some
(action, _) ->
3380 state.mode
<- Textentry
(
3381 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3383 G.postRedisplay "textentry histaction"
3386 | 0xff08 -> (* backspace *)
3387 if emptystr
text && cancelonempty
3390 G.postRedisplay "textentrykeyboard after cancel";
3393 let s = withoutlastutf8 text in
3394 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3396 | 0xff0d | 0xff8d -> (* (kp) enter *)
3399 G.postRedisplay "textentrykeyboard after confirm"
3401 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3402 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3403 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3404 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3406 | 0xff1b -> (* escape*)
3409 begin match opthist
with
3411 | Some
(_, onhistcancel
) -> onhistcancel
()
3415 G.postRedisplay "textentrykeyboard after cancel2"
3418 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3421 | 0xff9f | 0xffff -> () (* delete *)
3424 && key land 0xff00 != 0xff00 (* keyboard *)
3425 && key land 0xfe00 != 0xfe00 (* xkb *)
3426 && key land 0xfd00 != 0xfd00 (* 3270 *)
3428 begin match onkey
text key with
3432 G.postRedisplay "textentrykeyboard after confirm2";
3435 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3439 G.postRedisplay "textentrykeyboard after cancel3"
3442 state.mode
<- Textentry
(te
, onleave
);
3443 G.postRedisplay "textentrykeyboard switch";
3447 vlog "unhandled key %s" (Wsi.keyname
key)
3450 let firstof first active
=
3451 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3452 then max
0 (active
- (fstate.maxrows
/2))
3456 let calcfirst first active
=
3459 let rows = active
- first in
3460 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3464 let scrollph y maxy
=
3465 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3466 let sh = float state.winh
/. sh in
3467 let sh = max
sh (float conf.scrollh
) in
3469 let percent = float y /. float maxy
in
3470 let position = (float state.winh
-. sh) *. percent in
3473 if position +. sh > float state.winh
3474 then float state.winh
-. sh
3480 let coe s = (s :> uioh
);;
3482 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3484 val m_pan
= source#getpan
3485 val m_first
= source#getfirst
3486 val m_active
= source#getactive
3487 val m_qsearch
= source#getqsearch
3488 val m_prev_uioh
= state.uioh
3490 method private elemunder
y =
3491 let n = y / (fstate.fontsize
+1) in
3492 if m_first
+ n < source#getitemcount
3494 if source#hasaction
(m_first
+ n)
3495 then Some
(m_first
+ n)
3502 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3503 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3504 filledrect 0. 0. (float state.winw
) (float state.winh
);
3505 GlDraw.color
(1., 1., 1.);
3506 Gl.enable `texture_2d
;
3507 let fs = fstate.fontsize
in
3509 let ww = fstate.wwidth
in
3510 let tabw = 30.0*.ww in
3511 let itemcount = source#getitemcount
in
3513 if (row - m_first
) > fstate.maxrows
3516 if row >= 0 && row < itemcount
3518 let (s, level
) = source#getitem
row in
3519 let y = (row - m_first
) * nfs in
3520 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3523 Gl.disable `texture_2d
;
3524 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3525 GlDraw.color
(1., 1., 1.) ~
alpha;
3526 linerect 1. (float (y + 1))
3527 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3528 GlDraw.color
(1., 1., 1.);
3529 Gl.enable `texture_2d
;
3532 let drawtabularstring s =
3533 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3536 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3539 let len = String.length
s - tabpos - 1 in
3540 let s1 = String.sub
s 0 tabpos
3541 and s2
= String.sub
s (tabpos + 1) len in
3542 let nx = drawstr x s1 in
3544 let x = x +. (max
tabw sw) in
3551 let _ = drawtabularstring s in
3558 Gl.disable `texture_2d
;
3560 method updownlevel incr
=
3561 let len = source#getitemcount
in
3563 if m_active
>= 0 && m_active
< len
3564 then snd
(source#getitem m_active
)
3568 if i
= len then i
-1 else if i
= -1 then 0 else
3569 let _, l = source#getitem i
in
3570 if l != curlevel then i
else flow (i
+incr
)
3572 let active = flow m_active
in
3573 let first = calcfirst m_first
active in
3574 G.postRedisplay "outline updownlevel";
3575 {< m_active
= active; m_first
= first >}
3577 method private key1
key mask
=
3578 let set1 active first qsearch
=
3579 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3581 let search active pattern incr
=
3582 let active = if active = -1 then m_first
else active in
3585 if n >= 0 && n < source#getitemcount
3587 let s, _ = source#getitem
n in
3589 (try ignore
(Str.search_forward
re s 0); true
3590 with Not_found
-> false)
3592 else loop (n + incr
)
3599 let re = Str.regexp_case_fold pattern
in
3605 let itemcount = source#getitemcount
in
3606 let find start incr
=
3608 if i
= -1 || i
= itemcount
3611 if source#hasaction i
3613 else find (i
+ incr
)
3618 let set active first =
3619 let first = bound first 0 (itemcount - fstate.maxrows
) in
3621 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3624 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3626 let incr1 = if incr
> 0 then 1 else -1 in
3627 if isvisible m_first m_active
3630 let next = m_active
+ incr
in
3632 if next < 0 || next >= itemcount
3634 else find next incr1
3636 if abs
(m_active
- next) > fstate.maxrows
3642 let first = m_first
+ incr
in
3643 let first = bound first 0 (itemcount - fstate.maxrows
) in
3645 let next = m_active
+ incr
in
3646 let next = bound next 0 (itemcount - 1) in
3653 if isvisible first next
3660 let first = min
next m_first
in
3662 if abs
(next - first) > fstate.maxrows
3668 let first = m_first
+ incr
in
3669 let first = bound first 0 (itemcount - 1) in
3671 let next = m_active
+ incr
in
3672 let next = bound next 0 (itemcount - 1) in
3673 let next = find next incr1 in
3675 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3677 let active = if m_active
= -1 then next else m_active
in
3682 if isvisible first active
3688 G.postRedisplay "listview navigate";
3692 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3693 let incr = if key = 0x72 then -1 else 1 in
3695 match search (m_active
+ incr) m_qsearch
incr with
3697 state.text <- m_qsearch ^
" [not found]";
3700 state.text <- m_qsearch
;
3701 active, firstof m_first
active
3703 G.postRedisplay "listview ctrl-r/s";
3704 set1 active first m_qsearch
;
3706 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3707 if m_active
>= 0 && m_active
< source#getitemcount
3709 let s, _ = source#getitem m_active
in
3714 | 0xff08 -> (* backspace *)
3715 if emptystr m_qsearch
3718 let qsearch = withoutlastutf8 m_qsearch
in
3722 G.postRedisplay "listview empty qsearch";
3723 set1 m_active m_first
"";
3727 match search m_active
qsearch ~
-1 with
3729 state.text <- qsearch ^
" [not found]";
3732 state.text <- qsearch;
3733 active, firstof m_first
active
3735 G.postRedisplay "listview backspace qsearch";
3736 set1 active first qsearch
3739 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3740 let pattern = m_qsearch ^ toutf8
key in
3742 match search m_active
pattern 1 with
3744 state.text <- pattern ^
" [not found]";
3747 state.text <- pattern;
3748 active, firstof m_first
active
3750 G.postRedisplay "listview qsearch add";
3751 set1 active first pattern;
3753 | 0xff1b -> (* escape *)
3755 if emptystr m_qsearch
3757 G.postRedisplay "list view escape";
3760 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3762 | None
-> m_prev_uioh
3767 G.postRedisplay "list view kill qsearch";
3768 source#setqsearch
"";
3769 coe {< m_qsearch
= "" >}
3772 | 0xff0d | 0xff8d -> (* (kp) enter *)
3774 let self = {< m_qsearch
= "" >} in
3775 source#setqsearch
"";
3777 G.postRedisplay "listview enter";
3778 if m_active
>= 0 && m_active
< source#getitemcount
3780 source#exit
(coe self) false m_active m_first m_pan
"";
3783 source#exit
(coe self) true m_active m_first m_pan
"";
3786 begin match opt with
3787 | None
-> m_prev_uioh
3791 | 0xff9f | 0xffff -> (* (kp) delete *)
3794 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3795 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3796 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3797 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3799 | 0xff53 | 0xff98 -> (* (kp) right *)
3801 G.postRedisplay "listview right";
3802 coe {< m_pan
= m_pan
- 1 >}
3804 | 0xff51 | 0xff96 -> (* (kp) left *)
3806 G.postRedisplay "listview left";
3807 coe {< m_pan
= m_pan
+ 1 >}
3809 | 0xff50 | 0xff95 -> (* (kp) home *)
3810 let active = find 0 1 in
3811 G.postRedisplay "listview home";
3814 | 0xff57 | 0xff9c -> (* (kp) end *)
3815 let first = max
0 (itemcount - fstate.maxrows
) in
3816 let active = find (itemcount - 1) ~
-1 in
3817 G.postRedisplay "listview end";
3820 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3824 dolog
"listview unknown key %#x" key; coe self
3826 method key key mask
=
3827 match state.mode
with
3828 | Textentry te
-> textentrykeyboard key mask te
; coe self
3829 | _ -> self#key1
key mask
3831 method button button down
x y _ =
3834 | 1 when x > state.winw
- conf.scrollbw
->
3835 G.postRedisplay "listview scroll";
3838 let _, position, sh = self#
scrollph in
3839 if y > truncate
position && y < truncate
(position +. sh)
3841 state.mstate
<- Mscrolly
;
3845 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3846 let first = truncate
(s *. float source#getitemcount
) in
3847 let first = min source#getitemcount
first in
3848 Some
(coe {< m_first
= first; m_active
= first >})
3850 state.mstate
<- Mnone
;
3853 | 1 when not down
->
3854 begin match self#elemunder
y with
3856 G.postRedisplay "listview click";
3858 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3862 | n when (n == 4 || n == 5) && not down
->
3863 let len = source#getitemcount
in
3865 if n = 5 && m_first
+ fstate.maxrows
>= len
3869 let first = m_first
+ (if n == 4 then -1 else 1) in
3870 bound first 0 (len - 1)
3872 G.postRedisplay "listview wheel";
3873 Some
(coe {< m_first
= first >})
3874 | n when (n = 6 || n = 7) && not down
->
3875 let inc = if n = 7 then -1 else 1 in
3876 G.postRedisplay "listview hwheel";
3877 Some
(coe {< m_pan
= m_pan
+ inc >})
3882 | None
-> m_prev_uioh
3885 method multiclick
_ x y = self#button
1 true x y
3888 match state.mstate
with
3890 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3891 let first = truncate
(s *. float source#getitemcount
) in
3892 let first = min source#getitemcount
first in
3893 G.postRedisplay "listview motion";
3894 coe {< m_first
= first; m_active
= first >}
3897 method pmotion
x y =
3898 if x < state.winw
- conf.scrollbw
3901 match self#elemunder
y with
3902 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3903 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3907 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3912 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3916 method infochanged
_ = ()
3918 method scrollpw
= (0, 0.0, 0.0)
3920 let nfs = fstate.fontsize
+ 1 in
3921 let y = m_first
* nfs in
3922 let itemcount = source#getitemcount
in
3923 let maxi = max
0 (itemcount - fstate.maxrows
) in
3924 let maxy = maxi * nfs in
3925 let p, h = scrollph y maxy in
3928 method modehash
= modehash
3929 method eformsgs
= false
3932 class outlinelistview ~source
=
3933 let settext autonarrow
s =
3935 then state.text <- "[" ^
s ^
"]"
3936 else state.text <- s
3940 ~source
:(source
:> lvsource
)
3942 ~modehash
:(findkeyhash conf "outline")
3945 val m_autonarrow
= false
3947 method key key mask
=
3949 if emptystr
state.text
3951 else fstate.maxrows - 2
3953 let calcfirst first active =
3956 let rows = active - first in
3957 if rows > maxrows then active - maxrows else first
3961 let active = m_active
+ incr in
3962 let active = bound active 0 (source#getitemcount
- 1) in
3963 let first = calcfirst m_first
active in
3964 G.postRedisplay "outline navigate";
3965 coe {< m_active
= active; m_first
= first >}
3967 let navscroll first =
3969 let dist = m_active
- first in
3975 else first + maxrows
3978 G.postRedisplay "outline navscroll";
3979 coe {< m_first
= first; m_active
= active >}
3981 let ctrl = Wsi.withctrl mask
in
3983 | 97 when ctrl -> (* ctrl-a *)
3985 then source#denarrow
3986 else source#narrow m_qsearch
;
3987 settext (not m_autonarrow
) m_qsearch
;
3988 G.postRedisplay "toggle auto narrowing";
3989 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3991 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3993 G.postRedisplay "toggle auto narrowing";
3994 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3996 | 110 when ctrl -> (* ctrl-n *)
3997 source#narrow m_qsearch
;
3999 then source#add_narrow_pattern m_qsearch
;
4000 G.postRedisplay "outline ctrl-n";
4001 coe {< m_first
= 0; m_active
= 0 >}
4003 | 115 when ctrl -> (* ctrl-s *)
4004 let active = source#calcactive
(getanchor ()) in
4005 let first = firstof m_first
active in
4006 G.postRedisplay "outline ctrl-s";
4007 coe {< m_first
= first; m_active
= active >}
4009 | 117 when ctrl -> (* ctrl-u *)
4010 source#del_narrow_pattern
;
4011 let pattern = source#renarrow
in
4012 G.postRedisplay "outline ctrl-u";
4014 if emptystr
pattern then "" else "Narrowed to " ^
pattern
4016 settext m_autonarrow
text;
4017 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4019 | 108 when ctrl -> (* ctrl-l *)
4020 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
4021 G.postRedisplay "outline ctrl-l";
4022 coe {< m_first
= first >}
4024 | 0xff1b -> (* escape *)
4025 let o = super#
key key mask
in
4028 if nonemptystr m_qsearch
4030 source#add_narrow_pattern m_qsearch
;
4036 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
4037 if nonemptystr m_qsearch
4038 then source#add_narrow_pattern m_qsearch
;
4041 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
4042 let pattern = m_qsearch ^ toutf8
key in
4043 G.postRedisplay "outlinelistview autonarrow add";
4044 source#narrow
pattern;
4045 settext true pattern;
4046 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4048 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4049 if emptystr m_qsearch
4052 let pattern = withoutlastutf8 m_qsearch
in
4053 G.postRedisplay "outlinelistview autonarrow backspace";
4054 ignore
(source#renarrow
);
4055 source#narrow
pattern;
4056 settext true pattern;
4057 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4059 | 0xff9f | 0xffff -> (* (kp) delete *)
4060 source#remove m_active
;
4061 G.postRedisplay "outline delete";
4062 let active = max
0 (m_active
-1) in
4063 coe {< m_first
= firstof m_first
active;
4064 m_active
= active >}
4066 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4067 navscroll (max
0 (m_first
- 1))
4069 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4070 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4072 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4073 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4074 | 0xff55 | 0xff9a -> (* (kp) prior *)
4075 navigate ~
-(fstate.maxrows)
4076 | 0xff56 | 0xff9b -> (* (kp) next *)
4077 navigate fstate.maxrows
4079 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4083 G.postRedisplay "outline ctrl right";
4084 {< m_pan
= m_pan
+ 1 >}
4086 else self#updownlevel
1
4090 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4094 G.postRedisplay "outline ctrl left";
4095 {< m_pan
= m_pan
- 1 >}
4097 else self#updownlevel ~
-1
4101 | 0xff50 | 0xff95 -> (* (kp) home *)
4102 G.postRedisplay "outline home";
4103 coe {< m_first
= 0; m_active
= 0 >}
4105 | 0xff57 | 0xff9c -> (* (kp) end *)
4106 let active = source#getitemcount
- 1 in
4107 let first = max
0 (active - fstate.maxrows) in
4108 G.postRedisplay "outline end";
4109 coe {< m_active
= active; m_first
= first >}
4111 | _ -> super#
key key mask
4114 let gotounder under =
4115 let getpath filename
=
4117 if nonemptystr filename
4119 if Filename.is_relative filename
4121 let dir = Filename.dirname
state.path in
4123 if Filename.is_implicit
dir
4124 then Filename.concat
(Sys.getcwd
()) dir
4127 Filename.concat
dir filename
4131 if Sys.file_exists
path
4136 | Ulinkgoto
(pageno, top) ->
4140 gotopage1 pageno top;
4146 | Uremote
(filename
, pageno) ->
4147 let path = getpath filename
in
4152 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
4153 try popen command []
4156 "failed to execute `%s': %s\n" command (exntos exn
);
4159 let anchor = getanchor () in
4160 let ranchor = state.path, state.password
, anchor, state.origin
in
4162 state.anchor <- (pageno, 0.0, 0.0);
4163 state.ranchors
<- ranchor :: state.ranchors
;
4166 else showtext '
!'
("Could not find " ^ filename
)
4168 | Uremotedest
(filename
, destname
) ->
4169 let path = getpath filename
in
4174 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
4175 try popen command []
4178 "failed to execute `%s': %s\n" command (exntos exn
);
4181 let anchor = getanchor () in
4182 let ranchor = state.path, state.password
, anchor, state.origin
in
4184 state.nameddest
<- destname
;
4185 state.ranchors
<- ranchor :: state.ranchors
;
4188 else showtext '
!'
("Could not find " ^ filename
)
4190 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4193 let gotooutline (_, _, kind
) =
4197 let (pageno, y, _) = anchor in
4199 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4202 | Ouri
uri -> gotounder (Ulinkuri
uri)
4203 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
4204 | Oremote remote
-> gotounder (Uremote remote
)
4205 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
4208 let outlinesource usebookmarks
=
4211 inherit lvsourcebase
4212 val mutable m_items
= empty
4213 val mutable m_orig_items
= empty
4214 val mutable m_narrow_patterns
= []
4215 val mutable m_hadremovals
= false
4217 method getitemcount
=
4218 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4221 if n == Array.length m_items
&& m_hadremovals
4223 ("[Confirm removal]", 0)
4225 let s, n, _ = m_items
.(n) in
4228 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4229 ignore
(uioh
, first, qsearch);
4230 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4232 if m_narrow_patterns
= []
4238 if not
confrimremoval
4240 gotooutline m_items
.(active);
4244 state.bookmarks
<- Array.to_list m_items
;
4245 m_orig_items
<- m_items
;
4248 else m_items
<- items;
4252 method hasaction
_ = true
4255 if Array.length m_items
!= Array.length m_orig_items
4258 match m_narrow_patterns
with
4260 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
4262 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4265 method narrow
pattern =
4266 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4270 let rec loop accu n =
4272 then m_items
<- Array.of_list
accu
4274 let (s, _, _) as o = m_items
.(n) in
4276 if (try ignore
(Str.search_forward
re s 0); true
4277 with Not_found
-> false)
4283 loop [] (Array.length m_items
- 1)
4288 then Array.of_list
state.bookmarks
4291 m_items
<- m_orig_items
4296 if m >= 0 && m < Array.length m_items
4298 m_hadremovals
<- true;
4299 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4300 let n = if n >= m then n+1 else n in
4305 method add_narrow_pattern
pattern =
4306 m_narrow_patterns
<- pattern :: m_narrow_patterns
4308 method del_narrow_pattern
=
4309 match m_narrow_patterns
with
4310 | _ :: rest
-> m_narrow_patterns
<- rest
4315 match m_narrow_patterns
with
4316 | pattern :: [] -> self#narrow
pattern; pattern
4318 List.fold_left
(fun accu pattern ->
4319 self#narrow
pattern;
4320 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
4322 method calcactive
anchor =
4323 let rely = getanchory anchor in
4324 let rec loop n best bestd
=
4325 if n = Array.length m_items
4328 let _, _, kind
= m_items
.(n) in
4331 let orely = getanchory anchor in
4332 let d = abs
(orely - rely) in
4335 else loop (n+1) best bestd
4336 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
4337 loop (n+1) best bestd
4341 method reset
anchor items =
4342 m_hadremovals
<- false;
4343 if m_orig_items
== empty
4345 m_orig_items
<- items;
4346 if m_narrow_patterns
== []
4347 then m_items
<- items;
4349 let active = self#calcactive
anchor in
4351 m_first
<- firstof m_first
active
4355 let enterselector usebookmarks
=
4356 let source = outlinesource usebookmarks
in
4360 then Array.of_list
state.bookmarks
4363 if Array.length
outlines = 0
4365 showtext ' ' errmsg
;
4368 state.text <- source#greetmsg
;
4369 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4370 let anchor = getanchor () in
4371 source#reset
anchor outlines;
4372 state.uioh
<- coe (new outlinelistview ~
source);
4373 G.postRedisplay "enter selector";
4377 let enteroutlinemode =
4378 let f = enterselector false in
4379 fun ()-> f "Document has no outline";
4382 let enterbookmarkmode =
4383 let f = enterselector true in
4384 fun () -> f "Document has no bookmarks (yet)";
4387 let color_of_string s =
4388 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4389 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4393 let color_to_string (r, g, b) =
4394 let r = truncate
(r *. 256.0)
4395 and g = truncate
(g *. 256.0)
4396 and b = truncate
(b *. 256.0) in
4397 Printf.sprintf
"%d/%d/%d" r g b
4400 let irect_of_string s =
4401 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4404 let irect_to_string (x0,y0,x1,y1) =
4405 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4408 let makecheckers () =
4409 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4411 converted by Issac Trotts. July 25, 2002 *)
4412 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4413 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4414 let id = GlTex.gen_texture
() in
4415 GlTex.bind_texture `texture_2d
id;
4416 GlPix.store
(`unpack_alignment
1);
4417 GlTex.image2d
image;
4418 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4419 [ `mag_filter `nearest
; `min_filter `nearest
];
4423 let setcheckers enabled
=
4424 match state.texid
with
4426 if enabled
then state.texid
<- Some
(makecheckers ())
4431 GlTex.delete_texture texid
;
4432 state.texid
<- None
;
4436 let int_of_string_with_suffix s =
4437 let l = String.length
s in
4441 let suffix = Char.lowercase
s.[l-1] in
4443 | 'k'
-> String.sub
s 0 (l-1), 10
4444 | '
m'
-> String.sub
s 0 (l-1), 20
4445 | '
g'
-> String.sub
s 0 (l-1), 30
4449 let n = int_of_string
s1 in
4450 let m = n lsl shift
in
4452 then raise
(Failure
"value too large")
4456 let string_with_suffix_of_int n =
4460 let units = [(30, "G"); (20, "M"); (10, "K")] in
4463 let h = n mod 1000 in
4466 then string_of_int
h ^
s
4468 let s = Printf.sprintf
"_%03d%s" h s in
4474 let rec find = function
4476 | (shift
, suffix) :: rest
->
4477 if (n land ((1 lsl shift
) - 1)) = 0
4478 then prettyint (n lsr shift
) ^
suffix
4484 let defghyllscroll = (40, 8, 32);;
4485 let fastghyllscroll = (5,1,2);;
4486 let neatghyllscroll = (10,1,9);;
4487 let ghyllscroll_of_string s =
4489 | "default" -> Some
defghyllscroll
4490 | "fast" -> Some
(5,1,2)
4491 | "neat" -> Some
(10,1,9)
4492 | "" | "none" -> None
4494 let (n,a,b) as nab
=
4495 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4496 if n <= a || n <= b || a >= b
4497 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4502 let ghyllscroll_to_string ((n, a, b) as nab
) =
4503 (**) if nab
= defghyllscroll then "default"
4504 else if nab
= fastghyllscroll then "fast"
4505 else if nab
= neatghyllscroll then "neat"
4506 else Printf.sprintf
"%d,%d,%d" n a b;
4509 let describe_location () =
4510 let fn = page_of_y state.y in
4511 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4512 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4516 else (100. *. (float state.y /. float maxy))
4520 Printf.sprintf
"page %d of %d [%.2f%%]"
4521 (fn+1) state.pagecount
percent
4524 "pages %d-%d of %d [%.2f%%]"
4525 (fn+1) (ln+1) state.pagecount
percent
4528 let setpresentationmode v
=
4529 let n = page_of_y state.y in
4530 state.anchor <- (n, 0.0, 1.0);
4531 conf.presentation
<- v
;
4532 if conf.fitmodel
= FitPage
4533 then reqlayout conf.angle
conf.fitmodel
;
4538 let btos b = if b then "\xe2\x88\x9a" else "" in
4539 let showextended = ref false in
4540 let leave mode
= function
4541 | Confirm
-> state.mode
<- mode
4542 | Cancel
-> state.mode
<- mode
in
4545 val mutable m_first_time
= true
4546 val mutable m_l
= []
4547 val mutable m_a
= [||]
4548 val mutable m_prev_uioh
= nouioh
4549 val mutable m_prev_mode
= View
4551 inherit lvsourcebase
4553 method reset prev_mode prev_uioh
=
4554 m_a
<- Array.of_list
(List.rev m_l
);
4556 m_prev_mode
<- prev_mode
;
4557 m_prev_uioh
<- prev_uioh
;
4561 if n >= Array.length m_a
4565 | _, _, _, Action
_ -> m_active
<- n
4569 m_first_time
<- false;
4572 method int name get
set =
4574 (name, `
int get
, 1, Action
(
4577 try set (int_of_string
s)
4579 state.text <- Printf.sprintf
"bad integer `%s': %s"
4583 let te = name ^
": ", "", None
, intentry, ondone, true in
4584 state.mode
<- Textentry
(te, leave m_prev_mode
);
4588 method int_with_suffix
name get
set =
4590 (name, `intws get
, 1, Action
(
4593 try set (int_of_string_with_suffix s)
4595 state.text <- Printf.sprintf
"bad integer `%s': %s"
4600 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4602 state.mode
<- Textentry
(te, leave m_prev_mode
);
4606 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4608 (name, `
bool (btos, get
), offset
, Action
(
4615 method color
name get
set =
4617 (name, `color get
, 1, Action
(
4619 let invalid = (nan
, nan
, nan
) in
4622 try color_of_string s
4624 state.text <- Printf.sprintf
"bad color `%s': %s"
4631 let te = name ^
": ", "", None
, textentry, ondone, true in
4632 state.text <- color_to_string (get
());
4633 state.mode
<- Textentry
(te, leave m_prev_mode
);
4637 method string name get
set =
4639 (name, `
string get
, 1, Action
(
4641 let ondone s = set s in
4642 let te = name ^
": ", "", None
, textentry, ondone, true in
4643 state.mode
<- Textentry
(te, leave m_prev_mode
);
4647 method colorspace
name get
set =
4649 (name, `
string get
, 1, Action
(
4653 inherit lvsourcebase
4656 m_active
<- CSTE.to_int conf.colorspace
;
4659 method getitemcount
=
4660 Array.length
CSTE.names
4663 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4664 ignore
(uioh
, first, pan
, qsearch);
4665 if not cancel
then set active;
4667 method hasaction
_ = true
4671 let modehash = findkeyhash conf "info" in
4672 coe (new listview ~
source ~trusted
:true ~
modehash)
4675 method paxmark
name get
set =
4677 (name, `
string get
, 1, Action
(
4681 inherit lvsourcebase
4684 m_active
<- MTE.to_int conf.paxmark
;
4687 method getitemcount
= Array.length
MTE.names
4688 method getitem
n = (MTE.names.(n), 0)
4689 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4690 ignore
(uioh
, first, pan
, qsearch);
4691 if not cancel
then set active;
4693 method hasaction
_ = true
4697 let modehash = findkeyhash conf "info" in
4698 coe (new listview ~
source ~trusted
:true ~
modehash)
4701 method fitmodel
name get
set =
4703 (name, `
string get
, 1, Action
(
4707 inherit lvsourcebase
4710 m_active
<- FMTE.to_int conf.fitmodel
;
4713 method getitemcount
= Array.length
FMTE.names
4714 method getitem
n = (FMTE.names.(n), 0)
4715 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4716 ignore
(uioh
, first, pan
, qsearch);
4717 if not cancel
then set active;
4719 method hasaction
_ = true
4723 let modehash = findkeyhash conf "info" in
4724 coe (new listview ~
source ~trusted
:true ~
modehash)
4727 method caption
s offset
=
4728 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4730 method caption2
s f offset
=
4731 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4733 method getitemcount
= Array.length m_a
4736 let tostr = function
4737 | `
int f -> string_of_int
(f ())
4738 | `intws
f -> string_with_suffix_of_int (f ())
4740 | `color
f -> color_to_string (f ())
4741 | `
bool (btos, f) -> btos (f ())
4744 let name, t
, offset
, _ = m_a
.(n) in
4745 ((let s = tostr t
in
4747 then Printf.sprintf
"%s\t%s" name s
4751 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4755 m_qsearch
<- qsearch;
4757 match m_a
.(active) with
4758 | _, _, _, Action
f -> f uioh
4770 method hasaction
n =
4772 | _, _, _, Action
_ -> true
4776 let rec fillsrc prevmode prevuioh
=
4777 let sep () = src#caption
"" 0 in
4778 let colorp name get
set =
4780 (fun () -> color_to_string (get
()))
4783 let c = color_of_string v in
4786 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4789 let oldmode = state.mode
in
4790 let birdseye = isbirdseye state.mode
in
4792 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4794 src#
bool "presentation mode"
4795 (fun () -> conf.presentation
)
4796 (fun v -> setpresentationmode v);
4798 src#
bool "ignore case in searches"
4799 (fun () -> conf.icase
)
4800 (fun v -> conf.icase
<- v);
4803 (fun () -> conf.preload)
4804 (fun v -> conf.preload <- v);
4806 src#
bool "highlight links"
4807 (fun () -> conf.hlinks
)
4808 (fun v -> conf.hlinks
<- v);
4810 src#
bool "under info"
4811 (fun () -> conf.underinfo
)
4812 (fun v -> conf.underinfo
<- v);
4814 src#
bool "persistent bookmarks"
4815 (fun () -> conf.savebmarks
)
4816 (fun v -> conf.savebmarks
<- v);
4818 src#fitmodel
"fit model"
4819 (fun () -> FMTE.to_string conf.fitmodel
)
4820 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4822 src#
bool "trim margins"
4823 (fun () -> conf.trimmargins
)
4824 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4826 src#
bool "persistent location"
4827 (fun () -> conf.jumpback
)
4828 (fun v -> conf.jumpback
<- v);
4831 src#
int "inter-page space"
4832 (fun () -> conf.interpagespace
)
4834 conf.interpagespace
<- n;
4835 docolumns conf.columns
;
4837 match state.layout with
4842 state.maxy <- calcheight ();
4843 let y = getpagey pageno in
4848 (fun () -> conf.pagebias
)
4849 (fun v -> conf.pagebias
<- v);
4851 src#
int "scroll step"
4852 (fun () -> conf.scrollstep
)
4853 (fun n -> conf.scrollstep
<- n);
4855 src#
int "horizontal scroll step"
4856 (fun () -> conf.hscrollstep
)
4857 (fun v -> conf.hscrollstep
<- v);
4859 src#
int "auto scroll step"
4861 match state.autoscroll
with
4863 | _ -> conf.autoscrollstep
)
4865 let n = boundastep state.winh
n in
4866 if state.autoscroll
<> None
4867 then state.autoscroll
<- Some
n;
4868 conf.autoscrollstep
<- n);
4871 (fun () -> truncate
(conf.zoom *. 100.))
4872 (fun v -> setzoom ((float v) /. 100.));
4875 (fun () -> conf.angle
)
4876 (fun v -> reqlayout v conf.fitmodel
);
4878 src#
int "scroll bar width"
4879 (fun () -> conf.scrollbw
)
4882 reshape state.winw
state.winh
;
4885 src#
int "scroll handle height"
4886 (fun () -> conf.scrollh
)
4887 (fun v -> conf.scrollh
<- v;);
4889 src#
int "thumbnail width"
4890 (fun () -> conf.thumbw
)
4892 conf.thumbw
<- min
4096 v;
4895 leavebirdseye beye
false;
4900 let mode = state.mode in
4901 src#
string "columns"
4903 match conf.columns
with
4905 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4906 | Csplit
(count
, _) -> "-" ^ string_of_int count
4909 let n, a, b = multicolumns_of_string v in
4910 setcolumns mode n a b);
4913 src#caption
"Pixmap cache" 0;
4914 src#int_with_suffix
"size (advisory)"
4915 (fun () -> conf.memlimit
)
4916 (fun v -> conf.memlimit
<- v);
4919 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4920 (string_with_suffix_of_int state.memused
)
4921 (Hashtbl.length
state.tilemap
)) 1;
4924 src#caption
"Layout" 0;
4925 src#caption2
"Dimension"
4927 Printf.sprintf
"%dx%d (virtual %dx%d)"
4928 state.winw
state.winh
4933 src#caption2
"Position" (fun () ->
4934 Printf.sprintf
"%dx%d" state.x state.y
4937 src#caption2
"Position" (fun () -> describe_location ()) 1
4941 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4942 "Save these parameters as global defaults at exit"
4943 (fun () -> conf.bedefault
)
4944 (fun v -> conf.bedefault
<- v)
4948 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4949 src#
bool ~offset
:0 ~
btos "Extended parameters"
4950 (fun () -> !showextended)
4951 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4955 (fun () -> conf.checkers
)
4956 (fun v -> conf.checkers
<- v; setcheckers v);
4957 src#
bool "update cursor"
4958 (fun () -> conf.updatecurs
)
4959 (fun v -> conf.updatecurs
<- v);
4961 (fun () -> conf.verbose
)
4962 (fun v -> conf.verbose
<- v);
4963 src#
bool "invert colors"
4964 (fun () -> conf.invert
)
4965 (fun v -> conf.invert
<- v);
4967 (fun () -> conf.maxhfit
)
4968 (fun v -> conf.maxhfit
<- v);
4969 src#
bool "redirect stderr"
4970 (fun () -> conf.redirectstderr)
4971 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4973 (fun () -> conf.pax
!= None
)
4976 then conf.pax
<- Some
(ref (now (), 0, 0))
4977 else conf.pax
<- None
);
4978 src#
string "uri launcher"
4979 (fun () -> conf.urilauncher
)
4980 (fun v -> conf.urilauncher
<- v);
4981 src#
string "path launcher"
4982 (fun () -> conf.pathlauncher
)
4983 (fun v -> conf.pathlauncher
<- v);
4984 src#
string "tile size"
4985 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4988 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4989 conf.tilew
<- max
64 w;
4990 conf.tileh
<- max
64 h;
4993 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4996 src#
int "texture count"
4997 (fun () -> conf.texcount
)
5000 then conf.texcount
<- v
5001 else showtext '
!'
" Failed to set texture count please retry later"
5003 src#
int "slice height"
5004 (fun () -> conf.sliceheight
)
5006 conf.sliceheight
<- v;
5007 wcmd "sliceh %d" conf.sliceheight
;
5009 src#
int "anti-aliasing level"
5010 (fun () -> conf.aalevel
)
5012 conf.aalevel
<- bound v 0 8;
5013 state.anchor <- getanchor ();
5014 opendoc state.path state.password
;
5016 src#
string "page scroll scaling factor"
5017 (fun () -> string_of_float
conf.pgscale)
5020 let s = float_of_string
v in
5023 state.text <- Printf.sprintf
5024 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
5027 src#
int "ui font size"
5028 (fun () -> fstate.fontsize
)
5029 (fun v -> setfontsize (bound v 5 100));
5030 src#
int "hint font size"
5031 (fun () -> conf.hfsize
)
5032 (fun v -> conf.hfsize
<- bound v 5 100);
5033 colorp "background color"
5034 (fun () -> conf.bgcolor
)
5035 (fun v -> conf.bgcolor
<- v);
5036 src#
bool "crop hack"
5037 (fun () -> conf.crophack
)
5038 (fun v -> conf.crophack
<- v);
5039 src#
string "trim fuzz"
5040 (fun () -> irect_to_string conf.trimfuzz
)
5043 conf.trimfuzz
<- irect_of_string v;
5045 then settrim true conf.trimfuzz
;
5047 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
5049 src#
string "throttle"
5051 match conf.maxwait
with
5052 | None
-> "show place holder if page is not ready"
5055 then "wait for page to fully render"
5057 "wait " ^ string_of_float
time
5058 ^
" seconds before showing placeholder"
5062 let f = float_of_string
v in
5064 then conf.maxwait
<- None
5065 else conf.maxwait
<- Some
f
5067 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
5069 src#
string "ghyll scroll"
5071 match conf.ghyllscroll
with
5073 | Some nab
-> ghyllscroll_to_string nab
5076 try conf.ghyllscroll
<- ghyllscroll_of_string v
5078 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
5080 src#
string "selection command"
5081 (fun () -> conf.selcmd
)
5082 (fun v -> conf.selcmd
<- v);
5083 src#
string "synctex command"
5084 (fun () -> conf.stcmd
)
5085 (fun v -> conf.stcmd
<- v);
5086 src#
string "pax command"
5087 (fun () -> conf.paxcmd
)
5088 (fun v -> conf.paxcmd
<- v);
5089 src#colorspace
"color space"
5090 (fun () -> CSTE.to_string conf.colorspace
)
5092 conf.colorspace
<- CSTE.of_int v;
5096 src#paxmark
"pax mark method"
5097 (fun () -> MTE.to_string conf.paxmark
)
5098 (fun v -> conf.paxmark
<- MTE.of_int v);
5102 (fun () -> conf.usepbo
)
5103 (fun v -> conf.usepbo
<- v);
5104 src#
bool "mouse wheel scrolls pages"
5105 (fun () -> conf.wheelbypage
)
5106 (fun v -> conf.wheelbypage
<- v);
5107 src#
bool "open remote links in a new instance"
5108 (fun () -> conf.riani
)
5109 (fun v -> conf.riani
<- v);
5113 src#caption
"Document" 0;
5114 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
5115 src#caption2
"Pages"
5116 (fun () -> string_of_int
state.pagecount
) 1;
5117 src#caption2
"Dimensions"
5118 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5122 src#caption
"Trimmed margins" 0;
5123 src#caption2
"Dimensions"
5124 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5128 src#caption
"OpenGL" 0;
5129 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
5130 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
5133 src#caption
"Location" 0;
5134 if nonemptystr
state.origin
5135 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
5136 src#caption
("Path\t" ^ mbtoutf8
state.path) 1;
5138 src#reset prevmode prevuioh
;
5142 let prevmode = state.mode
5143 and prevuioh
= state.uioh in
5144 fillsrc prevmode prevuioh
;
5145 let source = (src :> lvsource
) in
5146 let modehash = findkeyhash conf "info" in
5147 state.uioh <- coe (object (self)
5148 inherit listview ~
source ~trusted
:true ~
modehash as super
5149 val mutable m_prevmemused
= 0
5150 method infochanged
= function
5152 if m_prevmemused
!= state.memused
5154 m_prevmemused
<- state.memused
;
5155 G.postRedisplay "memusedchanged";
5157 | Pdim
-> G.postRedisplay "pdimchanged"
5158 | Docinfo
-> fillsrc prevmode prevuioh
5160 method key key mask
=
5161 if not
(Wsi.withctrl mask
)
5164 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5165 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5166 | _ -> super#
key key mask
5167 else super#
key key mask
5169 G.postRedisplay "info";
5175 inherit lvsourcebase
5176 method getitemcount
= Array.length
state.help
5178 let s, l, _ = state.help
.(n) in
5181 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5185 m_qsearch
<- qsearch;
5186 match state.help
.(active) with
5187 | _, _, Action
f -> Some
(f uioh)
5197 method hasaction
n =
5198 match state.help
.(n) with
5199 | _, _, Action
_ -> true
5206 let modehash = findkeyhash conf "help" in
5207 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5208 G.postRedisplay "help";
5213 let re = Str.regexp
"[\r\n]" in
5215 inherit lvsourcebase
5216 val mutable m_items
= [||]
5218 method getitemcount
= 1 + Array.length m_items
5223 else m_items
.(n-1), 0
5225 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5230 then Buffer.clear
state.errmsgs
;
5231 m_qsearch
<- qsearch;
5238 method hasaction
n =
5242 state.newerrmsgs
<- false;
5243 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5244 m_items
<- Array.of_list
l
5252 let source = (msgsource :> lvsource
) in
5253 let modehash = findkeyhash conf "listview" in
5254 state.uioh <- coe (object
5255 inherit listview ~
source ~trusted
:false ~
modehash as super
5258 then msgsource#reset
;
5261 G.postRedisplay "msgs";
5264 let quickbookmark ?title
() =
5265 match state.layout with
5271 let sec = Unix.gettimeofday
() in
5272 let tm = Unix.localtime
sec in
5273 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5277 (tm.Unix.tm_year
+ 1900)
5280 | Some
title -> title
5282 state.bookmarks
<- (title, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5285 let setautoscrollspeed step goingdown
=
5286 let incr = max
1 ((abs step
) / 2) in
5287 let incr = if goingdown
then incr else -incr in
5288 let astep = boundastep state.winh
(step
+ incr) in
5289 state.autoscroll
<- Some
astep;
5293 match conf.columns
with
5295 | _ -> state.x != 0 || conf.zoom > 1.0
5298 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5300 let existsinrow pageno (columns
, coverA
, coverB
) p =
5301 let last = ((pageno - coverA
) mod columns
) + columns
in
5302 let rec any = function
5305 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5309 then (if l.pageno = last then false else any rest
)
5317 match state.layout with
5319 let pageno = page_of_y state.y in
5320 gotoghyll (getpagey (pageno+1))
5322 match conf.columns
with
5324 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5326 let y = clamp (pgscale state.winh
) in
5329 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5330 gotoghyll (getpagey pageno)
5331 | Cmulti
((c, _, _) as cl, _) ->
5332 if conf.presentation
5333 && (existsinrow l.pageno cl
5334 (fun l -> l.pageh
> l.pagey + l.pagevh))
5336 let y = clamp (pgscale state.winh
) in
5339 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5340 gotoghyll (getpagey pageno)
5342 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5344 let pagey, pageh
= getpageyh l.pageno in
5345 let pagey = pagey + pageh
* l.pagecol
in
5346 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5347 gotoghyll (pagey + pageh
+ ips)
5351 match state.layout with
5353 let pageno = page_of_y state.y in
5354 gotoghyll (getpagey (pageno-1))
5356 match conf.columns
with
5358 if conf.presentation
&& l.pagey != 0
5360 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5362 let pageno = max
0 (l.pageno-1) in
5363 gotoghyll (getpagey pageno)
5364 | Cmulti
((c, _, coverB
) as cl, _) ->
5365 if conf.presentation
&&
5366 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5368 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5371 if l.pageno = state.pagecount
- coverB
5375 let pageno = max
0 (l.pageno-decr) in
5376 gotoghyll (getpagey pageno)
5384 let pageno = max
0 (l.pageno-1) in
5385 let pagey, pageh
= getpageyh pageno in
5388 let pagey, pageh
= getpageyh l.pageno in
5389 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5394 let viewkeyboard key mask
=
5396 let mode = state.mode in
5397 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5400 G.postRedisplay "view:enttext"
5402 let ctrl = Wsi.withctrl mask
in
5404 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5410 | 0xff63 -> (* insert *)
5411 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5413 state.mode <- LinkNav
(Ltgendir
0);
5416 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5418 | 0xff1b | 113 -> (* escape / q *)
5419 begin match state.mstate
with
5421 state.mstate
<- Mnone
;
5422 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5423 G.postRedisplay "kill zoom rect";
5425 begin match state.mode with
5428 G.postRedisplay "esc leave linknav"
5430 match state.ranchors
with
5432 | (path, password
, anchor, origin
) :: rest
->
5433 state.ranchors
<- rest
;
5434 state.anchor <- anchor;
5435 state.origin
<- origin
;
5436 state.nameddest
<- "";
5437 opendoc path password
5441 | 0xff08 -> (* backspace *)
5442 gotoghyll (getnav ~
-1)
5450 Hashtbl.iter
(fun _ opaque
-> clearmark opaque
) state.pagemap
;
5451 G.postRedisplay "dehighlight";
5453 | 47 | 63 -> (* / ? *)
5454 let ondone isforw
s =
5455 cbput state.hists
.pat
s;
5456 state.searchpattern
<- s;
5459 let s = String.create
1 in
5460 s.[0] <- Char.chr
key;
5461 enttext (s, "", Some
(onhist state.hists
.pat
),
5462 textentry, ondone (key = 47), true)
5464 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5465 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5466 setzoom (conf.zoom +. incr)
5468 | 43 | 0xffab -> (* + *)
5471 try int_of_string
s with exc
->
5472 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5478 state.text <- "page bias is now " ^ string_of_int
n;
5481 enttext ("page bias: ", "", None
, intentry, ondone, true)
5483 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5484 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5485 setzoom (max
0.01 (conf.zoom -. decr))
5487 | 45 | 0xffad -> (* - *)
5488 let ondone msg
= state.text <- msg
in
5490 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5491 optentry state.mode, ondone, true
5494 | 48 when ctrl -> (* ctrl-0 *)
5502 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5504 match conf.columns
with
5505 | Csingle
_ | Cmulti
_ -> 1
5506 | Csplit
(n, _) -> n
5508 let h = state.winh
-
5509 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5511 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5512 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5515 | 51 when ctrl -> (* ctrl-3 *)
5517 match conf.fitmodel
with
5518 | FitWidth
-> FitProportional
5519 | FitProportional
-> FitPage
5520 | FitPage
-> FitWidth
5522 state.text <- "fit model: " ^
FMTE.to_string fm;
5523 reqlayout conf.angle
fm
5525 | 0xffc6 -> (* f9 *)
5528 | 57 when ctrl -> (* ctrl-9 *)
5531 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5532 when not
ctrl -> (* 0..9 *)
5535 try int_of_string
s with exc
->
5536 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5542 cbput state.hists
.pag
(string_of_int
n);
5543 gotopage1 (n + conf.pagebias
- 1) 0;
5546 let pageentry text key =
5547 match Char.unsafe_chr
key with
5548 | '
g'
-> TEdone
text
5549 | _ -> intentry text key
5551 let text = "x" in text.[0] <- Char.chr
key;
5552 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5555 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5556 reshape state.winw
state.winh
;
5559 state.bzoom
<- not
state.bzoom
;
5561 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5564 conf.hlinks
<- not
conf.hlinks
;
5565 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5566 G.postRedisplay "toggle highlightlinks";
5569 state.glinks
<- true;
5570 let mode = state.mode in
5571 state.mode <- Textentry
(
5572 (":", "", None
, linknentry, linkndone gotounder, false),
5574 state.glinks
<- false;
5578 G.postRedisplay "view:linkent(F)"
5581 state.glinks
<- true;
5582 let mode = state.mode in
5583 state.mode <- Textentry
(
5585 ":", "", None
, linknentry, linkndone (fun under ->
5586 selstring (undertext under);
5590 state.glinks
<- false;
5594 G.postRedisplay "view:linkent"
5597 begin match state.autoscroll
with
5599 conf.autoscrollstep
<- step
;
5600 state.autoscroll
<- None
5602 if conf.autoscrollstep
= 0
5603 then state.autoscroll
<- Some
1
5604 else state.autoscroll
<- Some
conf.autoscrollstep
5607 | 112 when ctrl -> (* ctrl-p *)
5611 setpresentationmode (not
conf.presentation
);
5612 showtext ' '
("presentation mode " ^
5613 if conf.presentation
then "on" else "off");
5616 if List.mem
Wsi.Fullscreen
state.winstate
5617 then Wsi.reshape conf.cwinw
conf.cwinh
5618 else Wsi.fullscreen
()
5620 | 112 | 78 -> (* p|N *)
5621 search state.searchpattern
false
5623 | 110 | 0xffc0 -> (* n|F3 *)
5624 search state.searchpattern
true
5627 begin match state.layout with
5630 gotoghyll (getpagey l.pageno)
5636 | 0xff9f | 0xffff -> (* delete *)
5640 showtext ' '
(describe_location ());
5643 begin match state.layout with
5646 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5651 enterbookmarkmode ()
5653 | 104 | 0xffbe -> (* h|F1 *)
5659 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5664 match state.layout with
5669 (s, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5672 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5676 showtext ' '
"Quick bookmark added";
5679 begin match state.layout with
5681 let rect = getpdimrect
l.pagedimno
in
5685 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5686 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5688 (truncate
(rect.(1) -. rect.(0)),
5689 truncate
(rect.(3) -. rect.(0)))
5691 let w = truncate
((float w)*.conf.zoom)
5692 and h = truncate
((float h)*.conf.zoom) in
5695 state.anchor <- getanchor ();
5696 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5698 G.postRedisplay "z";
5705 state.roam
<- noroam;
5706 | 60 | 62 -> (* < > *)
5707 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5709 | 91 | 93 -> (* [ ] *)
5711 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5713 G.postRedisplay "brightness";
5715 | 99 when state.mode = View
-> (* [alt-]c *)
5720 let m = (wadjsb state.winw
- state.w) / 2 in
5722 gotoy_and_clear_text state.y
5726 match state.prevcolumns
with
5727 | None
-> (1, 0, 0), 1.0
5728 | Some
(columns
, z
) ->
5731 | Csplit
(c, _) -> -c, 0, 0
5732 | Cmulti
((c, a, b), _) -> c, a, b
5733 | Csingle
_ -> 1, 0, 0
5737 setcolumns View
c a b;
5740 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5741 -> (* ctrl-shift- (kp) [up|down] *)
5742 let zoom, x = state.prevzoom
in
5746 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5747 begin match state.autoscroll
with
5749 begin match state.mode with
5750 | Birdseye beye
-> upbirdseye 1 beye
5753 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5755 if not
(Wsi.withshift mask
) && conf.presentation
5757 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5761 setautoscrollspeed n false
5764 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5765 begin match state.autoscroll
with
5767 begin match state.mode with
5768 | Birdseye beye
-> downbirdseye 1 beye
5771 then gotoy_and_clear_text (clamp (state.winh
/2))
5773 if not
(Wsi.withshift mask
) && conf.presentation
5775 else gotoy_and_clear_text (clamp conf.scrollstep
)
5779 setautoscrollspeed n true
5782 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5783 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5789 else conf.hscrollstep
5791 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5792 state.x <- panbound (state.x + dx);
5793 gotoy_and_clear_text state.y
5796 G.postRedisplay "left/right"
5799 | 0xff55 | 0xff9a -> (* (kp) prior *)
5803 match state.layout with
5805 | l :: _ -> state.y - l.pagey
5807 clamp (pgscale (-state.winh
))
5811 | 0xff56 | 0xff9b -> (* (kp) next *)
5815 match List.rev
state.layout with
5817 | l :: _ -> getpagey l.pageno
5819 clamp (pgscale state.winh
)
5823 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5825 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5826 gotoghyll (clamp state.maxy)
5829 when Wsi.withalt mask
-> (* alt-(kp) right *)
5830 gotoghyll (getnav 1)
5832 when Wsi.withalt mask
-> (* alt-(kp) left *)
5833 gotoghyll (getnav ~
-1)
5838 | 118 when conf.debug
-> (* v *)
5841 match getopaque l.pageno with
5844 let x0, y0, x1, y1 = pagebbox opaque
in
5845 let a,b = float x0, float y0 in
5846 let c,d = float x1, float y0 in
5847 let e,f = float x1, float y1 in
5848 let h,j
= float x0, float y1 in
5849 let rect = (a,b,c,d,e,f,h,j
) in
5851 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5853 G.postRedisplay "v";
5856 vlog "huh? %s" (Wsi.keyname
key)
5859 let linknavkeyboard key mask
linknav =
5860 let getpage pageno =
5861 let rec loop = function
5863 | l :: _ when l.pageno = pageno -> Some
l
5864 | _ :: rest
-> loop rest
5865 in loop state.layout
5867 let doexact (pageno, n) =
5868 match getopaque pageno, getpage pageno with
5869 | Some opaque
, Some
l ->
5870 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5872 let under = getlink opaque
n in
5873 G.postRedisplay "link gotounder";
5879 | 0xff50 -> (* home *)
5880 Some
(findlink opaque LDfirst
), -1
5882 | 0xff57 -> (* end *)
5883 Some
(findlink opaque LDlast
), 1
5885 | 0xff51 -> (* left *)
5886 Some
(findlink opaque
(LDleft
n)), -1
5888 | 0xff53 -> (* right *)
5889 Some
(findlink opaque
(LDright
n)), 1
5891 | 0xff52 -> (* up *)
5892 Some
(findlink opaque
(LDup
n)), -1
5894 | 0xff54 -> (* down *)
5895 Some
(findlink opaque
(LDdown
n)), 1
5900 begin match findpwl
l.pageno dir with
5904 state.mode <- LinkNav
(Ltgendir
dir);
5905 let y, h = getpageyh pageno in
5908 then y + h - state.winh
5913 begin match getopaque pageno, getpage pageno with
5914 | Some opaque
, Some
_ ->
5916 let ld = if dir > 0 then LDfirst
else LDlast
in
5919 begin match link with
5921 showlinktype (getlink opaque
m);
5922 state.mode <- LinkNav
(Ltexact
(pageno, m));
5923 G.postRedisplay "linknav jpage";
5930 begin match opt with
5931 | Some Lnotfound
-> pwl l dir;
5932 | Some
(Lfound
m) ->
5936 let _, y0, _, y1 = getlinkrect opaque
m in
5938 then gotopage1 l.pageno y0
5940 let d = fstate.fontsize
+ 1 in
5941 if y1 - l.pagey > l.pagevh - d
5942 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5943 else G.postRedisplay "linknav";
5945 showlinktype (getlink opaque
m);
5946 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5949 | None
-> viewkeyboard key mask
5951 | _ -> viewkeyboard key mask
5956 G.postRedisplay "leave linknav"
5960 | Ltgendir
_ -> viewkeyboard key mask
5961 | Ltexact exact
-> doexact exact
5964 let keyboard key mask
=
5965 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5966 then wcmd "interrupt"
5967 else state.uioh <- state.uioh#
key key mask
5970 let birdseyekeyboard key mask
5971 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5973 match conf.columns
with
5975 | Cmulti
((c, _, _), _) -> c
5976 | Csplit
_ -> failwith
"bird's eye split mode"
5978 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5980 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5981 let y, h = getpageyh pageno in
5982 let top = (state.winh
- h) / 2 in
5983 gotoy (max
0 (y - top))
5984 | 0xff0d (* enter *)
5985 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5986 | 0xff1b -> leavebirdseye beye
true (* escape *)
5987 | 0xff52 -> upbirdseye incr beye
(* up *)
5988 | 0xff54 -> downbirdseye incr beye
(* down *)
5989 | 0xff51 -> upbirdseye 1 beye
(* left *)
5990 | 0xff53 -> downbirdseye 1 beye
(* right *)
5992 | 0xff55 -> (* prior *)
5993 begin match state.layout with
5997 state.mode <- Birdseye
(
5998 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6000 gotopage1 l.pageno 0;
6003 let layout = layout (state.y-state.winh
) (pgh state.layout) in
6005 | [] -> gotoy (clamp (-state.winh
))
6007 state.mode <- Birdseye
(
6008 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6010 gotopage1 l.pageno 0
6013 | [] -> gotoy (clamp (-state.winh
))
6016 | 0xff56 -> (* next *)
6017 begin match List.rev
state.layout with
6019 let layout = layout (state.y + (pgh state.layout)) state.winh
in
6020 begin match layout with
6022 let incr = l.pageh
- l.pagevh in
6027 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
6029 G.postRedisplay "birdseye pagedown";
6031 else gotoy (clamp (incr + conf.interpagespace
*2));
6035 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
6036 gotopage1 l.pageno 0;
6039 | [] -> gotoy (clamp state.winh
)
6042 | 0xff50 -> (* home *)
6043 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
6046 | 0xff57 -> (* end *)
6047 let pageno = state.pagecount
- 1 in
6048 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
6049 if not
(pagevisible state.layout pageno)
6052 match List.rev
state.pdims
with
6054 | (_, _, h, _) :: _ -> h
6056 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
6057 else G.postRedisplay "birdseye end";
6058 | _ -> viewkeyboard key mask
6063 match state.mode with
6064 | Textentry
_ -> scalecolor 0.4
6066 | View
-> scalecolor 1.0
6067 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6068 if l.pageno = hooverpageno
6071 if l.pageno = pageno
6079 let postdrawpage l linkindexbase
=
6080 match getopaque l.pageno with
6082 if tileready l l.pagex
l.pagey
6084 let x = l.pagedispx - l.pagex
6085 and y = l.pagedispy - l.pagey in
6087 match conf.columns
with
6088 | Csingle
_ | Cmulti
_ ->
6089 (if conf.hlinks
then 1 else 0)
6091 && not
(isbirdseye state.mode) then 2 else 0)
6095 match state.mode with
6096 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6099 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6104 let scrollindicator () =
6105 let sbw, ph
, sh = state.uioh#
scrollph in
6106 let sbh, pw, sw = state.uioh#scrollpw
in
6108 GlDraw.color (0.64, 0.64, 0.64);
6110 (float (state.winw
- sbw)) 0.
6111 (float state.winw
) (float state.winh
)
6114 0. (float (state.winh
- sbh))
6115 (float (wadjsb state.winw
- 1)) (float state.winh
)
6117 GlDraw.color (0.0, 0.0, 0.0);
6120 (float (state.winw
- sbw)) ph
6121 (float state.winw
) (ph
+. sh)
6124 pw (float (state.winh
- sbh))
6125 (pw +. sw) (float state.winh
)
6130 match state.mstate
with
6131 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6134 | Msel
((x0, y0), (x1, y1)) ->
6135 let rec loop = function
6137 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6138 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6139 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6140 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6142 match getopaque l.pageno with
6144 let x0, y0 = pagetranslatepoint l x0 y0 in
6145 let x1, y1 = pagetranslatepoint l x1 y1 in
6146 seltext opaque
(x0, y0, x1, y1);
6154 let showrects = function [] -> () | rects
->
6156 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6157 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6159 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6161 if l.pageno = pageno
6163 let dx = float (l.pagedispx - l.pagex
) in
6164 let dy = float (l.pagedispy - l.pagey) in
6165 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6166 Raw.sets_float
state.vraw ~pos
:0
6171 GlArray.vertex `two
state.vraw
;
6172 GlArray.draw_arrays `triangle_strip
0 4;
6181 GlClear.color (scalecolor2 conf.bgcolor
);
6182 GlClear.clear
[`
color];
6183 List.iter
drawpage state.layout;
6185 match state.mode with
6186 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6187 begin match getopaque pageno with
6189 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6196 | None
-> state.rects
6201 let rec postloop linkindexbase
= function
6203 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6204 postloop linkindexbase rest
6208 postloop 0 state.layout;
6210 begin match state.mstate
with
6211 | Mzoomrect
((x0, y0), (x1, y1)) ->
6213 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6214 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6215 filledrect (float x0) (float y0) (float x1) (float y1);
6224 let zoomrect x y x1 y1 =
6227 and y0 = min
y y1 in
6228 gotoy (state.y + y0);
6229 state.anchor <- getanchor ();
6230 let zoom = (float state.w) /. float (x1 - x0) in
6232 match conf.fitmodel
, conf.columns
with
6233 | FitPage
, Csplit
_ ->
6234 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6237 let adjw = wadjsb state.winw
in
6239 then (adjw - state.w) / 2
6242 state.x <- (state.x + margin) - x0;
6244 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6245 state.mstate
<- Mnone
;
6249 let g opaque
l px py =
6250 match rectofblock opaque
px py with
6252 let x0 = a.(0) -. 20. in
6253 let x1 = a.(1) +. 20. in
6254 let y0 = a.(2) -. 20. in
6255 let zoom = (float state.w) /. (x1 -. x0) in
6256 let pagey = getpagey l.pageno in
6257 gotoy_and_clear_text (pagey + truncate
y0);
6258 state.anchor <- getanchor ();
6259 let margin = (state.w - l.pagew
)/2 in
6260 state.x <- -truncate
x0 - margin;
6265 match conf.columns
with
6267 showtext '
!'
"block zooming does not work properly in split columns mode"
6268 | _ -> onppundermouse g x y ()
6272 let winw = wadjsb state.winw - 1 in
6273 let s = float x /. float winw in
6274 let destx = truncate
(float (state.w + winw) *. s) in
6275 state.x <- winw - destx;
6276 gotoy_and_clear_text state.y;
6277 state.mstate
<- Mscrollx
;
6281 let s = float y /. float state.winh
in
6282 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6283 gotoy_and_clear_text desty;
6284 state.mstate
<- Mscrolly
;
6287 let viewmulticlick clicks
x y mask
=
6288 let g opaque
l px py =
6296 if markunder opaque
px py mark
6299 match getopaque l.pageno with
6302 match Ne.pipe () with
6306 "can not create mark pipe: %s"
6310 let doclose what fd
=
6311 Ne.clo fd
(fun msg
->
6312 dolog
"%s close failed: %s" what msg
)
6315 popen cmd
[r, 0; w, -1];
6316 copysel
w opaque
false;
6318 G.postRedisplay "viewmulticlick";
6320 dolog
"can not execute %S: %s" cmd
(exntos exn
);
6324 if Wsi.withctrl mask
6325 then state.roam
<- (fun () -> dopipe conf.paxcmd
)
6326 else dopipe conf.selcmd
6331 G.postRedisplay "viewmulticlick";
6332 onppundermouse g x y (fun () -> showtext '
!'
"Daisy whoopsie") ();
6335 let viewmouse button down
x y mask
=
6337 | n when (n == 4 || n == 5) && not down
->
6338 if Wsi.withctrl mask
6340 match state.mstate
with
6341 | Mzoom
(oldn
, i
) ->
6349 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6351 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6353 let zoom = conf.zoom -. incr in
6355 state.mstate
<- Mzoom
(n, 0);
6357 state.mstate
<- Mzoom
(n, i
+1);
6359 else state.mstate
<- Mzoom
(n, 0)
6361 | _ -> state.mstate
<- Mzoom
(n, 0)
6364 match state.autoscroll
with
6365 | Some step
-> setautoscrollspeed step
(n=4)
6367 if conf.wheelbypage
|| conf.presentation
6376 then -conf.scrollstep
6377 else conf.scrollstep
6379 let incr = incr * 2 in
6380 let y = clamp incr in
6381 gotoy_and_clear_text y
6384 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6386 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6387 gotoy_and_clear_text state.y
6389 | 1 when Wsi.withshift mask
->
6390 state.mstate
<- Mnone
;
6393 match unproject x y with
6394 | Some
(pageno, ux
, uy
) ->
6395 let cmd = Printf.sprintf
6397 conf.stcmd
state.path pageno ux uy
6403 | 1 when Wsi.withctrl mask
->
6406 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6407 state.mstate
<- Mpan
(x, y)
6410 state.mstate
<- Mnone
6415 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6417 state.mstate
<- Mzoomrect
(p, p)
6420 match state.mstate
with
6421 | Mzoomrect
((x0, y0), _) ->
6422 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6423 then zoomrect x0 y0 x y
6425 state.mstate
<- Mnone
;
6426 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6427 G.postRedisplay "kill accidental zoom rect";
6430 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6431 state.mstate
<- Mnone
6434 | 1 when x > state.winw - vscrollw () ->
6437 let _, position, sh = state.uioh#
scrollph in
6438 if y > truncate
position && y < truncate
(position +. sh)
6439 then state.mstate
<- Mscrolly
6442 state.mstate
<- Mnone
6444 | 1 when y > state.winh
- hscrollh () ->
6447 let _, position, sw = state.uioh#scrollpw
in
6448 if x > truncate
position && x < truncate
(position +. sw)
6449 then state.mstate
<- Mscrollx
6452 state.mstate
<- Mnone
6454 | 1 when state.bzoom
-> if not down
then zoomblock x y
6457 let dest = if down
then getunder x y else Unone
in
6458 begin match dest with
6461 | Uremote
_ | Uremotedest
_
6462 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6465 | Unone
when down
->
6466 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6467 state.mstate
<- Mpan
(x, y);
6469 | Unone
| Utext
_ ->
6472 if conf.angle
mod 360 = 0
6474 state.mstate
<- Msel
((x, y), (x, y));
6475 G.postRedisplay "mouse select";
6479 match state.mstate
with
6482 | Mzoom
_ | Mscrollx
| Mscrolly
->
6483 state.mstate
<- Mnone
6485 | Mzoomrect
((x0, y0), _) ->
6489 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6490 state.mstate
<- Mnone
6492 | Msel
((x0, y0), (x1, y1)) ->
6493 let rec loop = function
6497 let a0 = l.pagedispy in
6498 let a1 = a0 + l.pagevh in
6499 let b0 = l.pagedispx in
6500 let b1 = b0 + l.pagevw in
6501 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6502 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6506 match getopaque l.pageno with
6509 match Ne.pipe () with
6513 "can not create sel pipe: %s"
6516 let doclose what fd
=
6517 Ne.clo fd
(fun msg
->
6518 dolog
"%s close failed: %s" what msg
)
6521 popen conf.selcmd
[r, 0; w, -1];
6522 copysel
w opaque
true;
6524 G.postRedisplay "copysel";
6526 dolog
"can not execute %S: %s"
6527 conf.selcmd
(exntos exn
);
6535 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6536 state.mstate
<- Mnone
;
6543 let birdseyemouse button down
x y mask
6544 (conf, leftx
, _, hooverpageno
, anchor) =
6547 let rec loop = function
6550 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6551 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6553 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6559 | _ -> viewmouse button down
x y mask
6565 method key key mask
=
6566 begin match state.mode with
6567 | Textentry
textentry -> textentrykeyboard key mask
textentry
6568 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6569 | View
-> viewkeyboard key mask
6570 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6574 method button button bstate
x y mask
=
6575 begin match state.mode with
6577 | View
-> viewmouse button bstate
x y mask
6578 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6583 method multiclick clicks
x y mask
=
6584 begin match state.mode with
6586 | View
-> viewmulticlick clicks
x y mask
6593 begin match state.mode with
6595 | View
| Birdseye
_ | LinkNav
_ ->
6596 match state.mstate
with
6597 | Mzoom
_ | Mnone
-> ()
6602 state.mstate
<- Mpan
(x, y);
6604 then state.x <- panbound (state.x + dx);
6606 gotoy_and_clear_text y
6609 state.mstate
<- Msel
(a, (x, y));
6610 G.postRedisplay "motion select";
6613 let y = min
state.winh
(max
0 y) in
6617 let x = min
state.winw (max
0 x) in
6620 | Mzoomrect
(p0
, _) ->
6621 state.mstate
<- Mzoomrect
(p0
, (x, y));
6622 G.postRedisplay "motion zoomrect";
6626 method pmotion
x y =
6627 begin match state.mode with
6628 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6629 let rec loop = function
6631 if hooverpageno
!= -1
6633 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6634 G.postRedisplay "pmotion birdseye no hoover";
6637 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6638 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6640 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6641 G.postRedisplay "pmotion birdseye hoover";
6651 match state.mstate
with
6652 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6659 let past, _, _ = !r in
6661 let delta = now -. past in
6664 else r := (now, x, y)
6668 method infochanged
_ = ()
6671 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6674 then 0.0, float state.winh
6675 else scrollph state.y maxy
6680 let winw = wadjsb state.winw in
6681 let fwinw = float winw in
6683 let sw = fwinw /. float state.w in
6684 let sw = fwinw *. sw in
6685 max
sw (float conf.scrollh
)
6688 let maxx = state.w + winw in
6689 let x = winw - state.x in
6690 let percent = float x /. float maxx in
6691 (fwinw -. sw) *. percent
6693 hscrollh (), position, sw
6697 match state.mode with
6698 | LinkNav
_ -> "links"
6699 | Textentry
_ -> "textentry"
6700 | Birdseye
_ -> "birdseye"
6703 findkeyhash conf modename
6705 method eformsgs
= true
6712 let fontpath = ref "";;
6715 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6718 let l = String.length
s in
6719 let b = Buffer.create
l in
6725 try Sys.getenv
"HOME"
6728 ("Can not determine home directory location: " ^ exntos exn
);
6732 let modifier_of_string = function
6733 | "alt" -> Wsi.altmask
6734 | "shift" -> Wsi.shiftmask
6735 | "ctrl" | "control" -> Wsi.ctrlmask
6736 | "meta" -> Wsi.metamask
6741 let r = Str.regexp
"-" in
6743 let elems = Str.full_split
r s in
6746 let m1 = modifier_of_string s in
6748 then (Wsi.namekey
s, m)
6751 | Str.Delim
s when n land 1 = 0 -> g s
6753 | Str.Delim
_ -> (k
, m)
6755 let rec loop n k
m = function
6758 let k, m = f n k m x in
6764 let keys_of_string =
6765 let r = Str.regexp
"[ \t]" in
6767 let elems = Str.split
r s in
6768 List.map
key_of_string elems
6771 let copykeyhashes c =
6772 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6775 let config_of c attrs
=
6779 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6780 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6781 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6782 | "preload" -> { c with preload = bool_of_string
v }
6783 | "page-bias" -> { c with pagebias
= int_of_string
v }
6784 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6785 | "horizontal-scroll-step" ->
6786 { c with hscrollstep
= max
(int_of_string
v) 1 }
6787 | "auto-scroll-step" ->
6788 { c with autoscrollstep
= max
0 (int_of_string
v) }
6789 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6790 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6793 match String.lowercase
v with
6794 | "true" -> Some infinity
6796 | f -> Some
(float_of_string
f)
6798 { c with maxwait
= mw}
6799 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6800 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6801 | "vertical-margin" ->
6802 { c with interpagespace
= max
0 (int_of_string
v) }
6804 let zoom = float_of_string
v /. 100. in
6805 let zoom = max
zoom 0.0 in
6806 { c with zoom = zoom }
6807 | "presentation" -> { c with presentation
= bool_of_string
v }
6808 | "rotation-angle" -> { c with angle
= int_of_string
v }
6809 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6810 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6811 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6812 | "proportional-display" ->
6815 then FitProportional
6818 { c with fitmodel
= fm }
6819 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6820 | "pixmap-cache-size" ->
6821 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6822 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6823 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6824 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6825 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6826 | "background-color" -> { c with bgcolor
= color_of_string v }
6827 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6828 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6829 | "mupdf-store-size" ->
6830 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6831 | "checkers" -> { c with checkers
= bool_of_string
v }
6832 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6833 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6834 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6835 | "uri-launcher" -> { c with urilauncher
= unent v }
6836 | "path-launcher" -> { c with pathlauncher
= unent v }
6837 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6838 | "invert-colors" -> { c with invert
= bool_of_string
v }
6839 | "brightness" -> { c with colorscale
= float_of_string
v }
6840 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6841 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6843 let (n, _, _) as nab
= multicolumns_of_string v in
6845 then { c with columns
= Csplit
(-n, [||]) }
6846 else { c with columns
= Cmulti
(nab
, [||]) }
6847 | "birds-eye-columns" ->
6848 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6849 | "selection-command" -> { c with selcmd
= unent v }
6850 | "synctex-command" -> { c with stcmd
= unent v }
6851 | "pax-command" -> { c with paxcmd
= unent v }
6852 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6853 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6854 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6855 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6856 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6857 | "horizontal-scrollbar-visible" ->
6860 then c.scrollb
lor scrollbhv
6861 else c.scrollb
land (lnot
scrollbhv)
6863 { c with scrollb
= b }
6864 | "vertical-scrollbar-visible" ->
6867 then c.scrollb
lor scrollbvv
6868 else c.scrollb
land (lnot
scrollbvv)
6870 { c with scrollb
= b }
6871 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6875 then Some
(ref (0.0, 0, 0))
6877 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6880 prerr_endline
("Error processing attribute (`" ^
6881 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6884 let rec fold c = function
6887 let c = apply c k v in
6890 fold { c with keyhashes
= copykeyhashes c } attrs
;
6893 let fromstring f pos
n v d =
6896 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6897 n v pos
(exntos exn
)
6902 let bookmark_of attrs
=
6903 let rec fold title page
rely visy
= function
6904 | ("title", v) :: rest
-> fold v page
rely visy rest
6905 | ("page", v) :: rest
-> fold title v rely visy rest
6906 | ("rely", v) :: rest
-> fold title page
v visy rest
6907 | ("visy", v) :: rest
-> fold title page
rely v rest
6908 | _ :: rest
-> fold title page
rely visy rest
6909 | [] -> title, page
, rely, visy
6911 fold "invalid" "0" "0" "0" attrs
6915 let rec fold path page
rely pan visy
= function
6916 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6917 | ("page", v) :: rest
-> fold path v rely pan visy rest
6918 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6919 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6920 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6921 | _ :: rest
-> fold path page
rely pan visy rest
6922 | [] -> path, page
, rely, pan
, visy
6924 fold "" "0" "0" "0" "0" attrs
6928 let rec fold rs ls
= function
6929 | ("out", v) :: rest
-> fold v ls rest
6930 | ("in", v) :: rest
-> fold rs
v rest
6931 | _ :: rest
-> fold ls rs rest
6937 let setconf dst
src =
6938 dst
.scrollbw
<- src.scrollbw
;
6939 dst
.scrollh
<- src.scrollh
;
6940 dst
.icase
<- src.icase
;
6941 dst
.preload <- src.preload;
6942 dst
.pagebias
<- src.pagebias
;
6943 dst
.verbose
<- src.verbose
;
6944 dst
.scrollstep
<- src.scrollstep
;
6945 dst
.maxhfit
<- src.maxhfit
;
6946 dst
.crophack
<- src.crophack
;
6947 dst
.autoscrollstep
<- src.autoscrollstep
;
6948 dst
.maxwait
<- src.maxwait
;
6949 dst
.hlinks
<- src.hlinks
;
6950 dst
.underinfo
<- src.underinfo
;
6951 dst
.interpagespace
<- src.interpagespace
;
6952 dst
.zoom <- src.zoom;
6953 dst
.presentation
<- src.presentation
;
6954 dst
.angle
<- src.angle
;
6955 dst
.cwinw
<- src.cwinw
;
6956 dst
.cwinh
<- src.cwinh
;
6957 dst
.savebmarks
<- src.savebmarks
;
6958 dst
.memlimit
<- src.memlimit
;
6959 dst
.fitmodel
<- src.fitmodel
;
6960 dst
.texcount
<- src.texcount
;
6961 dst
.sliceheight
<- src.sliceheight
;
6962 dst
.thumbw
<- src.thumbw
;
6963 dst
.jumpback
<- src.jumpback
;
6964 dst
.bgcolor
<- src.bgcolor
;
6965 dst
.tilew
<- src.tilew
;
6966 dst
.tileh
<- src.tileh
;
6967 dst
.mustoresize
<- src.mustoresize
;
6968 dst
.checkers
<- src.checkers
;
6969 dst
.aalevel
<- src.aalevel
;
6970 dst
.trimmargins
<- src.trimmargins
;
6971 dst
.trimfuzz
<- src.trimfuzz
;
6972 dst
.urilauncher
<- src.urilauncher
;
6973 dst
.colorspace
<- src.colorspace
;
6974 dst
.invert
<- src.invert
;
6975 dst
.colorscale
<- src.colorscale
;
6976 dst
.redirectstderr <- src.redirectstderr;
6977 dst
.ghyllscroll
<- src.ghyllscroll
;
6978 dst
.columns
<- src.columns
;
6979 dst
.beyecolumns
<- src.beyecolumns
;
6980 dst
.selcmd
<- src.selcmd
;
6981 dst
.updatecurs
<- src.updatecurs
;
6982 dst
.pathlauncher
<- src.pathlauncher
;
6983 dst
.keyhashes
<- copykeyhashes src;
6984 dst
.hfsize
<- src.hfsize
;
6985 dst
.hscrollstep
<- src.hscrollstep
;
6986 dst
.pgscale <- src.pgscale;
6987 dst
.usepbo
<- src.usepbo
;
6988 dst
.wheelbypage
<- src.wheelbypage
;
6989 dst
.stcmd
<- src.stcmd
;
6990 dst
.paxcmd
<- src.paxcmd
;
6991 dst
.scrollb
<- src.scrollb
;
6992 dst
.riani
<- src.riani
;
6993 dst
.paxmark
<- src.paxmark
;
6997 else Some
((ref (0.0, 0, 0)));
7001 let h = Hashtbl.create
10 in
7002 let dc = { defconf with angle
= defconf.angle
} in
7003 let rec toplevel v t spos
_ =
7005 | Vdata
| Vcdata
| Vend
-> v
7006 | Vopen
("llppconfig", _, closed
) ->
7009 else { v with f = llppconfig
}
7011 error
"unexpected subelement at top level" s spos
7012 | Vclose
_ -> error
"unexpected close at top level" s spos
7014 and llppconfig
v t spos
_ =
7016 | Vdata
| Vcdata
-> v
7017 | Vend
-> error
"unexpected end of input in llppconfig" s spos
7018 | Vopen
("defaults", attrs
, closed
) ->
7019 let c = config_of dc attrs
in
7023 else { v with f = defaults
}
7025 | Vopen
("ui-font", attrs
, closed
) ->
7026 let rec getsize size
= function
7028 | ("size", v) :: rest
->
7030 fromstring int_of_string spos
"size" v fstate.fontsize
in
7032 | l -> getsize size l
7034 fstate.fontsize
<- getsize fstate.fontsize attrs
;
7037 else { v with f = uifont
(Buffer.create
10) }
7039 | Vopen
("doc", attrs
, closed
) ->
7040 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
7041 let path = unent pathent
7042 and pageno = fromstring int_of_string spos
"page" spage
0
7043 and rely = fromstring float_of_string spos
"rely" srely
0.0
7044 and pan
= fromstring int_of_string spos
"pan" span
0
7045 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7046 let c = config_of dc attrs
in
7047 let anchor = (pageno, rely, visy
) in
7049 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
7050 else { v with f = doc
path pan
anchor c [] }
7053 error
"unexpected subelement in llppconfig" s spos
7055 | Vclose
"llppconfig" -> { v with f = toplevel }
7056 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
7058 and defaults
v t spos
_ =
7060 | Vdata
| Vcdata
-> v
7061 | Vend
-> error
"unexpected end of input in defaults" s spos
7062 | Vopen
("keymap", attrs
, closed
) ->
7064 try List.assoc
"mode" attrs
7065 with Not_found
-> "global" in
7070 let h = findkeyhash dc modename in
7071 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7074 { v with f = pkeymap
ret KeyMap.empty }
7076 | Vopen
(_, _, _) ->
7077 error
"unexpected subelement in defaults" s spos
7079 | Vclose
"defaults" ->
7080 { v with f = llppconfig
}
7082 | Vclose
_ -> error
"unexpected close in defaults" s spos
7084 and uifont
b v t spos
epos =
7087 Buffer.add_substring
b s spos
(epos - spos
);
7089 | Vopen
(_, _, _) ->
7090 error
"unexpected subelement in ui-font" s spos
7091 | Vclose
"ui-font" ->
7092 if emptystr
!fontpath
7093 then fontpath := Buffer.contents
b;
7094 { v with f = llppconfig
}
7095 | Vclose
_ -> error
"unexpected close in ui-font" s spos
7096 | Vend
-> error
"unexpected end of input in ui-font" s spos
7098 and doc
path pan
anchor c bookmarks
v t spos
_ =
7100 | Vdata
| Vcdata
-> v
7101 | Vend
-> error
"unexpected end of input in doc" s spos
7102 | Vopen
("bookmarks", _, closed
) ->
7105 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
7107 | Vopen
("keymap", attrs
, closed
) ->
7109 try List.assoc
"mode" attrs
7110 with Not_found
-> "global"
7116 let h = findkeyhash c modename in
7117 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7118 doc
path pan
anchor c bookmarks
7120 { v with f = pkeymap
ret KeyMap.empty }
7122 | Vopen
(_, _, _) ->
7123 error
"unexpected subelement in doc" s spos
7126 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7127 { v with f = llppconfig
}
7129 | Vclose
_ -> error
"unexpected close in doc" s spos
7131 and pkeymap
ret keymap
v t spos
_ =
7133 | Vdata
| Vcdata
-> v
7134 | Vend
-> error
"unexpected end of input in keymap" s spos
7135 | Vopen
("map", attrs
, closed
) ->
7136 let r, l = map_of attrs
in
7137 let kss = fromstring keys_of_string spos
"in" r [] in
7138 let lss = fromstring keys_of_string spos
"out" l [] in
7142 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7143 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7146 then { v with f = pkeymap
ret keymap }
7149 { v with f = skip
"map" f }
7152 error
"unexpected subelement in keymap" s spos
7154 | Vclose
"keymap" ->
7155 { v with f = ret keymap }
7157 | Vclose
_ -> error
"unexpected close in keymap" s spos
7159 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7161 | Vdata
| Vcdata
-> v
7162 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7163 | Vopen
("item", attrs
, closed
) ->
7164 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7165 let page = fromstring int_of_string spos
"page" spage
0
7166 and rely = fromstring float_of_string spos
"rely" srely
0.0
7167 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7169 (unent titleent, 0, Oanchor
(page, rely, visy
)) :: bookmarks
7172 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7175 { v with f = skip
"item" f }
7178 error
"unexpected subelement in bookmarks" s spos
7180 | Vclose
"bookmarks" ->
7181 { v with f = doc
path pan
anchor c bookmarks }
7183 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7185 and skip tag
f v t spos
_ =
7187 | Vdata
| Vcdata
-> v
7189 error
("unexpected end of input in skipped " ^ tag
) s spos
7190 | Vopen
(tag'
, _, closed
) ->
7194 let f'
() = { v with f = skip tag
f } in
7195 { v with f = skip tag'
f'
}
7199 else error
("unexpected close in skipped " ^ tag
) s spos
7202 parse
{ f = toplevel; accu = () } s;
7208 let len = in_channel_length ic
in
7209 let s = String.create
len in
7210 really_input ic
s 0 len;
7213 | Parse_error
(msg
, s, pos
) ->
7214 let subs = subs s pos
in
7215 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7218 failwith
("config load error: " ^ exntos exn
)
7224 let dir = Filename.concat
home ".config" in
7225 if Sys.is_directory
dir then dir else home
7228 Filename.concat
dir "llpp.conf"
7231 let confpath = ref defconfpath;;
7234 if Sys.file_exists
!confpath
7237 (try Some
(open_in_bin
!confpath)
7240 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7251 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7260 f (Hashtbl.create
0, defconf)
7265 let pc, pb
, px, pa
=
7268 if emptystr
state.origin
7272 Hashtbl.find h (Filename.basename
key)
7273 with Not_found
-> dc, [], 0, emptyanchor
7277 state.bookmarks <- pb
;
7280 then state.anchor <- pa
;
7281 cbput state.hists
.nav pa
;
7287 let add_attrs bb always
dc c =
7290 then Printf.bprintf bb
"\n %s='%b'" s a
7293 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7296 then Printf.bprintf bb
"\n %s='%d'" s a
7299 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7302 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7305 then Printf.bprintf bb
"\n %s='%f'" s a
7309 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7313 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7317 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7321 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7326 | Some
(_N
, _A
, _B
) ->
7327 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7332 Printf.bprintf bb
"\n %s='none'" s
7342 else string_of_float
f
7344 Printf.bprintf bb
"\n %s='%s'" s v
7349 | Cmulti
((n, a, b), _) when n > 1 ->
7350 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7351 | Csplit
(n, _) when n > 1 ->
7352 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7358 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7363 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7367 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7371 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7373 oi
"width" c.cwinw
dc.cwinw
;
7374 oi
"height" c.cwinh
dc.cwinh
;
7375 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7376 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7377 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7378 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7379 ob "case-insensitive-search" c.icase
dc.icase
;
7380 ob "preload" c.preload dc.preload;
7381 oi
"page-bias" c.pagebias
dc.pagebias
;
7382 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7383 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7384 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7385 ob "crop-hack" c.crophack
dc.crophack
;
7386 oW
"throttle" c.maxwait
dc.maxwait
;
7387 ob "highlight-links" c.hlinks
dc.hlinks
;
7388 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7389 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7390 oz
"zoom" c.zoom dc.zoom;
7391 ob "presentation" c.presentation
dc.presentation
;
7392 oi
"rotation-angle" c.angle
dc.angle
;
7393 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7394 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7395 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7396 oi
"tex-count" c.texcount
dc.texcount
;
7397 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7398 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7399 ob "persistent-location" c.jumpback
dc.jumpback
;
7400 oc
"background-color" c.bgcolor
dc.bgcolor
;
7401 oi
"tile-width" c.tilew
dc.tilew
;
7402 oi
"tile-height" c.tileh
dc.tileh
;
7403 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7404 ob "checkers" c.checkers
dc.checkers
;
7405 oi
"aalevel" c.aalevel
dc.aalevel
;
7406 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7407 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7408 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7409 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7410 oC
"color-space" c.colorspace
dc.colorspace
;
7411 ob "invert-colors" c.invert
dc.invert
;
7412 oF
"brightness" c.colorscale
dc.colorscale
;
7413 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7414 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7415 oco
"columns" c.columns
dc.columns
;
7416 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7417 os
"selection-command" c.selcmd
dc.selcmd
;
7418 os
"synctex-command" c.stcmd
dc.stcmd
;
7419 os
"pax-command" c.paxcmd
dc.paxcmd
;
7420 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7421 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7422 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7423 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7424 ob "use-pbo" c.usepbo
dc.usepbo
;
7425 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7426 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7427 op
"point-and-x" c.pax
dc.pax
;
7428 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7431 let keymapsbuf always
dc c =
7432 let bb = Buffer.create
16 in
7433 let rec loop = function
7435 | (modename, h) :: rest
->
7436 let dh = findkeyhash dc modename in
7437 if always
|| h <> dh
7439 if Hashtbl.length
h > 0
7441 if Buffer.length
bb > 0
7442 then Buffer.add_char
bb '
\n'
;
7443 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7444 Hashtbl.iter
(fun i
o ->
7445 let isdifferent = always
||
7447 let dO = Hashtbl.find dh i
in
7449 with Not_found
-> true
7454 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7455 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7456 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7457 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7458 Buffer.add_string
bb (Wsi.keyname
k);
7461 let rec loop = function
7463 | km
:: [] -> addkm km
7464 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7468 Buffer.add_string
bb "<map in='";
7472 Buffer.add_string
bb "' out='";
7474 Buffer.add_string
bb "'/>\n"
7477 Buffer.add_string
bb "' out='";
7479 Buffer.add_string
bb "'/>\n"
7481 | KMmulti
(ins, kms
) ->
7482 Buffer.add_char
bb ' '
;
7484 Buffer.add_string
bb "' out='";
7486 Buffer.add_string
bb "'/>\n"
7488 Buffer.add_string
bb "</keymap>";
7498 let uifontsize = fstate.fontsize
in
7499 let bb = Buffer.create
32768 in
7500 let relx = float state.x /. float state.winw in
7502 let cx w = truncate
(relx *. float w) in
7504 (fun (w, h, x) ws
->
7506 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7507 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7508 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7510 (state.winw, state.winh
, state.x) state.winstate
7515 let dc = if conf.bedefault
then conf else dc in
7516 Buffer.add_string
bb "<llppconfig>\n";
7518 if nonemptystr
!fontpath
7520 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7526 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7529 Buffer.add_string
bb "<defaults";
7530 add_attrs bb true dc dc;
7531 let kb = keymapsbuf true dc dc in
7532 if Buffer.length
kb > 0
7534 Buffer.add_string
bb ">\n";
7535 Buffer.add_buffer
bb kb;
7536 Buffer.add_string
bb "\n</defaults>\n";
7538 else Buffer.add_string
bb "/>\n";
7540 let adddoc path pan
anchor c bookmarks =
7541 if bookmarks == [] && c = dc && anchor = emptyanchor
7544 Printf.bprintf
bb "<doc path='%s'"
7545 (enent
path 0 (String.length
path));
7547 if anchor <> emptyanchor
7549 let n, rely, visy
= anchor in
7550 Printf.bprintf
bb " page='%d'" n;
7553 Printf.bprintf
bb " rely='%f'" rely
7555 if abs_float visy
> 1e-6
7557 Printf.bprintf
bb " visy='%f'" visy
7562 then Printf.bprintf
bb " pan='%d'" pan
;
7564 add_attrs bb false dc c;
7565 let kb = keymapsbuf false dc c in
7567 begin match bookmarks with
7569 if Buffer.length
kb > 0
7571 Buffer.add_string
bb ">\n";
7572 Buffer.add_buffer
bb kb;
7573 Buffer.add_string
bb "\n</doc>\n";
7575 else Buffer.add_string
bb "/>\n"
7577 Buffer.add_string
bb ">\n<bookmarks>\n";
7578 List.iter
(fun (title, _, kind
) ->
7579 begin match kind
with
7580 | Oanchor
(page, rely, visy
) ->
7582 "<item title='%s' page='%d'"
7583 (enent
title 0 (String.length
title))
7588 Printf.bprintf
bb " rely='%f'" rely
7590 if abs_float visy
> 1e-6
7592 Printf.bprintf
bb " visy='%f'" visy
7594 | Onone
| Ouri
_ | Oremote
_ | Oremotedest
_ | Olaunch
_ ->
7595 failwith
"unexpected link in bookmarks"
7597 Buffer.add_string
bb "/>\n";
7599 Buffer.add_string
bb "</bookmarks>";
7600 if Buffer.length
kb > 0
7602 Buffer.add_string
bb "\n";
7603 Buffer.add_buffer
bb kb;
7605 Buffer.add_string
bb "\n</doc>\n";
7611 match state.mode with
7612 | Birdseye
(c, pan, _, _, _) ->
7614 match conf.columns
with
7615 | Cmulti
((c, _, _), _) -> Some
c
7619 match c.columns
with
7620 | Cmulti
(c, _) -> Cmulti
(c, [||])
7621 | Csingle
_ -> Csingle
[||]
7622 | Csplit
_ -> failwith
"quit from bird's eye while split"
7624 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7627 let basename = Filename.basename
7628 (if emptystr
state.origin
then state.path else state.origin
)
7630 adddoc basename pan (getanchor ())
7632 let autoscrollstep =
7633 match state.autoscroll
with
7635 | None
-> conf.autoscrollstep
7637 match state.mode with
7638 | Birdseye
(bc
, _, _, _, _) ->
7641 presentation
= bc
.presentation
;
7642 interpagespace
= bc
.interpagespace
;
7643 maxwait
= bc
.maxwait
;
7644 autoscrollstep = autoscrollstep }
7645 | _ -> { conf with autoscrollstep = autoscrollstep }
7647 (if conf.savebmarks
then state.bookmarks else []);
7649 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7651 then adddoc path x anchor c bookmarks
7653 Buffer.add_string
bb "</llppconfig>\n";
7656 if load1 f && Buffer.length
bb > 0
7659 let tmp = !confpath ^
".tmp" in
7660 let oc = open_out_bin
tmp in
7661 Buffer.output_buffer
oc bb;
7663 Unix.rename
tmp !confpath;
7666 ("error while saving configuration: " ^ exntos exn
)
7670 let adderrmsg src msg
=
7671 Buffer.add_string
state.errmsgs msg
;
7672 state.newerrmsgs
<- true;
7676 let adderrfmt src fmt
=
7677 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7681 let cl = splitatspace cmds
in
7683 try Scanf.sscanf
s fmt
f
7685 adderrfmt "remote exec"
7686 "error processing '%S': %s\n" cmds
(exntos exn
)
7689 | "reload" :: [] -> reload ()
7690 | "goto" :: args :: [] ->
7691 scan args "%u %f %f"
7693 let cmd, _ = state.geomcmds
in
7695 then gotopagexy pageno x y
7698 gotopagexy pageno x y;
7701 state.reprf
<- f state.reprf
7703 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7704 | "gotor" :: args :: [] ->
7706 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
7707 | "gotord" :: args :: [] ->
7709 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
7710 | "rect" :: args :: [] ->
7711 scan args "%u %u %f %f %f %f"
7712 (fun pageno color x0 y0 x1 y1 ->
7713 onpagerect pageno (fun w h ->
7714 let _,w1,h1
,_ = getpagedim pageno in
7715 let sw = float w1 /. float w
7716 and sh = float h1
/. float h in
7720 and y1s
= y1 *. sh in
7721 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7723 state.rects <- (pageno, color, rect) :: state.rects;
7724 G.postRedisplay "rect";
7727 | "activatewin" :: [] -> Wsi.activatewin
()
7728 | "quit" :: [] -> raise Quit
7730 adderrfmt "remote command"
7731 "error processing remote command: %S\n" cmds
;
7735 let scratch = String.create
80 in
7736 let buf = Buffer.create
80 in
7739 try Some
(Unix.read fd
scratch 0 80)
7741 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7742 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7745 match tempfr () with
7751 if Buffer.length
buf > 0
7753 let s = Buffer.contents
buf in
7763 let pos = String.index_from
scratch ppos '
\n'
in
7764 if pos >= n then -1 else pos
7765 with Not_found
-> -1
7769 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7770 let s = Buffer.contents
buf in
7776 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7782 let remoteopen path =
7783 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7785 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7790 let trimcachepath = ref "" in
7791 let rcmdpath = ref "" in
7792 let pageno = ref None
in
7793 selfexec := Sys.executable_name
;
7796 [("-p", Arg.String
(fun s -> state.password
<- s),
7797 "<password> Set password");
7801 Config.fontpath := s;
7802 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7804 "<path> Set path to the user interface font");
7808 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7809 Config.confpath := s),
7810 "<path> Set path to the configuration file");
7812 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
7813 "<page-number> Jump to page");
7815 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7816 "<path> Set path to the trim cache file");
7818 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7819 "<named-destination> Set named destination");
7821 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7822 ("-cxack", Arg.Set
cxack, " Cut corners");
7824 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7825 "<path> Set path to the remote commands source");
7827 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7828 "<original-path> Set original path");
7830 ("-v", Arg.Unit
(fun () ->
7832 "%s\nconfiguration path: %s\n"
7836 exit
0), " Print version and exit");
7839 (fun s -> state.path <- s)
7840 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7843 then selfexec := !selfexec ^
" -wtmode";
7845 if emptystr
state.path
7846 then (prerr_endline
"file name missing"; exit
1);
7848 if not
(Config.load ())
7849 then prerr_endline
"failed to load configuration";
7850 begin match !pageno with
7851 | Some
pageno -> state.anchor <- (pageno, 0.0, 0.0)
7855 let wsfd, winw, winh
= Wsi.init
(object
7856 val mutable m_hack
= false
7857 val mutable m_clicks
= 0
7858 val mutable m_click_x
= 0
7859 val mutable m_click_y
= 0
7860 val mutable m_lastclicktime
= infinity
7862 method expose
= if not m_hack
then G.postRedisplay "expose"
7863 method visible
= G.postRedisplay "visible"
7864 method display = m_hack
<- false; display ()
7865 method reshape w h =
7866 m_hack
<- w < state.winw && h < state.winh
;
7868 method mouse
b d x y m =
7871 (* http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx *)
7877 if abs
x - m_click_x
> 10
7878 || abs
y - m_click_y
> 10
7879 || abs_float
(t -. m_lastclicktime
) > 0.3
7881 m_clicks
<- m_clicks
+ 1;
7882 m_lastclicktime
<- t;
7884 then state.uioh <- state.uioh#button
b d x y m
7885 else state.uioh <- state.uioh#multiclick m_clicks
x y m
7888 m_lastclicktime
<- infinity
;
7889 state.uioh <- state.uioh#button
b d x y m
7893 state.uioh <- state.uioh#button
b d x y m
7896 state.mpos
<- (x, y);
7897 state.uioh <- state.uioh#motion
x y
7898 method pmotion
x y =
7899 state.mpos
<- (x, y);
7900 state.uioh <- state.uioh#pmotion
x y
7902 let mascm = m land (
7903 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7905 match state.keystate
with
7907 let km = k, mascm in
7910 let modehash = state.uioh#
modehash in
7911 try Hashtbl.find modehash km
7913 try Hashtbl.find (findkeyhash conf "global") km
7914 with Not_found
-> KMinsrt
(k, m)
7916 | KMinsrt
(k, m) -> keyboard k m
7917 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7918 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7920 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7921 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7922 state.keystate
<- KSnone
7923 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7924 state.keystate
<- KSinto
(keys
, insrt
)
7926 state.keystate
<- KSnone
7929 state.mpos
<- (x, y);
7930 state.uioh <- state.uioh#pmotion
x y
7931 method leave = state.mpos
<- (-1, -1)
7932 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7933 method quit
= raise Quit
7934 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7939 List.exists
GlMisc.check_extension
7940 [ "GL_ARB_texture_rectangle"
7941 ; "GL_EXT_texture_recangle"
7942 ; "GL_NV_texture_rectangle" ]
7944 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7947 let r = GlMisc.get_string `renderer
in
7948 let p = "Mesa DRI Intel(" in
7949 let l = String.length
p in
7950 String.length
r > l && String.sub
r 0 l = p
7953 defconf.sliceheight
<- 1024;
7954 defconf.texcount
<- 32;
7955 defconf.usepbo
<- true;
7959 match Ne.pipe () with
7961 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7965 match Ne.pipe () with
7967 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7977 setcheckers conf.checkers
;
7979 if conf.redirectstderr
7982 let s = Buffer.contents
state.errmsgs ^
7983 (match state.errfd
with
7985 let s = String.create
(80*24) in
7988 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7990 then Unix.read fd
s 0 (String.length
s)
7996 else String.sub
s 0 n
8000 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
8001 with exn
-> print_endline
(exntos exn
)
8006 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
8007 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
8008 !Config.fontpath, !trimcachepath,
8009 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
8011 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
8014 state.text <- "Opening " ^
(mbtoutf8
state.path);
8016 opendoc state.path state.password
;
8020 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
8023 if nonemptystr
!rcmdpath
8024 then remoteopen !rcmdpath
8029 let rec loop deadline
=
8031 match state.errfd
with
8032 | None
-> [state.sr
; state.wsfd]
8033 | Some fd
-> [state.sr
; state.wsfd; fd
]
8038 | Some fd
-> fd
:: r
8042 state.redisplay
<- false;
8049 if deadline
= infinity
8051 else max
0.0 (deadline
-. now)
8056 try Unix.select
r [] [] timeout
8057 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
8063 if state.ghyll
== noghyll
8065 match state.autoscroll
with
8066 | Some step
when step
!= 0 ->
8067 let y = state.y + step
in
8071 else if y >= state.maxy then 0 else y
8074 if state.mode = View
8075 then state.text <- "";
8078 else deadline
+. 0.01
8083 let rec checkfds = function
8085 | fd
:: rest
when fd
= state.sr
->
8086 let cmd = readcmd state.sr
in
8090 | fd
:: rest
when fd
= state.wsfd ->
8094 | fd
:: rest
when Some fd
= !optrfd ->
8095 begin match remote fd
with
8096 | None
-> optrfd := remoteopen !rcmdpath;
8097 | opt -> optrfd := opt
8102 let s = String.create
80 in
8103 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
8104 if conf.redirectstderr
8106 Buffer.add_substring
state.errmsgs
s 0 n;
8107 state.newerrmsgs
<- true;
8108 state.redisplay
<- true;
8111 prerr_string
(String.sub
s 0 n);
8119 if deadline
= infinity
8123 match state.autoscroll
with
8124 | Some step
when step
!= 0 -> deadline1
8125 | _ -> if state.ghyll
== noghyll then infinity
else deadline1