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
1653 GlFunc.blend_func `zero `one_minus_src_color
;
1655 begin match state.texid
with
1657 Gl.enable `texture_2d
;
1658 GlTex.bind_texture `texture_2d id
;
1661 and x1 = float (x+w)
1662 and y1 = float (y+h
) in
1664 let tw = float w /. 16.0
1665 and th
= float h
/. 16.0 in
1666 let tx0 = float tilex /. 16.0
1667 and ty0
= float tiley /. 16.0 in
1669 and ty1
= ty0
+. th
in
1670 Raw.sets_float
state.vraw ~pos
:0
1671 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1672 Raw.sets_float
state.traw ~pos
:0
1673 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1674 GlArray.vertex `two
state.vraw
;
1675 GlArray.tex_coord `two
state.traw
;
1676 GlArray.draw_arrays `triangle_strip
0 4;
1679 GlDraw.color
(1.0, 1.0, 1.0);
1680 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1682 if w > 128 && h
> fstate.fontsize
+ 10
1684 let c = if conf.invert
then 1.0 else 0.0 in
1685 GlDraw.color
(c, c, c);
1688 then (col*conf.tilew
, row*conf.tileh
)
1691 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1700 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1702 let tilevisible1 l x y =
1704 and ax1
= l.pagex
+ l.pagevw
1706 and ay1
= l.pagey + l.pagevh in
1710 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1711 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1713 let rx0 = max
ax0 bx0
1714 and ry0
= max ay0 by0
1715 and rx1
= min ax1
bx1
1716 and ry1
= min ay1 by1
in
1718 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1719 nonemptyintersection
1722 let tilevisible layout n x y =
1723 let rec findpageinlayout m
= function
1724 | l :: rest
when l.pageno = n ->
1725 tilevisible1 l x y || (
1726 match conf.columns
with
1727 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1730 | _ :: rest
-> findpageinlayout 0 rest
1733 findpageinlayout 0 layout;
1736 let tileready l x y =
1737 tilevisible1 l x y &&
1738 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1741 let tilepage n p
layout =
1742 let rec loop = function
1746 let f col row _ _ _ _ _ _ =
1747 if state.currently
= Idle
1749 match gettileopaque l col row with
1752 let x = col*conf.tilew
1753 and y = row*conf.tileh
in
1755 let w = l.pagew
- x in
1759 let h = l.pageh
- y in
1764 then getpbo
w h conf.colorspace
1767 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1770 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1771 conf.tilew
, conf.tileh
1780 if nogeomcmds state.geomcmds
1784 let preloadlayout y =
1785 let y = if y < state.winh
then 0 else y - state.winh
in
1786 let h = state.winh
*3 in
1791 let rec loop pages
=
1792 if state.currently
!= Idle
1797 begin match getopaque l.pageno with
1799 wcmd "page %d %d" l.pageno l.pagedimno
;
1800 state.currently
<- Loading
(l, state.gen
);
1802 tilepage l.pageno opaque pages
;
1807 if nogeomcmds state.geomcmds
1813 if conf.preload && state.currently
= Idle
1814 then load (preloadlayout state.y);
1817 let layoutready layout =
1818 let rec fold all ls
=
1819 all
&& match ls
with
1821 let seen = ref false in
1822 let allvisible = ref true in
1823 let foo col row _ _ _ _ _ _ =
1825 allvisible := !allvisible &&
1826 begin match gettileopaque l col row with
1832 fold (!seen && !allvisible) rest
1835 let alltilesvisible = fold true layout in
1840 let y = bound y 0 state.maxy
in
1841 let y, layout, proceed
=
1842 match conf.maxwait
with
1843 | Some time
when state.ghyll
== noghyll ->
1844 begin match state.throttle
with
1846 let layout = layout y state.winh
in
1847 let ready = layoutready layout in
1851 state.throttle
<- Some
(layout, y, now ());
1853 else G.postRedisplay "gotoy showall (None)";
1855 | Some
(_, _, started
) ->
1856 let dt = now () -. started
in
1859 state.throttle
<- None
;
1860 let layout = layout y state.winh
in
1862 G.postRedisplay "maxwait";
1869 let layout = layout y state.winh
in
1870 if not
!wtmode || layoutready layout
1871 then G.postRedisplay "gotoy ready";
1877 state.layout <- layout;
1878 begin match state.mode
with
1879 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1880 let rec loop = function
1882 state.mode
<- LinkNav
(Ltgendir
0)
1883 | l :: _ when l.pageno = pageno ->
1884 begin match getopaque pageno with
1886 state.mode
<- LinkNav
(Ltgendir
0)
1888 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1889 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1890 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1891 then state.mode
<- LinkNav
(Ltgendir
0)
1893 | _ :: rest
-> loop rest
1898 begin match state.mode
with
1899 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1900 if not
(pagevisible layout pageno)
1902 match state.layout with
1905 state.mode
<- Birdseye
(
1906 conf, leftx
, l.pageno, hooverpageno
, anchor
1909 | LinkNav
(Ltgendir dir
as lt
) ->
1911 let rec loop = function
1914 match getopaque l.pageno with
1920 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1922 if dir
> 0 then LDfirst
else LDlast
1928 | Lnotfound
-> loop rest
1930 showlinktype (getlink opaque
n);
1931 Ltexact
(l.pageno, n)
1935 state.mode
<- LinkNav
linknav
1940 state.ghyll
<- noghyll;
1943 let mx, my
= state.mpos
in
1948 let conttiling pageno opaque
=
1949 tilepage pageno opaque
1950 (if conf.preload then preloadlayout state.y else state.layout)
1953 let gotoy_and_clear_text y =
1954 if not
conf.verbose
then state.text <- "";
1960 let coloff = l.pagecol
* l.pageh
in
1961 float (l.pagey + coloff) /. float l.pageh
1968 if conf.presentation
1969 then float l.pagedispy /. float (calcips l.pageh
)
1970 else float l.pagedispy /. float conf.interpagespace
1973 (l.pageno, top, dtop)
1977 match state.layout with
1978 | l :: _ -> getanchor1 l
1980 let n = page_of_y state.y in
1984 let y, h = getpageyh n in
1985 let dy = y - state.y in
1987 if conf.presentation
1989 let ips = calcips h in
1990 float (dy + ips) /. float ips
1992 float dy /. float conf.interpagespace
1997 let getanchory (n, top, dtop) =
1998 let y, h = getpageyh n in
1999 if conf.presentation
2001 let ips = calcips h in
2002 y + truncate
(top*.float h -. dtop*.float ips) + ips;
2004 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
2007 let gotoanchor anchor
=
2008 gotoy (getanchory anchor
);
2012 cbput state.hists
.nav
(getanchor ());
2016 let anchor = cbgetc state.hists
.nav dir
in
2021 let scroll f n a
b =
2022 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2024 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2026 then s (float f /. float a
)
2029 then 1.0 -. s ((float (f-b) /. float (n-b)))
2035 let ins = float a
*. 0.5
2036 and outs
= float (n-b) *. 0.5 in
2038 ins +. outs
+. float ones
2040 let rec set (_N
, _A
, _B
) y sy
=
2041 let sum = summa _N _A _B
in
2042 let dy = float (y - sy
) in
2046 then state.ghyll
<- noghyll
2049 let s = scroll n _N _A _B
in
2050 let y1 = y1 +. ((s *. dy) /. sum) in
2051 gotoy_and_clear_text (truncate
y1);
2052 state.ghyll
<- gf (n+1) y1;
2056 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2058 gf 0 (float state.y)
2061 match conf.ghyllscroll
with
2063 gotoy_and_clear_text y
2065 if state.ghyll
== noghyll
2066 then set nab
y state.y
2067 else state.ghyll
(Some
y)
2070 let gotopage n top =
2071 let y, h = getpageyh n in
2072 let y = y + (truncate
(top *. float h)) in
2076 let gotopage1 n top =
2077 let y = getpagey n in
2082 let invalidate s f =
2087 match state.geomcmds
with
2088 | ps
, [] when emptystr ps
->
2090 state.geomcmds
<- s, [];
2093 state.geomcmds
<- ps
, [s, f];
2095 | ps
, (s'
, _) :: rest
when s'
= s ->
2096 state.geomcmds
<- ps
, ((s, f) :: rest
);
2099 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2103 Hashtbl.iter
(fun _ opaque
->
2104 wcmd "freepage %s" opaque
;
2106 Hashtbl.clear
state.pagemap
;
2110 if not
(Queue.is_empty
state.tilelru
)
2112 Queue.iter
(fun (k
, p
, s) ->
2113 wcmd "freetile %s" p
;
2114 state.memused
<- state.memused
- s;
2115 Hashtbl.remove
state.tilemap k
;
2117 state.uioh#infochanged Memused
;
2118 Queue.clear
state.tilelru
;
2124 let h = truncate
(float h*.conf.zoom
) in
2125 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2129 let opendoc path password
=
2131 state.password
<- password
;
2132 state.gen
<- state.gen
+ 1;
2133 state.docinfo
<- [];
2136 setaalevel
conf.aalevel
;
2138 if emptystr
state.origin
2142 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2143 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2144 invalidate "reqlayout"
2146 wcmd "reqlayout %d %d %d %s\000"
2147 conf.angle
(FMTE.to_int conf.fitmodel
)
2148 (stateh state.winh
) state.nameddest
2153 state.anchor <- getanchor ();
2154 opendoc state.path
state.password
;
2158 let c = c *. conf.colorscale
in
2162 let scalecolor2 (r
, g, b) =
2163 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2166 let docolumns = function
2168 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2169 let rec loop pageno pdimno pdim
y ph pdims
=
2170 if pageno = state.pagecount
2173 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2175 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2176 pdimno+1, pdim
, rest
2180 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2182 (if conf.presentation
2183 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2184 else (if pageno = 0 then 0 else conf.interpagespace
)
2187 a.(pageno) <- (pdimno, x, y, pdim
);
2188 loop (pageno+1) pdimno pdim
(y + h) h pdims
2190 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2191 conf.columns
<- Csingle
a;
2193 | Cmulti
((columns
, coverA
, coverB
), _) ->
2194 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2195 let rec loop pageno pdimno pdim
x y rowh pdims
=
2196 let rec fixrow m
= if m
= pageno then () else
2197 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2200 let y = y + (rowh
- h) / 2 in
2201 a.(m
) <- (pdimno, x, y, pdim
);
2205 if pageno = state.pagecount
2206 then fixrow (((pageno - 1) / columns
) * columns
)
2208 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2210 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2211 pdimno+1, pdim
, rest
2216 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2218 let x = (wadjsb state.winw
- w) / 2 in
2220 if conf.presentation
then calcips h else conf.interpagespace
in
2221 x, y + ips + rowh
, h
2224 if (pageno - coverA
) mod columns
= 0
2226 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2228 if conf.presentation
2230 let ips = calcips h in
2231 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2233 y + (if pageno = 0 then 0 else conf.interpagespace
)
2237 else x, y, max rowh
h
2241 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2244 if pageno = columns
&& conf.presentation
2246 let ips = calcips rowh
in
2247 for i
= 0 to pred columns
2249 let (pdimno, x, y, pdim
) = a.(i
) in
2250 a.(i
) <- (pdimno, x, y+ips, pdim
)
2256 fixrow (pageno - columns
);
2261 a.(pageno) <- (pdimno, x, y, pdim
);
2262 let x = x + w + xoff
*2 + conf.interpagespace
in
2263 loop (pageno+1) pdimno pdim
x y rowh' pdims
2265 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2266 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2269 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2270 let rec loop pageno pdimno pdim
y pdims
=
2271 if pageno = state.pagecount
2274 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2276 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2277 pdimno+1, pdim
, rest
2282 let rec loop1 n x y =
2283 if n = c then y else (
2284 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2285 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2288 let y = loop1 0 0 y in
2289 loop (pageno+1) pdimno pdim
y pdims
2291 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2292 conf.columns
<- Csplit
(c, a);
2296 docolumns conf.columns
;
2297 state.maxy
<- calcheight ();
2298 if state.reprf
== noreprf
2300 match state.mode
with
2301 | Birdseye
(_, _, pageno, _, _) ->
2302 let y, h = getpageyh pageno in
2303 let top = (state.winh
- h) / 2 in
2304 gotoy (max
0 (y - top))
2305 | _ -> gotoanchor state.anchor
2309 state.reprf
<- noreprf;
2314 GlDraw.viewport
0 0 w h;
2315 let firsttime = state.geomcmds
== firstgeomcmds in
2316 if not
firsttime && nogeomcmds state.geomcmds
2317 then state.anchor <- getanchor ();
2320 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2323 setfontsize fstate.fontsize
;
2324 GlMat.mode `modelview
;
2325 GlMat.load_identity
();
2327 GlMat.mode `projection
;
2328 GlMat.load_identity
();
2329 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2330 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2331 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2336 else float state.x /. float state.w
2338 invalidate "geometry"
2342 then state.x <- truncate
(relx *. float w);
2344 match conf.columns
with
2346 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2347 | Csplit
(c, _) -> w * c
2349 wcmd "geometry %d %d %d"
2350 w (stateh h) (FMTE.to_int conf.fitmodel
)
2355 let len = String.length
state.text in
2358 match state.mode
with
2359 | Textentry
_ | View
| LinkNav
_ ->
2360 let h, _, _ = state.uioh#scrollpw
in
2365 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2366 (x+.w) (float (state.winh
- hscrollh))
2369 let w = float (wadjsb state.winw
- 1) in
2370 if state.progress
>= 0.0 && state.progress
< 1.0
2372 GlDraw.color
(0.3, 0.3, 0.3);
2373 let w1 = w *. state.progress
in
2375 GlDraw.color
(0.0, 0.0, 0.0);
2379 GlDraw.color
(0.0, 0.0, 0.0);
2383 GlDraw.color
(1.0, 1.0, 1.0);
2384 drawstring fstate.fontsize
2385 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2388 match state.mode
with
2389 | Textentry
((prefix
, text, _, _, _, _), _) ->
2393 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2395 Printf.sprintf
"%s%s_" prefix
text
2404 if not
(istextentry state.mode
) && state.uioh#eformsgs
2406 let s1 = "(press 'e' to review error messasges)" in
2407 if nonemptystr
s then s ^
" " ^
s1 else s1
2417 let len = Queue.length
state.tilelru
in
2419 match state.throttle
with
2422 then preloadlayout state.y
2424 | Some
(layout, _, _) ->
2428 if state.memused
<= conf.memlimit
2433 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2434 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2435 let (_, pw, ph
, _) = getpagedim n in
2438 && colorspace
= conf.colorspace
2439 && angle
= conf.angle
2443 let x = col*conf.tilew
2444 and y = row*conf.tileh
in
2445 tilevisible (Lazy.force_val
layout) n x y
2447 then Queue.push lruitem
state.tilelru
2450 wcmd "freetile %s" p
;
2451 state.memused
<- state.memused
- s;
2452 state.uioh#infochanged Memused
;
2453 Hashtbl.remove
state.tilemap k
;
2461 let logcurrently = function
2462 | Idle
-> dolog
"Idle"
2463 | Loading
(l, gen
) ->
2464 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2465 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2467 "Tiling %d[%d,%d] page=%s cs=%s angle"
2468 l.pageno col row pageopaque
2469 (CSTE.to_string colorspace
)
2471 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2472 angle gen
conf.angle
state.gen
2474 conf.tilew
conf.tileh
2481 let r = Str.regexp
" " in
2482 fun s -> Str.bounded_split
r s 2;
2485 let onpagerect pageno f =
2487 match conf.columns
with
2488 | Cmulti
(_, b) -> b
2490 | Csplit
(_, b) -> b
2492 if pageno >= 0 && pageno < Array.length
b
2494 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2498 let gotopagexy1 pageno x y =
2499 let _,w1,h1
,leftx
= getpagedim pageno in
2500 let top = y /. (float h1
) in
2501 let left = x /. (float w1) in
2502 let py, w, h = getpageywh pageno in
2503 let wh = state.winh
- hscrollh () in
2504 let x = left *. (float w) in
2505 let x = leftx
+ state.x + truncate
x in
2507 if x < 0 || x >= wadjsb state.winw
2511 let pdy = truncate
(top *. float h) in
2512 let y'
= py + pdy in
2513 let dy = y'
- state.y in
2515 if x != state.x || not
(dy > 0 && dy < wh)
2517 if conf.presentation
2519 if abs
(py - y'
) > wh
2526 if state.x != sx || state.y != sy
2531 let ww = wadjsb state.winw
in
2533 and qy
= pdy / wh in
2535 and y = py + qy
* wh in
2536 let x = if -x + ww > w1 then -(w1-ww) else x
2537 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2539 if conf.presentation
2541 if abs
(py - y'
) > wh
2551 gotoy_and_clear_text y;
2553 else gotoy_and_clear_text state.y;
2556 let gotopagexy pageno x y =
2557 match state.mode
with
2558 | Birdseye
_ -> gotopage pageno 0.0
2559 | _ -> gotopagexy1 pageno x y
2563 (* dolog "%S" cmds; *)
2564 let cl = splitatspace cmds
in
2566 try Scanf.sscanf
s fmt
f
2568 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2571 let addoutline outline
=
2572 match state.currently
with
2573 | Outlining outlines
->
2574 state.currently
<- Outlining
(outline
:: outlines
)
2575 | Idle
-> state.currently
<- Outlining
[outline
]
2577 dolog
"invalid outlining state";
2578 logcurrently currently
2582 state.uioh#infochanged Pdim
;
2585 | "clearrects" :: [] ->
2586 state.rects
<- state.rects1
;
2587 G.postRedisplay "clearrects";
2589 | "continue" :: args :: [] ->
2590 let n = scan args "%u" (fun n -> n) in
2591 state.pagecount
<- n;
2592 begin match state.currently
with
2594 state.currently
<- Idle
;
2595 state.outlines
<- Array.of_list
(List.rev
l)
2599 let cur, cmds
= state.geomcmds
in
2601 then failwith
"umpossible";
2603 begin match List.rev cmds
with
2605 state.geomcmds
<- "", [];
2609 state.geomcmds
<- s, List.rev rest
;
2611 if conf.maxwait
= None
&& not
!wtmode
2612 then G.postRedisplay "continue";
2614 | "title" :: args :: [] ->
2617 | "msg" :: args :: [] ->
2620 | "vmsg" :: args :: [] ->
2622 then showtext ' '
args
2624 | "emsg" :: args :: [] ->
2625 Buffer.add_string
state.errmsgs
args;
2626 state.newerrmsgs
<- true;
2627 G.postRedisplay "error message"
2629 | "progress" :: args :: [] ->
2630 let progress, text =
2633 f, String.sub
args pos
(String.length
args - pos
))
2636 state.progress <- progress;
2637 G.postRedisplay "progress"
2639 | "firstmatch" :: args :: [] ->
2640 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2641 scan args "%u %d %f %f %f %f %f %f %f %f"
2642 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2643 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2645 let y = (getpagey pageno) + truncate
y0 in
2648 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2650 | "match" :: args :: [] ->
2651 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2652 scan args "%u %d %f %f %f %f %f %f %f %f"
2653 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2654 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2657 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2659 | "page" :: args :: [] ->
2660 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2661 begin match state.currently
with
2662 | Loading
(l, gen
) ->
2663 vlog "page %d took %f sec" l.pageno t
;
2664 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2665 begin match state.throttle
with
2667 let preloadedpages =
2669 then preloadlayout state.y
2674 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2675 IntSet.empty
preloadedpages
2678 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2679 if not
(IntSet.mem
pageno set)
2681 wcmd "freepage %s" opaque
;
2687 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2690 state.currently
<- Idle
;
2693 tilepage l.pageno pageopaque state.layout;
2695 load preloadedpages;
2696 if pagevisible state.layout l.pageno
2697 && layoutready state.layout
2698 then G.postRedisplay "page";
2701 | Some
(layout, _, _) ->
2702 state.currently
<- Idle
;
2703 tilepage l.pageno pageopaque layout;
2708 dolog
"Inconsistent loading state";
2709 logcurrently state.currently
;
2713 | "tile" :: args :: [] ->
2714 let (x, y, opaque
, size
, t
) =
2715 scan args "%u %u %s %u %f"
2716 (fun x y p size t
-> (x, y, p
, size
, t
))
2718 begin match state.currently
with
2719 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2720 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2723 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2725 wcmd "freetile %s" opaque
;
2726 state.currently
<- Idle
;
2730 puttileopaque l col row gen cs angle opaque size t
;
2731 state.memused
<- state.memused
+ size
;
2732 state.uioh#infochanged Memused
;
2734 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2735 opaque
, size
) state.tilelru
;
2738 match state.throttle
with
2739 | None
-> state.layout
2740 | Some
(layout, _, _) -> layout
2743 state.currently
<- Idle
;
2745 && conf.colorspace
= cs
2746 && conf.angle
= angle
2747 && tilevisible layout l.pageno x y
2748 then conttiling l.pageno pageopaque;
2750 begin match state.throttle
with
2752 preload state.layout;
2754 && conf.colorspace
= cs
2755 && conf.angle
= angle
2756 && tilevisible state.layout l.pageno x y
2757 && (not
!wtmode || layoutready state.layout)
2758 then G.postRedisplay "tile nothrottle";
2760 | Some
(layout, y, _) ->
2761 let ready = layoutready layout in
2765 state.layout <- layout;
2766 state.throttle
<- None
;
2767 G.postRedisplay "throttle";
2774 dolog
"Inconsistent tiling state";
2775 logcurrently state.currently
;
2779 | "pdim" :: args :: [] ->
2780 let (n, w, h, _) as pdim
=
2781 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2784 match conf.fitmodel
, conf.columns
with
2785 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2788 state.uioh#infochanged Pdim
;
2789 state.pdims
<- pdim :: state.pdims
2791 | "o" :: args :: [] ->
2792 let (l, n, t
, h, pos
) =
2793 scan args "%u %u %d %u %n"
2794 (fun l n t
h pos
-> l, n, t
, h, pos
)
2796 let s = String.sub
args pos
(String.length
args - pos
) in
2797 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
2799 | "ou" :: args :: [] ->
2800 let (l, len, pos
) = scan args "%u %u %n" (fun l len pos
-> l, len, pos
) in
2801 let s = String.sub
args pos
len in
2802 let pos2 = pos
+ len + 1 in
2803 let uri = String.sub
args pos2 (String.length
args - pos2) in
2804 addoutline (s, l, Ouri
uri)
2806 | "on" :: args :: [] ->
2807 let (l, pos
) = scan args "%u %n" (fun l pos
-> l, pos
) in
2808 let s = String.sub
args pos
(String.length
args - pos
) in
2809 addoutline (s, l, Onone
)
2811 | "a" :: args :: [] ->
2813 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2815 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2817 | "info" :: args :: [] ->
2818 state.docinfo
<- (1, args) :: state.docinfo
2820 | "infoend" :: [] ->
2821 state.uioh#infochanged Docinfo
;
2822 state.docinfo
<- List.rev
state.docinfo
2825 error
"unknown cmd `%S'" cmds
2830 let action = function
2831 | HCprev
-> cbget cb ~
-1
2832 | HCnext
-> cbget cb
1
2833 | HCfirst
-> cbget cb ~
-(cb
.rc)
2834 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2835 and cancel
() = cb
.rc <- rc
2839 let search pattern forward
=
2840 match conf.columns
with
2842 showtext '
!'
"searching does not work properly in split columns mode"
2844 if nonemptystr pattern
2847 match state.layout with
2850 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2852 wcmd "search %d %d %d %d,%s\000"
2853 (btod conf.icase
) pn py (btod forward
) pattern
;
2856 let intentry text key =
2858 if key >= 32 && key < 127
2864 let text = addchar text c in
2868 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2872 let linknentry text key =
2874 if key >= 32 && key < 127
2880 let text = addchar text c in
2884 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2892 let l = String.length
s in
2893 let rec loop pos
n = if pos
= l then n else
2894 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2895 loop (pos
+1) (n*26 + m)
2898 let rec loop n = function
2901 match getopaque l.pageno with
2902 | None
-> loop n rest
2904 let m = getlinkcount opaque
in
2907 let under = getlink opaque
n in
2910 else loop (n-m) rest
2912 loop n state.layout;
2916 let textentry text key =
2917 if key land 0xff00 = 0xff00
2919 else TEcont
(text ^ toutf8
key)
2922 let reqlayout angle fitmodel
=
2923 match state.throttle
with
2925 if nogeomcmds state.geomcmds
2926 then state.anchor <- getanchor ();
2927 conf.angle
<- angle
mod 360;
2930 match state.mode
with
2931 | LinkNav
_ -> state.mode
<- View
2934 conf.fitmodel
<- fitmodel
;
2935 invalidate "reqlayout"
2937 wcmd "reqlayout %d %d %d"
2938 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2943 let settrim trimmargins trimfuzz
=
2944 if nogeomcmds state.geomcmds
2945 then state.anchor <- getanchor ();
2946 conf.trimmargins
<- trimmargins
;
2947 conf.trimfuzz
<- trimfuzz
;
2948 let x0, y0, x1, y1 = trimfuzz
in
2949 invalidate "settrim"
2951 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2956 match state.throttle
with
2958 let zoom = max
0.0001 zoom in
2959 if zoom <> conf.zoom
2961 state.prevzoom
<- (conf.zoom, state.x);
2963 reshape state.winw
state.winh
;
2964 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2967 | Some
(layout, y, started
) ->
2969 match conf.maxwait
with
2973 let dt = now () -. started
in
2981 let setcolumns mode columns coverA coverB
=
2982 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2986 then showtext '
!'
"split mode doesn't work in bird's eye"
2988 conf.columns
<- Csplit
(-columns
, [||]);
2996 conf.columns
<- Csingle
[||];
3001 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
3005 reshape state.winw
state.winh
;
3008 let enterbirdseye () =
3009 let zoom = float conf.thumbw
/. float state.winw
in
3010 let birdseyepageno =
3011 let cy = state.winh
/ 2 in
3015 let rec fold best
= function
3018 let d = cy - (l.pagedispy + l.pagevh/2)
3019 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
3020 if abs
d < abs dbest
3027 state.mode
<- Birdseye
(
3028 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
3031 conf.presentation
<- false;
3032 conf.interpagespace
<- 10;
3033 conf.hlinks
<- false;
3034 conf.fitmodel
<- FitProportional
;
3036 state.mstate
<- Mnone
;
3037 conf.maxwait
<- None
;
3039 match conf.beyecolumns
with
3042 Cmulti
((c, 0, 0), [||])
3043 | None
-> Csingle
[||]
3045 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3048 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3053 reshape state.winw
state.winh
;
3056 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3058 conf.zoom <- c.zoom;
3059 conf.presentation
<- c.presentation
;
3060 conf.interpagespace
<- c.interpagespace
;
3061 conf.maxwait
<- c.maxwait
;
3062 conf.hlinks
<- c.hlinks
;
3063 conf.fitmodel
<- c.fitmodel
;
3064 conf.beyecolumns
<- (
3065 match conf.columns
with
3066 | Cmulti
((c, _, _), _) -> Some
c
3068 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3071 match c.columns
with
3072 | Cmulti
(c, _) -> Cmulti
(c, [||])
3073 | Csingle
_ -> Csingle
[||]
3074 | Csplit
(c, _) -> Csplit
(c, [||])
3078 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3081 reshape state.winw
state.winh
;
3082 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3086 let togglebirdseye () =
3087 match state.mode
with
3088 | Birdseye vals
-> leavebirdseye vals
true
3089 | View
-> enterbirdseye ()
3093 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3094 let pageno = max
0 (pageno - incr
) in
3095 let rec loop = function
3096 | [] -> gotopage1 pageno 0
3097 | l :: _ when l.pageno = pageno ->
3098 if l.pagedispy >= 0 && l.pagey = 0
3099 then G.postRedisplay "upbirdseye"
3100 else gotopage1 pageno 0
3101 | _ :: rest
-> loop rest
3104 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3107 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3108 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3109 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3110 let rec loop = function
3112 let y, h = getpageyh pageno in
3113 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3115 | l :: _ when l.pageno = pageno ->
3116 if l.pagevh != l.pageh
3117 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3118 else G.postRedisplay "downbirdseye"
3119 | _ :: rest
-> loop rest
3124 let boundastep h step
=
3126 then bound step ~
-h 0
3130 let optentry mode
_ key =
3131 let btos b = if b then "on" else "off" in
3132 if key >= 32 && key < 127
3134 let c = Char.chr
key in
3138 try conf.scrollstep
<- int_of_string
s with exc
->
3139 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3141 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3146 conf.autoscrollstep
<- boundastep state.winh
(int_of_string
s);
3147 if state.autoscroll
<> None
3148 then state.autoscroll
<- Some
conf.autoscrollstep
3150 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3152 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3157 let n, a, b = multicolumns_of_string s in
3158 setcolumns mode
n a b;
3160 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3162 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3167 let zoom = float (int_of_string
s) /. 100.0 in
3170 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3172 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3177 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3179 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3180 begin match mode
with
3182 leavebirdseye beye
false;
3187 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3189 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3194 Some
(int_of_string
s)
3196 state.text <- Printf.sprintf
"bad integer `%s': %s"
3200 | Some angle
-> reqlayout angle
conf.fitmodel
3203 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3206 conf.icase
<- not
conf.icase
;
3207 TEdone
("case insensitive search " ^
(btos conf.icase
))
3210 conf.preload <- not
conf.preload;
3212 TEdone
("preload " ^
(btos conf.preload))
3215 conf.verbose
<- not
conf.verbose
;
3216 TEdone
("verbose " ^
(btos conf.verbose
))
3219 conf.debug
<- not
conf.debug
;
3220 TEdone
("debug " ^
(btos conf.debug
))
3223 conf.maxhfit
<- not
conf.maxhfit
;
3224 state.maxy
<- calcheight ();
3225 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3228 conf.crophack
<- not
conf.crophack
;
3229 TEdone
("crophack " ^
btos conf.crophack
)
3233 match conf.maxwait
with
3235 conf.maxwait
<- Some infinity
;
3236 "always wait for page to complete"
3238 conf.maxwait
<- None
;
3239 "show placeholder if page is not ready"
3244 conf.underinfo
<- not
conf.underinfo
;
3245 TEdone
("underinfo " ^
btos conf.underinfo
)
3248 conf.savebmarks
<- not
conf.savebmarks
;
3249 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3255 match state.layout with
3260 conf.interpagespace
<- int_of_string
s;
3261 docolumns conf.columns
;
3262 state.maxy
<- calcheight ();
3263 let y = getpagey pageno in
3266 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3268 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3272 match conf.fitmodel
with
3273 | FitProportional
-> FitWidth
3274 | _ -> FitProportional
3276 reqlayout conf.angle
fm;
3277 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3280 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3281 TEdone
("trim margins " ^
btos conf.trimmargins
)
3284 conf.invert
<- not
conf.invert
;
3285 TEdone
("invert colors " ^
btos conf.invert
)
3289 cbput state.hists
.sel
s;
3292 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3293 textentry, ondone, true)
3297 then conf.pax
<- Some
(ref (0.0, 0, 0))
3298 else conf.pax
<- None
;
3299 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3302 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3308 class type lvsource
= object
3309 method getitemcount
: int
3310 method getitem
: int -> (string * int)
3311 method hasaction
: int -> bool
3320 method getactive
: int
3321 method getfirst
: int
3322 method getqsearch
: string
3323 method setqsearch
: string -> unit
3327 class virtual lvsourcebase
= object
3328 val mutable m_active
= 0
3329 val mutable m_first
= 0
3330 val mutable m_qsearch
= ""
3331 val mutable m_pan
= 0
3332 method getactive
= m_active
3333 method getfirst
= m_first
3334 method getqsearch
= m_qsearch
3335 method getpan
= m_pan
3336 method setqsearch
s = m_qsearch
<- s
3339 let withoutlastutf8 s =
3340 let len = String.length
s in
3348 let b = Char.code
s.[pos
] in
3349 if b land 0b11000000 = 0b11000000
3354 if Char.code
s.[len-1] land 0x80 = 0
3358 String.sub
s 0 first;
3361 let textentrykeyboard
3362 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3364 if key >= 0xffb0 && key <= 0xffb9
3365 then key - 0xffb0 + 48 else key
3368 state.mode
<- Textentry
(te
, onleave
);
3371 G.postRedisplay "textentrykeyboard enttext";
3373 let histaction cmd
=
3376 | Some
(action, _) ->
3377 state.mode
<- Textentry
(
3378 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3380 G.postRedisplay "textentry histaction"
3383 | 0xff08 -> (* backspace *)
3384 if emptystr
text && cancelonempty
3387 G.postRedisplay "textentrykeyboard after cancel";
3390 let s = withoutlastutf8 text in
3391 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3393 | 0xff0d | 0xff8d -> (* (kp) enter *)
3396 G.postRedisplay "textentrykeyboard after confirm"
3398 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3399 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3400 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3401 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3403 | 0xff1b -> (* escape*)
3406 begin match opthist
with
3408 | Some
(_, onhistcancel
) -> onhistcancel
()
3412 G.postRedisplay "textentrykeyboard after cancel2"
3415 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3418 | 0xff9f | 0xffff -> () (* delete *)
3421 && key land 0xff00 != 0xff00 (* keyboard *)
3422 && key land 0xfe00 != 0xfe00 (* xkb *)
3423 && key land 0xfd00 != 0xfd00 (* 3270 *)
3425 begin match onkey
text key with
3429 G.postRedisplay "textentrykeyboard after confirm2";
3432 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3436 G.postRedisplay "textentrykeyboard after cancel3"
3439 state.mode
<- Textentry
(te
, onleave
);
3440 G.postRedisplay "textentrykeyboard switch";
3444 vlog "unhandled key %s" (Wsi.keyname
key)
3447 let firstof first active
=
3448 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3449 then max
0 (active
- (fstate.maxrows
/2))
3453 let calcfirst first active
=
3456 let rows = active
- first in
3457 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3461 let scrollph y maxy
=
3462 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3463 let sh = float state.winh
/. sh in
3464 let sh = max
sh (float conf.scrollh
) in
3466 let percent = float y /. float maxy
in
3467 let position = (float state.winh
-. sh) *. percent in
3470 if position +. sh > float state.winh
3471 then float state.winh
-. sh
3477 let coe s = (s :> uioh
);;
3479 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3481 val m_pan
= source#getpan
3482 val m_first
= source#getfirst
3483 val m_active
= source#getactive
3484 val m_qsearch
= source#getqsearch
3485 val m_prev_uioh
= state.uioh
3487 method private elemunder
y =
3488 let n = y / (fstate.fontsize
+1) in
3489 if m_first
+ n < source#getitemcount
3491 if source#hasaction
(m_first
+ n)
3492 then Some
(m_first
+ n)
3499 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3500 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3501 filledrect 0. 0. (float state.winw
) (float state.winh
);
3502 GlDraw.color
(1., 1., 1.);
3503 Gl.enable `texture_2d
;
3504 let fs = fstate.fontsize
in
3506 let ww = fstate.wwidth
in
3507 let tabw = 30.0*.ww in
3508 let itemcount = source#getitemcount
in
3510 if (row - m_first
) > fstate.maxrows
3513 if row >= 0 && row < itemcount
3515 let (s, level
) = source#getitem
row in
3516 let y = (row - m_first
) * nfs in
3517 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3520 Gl.disable `texture_2d
;
3521 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3522 GlDraw.color
(1., 1., 1.) ~
alpha;
3523 linerect 1. (float (y + 1))
3524 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3525 GlDraw.color
(1., 1., 1.);
3526 Gl.enable `texture_2d
;
3529 let drawtabularstring s =
3530 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3533 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3536 let len = String.length
s - tabpos - 1 in
3537 let s1 = String.sub
s 0 tabpos
3538 and s2
= String.sub
s (tabpos + 1) len in
3539 let nx = drawstr x s1 in
3541 let x = x +. (max
tabw sw) in
3548 let _ = drawtabularstring s in
3555 Gl.disable `texture_2d
;
3557 method updownlevel incr
=
3558 let len = source#getitemcount
in
3560 if m_active
>= 0 && m_active
< len
3561 then snd
(source#getitem m_active
)
3565 if i
= len then i
-1 else if i
= -1 then 0 else
3566 let _, l = source#getitem i
in
3567 if l != curlevel then i
else flow (i
+incr
)
3569 let active = flow m_active
in
3570 let first = calcfirst m_first
active in
3571 G.postRedisplay "outline updownlevel";
3572 {< m_active
= active; m_first
= first >}
3574 method private key1
key mask
=
3575 let set1 active first qsearch
=
3576 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3578 let search active pattern incr
=
3579 let active = if active = -1 then m_first
else active in
3582 if n >= 0 && n < source#getitemcount
3584 let s, _ = source#getitem
n in
3586 (try ignore
(Str.search_forward
re s 0); true
3587 with Not_found
-> false)
3589 else loop (n + incr
)
3596 let re = Str.regexp_case_fold pattern
in
3602 let itemcount = source#getitemcount
in
3603 let find start incr
=
3605 if i
= -1 || i
= itemcount
3608 if source#hasaction i
3610 else find (i
+ incr
)
3615 let set active first =
3616 let first = bound first 0 (itemcount - fstate.maxrows
) in
3618 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3621 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3623 let incr1 = if incr
> 0 then 1 else -1 in
3624 if isvisible m_first m_active
3627 let next = m_active
+ incr
in
3629 if next < 0 || next >= itemcount
3631 else find next incr1
3633 if abs
(m_active
- next) > fstate.maxrows
3639 let first = m_first
+ incr
in
3640 let first = bound first 0 (itemcount - fstate.maxrows
) in
3642 let next = m_active
+ incr
in
3643 let next = bound next 0 (itemcount - 1) in
3650 if isvisible first next
3657 let first = min
next m_first
in
3659 if abs
(next - first) > fstate.maxrows
3665 let first = m_first
+ incr
in
3666 let first = bound first 0 (itemcount - 1) in
3668 let next = m_active
+ incr
in
3669 let next = bound next 0 (itemcount - 1) in
3670 let next = find next incr1 in
3672 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3674 let active = if m_active
= -1 then next else m_active
in
3679 if isvisible first active
3685 G.postRedisplay "listview navigate";
3689 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3690 let incr = if key = 0x72 then -1 else 1 in
3692 match search (m_active
+ incr) m_qsearch
incr with
3694 state.text <- m_qsearch ^
" [not found]";
3697 state.text <- m_qsearch
;
3698 active, firstof m_first
active
3700 G.postRedisplay "listview ctrl-r/s";
3701 set1 active first m_qsearch
;
3703 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3704 if m_active
>= 0 && m_active
< source#getitemcount
3706 let s, _ = source#getitem m_active
in
3711 | 0xff08 -> (* backspace *)
3712 if emptystr m_qsearch
3715 let qsearch = withoutlastutf8 m_qsearch
in
3719 G.postRedisplay "listview empty qsearch";
3720 set1 m_active m_first
"";
3724 match search m_active
qsearch ~
-1 with
3726 state.text <- qsearch ^
" [not found]";
3729 state.text <- qsearch;
3730 active, firstof m_first
active
3732 G.postRedisplay "listview backspace qsearch";
3733 set1 active first qsearch
3736 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3737 let pattern = m_qsearch ^ toutf8
key in
3739 match search m_active
pattern 1 with
3741 state.text <- pattern ^
" [not found]";
3744 state.text <- pattern;
3745 active, firstof m_first
active
3747 G.postRedisplay "listview qsearch add";
3748 set1 active first pattern;
3750 | 0xff1b -> (* escape *)
3752 if emptystr m_qsearch
3754 G.postRedisplay "list view escape";
3757 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3759 | None
-> m_prev_uioh
3764 G.postRedisplay "list view kill qsearch";
3765 source#setqsearch
"";
3766 coe {< m_qsearch
= "" >}
3769 | 0xff0d | 0xff8d -> (* (kp) enter *)
3771 let self = {< m_qsearch
= "" >} in
3772 source#setqsearch
"";
3774 G.postRedisplay "listview enter";
3775 if m_active
>= 0 && m_active
< source#getitemcount
3777 source#exit
(coe self) false m_active m_first m_pan
"";
3780 source#exit
(coe self) true m_active m_first m_pan
"";
3783 begin match opt with
3784 | None
-> m_prev_uioh
3788 | 0xff9f | 0xffff -> (* (kp) delete *)
3791 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3792 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3793 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3794 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3796 | 0xff53 | 0xff98 -> (* (kp) right *)
3798 G.postRedisplay "listview right";
3799 coe {< m_pan
= m_pan
- 1 >}
3801 | 0xff51 | 0xff96 -> (* (kp) left *)
3803 G.postRedisplay "listview left";
3804 coe {< m_pan
= m_pan
+ 1 >}
3806 | 0xff50 | 0xff95 -> (* (kp) home *)
3807 let active = find 0 1 in
3808 G.postRedisplay "listview home";
3811 | 0xff57 | 0xff9c -> (* (kp) end *)
3812 let first = max
0 (itemcount - fstate.maxrows
) in
3813 let active = find (itemcount - 1) ~
-1 in
3814 G.postRedisplay "listview end";
3817 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3821 dolog
"listview unknown key %#x" key; coe self
3823 method key key mask
=
3824 match state.mode
with
3825 | Textentry te
-> textentrykeyboard key mask te
; coe self
3826 | _ -> self#key1
key mask
3828 method button button down
x y _ =
3831 | 1 when x > state.winw
- conf.scrollbw
->
3832 G.postRedisplay "listview scroll";
3835 let _, position, sh = self#
scrollph in
3836 if y > truncate
position && y < truncate
(position +. sh)
3838 state.mstate
<- Mscrolly
;
3842 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3843 let first = truncate
(s *. float source#getitemcount
) in
3844 let first = min source#getitemcount
first in
3845 Some
(coe {< m_first
= first; m_active
= first >})
3847 state.mstate
<- Mnone
;
3850 | 1 when not down
->
3851 begin match self#elemunder
y with
3853 G.postRedisplay "listview click";
3855 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3859 | n when (n == 4 || n == 5) && not down
->
3860 let len = source#getitemcount
in
3862 if n = 5 && m_first
+ fstate.maxrows
>= len
3866 let first = m_first
+ (if n == 4 then -1 else 1) in
3867 bound first 0 (len - 1)
3869 G.postRedisplay "listview wheel";
3870 Some
(coe {< m_first
= first >})
3871 | n when (n = 6 || n = 7) && not down
->
3872 let inc = if n = 7 then -1 else 1 in
3873 G.postRedisplay "listview hwheel";
3874 Some
(coe {< m_pan
= m_pan
+ inc >})
3879 | None
-> m_prev_uioh
3883 match state.mstate
with
3885 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3886 let first = truncate
(s *. float source#getitemcount
) in
3887 let first = min source#getitemcount
first in
3888 G.postRedisplay "listview motion";
3889 coe {< m_first
= first; m_active
= first >}
3892 method pmotion
x y =
3893 if x < state.winw
- conf.scrollbw
3896 match self#elemunder
y with
3897 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3898 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3902 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3907 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3911 method infochanged
_ = ()
3913 method scrollpw
= (0, 0.0, 0.0)
3915 let nfs = fstate.fontsize
+ 1 in
3916 let y = m_first
* nfs in
3917 let itemcount = source#getitemcount
in
3918 let maxi = max
0 (itemcount - fstate.maxrows
) in
3919 let maxy = maxi * nfs in
3920 let p, h = scrollph y maxy in
3923 method modehash
= modehash
3924 method eformsgs
= false
3927 class outlinelistview ~source
=
3928 let settext autonarrow
s =
3930 then state.text <- "[" ^
s ^
"]"
3931 else state.text <- s
3935 ~source
:(source
:> lvsource
)
3937 ~modehash
:(findkeyhash conf "outline")
3940 val m_autonarrow
= false
3942 method key key mask
=
3944 if emptystr
state.text
3946 else fstate.maxrows - 2
3948 let calcfirst first active =
3951 let rows = active - first in
3952 if rows > maxrows then active - maxrows else first
3956 let active = m_active
+ incr in
3957 let active = bound active 0 (source#getitemcount
- 1) in
3958 let first = calcfirst m_first
active in
3959 G.postRedisplay "outline navigate";
3960 coe {< m_active
= active; m_first
= first >}
3962 let navscroll first =
3964 let dist = m_active
- first in
3970 else first + maxrows
3973 G.postRedisplay "outline navscroll";
3974 coe {< m_first
= first; m_active
= active >}
3976 let ctrl = Wsi.withctrl mask
in
3978 | 97 when ctrl -> (* ctrl-a *)
3980 then source#denarrow
3981 else source#narrow m_qsearch
;
3982 settext (not m_autonarrow
) m_qsearch
;
3983 G.postRedisplay "toggle auto narrowing";
3984 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3986 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3988 G.postRedisplay "toggle auto narrowing";
3989 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3991 | 110 when ctrl -> (* ctrl-n *)
3992 source#narrow m_qsearch
;
3994 then source#add_narrow_pattern m_qsearch
;
3995 G.postRedisplay "outline ctrl-n";
3996 coe {< m_first
= 0; m_active
= 0 >}
3998 | 115 when ctrl -> (* ctrl-s *)
3999 let active = source#calcactive
(getanchor ()) in
4000 let first = firstof m_first
active in
4001 G.postRedisplay "outline ctrl-s";
4002 coe {< m_first
= first; m_active
= active >}
4004 | 117 when ctrl -> (* ctrl-u *)
4005 source#del_narrow_pattern
;
4006 let pattern = source#renarrow
in
4007 G.postRedisplay "outline ctrl-u";
4009 if emptystr
pattern then "" else "Narrowed to " ^
pattern
4011 settext m_autonarrow
text;
4012 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4014 | 108 when ctrl -> (* ctrl-l *)
4015 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
4016 G.postRedisplay "outline ctrl-l";
4017 coe {< m_first
= first >}
4019 | 0xff1b -> (* escape *)
4020 let o = super#
key key mask
in
4023 if nonemptystr m_qsearch
4025 source#add_narrow_pattern m_qsearch
;
4031 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
4032 if nonemptystr m_qsearch
4033 then source#add_narrow_pattern m_qsearch
;
4036 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
4037 let pattern = m_qsearch ^ toutf8
key in
4038 G.postRedisplay "outlinelistview autonarrow add";
4039 source#narrow
pattern;
4040 settext true pattern;
4041 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4043 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4044 if emptystr m_qsearch
4047 let pattern = withoutlastutf8 m_qsearch
in
4048 G.postRedisplay "outlinelistview autonarrow backspace";
4049 ignore
(source#renarrow
);
4050 source#narrow
pattern;
4051 settext true pattern;
4052 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4054 | 0xff9f | 0xffff -> (* (kp) delete *)
4055 source#remove m_active
;
4056 G.postRedisplay "outline delete";
4057 let active = max
0 (m_active
-1) in
4058 coe {< m_first
= firstof m_first
active;
4059 m_active
= active >}
4061 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4062 navscroll (max
0 (m_first
- 1))
4064 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4065 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4067 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4068 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4069 | 0xff55 | 0xff9a -> (* (kp) prior *)
4070 navigate ~
-(fstate.maxrows)
4071 | 0xff56 | 0xff9b -> (* (kp) next *)
4072 navigate fstate.maxrows
4074 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4078 G.postRedisplay "outline ctrl right";
4079 {< m_pan
= m_pan
+ 1 >}
4081 else self#updownlevel
1
4085 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4089 G.postRedisplay "outline ctrl left";
4090 {< m_pan
= m_pan
- 1 >}
4092 else self#updownlevel ~
-1
4096 | 0xff50 | 0xff95 -> (* (kp) home *)
4097 G.postRedisplay "outline home";
4098 coe {< m_first
= 0; m_active
= 0 >}
4100 | 0xff57 | 0xff9c -> (* (kp) end *)
4101 let active = source#getitemcount
- 1 in
4102 let first = max
0 (active - fstate.maxrows) in
4103 G.postRedisplay "outline end";
4104 coe {< m_active
= active; m_first
= first >}
4106 | _ -> super#
key key mask
4109 let gotounder under =
4110 let getpath filename
=
4112 if nonemptystr filename
4114 if Filename.is_relative filename
4116 let dir = Filename.dirname
state.path in
4118 if Filename.is_implicit
dir
4119 then Filename.concat
(Sys.getcwd
()) dir
4122 Filename.concat
dir filename
4126 if Sys.file_exists
path
4131 | Ulinkgoto
(pageno, top) ->
4135 gotopage1 pageno top;
4141 | Uremote
(filename
, pageno) ->
4142 let path = getpath filename
in
4147 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
4148 try popen command []
4151 "failed to execute `%s': %s\n" command (exntos exn
);
4154 let anchor = getanchor () in
4155 let ranchor = state.path, state.password
, anchor, state.origin
in
4157 state.anchor <- (pageno, 0.0, 0.0);
4158 state.ranchors
<- ranchor :: state.ranchors
;
4161 else showtext '
!'
("Could not find " ^ filename
)
4163 | Uremotedest
(filename
, destname
) ->
4164 let path = getpath filename
in
4169 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
4170 try popen command []
4173 "failed to execute `%s': %s\n" command (exntos exn
);
4176 let anchor = getanchor () in
4177 let ranchor = state.path, state.password
, anchor, state.origin
in
4179 state.nameddest
<- destname
;
4180 state.ranchors
<- ranchor :: state.ranchors
;
4183 else showtext '
!'
("Could not find " ^ filename
)
4185 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4188 let gotooutline (_, _, kind
) =
4192 let (pageno, y, _) = anchor in
4194 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4197 | Ouri
uri -> gotounder (Ulinkuri
uri)
4198 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
4199 | Oremote remote
-> gotounder (Uremote remote
)
4200 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
4203 let outlinesource usebookmarks
=
4206 inherit lvsourcebase
4207 val mutable m_items
= empty
4208 val mutable m_orig_items
= empty
4209 val mutable m_narrow_patterns
= []
4210 val mutable m_hadremovals
= false
4212 method getitemcount
=
4213 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4216 if n == Array.length m_items
&& m_hadremovals
4218 ("[Confirm removal]", 0)
4220 let s, n, _ = m_items
.(n) in
4223 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4224 ignore
(uioh
, first, qsearch);
4225 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4227 if m_narrow_patterns
= []
4233 if not
confrimremoval
4235 gotooutline m_items
.(active);
4239 state.bookmarks
<- Array.to_list m_items
;
4240 m_orig_items
<- m_items
;
4243 else m_items
<- items;
4247 method hasaction
_ = true
4250 if Array.length m_items
!= Array.length m_orig_items
4253 match m_narrow_patterns
with
4255 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
4257 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4260 method narrow
pattern =
4261 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4265 let rec loop accu n =
4267 then m_items
<- Array.of_list
accu
4269 let (s, _, _) as o = m_items
.(n) in
4271 if (try ignore
(Str.search_forward
re s 0); true
4272 with Not_found
-> false)
4278 loop [] (Array.length m_items
- 1)
4283 then Array.of_list
state.bookmarks
4286 m_items
<- m_orig_items
4291 if m >= 0 && m < Array.length m_items
4293 m_hadremovals
<- true;
4294 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4295 let n = if n >= m then n+1 else n in
4300 method add_narrow_pattern
pattern =
4301 m_narrow_patterns
<- pattern :: m_narrow_patterns
4303 method del_narrow_pattern
=
4304 match m_narrow_patterns
with
4305 | _ :: rest
-> m_narrow_patterns
<- rest
4310 match m_narrow_patterns
with
4311 | pattern :: [] -> self#narrow
pattern; pattern
4313 List.fold_left
(fun accu pattern ->
4314 self#narrow
pattern;
4315 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
4317 method calcactive
anchor =
4318 let rely = getanchory anchor in
4319 let rec loop n best bestd
=
4320 if n = Array.length m_items
4323 let _, _, kind
= m_items
.(n) in
4326 let orely = getanchory anchor in
4327 let d = abs
(orely - rely) in
4330 else loop (n+1) best bestd
4331 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
4332 loop (n+1) best bestd
4336 method reset
anchor items =
4337 m_hadremovals
<- false;
4338 if m_orig_items
== empty
4340 m_orig_items
<- items;
4341 if m_narrow_patterns
== []
4342 then m_items
<- items;
4344 let active = self#calcactive
anchor in
4346 m_first
<- firstof m_first
active
4350 let enterselector usebookmarks
=
4351 let source = outlinesource usebookmarks
in
4355 then Array.of_list
state.bookmarks
4358 if Array.length
outlines = 0
4360 showtext ' ' errmsg
;
4363 state.text <- source#greetmsg
;
4364 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4365 let anchor = getanchor () in
4366 source#reset
anchor outlines;
4367 state.uioh
<- coe (new outlinelistview ~
source);
4368 G.postRedisplay "enter selector";
4372 let enteroutlinemode =
4373 let f = enterselector false in
4374 fun ()-> f "Document has no outline";
4377 let enterbookmarkmode =
4378 let f = enterselector true in
4379 fun () -> f "Document has no bookmarks (yet)";
4382 let color_of_string s =
4383 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4384 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4388 let color_to_string (r, g, b) =
4389 let r = truncate
(r *. 256.0)
4390 and g = truncate
(g *. 256.0)
4391 and b = truncate
(b *. 256.0) in
4392 Printf.sprintf
"%d/%d/%d" r g b
4395 let irect_of_string s =
4396 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4399 let irect_to_string (x0,y0,x1,y1) =
4400 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4403 let makecheckers () =
4404 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4406 converted by Issac Trotts. July 25, 2002 *)
4407 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4408 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4409 let id = GlTex.gen_texture
() in
4410 GlTex.bind_texture `texture_2d
id;
4411 GlPix.store
(`unpack_alignment
1);
4412 GlTex.image2d
image;
4413 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4414 [ `mag_filter `nearest
; `min_filter `nearest
];
4418 let setcheckers enabled
=
4419 match state.texid
with
4421 if enabled
then state.texid
<- Some
(makecheckers ())
4426 GlTex.delete_texture texid
;
4427 state.texid
<- None
;
4431 let int_of_string_with_suffix s =
4432 let l = String.length
s in
4436 let suffix = Char.lowercase
s.[l-1] in
4438 | 'k'
-> String.sub
s 0 (l-1), 10
4439 | '
m'
-> String.sub
s 0 (l-1), 20
4440 | '
g'
-> String.sub
s 0 (l-1), 30
4444 let n = int_of_string
s1 in
4445 let m = n lsl shift
in
4447 then raise
(Failure
"value too large")
4451 let string_with_suffix_of_int n =
4455 let units = [(30, "G"); (20, "M"); (10, "K")] in
4458 let h = n mod 1000 in
4461 then string_of_int
h ^
s
4463 let s = Printf.sprintf
"_%03d%s" h s in
4469 let rec find = function
4471 | (shift
, suffix) :: rest
->
4472 if (n land ((1 lsl shift
) - 1)) = 0
4473 then prettyint (n lsr shift
) ^
suffix
4479 let defghyllscroll = (40, 8, 32);;
4480 let fastghyllscroll = (5,1,2);;
4481 let neatghyllscroll = (10,1,9);;
4482 let ghyllscroll_of_string s =
4484 | "default" -> Some
defghyllscroll
4485 | "fast" -> Some
(5,1,2)
4486 | "neat" -> Some
(10,1,9)
4487 | "" | "none" -> None
4489 let (n,a,b) as nab
=
4490 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4491 if n <= a || n <= b || a >= b
4492 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4497 let ghyllscroll_to_string ((n, a, b) as nab
) =
4498 (**) if nab
= defghyllscroll then "default"
4499 else if nab
= fastghyllscroll then "fast"
4500 else if nab
= neatghyllscroll then "neat"
4501 else Printf.sprintf
"%d,%d,%d" n a b;
4504 let describe_location () =
4505 let fn = page_of_y state.y in
4506 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4507 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4511 else (100. *. (float state.y /. float maxy))
4515 Printf.sprintf
"page %d of %d [%.2f%%]"
4516 (fn+1) state.pagecount
percent
4519 "pages %d-%d of %d [%.2f%%]"
4520 (fn+1) (ln+1) state.pagecount
percent
4523 let setpresentationmode v
=
4524 let n = page_of_y state.y in
4525 state.anchor <- (n, 0.0, 1.0);
4526 conf.presentation
<- v
;
4527 if conf.fitmodel
= FitPage
4528 then reqlayout conf.angle
conf.fitmodel
;
4533 let btos b = if b then "\xe2\x88\x9a" else "" in
4534 let showextended = ref false in
4535 let leave mode
= function
4536 | Confirm
-> state.mode
<- mode
4537 | Cancel
-> state.mode
<- mode
in
4540 val mutable m_first_time
= true
4541 val mutable m_l
= []
4542 val mutable m_a
= [||]
4543 val mutable m_prev_uioh
= nouioh
4544 val mutable m_prev_mode
= View
4546 inherit lvsourcebase
4548 method reset prev_mode prev_uioh
=
4549 m_a
<- Array.of_list
(List.rev m_l
);
4551 m_prev_mode
<- prev_mode
;
4552 m_prev_uioh
<- prev_uioh
;
4556 if n >= Array.length m_a
4560 | _, _, _, Action
_ -> m_active
<- n
4564 m_first_time
<- false;
4567 method int name get
set =
4569 (name, `
int get
, 1, Action
(
4572 try set (int_of_string
s)
4574 state.text <- Printf.sprintf
"bad integer `%s': %s"
4578 let te = name ^
": ", "", None
, intentry, ondone, true in
4579 state.mode
<- Textentry
(te, leave m_prev_mode
);
4583 method int_with_suffix
name get
set =
4585 (name, `intws get
, 1, Action
(
4588 try set (int_of_string_with_suffix s)
4590 state.text <- Printf.sprintf
"bad integer `%s': %s"
4595 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4597 state.mode
<- Textentry
(te, leave m_prev_mode
);
4601 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4603 (name, `
bool (btos, get
), offset
, Action
(
4610 method color
name get
set =
4612 (name, `color get
, 1, Action
(
4614 let invalid = (nan
, nan
, nan
) in
4617 try color_of_string s
4619 state.text <- Printf.sprintf
"bad color `%s': %s"
4626 let te = name ^
": ", "", None
, textentry, ondone, true in
4627 state.text <- color_to_string (get
());
4628 state.mode
<- Textentry
(te, leave m_prev_mode
);
4632 method string name get
set =
4634 (name, `
string get
, 1, Action
(
4636 let ondone s = set s in
4637 let te = name ^
": ", "", None
, textentry, ondone, true in
4638 state.mode
<- Textentry
(te, leave m_prev_mode
);
4642 method colorspace
name get
set =
4644 (name, `
string get
, 1, Action
(
4648 inherit lvsourcebase
4651 m_active
<- CSTE.to_int conf.colorspace
;
4654 method getitemcount
=
4655 Array.length
CSTE.names
4658 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4659 ignore
(uioh
, first, pan
, qsearch);
4660 if not cancel
then set active;
4662 method hasaction
_ = true
4666 let modehash = findkeyhash conf "info" in
4667 coe (new listview ~
source ~trusted
:true ~
modehash)
4670 method paxmark
name get
set =
4672 (name, `
string get
, 1, Action
(
4676 inherit lvsourcebase
4679 m_active
<- MTE.to_int conf.paxmark
;
4682 method getitemcount
= Array.length
MTE.names
4683 method getitem
n = (MTE.names.(n), 0)
4684 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4685 ignore
(uioh
, first, pan
, qsearch);
4686 if not cancel
then set active;
4688 method hasaction
_ = true
4692 let modehash = findkeyhash conf "info" in
4693 coe (new listview ~
source ~trusted
:true ~
modehash)
4696 method fitmodel
name get
set =
4698 (name, `
string get
, 1, Action
(
4702 inherit lvsourcebase
4705 m_active
<- FMTE.to_int conf.fitmodel
;
4708 method getitemcount
= Array.length
FMTE.names
4709 method getitem
n = (FMTE.names.(n), 0)
4710 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4711 ignore
(uioh
, first, pan
, qsearch);
4712 if not cancel
then set active;
4714 method hasaction
_ = true
4718 let modehash = findkeyhash conf "info" in
4719 coe (new listview ~
source ~trusted
:true ~
modehash)
4722 method caption
s offset
=
4723 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4725 method caption2
s f offset
=
4726 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4728 method getitemcount
= Array.length m_a
4731 let tostr = function
4732 | `
int f -> string_of_int
(f ())
4733 | `intws
f -> string_with_suffix_of_int (f ())
4735 | `color
f -> color_to_string (f ())
4736 | `
bool (btos, f) -> btos (f ())
4739 let name, t
, offset
, _ = m_a
.(n) in
4740 ((let s = tostr t
in
4742 then Printf.sprintf
"%s\t%s" name s
4746 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4750 m_qsearch
<- qsearch;
4752 match m_a
.(active) with
4753 | _, _, _, Action
f -> f uioh
4765 method hasaction
n =
4767 | _, _, _, Action
_ -> true
4771 let rec fillsrc prevmode prevuioh
=
4772 let sep () = src#caption
"" 0 in
4773 let colorp name get
set =
4775 (fun () -> color_to_string (get
()))
4778 let c = color_of_string v in
4781 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4784 let oldmode = state.mode
in
4785 let birdseye = isbirdseye state.mode
in
4787 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4789 src#
bool "presentation mode"
4790 (fun () -> conf.presentation
)
4791 (fun v -> setpresentationmode v);
4793 src#
bool "ignore case in searches"
4794 (fun () -> conf.icase
)
4795 (fun v -> conf.icase
<- v);
4798 (fun () -> conf.preload)
4799 (fun v -> conf.preload <- v);
4801 src#
bool "highlight links"
4802 (fun () -> conf.hlinks
)
4803 (fun v -> conf.hlinks
<- v);
4805 src#
bool "under info"
4806 (fun () -> conf.underinfo
)
4807 (fun v -> conf.underinfo
<- v);
4809 src#
bool "persistent bookmarks"
4810 (fun () -> conf.savebmarks
)
4811 (fun v -> conf.savebmarks
<- v);
4813 src#fitmodel
"fit model"
4814 (fun () -> FMTE.to_string conf.fitmodel
)
4815 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4817 src#
bool "trim margins"
4818 (fun () -> conf.trimmargins
)
4819 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4821 src#
bool "persistent location"
4822 (fun () -> conf.jumpback
)
4823 (fun v -> conf.jumpback
<- v);
4826 src#
int "inter-page space"
4827 (fun () -> conf.interpagespace
)
4829 conf.interpagespace
<- n;
4830 docolumns conf.columns
;
4832 match state.layout with
4837 state.maxy <- calcheight ();
4838 let y = getpagey pageno in
4843 (fun () -> conf.pagebias
)
4844 (fun v -> conf.pagebias
<- v);
4846 src#
int "scroll step"
4847 (fun () -> conf.scrollstep
)
4848 (fun n -> conf.scrollstep
<- n);
4850 src#
int "horizontal scroll step"
4851 (fun () -> conf.hscrollstep
)
4852 (fun v -> conf.hscrollstep
<- v);
4854 src#
int "auto scroll step"
4856 match state.autoscroll
with
4858 | _ -> conf.autoscrollstep
)
4860 let n = boundastep state.winh
n in
4861 if state.autoscroll
<> None
4862 then state.autoscroll
<- Some
n;
4863 conf.autoscrollstep
<- n);
4866 (fun () -> truncate
(conf.zoom *. 100.))
4867 (fun v -> setzoom ((float v) /. 100.));
4870 (fun () -> conf.angle
)
4871 (fun v -> reqlayout v conf.fitmodel
);
4873 src#
int "scroll bar width"
4874 (fun () -> conf.scrollbw
)
4877 reshape state.winw
state.winh
;
4880 src#
int "scroll handle height"
4881 (fun () -> conf.scrollh
)
4882 (fun v -> conf.scrollh
<- v;);
4884 src#
int "thumbnail width"
4885 (fun () -> conf.thumbw
)
4887 conf.thumbw
<- min
4096 v;
4890 leavebirdseye beye
false;
4895 let mode = state.mode in
4896 src#
string "columns"
4898 match conf.columns
with
4900 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4901 | Csplit
(count
, _) -> "-" ^ string_of_int count
4904 let n, a, b = multicolumns_of_string v in
4905 setcolumns mode n a b);
4908 src#caption
"Pixmap cache" 0;
4909 src#int_with_suffix
"size (advisory)"
4910 (fun () -> conf.memlimit
)
4911 (fun v -> conf.memlimit
<- v);
4914 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4915 (string_with_suffix_of_int state.memused
)
4916 (Hashtbl.length
state.tilemap
)) 1;
4919 src#caption
"Layout" 0;
4920 src#caption2
"Dimension"
4922 Printf.sprintf
"%dx%d (virtual %dx%d)"
4923 state.winw
state.winh
4928 src#caption2
"Position" (fun () ->
4929 Printf.sprintf
"%dx%d" state.x state.y
4932 src#caption2
"Position" (fun () -> describe_location ()) 1
4936 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4937 "Save these parameters as global defaults at exit"
4938 (fun () -> conf.bedefault
)
4939 (fun v -> conf.bedefault
<- v)
4943 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4944 src#
bool ~offset
:0 ~
btos "Extended parameters"
4945 (fun () -> !showextended)
4946 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4950 (fun () -> conf.checkers
)
4951 (fun v -> conf.checkers
<- v; setcheckers v);
4952 src#
bool "update cursor"
4953 (fun () -> conf.updatecurs
)
4954 (fun v -> conf.updatecurs
<- v);
4956 (fun () -> conf.verbose
)
4957 (fun v -> conf.verbose
<- v);
4958 src#
bool "invert colors"
4959 (fun () -> conf.invert
)
4960 (fun v -> conf.invert
<- v);
4962 (fun () -> conf.maxhfit
)
4963 (fun v -> conf.maxhfit
<- v);
4964 src#
bool "redirect stderr"
4965 (fun () -> conf.redirectstderr)
4966 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4968 (fun () -> conf.pax
!= None
)
4971 then conf.pax
<- Some
(ref (now (), 0, 0))
4972 else conf.pax
<- None
);
4973 src#
string "uri launcher"
4974 (fun () -> conf.urilauncher
)
4975 (fun v -> conf.urilauncher
<- v);
4976 src#
string "path launcher"
4977 (fun () -> conf.pathlauncher
)
4978 (fun v -> conf.pathlauncher
<- v);
4979 src#
string "tile size"
4980 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4983 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4984 conf.tilew
<- max
64 w;
4985 conf.tileh
<- max
64 h;
4988 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4991 src#
int "texture count"
4992 (fun () -> conf.texcount
)
4995 then conf.texcount
<- v
4996 else showtext '
!'
" Failed to set texture count please retry later"
4998 src#
int "slice height"
4999 (fun () -> conf.sliceheight
)
5001 conf.sliceheight
<- v;
5002 wcmd "sliceh %d" conf.sliceheight
;
5004 src#
int "anti-aliasing level"
5005 (fun () -> conf.aalevel
)
5007 conf.aalevel
<- bound v 0 8;
5008 state.anchor <- getanchor ();
5009 opendoc state.path state.password
;
5011 src#
string "page scroll scaling factor"
5012 (fun () -> string_of_float
conf.pgscale)
5015 let s = float_of_string
v in
5018 state.text <- Printf.sprintf
5019 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
5022 src#
int "ui font size"
5023 (fun () -> fstate.fontsize
)
5024 (fun v -> setfontsize (bound v 5 100));
5025 src#
int "hint font size"
5026 (fun () -> conf.hfsize
)
5027 (fun v -> conf.hfsize
<- bound v 5 100);
5028 colorp "background color"
5029 (fun () -> conf.bgcolor
)
5030 (fun v -> conf.bgcolor
<- v);
5031 src#
bool "crop hack"
5032 (fun () -> conf.crophack
)
5033 (fun v -> conf.crophack
<- v);
5034 src#
string "trim fuzz"
5035 (fun () -> irect_to_string conf.trimfuzz
)
5038 conf.trimfuzz
<- irect_of_string v;
5040 then settrim true conf.trimfuzz
;
5042 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
5044 src#
string "throttle"
5046 match conf.maxwait
with
5047 | None
-> "show place holder if page is not ready"
5050 then "wait for page to fully render"
5052 "wait " ^ string_of_float
time
5053 ^
" seconds before showing placeholder"
5057 let f = float_of_string
v in
5059 then conf.maxwait
<- None
5060 else conf.maxwait
<- Some
f
5062 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
5064 src#
string "ghyll scroll"
5066 match conf.ghyllscroll
with
5068 | Some nab
-> ghyllscroll_to_string nab
5071 try conf.ghyllscroll
<- ghyllscroll_of_string v
5073 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
5075 src#
string "selection command"
5076 (fun () -> conf.selcmd
)
5077 (fun v -> conf.selcmd
<- v);
5078 src#
string "synctex command"
5079 (fun () -> conf.stcmd
)
5080 (fun v -> conf.stcmd
<- v);
5081 src#
string "pax command"
5082 (fun () -> conf.paxcmd
)
5083 (fun v -> conf.paxcmd
<- v);
5084 src#colorspace
"color space"
5085 (fun () -> CSTE.to_string conf.colorspace
)
5087 conf.colorspace
<- CSTE.of_int v;
5091 src#paxmark
"pax mark method"
5092 (fun () -> MTE.to_string conf.paxmark
)
5093 (fun v -> conf.paxmark
<- MTE.of_int v);
5097 (fun () -> conf.usepbo
)
5098 (fun v -> conf.usepbo
<- v);
5099 src#
bool "mouse wheel scrolls pages"
5100 (fun () -> conf.wheelbypage
)
5101 (fun v -> conf.wheelbypage
<- v);
5102 src#
bool "open remote links in a new instance"
5103 (fun () -> conf.riani
)
5104 (fun v -> conf.riani
<- v);
5108 src#caption
"Document" 0;
5109 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
5110 src#caption2
"Pages"
5111 (fun () -> string_of_int
state.pagecount
) 1;
5112 src#caption2
"Dimensions"
5113 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5117 src#caption
"Trimmed margins" 0;
5118 src#caption2
"Dimensions"
5119 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5123 src#caption
"OpenGL" 0;
5124 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
5125 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
5128 src#caption
"Location" 0;
5129 if nonemptystr
state.origin
5130 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
5131 src#caption
("Path\t" ^ mbtoutf8
state.path) 1;
5133 src#reset prevmode prevuioh
;
5137 let prevmode = state.mode
5138 and prevuioh
= state.uioh in
5139 fillsrc prevmode prevuioh
;
5140 let source = (src :> lvsource
) in
5141 let modehash = findkeyhash conf "info" in
5142 state.uioh <- coe (object (self)
5143 inherit listview ~
source ~trusted
:true ~
modehash as super
5144 val mutable m_prevmemused
= 0
5145 method infochanged
= function
5147 if m_prevmemused
!= state.memused
5149 m_prevmemused
<- state.memused
;
5150 G.postRedisplay "memusedchanged";
5152 | Pdim
-> G.postRedisplay "pdimchanged"
5153 | Docinfo
-> fillsrc prevmode prevuioh
5155 method key key mask
=
5156 if not
(Wsi.withctrl mask
)
5159 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5160 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5161 | _ -> super#
key key mask
5162 else super#
key key mask
5164 G.postRedisplay "info";
5170 inherit lvsourcebase
5171 method getitemcount
= Array.length
state.help
5173 let s, l, _ = state.help
.(n) in
5176 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5180 m_qsearch
<- qsearch;
5181 match state.help
.(active) with
5182 | _, _, Action
f -> Some
(f uioh)
5192 method hasaction
n =
5193 match state.help
.(n) with
5194 | _, _, Action
_ -> true
5201 let modehash = findkeyhash conf "help" in
5202 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5203 G.postRedisplay "help";
5208 let re = Str.regexp
"[\r\n]" in
5210 inherit lvsourcebase
5211 val mutable m_items
= [||]
5213 method getitemcount
= 1 + Array.length m_items
5218 else m_items
.(n-1), 0
5220 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5225 then Buffer.clear
state.errmsgs
;
5226 m_qsearch
<- qsearch;
5233 method hasaction
n =
5237 state.newerrmsgs
<- false;
5238 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5239 m_items
<- Array.of_list
l
5247 let source = (msgsource :> lvsource
) in
5248 let modehash = findkeyhash conf "listview" in
5249 state.uioh <- coe (object
5250 inherit listview ~
source ~trusted
:false ~
modehash as super
5253 then msgsource#reset
;
5256 G.postRedisplay "msgs";
5259 let quickbookmark ?title
() =
5260 match state.layout with
5266 let sec = Unix.gettimeofday
() in
5267 let tm = Unix.localtime
sec in
5268 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5272 (tm.Unix.tm_year
+ 1900)
5275 | Some
title -> title
5277 state.bookmarks
<- (title, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5280 let setautoscrollspeed step goingdown
=
5281 let incr = max
1 ((abs step
) / 2) in
5282 let incr = if goingdown
then incr else -incr in
5283 let astep = boundastep state.winh
(step
+ incr) in
5284 state.autoscroll
<- Some
astep;
5288 match conf.columns
with
5290 | _ -> state.x != 0 || conf.zoom > 1.0
5293 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5295 let existsinrow pageno (columns
, coverA
, coverB
) p =
5296 let last = ((pageno - coverA
) mod columns
) + columns
in
5297 let rec any = function
5300 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5304 then (if l.pageno = last then false else any rest
)
5312 match state.layout with
5314 let pageno = page_of_y state.y in
5315 gotoghyll (getpagey (pageno+1))
5317 match conf.columns
with
5319 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5321 let y = clamp (pgscale state.winh
) in
5324 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5325 gotoghyll (getpagey pageno)
5326 | Cmulti
((c, _, _) as cl, _) ->
5327 if conf.presentation
5328 && (existsinrow l.pageno cl
5329 (fun l -> l.pageh
> l.pagey + l.pagevh))
5331 let y = clamp (pgscale state.winh
) in
5334 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5335 gotoghyll (getpagey pageno)
5337 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5339 let pagey, pageh
= getpageyh l.pageno in
5340 let pagey = pagey + pageh
* l.pagecol
in
5341 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5342 gotoghyll (pagey + pageh
+ ips)
5346 match state.layout with
5348 let pageno = page_of_y state.y in
5349 gotoghyll (getpagey (pageno-1))
5351 match conf.columns
with
5353 if conf.presentation
&& l.pagey != 0
5355 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5357 let pageno = max
0 (l.pageno-1) in
5358 gotoghyll (getpagey pageno)
5359 | Cmulti
((c, _, coverB
) as cl, _) ->
5360 if conf.presentation
&&
5361 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5363 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5366 if l.pageno = state.pagecount
- coverB
5370 let pageno = max
0 (l.pageno-decr) in
5371 gotoghyll (getpagey pageno)
5379 let pageno = max
0 (l.pageno-1) in
5380 let pagey, pageh
= getpageyh pageno in
5383 let pagey, pageh
= getpageyh l.pageno in
5384 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5389 let viewkeyboard key mask
=
5391 let mode = state.mode in
5392 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5395 G.postRedisplay "view:enttext"
5397 let ctrl = Wsi.withctrl mask
in
5399 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5405 | 0xff63 -> (* insert *)
5406 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5408 state.mode <- LinkNav
(Ltgendir
0);
5411 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5413 | 0xff1b | 113 -> (* escape / q *)
5414 begin match state.mstate
with
5416 state.mstate
<- Mnone
;
5417 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5418 G.postRedisplay "kill zoom rect";
5420 begin match state.mode with
5423 G.postRedisplay "esc leave linknav"
5425 match state.ranchors
with
5427 | (path, password
, anchor, origin
) :: rest
->
5428 state.ranchors
<- rest
;
5429 state.anchor <- anchor;
5430 state.origin
<- origin
;
5431 state.nameddest
<- "";
5432 opendoc path password
5436 | 0xff08 -> (* backspace *)
5437 gotoghyll (getnav ~
-1)
5445 G.postRedisplay "dehighlight";
5447 | 47 | 63 -> (* / ? *)
5448 let ondone isforw
s =
5449 cbput state.hists
.pat
s;
5450 state.searchpattern
<- s;
5453 let s = String.create
1 in
5454 s.[0] <- Char.chr
key;
5455 enttext (s, "", Some
(onhist state.hists
.pat
),
5456 textentry, ondone (key = 47), true)
5458 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5459 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5460 setzoom (conf.zoom +. incr)
5462 | 43 | 0xffab -> (* + *)
5465 try int_of_string
s with exc
->
5466 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5472 state.text <- "page bias is now " ^ string_of_int
n;
5475 enttext ("page bias: ", "", None
, intentry, ondone, true)
5477 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5478 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5479 setzoom (max
0.01 (conf.zoom -. decr))
5481 | 45 | 0xffad -> (* - *)
5482 let ondone msg
= state.text <- msg
in
5484 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5485 optentry state.mode, ondone, true
5488 | 48 when ctrl -> (* ctrl-0 *)
5496 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5498 match conf.columns
with
5499 | Csingle
_ | Cmulti
_ -> 1
5500 | Csplit
(n, _) -> n
5502 let h = state.winh
-
5503 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5505 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5506 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5509 | 51 when ctrl -> (* ctrl-3 *)
5511 match conf.fitmodel
with
5512 | FitWidth
-> FitProportional
5513 | FitProportional
-> FitPage
5514 | FitPage
-> FitWidth
5516 state.text <- "fit model: " ^
FMTE.to_string fm;
5517 reqlayout conf.angle
fm
5519 | 0xffc6 -> (* f9 *)
5522 | 57 when ctrl -> (* ctrl-9 *)
5525 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5526 when not
ctrl -> (* 0..9 *)
5529 try int_of_string
s with exc
->
5530 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5536 cbput state.hists
.pag
(string_of_int
n);
5537 gotopage1 (n + conf.pagebias
- 1) 0;
5540 let pageentry text key =
5541 match Char.unsafe_chr
key with
5542 | '
g'
-> TEdone
text
5543 | _ -> intentry text key
5545 let text = "x" in text.[0] <- Char.chr
key;
5546 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5549 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5550 reshape state.winw
state.winh
;
5553 state.bzoom
<- not
state.bzoom
;
5555 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5558 conf.hlinks
<- not
conf.hlinks
;
5559 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5560 G.postRedisplay "toggle highlightlinks";
5563 state.glinks
<- true;
5564 let mode = state.mode in
5565 state.mode <- Textentry
(
5566 (":", "", None
, linknentry, linkndone gotounder, false),
5568 state.glinks
<- false;
5572 G.postRedisplay "view:linkent(F)"
5575 state.glinks
<- true;
5576 let mode = state.mode in
5577 state.mode <- Textentry
(
5579 ":", "", None
, linknentry, linkndone (fun under ->
5580 selstring (undertext under);
5584 state.glinks
<- false;
5588 G.postRedisplay "view:linkent"
5591 begin match state.autoscroll
with
5593 conf.autoscrollstep
<- step
;
5594 state.autoscroll
<- None
5596 if conf.autoscrollstep
= 0
5597 then state.autoscroll
<- Some
1
5598 else state.autoscroll
<- Some
conf.autoscrollstep
5601 | 112 when ctrl -> (* ctrl-p *)
5605 setpresentationmode (not
conf.presentation
);
5606 showtext ' '
("presentation mode " ^
5607 if conf.presentation
then "on" else "off");
5610 if List.mem
Wsi.Fullscreen
state.winstate
5611 then Wsi.reshape conf.cwinw
conf.cwinh
5612 else Wsi.fullscreen
()
5614 | 112 | 78 -> (* p|N *)
5615 search state.searchpattern
false
5617 | 110 | 0xffc0 -> (* n|F3 *)
5618 search state.searchpattern
true
5621 begin match state.layout with
5624 gotoghyll (getpagey l.pageno)
5630 | 0xff9f | 0xffff -> (* delete *)
5634 showtext ' '
(describe_location ());
5637 begin match state.layout with
5640 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5645 enterbookmarkmode ()
5647 | 104 | 0xffbe -> (* h|F1 *)
5653 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5658 match state.layout with
5663 (s, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5666 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5670 showtext ' '
"Quick bookmark added";
5673 begin match state.layout with
5675 let rect = getpdimrect
l.pagedimno
in
5679 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5680 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5682 (truncate
(rect.(1) -. rect.(0)),
5683 truncate
(rect.(3) -. rect.(0)))
5685 let w = truncate
((float w)*.conf.zoom)
5686 and h = truncate
((float h)*.conf.zoom) in
5689 state.anchor <- getanchor ();
5690 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5692 G.postRedisplay "z";
5697 | 120 -> state.roam
() (* x *)
5698 | 60 | 62 -> (* < > *)
5699 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5701 | 91 | 93 -> (* [ ] *)
5703 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5705 G.postRedisplay "brightness";
5707 | 99 when state.mode = View
-> (* [alt-]c *)
5712 let m = (wadjsb state.winw
- state.w) / 2 in
5714 gotoy_and_clear_text state.y
5718 match state.prevcolumns
with
5719 | None
-> (1, 0, 0), 1.0
5720 | Some
(columns
, z
) ->
5723 | Csplit
(c, _) -> -c, 0, 0
5724 | Cmulti
((c, a, b), _) -> c, a, b
5725 | Csingle
_ -> 1, 0, 0
5729 setcolumns View
c a b;
5732 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5733 -> (* ctrl-shift- (kp) [up|down] *)
5734 let zoom, x = state.prevzoom
in
5738 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5739 begin match state.autoscroll
with
5741 begin match state.mode with
5742 | Birdseye beye
-> upbirdseye 1 beye
5745 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5747 if not
(Wsi.withshift mask
) && conf.presentation
5749 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5753 setautoscrollspeed n false
5756 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5757 begin match state.autoscroll
with
5759 begin match state.mode with
5760 | Birdseye beye
-> downbirdseye 1 beye
5763 then gotoy_and_clear_text (clamp (state.winh
/2))
5765 if not
(Wsi.withshift mask
) && conf.presentation
5767 else gotoy_and_clear_text (clamp conf.scrollstep
)
5771 setautoscrollspeed n true
5774 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5775 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5781 else conf.hscrollstep
5783 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5784 state.x <- panbound (state.x + dx);
5785 gotoy_and_clear_text state.y
5788 G.postRedisplay "left/right"
5791 | 0xff55 | 0xff9a -> (* (kp) prior *)
5795 match state.layout with
5797 | l :: _ -> state.y - l.pagey
5799 clamp (pgscale (-state.winh
))
5803 | 0xff56 | 0xff9b -> (* (kp) next *)
5807 match List.rev
state.layout with
5809 | l :: _ -> getpagey l.pageno
5811 clamp (pgscale state.winh
)
5815 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5817 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5818 gotoghyll (clamp state.maxy)
5821 when Wsi.withalt mask
-> (* alt-(kp) right *)
5822 gotoghyll (getnav 1)
5824 when Wsi.withalt mask
-> (* alt-(kp) left *)
5825 gotoghyll (getnav ~
-1)
5830 | 118 when conf.debug
-> (* v *)
5833 match getopaque l.pageno with
5836 let x0, y0, x1, y1 = pagebbox opaque
in
5837 let a,b = float x0, float y0 in
5838 let c,d = float x1, float y0 in
5839 let e,f = float x1, float y1 in
5840 let h,j
= float x0, float y1 in
5841 let rect = (a,b,c,d,e,f,h,j
) in
5843 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5845 G.postRedisplay "v";
5848 vlog "huh? %s" (Wsi.keyname
key)
5851 let linknavkeyboard key mask
linknav =
5852 let getpage pageno =
5853 let rec loop = function
5855 | l :: _ when l.pageno = pageno -> Some
l
5856 | _ :: rest
-> loop rest
5857 in loop state.layout
5859 let doexact (pageno, n) =
5860 match getopaque pageno, getpage pageno with
5861 | Some opaque
, Some
l ->
5862 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5864 let under = getlink opaque
n in
5865 G.postRedisplay "link gotounder";
5871 | 0xff50 -> (* home *)
5872 Some
(findlink opaque LDfirst
), -1
5874 | 0xff57 -> (* end *)
5875 Some
(findlink opaque LDlast
), 1
5877 | 0xff51 -> (* left *)
5878 Some
(findlink opaque
(LDleft
n)), -1
5880 | 0xff53 -> (* right *)
5881 Some
(findlink opaque
(LDright
n)), 1
5883 | 0xff52 -> (* up *)
5884 Some
(findlink opaque
(LDup
n)), -1
5886 | 0xff54 -> (* down *)
5887 Some
(findlink opaque
(LDdown
n)), 1
5892 begin match findpwl
l.pageno dir with
5896 state.mode <- LinkNav
(Ltgendir
dir);
5897 let y, h = getpageyh pageno in
5900 then y + h - state.winh
5905 begin match getopaque pageno, getpage pageno with
5906 | Some opaque
, Some
_ ->
5908 let ld = if dir > 0 then LDfirst
else LDlast
in
5911 begin match link with
5913 showlinktype (getlink opaque
m);
5914 state.mode <- LinkNav
(Ltexact
(pageno, m));
5915 G.postRedisplay "linknav jpage";
5922 begin match opt with
5923 | Some Lnotfound
-> pwl l dir;
5924 | Some
(Lfound
m) ->
5928 let _, y0, _, y1 = getlinkrect opaque
m in
5930 then gotopage1 l.pageno y0
5932 let d = fstate.fontsize
+ 1 in
5933 if y1 - l.pagey > l.pagevh - d
5934 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5935 else G.postRedisplay "linknav";
5937 showlinktype (getlink opaque
m);
5938 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5941 | None
-> viewkeyboard key mask
5943 | _ -> viewkeyboard key mask
5948 G.postRedisplay "leave linknav"
5952 | Ltgendir
_ -> viewkeyboard key mask
5953 | Ltexact exact
-> doexact exact
5956 let keyboard key mask
=
5957 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5958 then wcmd "interrupt"
5959 else state.uioh <- state.uioh#
key key mask
5962 let birdseyekeyboard key mask
5963 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5965 match conf.columns
with
5967 | Cmulti
((c, _, _), _) -> c
5968 | Csplit
_ -> failwith
"bird's eye split mode"
5970 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5972 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5973 let y, h = getpageyh pageno in
5974 let top = (state.winh
- h) / 2 in
5975 gotoy (max
0 (y - top))
5976 | 0xff0d (* enter *)
5977 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5978 | 0xff1b -> leavebirdseye beye
true (* escape *)
5979 | 0xff52 -> upbirdseye incr beye
(* up *)
5980 | 0xff54 -> downbirdseye incr beye
(* down *)
5981 | 0xff51 -> upbirdseye 1 beye
(* left *)
5982 | 0xff53 -> downbirdseye 1 beye
(* right *)
5984 | 0xff55 -> (* prior *)
5985 begin match state.layout with
5989 state.mode <- Birdseye
(
5990 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5992 gotopage1 l.pageno 0;
5995 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5997 | [] -> gotoy (clamp (-state.winh
))
5999 state.mode <- Birdseye
(
6000 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6002 gotopage1 l.pageno 0
6005 | [] -> gotoy (clamp (-state.winh
))
6008 | 0xff56 -> (* next *)
6009 begin match List.rev
state.layout with
6011 let layout = layout (state.y + (pgh state.layout)) state.winh
in
6012 begin match layout with
6014 let incr = l.pageh
- l.pagevh in
6019 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
6021 G.postRedisplay "birdseye pagedown";
6023 else gotoy (clamp (incr + conf.interpagespace
*2));
6027 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
6028 gotopage1 l.pageno 0;
6031 | [] -> gotoy (clamp state.winh
)
6034 | 0xff50 -> (* home *)
6035 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
6038 | 0xff57 -> (* end *)
6039 let pageno = state.pagecount
- 1 in
6040 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
6041 if not
(pagevisible state.layout pageno)
6044 match List.rev
state.pdims
with
6046 | (_, _, h, _) :: _ -> h
6048 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
6049 else G.postRedisplay "birdseye end";
6050 | _ -> viewkeyboard key mask
6055 match state.mode with
6056 | Textentry
_ -> scalecolor 0.4
6058 | View
-> scalecolor 1.0
6059 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6060 if l.pageno = hooverpageno
6063 if l.pageno = pageno
6071 let postdrawpage l linkindexbase
=
6072 match getopaque l.pageno with
6074 if tileready l l.pagex
l.pagey
6076 let x = l.pagedispx - l.pagex
6077 and y = l.pagedispy - l.pagey in
6079 match conf.columns
with
6080 | Csingle
_ | Cmulti
_ ->
6081 (if conf.hlinks
then 1 else 0)
6083 && not
(isbirdseye state.mode) then 2 else 0)
6087 match state.mode with
6088 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6091 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6096 let scrollindicator () =
6097 let sbw, ph
, sh = state.uioh#
scrollph in
6098 let sbh, pw, sw = state.uioh#scrollpw
in
6100 GlDraw.color (0.64, 0.64, 0.64);
6102 (float (state.winw
- sbw)) 0.
6103 (float state.winw
) (float state.winh
)
6106 0. (float (state.winh
- sbh))
6107 (float (wadjsb state.winw
- 1)) (float state.winh
)
6109 GlDraw.color (0.0, 0.0, 0.0);
6112 (float (state.winw
- sbw)) ph
6113 (float state.winw
) (ph
+. sh)
6116 pw (float (state.winh
- sbh))
6117 (pw +. sw) (float state.winh
)
6122 match state.mstate
with
6123 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6126 | Msel
((x0, y0), (x1, y1)) ->
6127 let rec loop = function
6129 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6130 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6131 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6132 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6134 match getopaque l.pageno with
6136 let x0, y0 = pagetranslatepoint l x0 y0 in
6137 let x1, y1 = pagetranslatepoint l x1 y1 in
6138 seltext opaque
(x0, y0, x1, y1);
6146 let showrects = function [] -> () | rects
->
6148 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6149 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6151 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6153 if l.pageno = pageno
6155 let dx = float (l.pagedispx - l.pagex
) in
6156 let dy = float (l.pagedispy - l.pagey) in
6157 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6158 Raw.sets_float
state.vraw ~pos
:0
6163 GlArray.vertex `two
state.vraw
;
6164 GlArray.draw_arrays `triangle_strip
0 4;
6173 GlClear.color (scalecolor2 conf.bgcolor
);
6174 GlClear.clear
[`
color];
6175 List.iter
drawpage state.layout;
6177 match state.mode with
6178 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6179 begin match getopaque pageno with
6181 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6188 | None
-> state.rects
6193 let rec postloop linkindexbase
= function
6195 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6196 postloop linkindexbase rest
6200 postloop 0 state.layout;
6202 begin match state.mstate
with
6203 | Mzoomrect
((x0, y0), (x1, y1)) ->
6205 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6206 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6207 filledrect (float x0) (float y0) (float x1) (float y1);
6216 let zoomrect x y x1 y1 =
6219 and y0 = min
y y1 in
6220 gotoy (state.y + y0);
6221 state.anchor <- getanchor ();
6222 let zoom = (float state.w) /. float (x1 - x0) in
6224 match conf.fitmodel
, conf.columns
with
6225 | FitPage
, Csplit
_ ->
6226 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6229 let adjw = wadjsb state.winw
in
6231 then (adjw - state.w) / 2
6234 state.x <- (state.x + margin) - x0;
6236 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6237 state.mstate
<- Mnone
;
6241 let g opaque
l px py =
6242 match rectofblock opaque
px py with
6244 let x0 = a.(0) -. 20. in
6245 let x1 = a.(1) +. 20. in
6246 let y0 = a.(2) -. 20. in
6247 let zoom = (float state.w) /. (x1 -. x0) in
6248 let pagey = getpagey l.pageno in
6249 gotoy_and_clear_text (pagey + truncate
y0);
6250 state.anchor <- getanchor ();
6251 let margin = (state.w - l.pagew
)/2 in
6252 state.x <- -truncate
x0 - margin;
6257 match conf.columns
with
6259 showtext '
!'
"block zooming does not work properly in split columns mode"
6260 | _ -> onppundermouse g x y ()
6264 let winw = wadjsb state.winw - 1 in
6265 let s = float x /. float winw in
6266 let destx = truncate
(float (state.w + winw) *. s) in
6267 state.x <- winw - destx;
6268 gotoy_and_clear_text state.y;
6269 state.mstate
<- Mscrollx
;
6273 let s = float y /. float state.winh
in
6274 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6275 gotoy_and_clear_text desty;
6276 state.mstate
<- Mscrolly
;
6279 let viewmouse button down
x y mask
=
6281 | n when (n == 4 || n == 5) && not down
->
6282 if Wsi.withctrl mask
6284 match state.mstate
with
6285 | Mzoom
(oldn
, i
) ->
6293 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6295 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6297 let zoom = conf.zoom -. incr in
6299 state.mstate
<- Mzoom
(n, 0);
6301 state.mstate
<- Mzoom
(n, i
+1);
6303 else state.mstate
<- Mzoom
(n, 0)
6305 | _ -> state.mstate
<- Mzoom
(n, 0)
6308 match state.autoscroll
with
6309 | Some step
-> setautoscrollspeed step
(n=4)
6311 if conf.wheelbypage
|| conf.presentation
6320 then -conf.scrollstep
6321 else conf.scrollstep
6323 let incr = incr * 2 in
6324 let y = clamp incr in
6325 gotoy_and_clear_text y
6328 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6330 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6331 gotoy_and_clear_text state.y
6333 | 1 when Wsi.withshift mask
->
6334 state.mstate
<- Mnone
;
6337 match unproject x y with
6338 | Some
(pageno, ux
, uy
) ->
6339 let cmd = Printf.sprintf
6341 conf.stcmd
state.path pageno ux uy
6347 | 1 when Wsi.withctrl mask
->
6350 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6351 state.mstate
<- Mpan
(x, y)
6354 state.mstate
<- Mnone
6359 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6361 state.mstate
<- Mzoomrect
(p, p)
6364 match state.mstate
with
6365 | Mzoomrect
((x0, y0), _) ->
6366 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6367 then zoomrect x0 y0 x y
6369 state.mstate
<- Mnone
;
6370 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6371 G.postRedisplay "kill accidental zoom rect";
6374 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6375 state.mstate
<- Mnone
6378 | 1 when x > state.winw - vscrollw () ->
6381 let _, position, sh = state.uioh#
scrollph in
6382 if y > truncate
position && y < truncate
(position +. sh)
6383 then state.mstate
<- Mscrolly
6386 state.mstate
<- Mnone
6388 | 1 when y > state.winh
- hscrollh () ->
6391 let _, position, sw = state.uioh#scrollpw
in
6392 if x > truncate
position && x < truncate
(position +. sw)
6393 then state.mstate
<- Mscrollx
6396 state.mstate
<- Mnone
6398 | 1 when state.bzoom
-> if not down
then zoomblock x y
6401 let dest = if down
then getunder x y else Unone
in
6402 begin match dest with
6405 | Uremote
_ | Uremotedest
_
6406 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6409 | Unone
when down
->
6410 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6411 state.mstate
<- Mpan
(x, y);
6413 | Unone
| Utext
_ ->
6416 if conf.angle
mod 360 = 0
6418 state.mstate
<- Msel
((x, y), (x, y));
6419 G.postRedisplay "mouse select";
6423 match state.mstate
with
6426 | Mzoom
_ | Mscrollx
| Mscrolly
->
6427 state.mstate
<- Mnone
6429 | Mzoomrect
((x0, y0), _) ->
6433 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6434 state.mstate
<- Mnone
6436 | Msel
((x0, y0), (x1, y1)) ->
6437 let rec loop = function
6441 let a0 = l.pagedispy in
6442 let a1 = a0 + l.pagevh in
6443 let b0 = l.pagedispx in
6444 let b1 = b0 + l.pagevw in
6445 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6446 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6450 match getopaque l.pageno with
6453 match Ne.pipe () with
6457 "can not create sel pipe: %s"
6460 let doclose what fd
=
6461 Ne.clo fd
(fun msg
->
6462 dolog
"%s close failed: %s" what msg
)
6465 popen conf.selcmd
[r, 0; w, -1];
6466 copysel
w opaque
true;
6468 G.postRedisplay "copysel";
6470 dolog
"can not execute %S: %s"
6471 conf.selcmd
(exntos exn
);
6479 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6480 state.mstate
<- Mnone
;
6487 let birdseyemouse button down
x y mask
6488 (conf, leftx
, _, hooverpageno
, anchor) =
6491 let rec loop = function
6494 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6495 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6497 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6503 | _ -> viewmouse button down
x y mask
6509 method key key mask
=
6510 begin match state.mode with
6511 | Textentry
textentry -> textentrykeyboard key mask
textentry
6512 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6513 | View
-> viewkeyboard key mask
6514 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6518 method button button bstate
x y mask
=
6519 begin match state.mode with
6521 | View
-> viewmouse button bstate
x y mask
6522 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6528 begin match state.mode with
6530 | View
| Birdseye
_ | LinkNav
_ ->
6531 match state.mstate
with
6532 | Mzoom
_ | Mnone
-> ()
6537 state.mstate
<- Mpan
(x, y);
6539 then state.x <- panbound (state.x + dx);
6541 gotoy_and_clear_text y
6544 state.mstate
<- Msel
(a, (x, y));
6545 G.postRedisplay "motion select";
6548 let y = min
state.winh
(max
0 y) in
6552 let x = min
state.winw (max
0 x) in
6555 | Mzoomrect
(p0
, _) ->
6556 state.mstate
<- Mzoomrect
(p0
, (x, y));
6557 G.postRedisplay "motion zoomrect";
6561 method pmotion
x y =
6562 begin match state.mode with
6563 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6564 let rec loop = function
6566 if hooverpageno
!= -1
6568 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6569 G.postRedisplay "pmotion birdseye no hoover";
6572 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6573 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6575 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6576 G.postRedisplay "pmotion birdseye hoover";
6586 match state.mstate
with
6587 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6594 let past, _, _ = !r in
6596 let delta = now -. past in
6599 else r := (now, x, y)
6603 method infochanged
_ = ()
6606 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6609 then 0.0, float state.winh
6610 else scrollph state.y maxy
6615 let winw = wadjsb state.winw in
6616 let fwinw = float winw in
6618 let sw = fwinw /. float state.w in
6619 let sw = fwinw *. sw in
6620 max
sw (float conf.scrollh
)
6623 let maxx = state.w + winw in
6624 let x = winw - state.x in
6625 let percent = float x /. float maxx in
6626 (fwinw -. sw) *. percent
6628 hscrollh (), position, sw
6632 match state.mode with
6633 | LinkNav
_ -> "links"
6634 | Textentry
_ -> "textentry"
6635 | Birdseye
_ -> "birdseye"
6638 findkeyhash conf modename
6640 method eformsgs
= true
6647 let fontpath = ref "";;
6650 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6653 let l = String.length
s in
6654 let b = Buffer.create
l in
6660 try Sys.getenv
"HOME"
6663 ("Can not determine home directory location: " ^ exntos exn
);
6667 let modifier_of_string = function
6668 | "alt" -> Wsi.altmask
6669 | "shift" -> Wsi.shiftmask
6670 | "ctrl" | "control" -> Wsi.ctrlmask
6671 | "meta" -> Wsi.metamask
6676 let r = Str.regexp
"-" in
6678 let elems = Str.full_split
r s in
6681 let m1 = modifier_of_string s in
6683 then (Wsi.namekey
s, m)
6686 | Str.Delim
s when n land 1 = 0 -> g s
6688 | Str.Delim
_ -> (k
, m)
6690 let rec loop n k
m = function
6693 let k, m = f n k m x in
6699 let keys_of_string =
6700 let r = Str.regexp
"[ \t]" in
6702 let elems = Str.split
r s in
6703 List.map
key_of_string elems
6706 let copykeyhashes c =
6707 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6710 let config_of c attrs
=
6714 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6715 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6716 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6717 | "preload" -> { c with preload = bool_of_string
v }
6718 | "page-bias" -> { c with pagebias
= int_of_string
v }
6719 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6720 | "horizontal-scroll-step" ->
6721 { c with hscrollstep
= max
(int_of_string
v) 1 }
6722 | "auto-scroll-step" ->
6723 { c with autoscrollstep
= max
0 (int_of_string
v) }
6724 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6725 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6728 match String.lowercase
v with
6729 | "true" -> Some infinity
6731 | f -> Some
(float_of_string
f)
6733 { c with maxwait
= mw}
6734 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6735 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6736 | "vertical-margin" ->
6737 { c with interpagespace
= max
0 (int_of_string
v) }
6739 let zoom = float_of_string
v /. 100. in
6740 let zoom = max
zoom 0.0 in
6741 { c with zoom = zoom }
6742 | "presentation" -> { c with presentation
= bool_of_string
v }
6743 | "rotation-angle" -> { c with angle
= int_of_string
v }
6744 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6745 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6746 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6747 | "proportional-display" ->
6750 then FitProportional
6753 { c with fitmodel
= fm }
6754 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6755 | "pixmap-cache-size" ->
6756 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6757 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6758 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6759 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6760 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6761 | "background-color" -> { c with bgcolor
= color_of_string v }
6762 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6763 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6764 | "mupdf-store-size" ->
6765 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6766 | "checkers" -> { c with checkers
= bool_of_string
v }
6767 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6768 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6769 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6770 | "uri-launcher" -> { c with urilauncher
= unent v }
6771 | "path-launcher" -> { c with pathlauncher
= unent v }
6772 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6773 | "invert-colors" -> { c with invert
= bool_of_string
v }
6774 | "brightness" -> { c with colorscale
= float_of_string
v }
6775 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6776 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6778 let (n, _, _) as nab
= multicolumns_of_string v in
6780 then { c with columns
= Csplit
(-n, [||]) }
6781 else { c with columns
= Cmulti
(nab
, [||]) }
6782 | "birds-eye-columns" ->
6783 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6784 | "selection-command" -> { c with selcmd
= unent v }
6785 | "synctex-command" -> { c with stcmd
= unent v }
6786 | "pax-command" -> { c with paxcmd
= unent v }
6787 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6788 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6789 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6790 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6791 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6792 | "horizontal-scrollbar-visible" ->
6795 then c.scrollb
lor scrollbhv
6796 else c.scrollb
land (lnot
scrollbhv)
6798 { c with scrollb
= b }
6799 | "vertical-scrollbar-visible" ->
6802 then c.scrollb
lor scrollbvv
6803 else c.scrollb
land (lnot
scrollbvv)
6805 { c with scrollb
= b }
6806 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6810 then Some
(ref (0.0, 0, 0))
6812 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6815 prerr_endline
("Error processing attribute (`" ^
6816 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6819 let rec fold c = function
6822 let c = apply c k v in
6825 fold { c with keyhashes
= copykeyhashes c } attrs
;
6828 let fromstring f pos
n v d =
6831 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6832 n v pos
(exntos exn
)
6837 let bookmark_of attrs
=
6838 let rec fold title page
rely visy
= function
6839 | ("title", v) :: rest
-> fold v page
rely visy rest
6840 | ("page", v) :: rest
-> fold title v rely visy rest
6841 | ("rely", v) :: rest
-> fold title page
v visy rest
6842 | ("visy", v) :: rest
-> fold title page
rely v rest
6843 | _ :: rest
-> fold title page
rely visy rest
6844 | [] -> title, page
, rely, visy
6846 fold "invalid" "0" "0" "0" attrs
6850 let rec fold path page
rely pan visy
= function
6851 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6852 | ("page", v) :: rest
-> fold path v rely pan visy rest
6853 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6854 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6855 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6856 | _ :: rest
-> fold path page
rely pan visy rest
6857 | [] -> path, page
, rely, pan
, visy
6859 fold "" "0" "0" "0" "0" attrs
6863 let rec fold rs ls
= function
6864 | ("out", v) :: rest
-> fold v ls rest
6865 | ("in", v) :: rest
-> fold rs
v rest
6866 | _ :: rest
-> fold ls rs rest
6872 let setconf dst
src =
6873 dst
.scrollbw
<- src.scrollbw
;
6874 dst
.scrollh
<- src.scrollh
;
6875 dst
.icase
<- src.icase
;
6876 dst
.preload <- src.preload;
6877 dst
.pagebias
<- src.pagebias
;
6878 dst
.verbose
<- src.verbose
;
6879 dst
.scrollstep
<- src.scrollstep
;
6880 dst
.maxhfit
<- src.maxhfit
;
6881 dst
.crophack
<- src.crophack
;
6882 dst
.autoscrollstep
<- src.autoscrollstep
;
6883 dst
.maxwait
<- src.maxwait
;
6884 dst
.hlinks
<- src.hlinks
;
6885 dst
.underinfo
<- src.underinfo
;
6886 dst
.interpagespace
<- src.interpagespace
;
6887 dst
.zoom <- src.zoom;
6888 dst
.presentation
<- src.presentation
;
6889 dst
.angle
<- src.angle
;
6890 dst
.cwinw
<- src.cwinw
;
6891 dst
.cwinh
<- src.cwinh
;
6892 dst
.savebmarks
<- src.savebmarks
;
6893 dst
.memlimit
<- src.memlimit
;
6894 dst
.fitmodel
<- src.fitmodel
;
6895 dst
.texcount
<- src.texcount
;
6896 dst
.sliceheight
<- src.sliceheight
;
6897 dst
.thumbw
<- src.thumbw
;
6898 dst
.jumpback
<- src.jumpback
;
6899 dst
.bgcolor
<- src.bgcolor
;
6900 dst
.tilew
<- src.tilew
;
6901 dst
.tileh
<- src.tileh
;
6902 dst
.mustoresize
<- src.mustoresize
;
6903 dst
.checkers
<- src.checkers
;
6904 dst
.aalevel
<- src.aalevel
;
6905 dst
.trimmargins
<- src.trimmargins
;
6906 dst
.trimfuzz
<- src.trimfuzz
;
6907 dst
.urilauncher
<- src.urilauncher
;
6908 dst
.colorspace
<- src.colorspace
;
6909 dst
.invert
<- src.invert
;
6910 dst
.colorscale
<- src.colorscale
;
6911 dst
.redirectstderr <- src.redirectstderr;
6912 dst
.ghyllscroll
<- src.ghyllscroll
;
6913 dst
.columns
<- src.columns
;
6914 dst
.beyecolumns
<- src.beyecolumns
;
6915 dst
.selcmd
<- src.selcmd
;
6916 dst
.updatecurs
<- src.updatecurs
;
6917 dst
.pathlauncher
<- src.pathlauncher
;
6918 dst
.keyhashes
<- copykeyhashes src;
6919 dst
.hfsize
<- src.hfsize
;
6920 dst
.hscrollstep
<- src.hscrollstep
;
6921 dst
.pgscale <- src.pgscale;
6922 dst
.usepbo
<- src.usepbo
;
6923 dst
.wheelbypage
<- src.wheelbypage
;
6924 dst
.stcmd
<- src.stcmd
;
6925 dst
.paxcmd
<- src.paxcmd
;
6926 dst
.scrollb
<- src.scrollb
;
6927 dst
.riani
<- src.riani
;
6928 dst
.paxmark
<- src.paxmark
;
6932 else Some
((ref (0.0, 0, 0)));
6936 let h = Hashtbl.create
10 in
6937 let dc = { defconf with angle
= defconf.angle
} in
6938 let rec toplevel v t spos
_ =
6940 | Vdata
| Vcdata
| Vend
-> v
6941 | Vopen
("llppconfig", _, closed
) ->
6944 else { v with f = llppconfig
}
6946 error
"unexpected subelement at top level" s spos
6947 | Vclose
_ -> error
"unexpected close at top level" s spos
6949 and llppconfig
v t spos
_ =
6951 | Vdata
| Vcdata
-> v
6952 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6953 | Vopen
("defaults", attrs
, closed
) ->
6954 let c = config_of dc attrs
in
6958 else { v with f = defaults
}
6960 | Vopen
("ui-font", attrs
, closed
) ->
6961 let rec getsize size
= function
6963 | ("size", v) :: rest
->
6965 fromstring int_of_string spos
"size" v fstate.fontsize
in
6967 | l -> getsize size l
6969 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6972 else { v with f = uifont
(Buffer.create
10) }
6974 | Vopen
("doc", attrs
, closed
) ->
6975 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6976 let path = unent pathent
6977 and pageno = fromstring int_of_string spos
"page" spage
0
6978 and rely = fromstring float_of_string spos
"rely" srely
0.0
6979 and pan
= fromstring int_of_string spos
"pan" span
0
6980 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6981 let c = config_of dc attrs
in
6982 let anchor = (pageno, rely, visy
) in
6984 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6985 else { v with f = doc
path pan
anchor c [] }
6988 error
"unexpected subelement in llppconfig" s spos
6990 | Vclose
"llppconfig" -> { v with f = toplevel }
6991 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6993 and defaults
v t spos
_ =
6995 | Vdata
| Vcdata
-> v
6996 | Vend
-> error
"unexpected end of input in defaults" s spos
6997 | Vopen
("keymap", attrs
, closed
) ->
6999 try List.assoc
"mode" attrs
7000 with Not_found
-> "global" in
7005 let h = findkeyhash dc modename in
7006 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7009 { v with f = pkeymap
ret KeyMap.empty }
7011 | Vopen
(_, _, _) ->
7012 error
"unexpected subelement in defaults" s spos
7014 | Vclose
"defaults" ->
7015 { v with f = llppconfig
}
7017 | Vclose
_ -> error
"unexpected close in defaults" s spos
7019 and uifont
b v t spos
epos =
7022 Buffer.add_substring
b s spos
(epos - spos
);
7024 | Vopen
(_, _, _) ->
7025 error
"unexpected subelement in ui-font" s spos
7026 | Vclose
"ui-font" ->
7027 if emptystr
!fontpath
7028 then fontpath := Buffer.contents
b;
7029 { v with f = llppconfig
}
7030 | Vclose
_ -> error
"unexpected close in ui-font" s spos
7031 | Vend
-> error
"unexpected end of input in ui-font" s spos
7033 and doc
path pan
anchor c bookmarks
v t spos
_ =
7035 | Vdata
| Vcdata
-> v
7036 | Vend
-> error
"unexpected end of input in doc" s spos
7037 | Vopen
("bookmarks", _, closed
) ->
7040 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
7042 | Vopen
("keymap", attrs
, closed
) ->
7044 try List.assoc
"mode" attrs
7045 with Not_found
-> "global"
7051 let h = findkeyhash c modename in
7052 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7053 doc
path pan
anchor c bookmarks
7055 { v with f = pkeymap
ret KeyMap.empty }
7057 | Vopen
(_, _, _) ->
7058 error
"unexpected subelement in doc" s spos
7061 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7062 { v with f = llppconfig
}
7064 | Vclose
_ -> error
"unexpected close in doc" s spos
7066 and pkeymap
ret keymap
v t spos
_ =
7068 | Vdata
| Vcdata
-> v
7069 | Vend
-> error
"unexpected end of input in keymap" s spos
7070 | Vopen
("map", attrs
, closed
) ->
7071 let r, l = map_of attrs
in
7072 let kss = fromstring keys_of_string spos
"in" r [] in
7073 let lss = fromstring keys_of_string spos
"out" l [] in
7077 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7078 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7081 then { v with f = pkeymap
ret keymap }
7084 { v with f = skip
"map" f }
7087 error
"unexpected subelement in keymap" s spos
7089 | Vclose
"keymap" ->
7090 { v with f = ret keymap }
7092 | Vclose
_ -> error
"unexpected close in keymap" s spos
7094 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7096 | Vdata
| Vcdata
-> v
7097 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7098 | Vopen
("item", attrs
, closed
) ->
7099 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7100 let page = fromstring int_of_string spos
"page" spage
0
7101 and rely = fromstring float_of_string spos
"rely" srely
0.0
7102 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7104 (unent titleent, 0, Oanchor
(page, rely, visy
)) :: bookmarks
7107 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7110 { v with f = skip
"item" f }
7113 error
"unexpected subelement in bookmarks" s spos
7115 | Vclose
"bookmarks" ->
7116 { v with f = doc
path pan
anchor c bookmarks }
7118 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7120 and skip tag
f v t spos
_ =
7122 | Vdata
| Vcdata
-> v
7124 error
("unexpected end of input in skipped " ^ tag
) s spos
7125 | Vopen
(tag'
, _, closed
) ->
7129 let f'
() = { v with f = skip tag
f } in
7130 { v with f = skip tag'
f'
}
7134 else error
("unexpected close in skipped " ^ tag
) s spos
7137 parse
{ f = toplevel; accu = () } s;
7143 let len = in_channel_length ic
in
7144 let s = String.create
len in
7145 really_input ic
s 0 len;
7148 | Parse_error
(msg
, s, pos
) ->
7149 let subs = subs s pos
in
7150 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7153 failwith
("config load error: " ^ exntos exn
)
7159 let dir = Filename.concat
home ".config" in
7160 if Sys.is_directory
dir then dir else home
7163 Filename.concat
dir "llpp.conf"
7166 let confpath = ref defconfpath;;
7169 if Sys.file_exists
!confpath
7172 (try Some
(open_in_bin
!confpath)
7175 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7186 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7195 f (Hashtbl.create
0, defconf)
7200 let pc, pb
, px, pa
=
7203 if emptystr
state.origin
7207 Hashtbl.find h (Filename.basename
key)
7208 with Not_found
-> dc, [], 0, emptyanchor
7212 state.bookmarks <- pb
;
7215 then state.anchor <- pa
;
7216 cbput state.hists
.nav pa
;
7222 let add_attrs bb always
dc c =
7225 then Printf.bprintf bb
"\n %s='%b'" s a
7228 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7231 then Printf.bprintf bb
"\n %s='%d'" s a
7234 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7237 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7240 then Printf.bprintf bb
"\n %s='%f'" s a
7244 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7248 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7252 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7256 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7261 | Some
(_N
, _A
, _B
) ->
7262 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7267 Printf.bprintf bb
"\n %s='none'" s
7277 else string_of_float
f
7279 Printf.bprintf bb
"\n %s='%s'" s v
7284 | Cmulti
((n, a, b), _) when n > 1 ->
7285 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7286 | Csplit
(n, _) when n > 1 ->
7287 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7293 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7298 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7302 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7306 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7308 oi
"width" c.cwinw
dc.cwinw
;
7309 oi
"height" c.cwinh
dc.cwinh
;
7310 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7311 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7312 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7313 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7314 ob "case-insensitive-search" c.icase
dc.icase
;
7315 ob "preload" c.preload dc.preload;
7316 oi
"page-bias" c.pagebias
dc.pagebias
;
7317 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7318 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7319 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7320 ob "crop-hack" c.crophack
dc.crophack
;
7321 oW
"throttle" c.maxwait
dc.maxwait
;
7322 ob "highlight-links" c.hlinks
dc.hlinks
;
7323 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7324 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7325 oz
"zoom" c.zoom dc.zoom;
7326 ob "presentation" c.presentation
dc.presentation
;
7327 oi
"rotation-angle" c.angle
dc.angle
;
7328 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7329 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7330 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7331 oi
"tex-count" c.texcount
dc.texcount
;
7332 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7333 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7334 ob "persistent-location" c.jumpback
dc.jumpback
;
7335 oc
"background-color" c.bgcolor
dc.bgcolor
;
7336 oi
"tile-width" c.tilew
dc.tilew
;
7337 oi
"tile-height" c.tileh
dc.tileh
;
7338 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7339 ob "checkers" c.checkers
dc.checkers
;
7340 oi
"aalevel" c.aalevel
dc.aalevel
;
7341 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7342 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7343 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7344 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7345 oC
"color-space" c.colorspace
dc.colorspace
;
7346 ob "invert-colors" c.invert
dc.invert
;
7347 oF
"brightness" c.colorscale
dc.colorscale
;
7348 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7349 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7350 oco
"columns" c.columns
dc.columns
;
7351 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7352 os
"selection-command" c.selcmd
dc.selcmd
;
7353 os
"synctex-command" c.stcmd
dc.stcmd
;
7354 os
"pax-command" c.paxcmd
dc.paxcmd
;
7355 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7356 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7357 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7358 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7359 ob "use-pbo" c.usepbo
dc.usepbo
;
7360 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7361 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7362 op
"point-and-x" c.pax
dc.pax
;
7363 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7366 let keymapsbuf always
dc c =
7367 let bb = Buffer.create
16 in
7368 let rec loop = function
7370 | (modename, h) :: rest
->
7371 let dh = findkeyhash dc modename in
7372 if always
|| h <> dh
7374 if Hashtbl.length
h > 0
7376 if Buffer.length
bb > 0
7377 then Buffer.add_char
bb '
\n'
;
7378 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7379 Hashtbl.iter
(fun i
o ->
7380 let isdifferent = always
||
7382 let dO = Hashtbl.find dh i
in
7384 with Not_found
-> true
7389 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7390 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7391 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7392 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7393 Buffer.add_string
bb (Wsi.keyname
k);
7396 let rec loop = function
7398 | km
:: [] -> addkm km
7399 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7403 Buffer.add_string
bb "<map in='";
7407 Buffer.add_string
bb "' out='";
7409 Buffer.add_string
bb "'/>\n"
7412 Buffer.add_string
bb "' out='";
7414 Buffer.add_string
bb "'/>\n"
7416 | KMmulti
(ins, kms
) ->
7417 Buffer.add_char
bb ' '
;
7419 Buffer.add_string
bb "' out='";
7421 Buffer.add_string
bb "'/>\n"
7423 Buffer.add_string
bb "</keymap>";
7433 let uifontsize = fstate.fontsize
in
7434 let bb = Buffer.create
32768 in
7435 let relx = float state.x /. float state.winw in
7437 let cx w = truncate
(relx *. float w) in
7439 (fun (w, h, x) ws
->
7441 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7442 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7443 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7445 (state.winw, state.winh
, state.x) state.winstate
7450 let dc = if conf.bedefault
then conf else dc in
7451 Buffer.add_string
bb "<llppconfig>\n";
7453 if nonemptystr
!fontpath
7455 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7461 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7464 Buffer.add_string
bb "<defaults";
7465 add_attrs bb true dc dc;
7466 let kb = keymapsbuf true dc dc in
7467 if Buffer.length
kb > 0
7469 Buffer.add_string
bb ">\n";
7470 Buffer.add_buffer
bb kb;
7471 Buffer.add_string
bb "\n</defaults>\n";
7473 else Buffer.add_string
bb "/>\n";
7475 let adddoc path pan
anchor c bookmarks =
7476 if bookmarks == [] && c = dc && anchor = emptyanchor
7479 Printf.bprintf
bb "<doc path='%s'"
7480 (enent
path 0 (String.length
path));
7482 if anchor <> emptyanchor
7484 let n, rely, visy
= anchor in
7485 Printf.bprintf
bb " page='%d'" n;
7488 Printf.bprintf
bb " rely='%f'" rely
7490 if abs_float visy
> 1e-6
7492 Printf.bprintf
bb " visy='%f'" visy
7497 then Printf.bprintf
bb " pan='%d'" pan
;
7499 add_attrs bb false dc c;
7500 let kb = keymapsbuf false dc c in
7502 begin match bookmarks with
7504 if Buffer.length
kb > 0
7506 Buffer.add_string
bb ">\n";
7507 Buffer.add_buffer
bb kb;
7508 Buffer.add_string
bb "\n</doc>\n";
7510 else Buffer.add_string
bb "/>\n"
7512 Buffer.add_string
bb ">\n<bookmarks>\n";
7513 List.iter
(fun (title, _, kind
) ->
7514 begin match kind
with
7515 | Oanchor
(page, rely, visy
) ->
7517 "<item title='%s' page='%d'"
7518 (enent
title 0 (String.length
title))
7523 Printf.bprintf
bb " rely='%f'" rely
7525 if abs_float visy
> 1e-6
7527 Printf.bprintf
bb " visy='%f'" visy
7529 | Onone
| Ouri
_ | Oremote
_ | Oremotedest
_ | Olaunch
_ ->
7530 failwith
"unexpected link in bookmarks"
7532 Buffer.add_string
bb "/>\n";
7534 Buffer.add_string
bb "</bookmarks>";
7535 if Buffer.length
kb > 0
7537 Buffer.add_string
bb "\n";
7538 Buffer.add_buffer
bb kb;
7540 Buffer.add_string
bb "\n</doc>\n";
7546 match state.mode with
7547 | Birdseye
(c, pan, _, _, _) ->
7549 match conf.columns
with
7550 | Cmulti
((c, _, _), _) -> Some
c
7554 match c.columns
with
7555 | Cmulti
(c, _) -> Cmulti
(c, [||])
7556 | Csingle
_ -> Csingle
[||]
7557 | Csplit
_ -> failwith
"quit from bird's eye while split"
7559 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7562 let basename = Filename.basename
7563 (if emptystr
state.origin
then state.path else state.origin
)
7565 adddoc basename pan (getanchor ())
7567 let autoscrollstep =
7568 match state.autoscroll
with
7570 | None
-> conf.autoscrollstep
7572 match state.mode with
7573 | Birdseye
(bc
, _, _, _, _) ->
7576 presentation
= bc
.presentation
;
7577 interpagespace
= bc
.interpagespace
;
7578 maxwait
= bc
.maxwait
;
7579 autoscrollstep = autoscrollstep }
7580 | _ -> { conf with autoscrollstep = autoscrollstep }
7582 (if conf.savebmarks
then state.bookmarks else []);
7584 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7586 then adddoc path x anchor c bookmarks
7588 Buffer.add_string
bb "</llppconfig>\n";
7591 if load1 f && Buffer.length
bb > 0
7594 let tmp = !confpath ^
".tmp" in
7595 let oc = open_out_bin
tmp in
7596 Buffer.output_buffer
oc bb;
7598 Unix.rename
tmp !confpath;
7601 ("error while saving configuration: " ^ exntos exn
)
7605 let adderrmsg src msg
=
7606 Buffer.add_string
state.errmsgs msg
;
7607 state.newerrmsgs
<- true;
7611 let adderrfmt src fmt
=
7612 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7616 let cl = splitatspace cmds
in
7618 try Scanf.sscanf
s fmt
f
7620 adderrfmt "remote exec"
7621 "error processing '%S': %s\n" cmds
(exntos exn
)
7624 | "reload" :: [] -> reload ()
7625 | "goto" :: args :: [] ->
7626 scan args "%u %f %f"
7628 let cmd, _ = state.geomcmds
in
7630 then gotopagexy pageno x y
7633 gotopagexy pageno x y;
7636 state.reprf
<- f state.reprf
7638 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7639 | "gotor" :: args :: [] ->
7641 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
7642 | "gotord" :: args :: [] ->
7644 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
7645 | "rect" :: args :: [] ->
7646 scan args "%u %u %f %f %f %f"
7647 (fun pageno color x0 y0 x1 y1 ->
7648 onpagerect pageno (fun w h ->
7649 let _,w1,h1
,_ = getpagedim pageno in
7650 let sw = float w1 /. float w
7651 and sh = float h1
/. float h in
7655 and y1s
= y1 *. sh in
7656 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7658 state.rects <- (pageno, color, rect) :: state.rects;
7659 G.postRedisplay "rect";
7662 | "activatewin" :: [] -> Wsi.activatewin
()
7663 | "quit" :: [] -> raise Quit
7665 adderrfmt "remote command"
7666 "error processing remote command: %S\n" cmds
;
7670 let scratch = String.create
80 in
7671 let buf = Buffer.create
80 in
7674 try Some
(Unix.read fd
scratch 0 80)
7676 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7677 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7680 match tempfr () with
7686 if Buffer.length
buf > 0
7688 let s = Buffer.contents
buf in
7698 let pos = String.index_from
scratch ppos '
\n'
in
7699 if pos >= n then -1 else pos
7700 with Not_found
-> -1
7704 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7705 let s = Buffer.contents
buf in
7711 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7717 let remoteopen path =
7718 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7720 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7725 let trimcachepath = ref "" in
7726 let rcmdpath = ref "" in
7727 let pageno = ref None
in
7728 selfexec := Sys.executable_name
;
7731 [("-p", Arg.String
(fun s -> state.password
<- s),
7732 "<password> Set password");
7736 Config.fontpath := s;
7737 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7739 "<path> Set path to the user interface font");
7743 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7744 Config.confpath := s),
7745 "<path> Set path to the configuration file");
7747 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
7748 "<page-number> Jump to page");
7750 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7751 "<path> Set path to the trim cache file");
7753 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7754 "<named-destination> Set named destination");
7756 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7757 ("-cxack", Arg.Set
cxack, " Cut corners");
7759 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7760 "<path> Set path to the remote commands source");
7762 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7763 "<original-path> Set original path");
7765 ("-v", Arg.Unit
(fun () ->
7767 "%s\nconfiguration path: %s\n"
7771 exit
0), " Print version and exit");
7774 (fun s -> state.path <- s)
7775 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7778 then selfexec := !selfexec ^
" -wtmode";
7780 if emptystr
state.path
7781 then (prerr_endline
"file name missing"; exit
1);
7783 if not
(Config.load ())
7784 then prerr_endline
"failed to load configuration";
7785 begin match !pageno with
7786 | Some
pageno -> state.anchor <- (pageno, 0.0, 0.0)
7790 let wsfd, winw, winh
= Wsi.init
(object
7791 val mutable m_hack
= false
7792 method expose
= if not m_hack
then G.postRedisplay "expose"
7793 method visible
= G.postRedisplay "visible"
7794 method display = m_hack
<- false; display ()
7795 method reshape w h =
7796 m_hack
<- w < state.winw && h < state.winh
;
7798 method mouse
b d x y m = state.uioh <- state.uioh#button
b d x y m
7800 state.mpos
<- (x, y);
7801 state.uioh <- state.uioh#motion
x y
7802 method pmotion
x y =
7803 state.mpos
<- (x, y);
7804 state.uioh <- state.uioh#pmotion
x y
7806 let mascm = m land (
7807 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7809 match state.keystate
with
7811 let km = k, mascm in
7814 let modehash = state.uioh#
modehash in
7815 try Hashtbl.find modehash km
7817 try Hashtbl.find (findkeyhash conf "global") km
7818 with Not_found
-> KMinsrt
(k, m)
7820 | KMinsrt
(k, m) -> keyboard k m
7821 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7822 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7824 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7825 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7826 state.keystate
<- KSnone
7827 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7828 state.keystate
<- KSinto
(keys
, insrt
)
7830 state.keystate
<- KSnone
7833 state.mpos
<- (x, y);
7834 state.uioh <- state.uioh#pmotion
x y
7835 method leave = state.mpos
<- (-1, -1)
7836 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7837 method quit
= raise Quit
7838 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7843 List.exists
GlMisc.check_extension
7844 [ "GL_ARB_texture_rectangle"
7845 ; "GL_EXT_texture_recangle"
7846 ; "GL_NV_texture_rectangle" ]
7848 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7851 let r = GlMisc.get_string `renderer
in
7852 let p = "Mesa DRI Intel(" in
7853 let l = String.length
p in
7854 String.length
r > l && String.sub
r 0 l = p
7857 defconf.sliceheight
<- 1024;
7858 defconf.texcount
<- 32;
7859 defconf.usepbo
<- true;
7863 match Ne.pipe () with
7865 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7869 match Ne.pipe () with
7871 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7881 setcheckers conf.checkers
;
7883 if conf.redirectstderr
7886 let s = Buffer.contents
state.errmsgs ^
7887 (match state.errfd
with
7889 let s = String.create
(80*24) in
7892 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7894 then Unix.read fd
s 0 (String.length
s)
7900 else String.sub
s 0 n
7904 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7905 with exn
-> print_endline
(exntos exn
)
7910 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7911 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7912 !Config.fontpath, !trimcachepath,
7913 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7915 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
7918 state.text <- "Opening " ^
(mbtoutf8
state.path);
7920 opendoc state.path state.password
;
7924 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7927 if nonemptystr
!rcmdpath
7928 then remoteopen !rcmdpath
7933 let rec loop deadline
=
7935 match state.errfd
with
7936 | None
-> [state.sr
; state.wsfd]
7937 | Some fd
-> [state.sr
; state.wsfd; fd
]
7942 | Some fd
-> fd
:: r
7946 state.redisplay
<- false;
7953 if deadline
= infinity
7955 else max
0.0 (deadline
-. now)
7960 try Unix.select
r [] [] timeout
7961 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7967 if state.ghyll
== noghyll
7969 match state.autoscroll
with
7970 | Some step
when step
!= 0 ->
7971 let y = state.y + step
in
7975 else if y >= state.maxy then 0 else y
7978 if state.mode = View
7979 then state.text <- "";
7982 else deadline
+. 0.01
7987 let rec checkfds = function
7989 | fd
:: rest
when fd
= state.sr
->
7990 let cmd = readcmd state.sr
in
7994 | fd
:: rest
when fd
= state.wsfd ->
7998 | fd
:: rest
when Some fd
= !optrfd ->
7999 begin match remote fd
with
8000 | None
-> optrfd := remoteopen !rcmdpath;
8001 | opt -> optrfd := opt
8006 let s = String.create
80 in
8007 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
8008 if conf.redirectstderr
8010 Buffer.add_substring
state.errmsgs
s 0 n;
8011 state.newerrmsgs
<- true;
8012 state.redisplay
<- true;
8015 prerr_string
(String.sub
s 0 n);
8023 if deadline
= infinity
8027 match state.autoscroll
with
8028 | Some step
when step
!= 0 -> deadline1
8029 | _ -> if state.ghyll
== noghyll then infinity
else deadline1