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 motion
: int -> int -> uioh
417 method pmotion
: int -> int -> uioh
418 method infochanged
: infochange
-> unit
419 method scrollpw
: (int * float * float)
420 method scrollph
: (int * float * float)
421 method modehash
: keyhash
422 method eformsgs
: bool
426 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
427 | Textentry
of (textentry
* onleave
)
429 | LinkNav
of linktarget
430 and onleave
= leavetextentrystatus
-> unit
431 and leavetextentrystatus
= | Cancel
| Confirm
432 and helpitem
= string * int * action
435 | Action
of (uioh
-> uioh
)
437 | Ltexact
of (pageno
* int)
441 let isbirdseye = function Birdseye _
-> true | _
-> false;;
442 let istextentry = function Textentry _
-> true | _
-> false;;
446 | Loading
of (page
* gen
)
448 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
450 | Outlining
of outline list
453 let emptykeyhash = Hashtbl.create
0;;
454 let nouioh : uioh
= object (self
)
456 method key _ _
= self
457 method button _ _ _ _ _
= self
458 method motion _ _
= self
459 method pmotion _ _
= self
460 method infochanged _
= ()
461 method scrollpw
= (0, nan
, nan
)
462 method scrollph
= (0, nan
, nan
)
463 method modehash
= emptykeyhash
464 method eformsgs
= false
468 { mutable sr
: Unix.file_descr
469 ; mutable sw
: Unix.file_descr
470 ; mutable wsfd
: Unix.file_descr
471 ; mutable errfd
: Unix.file_descr
option
472 ; mutable stderr
: Unix.file_descr
473 ; mutable errmsgs
: Buffer.t
474 ; mutable newerrmsgs
: bool
478 ; mutable anchor
: anchor
479 ; mutable ranchors
: (string * string * anchor
* string) list
481 ; mutable layout
: page list
482 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
483 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
484 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
485 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
486 ; mutable pagecount
: int
487 ; mutable currently
: currently
488 ; mutable mstate
: mstate
489 ; mutable searchpattern
: string
490 ; mutable rects
: (pageno
* recttype
* rect
) list
491 ; mutable rects1
: (pageno
* recttype
* rect
) list
492 ; mutable text
: string
493 ; mutable winstate
: Wsi.winstate list
494 ; mutable mode
: mode
495 ; mutable uioh
: uioh
496 ; mutable outlines
: outline array
497 ; mutable bookmarks
: outline list
498 ; mutable path
: string
499 ; mutable password
: string
500 ; mutable nameddest
: string
501 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
502 ; mutable memused
: memsize
504 ; mutable throttle
: (page list
* int * float) option
505 ; mutable autoscroll
: int option
506 ; mutable ghyll
: (int option -> unit)
507 ; mutable help
: helpitem array
508 ; mutable docinfo
: (int * string) list
509 ; mutable texid
: GlTex.texture_id
option
511 ; mutable prevzoom
: (float * int)
512 ; mutable progress
: float
513 ; mutable redisplay
: bool
514 ; mutable mpos
: mpos
515 ; mutable keystate
: keystate
516 ; mutable glinks
: bool
517 ; mutable prevcolumns
: (columns
* float) option
520 ; mutable reprf
: (unit -> unit)
521 ; mutable origin
: string
522 ; mutable roam
: (unit -> unit)
523 ; mutable bzoom
: bool
524 ; mutable traw
: [`
float] Raw.t
525 ; mutable vraw
: [`
float] Raw.t
528 { pat
: string circbuf
529 ; pag
: string circbuf
530 ; nav
: anchor circbuf
531 ; sel
: string circbuf
538 ; scrollb
= scrollbhv lor scrollbvv
554 ; presentation
= false
559 ; fitmodel
= FitProportional
560 ; trimmargins
= false
561 ; trimfuzz
= (0,0,0,0)
562 ; memlimit
= 32 lsl 20
567 ; bgcolor
= (0.5, 0.5, 0.5)
571 ; mustoresize
= 256 lsl 20
576 | Plinux
| Pfreebsd
| Pdragonflybsd
577 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
578 | Posx
-> "open \"%s\""
579 | Pcygwin
-> "cygstart \"%s\""
580 | Punknown
-> "echo %s")
581 ; pathlauncher
= "lp \"%s\""
584 | Plinux
| Pfreebsd
| Pdragonflybsd
585 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
593 ; redirectstderr
= false
595 ; columns
= Csingle
[||]
601 ; wheelbypage
= false
602 ; stcmd
= "echo SyncTex"
605 ; paxmark
= Mark_word
607 let mk n
= (n
, Hashtbl.create
1) in
621 let wtmode = ref false;;
622 let cxack = ref false;;
624 let findkeyhash c name
=
625 try List.assoc name c
.keyhashes
626 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
629 let conf = { defconf with angle
= defconf.angle
};;
631 let pgscale h
= truncate
(float h
*. conf.pgscale);;
634 { mutable fontsize
: int
635 ; mutable wwidth
: float
636 ; mutable maxrows
: int
648 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
649 let len = String.length s
in
650 if colonpos >= 0 && colonpos + 3 < len
652 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
655 try String.rindex_from s
colonpos ' '
659 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
662 | "http" | "ftp" | "mailto" ->
664 try String.index_from s
colonpos ' '
665 with Not_found
-> len
667 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
675 if emptystr
conf.urilauncher
676 then print_endline uri
678 let url = geturl uri
in
680 then Printf.eprintf
"obtained empty url from uri %S" uri
682 let re = Str.regexp
"%s" in
683 let command = Str.global_replace
re url conf.urilauncher
in
687 "failed to execute `%s': %s\n" command (exntos exn
);
693 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
694 Help.version (fz_version
()) Sys.ocaml_version
695 (platform_to_string platform) Sys.word_size
699 let strings = version () :: "" :: Help.keys
in
702 let url = geturl s
in
704 then (s
, 0, Action
(fun u
-> gotouri url; u
))
705 else (s
, 0, Noaction
)
710 let firstgeomcmds = "", [];;
711 let noreprf () = ();;
718 ; stderr
= Unix.stderr
719 ; errmsgs
= Buffer.create
0
724 ; anchor
= emptyanchor
728 ; tilelru
= Queue.create
()
729 ; pagemap
= Hashtbl.create
10
730 ; tilemap
= Hashtbl.create
10
746 ; geomcmds
= firstgeomcmds
748 { nav
= cbnew 10 emptyanchor
761 ; prevzoom
= (1.0, 0)
773 ; roam
= (fun () -> ())
775 ; traw
= Raw.create_static `
float 8
776 ; vraw
= Raw.create_static `
float 8
781 if (conf.scrollb
land scrollbhv = 0)
782 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
788 if (conf.scrollb
land scrollbvv = 0)
793 let wadjsb w
= w
- vscrollw ();;
796 fstate.fontsize
<- n
;
797 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
798 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
804 Printf.kprintf prerr_endline fmt
806 Printf.kprintf ignore fmt
810 if emptystr
conf.pathlauncher
811 then print_endline
state.path
813 let re = Str.regexp
"%s" in
814 let command = Str.global_replace
re state.path
conf.pathlauncher
in
817 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
823 type 'a t
= | Res
of 'a
| Exn
of exn
;;
826 try Res
(Unix.pipe ())
831 try tempfailureretry
Unix.close fd
832 with exn
-> f
(exntos exn
)
836 try Res
(tempfailureretry
Unix.dup fd
)
841 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
846 let redirectstderr () =
847 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
848 if conf.redirectstderr
850 match Ne.pipe () with
852 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
855 begin match Ne.dup Unix.stderr
with
857 dolog
"failed to dup stderr: %s" (exntos exn
);
858 Ne.clo r
(clofail "pipe/r");
859 Ne.clo w
(clofail "pipe/w");
861 | Ne.Res dupstderr
->
862 begin match Ne.dup2 w
Unix.stderr
with
864 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
865 Ne.clo dupstderr
(clofail "stderr duplicate");
866 Ne.clo r
(clofail "redir pipe/r");
867 Ne.clo w
(clofail "redir pipe/w");
870 state.stderr
<- dupstderr
;
871 state.errfd
<- Some r
;
875 state.newerrmsgs
<- false;
876 begin match state.errfd
with
878 begin match Ne.dup2 state.stderr
Unix.stderr
with
880 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
882 Ne.clo fd
(clofail "dup of stderr");
887 prerr_string
(Buffer.contents
state.errmsgs
);
889 Buffer.clear
state.errmsgs
;
895 let postRedisplay who
=
897 then prerr_endline
("redisplay for " ^ who
);
898 state.redisplay
<- true;
902 let getopaque pageno
=
903 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
904 with Not_found
-> None
907 let putopaque pageno opaque
=
908 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
911 let pagetranslatepoint l x y
=
912 let dy = y
- l
.pagedispy
in
913 let y = dy + l
.pagey
in
914 let dx = x
- l
.pagedispx
in
915 let x = dx + l
.pagex
in
919 let onppundermouse g
x y d
=
922 begin match getopaque l
.pageno
with
924 let x0 = l
.pagedispx
in
925 let x1 = x0 + l
.pagevw
in
926 let y0 = l
.pagedispy
in
927 let y1 = y0 + l
.pagevh
in
928 if y >= y0 && y <= y1 && x >= x0 && x <= x1
930 let px, py
= pagetranslatepoint l
x y in
931 match g opaque l
px py
with
944 let g opaque l
px py
=
947 match rectofblock opaque
px py
with
949 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
950 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
951 G.postRedisplay "getunder";
954 match whatsunder opaque
px py
with
956 | under
-> Some under
958 onppundermouse g x y Unone
963 match unproject opaque
x y with
964 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
967 onppundermouse g x y None
;
971 state.text
<- Printf.sprintf
"%c%s" c s
;
972 G.postRedisplay "showtext";
976 let g opaque l
px py
=
977 if markunder opaque
px py
conf.paxmark
980 match getopaque l
.pageno
with
983 match Ne.pipe () with
987 "can not create mark pipe: %s"
990 let doclose what fd
=
991 Ne.clo fd
(fun msg
->
992 dolog
"%s close failed: %s" what msg
)
995 popen conf.paxcmd
[r
, 0; w
, -1];
996 copysel w opaque
false;
998 G.postRedisplay "paxunder";
1000 dolog
"can not execute %S: %s"
1001 conf.paxcmd
(exntos exn
);
1008 G.postRedisplay "paxunder";
1009 if conf.paxmark
= Mark_page
1012 match getopaque l
.pageno
with
1014 | Some opaque
-> clearmark opaque
) state.layout
;
1016 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1020 match Ne.pipe () with
1022 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1025 try popen conf.selcmd
[r
, 0; w
, -1]; true
1028 (Printf.sprintf
"failed to execute %s: %s"
1029 conf.selcmd
(exntos exn
));
1033 Ne.clo fd
(fun msg
->
1034 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1040 let l = String.length s
in
1041 let n = tempfailureretry
(Unix.write w s
0) l in
1046 "failed to write %d characters to sel pipe, wrote %d"
1051 (Printf.sprintf
"failed to write to sel pipe: %s"
1060 let undertext = function
1063 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1064 | Utext s
-> "font: " ^ s
1065 | Uunexpected s
-> "unexpected: " ^ s
1066 | Ulaunch s
-> "launch: " ^ s
1067 | Unamed s
-> "named: " ^ s
1068 | Uremote
(filename
, pageno
) ->
1069 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1070 | Uremotedest
(filename
, destname
) ->
1071 Printf.sprintf
"%s: destination %S" filename destname
1074 let updateunder x y =
1075 match getunder x y with
1076 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1078 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1079 Wsi.setcursor
Wsi.CURSOR_INFO
1080 | Ulinkgoto
(pageno
, _
) ->
1082 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1083 Wsi.setcursor
Wsi.CURSOR_INFO
1085 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1086 Wsi.setcursor
Wsi.CURSOR_TEXT
1088 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1089 Wsi.setcursor
Wsi.CURSOR_INHERIT
1091 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1092 Wsi.setcursor
Wsi.CURSOR_INHERIT
1094 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1095 Wsi.setcursor
Wsi.CURSOR_INHERIT
1096 | Uremote
(filename
, pageno
) ->
1097 if conf.underinfo
then showtext 'r'
1098 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1099 Wsi.setcursor
Wsi.CURSOR_INFO
1100 | Uremotedest
(filename
, destname
) ->
1101 if conf.underinfo
then showtext 'r'
1102 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1103 Wsi.setcursor
Wsi.CURSOR_INFO
1106 let showlinktype under
=
1112 let s = undertext under
in
1117 let b = Buffer.create
(String.length
s + 1) in
1118 Buffer.add_string
b s;
1119 Buffer.add_char
b c
;
1123 module type TextEnumType
=
1127 val names
: string array
1130 module TextEnumMake
(Ten
: TextEnumType
) =
1132 let names = Ten.names;;
1133 let to_int (t
: Ten.t
) = Obj.magic t
;;
1134 let to_string t
= names.(to_int t
);;
1135 let of_int n : Ten.t
= Obj.magic
n;;
1138 if i
= Array.length
names
1139 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1141 if Ten.names.(i
) = s
1148 module CSTE
= TextEnumMake
(struct
1149 type t
= colorspace
;;
1150 let name = "colorspace";;
1151 let names = [|"rgb"; "bgr"; "gray"|];;
1154 module MTE
= TextEnumMake
(struct
1157 let names = [|"page"; "block"; "line"; "word"|];;
1160 module FMTE
= TextEnumMake
(struct
1162 let name = "fitmodel";;
1163 let names = [|"width"; "proportional"; "page"|];;
1166 let intentry_with_suffix text key
=
1168 if key
>= 32 && key
< 127
1172 match Char.lowercase
c with
1174 let text = addchar text c in
1177 | 'k'
| 'm'
| '
g'
->
1178 let text = addchar text c in
1182 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1186 let multicolumns_to_string (n, a
, b) =
1188 then Printf.sprintf
"%d" n
1189 else Printf.sprintf
"%d,%d,%d" n a
b;
1192 let multicolumns_of_string s =
1194 (int_of_string
s, 0, 0)
1196 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1198 then failwith
"subtly broken"; (n, a
, b)
1204 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1205 if n != 4 then error
"incomplete read(len) = %d" n;
1207 lor (Char.code
s.[0] lsl 24)
1208 lor (Char.code
s.[1] lsl 16)
1209 lor (Char.code
s.[2] lsl 8)
1210 lor (Char.code
s.[3] lsl 0)
1212 let s = String.create
len in
1213 let n = tempfailureretry
(Unix.read fd
s 0) len in
1214 if n != len then error
"incomplete read(data) %d vs %d" n len;
1218 let btod b = if b then 1 else 0;;
1221 let b = Buffer.create
16 in
1222 Buffer.add_string
b "llll";
1225 let s = Buffer.contents
b in
1226 let n = String.length
s in
1228 (* dolog "wcmd %S" (String.sub s 4 len); *)
1229 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1230 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1231 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1232 s.[3] <- Char.chr
(len land 0xff);
1233 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1234 if n'
!= n then error
"write failed %d vs %d" n'
n;
1239 let d = state.winh
- h
in
1240 max
conf.interpagespace
((d + 1) / 2)
1243 let rowyh (c, coverA
, coverB
) b n =
1244 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1246 let _, _, vy
, (_, _, h
, _) = b.(n) in
1249 let n'
= n - coverA
in
1252 let e = min
state.pagecount
(s + c) in
1253 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1254 let _, _, y, (_, _, h
, _) = b.(m
) in
1255 let miny = min
miny y in
1256 let maxh = max
maxh h
in
1257 find (m
+1) miny maxh
1262 match conf.columns
with
1263 | Cmulti
((_, _, _) as cl
, b) ->
1264 if Array.length
b > 0
1266 let y, h
= rowyh cl
b (Array.length
b - 1) in
1267 y + h
+ (if conf.presentation
then calcips h
else 0)
1270 if Array.length
b > 0
1272 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1273 y + h
+ (if conf.presentation
then calcips h
else 0)
1276 if Array.length
b > 0
1278 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1283 let getpageywh pageno
=
1284 let pageno = bound pageno 0 (state.pagecount
-1) in
1285 match conf.columns
with
1287 if Array.length
b = 0
1290 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1292 if conf.presentation
1298 if Array.length
b = 0
1301 let y, h
= rowyh cl
b pageno in
1302 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1304 if conf.presentation
1310 if Array.length
b = 0
1314 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1318 let getpageyh pageno =
1319 let y,_,h
= getpageywh pageno in
1323 let getpagedim pageno =
1326 | (n, _, _, _) as pdim
:: rest
->
1328 then (if n = pageno then pdim
else ppdim
)
1333 f (-1, -1, -1, -1) state.pdims
1336 let getpagey pageno = fst
(getpageyh pageno);;
1338 let nogeomcmds cmds
=
1340 | s, [] -> emptystr
s
1345 let ((c, coverA
, coverB
) as cl
), b =
1346 match conf.columns
with
1347 | Csingle
b -> (1, 0, 0), b
1348 | Cmulti
(c, b) -> c, b
1349 | Csplit
(_, b) -> (1, 0, 0), b
1351 if Array.length
b = 0
1354 let rec bsearch nmin nmax
=
1356 then bound nmin
0 (state.pagecount
-1)
1358 let n = (nmax
+ nmin
) / 2 in
1359 let vy, h
= rowyh cl
b n in
1361 if conf.presentation
1363 let ips = calcips h
in
1364 let y0 = vy - ips in
1365 let y1 = vy + h
+ ips in
1369 then 0, vy + h
+ conf.interpagespace
1371 let y0 = vy - conf.interpagespace
in
1372 y0, y0 + h
+ conf.interpagespace
1375 if y >= y0 && y < y1
1382 if n < state.pagecount
- coverB
1383 then ((n-coverA
)/c)*c + coverA
1390 then bsearch (n+1) nmax
1391 else bsearch nmin
(n-1)
1394 bsearch 0 (state.pagecount
-1);
1397 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1398 let sh = sh - (hscrollh ()) in
1399 let rec fold accu
n =
1400 if n = Array.length
b
1403 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1406 || n = state.pagecount
- coverB
1407 || (n - coverA
) mod columns
= columns
- 1)
1413 let pagey = max
0 (y - vy) in
1414 let pagedispy = if pagey > 0 then 0 else vy - y in
1415 let pagedispx, pagex
=
1417 if n = coverA
- 1 || n = state.pagecount
- coverB
1418 then state.x + (wadjsb state.winw
- w
) / 2
1419 else dx + xoff
+ state.x
1426 let vw = wadjsb state.winw
- pagedispx in
1427 let pw = w
- pagex
in
1430 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1431 if pagevw > 0 && pagevh > 0
1435 ; pagedimno
= pdimno
1442 ; pagedispx = pagedispx
1443 ; pagedispy = pagedispy
1455 if Array.length
b = 0
1457 else List.rev
(fold [] (page_of_y y))
1460 let layoutS (columns
, b) y sh =
1461 let sh = sh - hscrollh () in
1462 let rec fold accu n =
1463 if n = Array.length
b
1466 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1473 let x = xoff
+ state.x in
1474 let pagey = max
0 (y - vy) in
1475 let pagedispy = if pagey > 0 then 0 else vy - y in
1476 let pagedispx, pagex
=
1490 let pagecolw = pagew
/columns
in
1492 if pagecolw < state.winw
1493 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1497 let vw = wadjsb state.winw
- pagedispx in
1498 let pw = pagew
- pagex
in
1501 let pagevw = min
pagevw pagecolw in
1502 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1503 if pagevw > 0 && pagevh > 0
1506 { pageno = n/columns
1507 ; pagedimno
= pdimno
1514 ; pagedispx = pagedispx
1515 ; pagedispy = pagedispy
1516 ; pagecol
= n mod columns
1527 List.rev
(fold [] 0)
1531 if nogeomcmds state.geomcmds
1533 match conf.columns
with
1534 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1535 | Cmulti
c -> layoutN c y sh
1536 | Csplit
s -> layoutS s y sh
1541 let y = state.y + incr
in
1543 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1548 let tilex = l.pagex
mod conf.tilew
in
1549 let tiley = l.pagey mod conf.tileh
in
1551 let col = l.pagex
/ conf.tilew
in
1552 let row = l.pagey / conf.tileh
in
1554 let rec rowloop row y0 dispy h
=
1558 let dh = conf.tileh
- y0 in
1559 let dh = min h
dh in
1560 let rec colloop col x0 dispx w
=
1564 let dw = conf.tilew
- x0 in
1565 let dw = min w
dw in
1567 f col row dispx dispy
x0 y0 dw dh;
1568 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1571 colloop col tilex l.pagedispx l.pagevw;
1572 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1575 if l.pagevw > 0 && l.pagevh > 0
1576 then rowloop row tiley l.pagedispy l.pagevh;
1579 let gettileopaque l col row =
1581 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1583 try Some
(Hashtbl.find state.tilemap
key)
1584 with Not_found
-> None
1587 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1588 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1589 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1592 let filledrect x0 y0 x1 y1 =
1593 GlArray.disable `texture_coord
;
1594 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1595 GlArray.vertex `two
state.vraw
;
1596 GlArray.draw_arrays `triangle_strip
0 4;
1597 GlArray.enable `texture_coord
;
1600 let linerect x0 y0 x1 y1 =
1601 GlArray.disable `texture_coord
;
1602 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1603 GlArray.vertex `two
state.vraw
;
1604 GlArray.draw_arrays `line_loop
0 4;
1605 GlArray.enable `texture_coord
;
1608 let drawtiles l color
=
1611 let f col row x y tilex tiley w h
=
1612 match gettileopaque l col row with
1613 | Some
(opaque
, _, t
) ->
1614 let params = x, y, w
, h
, tilex, tiley in
1618 GlFunc.blend_func `zero `one_minus_src_color
;
1620 drawtile
params opaque
;
1622 then Gl.disable `blend
;
1626 let s = Printf.sprintf
1630 let w = measurestr
fstate.fontsize
s in
1631 GlDraw.color
(0.0, 0.0, 0.0);
1632 filledrect (float (x-2))
1635 (float (y + fstate.fontsize
+ 2));
1636 GlDraw.color
(1.0, 1.0, 1.0);
1637 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1644 let lw = wadjsb state.winw
- x in
1647 let lh = state.winh
- y in
1650 begin match state.texid
with
1652 Gl.enable `texture_2d
;
1653 GlTex.bind_texture `texture_2d id
;
1656 and x1 = float (x+w)
1657 and y1 = float (y+h
) in
1659 let tw = float w /. 16.0
1660 and th
= float h
/. 16.0 in
1661 let tx0 = float tilex /. 16.0
1662 and ty0
= float tiley /. 16.0 in
1664 and ty1
= ty0
+. th
in
1665 Raw.sets_float
state.vraw ~pos
:0
1666 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1667 Raw.sets_float
state.traw ~pos
:0
1668 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1669 GlArray.vertex `two
state.vraw
;
1670 GlArray.tex_coord `two
state.traw
;
1671 GlArray.draw_arrays `triangle_strip
0 4;
1674 GlDraw.color
(1.0, 1.0, 1.0);
1675 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1677 if w > 128 && h
> fstate.fontsize
+ 10
1679 GlDraw.color
(0.0, 0.0, 0.0);
1682 then (col*conf.tilew
, row*conf.tileh
)
1685 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1694 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1696 let tilevisible1 l x y =
1698 and ax1
= l.pagex
+ l.pagevw
1700 and ay1
= l.pagey + l.pagevh in
1704 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1705 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1707 let rx0 = max
ax0 bx0
1708 and ry0
= max ay0 by0
1709 and rx1
= min ax1
bx1
1710 and ry1
= min ay1 by1
in
1712 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1713 nonemptyintersection
1716 let tilevisible layout n x y =
1717 let rec findpageinlayout m
= function
1718 | l :: rest
when l.pageno = n ->
1719 tilevisible1 l x y || (
1720 match conf.columns
with
1721 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1724 | _ :: rest
-> findpageinlayout 0 rest
1727 findpageinlayout 0 layout;
1730 let tileready l x y =
1731 tilevisible1 l x y &&
1732 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1735 let tilepage n p
layout =
1736 let rec loop = function
1740 let f col row _ _ _ _ _ _ =
1741 if state.currently
= Idle
1743 match gettileopaque l col row with
1746 let x = col*conf.tilew
1747 and y = row*conf.tileh
in
1749 let w = l.pagew
- x in
1753 let h = l.pageh
- y in
1758 then getpbo
w h conf.colorspace
1761 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1764 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1765 conf.tilew
, conf.tileh
1774 if nogeomcmds state.geomcmds
1778 let preloadlayout y =
1779 let y = if y < state.winh
then 0 else y - state.winh
in
1780 let h = state.winh
*3 in
1785 let rec loop pages
=
1786 if state.currently
!= Idle
1791 begin match getopaque l.pageno with
1793 wcmd "page %d %d" l.pageno l.pagedimno
;
1794 state.currently
<- Loading
(l, state.gen
);
1796 tilepage l.pageno opaque pages
;
1801 if nogeomcmds state.geomcmds
1807 if conf.preload && state.currently
= Idle
1808 then load (preloadlayout state.y);
1811 let layoutready layout =
1812 let rec fold all ls
=
1813 all
&& match ls
with
1815 let seen = ref false in
1816 let allvisible = ref true in
1817 let foo col row _ _ _ _ _ _ =
1819 allvisible := !allvisible &&
1820 begin match gettileopaque l col row with
1826 fold (!seen && !allvisible) rest
1829 let alltilesvisible = fold true layout in
1834 let y = bound y 0 state.maxy
in
1835 let y, layout, proceed
=
1836 match conf.maxwait
with
1837 | Some time
when state.ghyll
== noghyll ->
1838 begin match state.throttle
with
1840 let layout = layout y state.winh
in
1841 let ready = layoutready layout in
1845 state.throttle
<- Some
(layout, y, now ());
1847 else G.postRedisplay "gotoy showall (None)";
1849 | Some
(_, _, started
) ->
1850 let dt = now () -. started
in
1853 state.throttle
<- None
;
1854 let layout = layout y state.winh
in
1856 G.postRedisplay "maxwait";
1863 let layout = layout y state.winh
in
1864 if not
!wtmode || layoutready layout
1865 then G.postRedisplay "gotoy ready";
1871 state.layout <- layout;
1872 begin match state.mode
with
1873 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1874 let rec loop = function
1876 state.mode
<- LinkNav
(Ltgendir
0)
1877 | l :: _ when l.pageno = pageno ->
1878 begin match getopaque pageno with
1880 state.mode
<- LinkNav
(Ltgendir
0)
1882 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1883 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1884 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1885 then state.mode
<- LinkNav
(Ltgendir
0)
1887 | _ :: rest
-> loop rest
1892 begin match state.mode
with
1893 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1894 if not
(pagevisible layout pageno)
1896 match state.layout with
1899 state.mode
<- Birdseye
(
1900 conf, leftx
, l.pageno, hooverpageno
, anchor
1903 | LinkNav
(Ltgendir dir
as lt
) ->
1905 let rec loop = function
1908 match getopaque l.pageno with
1914 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1916 if dir
> 0 then LDfirst
else LDlast
1922 | Lnotfound
-> loop rest
1924 showlinktype (getlink opaque
n);
1925 Ltexact
(l.pageno, n)
1929 state.mode
<- LinkNav
linknav
1934 state.ghyll
<- noghyll;
1937 let mx, my
= state.mpos
in
1942 let conttiling pageno opaque
=
1943 tilepage pageno opaque
1944 (if conf.preload then preloadlayout state.y else state.layout)
1947 let gotoy_and_clear_text y =
1948 if not
conf.verbose
then state.text <- "";
1954 let coloff = l.pagecol
* l.pageh
in
1955 float (l.pagey + coloff) /. float l.pageh
1962 if conf.presentation
1963 then float l.pagedispy /. float (calcips l.pageh
)
1964 else float l.pagedispy /. float conf.interpagespace
1967 (l.pageno, top, dtop)
1971 match state.layout with
1972 | l :: _ -> getanchor1 l
1974 let n = page_of_y state.y in
1978 let y, h = getpageyh n in
1979 let dy = y - state.y in
1981 if conf.presentation
1983 let ips = calcips h in
1984 float (dy + ips) /. float ips
1986 float dy /. float conf.interpagespace
1991 let getanchory (n, top, dtop) =
1992 let y, h = getpageyh n in
1993 if conf.presentation
1995 let ips = calcips h in
1996 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1998 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
2001 let gotoanchor anchor
=
2002 gotoy (getanchory anchor
);
2006 cbput state.hists
.nav
(getanchor ());
2010 let anchor = cbgetc state.hists
.nav dir
in
2015 let scroll f n a
b =
2016 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2018 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2020 then s (float f /. float a
)
2023 then 1.0 -. s ((float (f-b) /. float (n-b)))
2029 let ins = float a
*. 0.5
2030 and outs
= float (n-b) *. 0.5 in
2032 ins +. outs
+. float ones
2034 let rec set (_N
, _A
, _B
) y sy
=
2035 let sum = summa _N _A _B
in
2036 let dy = float (y - sy
) in
2040 then state.ghyll
<- noghyll
2043 let s = scroll n _N _A _B
in
2044 let y1 = y1 +. ((s *. dy) /. sum) in
2045 gotoy_and_clear_text (truncate
y1);
2046 state.ghyll
<- gf (n+1) y1;
2050 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2052 gf 0 (float state.y)
2055 match conf.ghyllscroll
with
2057 gotoy_and_clear_text y
2059 if state.ghyll
== noghyll
2060 then set nab
y state.y
2061 else state.ghyll
(Some
y)
2064 let gotopage n top =
2065 let y, h = getpageyh n in
2066 let y = y + (truncate
(top *. float h)) in
2070 let gotopage1 n top =
2071 let y = getpagey n in
2076 let invalidate s f =
2081 match state.geomcmds
with
2082 | ps
, [] when emptystr ps
->
2084 state.geomcmds
<- s, [];
2087 state.geomcmds
<- ps
, [s, f];
2089 | ps
, (s'
, _) :: rest
when s'
= s ->
2090 state.geomcmds
<- ps
, ((s, f) :: rest
);
2093 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2097 Hashtbl.iter
(fun _ opaque
->
2098 wcmd "freepage %s" opaque
;
2100 Hashtbl.clear
state.pagemap
;
2104 if not
(Queue.is_empty
state.tilelru
)
2106 Queue.iter
(fun (k
, p
, s) ->
2107 wcmd "freetile %s" p
;
2108 state.memused
<- state.memused
- s;
2109 Hashtbl.remove
state.tilemap k
;
2111 state.uioh#infochanged Memused
;
2112 Queue.clear
state.tilelru
;
2118 let h = truncate
(float h*.conf.zoom
) in
2119 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2123 let opendoc path password
=
2125 state.password
<- password
;
2126 state.gen
<- state.gen
+ 1;
2127 state.docinfo
<- [];
2130 setaalevel
conf.aalevel
;
2132 if emptystr
state.origin
2136 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2137 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2138 invalidate "reqlayout"
2140 wcmd "reqlayout %d %d %d %s\000"
2141 conf.angle
(FMTE.to_int conf.fitmodel
)
2142 (stateh state.winh
) state.nameddest
2147 state.anchor <- getanchor ();
2148 opendoc state.path
state.password
;
2152 let c = c *. conf.colorscale
in
2156 let scalecolor2 (r
, g, b) =
2157 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2160 let docolumns = function
2162 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2163 let rec loop pageno pdimno pdim
y ph pdims
=
2164 if pageno = state.pagecount
2167 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2169 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2170 pdimno+1, pdim
, rest
2174 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2176 (if conf.presentation
2177 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2178 else (if pageno = 0 then 0 else conf.interpagespace
)
2181 a.(pageno) <- (pdimno, x, y, pdim
);
2182 loop (pageno+1) pdimno pdim
(y + h) h pdims
2184 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2185 conf.columns
<- Csingle
a;
2187 | Cmulti
((columns
, coverA
, coverB
), _) ->
2188 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2189 let rec loop pageno pdimno pdim
x y rowh pdims
=
2190 let rec fixrow m
= if m
= pageno then () else
2191 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2194 let y = y + (rowh
- h) / 2 in
2195 a.(m
) <- (pdimno, x, y, pdim
);
2199 if pageno = state.pagecount
2200 then fixrow (((pageno - 1) / columns
) * columns
)
2202 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2204 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2205 pdimno+1, pdim
, rest
2210 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2212 let x = (wadjsb state.winw
- w) / 2 in
2214 if conf.presentation
then calcips h else conf.interpagespace
in
2215 x, y + ips + rowh
, h
2218 if (pageno - coverA
) mod columns
= 0
2220 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2222 if conf.presentation
2224 let ips = calcips h in
2225 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2227 y + (if pageno = 0 then 0 else conf.interpagespace
)
2231 else x, y, max rowh
h
2235 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2238 if pageno = columns
&& conf.presentation
2240 let ips = calcips rowh
in
2241 for i
= 0 to pred columns
2243 let (pdimno, x, y, pdim
) = a.(i
) in
2244 a.(i
) <- (pdimno, x, y+ips, pdim
)
2250 fixrow (pageno - columns
);
2255 a.(pageno) <- (pdimno, x, y, pdim
);
2256 let x = x + w + xoff
*2 + conf.interpagespace
in
2257 loop (pageno+1) pdimno pdim
x y rowh' pdims
2259 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2260 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2263 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2264 let rec loop pageno pdimno pdim
y pdims
=
2265 if pageno = state.pagecount
2268 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2270 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2271 pdimno+1, pdim
, rest
2276 let rec loop1 n x y =
2277 if n = c then y else (
2278 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2279 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2282 let y = loop1 0 0 y in
2283 loop (pageno+1) pdimno pdim
y pdims
2285 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2286 conf.columns
<- Csplit
(c, a);
2290 docolumns conf.columns
;
2291 state.maxy
<- calcheight ();
2292 if state.reprf
== noreprf
2294 match state.mode
with
2295 | Birdseye
(_, _, pageno, _, _) ->
2296 let y, h = getpageyh pageno in
2297 let top = (state.winh
- h) / 2 in
2298 gotoy (max
0 (y - top))
2299 | _ -> gotoanchor state.anchor
2303 state.reprf
<- noreprf;
2308 GlDraw.viewport
0 0 w h;
2309 let firsttime = state.geomcmds
== firstgeomcmds in
2310 if not
firsttime && nogeomcmds state.geomcmds
2311 then state.anchor <- getanchor ();
2314 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2317 setfontsize fstate.fontsize
;
2318 GlMat.mode `modelview
;
2319 GlMat.load_identity
();
2321 GlMat.mode `projection
;
2322 GlMat.load_identity
();
2323 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2324 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2325 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2330 else float state.x /. float state.w
2332 invalidate "geometry"
2336 then state.x <- truncate
(relx *. float w);
2338 match conf.columns
with
2340 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2341 | Csplit
(c, _) -> w * c
2343 wcmd "geometry %d %d %d"
2344 w (stateh h) (FMTE.to_int conf.fitmodel
)
2349 let len = String.length
state.text in
2352 match state.mode
with
2353 | Textentry
_ | View
| LinkNav
_ ->
2354 let h, _, _ = state.uioh#scrollpw
in
2359 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2360 (x+.w) (float (state.winh
- hscrollh))
2363 let w = float (wadjsb state.winw
- 1) in
2364 if state.progress
>= 0.0 && state.progress
< 1.0
2366 GlDraw.color
(0.3, 0.3, 0.3);
2367 let w1 = w *. state.progress
in
2369 GlDraw.color
(0.0, 0.0, 0.0);
2373 GlDraw.color
(0.0, 0.0, 0.0);
2377 GlDraw.color
(1.0, 1.0, 1.0);
2378 drawstring fstate.fontsize
2379 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2382 match state.mode
with
2383 | Textentry
((prefix
, text, _, _, _, _), _) ->
2387 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2389 Printf.sprintf
"%s%s_" prefix
text
2398 if not
(istextentry state.mode
) && state.uioh#eformsgs
2400 let s1 = "(press 'e' to review error messasges)" in
2401 if nonemptystr
s then s ^
" " ^
s1 else s1
2411 let len = Queue.length
state.tilelru
in
2413 match state.throttle
with
2416 then preloadlayout state.y
2418 | Some
(layout, _, _) ->
2422 if state.memused
<= conf.memlimit
2427 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2428 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2429 let (_, pw, ph
, _) = getpagedim n in
2432 && colorspace
= conf.colorspace
2433 && angle
= conf.angle
2437 let x = col*conf.tilew
2438 and y = row*conf.tileh
in
2439 tilevisible (Lazy.force_val
layout) n x y
2441 then Queue.push lruitem
state.tilelru
2444 wcmd "freetile %s" p
;
2445 state.memused
<- state.memused
- s;
2446 state.uioh#infochanged Memused
;
2447 Hashtbl.remove
state.tilemap k
;
2455 let logcurrently = function
2456 | Idle
-> dolog
"Idle"
2457 | Loading
(l, gen
) ->
2458 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2459 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2461 "Tiling %d[%d,%d] page=%s cs=%s angle"
2462 l.pageno col row pageopaque
2463 (CSTE.to_string colorspace
)
2465 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2466 angle gen
conf.angle
state.gen
2468 conf.tilew
conf.tileh
2475 let r = Str.regexp
" " in
2476 fun s -> Str.bounded_split
r s 2;
2479 let onpagerect pageno f =
2481 match conf.columns
with
2482 | Cmulti
(_, b) -> b
2484 | Csplit
(_, b) -> b
2486 if pageno >= 0 && pageno < Array.length
b
2488 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2492 let gotopagexy1 pageno x y =
2493 let _,w1,h1
,leftx
= getpagedim pageno in
2494 let top = y /. (float h1
) in
2495 let left = x /. (float w1) in
2496 let py, w, h = getpageywh pageno in
2497 let wh = state.winh
- hscrollh () in
2498 let x = left *. (float w) in
2499 let x = leftx
+ state.x + truncate
x in
2501 if x < 0 || x >= wadjsb state.winw
2505 let pdy = truncate
(top *. float h) in
2506 let y'
= py + pdy in
2507 let dy = y'
- state.y in
2509 if x != state.x || not
(dy > 0 && dy < wh)
2511 if conf.presentation
2513 if abs
(py - y'
) > wh
2520 if state.x != sx || state.y != sy
2525 let ww = wadjsb state.winw
in
2527 and qy
= pdy / wh in
2529 and y = py + qy
* wh in
2530 let x = if -x + ww > w1 then -(w1-ww) else x
2531 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2533 if conf.presentation
2535 if abs
(py - y'
) > wh
2545 gotoy_and_clear_text y;
2547 else gotoy_and_clear_text state.y;
2550 let gotopagexy pageno x y =
2551 match state.mode
with
2552 | Birdseye
_ -> gotopage pageno 0.0
2553 | _ -> gotopagexy1 pageno x y
2557 (* dolog "%S" cmds; *)
2558 let cl = splitatspace cmds
in
2560 try Scanf.sscanf
s fmt
f
2562 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2565 let addoutline outline
=
2566 match state.currently
with
2567 | Outlining outlines
->
2568 state.currently
<- Outlining
(outline
:: outlines
)
2569 | Idle
-> state.currently
<- Outlining
[outline
]
2571 dolog
"invalid outlining state";
2572 logcurrently currently
2576 state.uioh#infochanged Pdim
;
2579 | "clearrects" :: [] ->
2580 state.rects
<- state.rects1
;
2581 G.postRedisplay "clearrects";
2583 | "continue" :: args :: [] ->
2584 let n = scan args "%u" (fun n -> n) in
2585 state.pagecount
<- n;
2586 begin match state.currently
with
2588 state.currently
<- Idle
;
2589 state.outlines
<- Array.of_list
(List.rev
l)
2593 let cur, cmds
= state.geomcmds
in
2595 then failwith
"umpossible";
2597 begin match List.rev cmds
with
2599 state.geomcmds
<- "", [];
2603 state.geomcmds
<- s, List.rev rest
;
2605 if conf.maxwait
= None
&& not
!wtmode
2606 then G.postRedisplay "continue";
2608 | "title" :: args :: [] ->
2611 | "msg" :: args :: [] ->
2614 | "vmsg" :: args :: [] ->
2616 then showtext ' '
args
2618 | "emsg" :: args :: [] ->
2619 Buffer.add_string
state.errmsgs
args;
2620 state.newerrmsgs
<- true;
2621 G.postRedisplay "error message"
2623 | "progress" :: args :: [] ->
2624 let progress, text =
2627 f, String.sub
args pos
(String.length
args - pos
))
2630 state.progress <- progress;
2631 G.postRedisplay "progress"
2633 | "firstmatch" :: args :: [] ->
2634 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2635 scan args "%u %d %f %f %f %f %f %f %f %f"
2636 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2637 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2639 let y = (getpagey pageno) + truncate
y0 in
2642 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2644 | "match" :: args :: [] ->
2645 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2646 scan args "%u %d %f %f %f %f %f %f %f %f"
2647 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2648 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2651 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2653 | "page" :: args :: [] ->
2654 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2655 begin match state.currently
with
2656 | Loading
(l, gen
) ->
2657 vlog "page %d took %f sec" l.pageno t
;
2658 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2659 begin match state.throttle
with
2661 let preloadedpages =
2663 then preloadlayout state.y
2668 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2669 IntSet.empty
preloadedpages
2672 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2673 if not
(IntSet.mem
pageno set)
2675 wcmd "freepage %s" opaque
;
2681 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2684 state.currently
<- Idle
;
2687 tilepage l.pageno pageopaque state.layout;
2689 load preloadedpages;
2690 if pagevisible state.layout l.pageno
2691 && layoutready state.layout
2692 then G.postRedisplay "page";
2695 | Some
(layout, _, _) ->
2696 state.currently
<- Idle
;
2697 tilepage l.pageno pageopaque layout;
2702 dolog
"Inconsistent loading state";
2703 logcurrently state.currently
;
2707 | "tile" :: args :: [] ->
2708 let (x, y, opaque
, size
, t
) =
2709 scan args "%u %u %s %u %f"
2710 (fun x y p size t
-> (x, y, p
, size
, t
))
2712 begin match state.currently
with
2713 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2714 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2717 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2719 wcmd "freetile %s" opaque
;
2720 state.currently
<- Idle
;
2724 puttileopaque l col row gen cs angle opaque size t
;
2725 state.memused
<- state.memused
+ size
;
2726 state.uioh#infochanged Memused
;
2728 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2729 opaque
, size
) state.tilelru
;
2732 match state.throttle
with
2733 | None
-> state.layout
2734 | Some
(layout, _, _) -> layout
2737 state.currently
<- Idle
;
2739 && conf.colorspace
= cs
2740 && conf.angle
= angle
2741 && tilevisible layout l.pageno x y
2742 then conttiling l.pageno pageopaque;
2744 begin match state.throttle
with
2746 preload state.layout;
2748 && conf.colorspace
= cs
2749 && conf.angle
= angle
2750 && tilevisible state.layout l.pageno x y
2751 && (not
!wtmode || layoutready state.layout)
2752 then G.postRedisplay "tile nothrottle";
2754 | Some
(layout, y, _) ->
2755 let ready = layoutready layout in
2759 state.layout <- layout;
2760 state.throttle
<- None
;
2761 G.postRedisplay "throttle";
2768 dolog
"Inconsistent tiling state";
2769 logcurrently state.currently
;
2773 | "pdim" :: args :: [] ->
2774 let (n, w, h, _) as pdim
=
2775 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2778 match conf.fitmodel
, conf.columns
with
2779 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2782 state.uioh#infochanged Pdim
;
2783 state.pdims
<- pdim :: state.pdims
2785 | "o" :: args :: [] ->
2786 let (l, n, t
, h, pos
) =
2787 scan args "%u %u %d %u %n"
2788 (fun l n t
h pos
-> l, n, t
, h, pos
)
2790 let s = String.sub
args pos
(String.length
args - pos
) in
2791 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
2793 | "ou" :: args :: [] ->
2794 let (l, len, pos
) = scan args "%u %u %n" (fun l len pos
-> l, len, pos
) in
2795 let s = String.sub
args pos
len in
2796 let pos2 = pos
+ len + 1 in
2797 let uri = String.sub
args pos2 (String.length
args - pos2) in
2798 addoutline (s, l, Ouri
uri)
2800 | "on" :: args :: [] ->
2801 let (l, pos
) = scan args "%u %n" (fun l pos
-> l, pos
) in
2802 let s = String.sub
args pos
(String.length
args - pos
) in
2803 addoutline (s, l, Onone
)
2805 | "a" :: args :: [] ->
2807 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2809 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2811 | "info" :: args :: [] ->
2812 state.docinfo
<- (1, args) :: state.docinfo
2814 | "infoend" :: [] ->
2815 state.uioh#infochanged Docinfo
;
2816 state.docinfo
<- List.rev
state.docinfo
2819 error
"unknown cmd `%S'" cmds
2824 let action = function
2825 | HCprev
-> cbget cb ~
-1
2826 | HCnext
-> cbget cb
1
2827 | HCfirst
-> cbget cb ~
-(cb
.rc)
2828 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2829 and cancel
() = cb
.rc <- rc
2833 let search pattern forward
=
2834 match conf.columns
with
2836 showtext '
!'
"searching does not work properly in split columns mode"
2838 if nonemptystr pattern
2841 match state.layout with
2844 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2846 wcmd "search %d %d %d %d,%s\000"
2847 (btod conf.icase
) pn py (btod forward
) pattern
;
2850 let intentry text key =
2852 if key >= 32 && key < 127
2858 let text = addchar text c in
2862 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2866 let linknentry text key =
2868 if key >= 32 && key < 127
2874 let text = addchar text c in
2878 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2886 let l = String.length
s in
2887 let rec loop pos
n = if pos
= l then n else
2888 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2889 loop (pos
+1) (n*26 + m)
2892 let rec loop n = function
2895 match getopaque l.pageno with
2896 | None
-> loop n rest
2898 let m = getlinkcount opaque
in
2901 let under = getlink opaque
n in
2904 else loop (n-m) rest
2906 loop n state.layout;
2910 let textentry text key =
2911 if key land 0xff00 = 0xff00
2913 else TEcont
(text ^ toutf8
key)
2916 let reqlayout angle fitmodel
=
2917 match state.throttle
with
2919 if nogeomcmds state.geomcmds
2920 then state.anchor <- getanchor ();
2921 conf.angle
<- angle
mod 360;
2924 match state.mode
with
2925 | LinkNav
_ -> state.mode
<- View
2928 conf.fitmodel
<- fitmodel
;
2929 invalidate "reqlayout"
2931 wcmd "reqlayout %d %d %d"
2932 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2937 let settrim trimmargins trimfuzz
=
2938 if nogeomcmds state.geomcmds
2939 then state.anchor <- getanchor ();
2940 conf.trimmargins
<- trimmargins
;
2941 conf.trimfuzz
<- trimfuzz
;
2942 let x0, y0, x1, y1 = trimfuzz
in
2943 invalidate "settrim"
2945 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2950 match state.throttle
with
2952 let zoom = max
0.0001 zoom in
2953 if zoom <> conf.zoom
2955 state.prevzoom
<- (conf.zoom, state.x);
2957 reshape state.winw
state.winh
;
2958 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2961 | Some
(layout, y, started
) ->
2963 match conf.maxwait
with
2967 let dt = now () -. started
in
2975 let setcolumns mode columns coverA coverB
=
2976 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2980 then showtext '
!'
"split mode doesn't work in bird's eye"
2982 conf.columns
<- Csplit
(-columns
, [||]);
2990 conf.columns
<- Csingle
[||];
2995 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2999 reshape state.winw
state.winh
;
3002 let enterbirdseye () =
3003 let zoom = float conf.thumbw
/. float state.winw
in
3004 let birdseyepageno =
3005 let cy = state.winh
/ 2 in
3009 let rec fold best
= function
3012 let d = cy - (l.pagedispy + l.pagevh/2)
3013 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
3014 if abs
d < abs dbest
3021 state.mode
<- Birdseye
(
3022 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
3025 conf.presentation
<- false;
3026 conf.interpagespace
<- 10;
3027 conf.hlinks
<- false;
3028 conf.fitmodel
<- FitProportional
;
3030 state.mstate
<- Mnone
;
3031 conf.maxwait
<- None
;
3033 match conf.beyecolumns
with
3036 Cmulti
((c, 0, 0), [||])
3037 | None
-> Csingle
[||]
3039 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3042 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3047 reshape state.winw
state.winh
;
3050 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3052 conf.zoom <- c.zoom;
3053 conf.presentation
<- c.presentation
;
3054 conf.interpagespace
<- c.interpagespace
;
3055 conf.maxwait
<- c.maxwait
;
3056 conf.hlinks
<- c.hlinks
;
3057 conf.fitmodel
<- c.fitmodel
;
3058 conf.beyecolumns
<- (
3059 match conf.columns
with
3060 | Cmulti
((c, _, _), _) -> Some
c
3062 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3065 match c.columns
with
3066 | Cmulti
(c, _) -> Cmulti
(c, [||])
3067 | Csingle
_ -> Csingle
[||]
3068 | Csplit
(c, _) -> Csplit
(c, [||])
3072 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3075 reshape state.winw
state.winh
;
3076 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3080 let togglebirdseye () =
3081 match state.mode
with
3082 | Birdseye vals
-> leavebirdseye vals
true
3083 | View
-> enterbirdseye ()
3087 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3088 let pageno = max
0 (pageno - incr
) in
3089 let rec loop = function
3090 | [] -> gotopage1 pageno 0
3091 | l :: _ when l.pageno = pageno ->
3092 if l.pagedispy >= 0 && l.pagey = 0
3093 then G.postRedisplay "upbirdseye"
3094 else gotopage1 pageno 0
3095 | _ :: rest
-> loop rest
3098 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3101 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3102 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3103 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3104 let rec loop = function
3106 let y, h = getpageyh pageno in
3107 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3109 | l :: _ when l.pageno = pageno ->
3110 if l.pagevh != l.pageh
3111 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3112 else G.postRedisplay "downbirdseye"
3113 | _ :: rest
-> loop rest
3118 let optentry mode
_ key =
3119 let btos b = if b then "on" else "off" in
3120 if key >= 32 && key < 127
3122 let c = Char.chr
key in
3126 try conf.scrollstep
<- int_of_string
s with exc
->
3127 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3129 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3134 conf.autoscrollstep
<- int_of_string
s;
3135 if state.autoscroll
<> None
3136 then state.autoscroll
<- Some
conf.autoscrollstep
3138 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3140 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3145 let n, a, b = multicolumns_of_string s in
3146 setcolumns mode
n a b;
3148 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3150 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3155 let zoom = float (int_of_string
s) /. 100.0 in
3158 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3160 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3165 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3167 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3168 begin match mode
with
3170 leavebirdseye beye
false;
3175 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3177 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3182 Some
(int_of_string
s)
3184 state.text <- Printf.sprintf
"bad integer `%s': %s"
3188 | Some angle
-> reqlayout angle
conf.fitmodel
3191 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3194 conf.icase
<- not
conf.icase
;
3195 TEdone
("case insensitive search " ^
(btos conf.icase
))
3198 conf.preload <- not
conf.preload;
3200 TEdone
("preload " ^
(btos conf.preload))
3203 conf.verbose
<- not
conf.verbose
;
3204 TEdone
("verbose " ^
(btos conf.verbose
))
3207 conf.debug
<- not
conf.debug
;
3208 TEdone
("debug " ^
(btos conf.debug
))
3211 conf.maxhfit
<- not
conf.maxhfit
;
3212 state.maxy
<- calcheight ();
3213 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3216 conf.crophack
<- not
conf.crophack
;
3217 TEdone
("crophack " ^
btos conf.crophack
)
3221 match conf.maxwait
with
3223 conf.maxwait
<- Some infinity
;
3224 "always wait for page to complete"
3226 conf.maxwait
<- None
;
3227 "show placeholder if page is not ready"
3232 conf.underinfo
<- not
conf.underinfo
;
3233 TEdone
("underinfo " ^
btos conf.underinfo
)
3236 conf.savebmarks
<- not
conf.savebmarks
;
3237 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3243 match state.layout with
3248 conf.interpagespace
<- int_of_string
s;
3249 docolumns conf.columns
;
3250 state.maxy
<- calcheight ();
3251 let y = getpagey pageno in
3254 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3256 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3260 match conf.fitmodel
with
3261 | FitProportional
-> FitWidth
3262 | _ -> FitProportional
3264 reqlayout conf.angle
fm;
3265 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3268 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3269 TEdone
("trim margins " ^
btos conf.trimmargins
)
3272 conf.invert
<- not
conf.invert
;
3273 TEdone
("invert colors " ^
btos conf.invert
)
3277 cbput state.hists
.sel
s;
3280 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3281 textentry, ondone, true)
3285 then conf.pax
<- Some
(ref (0.0, 0, 0))
3286 else conf.pax
<- None
;
3287 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3290 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3296 class type lvsource
= object
3297 method getitemcount
: int
3298 method getitem
: int -> (string * int)
3299 method hasaction
: int -> bool
3308 method getactive
: int
3309 method getfirst
: int
3310 method getqsearch
: string
3311 method setqsearch
: string -> unit
3315 class virtual lvsourcebase
= object
3316 val mutable m_active
= 0
3317 val mutable m_first
= 0
3318 val mutable m_qsearch
= ""
3319 val mutable m_pan
= 0
3320 method getactive
= m_active
3321 method getfirst
= m_first
3322 method getqsearch
= m_qsearch
3323 method getpan
= m_pan
3324 method setqsearch
s = m_qsearch
<- s
3327 let withoutlastutf8 s =
3328 let len = String.length
s in
3336 let b = Char.code
s.[pos
] in
3337 if b land 0b11000000 = 0b11000000
3342 if Char.code
s.[len-1] land 0x80 = 0
3346 String.sub
s 0 first;
3349 let textentrykeyboard
3350 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3352 if key >= 0xffb0 && key <= 0xffb9
3353 then key - 0xffb0 + 48 else key
3356 state.mode
<- Textentry
(te
, onleave
);
3359 G.postRedisplay "textentrykeyboard enttext";
3361 let histaction cmd
=
3364 | Some
(action, _) ->
3365 state.mode
<- Textentry
(
3366 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3368 G.postRedisplay "textentry histaction"
3371 | 0xff08 -> (* backspace *)
3372 if emptystr
text && cancelonempty
3375 G.postRedisplay "textentrykeyboard after cancel";
3378 let s = withoutlastutf8 text in
3379 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3381 | 0xff0d | 0xff8d -> (* (kp) enter *)
3384 G.postRedisplay "textentrykeyboard after confirm"
3386 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3387 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3388 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3389 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3391 | 0xff1b -> (* escape*)
3394 begin match opthist
with
3396 | Some
(_, onhistcancel
) -> onhistcancel
()
3400 G.postRedisplay "textentrykeyboard after cancel2"
3403 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3406 | 0xff9f | 0xffff -> () (* delete *)
3409 && key land 0xff00 != 0xff00 (* keyboard *)
3410 && key land 0xfe00 != 0xfe00 (* xkb *)
3411 && key land 0xfd00 != 0xfd00 (* 3270 *)
3413 begin match onkey
text key with
3417 G.postRedisplay "textentrykeyboard after confirm2";
3420 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3424 G.postRedisplay "textentrykeyboard after cancel3"
3427 state.mode
<- Textentry
(te
, onleave
);
3428 G.postRedisplay "textentrykeyboard switch";
3432 vlog "unhandled key %s" (Wsi.keyname
key)
3435 let firstof first active
=
3436 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3437 then max
0 (active
- (fstate.maxrows
/2))
3441 let calcfirst first active
=
3444 let rows = active
- first in
3445 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3449 let scrollph y maxy
=
3450 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3451 let sh = float state.winh
/. sh in
3452 let sh = max
sh (float conf.scrollh
) in
3454 let percent = float y /. float maxy
in
3455 let position = (float state.winh
-. sh) *. percent in
3458 if position +. sh > float state.winh
3459 then float state.winh
-. sh
3465 let coe s = (s :> uioh
);;
3467 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3469 val m_pan
= source#getpan
3470 val m_first
= source#getfirst
3471 val m_active
= source#getactive
3472 val m_qsearch
= source#getqsearch
3473 val m_prev_uioh
= state.uioh
3475 method private elemunder
y =
3476 let n = y / (fstate.fontsize
+1) in
3477 if m_first
+ n < source#getitemcount
3479 if source#hasaction
(m_first
+ n)
3480 then Some
(m_first
+ n)
3487 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3488 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3489 filledrect 0. 0. (float state.winw
) (float state.winh
);
3490 GlDraw.color
(1., 1., 1.);
3491 Gl.enable `texture_2d
;
3492 let fs = fstate.fontsize
in
3494 let ww = fstate.wwidth
in
3495 let tabw = 30.0*.ww in
3496 let itemcount = source#getitemcount
in
3498 if (row - m_first
) > fstate.maxrows
3501 if row >= 0 && row < itemcount
3503 let (s, level
) = source#getitem
row in
3504 let y = (row - m_first
) * nfs in
3505 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3508 Gl.disable `texture_2d
;
3509 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3510 GlDraw.color
(1., 1., 1.) ~
alpha;
3511 linerect 1. (float (y + 1))
3512 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3513 GlDraw.color
(1., 1., 1.);
3514 Gl.enable `texture_2d
;
3517 let drawtabularstring s =
3518 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3521 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3524 let len = String.length
s - tabpos - 1 in
3525 let s1 = String.sub
s 0 tabpos
3526 and s2
= String.sub
s (tabpos + 1) len in
3527 let nx = drawstr x s1 in
3529 let x = x +. (max
tabw sw) in
3536 let _ = drawtabularstring s in
3543 Gl.disable `texture_2d
;
3545 method updownlevel incr
=
3546 let len = source#getitemcount
in
3548 if m_active
>= 0 && m_active
< len
3549 then snd
(source#getitem m_active
)
3553 if i
= len then i
-1 else if i
= -1 then 0 else
3554 let _, l = source#getitem i
in
3555 if l != curlevel then i
else flow (i
+incr
)
3557 let active = flow m_active
in
3558 let first = calcfirst m_first
active in
3559 G.postRedisplay "outline updownlevel";
3560 {< m_active
= active; m_first
= first >}
3562 method private key1
key mask
=
3563 let set1 active first qsearch
=
3564 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3566 let search active pattern incr
=
3567 let active = if active = -1 then m_first
else active in
3570 if n >= 0 && n < source#getitemcount
3572 let s, _ = source#getitem
n in
3574 (try ignore
(Str.search_forward
re s 0); true
3575 with Not_found
-> false)
3577 else loop (n + incr
)
3584 let re = Str.regexp_case_fold pattern
in
3590 let itemcount = source#getitemcount
in
3591 let find start incr
=
3593 if i
= -1 || i
= itemcount
3596 if source#hasaction i
3598 else find (i
+ incr
)
3603 let set active first =
3604 let first = bound first 0 (itemcount - fstate.maxrows
) in
3606 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3609 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3611 let incr1 = if incr
> 0 then 1 else -1 in
3612 if isvisible m_first m_active
3615 let next = m_active
+ incr
in
3617 if next < 0 || next >= itemcount
3619 else find next incr1
3621 if abs
(m_active
- next) > fstate.maxrows
3627 let first = m_first
+ incr
in
3628 let first = bound first 0 (itemcount - fstate.maxrows
) in
3630 let next = m_active
+ incr
in
3631 let next = bound next 0 (itemcount - 1) in
3638 if isvisible first next
3645 let first = min
next m_first
in
3647 if abs
(next - first) > fstate.maxrows
3653 let first = m_first
+ incr
in
3654 let first = bound first 0 (itemcount - 1) in
3656 let next = m_active
+ incr
in
3657 let next = bound next 0 (itemcount - 1) in
3658 let next = find next incr1 in
3660 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3662 let active = if m_active
= -1 then next else m_active
in
3667 if isvisible first active
3673 G.postRedisplay "listview navigate";
3677 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3678 let incr = if key = 0x72 then -1 else 1 in
3680 match search (m_active
+ incr) m_qsearch
incr with
3682 state.text <- m_qsearch ^
" [not found]";
3685 state.text <- m_qsearch
;
3686 active, firstof m_first
active
3688 G.postRedisplay "listview ctrl-r/s";
3689 set1 active first m_qsearch
;
3691 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3692 if m_active
>= 0 && m_active
< source#getitemcount
3694 let s, _ = source#getitem m_active
in
3699 | 0xff08 -> (* backspace *)
3700 if emptystr m_qsearch
3703 let qsearch = withoutlastutf8 m_qsearch
in
3707 G.postRedisplay "listview empty qsearch";
3708 set1 m_active m_first
"";
3712 match search m_active
qsearch ~
-1 with
3714 state.text <- qsearch ^
" [not found]";
3717 state.text <- qsearch;
3718 active, firstof m_first
active
3720 G.postRedisplay "listview backspace qsearch";
3721 set1 active first qsearch
3724 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3725 let pattern = m_qsearch ^ toutf8
key in
3727 match search m_active
pattern 1 with
3729 state.text <- pattern ^
" [not found]";
3732 state.text <- pattern;
3733 active, firstof m_first
active
3735 G.postRedisplay "listview qsearch add";
3736 set1 active first pattern;
3738 | 0xff1b -> (* escape *)
3740 if emptystr m_qsearch
3742 G.postRedisplay "list view escape";
3745 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3747 | None
-> m_prev_uioh
3752 G.postRedisplay "list view kill qsearch";
3753 source#setqsearch
"";
3754 coe {< m_qsearch
= "" >}
3757 | 0xff0d | 0xff8d -> (* (kp) enter *)
3759 let self = {< m_qsearch
= "" >} in
3760 source#setqsearch
"";
3762 G.postRedisplay "listview enter";
3763 if m_active
>= 0 && m_active
< source#getitemcount
3765 source#exit
(coe self) false m_active m_first m_pan
"";
3768 source#exit
(coe self) true m_active m_first m_pan
"";
3771 begin match opt with
3772 | None
-> m_prev_uioh
3776 | 0xff9f | 0xffff -> (* (kp) delete *)
3779 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3780 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3781 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3782 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3784 | 0xff53 | 0xff98 -> (* (kp) right *)
3786 G.postRedisplay "listview right";
3787 coe {< m_pan
= m_pan
- 1 >}
3789 | 0xff51 | 0xff96 -> (* (kp) left *)
3791 G.postRedisplay "listview left";
3792 coe {< m_pan
= m_pan
+ 1 >}
3794 | 0xff50 | 0xff95 -> (* (kp) home *)
3795 let active = find 0 1 in
3796 G.postRedisplay "listview home";
3799 | 0xff57 | 0xff9c -> (* (kp) end *)
3800 let first = max
0 (itemcount - fstate.maxrows
) in
3801 let active = find (itemcount - 1) ~
-1 in
3802 G.postRedisplay "listview end";
3805 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3809 dolog
"listview unknown key %#x" key; coe self
3811 method key key mask
=
3812 match state.mode
with
3813 | Textentry te
-> textentrykeyboard key mask te
; coe self
3814 | _ -> self#key1
key mask
3816 method button button down
x y _ =
3819 | 1 when x > state.winw
- conf.scrollbw
->
3820 G.postRedisplay "listview scroll";
3823 let _, position, sh = self#
scrollph in
3824 if y > truncate
position && y < truncate
(position +. sh)
3826 state.mstate
<- Mscrolly
;
3830 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3831 let first = truncate
(s *. float source#getitemcount
) in
3832 let first = min source#getitemcount
first in
3833 Some
(coe {< m_first
= first; m_active
= first >})
3835 state.mstate
<- Mnone
;
3838 | 1 when not down
->
3839 begin match self#elemunder
y with
3841 G.postRedisplay "listview click";
3843 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3847 | n when (n == 4 || n == 5) && not down
->
3848 let len = source#getitemcount
in
3850 if n = 5 && m_first
+ fstate.maxrows
>= len
3854 let first = m_first
+ (if n == 4 then -1 else 1) in
3855 bound first 0 (len - 1)
3857 G.postRedisplay "listview wheel";
3858 Some
(coe {< m_first
= first >})
3859 | n when (n = 6 || n = 7) && not down
->
3860 let inc = if n = 7 then -1 else 1 in
3861 G.postRedisplay "listview hwheel";
3862 Some
(coe {< m_pan
= m_pan
+ inc >})
3867 | None
-> m_prev_uioh
3871 match state.mstate
with
3873 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3874 let first = truncate
(s *. float source#getitemcount
) in
3875 let first = min source#getitemcount
first in
3876 G.postRedisplay "listview motion";
3877 coe {< m_first
= first; m_active
= first >}
3880 method pmotion
x y =
3881 if x < state.winw
- conf.scrollbw
3884 match self#elemunder
y with
3885 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3886 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3890 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3895 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3899 method infochanged
_ = ()
3901 method scrollpw
= (0, 0.0, 0.0)
3903 let nfs = fstate.fontsize
+ 1 in
3904 let y = m_first
* nfs in
3905 let itemcount = source#getitemcount
in
3906 let maxi = max
0 (itemcount - fstate.maxrows
) in
3907 let maxy = maxi * nfs in
3908 let p, h = scrollph y maxy in
3911 method modehash
= modehash
3912 method eformsgs
= false
3915 class outlinelistview ~source
=
3916 let settext autonarrow
s =
3918 then state.text <- "[" ^
s ^
"]"
3919 else state.text <- s
3923 ~source
:(source
:> lvsource
)
3925 ~modehash
:(findkeyhash conf "outline")
3928 val m_autonarrow
= false
3930 method key key mask
=
3932 if emptystr
state.text
3934 else fstate.maxrows - 2
3936 let calcfirst first active =
3939 let rows = active - first in
3940 if rows > maxrows then active - maxrows else first
3944 let active = m_active
+ incr in
3945 let active = bound active 0 (source#getitemcount
- 1) in
3946 let first = calcfirst m_first
active in
3947 G.postRedisplay "outline navigate";
3948 coe {< m_active
= active; m_first
= first >}
3950 let navscroll first =
3952 let dist = m_active
- first in
3958 else first + maxrows
3961 G.postRedisplay "outline navscroll";
3962 coe {< m_first
= first; m_active
= active >}
3964 let ctrl = Wsi.withctrl mask
in
3966 | 97 when ctrl -> (* ctrl-a *)
3968 then source#denarrow
3969 else source#narrow m_qsearch
;
3970 settext (not m_autonarrow
) m_qsearch
;
3971 G.postRedisplay "toggle auto narrowing";
3972 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3974 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3976 G.postRedisplay "toggle auto narrowing";
3977 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3979 | 110 when ctrl -> (* ctrl-n *)
3980 source#narrow m_qsearch
;
3982 then source#add_narrow_pattern m_qsearch
;
3983 G.postRedisplay "outline ctrl-n";
3984 coe {< m_first
= 0; m_active
= 0 >}
3986 | 115 when ctrl -> (* ctrl-s *)
3987 let active = source#calcactive
(getanchor ()) in
3988 let first = firstof m_first
active in
3989 G.postRedisplay "outline ctrl-s";
3990 coe {< m_first
= first; m_active
= active >}
3992 | 117 when ctrl -> (* ctrl-u *)
3993 source#del_narrow_pattern
;
3994 let pattern = source#renarrow
in
3995 G.postRedisplay "outline ctrl-u";
3997 if emptystr
pattern then "" else "Narrowed to " ^
pattern
3999 settext m_autonarrow
text;
4000 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4002 | 108 when ctrl -> (* ctrl-l *)
4003 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
4004 G.postRedisplay "outline ctrl-l";
4005 coe {< m_first
= first >}
4007 | 0xff1b -> (* escape *)
4008 let o = super#
key key mask
in
4011 if nonemptystr m_qsearch
4013 source#add_narrow_pattern m_qsearch
;
4019 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
4020 if nonemptystr m_qsearch
4021 then source#add_narrow_pattern m_qsearch
;
4024 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
4025 let pattern = m_qsearch ^ toutf8
key in
4026 G.postRedisplay "outlinelistview autonarrow add";
4027 source#narrow
pattern;
4028 settext true pattern;
4029 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4031 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4032 if emptystr m_qsearch
4035 let pattern = withoutlastutf8 m_qsearch
in
4036 G.postRedisplay "outlinelistview autonarrow backspace";
4037 ignore
(source#renarrow
);
4038 source#narrow
pattern;
4039 settext true pattern;
4040 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4042 | 0xff9f | 0xffff -> (* (kp) delete *)
4043 source#remove m_active
;
4044 G.postRedisplay "outline delete";
4045 let active = max
0 (m_active
-1) in
4046 coe {< m_first
= firstof m_first
active;
4047 m_active
= active >}
4049 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4050 navscroll (max
0 (m_first
- 1))
4052 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4053 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4055 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4056 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4057 | 0xff55 | 0xff9a -> (* (kp) prior *)
4058 navigate ~
-(fstate.maxrows)
4059 | 0xff56 | 0xff9b -> (* (kp) next *)
4060 navigate fstate.maxrows
4062 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4066 G.postRedisplay "outline ctrl right";
4067 {< m_pan
= m_pan
+ 1 >}
4069 else self#updownlevel
1
4073 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4077 G.postRedisplay "outline ctrl left";
4078 {< m_pan
= m_pan
- 1 >}
4080 else self#updownlevel ~
-1
4084 | 0xff50 | 0xff95 -> (* (kp) home *)
4085 G.postRedisplay "outline home";
4086 coe {< m_first
= 0; m_active
= 0 >}
4088 | 0xff57 | 0xff9c -> (* (kp) end *)
4089 let active = source#getitemcount
- 1 in
4090 let first = max
0 (active - fstate.maxrows) in
4091 G.postRedisplay "outline end";
4092 coe {< m_active
= active; m_first
= first >}
4094 | _ -> super#
key key mask
4097 let gotounder under =
4098 let getpath filename
=
4100 if nonemptystr filename
4102 if Filename.is_relative filename
4104 let dir = Filename.dirname
state.path in
4106 if Filename.is_implicit
dir
4107 then Filename.concat
(Sys.getcwd
()) dir
4110 Filename.concat
dir filename
4114 if Sys.file_exists
path
4119 | Ulinkgoto
(pageno, top) ->
4123 gotopage1 pageno top;
4129 | Uremote
(filename
, pageno) ->
4130 let path = getpath filename
in
4135 let command = !selfexec ^
" " ^
path in
4136 try popen command []
4139 "failed to execute `%s': %s\n" command (exntos exn
);
4142 let anchor = getanchor () in
4143 let ranchor = state.path, state.password
, anchor, state.origin
in
4145 state.anchor <- (pageno, 0.0, 0.0);
4146 state.ranchors
<- ranchor :: state.ranchors
;
4149 else showtext '
!'
("Could not find " ^ filename
)
4151 | Uremotedest
(filename
, destname
) ->
4152 let path = getpath filename
in
4157 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
4158 try popen command []
4161 "failed to execute `%s': %s\n" command (exntos exn
);
4164 let anchor = getanchor () in
4165 let ranchor = state.path, state.password
, anchor, state.origin
in
4167 state.nameddest
<- destname
;
4168 state.ranchors
<- ranchor :: state.ranchors
;
4171 else showtext '
!'
("Could not find " ^ filename
)
4173 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4176 let gotooutline (_, _, kind
) =
4180 let (pageno, y, _) = anchor in
4182 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4185 | Ouri
uri -> gotounder (Ulinkuri
uri)
4186 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
4187 | Oremote remote
-> gotounder (Uremote remote
)
4188 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
4191 let outlinesource usebookmarks
=
4194 inherit lvsourcebase
4195 val mutable m_items
= empty
4196 val mutable m_orig_items
= empty
4197 val mutable m_narrow_patterns
= []
4198 val mutable m_hadremovals
= false
4200 method getitemcount
=
4201 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4204 if n == Array.length m_items
&& m_hadremovals
4206 ("[Confirm removal]", 0)
4208 let s, n, _ = m_items
.(n) in
4211 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4212 ignore
(uioh
, first, qsearch);
4213 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4215 if m_narrow_patterns
= []
4221 if not
confrimremoval
4223 gotooutline m_items
.(active);
4227 state.bookmarks
<- Array.to_list m_items
;
4228 m_orig_items
<- m_items
;
4231 else m_items
<- items;
4235 method hasaction
_ = true
4238 if Array.length m_items
!= Array.length m_orig_items
4241 match m_narrow_patterns
with
4243 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
4245 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4248 method narrow
pattern =
4249 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4253 let rec loop accu n =
4255 then m_items
<- Array.of_list
accu
4257 let (s, _, _) as o = m_items
.(n) in
4259 if (try ignore
(Str.search_forward
re s 0); true
4260 with Not_found
-> false)
4266 loop [] (Array.length m_items
- 1)
4271 then Array.of_list
state.bookmarks
4274 m_items
<- m_orig_items
4279 if m >= 0 && m < Array.length m_items
4281 m_hadremovals
<- true;
4282 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4283 let n = if n >= m then n+1 else n in
4288 method add_narrow_pattern
pattern =
4289 m_narrow_patterns
<- pattern :: m_narrow_patterns
4291 method del_narrow_pattern
=
4292 match m_narrow_patterns
with
4293 | _ :: rest
-> m_narrow_patterns
<- rest
4298 match m_narrow_patterns
with
4299 | pattern :: [] -> self#narrow
pattern; pattern
4301 List.fold_left
(fun accu pattern ->
4302 self#narrow
pattern;
4303 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
4305 method calcactive
anchor =
4306 let rely = getanchory anchor in
4307 let rec loop n best bestd
=
4308 if n = Array.length m_items
4311 let _, _, kind
= m_items
.(n) in
4314 let orely = getanchory anchor in
4315 let d = abs
(orely - rely) in
4318 else loop (n+1) best bestd
4319 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
4320 loop (n+1) best bestd
4324 method reset
anchor items =
4325 m_hadremovals
<- false;
4326 if m_orig_items
== empty
4328 m_orig_items
<- items;
4329 if m_narrow_patterns
== []
4330 then m_items
<- items;
4332 let active = self#calcactive
anchor in
4334 m_first
<- firstof m_first
active
4338 let enterselector usebookmarks
=
4339 let source = outlinesource usebookmarks
in
4343 then Array.of_list
state.bookmarks
4346 if Array.length
outlines = 0
4348 showtext ' ' errmsg
;
4351 state.text <- source#greetmsg
;
4352 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4353 let anchor = getanchor () in
4354 source#reset
anchor outlines;
4355 state.uioh
<- coe (new outlinelistview ~
source);
4356 G.postRedisplay "enter selector";
4360 let enteroutlinemode =
4361 let f = enterselector false in
4362 fun ()-> f "Document has no outline";
4365 let enterbookmarkmode =
4366 let f = enterselector true in
4367 fun () -> f "Document has no bookmarks (yet)";
4370 let color_of_string s =
4371 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4372 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4376 let color_to_string (r, g, b) =
4377 let r = truncate
(r *. 256.0)
4378 and g = truncate
(g *. 256.0)
4379 and b = truncate
(b *. 256.0) in
4380 Printf.sprintf
"%d/%d/%d" r g b
4383 let irect_of_string s =
4384 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4387 let irect_to_string (x0,y0,x1,y1) =
4388 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4391 let makecheckers () =
4392 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4394 converted by Issac Trotts. July 25, 2002 *)
4395 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4396 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4397 let id = GlTex.gen_texture
() in
4398 GlTex.bind_texture `texture_2d
id;
4399 GlPix.store
(`unpack_alignment
1);
4400 GlTex.image2d
image;
4401 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4402 [ `mag_filter `nearest
; `min_filter `nearest
];
4406 let setcheckers enabled
=
4407 match state.texid
with
4409 if enabled
then state.texid
<- Some
(makecheckers ())
4414 GlTex.delete_texture texid
;
4415 state.texid
<- None
;
4419 let int_of_string_with_suffix s =
4420 let l = String.length
s in
4424 let suffix = Char.lowercase
s.[l-1] in
4426 | 'k'
-> String.sub
s 0 (l-1), 10
4427 | '
m'
-> String.sub
s 0 (l-1), 20
4428 | '
g'
-> String.sub
s 0 (l-1), 30
4432 let n = int_of_string
s1 in
4433 let m = n lsl shift
in
4435 then raise
(Failure
"value too large")
4439 let string_with_suffix_of_int n =
4443 let units = [(30, "G"); (20, "M"); (10, "K")] in
4446 let h = n mod 1000 in
4449 then string_of_int
h ^
s
4451 let s = Printf.sprintf
"_%03d%s" h s in
4457 let rec find = function
4459 | (shift
, suffix) :: rest
->
4460 if (n land ((1 lsl shift
) - 1)) = 0
4461 then prettyint (n lsr shift
) ^
suffix
4467 let defghyllscroll = (40, 8, 32);;
4468 let fastghyllscroll = (5,1,2);;
4469 let neatghyllscroll = (10,1,9);;
4470 let ghyllscroll_of_string s =
4472 | "default" -> Some
defghyllscroll
4473 | "fast" -> Some
(5,1,2)
4474 | "neat" -> Some
(10,1,9)
4475 | "" | "none" -> None
4477 let (n,a,b) as nab
=
4478 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4479 if n <= a || n <= b || a >= b
4480 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4485 let ghyllscroll_to_string ((n, a, b) as nab
) =
4486 (**) if nab
= defghyllscroll then "default"
4487 else if nab
= fastghyllscroll then "fast"
4488 else if nab
= neatghyllscroll then "neat"
4489 else Printf.sprintf
"%d,%d,%d" n a b;
4492 let describe_location () =
4493 let fn = page_of_y state.y in
4494 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4495 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4499 else (100. *. (float state.y /. float maxy))
4503 Printf.sprintf
"page %d of %d [%.2f%%]"
4504 (fn+1) state.pagecount
percent
4507 "pages %d-%d of %d [%.2f%%]"
4508 (fn+1) (ln+1) state.pagecount
percent
4511 let setpresentationmode v
=
4512 let n = page_of_y state.y in
4513 state.anchor <- (n, 0.0, 1.0);
4514 conf.presentation
<- v
;
4515 if conf.fitmodel
= FitPage
4516 then reqlayout conf.angle
conf.fitmodel
;
4521 let btos b = if b then "\xe2\x88\x9a" else "" in
4522 let showextended = ref false in
4523 let leave mode
= function
4524 | Confirm
-> state.mode
<- mode
4525 | Cancel
-> state.mode
<- mode
in
4528 val mutable m_first_time
= true
4529 val mutable m_l
= []
4530 val mutable m_a
= [||]
4531 val mutable m_prev_uioh
= nouioh
4532 val mutable m_prev_mode
= View
4534 inherit lvsourcebase
4536 method reset prev_mode prev_uioh
=
4537 m_a
<- Array.of_list
(List.rev m_l
);
4539 m_prev_mode
<- prev_mode
;
4540 m_prev_uioh
<- prev_uioh
;
4544 if n >= Array.length m_a
4548 | _, _, _, Action
_ -> m_active
<- n
4552 m_first_time
<- false;
4555 method int name get
set =
4557 (name, `
int get
, 1, Action
(
4560 try set (int_of_string
s)
4562 state.text <- Printf.sprintf
"bad integer `%s': %s"
4566 let te = name ^
": ", "", None
, intentry, ondone, true in
4567 state.mode
<- Textentry
(te, leave m_prev_mode
);
4571 method int_with_suffix
name get
set =
4573 (name, `intws get
, 1, Action
(
4576 try set (int_of_string_with_suffix s)
4578 state.text <- Printf.sprintf
"bad integer `%s': %s"
4583 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4585 state.mode
<- Textentry
(te, leave m_prev_mode
);
4589 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4591 (name, `
bool (btos, get
), offset
, Action
(
4598 method color
name get
set =
4600 (name, `color get
, 1, Action
(
4602 let invalid = (nan
, nan
, nan
) in
4605 try color_of_string s
4607 state.text <- Printf.sprintf
"bad color `%s': %s"
4614 let te = name ^
": ", "", None
, textentry, ondone, true in
4615 state.text <- color_to_string (get
());
4616 state.mode
<- Textentry
(te, leave m_prev_mode
);
4620 method string name get
set =
4622 (name, `
string get
, 1, Action
(
4624 let ondone s = set s in
4625 let te = name ^
": ", "", None
, textentry, ondone, true in
4626 state.mode
<- Textentry
(te, leave m_prev_mode
);
4630 method colorspace
name get
set =
4632 (name, `
string get
, 1, Action
(
4636 inherit lvsourcebase
4639 m_active
<- CSTE.to_int conf.colorspace
;
4642 method getitemcount
=
4643 Array.length
CSTE.names
4646 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4647 ignore
(uioh
, first, pan
, qsearch);
4648 if not cancel
then set active;
4650 method hasaction
_ = true
4654 let modehash = findkeyhash conf "info" in
4655 coe (new listview ~
source ~trusted
:true ~
modehash)
4658 method paxmark
name get
set =
4660 (name, `
string get
, 1, Action
(
4664 inherit lvsourcebase
4667 m_active
<- MTE.to_int conf.paxmark
;
4670 method getitemcount
= Array.length
MTE.names
4671 method getitem
n = (MTE.names.(n), 0)
4672 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4673 ignore
(uioh
, first, pan
, qsearch);
4674 if not cancel
then set active;
4676 method hasaction
_ = true
4680 let modehash = findkeyhash conf "info" in
4681 coe (new listview ~
source ~trusted
:true ~
modehash)
4684 method fitmodel
name get
set =
4686 (name, `
string get
, 1, Action
(
4690 inherit lvsourcebase
4693 m_active
<- FMTE.to_int conf.fitmodel
;
4696 method getitemcount
= Array.length
FMTE.names
4697 method getitem
n = (FMTE.names.(n), 0)
4698 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4699 ignore
(uioh
, first, pan
, qsearch);
4700 if not cancel
then set active;
4702 method hasaction
_ = true
4706 let modehash = findkeyhash conf "info" in
4707 coe (new listview ~
source ~trusted
:true ~
modehash)
4710 method caption
s offset
=
4711 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4713 method caption2
s f offset
=
4714 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4716 method getitemcount
= Array.length m_a
4719 let tostr = function
4720 | `
int f -> string_of_int
(f ())
4721 | `intws
f -> string_with_suffix_of_int (f ())
4723 | `color
f -> color_to_string (f ())
4724 | `
bool (btos, f) -> btos (f ())
4727 let name, t
, offset
, _ = m_a
.(n) in
4728 ((let s = tostr t
in
4730 then Printf.sprintf
"%s\t%s" name s
4734 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4738 m_qsearch
<- qsearch;
4740 match m_a
.(active) with
4741 | _, _, _, Action
f -> f uioh
4753 method hasaction
n =
4755 | _, _, _, Action
_ -> true
4759 let rec fillsrc prevmode prevuioh
=
4760 let sep () = src#caption
"" 0 in
4761 let colorp name get
set =
4763 (fun () -> color_to_string (get
()))
4766 let c = color_of_string v in
4769 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4772 let oldmode = state.mode
in
4773 let birdseye = isbirdseye state.mode
in
4775 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4777 src#
bool "presentation mode"
4778 (fun () -> conf.presentation
)
4779 (fun v -> setpresentationmode v);
4781 src#
bool "ignore case in searches"
4782 (fun () -> conf.icase
)
4783 (fun v -> conf.icase
<- v);
4786 (fun () -> conf.preload)
4787 (fun v -> conf.preload <- v);
4789 src#
bool "highlight links"
4790 (fun () -> conf.hlinks
)
4791 (fun v -> conf.hlinks
<- v);
4793 src#
bool "under info"
4794 (fun () -> conf.underinfo
)
4795 (fun v -> conf.underinfo
<- v);
4797 src#
bool "persistent bookmarks"
4798 (fun () -> conf.savebmarks
)
4799 (fun v -> conf.savebmarks
<- v);
4801 src#fitmodel
"fit model"
4802 (fun () -> FMTE.to_string conf.fitmodel
)
4803 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4805 src#
bool "trim margins"
4806 (fun () -> conf.trimmargins
)
4807 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4809 src#
bool "persistent location"
4810 (fun () -> conf.jumpback
)
4811 (fun v -> conf.jumpback
<- v);
4814 src#
int "inter-page space"
4815 (fun () -> conf.interpagespace
)
4817 conf.interpagespace
<- n;
4818 docolumns conf.columns
;
4820 match state.layout with
4825 state.maxy <- calcheight ();
4826 let y = getpagey pageno in
4831 (fun () -> conf.pagebias
)
4832 (fun v -> conf.pagebias
<- v);
4834 src#
int "scroll step"
4835 (fun () -> conf.scrollstep
)
4836 (fun n -> conf.scrollstep
<- n);
4838 src#
int "horizontal scroll step"
4839 (fun () -> conf.hscrollstep
)
4840 (fun v -> conf.hscrollstep
<- v);
4842 src#
int "auto scroll step"
4844 match state.autoscroll
with
4846 | _ -> conf.autoscrollstep
)
4848 if state.autoscroll
<> None
4849 then state.autoscroll
<- Some
n;
4850 conf.autoscrollstep
<- n);
4853 (fun () -> truncate
(conf.zoom *. 100.))
4854 (fun v -> setzoom ((float v) /. 100.));
4857 (fun () -> conf.angle
)
4858 (fun v -> reqlayout v conf.fitmodel
);
4860 src#
int "scroll bar width"
4861 (fun () -> conf.scrollbw
)
4864 reshape state.winw
state.winh
;
4867 src#
int "scroll handle height"
4868 (fun () -> conf.scrollh
)
4869 (fun v -> conf.scrollh
<- v;);
4871 src#
int "thumbnail width"
4872 (fun () -> conf.thumbw
)
4874 conf.thumbw
<- min
4096 v;
4877 leavebirdseye beye
false;
4882 let mode = state.mode in
4883 src#
string "columns"
4885 match conf.columns
with
4887 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4888 | Csplit
(count
, _) -> "-" ^ string_of_int count
4891 let n, a, b = multicolumns_of_string v in
4892 setcolumns mode n a b);
4895 src#caption
"Pixmap cache" 0;
4896 src#int_with_suffix
"size (advisory)"
4897 (fun () -> conf.memlimit
)
4898 (fun v -> conf.memlimit
<- v);
4901 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4902 (string_with_suffix_of_int state.memused
)
4903 (Hashtbl.length
state.tilemap
)) 1;
4906 src#caption
"Layout" 0;
4907 src#caption2
"Dimension"
4909 Printf.sprintf
"%dx%d (virtual %dx%d)"
4910 state.winw
state.winh
4915 src#caption2
"Position" (fun () ->
4916 Printf.sprintf
"%dx%d" state.x state.y
4919 src#caption2
"Position" (fun () -> describe_location ()) 1
4923 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4924 "Save these parameters as global defaults at exit"
4925 (fun () -> conf.bedefault
)
4926 (fun v -> conf.bedefault
<- v)
4930 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4931 src#
bool ~offset
:0 ~
btos "Extended parameters"
4932 (fun () -> !showextended)
4933 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4937 (fun () -> conf.checkers
)
4938 (fun v -> conf.checkers
<- v; setcheckers v);
4939 src#
bool "update cursor"
4940 (fun () -> conf.updatecurs
)
4941 (fun v -> conf.updatecurs
<- v);
4943 (fun () -> conf.verbose
)
4944 (fun v -> conf.verbose
<- v);
4945 src#
bool "invert colors"
4946 (fun () -> conf.invert
)
4947 (fun v -> conf.invert
<- v);
4949 (fun () -> conf.maxhfit
)
4950 (fun v -> conf.maxhfit
<- v);
4951 src#
bool "redirect stderr"
4952 (fun () -> conf.redirectstderr)
4953 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4955 (fun () -> conf.pax
!= None
)
4958 then conf.pax
<- Some
(ref (now (), 0, 0))
4959 else conf.pax
<- None
);
4960 src#
string "uri launcher"
4961 (fun () -> conf.urilauncher
)
4962 (fun v -> conf.urilauncher
<- v);
4963 src#
string "path launcher"
4964 (fun () -> conf.pathlauncher
)
4965 (fun v -> conf.pathlauncher
<- v);
4966 src#
string "tile size"
4967 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4970 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4971 conf.tilew
<- max
64 w;
4972 conf.tileh
<- max
64 h;
4975 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4978 src#
int "texture count"
4979 (fun () -> conf.texcount
)
4982 then conf.texcount
<- v
4983 else showtext '
!'
" Failed to set texture count please retry later"
4985 src#
int "slice height"
4986 (fun () -> conf.sliceheight
)
4988 conf.sliceheight
<- v;
4989 wcmd "sliceh %d" conf.sliceheight
;
4991 src#
int "anti-aliasing level"
4992 (fun () -> conf.aalevel
)
4994 conf.aalevel
<- bound v 0 8;
4995 state.anchor <- getanchor ();
4996 opendoc state.path state.password
;
4998 src#
string "page scroll scaling factor"
4999 (fun () -> string_of_float
conf.pgscale)
5002 let s = float_of_string
v in
5005 state.text <- Printf.sprintf
5006 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
5009 src#
int "ui font size"
5010 (fun () -> fstate.fontsize
)
5011 (fun v -> setfontsize (bound v 5 100));
5012 src#
int "hint font size"
5013 (fun () -> conf.hfsize
)
5014 (fun v -> conf.hfsize
<- bound v 5 100);
5015 colorp "background color"
5016 (fun () -> conf.bgcolor
)
5017 (fun v -> conf.bgcolor
<- v);
5018 src#
bool "crop hack"
5019 (fun () -> conf.crophack
)
5020 (fun v -> conf.crophack
<- v);
5021 src#
string "trim fuzz"
5022 (fun () -> irect_to_string conf.trimfuzz
)
5025 conf.trimfuzz
<- irect_of_string v;
5027 then settrim true conf.trimfuzz
;
5029 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
5031 src#
string "throttle"
5033 match conf.maxwait
with
5034 | None
-> "show place holder if page is not ready"
5037 then "wait for page to fully render"
5039 "wait " ^ string_of_float
time
5040 ^
" seconds before showing placeholder"
5044 let f = float_of_string
v in
5046 then conf.maxwait
<- None
5047 else conf.maxwait
<- Some
f
5049 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
5051 src#
string "ghyll scroll"
5053 match conf.ghyllscroll
with
5055 | Some nab
-> ghyllscroll_to_string nab
5058 try conf.ghyllscroll
<- ghyllscroll_of_string v
5060 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
5062 src#
string "selection command"
5063 (fun () -> conf.selcmd
)
5064 (fun v -> conf.selcmd
<- v);
5065 src#
string "synctex command"
5066 (fun () -> conf.stcmd
)
5067 (fun v -> conf.stcmd
<- v);
5068 src#
string "pax command"
5069 (fun () -> conf.paxcmd
)
5070 (fun v -> conf.paxcmd
<- v);
5071 src#colorspace
"color space"
5072 (fun () -> CSTE.to_string conf.colorspace
)
5074 conf.colorspace
<- CSTE.of_int v;
5078 src#paxmark
"pax mark method"
5079 (fun () -> MTE.to_string conf.paxmark
)
5080 (fun v -> conf.paxmark
<- MTE.of_int v);
5084 (fun () -> conf.usepbo
)
5085 (fun v -> conf.usepbo
<- v);
5086 src#
bool "mouse wheel scrolls pages"
5087 (fun () -> conf.wheelbypage
)
5088 (fun v -> conf.wheelbypage
<- v);
5089 src#
bool "open remote links in a new instance"
5090 (fun () -> conf.riani
)
5091 (fun v -> conf.riani
<- v);
5095 src#caption
"Document" 0;
5096 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
5097 src#caption2
"Pages"
5098 (fun () -> string_of_int
state.pagecount
) 1;
5099 src#caption2
"Dimensions"
5100 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5104 src#caption
"Trimmed margins" 0;
5105 src#caption2
"Dimensions"
5106 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5110 src#caption
"OpenGL" 0;
5111 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
5112 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
5115 src#caption
"Location" 0;
5116 if nonemptystr
state.origin
5117 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
5118 src#caption
("Path\t" ^ mbtoutf8
state.path) 1;
5120 src#reset prevmode prevuioh
;
5124 let prevmode = state.mode
5125 and prevuioh
= state.uioh in
5126 fillsrc prevmode prevuioh
;
5127 let source = (src :> lvsource
) in
5128 let modehash = findkeyhash conf "info" in
5129 state.uioh <- coe (object (self)
5130 inherit listview ~
source ~trusted
:true ~
modehash as super
5131 val mutable m_prevmemused
= 0
5132 method infochanged
= function
5134 if m_prevmemused
!= state.memused
5136 m_prevmemused
<- state.memused
;
5137 G.postRedisplay "memusedchanged";
5139 | Pdim
-> G.postRedisplay "pdimchanged"
5140 | Docinfo
-> fillsrc prevmode prevuioh
5142 method key key mask
=
5143 if not
(Wsi.withctrl mask
)
5146 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5147 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5148 | _ -> super#
key key mask
5149 else super#
key key mask
5151 G.postRedisplay "info";
5157 inherit lvsourcebase
5158 method getitemcount
= Array.length
state.help
5160 let s, l, _ = state.help
.(n) in
5163 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5167 m_qsearch
<- qsearch;
5168 match state.help
.(active) with
5169 | _, _, Action
f -> Some
(f uioh)
5179 method hasaction
n =
5180 match state.help
.(n) with
5181 | _, _, Action
_ -> true
5188 let modehash = findkeyhash conf "help" in
5189 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5190 G.postRedisplay "help";
5195 let re = Str.regexp
"[\r\n]" in
5197 inherit lvsourcebase
5198 val mutable m_items
= [||]
5200 method getitemcount
= 1 + Array.length m_items
5205 else m_items
.(n-1), 0
5207 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5212 then Buffer.clear
state.errmsgs
;
5213 m_qsearch
<- qsearch;
5220 method hasaction
n =
5224 state.newerrmsgs
<- false;
5225 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5226 m_items
<- Array.of_list
l
5234 let source = (msgsource :> lvsource
) in
5235 let modehash = findkeyhash conf "listview" in
5236 state.uioh <- coe (object
5237 inherit listview ~
source ~trusted
:false ~
modehash as super
5240 then msgsource#reset
;
5243 G.postRedisplay "msgs";
5246 let quickbookmark ?title
() =
5247 match state.layout with
5253 let sec = Unix.gettimeofday
() in
5254 let tm = Unix.localtime
sec in
5255 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5259 (tm.Unix.tm_year
+ 1900)
5262 | Some
title -> title
5264 state.bookmarks
<- (title, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5267 let setautoscrollspeed step goingdown
=
5268 let incr = max
1 ((abs step
) / 2) in
5269 let incr = if goingdown
then incr else -incr in
5270 let astep = step
+ incr in
5271 state.autoscroll
<- Some
astep;
5275 match conf.columns
with
5277 | _ -> state.x != 0 || conf.zoom > 1.0
5280 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5282 let existsinrow pageno (columns
, coverA
, coverB
) p =
5283 let last = ((pageno - coverA
) mod columns
) + columns
in
5284 let rec any = function
5287 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5291 then (if l.pageno = last then false else any rest
)
5299 match state.layout with
5301 let pageno = page_of_y state.y in
5302 gotoghyll (getpagey (pageno+1))
5304 match conf.columns
with
5306 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5308 let y = clamp (pgscale state.winh
) in
5311 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5312 gotoghyll (getpagey pageno)
5313 | Cmulti
((c, _, _) as cl, _) ->
5314 if conf.presentation
5315 && (existsinrow l.pageno cl
5316 (fun l -> l.pageh
> l.pagey + l.pagevh))
5318 let y = clamp (pgscale state.winh
) in
5321 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5322 gotoghyll (getpagey pageno)
5324 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5326 let pagey, pageh
= getpageyh l.pageno in
5327 let pagey = pagey + pageh
* l.pagecol
in
5328 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5329 gotoghyll (pagey + pageh
+ ips)
5333 match state.layout with
5335 let pageno = page_of_y state.y in
5336 gotoghyll (getpagey (pageno-1))
5338 match conf.columns
with
5340 if conf.presentation
&& l.pagey != 0
5342 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5344 let pageno = max
0 (l.pageno-1) in
5345 gotoghyll (getpagey pageno)
5346 | Cmulti
((c, _, coverB
) as cl, _) ->
5347 if conf.presentation
&&
5348 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5350 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5353 if l.pageno = state.pagecount
- coverB
5357 let pageno = max
0 (l.pageno-decr) in
5358 gotoghyll (getpagey pageno)
5366 let pageno = max
0 (l.pageno-1) in
5367 let pagey, pageh
= getpageyh pageno in
5370 let pagey, pageh
= getpageyh l.pageno in
5371 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5376 let viewkeyboard key mask
=
5378 let mode = state.mode in
5379 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5382 G.postRedisplay "view:enttext"
5384 let ctrl = Wsi.withctrl mask
in
5386 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5392 | 0xff63 -> (* insert *)
5393 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5395 state.mode <- LinkNav
(Ltgendir
0);
5398 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5400 | 0xff1b | 113 -> (* escape / q *)
5401 begin match state.mstate
with
5403 state.mstate
<- Mnone
;
5404 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5405 G.postRedisplay "kill zoom rect";
5407 begin match state.mode with
5410 G.postRedisplay "esc leave linknav"
5412 match state.ranchors
with
5414 | (path, password
, anchor, origin
) :: rest
->
5415 state.ranchors
<- rest
;
5416 state.anchor <- anchor;
5417 state.origin
<- origin
;
5418 state.nameddest
<- "";
5419 opendoc path password
5423 | 0xff08 -> (* backspace *)
5424 gotoghyll (getnav ~
-1)
5432 G.postRedisplay "dehighlight";
5434 | 47 | 63 -> (* / ? *)
5435 let ondone isforw
s =
5436 cbput state.hists
.pat
s;
5437 state.searchpattern
<- s;
5440 let s = String.create
1 in
5441 s.[0] <- Char.chr
key;
5442 enttext (s, "", Some
(onhist state.hists
.pat
),
5443 textentry, ondone (key = 47), true)
5445 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5446 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5447 setzoom (conf.zoom +. incr)
5449 | 43 | 0xffab -> (* + *)
5452 try int_of_string
s with exc
->
5453 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5459 state.text <- "page bias is now " ^ string_of_int
n;
5462 enttext ("page bias: ", "", None
, intentry, ondone, true)
5464 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5465 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5466 setzoom (max
0.01 (conf.zoom -. decr))
5468 | 45 | 0xffad -> (* - *)
5469 let ondone msg
= state.text <- msg
in
5471 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5472 optentry state.mode, ondone, true
5475 | 48 when ctrl -> (* ctrl-0 *)
5483 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5485 match conf.columns
with
5486 | Csingle
_ | Cmulti
_ -> 1
5487 | Csplit
(n, _) -> n
5489 let h = state.winh
-
5490 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5492 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5493 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5496 | 51 when ctrl -> (* ctrl-3 *)
5498 match conf.fitmodel
with
5499 | FitWidth
-> FitProportional
5500 | FitProportional
-> FitPage
5501 | FitPage
-> FitWidth
5503 state.text <- "fit model: " ^
FMTE.to_string fm;
5504 reqlayout conf.angle
fm
5506 | 0xffc6 -> (* f9 *)
5509 | 57 when ctrl -> (* ctrl-9 *)
5512 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5513 when not
ctrl -> (* 0..9 *)
5516 try int_of_string
s with exc
->
5517 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5523 cbput state.hists
.pag
(string_of_int
n);
5524 gotopage1 (n + conf.pagebias
- 1) 0;
5527 let pageentry text key =
5528 match Char.unsafe_chr
key with
5529 | '
g'
-> TEdone
text
5530 | _ -> intentry text key
5532 let text = "x" in text.[0] <- Char.chr
key;
5533 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5536 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5537 reshape state.winw
state.winh
;
5540 state.bzoom
<- not
state.bzoom
;
5542 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5545 conf.hlinks
<- not
conf.hlinks
;
5546 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5547 G.postRedisplay "toggle highlightlinks";
5550 state.glinks
<- true;
5551 let mode = state.mode in
5552 state.mode <- Textentry
(
5553 (":", "", None
, linknentry, linkndone gotounder, false),
5555 state.glinks
<- false;
5559 G.postRedisplay "view:linkent(F)"
5562 state.glinks
<- true;
5563 let mode = state.mode in
5564 state.mode <- Textentry
(
5566 ":", "", None
, linknentry, linkndone (fun under ->
5567 selstring (undertext under);
5571 state.glinks
<- false;
5575 G.postRedisplay "view:linkent"
5578 begin match state.autoscroll
with
5580 conf.autoscrollstep
<- step
;
5581 state.autoscroll
<- None
5583 if conf.autoscrollstep
= 0
5584 then state.autoscroll
<- Some
1
5585 else state.autoscroll
<- Some
conf.autoscrollstep
5588 | 112 when ctrl -> (* ctrl-p *)
5592 setpresentationmode (not
conf.presentation
);
5593 showtext ' '
("presentation mode " ^
5594 if conf.presentation
then "on" else "off");
5597 if List.mem
Wsi.Fullscreen
state.winstate
5598 then Wsi.reshape conf.cwinw
conf.cwinh
5599 else Wsi.fullscreen
()
5601 | 112 | 78 -> (* p|N *)
5602 search state.searchpattern
false
5604 | 110 | 0xffc0 -> (* n|F3 *)
5605 search state.searchpattern
true
5608 begin match state.layout with
5611 gotoghyll (getpagey l.pageno)
5617 | 0xff9f | 0xffff -> (* delete *)
5621 showtext ' '
(describe_location ());
5624 begin match state.layout with
5627 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5632 enterbookmarkmode ()
5634 | 104 | 0xffbe -> (* h|F1 *)
5640 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5645 match state.layout with
5650 (s, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5653 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5657 showtext ' '
"Quick bookmark added";
5660 begin match state.layout with
5662 let rect = getpdimrect
l.pagedimno
in
5666 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5667 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5669 (truncate
(rect.(1) -. rect.(0)),
5670 truncate
(rect.(3) -. rect.(0)))
5672 let w = truncate
((float w)*.conf.zoom)
5673 and h = truncate
((float h)*.conf.zoom) in
5676 state.anchor <- getanchor ();
5677 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5679 G.postRedisplay "z";
5684 | 120 -> state.roam
() (* x *)
5685 | 60 | 62 -> (* < > *)
5686 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5688 | 91 | 93 -> (* [ ] *)
5690 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5692 G.postRedisplay "brightness";
5694 | 99 when state.mode = View
-> (* [alt-]c *)
5699 let m = (wadjsb state.winw
- state.w) / 2 in
5701 gotoy_and_clear_text state.y
5705 match state.prevcolumns
with
5706 | None
-> (1, 0, 0), 1.0
5707 | Some
(columns
, z
) ->
5710 | Csplit
(c, _) -> -c, 0, 0
5711 | Cmulti
((c, a, b), _) -> c, a, b
5712 | Csingle
_ -> 1, 0, 0
5716 setcolumns View
c a b;
5719 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5720 -> (* ctrl-shift- (kp) [up|down] *)
5721 let zoom, x = state.prevzoom
in
5725 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5726 begin match state.autoscroll
with
5728 begin match state.mode with
5729 | Birdseye beye
-> upbirdseye 1 beye
5732 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5734 if not
(Wsi.withshift mask
) && conf.presentation
5736 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5740 setautoscrollspeed n false
5743 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5744 begin match state.autoscroll
with
5746 begin match state.mode with
5747 | Birdseye beye
-> downbirdseye 1 beye
5750 then gotoy_and_clear_text (clamp (state.winh
/2))
5752 if not
(Wsi.withshift mask
) && conf.presentation
5754 else gotoy_and_clear_text (clamp conf.scrollstep
)
5758 setautoscrollspeed n true
5761 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5762 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5768 else conf.hscrollstep
5770 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5771 state.x <- panbound (state.x + dx);
5772 gotoy_and_clear_text state.y
5775 G.postRedisplay "left/right"
5778 | 0xff55 | 0xff9a -> (* (kp) prior *)
5782 match state.layout with
5784 | l :: _ -> state.y - l.pagey
5786 clamp (pgscale (-state.winh
))
5790 | 0xff56 | 0xff9b -> (* (kp) next *)
5794 match List.rev
state.layout with
5796 | l :: _ -> getpagey l.pageno
5798 clamp (pgscale state.winh
)
5802 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5804 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5805 gotoghyll (clamp state.maxy)
5808 when Wsi.withalt mask
-> (* alt-(kp) right *)
5809 gotoghyll (getnav 1)
5811 when Wsi.withalt mask
-> (* alt-(kp) left *)
5812 gotoghyll (getnav ~
-1)
5817 | 118 when conf.debug
-> (* v *)
5820 match getopaque l.pageno with
5823 let x0, y0, x1, y1 = pagebbox opaque
in
5824 let a,b = float x0, float y0 in
5825 let c,d = float x1, float y0 in
5826 let e,f = float x1, float y1 in
5827 let h,j
= float x0, float y1 in
5828 let rect = (a,b,c,d,e,f,h,j
) in
5830 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5832 G.postRedisplay "v";
5835 vlog "huh? %s" (Wsi.keyname
key)
5838 let linknavkeyboard key mask
linknav =
5839 let getpage pageno =
5840 let rec loop = function
5842 | l :: _ when l.pageno = pageno -> Some
l
5843 | _ :: rest
-> loop rest
5844 in loop state.layout
5846 let doexact (pageno, n) =
5847 match getopaque pageno, getpage pageno with
5848 | Some opaque
, Some
l ->
5849 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5851 let under = getlink opaque
n in
5852 G.postRedisplay "link gotounder";
5858 | 0xff50 -> (* home *)
5859 Some
(findlink opaque LDfirst
), -1
5861 | 0xff57 -> (* end *)
5862 Some
(findlink opaque LDlast
), 1
5864 | 0xff51 -> (* left *)
5865 Some
(findlink opaque
(LDleft
n)), -1
5867 | 0xff53 -> (* right *)
5868 Some
(findlink opaque
(LDright
n)), 1
5870 | 0xff52 -> (* up *)
5871 Some
(findlink opaque
(LDup
n)), -1
5873 | 0xff54 -> (* down *)
5874 Some
(findlink opaque
(LDdown
n)), 1
5879 begin match findpwl
l.pageno dir with
5883 state.mode <- LinkNav
(Ltgendir
dir);
5884 let y, h = getpageyh pageno in
5887 then y + h - state.winh
5892 begin match getopaque pageno, getpage pageno with
5893 | Some opaque
, Some
_ ->
5895 let ld = if dir > 0 then LDfirst
else LDlast
in
5898 begin match link with
5900 showlinktype (getlink opaque
m);
5901 state.mode <- LinkNav
(Ltexact
(pageno, m));
5902 G.postRedisplay "linknav jpage";
5909 begin match opt with
5910 | Some Lnotfound
-> pwl l dir;
5911 | Some
(Lfound
m) ->
5915 let _, y0, _, y1 = getlinkrect opaque
m in
5917 then gotopage1 l.pageno y0
5919 let d = fstate.fontsize
+ 1 in
5920 if y1 - l.pagey > l.pagevh - d
5921 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5922 else G.postRedisplay "linknav";
5924 showlinktype (getlink opaque
m);
5925 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5928 | None
-> viewkeyboard key mask
5930 | _ -> viewkeyboard key mask
5935 G.postRedisplay "leave linknav"
5939 | Ltgendir
_ -> viewkeyboard key mask
5940 | Ltexact exact
-> doexact exact
5943 let keyboard key mask
=
5944 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5945 then wcmd "interrupt"
5946 else state.uioh <- state.uioh#
key key mask
5949 let birdseyekeyboard key mask
5950 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5952 match conf.columns
with
5954 | Cmulti
((c, _, _), _) -> c
5955 | Csplit
_ -> failwith
"bird's eye split mode"
5957 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5959 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5960 let y, h = getpageyh pageno in
5961 let top = (state.winh
- h) / 2 in
5962 gotoy (max
0 (y - top))
5963 | 0xff0d (* enter *)
5964 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5965 | 0xff1b -> leavebirdseye beye
true (* escape *)
5966 | 0xff52 -> upbirdseye incr beye
(* up *)
5967 | 0xff54 -> downbirdseye incr beye
(* down *)
5968 | 0xff51 -> upbirdseye 1 beye
(* left *)
5969 | 0xff53 -> downbirdseye 1 beye
(* right *)
5971 | 0xff55 -> (* prior *)
5972 begin match state.layout with
5976 state.mode <- Birdseye
(
5977 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5979 gotopage1 l.pageno 0;
5982 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5984 | [] -> gotoy (clamp (-state.winh
))
5986 state.mode <- Birdseye
(
5987 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5989 gotopage1 l.pageno 0
5992 | [] -> gotoy (clamp (-state.winh
))
5995 | 0xff56 -> (* next *)
5996 begin match List.rev
state.layout with
5998 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5999 begin match layout with
6001 let incr = l.pageh
- l.pagevh in
6006 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
6008 G.postRedisplay "birdseye pagedown";
6010 else gotoy (clamp (incr + conf.interpagespace
*2));
6014 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
6015 gotopage1 l.pageno 0;
6018 | [] -> gotoy (clamp state.winh
)
6021 | 0xff50 -> (* home *)
6022 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
6025 | 0xff57 -> (* end *)
6026 let pageno = state.pagecount
- 1 in
6027 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
6028 if not
(pagevisible state.layout pageno)
6031 match List.rev
state.pdims
with
6033 | (_, _, h, _) :: _ -> h
6035 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
6036 else G.postRedisplay "birdseye end";
6037 | _ -> viewkeyboard key mask
6042 match state.mode with
6043 | Textentry
_ -> scalecolor 0.4
6045 | View
-> scalecolor 1.0
6046 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6047 if l.pageno = hooverpageno
6050 if l.pageno = pageno
6058 let postdrawpage l linkindexbase
=
6059 match getopaque l.pageno with
6061 if tileready l l.pagex
l.pagey
6063 let x = l.pagedispx - l.pagex
6064 and y = l.pagedispy - l.pagey in
6066 match conf.columns
with
6067 | Csingle
_ | Cmulti
_ ->
6068 (if conf.hlinks
then 1 else 0)
6070 && not
(isbirdseye state.mode) then 2 else 0)
6074 match state.mode with
6075 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6078 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6083 let scrollindicator () =
6084 let sbw, ph
, sh = state.uioh#
scrollph in
6085 let sbh, pw, sw = state.uioh#scrollpw
in
6087 GlDraw.color (0.64, 0.64, 0.64);
6089 (float (state.winw
- sbw)) 0.
6090 (float state.winw
) (float state.winh
)
6093 0. (float (state.winh
- sbh))
6094 (float (wadjsb state.winw
- 1)) (float state.winh
)
6096 GlDraw.color (0.0, 0.0, 0.0);
6099 (float (state.winw
- sbw)) ph
6100 (float state.winw
) (ph
+. sh)
6103 pw (float (state.winh
- sbh))
6104 (pw +. sw) (float state.winh
)
6109 match state.mstate
with
6110 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6113 | Msel
((x0, y0), (x1, y1)) ->
6114 let rec loop = function
6116 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6117 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6118 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6119 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6121 match getopaque l.pageno with
6123 let x0, y0 = pagetranslatepoint l x0 y0 in
6124 let x1, y1 = pagetranslatepoint l x1 y1 in
6125 seltext opaque
(x0, y0, x1, y1);
6133 let showrects = function [] -> () | rects
->
6135 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6136 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6138 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6140 if l.pageno = pageno
6142 let dx = float (l.pagedispx - l.pagex
) in
6143 let dy = float (l.pagedispy - l.pagey) in
6144 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6145 Raw.sets_float
state.vraw ~pos
:0
6150 GlArray.vertex `two
state.vraw
;
6151 GlArray.draw_arrays `triangle_strip
0 4;
6160 GlClear.color (scalecolor2 conf.bgcolor
);
6161 GlClear.clear
[`
color];
6162 List.iter
drawpage state.layout;
6164 match state.mode with
6165 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6166 begin match getopaque pageno with
6168 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6175 | None
-> state.rects
6180 let rec postloop linkindexbase
= function
6182 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6183 postloop linkindexbase rest
6187 postloop 0 state.layout;
6189 begin match state.mstate
with
6190 | Mzoomrect
((x0, y0), (x1, y1)) ->
6192 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6193 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6194 filledrect (float x0) (float y0) (float x1) (float y1);
6203 let zoomrect x y x1 y1 =
6206 and y0 = min
y y1 in
6207 gotoy (state.y + y0);
6208 state.anchor <- getanchor ();
6209 let zoom = (float state.w) /. float (x1 - x0) in
6211 match conf.fitmodel
, conf.columns
with
6212 | FitPage
, Csplit
_ ->
6213 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6216 let adjw = wadjsb state.winw
in
6218 then (adjw - state.w) / 2
6221 state.x <- (state.x + margin) - x0;
6223 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6224 state.mstate
<- Mnone
;
6228 let g opaque
l px py =
6229 match rectofblock opaque
px py with
6231 let x0 = a.(0) -. 20. in
6232 let x1 = a.(1) +. 20. in
6233 let y0 = a.(2) -. 20. in
6234 let zoom = (float state.w) /. (x1 -. x0) in
6235 let pagey = getpagey l.pageno in
6236 gotoy_and_clear_text (pagey + truncate
y0);
6237 state.anchor <- getanchor ();
6238 let margin = (state.w - l.pagew
)/2 in
6239 state.x <- -truncate
x0 - margin;
6244 match conf.columns
with
6246 showtext '
!'
"block zooming does not work properly in split columns mode"
6247 | _ -> onppundermouse g x y ()
6251 let winw = wadjsb state.winw - 1 in
6252 let s = float x /. float winw in
6253 let destx = truncate
(float (state.w + winw) *. s) in
6254 state.x <- winw - destx;
6255 gotoy_and_clear_text state.y;
6256 state.mstate
<- Mscrollx
;
6260 let s = float y /. float state.winh
in
6261 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6262 gotoy_and_clear_text desty;
6263 state.mstate
<- Mscrolly
;
6266 let viewmouse button down
x y mask
=
6268 | n when (n == 4 || n == 5) && not down
->
6269 if Wsi.withctrl mask
6271 match state.mstate
with
6272 | Mzoom
(oldn
, i
) ->
6280 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6282 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6284 let zoom = conf.zoom -. incr in
6286 state.mstate
<- Mzoom
(n, 0);
6288 state.mstate
<- Mzoom
(n, i
+1);
6290 else state.mstate
<- Mzoom
(n, 0)
6292 | _ -> state.mstate
<- Mzoom
(n, 0)
6295 match state.autoscroll
with
6296 | Some step
-> setautoscrollspeed step
(n=4)
6298 if conf.wheelbypage
|| conf.presentation
6307 then -conf.scrollstep
6308 else conf.scrollstep
6310 let incr = incr * 2 in
6311 let y = clamp incr in
6312 gotoy_and_clear_text y
6315 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6317 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6318 gotoy_and_clear_text state.y
6320 | 1 when Wsi.withshift mask
->
6321 state.mstate
<- Mnone
;
6324 match unproject x y with
6325 | Some
(pageno, ux
, uy
) ->
6326 let cmd = Printf.sprintf
6328 conf.stcmd
state.path pageno ux uy
6334 | 1 when Wsi.withctrl mask
->
6337 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6338 state.mstate
<- Mpan
(x, y)
6341 state.mstate
<- Mnone
6346 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6348 state.mstate
<- Mzoomrect
(p, p)
6351 match state.mstate
with
6352 | Mzoomrect
((x0, y0), _) ->
6353 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6354 then zoomrect x0 y0 x y
6356 state.mstate
<- Mnone
;
6357 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6358 G.postRedisplay "kill accidental zoom rect";
6361 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6362 state.mstate
<- Mnone
6365 | 1 when x > state.winw - vscrollw () ->
6368 let _, position, sh = state.uioh#
scrollph in
6369 if y > truncate
position && y < truncate
(position +. sh)
6370 then state.mstate
<- Mscrolly
6373 state.mstate
<- Mnone
6375 | 1 when y > state.winh
- hscrollh () ->
6378 let _, position, sw = state.uioh#scrollpw
in
6379 if x > truncate
position && x < truncate
(position +. sw)
6380 then state.mstate
<- Mscrollx
6383 state.mstate
<- Mnone
6385 | 1 when state.bzoom
-> if not down
then zoomblock x y
6388 let dest = if down
then getunder x y else Unone
in
6389 begin match dest with
6392 | Uremote
_ | Uremotedest
_
6393 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6396 | Unone
when down
->
6397 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6398 state.mstate
<- Mpan
(x, y);
6400 | Unone
| Utext
_ ->
6403 if conf.angle
mod 360 = 0
6405 state.mstate
<- Msel
((x, y), (x, y));
6406 G.postRedisplay "mouse select";
6410 match state.mstate
with
6413 | Mzoom
_ | Mscrollx
| Mscrolly
->
6414 state.mstate
<- Mnone
6416 | Mzoomrect
((x0, y0), _) ->
6420 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6421 state.mstate
<- Mnone
6423 | Msel
((x0, y0), (x1, y1)) ->
6424 let rec loop = function
6428 let a0 = l.pagedispy in
6429 let a1 = a0 + l.pagevh in
6430 let b0 = l.pagedispx in
6431 let b1 = b0 + l.pagevw in
6432 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6433 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6437 match getopaque l.pageno with
6440 match Ne.pipe () with
6444 "can not create sel pipe: %s"
6447 let doclose what fd
=
6448 Ne.clo fd
(fun msg
->
6449 dolog
"%s close failed: %s" what msg
)
6452 popen conf.selcmd
[r, 0; w, -1];
6453 copysel
w opaque
true;
6455 G.postRedisplay "copysel";
6457 dolog
"can not execute %S: %s"
6458 conf.selcmd
(exntos exn
);
6466 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6467 state.mstate
<- Mnone
;
6474 let birdseyemouse button down
x y mask
6475 (conf, leftx
, _, hooverpageno
, anchor) =
6478 let rec loop = function
6481 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6482 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6484 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6490 | _ -> viewmouse button down
x y mask
6496 method key key mask
=
6497 begin match state.mode with
6498 | Textentry
textentry -> textentrykeyboard key mask
textentry
6499 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6500 | View
-> viewkeyboard key mask
6501 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6505 method button button bstate
x y mask
=
6506 begin match state.mode with
6508 | View
-> viewmouse button bstate
x y mask
6509 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6515 begin match state.mode with
6517 | View
| Birdseye
_ | LinkNav
_ ->
6518 match state.mstate
with
6519 | Mzoom
_ | Mnone
-> ()
6524 state.mstate
<- Mpan
(x, y);
6526 then state.x <- panbound (state.x + dx);
6528 gotoy_and_clear_text y
6531 state.mstate
<- Msel
(a, (x, y));
6532 G.postRedisplay "motion select";
6535 let y = min
state.winh
(max
0 y) in
6539 let x = min
state.winw (max
0 x) in
6542 | Mzoomrect
(p0
, _) ->
6543 state.mstate
<- Mzoomrect
(p0
, (x, y));
6544 G.postRedisplay "motion zoomrect";
6548 method pmotion
x y =
6549 begin match state.mode with
6550 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6551 let rec loop = function
6553 if hooverpageno
!= -1
6555 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6556 G.postRedisplay "pmotion birdseye no hoover";
6559 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6560 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6562 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6563 G.postRedisplay "pmotion birdseye hoover";
6573 match state.mstate
with
6574 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6581 let past, _, _ = !r in
6583 let delta = now -. past in
6586 else r := (now, x, y)
6590 method infochanged
_ = ()
6593 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6596 then 0.0, float state.winh
6597 else scrollph state.y maxy
6602 let winw = wadjsb state.winw in
6603 let fwinw = float winw in
6605 let sw = fwinw /. float state.w in
6606 let sw = fwinw *. sw in
6607 max
sw (float conf.scrollh
)
6610 let maxx = state.w + winw in
6611 let x = winw - state.x in
6612 let percent = float x /. float maxx in
6613 (fwinw -. sw) *. percent
6615 hscrollh (), position, sw
6619 match state.mode with
6620 | LinkNav
_ -> "links"
6621 | Textentry
_ -> "textentry"
6622 | Birdseye
_ -> "birdseye"
6625 findkeyhash conf modename
6627 method eformsgs
= true
6634 let fontpath = ref "";;
6637 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6640 let l = String.length
s in
6641 let b = Buffer.create
l in
6647 try Sys.getenv
"HOME"
6650 ("Can not determine home directory location: " ^ exntos exn
);
6654 let modifier_of_string = function
6655 | "alt" -> Wsi.altmask
6656 | "shift" -> Wsi.shiftmask
6657 | "ctrl" | "control" -> Wsi.ctrlmask
6658 | "meta" -> Wsi.metamask
6663 let r = Str.regexp
"-" in
6665 let elems = Str.full_split
r s in
6668 let m1 = modifier_of_string s in
6670 then (Wsi.namekey
s, m)
6673 | Str.Delim
s when n land 1 = 0 -> g s
6675 | Str.Delim
_ -> (k
, m)
6677 let rec loop n k
m = function
6680 let k, m = f n k m x in
6686 let keys_of_string =
6687 let r = Str.regexp
"[ \t]" in
6689 let elems = Str.split
r s in
6690 List.map
key_of_string elems
6693 let copykeyhashes c =
6694 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6697 let config_of c attrs
=
6701 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6702 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6703 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6704 | "preload" -> { c with preload = bool_of_string
v }
6705 | "page-bias" -> { c with pagebias
= int_of_string
v }
6706 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6707 | "horizontal-scroll-step" ->
6708 { c with hscrollstep
= max
(int_of_string
v) 1 }
6709 | "auto-scroll-step" ->
6710 { c with autoscrollstep
= max
0 (int_of_string
v) }
6711 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6712 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6715 match String.lowercase
v with
6716 | "true" -> Some infinity
6718 | f -> Some
(float_of_string
f)
6720 { c with maxwait
= mw}
6721 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6722 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6723 | "vertical-margin" ->
6724 { c with interpagespace
= max
0 (int_of_string
v) }
6726 let zoom = float_of_string
v /. 100. in
6727 let zoom = max
zoom 0.0 in
6728 { c with zoom = zoom }
6729 | "presentation" -> { c with presentation
= bool_of_string
v }
6730 | "rotation-angle" -> { c with angle
= int_of_string
v }
6731 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6732 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6733 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6734 | "proportional-display" ->
6737 then FitProportional
6740 { c with fitmodel
= fm }
6741 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6742 | "pixmap-cache-size" ->
6743 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6744 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6745 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6746 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6747 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6748 | "background-color" -> { c with bgcolor
= color_of_string v }
6749 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6750 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6751 | "mupdf-store-size" ->
6752 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6753 | "checkers" -> { c with checkers
= bool_of_string
v }
6754 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6755 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6756 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6757 | "uri-launcher" -> { c with urilauncher
= unent v }
6758 | "path-launcher" -> { c with pathlauncher
= unent v }
6759 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6760 | "invert-colors" -> { c with invert
= bool_of_string
v }
6761 | "brightness" -> { c with colorscale
= float_of_string
v }
6762 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6763 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6765 let (n, _, _) as nab
= multicolumns_of_string v in
6767 then { c with columns
= Csplit
(-n, [||]) }
6768 else { c with columns
= Cmulti
(nab
, [||]) }
6769 | "birds-eye-columns" ->
6770 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6771 | "selection-command" -> { c with selcmd
= unent v }
6772 | "synctex-command" -> { c with stcmd
= unent v }
6773 | "pax-command" -> { c with paxcmd
= unent v }
6774 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6775 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6776 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6777 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6778 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6779 | "horizontal-scrollbar-visible" ->
6782 then c.scrollb
lor scrollbhv
6783 else c.scrollb
land (lnot
scrollbhv)
6785 { c with scrollb
= b }
6786 | "vertical-scrollbar-visible" ->
6789 then c.scrollb
lor scrollbvv
6790 else c.scrollb
land (lnot
scrollbvv)
6792 { c with scrollb
= b }
6793 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6797 then Some
(ref (0.0, 0, 0))
6799 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6802 prerr_endline
("Error processing attribute (`" ^
6803 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6806 let rec fold c = function
6809 let c = apply c k v in
6812 fold { c with keyhashes
= copykeyhashes c } attrs
;
6815 let fromstring f pos
n v d =
6818 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6819 n v pos
(exntos exn
)
6824 let bookmark_of attrs
=
6825 let rec fold title page
rely visy
= function
6826 | ("title", v) :: rest
-> fold v page
rely visy rest
6827 | ("page", v) :: rest
-> fold title v rely visy rest
6828 | ("rely", v) :: rest
-> fold title page
v visy rest
6829 | ("visy", v) :: rest
-> fold title page
rely v rest
6830 | _ :: rest
-> fold title page
rely visy rest
6831 | [] -> title, page
, rely, visy
6833 fold "invalid" "0" "0" "0" attrs
6837 let rec fold path page
rely pan visy
= function
6838 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6839 | ("page", v) :: rest
-> fold path v rely pan visy rest
6840 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6841 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6842 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6843 | _ :: rest
-> fold path page
rely pan visy rest
6844 | [] -> path, page
, rely, pan
, visy
6846 fold "" "0" "0" "0" "0" attrs
6850 let rec fold rs ls
= function
6851 | ("out", v) :: rest
-> fold v ls rest
6852 | ("in", v) :: rest
-> fold rs
v rest
6853 | _ :: rest
-> fold ls rs rest
6859 let setconf dst
src =
6860 dst
.scrollbw
<- src.scrollbw
;
6861 dst
.scrollh
<- src.scrollh
;
6862 dst
.icase
<- src.icase
;
6863 dst
.preload <- src.preload;
6864 dst
.pagebias
<- src.pagebias
;
6865 dst
.verbose
<- src.verbose
;
6866 dst
.scrollstep
<- src.scrollstep
;
6867 dst
.maxhfit
<- src.maxhfit
;
6868 dst
.crophack
<- src.crophack
;
6869 dst
.autoscrollstep
<- src.autoscrollstep
;
6870 dst
.maxwait
<- src.maxwait
;
6871 dst
.hlinks
<- src.hlinks
;
6872 dst
.underinfo
<- src.underinfo
;
6873 dst
.interpagespace
<- src.interpagespace
;
6874 dst
.zoom <- src.zoom;
6875 dst
.presentation
<- src.presentation
;
6876 dst
.angle
<- src.angle
;
6877 dst
.cwinw
<- src.cwinw
;
6878 dst
.cwinh
<- src.cwinh
;
6879 dst
.savebmarks
<- src.savebmarks
;
6880 dst
.memlimit
<- src.memlimit
;
6881 dst
.fitmodel
<- src.fitmodel
;
6882 dst
.texcount
<- src.texcount
;
6883 dst
.sliceheight
<- src.sliceheight
;
6884 dst
.thumbw
<- src.thumbw
;
6885 dst
.jumpback
<- src.jumpback
;
6886 dst
.bgcolor
<- src.bgcolor
;
6887 dst
.tilew
<- src.tilew
;
6888 dst
.tileh
<- src.tileh
;
6889 dst
.mustoresize
<- src.mustoresize
;
6890 dst
.checkers
<- src.checkers
;
6891 dst
.aalevel
<- src.aalevel
;
6892 dst
.trimmargins
<- src.trimmargins
;
6893 dst
.trimfuzz
<- src.trimfuzz
;
6894 dst
.urilauncher
<- src.urilauncher
;
6895 dst
.colorspace
<- src.colorspace
;
6896 dst
.invert
<- src.invert
;
6897 dst
.colorscale
<- src.colorscale
;
6898 dst
.redirectstderr <- src.redirectstderr;
6899 dst
.ghyllscroll
<- src.ghyllscroll
;
6900 dst
.columns
<- src.columns
;
6901 dst
.beyecolumns
<- src.beyecolumns
;
6902 dst
.selcmd
<- src.selcmd
;
6903 dst
.updatecurs
<- src.updatecurs
;
6904 dst
.pathlauncher
<- src.pathlauncher
;
6905 dst
.keyhashes
<- copykeyhashes src;
6906 dst
.hfsize
<- src.hfsize
;
6907 dst
.hscrollstep
<- src.hscrollstep
;
6908 dst
.pgscale <- src.pgscale;
6909 dst
.usepbo
<- src.usepbo
;
6910 dst
.wheelbypage
<- src.wheelbypage
;
6911 dst
.stcmd
<- src.stcmd
;
6912 dst
.paxcmd
<- src.paxcmd
;
6913 dst
.scrollb
<- src.scrollb
;
6914 dst
.riani
<- src.riani
;
6915 dst
.paxmark
<- src.paxmark
;
6919 else Some
((ref (0.0, 0, 0)));
6923 let h = Hashtbl.create
10 in
6924 let dc = { defconf with angle
= defconf.angle
} in
6925 let rec toplevel v t spos
_ =
6927 | Vdata
| Vcdata
| Vend
-> v
6928 | Vopen
("llppconfig", _, closed
) ->
6931 else { v with f = llppconfig
}
6933 error
"unexpected subelement at top level" s spos
6934 | Vclose
_ -> error
"unexpected close at top level" s spos
6936 and llppconfig
v t spos
_ =
6938 | Vdata
| Vcdata
-> v
6939 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6940 | Vopen
("defaults", attrs
, closed
) ->
6941 let c = config_of dc attrs
in
6945 else { v with f = defaults
}
6947 | Vopen
("ui-font", attrs
, closed
) ->
6948 let rec getsize size
= function
6950 | ("size", v) :: rest
->
6952 fromstring int_of_string spos
"size" v fstate.fontsize
in
6954 | l -> getsize size l
6956 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6959 else { v with f = uifont
(Buffer.create
10) }
6961 | Vopen
("doc", attrs
, closed
) ->
6962 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6963 let path = unent pathent
6964 and pageno = fromstring int_of_string spos
"page" spage
0
6965 and rely = fromstring float_of_string spos
"rely" srely
0.0
6966 and pan
= fromstring int_of_string spos
"pan" span
0
6967 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6968 let c = config_of dc attrs
in
6969 let anchor = (pageno, rely, visy
) in
6971 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6972 else { v with f = doc
path pan
anchor c [] }
6975 error
"unexpected subelement in llppconfig" s spos
6977 | Vclose
"llppconfig" -> { v with f = toplevel }
6978 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6980 and defaults
v t spos
_ =
6982 | Vdata
| Vcdata
-> v
6983 | Vend
-> error
"unexpected end of input in defaults" s spos
6984 | Vopen
("keymap", attrs
, closed
) ->
6986 try List.assoc
"mode" attrs
6987 with Not_found
-> "global" in
6992 let h = findkeyhash dc modename in
6993 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6996 { v with f = pkeymap
ret KeyMap.empty }
6998 | Vopen
(_, _, _) ->
6999 error
"unexpected subelement in defaults" s spos
7001 | Vclose
"defaults" ->
7002 { v with f = llppconfig
}
7004 | Vclose
_ -> error
"unexpected close in defaults" s spos
7006 and uifont
b v t spos
epos =
7009 Buffer.add_substring
b s spos
(epos - spos
);
7011 | Vopen
(_, _, _) ->
7012 error
"unexpected subelement in ui-font" s spos
7013 | Vclose
"ui-font" ->
7014 if emptystr
!fontpath
7015 then fontpath := Buffer.contents
b;
7016 { v with f = llppconfig
}
7017 | Vclose
_ -> error
"unexpected close in ui-font" s spos
7018 | Vend
-> error
"unexpected end of input in ui-font" s spos
7020 and doc
path pan
anchor c bookmarks
v t spos
_ =
7022 | Vdata
| Vcdata
-> v
7023 | Vend
-> error
"unexpected end of input in doc" s spos
7024 | Vopen
("bookmarks", _, closed
) ->
7027 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
7029 | Vopen
("keymap", attrs
, closed
) ->
7031 try List.assoc
"mode" attrs
7032 with Not_found
-> "global"
7038 let h = findkeyhash c modename in
7039 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7040 doc
path pan
anchor c bookmarks
7042 { v with f = pkeymap
ret KeyMap.empty }
7044 | Vopen
(_, _, _) ->
7045 error
"unexpected subelement in doc" s spos
7048 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7049 { v with f = llppconfig
}
7051 | Vclose
_ -> error
"unexpected close in doc" s spos
7053 and pkeymap
ret keymap
v t spos
_ =
7055 | Vdata
| Vcdata
-> v
7056 | Vend
-> error
"unexpected end of input in keymap" s spos
7057 | Vopen
("map", attrs
, closed
) ->
7058 let r, l = map_of attrs
in
7059 let kss = fromstring keys_of_string spos
"in" r [] in
7060 let lss = fromstring keys_of_string spos
"out" l [] in
7064 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7065 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7068 then { v with f = pkeymap
ret keymap }
7071 { v with f = skip
"map" f }
7074 error
"unexpected subelement in keymap" s spos
7076 | Vclose
"keymap" ->
7077 { v with f = ret keymap }
7079 | Vclose
_ -> error
"unexpected close in keymap" s spos
7081 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7083 | Vdata
| Vcdata
-> v
7084 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7085 | Vopen
("item", attrs
, closed
) ->
7086 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7087 let page = fromstring int_of_string spos
"page" spage
0
7088 and rely = fromstring float_of_string spos
"rely" srely
0.0
7089 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7091 (unent titleent, 0, Oanchor
(page, rely, visy
)) :: bookmarks
7094 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7097 { v with f = skip
"item" f }
7100 error
"unexpected subelement in bookmarks" s spos
7102 | Vclose
"bookmarks" ->
7103 { v with f = doc
path pan
anchor c bookmarks }
7105 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7107 and skip tag
f v t spos
_ =
7109 | Vdata
| Vcdata
-> v
7111 error
("unexpected end of input in skipped " ^ tag
) s spos
7112 | Vopen
(tag'
, _, closed
) ->
7116 let f'
() = { v with f = skip tag
f } in
7117 { v with f = skip tag'
f'
}
7121 else error
("unexpected close in skipped " ^ tag
) s spos
7124 parse
{ f = toplevel; accu = () } s;
7130 let len = in_channel_length ic
in
7131 let s = String.create
len in
7132 really_input ic
s 0 len;
7135 | Parse_error
(msg
, s, pos
) ->
7136 let subs = subs s pos
in
7137 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7140 failwith
("config load error: " ^ exntos exn
)
7146 let dir = Filename.concat
home ".config" in
7147 if Sys.is_directory
dir then dir else home
7150 Filename.concat
dir "llpp.conf"
7153 let confpath = ref defconfpath;;
7156 if Sys.file_exists
!confpath
7159 (try Some
(open_in_bin
!confpath)
7162 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7173 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7182 f (Hashtbl.create
0, defconf)
7187 let pc, pb
, px, pa
=
7190 if emptystr
state.origin
7194 Hashtbl.find h (Filename.basename
key)
7195 with Not_found
-> dc, [], 0, emptyanchor
7199 state.bookmarks <- pb
;
7202 then state.anchor <- pa
;
7203 cbput state.hists
.nav pa
;
7209 let add_attrs bb always
dc c =
7212 then Printf.bprintf bb
"\n %s='%b'" s a
7215 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7218 then Printf.bprintf bb
"\n %s='%d'" s a
7221 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7224 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7227 then Printf.bprintf bb
"\n %s='%f'" s a
7231 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7235 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7239 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7243 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7248 | Some
(_N
, _A
, _B
) ->
7249 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7254 Printf.bprintf bb
"\n %s='none'" s
7264 else string_of_float
f
7266 Printf.bprintf bb
"\n %s='%s'" s v
7271 | Cmulti
((n, a, b), _) when n > 1 ->
7272 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7273 | Csplit
(n, _) when n > 1 ->
7274 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7280 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7285 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7289 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7293 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7295 oi
"width" c.cwinw
dc.cwinw
;
7296 oi
"height" c.cwinh
dc.cwinh
;
7297 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7298 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7299 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7300 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7301 ob "case-insensitive-search" c.icase
dc.icase
;
7302 ob "preload" c.preload dc.preload;
7303 oi
"page-bias" c.pagebias
dc.pagebias
;
7304 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7305 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7306 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7307 ob "crop-hack" c.crophack
dc.crophack
;
7308 oW
"throttle" c.maxwait
dc.maxwait
;
7309 ob "highlight-links" c.hlinks
dc.hlinks
;
7310 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7311 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7312 oz
"zoom" c.zoom dc.zoom;
7313 ob "presentation" c.presentation
dc.presentation
;
7314 oi
"rotation-angle" c.angle
dc.angle
;
7315 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7316 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7317 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7318 oi
"tex-count" c.texcount
dc.texcount
;
7319 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7320 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7321 ob "persistent-location" c.jumpback
dc.jumpback
;
7322 oc
"background-color" c.bgcolor
dc.bgcolor
;
7323 oi
"tile-width" c.tilew
dc.tilew
;
7324 oi
"tile-height" c.tileh
dc.tileh
;
7325 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7326 ob "checkers" c.checkers
dc.checkers
;
7327 oi
"aalevel" c.aalevel
dc.aalevel
;
7328 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7329 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7330 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7331 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7332 oC
"color-space" c.colorspace
dc.colorspace
;
7333 ob "invert-colors" c.invert
dc.invert
;
7334 oF
"brightness" c.colorscale
dc.colorscale
;
7335 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7336 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7337 oco
"columns" c.columns
dc.columns
;
7338 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7339 os
"selection-command" c.selcmd
dc.selcmd
;
7340 os
"synctex-command" c.stcmd
dc.stcmd
;
7341 os
"pax-command" c.paxcmd
dc.paxcmd
;
7342 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7343 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7344 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7345 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7346 ob "use-pbo" c.usepbo
dc.usepbo
;
7347 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7348 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7349 op
"point-and-x" c.pax
dc.pax
;
7350 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7353 let keymapsbuf always
dc c =
7354 let bb = Buffer.create
16 in
7355 let rec loop = function
7357 | (modename, h) :: rest
->
7358 let dh = findkeyhash dc modename in
7359 if always
|| h <> dh
7361 if Hashtbl.length
h > 0
7363 if Buffer.length
bb > 0
7364 then Buffer.add_char
bb '
\n'
;
7365 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7366 Hashtbl.iter
(fun i
o ->
7367 let isdifferent = always
||
7369 let dO = Hashtbl.find dh i
in
7371 with Not_found
-> true
7376 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7377 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7378 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7379 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7380 Buffer.add_string
bb (Wsi.keyname
k);
7383 let rec loop = function
7385 | km
:: [] -> addkm km
7386 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7390 Buffer.add_string
bb "<map in='";
7394 Buffer.add_string
bb "' out='";
7396 Buffer.add_string
bb "'/>\n"
7399 Buffer.add_string
bb "' out='";
7401 Buffer.add_string
bb "'/>\n"
7403 | KMmulti
(ins, kms
) ->
7404 Buffer.add_char
bb ' '
;
7406 Buffer.add_string
bb "' out='";
7408 Buffer.add_string
bb "'/>\n"
7410 Buffer.add_string
bb "</keymap>";
7420 let uifontsize = fstate.fontsize
in
7421 let bb = Buffer.create
32768 in
7422 let relx = float state.x /. float state.winw in
7424 let cx w = truncate
(relx *. float w) in
7426 (fun (w, h, x) ws
->
7428 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7429 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7430 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7432 (state.winw, state.winh
, state.x) state.winstate
7437 let dc = if conf.bedefault
then conf else dc in
7438 Buffer.add_string
bb "<llppconfig>\n";
7440 if nonemptystr
!fontpath
7442 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7448 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7451 Buffer.add_string
bb "<defaults";
7452 add_attrs bb true dc dc;
7453 let kb = keymapsbuf true dc dc in
7454 if Buffer.length
kb > 0
7456 Buffer.add_string
bb ">\n";
7457 Buffer.add_buffer
bb kb;
7458 Buffer.add_string
bb "\n</defaults>\n";
7460 else Buffer.add_string
bb "/>\n";
7462 let adddoc path pan
anchor c bookmarks =
7463 if bookmarks == [] && c = dc && anchor = emptyanchor
7466 Printf.bprintf
bb "<doc path='%s'"
7467 (enent
path 0 (String.length
path));
7469 if anchor <> emptyanchor
7471 let n, rely, visy
= anchor in
7472 Printf.bprintf
bb " page='%d'" n;
7475 Printf.bprintf
bb " rely='%f'" rely
7477 if abs_float visy
> 1e-6
7479 Printf.bprintf
bb " visy='%f'" visy
7484 then Printf.bprintf
bb " pan='%d'" pan
;
7486 add_attrs bb false dc c;
7487 let kb = keymapsbuf false dc c in
7489 begin match bookmarks with
7491 if Buffer.length
kb > 0
7493 Buffer.add_string
bb ">\n";
7494 Buffer.add_buffer
bb kb;
7495 Buffer.add_string
bb "\n</doc>\n";
7497 else Buffer.add_string
bb "/>\n"
7499 Buffer.add_string
bb ">\n<bookmarks>\n";
7500 List.iter
(fun (title, _, kind
) ->
7501 begin match kind
with
7502 | Oanchor
(page, rely, visy
) ->
7504 "<item title='%s' page='%d'"
7505 (enent
title 0 (String.length
title))
7510 Printf.bprintf
bb " rely='%f'" rely
7512 if abs_float visy
> 1e-6
7514 Printf.bprintf
bb " visy='%f'" visy
7516 | Onone
| Ouri
_ | Oremote
_ | Oremotedest
_ | Olaunch
_ ->
7517 failwith
"unexpected link in bookmarks"
7519 Buffer.add_string
bb "/>\n";
7521 Buffer.add_string
bb "</bookmarks>";
7522 if Buffer.length
kb > 0
7524 Buffer.add_string
bb "\n";
7525 Buffer.add_buffer
bb kb;
7527 Buffer.add_string
bb "\n</doc>\n";
7533 match state.mode with
7534 | Birdseye
(c, pan, _, _, _) ->
7536 match conf.columns
with
7537 | Cmulti
((c, _, _), _) -> Some
c
7541 match c.columns
with
7542 | Cmulti
(c, _) -> Cmulti
(c, [||])
7543 | Csingle
_ -> Csingle
[||]
7544 | Csplit
_ -> failwith
"quit from bird's eye while split"
7546 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7549 let basename = Filename.basename
7550 (if emptystr
state.origin
then state.path else state.origin
)
7552 adddoc basename pan (getanchor ())
7554 let autoscrollstep =
7555 match state.autoscroll
with
7557 | None
-> conf.autoscrollstep
7559 match state.mode with
7560 | Birdseye
(bc
, _, _, _, _) ->
7563 presentation
= bc
.presentation
;
7564 interpagespace
= bc
.interpagespace
;
7565 maxwait
= bc
.maxwait
;
7566 autoscrollstep = autoscrollstep }
7567 | _ -> { conf with autoscrollstep = autoscrollstep }
7569 (if conf.savebmarks
then state.bookmarks else []);
7571 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7573 then adddoc path x anchor c bookmarks
7575 Buffer.add_string
bb "</llppconfig>\n";
7578 if load1 f && Buffer.length
bb > 0
7581 let tmp = !confpath ^
".tmp" in
7582 let oc = open_out_bin
tmp in
7583 Buffer.output_buffer
oc bb;
7585 Unix.rename
tmp !confpath;
7588 ("error while saving configuration: " ^ exntos exn
)
7592 let adderrmsg src msg
=
7593 Buffer.add_string
state.errmsgs msg
;
7594 state.newerrmsgs
<- true;
7598 let adderrfmt src fmt
=
7599 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7603 let cl = splitatspace cmds
in
7605 try Scanf.sscanf
s fmt
f
7607 adderrfmt "remote exec"
7608 "error processing '%S': %s\n" cmds
(exntos exn
)
7611 | "reload" :: [] -> reload ()
7612 | "goto" :: args :: [] ->
7613 scan args "%u %f %f"
7615 let cmd, _ = state.geomcmds
in
7617 then gotopagexy pageno x y
7620 gotopagexy pageno x y;
7623 state.reprf
<- f state.reprf
7625 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7626 | "gotor" :: args :: [] ->
7628 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
7629 | "gotord" :: args :: [] ->
7631 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
7632 | "rect" :: args :: [] ->
7633 scan args "%u %u %f %f %f %f"
7634 (fun pageno color x0 y0 x1 y1 ->
7635 onpagerect pageno (fun w h ->
7636 let _,w1,h1
,_ = getpagedim pageno in
7637 let sw = float w1 /. float w
7638 and sh = float h1
/. float h in
7642 and y1s
= y1 *. sh in
7643 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7645 state.rects <- (pageno, color, rect) :: state.rects;
7646 G.postRedisplay "rect";
7649 | "activatewin" :: [] -> Wsi.activatewin
()
7650 | "quit" :: [] -> raise Quit
7652 adderrfmt "remote command"
7653 "error processing remote command: %S\n" cmds
;
7657 let scratch = String.create
80 in
7658 let buf = Buffer.create
80 in
7661 try Some
(Unix.read fd
scratch 0 80)
7663 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7664 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7667 match tempfr () with
7673 if Buffer.length
buf > 0
7675 let s = Buffer.contents
buf in
7685 let pos = String.index_from
scratch ppos '
\n'
in
7686 if pos >= n then -1 else pos
7687 with Not_found
-> -1
7691 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7692 let s = Buffer.contents
buf in
7698 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7704 let remoteopen path =
7705 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7707 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7712 let trimcachepath = ref "" in
7713 let rcmdpath = ref "" in
7714 selfexec := Sys.executable_name
;
7717 [("-p", Arg.String
(fun s -> state.password
<- s),
7718 "<password> Set password");
7722 Config.fontpath := s;
7723 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7725 "<path> Set path to the user interface font");
7729 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7730 Config.confpath := s),
7731 "<path> Set path to the configuration file");
7733 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7734 "<path> Set path to the trim cache file");
7736 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7737 "<named-destination> Set named destination");
7739 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7740 ("-cxack", Arg.Set
cxack, " Cut corners");
7742 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7743 "<path> Set path to the remote commands source");
7745 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7746 "<original-path> Set original path");
7748 ("-v", Arg.Unit
(fun () ->
7750 "%s\nconfiguration path: %s\n"
7754 exit
0), " Print version and exit");
7757 (fun s -> state.path <- s)
7758 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7761 then selfexec := !selfexec ^
" -wtmode";
7763 if emptystr
state.path
7764 then (prerr_endline
"file name missing"; exit
1);
7766 if not
(Config.load ())
7767 then prerr_endline
"failed to load configuration";
7769 let wsfd, winw, winh
= Wsi.init
(object
7770 val mutable m_hack
= false
7771 method expose
= if not m_hack
then G.postRedisplay "expose"
7772 method visible
= G.postRedisplay "visible"
7773 method display = m_hack
<- false; display ()
7774 method reshape w h =
7775 m_hack
<- w < state.winw && h < state.winh
;
7777 method mouse
b d x y m = state.uioh <- state.uioh#button
b d x y m
7779 state.mpos
<- (x, y);
7780 state.uioh <- state.uioh#motion
x y
7781 method pmotion
x y =
7782 state.mpos
<- (x, y);
7783 state.uioh <- state.uioh#pmotion
x y
7785 let mascm = m land (
7786 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7788 match state.keystate
with
7790 let km = k, mascm in
7793 let modehash = state.uioh#
modehash in
7794 try Hashtbl.find modehash km
7796 try Hashtbl.find (findkeyhash conf "global") km
7797 with Not_found
-> KMinsrt
(k, m)
7799 | KMinsrt
(k, m) -> keyboard k m
7800 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7801 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7803 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7804 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7805 state.keystate
<- KSnone
7806 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7807 state.keystate
<- KSinto
(keys
, insrt
)
7809 state.keystate
<- KSnone
7812 state.mpos
<- (x, y);
7813 state.uioh <- state.uioh#pmotion
x y
7814 method leave = state.mpos
<- (-1, -1)
7815 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7816 method quit
= raise Quit
7817 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7822 List.exists
GlMisc.check_extension
7823 [ "GL_ARB_texture_rectangle"
7824 ; "GL_EXT_texture_recangle"
7825 ; "GL_NV_texture_rectangle" ]
7827 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7830 let r = GlMisc.get_string `renderer
in
7831 let p = "Mesa DRI Intel(" in
7832 let l = String.length
p in
7833 String.length
r > l && String.sub
r 0 l = p
7836 defconf.sliceheight
<- 1024;
7837 defconf.texcount
<- 32;
7838 defconf.usepbo
<- true;
7842 match Ne.pipe () with
7844 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7848 match Ne.pipe () with
7850 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7860 setcheckers conf.checkers
;
7862 if conf.redirectstderr
7865 let s = Buffer.contents
state.errmsgs ^
7866 (match state.errfd
with
7868 let s = String.create
(80*24) in
7871 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7873 then Unix.read fd
s 0 (String.length
s)
7879 else String.sub
s 0 n
7883 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7884 with exn
-> print_endline
(exntos exn
)
7889 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7890 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7891 !Config.fontpath, !trimcachepath,
7892 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7894 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
7897 state.text <- "Opening " ^
(mbtoutf8
state.path);
7899 opendoc state.path state.password
;
7903 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7906 if nonemptystr
!rcmdpath
7907 then remoteopen !rcmdpath
7912 let rec loop deadline
=
7914 match state.errfd
with
7915 | None
-> [state.sr
; state.wsfd]
7916 | Some fd
-> [state.sr
; state.wsfd; fd
]
7921 | Some fd
-> fd
:: r
7925 state.redisplay
<- false;
7932 if deadline
= infinity
7934 else max
0.0 (deadline
-. now)
7939 try Unix.select
r [] [] timeout
7940 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7946 if state.ghyll
== noghyll
7948 match state.autoscroll
with
7949 | Some step
when step
!= 0 ->
7950 let y = state.y + step
in
7954 else if y >= state.maxy then 0 else y
7957 if state.mode = View
7958 then state.text <- "";
7961 else deadline
+. 0.01
7966 let rec checkfds = function
7968 | fd
:: rest
when fd
= state.sr
->
7969 let cmd = readcmd state.sr
in
7973 | fd
:: rest
when fd
= state.wsfd ->
7977 | fd
:: rest
when Some fd
= !optrfd ->
7978 begin match remote fd
with
7979 | None
-> optrfd := remoteopen !rcmdpath;
7980 | opt -> optrfd := opt
7985 let s = String.create
80 in
7986 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7987 if conf.redirectstderr
7989 Buffer.add_substring
state.errmsgs
s 0 n;
7990 state.newerrmsgs
<- true;
7991 state.redisplay
<- true;
7994 prerr_string
(String.sub
s 0 n);
8002 if deadline
= infinity
8006 match state.autoscroll
with
8007 | Some step
when step
!= 0 -> deadline1
8008 | _ -> if state.ghyll
== noghyll then infinity
else deadline1