8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
11 | Ulaunch
of launchcommand
13 | Uremote
of (filename
* pageno
)
14 | Uremotedest
of (filename
* destname
)
16 and launchcommand
= string
19 and destname
= string;;
28 type params
= (angle
* fitmodel
* trimparams
29 * texcount
* sliceheight
* memsize
30 * colorspace
* fontpath
* trimcachepath
39 and trimmargins
= bool
40 and interpagespace
= int
47 and trimcachepath
= string
50 and irect
= (int * int * int * int)
51 and trimparams
= (trimmargins
* irect
)
52 and colorspace
= | Rgb
| Bgr
| Gray
53 and fitmodel
= | FitWidth
| FitProportional
| FitPage
63 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
72 | LDfirstvisible
of (int * int * int)
87 | KMmulti
of key list
* key list
89 and keyhash
= (key
, keymap
) Hashtbl.t
92 | KSinto
of (key list
* key list
)
95 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
96 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
98 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
100 external init
: pipe
-> params
-> unit = "ml_init";;
101 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
102 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
103 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
104 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
105 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
106 external clearmark
: string -> unit = "ml_clearmark";;
107 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
108 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
109 external measurestr
: int -> string -> float = "ml_measure_string";;
110 external postprocess
:
111 opaque
-> int -> int -> int -> (int * string * int) -> int
113 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
114 external platform
: unit -> platform
= "ml_platform";;
115 external setaalevel
: int -> unit = "ml_setaalevel";;
116 external realloctexts
: int -> bool = "ml_realloctexts";;
117 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
118 external getlink
: opaque
-> int -> under
= "ml_getlink";;
119 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
120 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
121 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
122 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
123 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
124 external freepbo
: string -> unit = "ml_freepbo";;
125 external unmappbo
: string -> unit = "ml_unmappbo";;
126 external pbousable
: unit -> bool = "ml_pbo_usable";;
127 external unproject
: opaque
-> int -> int -> (int * int) option
129 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
130 external rectofblock
: opaque
-> int -> int -> float array
option
132 external fz_version
: unit -> string = "ml_fz_version";;
133 external begintiles
: unit -> unit = "ml_begintiles";;
134 external endtiles
: unit -> unit = "ml_endtiles";;
136 let platform_to_string = function
137 | Punknown
-> "unknown"
141 | Pfreebsd
-> "FreeBSD"
142 | Pdragonflybsd
-> "DragonflyBSD"
143 | Popenbsd
-> "OpenBSD"
144 | Pnetbsd
-> "NetBSD"
145 | Pcygwin
-> "Cygwin"
148 let platform = platform ();;
150 let now = Unix.gettimeofday
;;
152 let selfexec = ref "";;
155 if platform = Pcygwin
157 let sh = "/bin/sh" in
158 let args = [|sh; "-c"; cmd
|] in
159 let rec std si so se
= function
161 | (fd
, 0) :: rest
-> std fd so se rest
162 | (fd
, -1) :: rest
->
163 Unix.set_close_on_exec fd
;
166 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
168 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
169 ignore
(Unix.create_process
sh args si so se
)
174 type mpos
= int * int
176 | Msel
of (mpos
* mpos
)
178 | Mscrolly
| Mscrollx
179 | Mzoom
of (int * int)
180 | Mzoomrect
of (mpos
* mpos
)
184 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
185 and onkey
= string -> int -> te
186 and ondone
= string -> unit
187 and histcancel
= unit -> unit
188 and onhist
= ((histcmd
-> string) * histcancel
)
189 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
190 and cancelonempty
= bool
195 | TEswitch
of textentry
206 let bound v minv maxv
=
207 max minv
(min maxv v
);
211 { store
= Array.create n v
218 let cbcap b
= Array.length b
.store
;;
223 b
.wc
<- (b
.wc
+ 1) mod cap;
225 b
.len
<- min
(b
.len
+ 1) cap;
228 let cbempty b
= b
.len
= 0;;
230 let cbgetg b circular dir
=
234 let rc = b
.rc + dir
in
246 else bound rc 0 (b
.len
-1)
252 let cbget b
= cbgetg b
false;;
253 let cbgetc b
= cbgetg b
true;;
255 let drawstring size x y s
=
257 Gl.enable `texture_2d
;
258 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
259 ignore
(drawstr size x y s
);
261 Gl.disable `texture_2d
;
264 let drawstring1 size x y s
=
268 let drawstring2 size x y fmt
=
269 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
288 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
289 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
290 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
291 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
292 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
293 dolog
" column %d" l
.pagecol
;
297 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
299 dolog
" x0,y0=(% f, % f)" x0 y0
;
300 dolog
" x1,y1=(% f, % f)" x1 y1
;
301 dolog
" x2,y2=(% f, % f)" x2 y2
;
302 dolog
" x3,y3=(% f, % f)" x3 y3
;
306 type multicolumns
= multicol
* pagegeom
307 and singlecolumn
= pagegeom
308 and splitcolumns
= columncount
* pagegeom
309 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
310 and multicol
= columncount
* covercount
* covercount
312 and columncount
= int
313 and covercount
= int;;
320 { mutable scrollbw
: int
321 ; mutable scrollh
: int
322 ; mutable scrollb
: scrollb
323 ; mutable icase
: bool
324 ; mutable preload
: bool
325 ; mutable pagebias
: int
326 ; mutable verbose
: bool
327 ; mutable debug
: bool
328 ; mutable scrollstep
: int
329 ; mutable hscrollstep
: int
330 ; mutable maxhfit
: bool
331 ; mutable crophack
: bool
332 ; mutable autoscrollstep
: int
333 ; mutable maxwait
: float option
334 ; mutable hlinks
: bool
335 ; mutable underinfo
: bool
336 ; mutable interpagespace
: interpagespace
337 ; mutable zoom
: float
338 ; mutable presentation
: bool
339 ; mutable angle
: angle
340 ; mutable cwinw
: int
341 ; mutable cwinh
: int
342 ; mutable savebmarks
: bool
343 ; mutable fitmodel
: fitmodel
344 ; mutable trimmargins
: trimmargins
345 ; mutable trimfuzz
: irect
346 ; mutable memlimit
: memsize
347 ; mutable texcount
: texcount
348 ; mutable sliceheight
: sliceheight
349 ; mutable thumbw
: width
350 ; mutable jumpback
: bool
351 ; mutable bgcolor
: (float * float * float)
352 ; mutable bedefault
: bool
353 ; mutable tilew
: int
354 ; mutable tileh
: int
355 ; mutable mustoresize
: memsize
356 ; mutable checkers
: bool
357 ; mutable aalevel
: int
358 ; mutable urilauncher
: string
359 ; mutable pathlauncher
: string
360 ; mutable colorspace
: colorspace
361 ; mutable invert
: bool
362 ; mutable colorscale
: float
363 ; mutable redirectstderr
: bool
364 ; mutable ghyllscroll
: (int * int * int) option
365 ; mutable columns
: columns
366 ; mutable beyecolumns
: columncount
option
367 ; mutable selcmd
: string
368 ; mutable paxcmd
: string
369 ; mutable updatecurs
: bool
370 ; mutable keyhashes
: (string * keyhash
) list
371 ; mutable hfsize
: int
372 ; mutable pgscale
: float
373 ; mutable usepbo
: bool
374 ; mutable wheelbypage
: bool
375 ; mutable stcmd
: string
376 ; mutable riani
: bool
377 ; mutable pax
: (float * int * int) ref option
378 ; mutable paxmark
: mark
381 | Csingle
of singlecolumn
382 | Cmulti
of multicolumns
383 | Csplit
of splitcolumns
386 type anchor
= pageno
* top
* dtop
;;
392 | Olaunch
of launchcommand
393 | Oremote
of (filename
* pageno
)
394 | Oremotedest
of (filename
* destname
)
395 and outline
= (caption
* outlinelevel
* outlinekind
)
396 and outlinelevel
= int
399 type rect
= float * float * float * float * float * float * float * float;;
401 type tile
= opaque
* pixmapsize
* elapsed
402 and elapsed
= float;;
403 type pagemapkey
= pageno
* gen
;;
404 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
408 let emptyanchor = (0, 0.0, 0.0);;
410 type infochange
= | Memused
| Docinfo
| Pdim
;;
412 class type uioh
= object
413 method display
: unit
414 method key
: int -> int -> uioh
415 method button
: int -> bool -> int -> int -> int -> uioh
416 method multiclick
: int -> int -> int -> int -> uioh
417 method motion
: int -> int -> uioh
418 method pmotion
: int -> int -> uioh
419 method infochanged
: infochange
-> unit
420 method scrollpw
: (int * float * float)
421 method scrollph
: (int * float * float)
422 method modehash
: keyhash
423 method eformsgs
: bool
427 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
428 | Textentry
of (textentry
* onleave
)
430 | LinkNav
of linktarget
431 and onleave
= leavetextentrystatus
-> unit
432 and leavetextentrystatus
= | Cancel
| Confirm
433 and helpitem
= string * int * action
436 | Action
of (uioh
-> uioh
)
438 | Ltexact
of (pageno
* int)
442 let isbirdseye = function Birdseye _
-> true | _
-> false;;
443 let istextentry = function Textentry _
-> true | _
-> false;;
447 | Loading
of (page
* gen
)
449 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
451 | Outlining
of outline list
454 let emptykeyhash = Hashtbl.create
0;;
455 let nouioh : uioh
= object (self
)
457 method key _ _
= self
458 method multiclick _ _ _ _
= self
459 method button _ _ _ _ _
= self
460 method motion _ _
= self
461 method pmotion _ _
= self
462 method infochanged _
= ()
463 method scrollpw
= (0, nan
, nan
)
464 method scrollph
= (0, nan
, nan
)
465 method modehash
= emptykeyhash
466 method eformsgs
= false
470 { mutable sr
: Unix.file_descr
471 ; mutable sw
: Unix.file_descr
472 ; mutable wsfd
: Unix.file_descr
473 ; mutable errfd
: Unix.file_descr
option
474 ; mutable stderr
: Unix.file_descr
475 ; mutable errmsgs
: Buffer.t
476 ; mutable newerrmsgs
: bool
480 ; mutable anchor
: anchor
481 ; mutable ranchors
: (string * string * anchor
* string) list
483 ; mutable layout
: page list
484 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
485 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
486 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
487 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
488 ; mutable pagecount
: int
489 ; mutable currently
: currently
490 ; mutable mstate
: mstate
491 ; mutable searchpattern
: string
492 ; mutable rects
: (pageno
* recttype
* rect
) list
493 ; mutable rects1
: (pageno
* recttype
* rect
) list
494 ; mutable text
: string
495 ; mutable winstate
: Wsi.winstate list
496 ; mutable mode
: mode
497 ; mutable uioh
: uioh
498 ; mutable outlines
: outline array
499 ; mutable bookmarks
: outline list
500 ; mutable path
: string
501 ; mutable password
: string
502 ; mutable nameddest
: string
503 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
504 ; mutable memused
: memsize
506 ; mutable throttle
: (page list
* int * float) option
507 ; mutable autoscroll
: int option
508 ; mutable ghyll
: (int option -> unit)
509 ; mutable help
: helpitem array
510 ; mutable docinfo
: (int * string) list
511 ; mutable texid
: GlTex.texture_id
option
513 ; mutable prevzoom
: (float * int)
514 ; mutable progress
: float
515 ; mutable redisplay
: bool
516 ; mutable mpos
: mpos
517 ; mutable keystate
: keystate
518 ; mutable glinks
: bool
519 ; mutable prevcolumns
: (columns
* float) option
522 ; mutable reprf
: (unit -> unit)
523 ; mutable origin
: string
524 ; mutable roam
: (unit -> unit)
525 ; mutable bzoom
: bool
526 ; mutable traw
: [`
float] Raw.t
527 ; mutable vraw
: [`
float] Raw.t
530 { pat
: string circbuf
531 ; pag
: string circbuf
532 ; nav
: anchor circbuf
533 ; sel
: string circbuf
540 ; scrollb
= scrollbhv lor scrollbvv
556 ; presentation
= false
561 ; fitmodel
= FitProportional
562 ; trimmargins
= false
563 ; trimfuzz
= (0,0,0,0)
564 ; memlimit
= 32 lsl 20
569 ; bgcolor
= (0.5, 0.5, 0.5)
573 ; mustoresize
= 256 lsl 20
578 | Plinux
| Pfreebsd
| Pdragonflybsd
579 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
580 | Posx
-> "open \"%s\""
581 | Pcygwin
-> "cygstart \"%s\""
582 | Punknown
-> "echo %s")
583 ; pathlauncher
= "lp \"%s\""
586 | Plinux
| Pfreebsd
| Pdragonflybsd
587 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
595 ; redirectstderr
= false
597 ; columns
= Csingle
[||]
603 ; wheelbypage
= false
604 ; stcmd
= "echo SyncTex"
607 ; paxmark
= Mark_word
609 let mk n
= (n
, Hashtbl.create
1) in
623 let wtmode = ref false;;
624 let cxack = ref false;;
626 let findkeyhash c name
=
627 try List.assoc name c
.keyhashes
628 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
631 let conf = { defconf with angle
= defconf.angle
};;
633 let pgscale h
= truncate
(float h
*. conf.pgscale);;
636 { mutable fontsize
: int
637 ; mutable wwidth
: float
638 ; mutable maxrows
: int
650 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
651 let len = String.length s
in
652 if colonpos >= 0 && colonpos + 3 < len
654 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
657 try String.rindex_from s
colonpos ' '
661 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
664 | "http" | "ftp" | "mailto" ->
666 try String.index_from s
colonpos ' '
667 with Not_found
-> len
669 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
677 if emptystr
conf.urilauncher
678 then print_endline uri
680 let url = geturl uri
in
682 then Printf.eprintf
"obtained empty url from uri %S" uri
684 let re = Str.regexp
"%s" in
685 let command = Str.global_replace
re url conf.urilauncher
in
689 "failed to execute `%s': %s\n" command (exntos exn
);
695 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
696 Help.version (fz_version
()) Sys.ocaml_version
697 (platform_to_string platform) Sys.word_size
701 let strings = version () :: "" :: Help.keys
in
704 let url = geturl s
in
706 then (s
, 0, Action
(fun u
-> gotouri url; u
))
707 else (s
, 0, Noaction
)
712 let firstgeomcmds = "", [];;
713 let noreprf () = ();;
721 ; stderr
= Unix.stderr
722 ; errmsgs
= Buffer.create
0
727 ; anchor
= emptyanchor
731 ; tilelru
= Queue.create
()
732 ; pagemap
= Hashtbl.create
10
733 ; tilemap
= Hashtbl.create
10
749 ; geomcmds
= firstgeomcmds
751 { nav
= cbnew 10 emptyanchor
764 ; prevzoom
= (1.0, 0)
778 ; traw
= Raw.create_static `
float 8
779 ; vraw
= Raw.create_static `
float 8
784 if (conf.scrollb
land scrollbhv = 0)
785 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
791 if (conf.scrollb
land scrollbvv = 0)
796 let wadjsb w
= w
- vscrollw ();;
799 fstate.fontsize
<- n
;
800 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
801 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
807 Printf.kprintf prerr_endline fmt
809 Printf.kprintf ignore fmt
813 if emptystr
conf.pathlauncher
814 then print_endline
state.path
816 let re = Str.regexp
"%s" in
817 let command = Str.global_replace
re state.path
conf.pathlauncher
in
820 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
826 type 'a t
= | Res
of 'a
| Exn
of exn
;;
829 try Res
(Unix.pipe ())
834 try tempfailureretry
Unix.close fd
835 with exn
-> f
(exntos exn
)
839 try Res
(tempfailureretry
Unix.dup fd
)
844 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
849 let redirectstderr () =
850 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
851 if conf.redirectstderr
853 match Ne.pipe () with
855 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
858 begin match Ne.dup Unix.stderr
with
860 dolog
"failed to dup stderr: %s" (exntos exn
);
861 Ne.clo r
(clofail "pipe/r");
862 Ne.clo w
(clofail "pipe/w");
864 | Ne.Res dupstderr
->
865 begin match Ne.dup2 w
Unix.stderr
with
867 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
868 Ne.clo dupstderr
(clofail "stderr duplicate");
869 Ne.clo r
(clofail "redir pipe/r");
870 Ne.clo w
(clofail "redir pipe/w");
873 state.stderr
<- dupstderr
;
874 state.errfd
<- Some r
;
878 state.newerrmsgs
<- false;
879 begin match state.errfd
with
881 begin match Ne.dup2 state.stderr
Unix.stderr
with
883 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
885 Ne.clo fd
(clofail "dup of stderr");
890 prerr_string
(Buffer.contents
state.errmsgs
);
892 Buffer.clear
state.errmsgs
;
898 let postRedisplay who
=
900 then prerr_endline
("redisplay for " ^ who
);
901 state.redisplay
<- true;
905 let getopaque pageno
=
906 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
907 with Not_found
-> None
910 let putopaque pageno opaque
=
911 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
914 let pagetranslatepoint l x y
=
915 let dy = y
- l
.pagedispy
in
916 let y = dy + l
.pagey
in
917 let dx = x
- l
.pagedispx
in
918 let x = dx + l
.pagex
in
922 let onppundermouse g
x y d
=
925 begin match getopaque l
.pageno
with
927 let x0 = l
.pagedispx
in
928 let x1 = x0 + l
.pagevw
in
929 let y0 = l
.pagedispy
in
930 let y1 = y0 + l
.pagevh
in
931 if y >= y0 && y <= y1 && x >= x0 && x <= x1
933 let px, py
= pagetranslatepoint l
x y in
934 match g opaque l
px py
with
947 let g opaque l
px py
=
950 match rectofblock opaque
px py
with
952 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
953 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
954 G.postRedisplay "getunder";
957 match whatsunder opaque
px py
with
959 | under
-> Some under
961 onppundermouse g x y Unone
966 match unproject opaque
x y with
967 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
970 onppundermouse g x y None
;
974 state.text
<- Printf.sprintf
"%c%s" c s
;
975 G.postRedisplay "showtext";
979 let g opaque l
px py
=
980 if markunder opaque
px py
conf.paxmark
983 match getopaque l
.pageno
with
986 match Ne.pipe () with
990 "can not create mark pipe: %s"
993 let doclose what fd
=
994 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
997 popen conf.paxcmd
[r
, 0; w
, -1];
999 doclose "paxunder pipe/w" w
;
1000 dolog
"can not execute %S: %s" conf.paxcmd
(exntos exn
);
1002 copysel w opaque
false;
1003 G.postRedisplay "paxunder";
1004 doclose "paxunder pipe/r" r
;
1009 G.postRedisplay "paxunder";
1010 if conf.paxmark
= Mark_page
1013 match getopaque l
.pageno
with
1015 | Some opaque
-> clearmark opaque
) state.layout
;
1017 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1021 match Ne.pipe () with
1023 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1026 Ne.clo fd
(fun msg
->
1027 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1031 try popen conf.selcmd
[r
, 0; w
, -1]; true
1033 clo "selstring pipe/w" w
;
1035 (Printf.sprintf
"failed to execute %s: %s"
1036 conf.selcmd
(exntos exn
));
1042 let l = String.length s
in
1043 let n = tempfailureretry
(Unix.write w s
0) l in
1048 "failed to write %d characters to sel pipe, wrote %d"
1053 (Printf.sprintf
"failed to write to sel pipe: %s"
1058 clo "selstring pipe/r" r
;
1061 let undertext = function
1064 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1065 | Utext s
-> "font: " ^ s
1066 | Uunexpected s
-> "unexpected: " ^ s
1067 | Ulaunch s
-> "launch: " ^ s
1068 | Unamed s
-> "named: " ^ s
1069 | Uremote
(filename
, pageno
) ->
1070 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1071 | Uremotedest
(filename
, destname
) ->
1072 Printf.sprintf
"%s: destination %S" filename destname
1075 let updateunder x y =
1076 match getunder x y with
1077 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1079 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1080 Wsi.setcursor
Wsi.CURSOR_INFO
1081 | Ulinkgoto
(pageno
, _
) ->
1083 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1084 Wsi.setcursor
Wsi.CURSOR_INFO
1086 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1087 Wsi.setcursor
Wsi.CURSOR_TEXT
1089 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1090 Wsi.setcursor
Wsi.CURSOR_INHERIT
1092 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1093 Wsi.setcursor
Wsi.CURSOR_INHERIT
1095 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1096 Wsi.setcursor
Wsi.CURSOR_INHERIT
1097 | Uremote
(filename
, pageno
) ->
1098 if conf.underinfo
then showtext 'r'
1099 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1100 Wsi.setcursor
Wsi.CURSOR_INFO
1101 | Uremotedest
(filename
, destname
) ->
1102 if conf.underinfo
then showtext 'r'
1103 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1104 Wsi.setcursor
Wsi.CURSOR_INFO
1107 let showlinktype under
=
1113 let s = undertext under
in
1118 let b = Buffer.create
(String.length
s + 1) in
1119 Buffer.add_string
b s;
1120 Buffer.add_char
b c
;
1124 module type TextEnumType
=
1128 val names
: string array
1131 module TextEnumMake
(Ten
: TextEnumType
) =
1133 let names = Ten.names;;
1134 let to_int (t
: Ten.t
) = Obj.magic t
;;
1135 let to_string t
= names.(to_int t
);;
1136 let of_int n : Ten.t
= Obj.magic
n;;
1139 if i
= Array.length
names
1140 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1142 if Ten.names.(i
) = s
1149 module CSTE
= TextEnumMake
(struct
1150 type t
= colorspace
;;
1151 let name = "colorspace";;
1152 let names = [|"rgb"; "bgr"; "gray"|];;
1155 module MTE
= TextEnumMake
(struct
1158 let names = [|"page"; "block"; "line"; "word"|];;
1161 module FMTE
= TextEnumMake
(struct
1163 let name = "fitmodel";;
1164 let names = [|"width"; "proportional"; "page"|];;
1167 let intentry_with_suffix text key
=
1169 if key
>= 32 && key
< 127
1173 match Char.lowercase
c with
1175 let text = addchar text c in
1178 | 'k'
| 'm'
| '
g'
->
1179 let text = addchar text c in
1183 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1187 let multicolumns_to_string (n, a
, b) =
1189 then Printf.sprintf
"%d" n
1190 else Printf.sprintf
"%d,%d,%d" n a
b;
1193 let multicolumns_of_string s =
1195 (int_of_string
s, 0, 0)
1197 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1199 then failwith
"subtly broken"; (n, a
, b)
1205 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1206 if n != 4 then error
"incomplete read(len) = %d" n;
1208 lor (Char.code
s.[0] lsl 24)
1209 lor (Char.code
s.[1] lsl 16)
1210 lor (Char.code
s.[2] lsl 8)
1211 lor (Char.code
s.[3] lsl 0)
1213 let s = String.create
len in
1214 let n = tempfailureretry
(Unix.read fd
s 0) len in
1215 if n != len then error
"incomplete read(data) %d vs %d" n len;
1219 let btod b = if b then 1 else 0;;
1222 let b = Buffer.create
16 in
1223 Buffer.add_string
b "llll";
1226 let s = Buffer.contents
b in
1227 let n = String.length
s in
1229 (* dolog "wcmd %S" (String.sub s 4 len); *)
1230 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1231 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1232 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1233 s.[3] <- Char.chr
(len land 0xff);
1234 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1235 if n'
!= n then error
"write failed %d vs %d" n'
n;
1240 let d = state.winh
- h
in
1241 max
conf.interpagespace
((d + 1) / 2)
1244 let rowyh (c, coverA
, coverB
) b n =
1245 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1247 let _, _, vy
, (_, _, h
, _) = b.(n) in
1250 let n'
= n - coverA
in
1253 let e = min
state.pagecount
(s + c) in
1254 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1255 let _, _, y, (_, _, h
, _) = b.(m
) in
1256 let miny = min
miny y in
1257 let maxh = max
maxh h
in
1258 find (m
+1) miny maxh
1263 match conf.columns
with
1264 | Cmulti
((_, _, _) as cl
, b) ->
1265 if Array.length
b > 0
1267 let y, h
= rowyh cl
b (Array.length
b - 1) in
1268 y + h
+ (if conf.presentation
then calcips h
else 0)
1271 if Array.length
b > 0
1273 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1274 y + h
+ (if conf.presentation
then calcips h
else 0)
1277 if Array.length
b > 0
1279 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1284 let getpageywh pageno
=
1285 let pageno = bound pageno 0 (state.pagecount
-1) in
1286 match conf.columns
with
1288 if Array.length
b = 0
1291 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1293 if conf.presentation
1299 if Array.length
b = 0
1302 let y, h
= rowyh cl
b pageno in
1303 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1305 if conf.presentation
1311 if Array.length
b = 0
1315 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1319 let getpageyh pageno =
1320 let y,_,h
= getpageywh pageno in
1324 let getpagedim pageno =
1327 | (n, _, _, _) as pdim
:: rest
->
1329 then (if n = pageno then pdim
else ppdim
)
1334 f (-1, -1, -1, -1) state.pdims
1337 let getpagey pageno = fst
(getpageyh pageno);;
1339 let nogeomcmds cmds
=
1341 | s, [] -> emptystr
s
1346 let ((c, coverA
, coverB
) as cl
), b =
1347 match conf.columns
with
1348 | Csingle
b -> (1, 0, 0), b
1349 | Cmulti
(c, b) -> c, b
1350 | Csplit
(_, b) -> (1, 0, 0), b
1352 if Array.length
b = 0
1355 let rec bsearch nmin nmax
=
1357 then bound nmin
0 (state.pagecount
-1)
1359 let n = (nmax
+ nmin
) / 2 in
1360 let vy, h
= rowyh cl
b n in
1362 if conf.presentation
1364 let ips = calcips h
in
1365 let y0 = vy - ips in
1366 let y1 = vy + h
+ ips in
1370 then 0, vy + h
+ conf.interpagespace
1372 let y0 = vy - conf.interpagespace
in
1373 y0, y0 + h
+ conf.interpagespace
1376 if y >= y0 && y < y1
1383 if n < state.pagecount
- coverB
1384 then ((n-coverA
)/c)*c + coverA
1391 then bsearch (n+1) nmax
1392 else bsearch nmin
(n-1)
1395 bsearch 0 (state.pagecount
-1);
1398 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1399 let sh = sh - (hscrollh ()) in
1400 let rec fold accu
n =
1401 if n = Array.length
b
1404 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1407 || n = state.pagecount
- coverB
1408 || (n - coverA
) mod columns
= columns
- 1)
1414 let pagey = max
0 (y - vy) in
1415 let pagedispy = if pagey > 0 then 0 else vy - y in
1416 let pagedispx, pagex
=
1418 if n = coverA
- 1 || n = state.pagecount
- coverB
1419 then state.x + (wadjsb state.winw
- w
) / 2
1420 else dx + xoff
+ state.x
1427 let vw = wadjsb state.winw
- pagedispx in
1428 let pw = w
- pagex
in
1431 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1432 if pagevw > 0 && pagevh > 0
1436 ; pagedimno
= pdimno
1443 ; pagedispx = pagedispx
1444 ; pagedispy = pagedispy
1456 if Array.length
b = 0
1458 else List.rev
(fold [] (page_of_y y))
1461 let layoutS (columns
, b) y sh =
1462 let sh = sh - hscrollh () in
1463 let rec fold accu n =
1464 if n = Array.length
b
1467 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1474 let x = xoff
+ state.x in
1475 let pagey = max
0 (y - vy) in
1476 let pagedispy = if pagey > 0 then 0 else vy - y in
1477 let pagedispx, pagex
=
1491 let pagecolw = pagew
/columns
in
1493 if pagecolw < state.winw
1494 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1498 let vw = wadjsb state.winw
- pagedispx in
1499 let pw = pagew
- pagex
in
1502 let pagevw = min
pagevw pagecolw in
1503 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1504 if pagevw > 0 && pagevh > 0
1507 { pageno = n/columns
1508 ; pagedimno
= pdimno
1515 ; pagedispx = pagedispx
1516 ; pagedispy = pagedispy
1517 ; pagecol
= n mod columns
1528 List.rev
(fold [] 0)
1532 if nogeomcmds state.geomcmds
1534 match conf.columns
with
1535 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1536 | Cmulti
c -> layoutN c y sh
1537 | Csplit
s -> layoutS s y sh
1542 let y = state.y + incr
in
1544 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1549 let tilex = l.pagex
mod conf.tilew
in
1550 let tiley = l.pagey mod conf.tileh
in
1552 let col = l.pagex
/ conf.tilew
in
1553 let row = l.pagey / conf.tileh
in
1555 let rec rowloop row y0 dispy h
=
1559 let dh = conf.tileh
- y0 in
1560 let dh = min h
dh in
1561 let rec colloop col x0 dispx w
=
1565 let dw = conf.tilew
- x0 in
1566 let dw = min w
dw in
1568 f col row dispx dispy
x0 y0 dw dh;
1569 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1572 colloop col tilex l.pagedispx l.pagevw;
1573 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1576 if l.pagevw > 0 && l.pagevh > 0
1577 then rowloop row tiley l.pagedispy l.pagevh;
1580 let gettileopaque l col row =
1582 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1584 try Some
(Hashtbl.find state.tilemap
key)
1585 with Not_found
-> None
1588 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1589 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1590 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1593 let filledrect x0 y0 x1 y1 =
1594 GlArray.disable `texture_coord
;
1595 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1596 GlArray.vertex `two
state.vraw
;
1597 GlArray.draw_arrays `triangle_strip
0 4;
1598 GlArray.enable `texture_coord
;
1601 let linerect x0 y0 x1 y1 =
1602 GlArray.disable `texture_coord
;
1603 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1604 GlArray.vertex `two
state.vraw
;
1605 GlArray.draw_arrays `line_loop
0 4;
1606 GlArray.enable `texture_coord
;
1609 let drawtiles l color
=
1612 let f col row x y tilex tiley w h
=
1613 match gettileopaque l col row with
1614 | Some
(opaque
, _, t
) ->
1615 let params = x, y, w
, h
, tilex, tiley in
1619 GlFunc.blend_func `zero `one_minus_src_color
;
1621 drawtile
params opaque
;
1623 then Gl.disable `blend
;
1627 let s = Printf.sprintf
1631 let w = measurestr
fstate.fontsize
s in
1632 GlDraw.color
(0.0, 0.0, 0.0);
1633 filledrect (float (x-2))
1636 (float (y + fstate.fontsize
+ 2));
1637 GlDraw.color
(1.0, 1.0, 1.0);
1638 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1645 let lw = wadjsb state.winw
- x in
1648 let lh = state.winh
- y in
1654 GlFunc.blend_func `zero `one_minus_src_color
;
1656 begin match state.texid
with
1658 Gl.enable `texture_2d
;
1659 GlTex.bind_texture `texture_2d id
;
1662 and x1 = float (x+w)
1663 and y1 = float (y+h
) in
1665 let tw = float w /. 16.0
1666 and th
= float h
/. 16.0 in
1667 let tx0 = float tilex /. 16.0
1668 and ty0
= float tiley /. 16.0 in
1670 and ty1
= ty0
+. th
in
1671 Raw.sets_float
state.vraw ~pos
:0
1672 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1673 Raw.sets_float
state.traw ~pos
:0
1674 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1675 GlArray.vertex `two
state.vraw
;
1676 GlArray.tex_coord `two
state.traw
;
1677 GlArray.draw_arrays `triangle_strip
0 4;
1680 GlDraw.color
(1.0, 1.0, 1.0);
1681 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1683 if w > 128 && h
> fstate.fontsize
+ 10
1685 let c = if conf.invert
then 1.0 else 0.0 in
1686 GlDraw.color
(c, c, c);
1689 then (col*conf.tilew
, row*conf.tileh
)
1692 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1701 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1703 let tilevisible1 l x y =
1705 and ax1
= l.pagex
+ l.pagevw
1707 and ay1
= l.pagey + l.pagevh in
1711 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1712 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1714 let rx0 = max
ax0 bx0
1715 and ry0
= max ay0 by0
1716 and rx1
= min ax1
bx1
1717 and ry1
= min ay1 by1
in
1719 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1720 nonemptyintersection
1723 let tilevisible layout n x y =
1724 let rec findpageinlayout m
= function
1725 | l :: rest
when l.pageno = n ->
1726 tilevisible1 l x y || (
1727 match conf.columns
with
1728 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1731 | _ :: rest
-> findpageinlayout 0 rest
1734 findpageinlayout 0 layout;
1737 let tileready l x y =
1738 tilevisible1 l x y &&
1739 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1742 let tilepage n p
layout =
1743 let rec loop = function
1747 let f col row _ _ _ _ _ _ =
1748 if state.currently
= Idle
1750 match gettileopaque l col row with
1753 let x = col*conf.tilew
1754 and y = row*conf.tileh
in
1756 let w = l.pagew
- x in
1760 let h = l.pageh
- y in
1765 then getpbo
w h conf.colorspace
1768 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1771 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1772 conf.tilew
, conf.tileh
1781 if nogeomcmds state.geomcmds
1785 let preloadlayout y =
1786 let y = if y < state.winh
then 0 else y - state.winh
in
1787 let h = state.winh
*3 in
1792 let rec loop pages
=
1793 if state.currently
!= Idle
1798 begin match getopaque l.pageno with
1800 wcmd "page %d %d" l.pageno l.pagedimno
;
1801 state.currently
<- Loading
(l, state.gen
);
1803 tilepage l.pageno opaque pages
;
1808 if nogeomcmds state.geomcmds
1814 if conf.preload && state.currently
= Idle
1815 then load (preloadlayout state.y);
1818 let layoutready layout =
1819 let rec fold all ls
=
1820 all
&& match ls
with
1822 let seen = ref false in
1823 let allvisible = ref true in
1824 let foo col row _ _ _ _ _ _ =
1826 allvisible := !allvisible &&
1827 begin match gettileopaque l col row with
1833 fold (!seen && !allvisible) rest
1836 let alltilesvisible = fold true layout in
1841 let y = bound y 0 state.maxy
in
1842 let y, layout, proceed
=
1843 match conf.maxwait
with
1844 | Some time
when state.ghyll
== noghyll ->
1845 begin match state.throttle
with
1847 let layout = layout y state.winh
in
1848 let ready = layoutready layout in
1852 state.throttle
<- Some
(layout, y, now ());
1854 else G.postRedisplay "gotoy showall (None)";
1856 | Some
(_, _, started
) ->
1857 let dt = now () -. started
in
1860 state.throttle
<- None
;
1861 let layout = layout y state.winh
in
1863 G.postRedisplay "maxwait";
1870 let layout = layout y state.winh
in
1871 if not
!wtmode || layoutready layout
1872 then G.postRedisplay "gotoy ready";
1878 state.layout <- layout;
1879 begin match state.mode
with
1880 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1881 let rec loop = function
1883 state.mode
<- LinkNav
(Ltgendir
0)
1884 | l :: _ when l.pageno = pageno ->
1885 begin match getopaque pageno with
1887 state.mode
<- LinkNav
(Ltgendir
0)
1889 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1890 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1891 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1892 then state.mode
<- LinkNav
(Ltgendir
0)
1894 | _ :: rest
-> loop rest
1899 begin match state.mode
with
1900 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1901 if not
(pagevisible layout pageno)
1903 match state.layout with
1906 state.mode
<- Birdseye
(
1907 conf, leftx
, l.pageno, hooverpageno
, anchor
1910 | LinkNav
(Ltgendir dir
as lt
) ->
1912 let rec loop = function
1915 match getopaque l.pageno with
1921 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1923 if dir
> 0 then LDfirst
else LDlast
1929 | Lnotfound
-> loop rest
1931 showlinktype (getlink opaque
n);
1932 Ltexact
(l.pageno, n)
1936 state.mode
<- LinkNav
linknav
1941 state.ghyll
<- noghyll;
1944 let mx, my
= state.mpos
in
1949 let conttiling pageno opaque
=
1950 tilepage pageno opaque
1951 (if conf.preload then preloadlayout state.y else state.layout)
1954 let gotoy_and_clear_text y =
1955 if not
conf.verbose
then state.text <- "";
1961 let coloff = l.pagecol
* l.pageh
in
1962 float (l.pagey + coloff) /. float l.pageh
1969 if conf.presentation
1970 then float l.pagedispy /. float (calcips l.pageh
)
1971 else float l.pagedispy /. float conf.interpagespace
1974 (l.pageno, top, dtop)
1978 match state.layout with
1979 | l :: _ -> getanchor1 l
1981 let n = page_of_y state.y in
1985 let y, h = getpageyh n in
1986 let dy = y - state.y in
1988 if conf.presentation
1990 let ips = calcips h in
1991 float (dy + ips) /. float ips
1993 float dy /. float conf.interpagespace
1998 let getanchory (n, top, dtop) =
1999 let y, h = getpageyh n in
2000 if conf.presentation
2002 let ips = calcips h in
2003 y + truncate
(top*.float h -. dtop*.float ips) + ips;
2005 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
2008 let gotoanchor anchor
=
2009 gotoy (getanchory anchor
);
2013 cbput state.hists
.nav
(getanchor ());
2017 let anchor = cbgetc state.hists
.nav dir
in
2022 let scroll f n a
b =
2023 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2025 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2027 then s (float f /. float a
)
2030 then 1.0 -. s ((float (f-b) /. float (n-b)))
2036 let ins = float a
*. 0.5
2037 and outs
= float (n-b) *. 0.5 in
2039 ins +. outs
+. float ones
2041 let rec set (_N
, _A
, _B
) y sy
=
2042 let sum = summa _N _A _B
in
2043 let dy = float (y - sy
) in
2047 then state.ghyll
<- noghyll
2050 let s = scroll n _N _A _B
in
2051 let y1 = y1 +. ((s *. dy) /. sum) in
2052 gotoy_and_clear_text (truncate
y1);
2053 state.ghyll
<- gf (n+1) y1;
2057 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2059 gf 0 (float state.y)
2062 match conf.ghyllscroll
with
2064 gotoy_and_clear_text y
2066 if state.ghyll
== noghyll
2067 then set nab
y state.y
2068 else state.ghyll
(Some
y)
2071 let gotopage n top =
2072 let y, h = getpageyh n in
2073 let y = y + (truncate
(top *. float h)) in
2077 let gotopage1 n top =
2078 let y = getpagey n in
2083 let invalidate s f =
2088 match state.geomcmds
with
2089 | ps
, [] when emptystr ps
->
2091 state.geomcmds
<- s, [];
2094 state.geomcmds
<- ps
, [s, f];
2096 | ps
, (s'
, _) :: rest
when s'
= s ->
2097 state.geomcmds
<- ps
, ((s, f) :: rest
);
2100 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2104 Hashtbl.iter
(fun _ opaque
->
2105 wcmd "freepage %s" opaque
;
2107 Hashtbl.clear
state.pagemap
;
2111 if not
(Queue.is_empty
state.tilelru
)
2113 Queue.iter
(fun (k
, p
, s) ->
2114 wcmd "freetile %s" p
;
2115 state.memused
<- state.memused
- s;
2116 Hashtbl.remove
state.tilemap k
;
2118 state.uioh#infochanged Memused
;
2119 Queue.clear
state.tilelru
;
2125 let h = truncate
(float h*.conf.zoom
) in
2126 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2130 let opendoc path password
=
2132 state.password
<- password
;
2133 state.gen
<- state.gen
+ 1;
2134 state.docinfo
<- [];
2137 setaalevel
conf.aalevel
;
2139 if emptystr
state.origin
2143 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2144 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2145 invalidate "reqlayout"
2147 wcmd "reqlayout %d %d %d %s\000"
2148 conf.angle
(FMTE.to_int conf.fitmodel
)
2149 (stateh state.winh
) state.nameddest
2154 state.anchor <- getanchor ();
2155 opendoc state.path
state.password
;
2159 let c = c *. conf.colorscale
in
2163 let scalecolor2 (r
, g, b) =
2164 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2167 let docolumns = function
2169 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2170 let rec loop pageno pdimno pdim
y ph pdims
=
2171 if pageno = state.pagecount
2174 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2176 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2177 pdimno+1, pdim
, rest
2181 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2183 (if conf.presentation
2184 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2185 else (if pageno = 0 then 0 else conf.interpagespace
)
2188 a.(pageno) <- (pdimno, x, y, pdim
);
2189 loop (pageno+1) pdimno pdim
(y + h) h pdims
2191 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2192 conf.columns
<- Csingle
a;
2194 | Cmulti
((columns
, coverA
, coverB
), _) ->
2195 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2196 let rec loop pageno pdimno pdim
x y rowh pdims
=
2197 let rec fixrow m
= if m
= pageno then () else
2198 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2201 let y = y + (rowh
- h) / 2 in
2202 a.(m
) <- (pdimno, x, y, pdim
);
2206 if pageno = state.pagecount
2207 then fixrow (((pageno - 1) / columns
) * columns
)
2209 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2211 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2212 pdimno+1, pdim
, rest
2217 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2219 let x = (wadjsb state.winw
- w) / 2 in
2221 if conf.presentation
then calcips h else conf.interpagespace
in
2222 x, y + ips + rowh
, h
2225 if (pageno - coverA
) mod columns
= 0
2227 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2229 if conf.presentation
2231 let ips = calcips h in
2232 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2234 y + (if pageno = 0 then 0 else conf.interpagespace
)
2238 else x, y, max rowh
h
2242 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2245 if pageno = columns
&& conf.presentation
2247 let ips = calcips rowh
in
2248 for i
= 0 to pred columns
2250 let (pdimno, x, y, pdim
) = a.(i
) in
2251 a.(i
) <- (pdimno, x, y+ips, pdim
)
2257 fixrow (pageno - columns
);
2262 a.(pageno) <- (pdimno, x, y, pdim
);
2263 let x = x + w + xoff
*2 + conf.interpagespace
in
2264 loop (pageno+1) pdimno pdim
x y rowh' pdims
2266 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2267 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2270 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2271 let rec loop pageno pdimno pdim
y pdims
=
2272 if pageno = state.pagecount
2275 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2277 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2278 pdimno+1, pdim
, rest
2283 let rec loop1 n x y =
2284 if n = c then y else (
2285 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2286 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2289 let y = loop1 0 0 y in
2290 loop (pageno+1) pdimno pdim
y pdims
2292 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2293 conf.columns
<- Csplit
(c, a);
2297 docolumns conf.columns
;
2298 state.maxy
<- calcheight ();
2299 if state.reprf
== noreprf
2301 match state.mode
with
2302 | Birdseye
(_, _, pageno, _, _) ->
2303 let y, h = getpageyh pageno in
2304 let top = (state.winh
- h) / 2 in
2305 gotoy (max
0 (y - top))
2306 | _ -> gotoanchor state.anchor
2310 state.reprf
<- noreprf;
2315 GlDraw.viewport
0 0 w h;
2316 let firsttime = state.geomcmds
== firstgeomcmds in
2317 if not
firsttime && nogeomcmds state.geomcmds
2318 then state.anchor <- getanchor ();
2321 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2324 setfontsize fstate.fontsize
;
2325 GlMat.mode `modelview
;
2326 GlMat.load_identity
();
2328 GlMat.mode `projection
;
2329 GlMat.load_identity
();
2330 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2331 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2332 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2337 else float state.x /. float state.w
2339 invalidate "geometry"
2343 then state.x <- truncate
(relx *. float w);
2345 match conf.columns
with
2347 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2348 | Csplit
(c, _) -> w * c
2350 wcmd "geometry %d %d %d"
2351 w (stateh h) (FMTE.to_int conf.fitmodel
)
2356 let len = String.length
state.text in
2359 match state.mode
with
2360 | Textentry
_ | View
| LinkNav
_ ->
2361 let h, _, _ = state.uioh#scrollpw
in
2366 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2367 (x+.w) (float (state.winh
- hscrollh))
2370 let w = float (wadjsb state.winw
- 1) in
2371 if state.progress
>= 0.0 && state.progress
< 1.0
2373 GlDraw.color
(0.3, 0.3, 0.3);
2374 let w1 = w *. state.progress
in
2376 GlDraw.color
(0.0, 0.0, 0.0);
2380 GlDraw.color
(0.0, 0.0, 0.0);
2384 GlDraw.color
(1.0, 1.0, 1.0);
2385 drawstring fstate.fontsize
2386 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2389 match state.mode
with
2390 | Textentry
((prefix
, text, _, _, _, _), _) ->
2394 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2396 Printf.sprintf
"%s%s_" prefix
text
2405 if not
(istextentry state.mode
) && state.uioh#eformsgs
2407 let s1 = "(press 'e' to review error messasges)" in
2408 if nonemptystr
s then s ^
" " ^
s1 else s1
2418 let len = Queue.length
state.tilelru
in
2420 match state.throttle
with
2423 then preloadlayout state.y
2425 | Some
(layout, _, _) ->
2429 if state.memused
<= conf.memlimit
2434 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2435 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2436 let (_, pw, ph
, _) = getpagedim n in
2439 && colorspace
= conf.colorspace
2440 && angle
= conf.angle
2444 let x = col*conf.tilew
2445 and y = row*conf.tileh
in
2446 tilevisible (Lazy.force_val
layout) n x y
2448 then Queue.push lruitem
state.tilelru
2451 wcmd "freetile %s" p
;
2452 state.memused
<- state.memused
- s;
2453 state.uioh#infochanged Memused
;
2454 Hashtbl.remove
state.tilemap k
;
2462 let logcurrently = function
2463 | Idle
-> dolog
"Idle"
2464 | Loading
(l, gen
) ->
2465 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2466 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2468 "Tiling %d[%d,%d] page=%s cs=%s angle"
2469 l.pageno col row pageopaque
2470 (CSTE.to_string colorspace
)
2472 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2473 angle gen
conf.angle
state.gen
2475 conf.tilew
conf.tileh
2482 let r = Str.regexp
" " in
2483 fun s -> Str.bounded_split
r s 2;
2486 let onpagerect pageno f =
2488 match conf.columns
with
2489 | Cmulti
(_, b) -> b
2491 | Csplit
(_, b) -> b
2493 if pageno >= 0 && pageno < Array.length
b
2495 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2499 let gotopagexy1 pageno x y =
2500 let _,w1,h1
,leftx
= getpagedim pageno in
2501 let top = y /. (float h1
) in
2502 let left = x /. (float w1) in
2503 let py, w, h = getpageywh pageno in
2504 let wh = state.winh
- hscrollh () in
2505 let x = left *. (float w) in
2506 let x = leftx
+ state.x + truncate
x in
2508 if x < 0 || x >= wadjsb state.winw
2512 let pdy = truncate
(top *. float h) in
2513 let y'
= py + pdy in
2514 let dy = y'
- state.y in
2516 if x != state.x || not
(dy > 0 && dy < wh)
2518 if conf.presentation
2520 if abs
(py - y'
) > wh
2527 if state.x != sx || state.y != sy
2532 let ww = wadjsb state.winw
in
2534 and qy
= pdy / wh in
2536 and y = py + qy
* wh in
2537 let x = if -x + ww > w1 then -(w1-ww) else x
2538 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2540 if conf.presentation
2542 if abs
(py - y'
) > wh
2552 gotoy_and_clear_text y;
2554 else gotoy_and_clear_text state.y;
2557 let gotopagexy pageno x y =
2558 match state.mode
with
2559 | Birdseye
_ -> gotopage pageno 0.0
2560 | _ -> gotopagexy1 pageno x y
2564 (* dolog "%S" cmds; *)
2565 let cl = splitatspace cmds
in
2567 try Scanf.sscanf
s fmt
f
2569 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2572 let addoutline outline
=
2573 match state.currently
with
2574 | Outlining outlines
->
2575 state.currently
<- Outlining
(outline
:: outlines
)
2576 | Idle
-> state.currently
<- Outlining
[outline
]
2578 dolog
"invalid outlining state";
2579 logcurrently currently
2583 state.uioh#infochanged Pdim
;
2586 | "clearrects" :: [] ->
2587 state.rects
<- state.rects1
;
2588 G.postRedisplay "clearrects";
2590 | "continue" :: args :: [] ->
2591 let n = scan args "%u" (fun n -> n) in
2592 state.pagecount
<- n;
2593 begin match state.currently
with
2595 state.currently
<- Idle
;
2596 state.outlines
<- Array.of_list
(List.rev
l)
2600 let cur, cmds
= state.geomcmds
in
2602 then failwith
"umpossible";
2604 begin match List.rev cmds
with
2606 state.geomcmds
<- "", [];
2610 state.geomcmds
<- s, List.rev rest
;
2612 if conf.maxwait
= None
&& not
!wtmode
2613 then G.postRedisplay "continue";
2615 | "title" :: args :: [] ->
2618 | "msg" :: args :: [] ->
2621 | "vmsg" :: args :: [] ->
2623 then showtext ' '
args
2625 | "emsg" :: args :: [] ->
2626 Buffer.add_string
state.errmsgs
args;
2627 state.newerrmsgs
<- true;
2628 G.postRedisplay "error message"
2630 | "progress" :: args :: [] ->
2631 let progress, text =
2634 f, String.sub
args pos
(String.length
args - pos
))
2637 state.progress <- progress;
2638 G.postRedisplay "progress"
2640 | "firstmatch" :: args :: [] ->
2641 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2642 scan args "%u %d %f %f %f %f %f %f %f %f"
2643 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2644 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2646 let y = (getpagey pageno) + truncate
y0 in
2649 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2651 | "match" :: args :: [] ->
2652 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2653 scan args "%u %d %f %f %f %f %f %f %f %f"
2654 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2655 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2658 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2660 | "page" :: args :: [] ->
2661 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2662 begin match state.currently
with
2663 | Loading
(l, gen
) ->
2664 vlog "page %d took %f sec" l.pageno t
;
2665 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2666 begin match state.throttle
with
2668 let preloadedpages =
2670 then preloadlayout state.y
2675 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2676 IntSet.empty
preloadedpages
2679 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2680 if not
(IntSet.mem
pageno set)
2682 wcmd "freepage %s" opaque
;
2688 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2691 state.currently
<- Idle
;
2694 tilepage l.pageno pageopaque state.layout;
2696 load preloadedpages;
2697 if pagevisible state.layout l.pageno
2698 && layoutready state.layout
2699 then G.postRedisplay "page";
2702 | Some
(layout, _, _) ->
2703 state.currently
<- Idle
;
2704 tilepage l.pageno pageopaque layout;
2709 dolog
"Inconsistent loading state";
2710 logcurrently state.currently
;
2714 | "tile" :: args :: [] ->
2715 let (x, y, opaque
, size
, t
) =
2716 scan args "%u %u %s %u %f"
2717 (fun x y p size t
-> (x, y, p
, size
, t
))
2719 begin match state.currently
with
2720 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2721 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2724 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2726 wcmd "freetile %s" opaque
;
2727 state.currently
<- Idle
;
2731 puttileopaque l col row gen cs angle opaque size t
;
2732 state.memused
<- state.memused
+ size
;
2733 state.uioh#infochanged Memused
;
2735 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2736 opaque
, size
) state.tilelru
;
2739 match state.throttle
with
2740 | None
-> state.layout
2741 | Some
(layout, _, _) -> layout
2744 state.currently
<- Idle
;
2746 && conf.colorspace
= cs
2747 && conf.angle
= angle
2748 && tilevisible layout l.pageno x y
2749 then conttiling l.pageno pageopaque;
2751 begin match state.throttle
with
2753 preload state.layout;
2755 && conf.colorspace
= cs
2756 && conf.angle
= angle
2757 && tilevisible state.layout l.pageno x y
2758 && (not
!wtmode || layoutready state.layout)
2759 then G.postRedisplay "tile nothrottle";
2761 | Some
(layout, y, _) ->
2762 let ready = layoutready layout in
2766 state.layout <- layout;
2767 state.throttle
<- None
;
2768 G.postRedisplay "throttle";
2775 dolog
"Inconsistent tiling state";
2776 logcurrently state.currently
;
2780 | "pdim" :: args :: [] ->
2781 let (n, w, h, _) as pdim
=
2782 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2785 match conf.fitmodel
, conf.columns
with
2786 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2789 state.uioh#infochanged Pdim
;
2790 state.pdims
<- pdim :: state.pdims
2792 | "o" :: args :: [] ->
2793 let (l, n, t
, h, pos
) =
2794 scan args "%u %u %d %u %n"
2795 (fun l n t
h pos
-> l, n, t
, h, pos
)
2797 let s = String.sub
args pos
(String.length
args - pos
) in
2798 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
2800 | "ou" :: args :: [] ->
2801 let (l, len, pos
) = scan args "%u %u %n" (fun l len pos
-> l, len, pos
) in
2802 let s = String.sub
args pos
len in
2803 let pos2 = pos
+ len + 1 in
2804 let uri = String.sub
args pos2 (String.length
args - pos2) in
2805 addoutline (s, l, Ouri
uri)
2807 | "on" :: args :: [] ->
2808 let (l, pos
) = scan args "%u %n" (fun l pos
-> l, pos
) in
2809 let s = String.sub
args pos
(String.length
args - pos
) in
2810 addoutline (s, l, Onone
)
2812 | "a" :: args :: [] ->
2814 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2816 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2818 | "info" :: args :: [] ->
2819 state.docinfo
<- (1, args) :: state.docinfo
2821 | "infoend" :: [] ->
2822 state.uioh#infochanged Docinfo
;
2823 state.docinfo
<- List.rev
state.docinfo
2826 error
"unknown cmd `%S'" cmds
2831 let action = function
2832 | HCprev
-> cbget cb ~
-1
2833 | HCnext
-> cbget cb
1
2834 | HCfirst
-> cbget cb ~
-(cb
.rc)
2835 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2836 and cancel
() = cb
.rc <- rc
2840 let search pattern forward
=
2841 match conf.columns
with
2843 showtext '
!'
"searching does not work properly in split columns mode"
2845 if nonemptystr pattern
2848 match state.layout with
2851 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2853 wcmd "search %d %d %d %d,%s\000"
2854 (btod conf.icase
) pn py (btod forward
) pattern
;
2857 let intentry text key =
2859 if key >= 32 && key < 127
2865 let text = addchar text c in
2869 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2873 let linknentry text key =
2875 if key >= 32 && key < 127
2881 let text = addchar text c in
2885 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2893 let l = String.length
s in
2894 let rec loop pos
n = if pos
= l then n else
2895 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2896 loop (pos
+1) (n*26 + m)
2899 let rec loop n = function
2902 match getopaque l.pageno with
2903 | None
-> loop n rest
2905 let m = getlinkcount opaque
in
2908 let under = getlink opaque
n in
2911 else loop (n-m) rest
2913 loop n state.layout;
2917 let textentry text key =
2918 if key land 0xff00 = 0xff00
2920 else TEcont
(text ^ toutf8
key)
2923 let reqlayout angle fitmodel
=
2924 match state.throttle
with
2926 if nogeomcmds state.geomcmds
2927 then state.anchor <- getanchor ();
2928 conf.angle
<- angle
mod 360;
2931 match state.mode
with
2932 | LinkNav
_ -> state.mode
<- View
2935 conf.fitmodel
<- fitmodel
;
2936 invalidate "reqlayout"
2938 wcmd "reqlayout %d %d %d"
2939 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2944 let settrim trimmargins trimfuzz
=
2945 if nogeomcmds state.geomcmds
2946 then state.anchor <- getanchor ();
2947 conf.trimmargins
<- trimmargins
;
2948 conf.trimfuzz
<- trimfuzz
;
2949 let x0, y0, x1, y1 = trimfuzz
in
2950 invalidate "settrim"
2952 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2957 match state.throttle
with
2959 let zoom = max
0.0001 zoom in
2960 if zoom <> conf.zoom
2962 state.prevzoom
<- (conf.zoom, state.x);
2964 reshape state.winw
state.winh
;
2965 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2968 | Some
(layout, y, started
) ->
2970 match conf.maxwait
with
2974 let dt = now () -. started
in
2982 let setcolumns mode columns coverA coverB
=
2983 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2987 then showtext '
!'
"split mode doesn't work in bird's eye"
2989 conf.columns
<- Csplit
(-columns
, [||]);
2997 conf.columns
<- Csingle
[||];
3002 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
3006 reshape state.winw
state.winh
;
3009 let enterbirdseye () =
3010 let zoom = float conf.thumbw
/. float state.winw
in
3011 let birdseyepageno =
3012 let cy = state.winh
/ 2 in
3016 let rec fold best
= function
3019 let d = cy - (l.pagedispy + l.pagevh/2)
3020 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
3021 if abs
d < abs dbest
3028 state.mode
<- Birdseye
(
3029 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
3032 conf.presentation
<- false;
3033 conf.interpagespace
<- 10;
3034 conf.hlinks
<- false;
3035 conf.fitmodel
<- FitProportional
;
3037 state.mstate
<- Mnone
;
3038 conf.maxwait
<- None
;
3040 match conf.beyecolumns
with
3043 Cmulti
((c, 0, 0), [||])
3044 | None
-> Csingle
[||]
3046 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3049 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3054 reshape state.winw
state.winh
;
3057 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3059 conf.zoom <- c.zoom;
3060 conf.presentation
<- c.presentation
;
3061 conf.interpagespace
<- c.interpagespace
;
3062 conf.maxwait
<- c.maxwait
;
3063 conf.hlinks
<- c.hlinks
;
3064 conf.fitmodel
<- c.fitmodel
;
3065 conf.beyecolumns
<- (
3066 match conf.columns
with
3067 | Cmulti
((c, _, _), _) -> Some
c
3069 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3072 match c.columns
with
3073 | Cmulti
(c, _) -> Cmulti
(c, [||])
3074 | Csingle
_ -> Csingle
[||]
3075 | Csplit
(c, _) -> Csplit
(c, [||])
3079 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3082 reshape state.winw
state.winh
;
3083 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3087 let togglebirdseye () =
3088 match state.mode
with
3089 | Birdseye vals
-> leavebirdseye vals
true
3090 | View
-> enterbirdseye ()
3094 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3095 let pageno = max
0 (pageno - incr
) in
3096 let rec loop = function
3097 | [] -> gotopage1 pageno 0
3098 | l :: _ when l.pageno = pageno ->
3099 if l.pagedispy >= 0 && l.pagey = 0
3100 then G.postRedisplay "upbirdseye"
3101 else gotopage1 pageno 0
3102 | _ :: rest
-> loop rest
3105 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3108 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3109 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3110 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3111 let rec loop = function
3113 let y, h = getpageyh pageno in
3114 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3116 | l :: _ when l.pageno = pageno ->
3117 if l.pagevh != l.pageh
3118 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3119 else G.postRedisplay "downbirdseye"
3120 | _ :: rest
-> loop rest
3125 let boundastep h step
=
3127 then bound step ~
-h 0
3131 let optentry mode
_ key =
3132 let btos b = if b then "on" else "off" in
3133 if key >= 32 && key < 127
3135 let c = Char.chr
key in
3139 try conf.scrollstep
<- int_of_string
s with exc
->
3140 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3142 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3147 conf.autoscrollstep
<- boundastep state.winh
(int_of_string
s);
3148 if state.autoscroll
<> None
3149 then state.autoscroll
<- Some
conf.autoscrollstep
3151 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3153 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3158 let n, a, b = multicolumns_of_string s in
3159 setcolumns mode
n a b;
3161 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3163 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3168 let zoom = float (int_of_string
s) /. 100.0 in
3171 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3173 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3178 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3180 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3181 begin match mode
with
3183 leavebirdseye beye
false;
3188 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3190 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3195 Some
(int_of_string
s)
3197 state.text <- Printf.sprintf
"bad integer `%s': %s"
3201 | Some angle
-> reqlayout angle
conf.fitmodel
3204 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3207 conf.icase
<- not
conf.icase
;
3208 TEdone
("case insensitive search " ^
(btos conf.icase
))
3211 conf.preload <- not
conf.preload;
3213 TEdone
("preload " ^
(btos conf.preload))
3216 conf.verbose
<- not
conf.verbose
;
3217 TEdone
("verbose " ^
(btos conf.verbose
))
3220 conf.debug
<- not
conf.debug
;
3221 TEdone
("debug " ^
(btos conf.debug
))
3224 conf.maxhfit
<- not
conf.maxhfit
;
3225 state.maxy
<- calcheight ();
3226 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3229 conf.crophack
<- not
conf.crophack
;
3230 TEdone
("crophack " ^
btos conf.crophack
)
3234 match conf.maxwait
with
3236 conf.maxwait
<- Some infinity
;
3237 "always wait for page to complete"
3239 conf.maxwait
<- None
;
3240 "show placeholder if page is not ready"
3245 conf.underinfo
<- not
conf.underinfo
;
3246 TEdone
("underinfo " ^
btos conf.underinfo
)
3249 conf.savebmarks
<- not
conf.savebmarks
;
3250 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3256 match state.layout with
3261 conf.interpagespace
<- int_of_string
s;
3262 docolumns conf.columns
;
3263 state.maxy
<- calcheight ();
3264 let y = getpagey pageno in
3267 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3269 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3273 match conf.fitmodel
with
3274 | FitProportional
-> FitWidth
3275 | _ -> FitProportional
3277 reqlayout conf.angle
fm;
3278 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3281 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3282 TEdone
("trim margins " ^
btos conf.trimmargins
)
3285 conf.invert
<- not
conf.invert
;
3286 TEdone
("invert colors " ^
btos conf.invert
)
3290 cbput state.hists
.sel
s;
3293 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3294 textentry, ondone, true)
3298 then conf.pax
<- Some
(ref (0.0, 0, 0))
3299 else conf.pax
<- None
;
3300 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3303 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3309 class type lvsource
= object
3310 method getitemcount
: int
3311 method getitem
: int -> (string * int)
3312 method hasaction
: int -> bool
3321 method getactive
: int
3322 method getfirst
: int
3323 method getqsearch
: string
3324 method setqsearch
: string -> unit
3328 class virtual lvsourcebase
= object
3329 val mutable m_active
= 0
3330 val mutable m_first
= 0
3331 val mutable m_qsearch
= ""
3332 val mutable m_pan
= 0
3333 method getactive
= m_active
3334 method getfirst
= m_first
3335 method getqsearch
= m_qsearch
3336 method getpan
= m_pan
3337 method setqsearch
s = m_qsearch
<- s
3340 let withoutlastutf8 s =
3341 let len = String.length
s in
3349 let b = Char.code
s.[pos
] in
3350 if b land 0b11000000 = 0b11000000
3355 if Char.code
s.[len-1] land 0x80 = 0
3359 String.sub
s 0 first;
3362 let textentrykeyboard
3363 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3365 if key >= 0xffb0 && key <= 0xffb9
3366 then key - 0xffb0 + 48 else key
3369 state.mode
<- Textentry
(te
, onleave
);
3372 G.postRedisplay "textentrykeyboard enttext";
3374 let histaction cmd
=
3377 | Some
(action, _) ->
3378 state.mode
<- Textentry
(
3379 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3381 G.postRedisplay "textentry histaction"
3384 | 0xff08 -> (* backspace *)
3385 if emptystr
text && cancelonempty
3388 G.postRedisplay "textentrykeyboard after cancel";
3391 let s = withoutlastutf8 text in
3392 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3394 | 0xff0d | 0xff8d -> (* (kp) enter *)
3397 G.postRedisplay "textentrykeyboard after confirm"
3399 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3400 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3401 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3402 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3404 | 0xff1b -> (* escape*)
3407 begin match opthist
with
3409 | Some
(_, onhistcancel
) -> onhistcancel
()
3413 G.postRedisplay "textentrykeyboard after cancel2"
3416 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3419 | 0xff9f | 0xffff -> () (* delete *)
3422 && key land 0xff00 != 0xff00 (* keyboard *)
3423 && key land 0xfe00 != 0xfe00 (* xkb *)
3424 && key land 0xfd00 != 0xfd00 (* 3270 *)
3426 begin match onkey
text key with
3430 G.postRedisplay "textentrykeyboard after confirm2";
3433 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3437 G.postRedisplay "textentrykeyboard after cancel3"
3440 state.mode
<- Textentry
(te
, onleave
);
3441 G.postRedisplay "textentrykeyboard switch";
3445 vlog "unhandled key %s" (Wsi.keyname
key)
3448 let firstof first active
=
3449 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3450 then max
0 (active
- (fstate.maxrows
/2))
3454 let calcfirst first active
=
3457 let rows = active
- first in
3458 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3462 let scrollph y maxy
=
3463 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3464 let sh = float state.winh
/. sh in
3465 let sh = max
sh (float conf.scrollh
) in
3467 let percent = float y /. float maxy
in
3468 let position = (float state.winh
-. sh) *. percent in
3471 if position +. sh > float state.winh
3472 then float state.winh
-. sh
3478 let coe s = (s :> uioh
);;
3480 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3482 val m_pan
= source#getpan
3483 val m_first
= source#getfirst
3484 val m_active
= source#getactive
3485 val m_qsearch
= source#getqsearch
3486 val m_prev_uioh
= state.uioh
3488 method private elemunder
y =
3489 let n = y / (fstate.fontsize
+1) in
3490 if m_first
+ n < source#getitemcount
3492 if source#hasaction
(m_first
+ n)
3493 then Some
(m_first
+ n)
3500 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3501 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3502 filledrect 0. 0. (float state.winw
) (float state.winh
);
3503 GlDraw.color
(1., 1., 1.);
3504 Gl.enable `texture_2d
;
3505 let fs = fstate.fontsize
in
3507 let ww = fstate.wwidth
in
3508 let tabw = 30.0*.ww in
3509 let itemcount = source#getitemcount
in
3511 if (row - m_first
) > fstate.maxrows
3514 if row >= 0 && row < itemcount
3516 let (s, level
) = source#getitem
row in
3517 let y = (row - m_first
) * nfs in
3518 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3521 Gl.disable `texture_2d
;
3522 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3523 GlDraw.color
(1., 1., 1.) ~
alpha;
3524 linerect 1. (float (y + 1))
3525 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3526 GlDraw.color
(1., 1., 1.);
3527 Gl.enable `texture_2d
;
3530 let drawtabularstring s =
3531 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3534 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3537 let len = String.length
s - tabpos - 1 in
3538 let s1 = String.sub
s 0 tabpos
3539 and s2
= String.sub
s (tabpos + 1) len in
3540 let nx = drawstr x s1 in
3542 let x = x +. (max
tabw sw) in
3549 let _ = drawtabularstring s in
3556 Gl.disable `texture_2d
;
3558 method updownlevel incr
=
3559 let len = source#getitemcount
in
3561 if m_active
>= 0 && m_active
< len
3562 then snd
(source#getitem m_active
)
3566 if i
= len then i
-1 else if i
= -1 then 0 else
3567 let _, l = source#getitem i
in
3568 if l != curlevel then i
else flow (i
+incr
)
3570 let active = flow m_active
in
3571 let first = calcfirst m_first
active in
3572 G.postRedisplay "outline updownlevel";
3573 {< m_active
= active; m_first
= first >}
3575 method private key1
key mask
=
3576 let set1 active first qsearch
=
3577 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3579 let search active pattern incr
=
3580 let active = if active = -1 then m_first
else active in
3583 if n >= 0 && n < source#getitemcount
3585 let s, _ = source#getitem
n in
3587 (try ignore
(Str.search_forward
re s 0); true
3588 with Not_found
-> false)
3590 else loop (n + incr
)
3597 let re = Str.regexp_case_fold pattern
in
3603 let itemcount = source#getitemcount
in
3604 let find start incr
=
3606 if i
= -1 || i
= itemcount
3609 if source#hasaction i
3611 else find (i
+ incr
)
3616 let set active first =
3617 let first = bound first 0 (itemcount - fstate.maxrows
) in
3619 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3622 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3624 let incr1 = if incr
> 0 then 1 else -1 in
3625 if isvisible m_first m_active
3628 let next = m_active
+ incr
in
3630 if next < 0 || next >= itemcount
3632 else find next incr1
3634 if abs
(m_active
- next) > fstate.maxrows
3640 let first = m_first
+ incr
in
3641 let first = bound first 0 (itemcount - fstate.maxrows
) in
3643 let next = m_active
+ incr
in
3644 let next = bound next 0 (itemcount - 1) in
3651 if isvisible first next
3658 let first = min
next m_first
in
3660 if abs
(next - first) > fstate.maxrows
3666 let first = m_first
+ incr
in
3667 let first = bound first 0 (itemcount - 1) in
3669 let next = m_active
+ incr
in
3670 let next = bound next 0 (itemcount - 1) in
3671 let next = find next incr1 in
3673 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3675 let active = if m_active
= -1 then next else m_active
in
3680 if isvisible first active
3686 G.postRedisplay "listview navigate";
3690 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3691 let incr = if key = 0x72 then -1 else 1 in
3693 match search (m_active
+ incr) m_qsearch
incr with
3695 state.text <- m_qsearch ^
" [not found]";
3698 state.text <- m_qsearch
;
3699 active, firstof m_first
active
3701 G.postRedisplay "listview ctrl-r/s";
3702 set1 active first m_qsearch
;
3704 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3705 if m_active
>= 0 && m_active
< source#getitemcount
3707 let s, _ = source#getitem m_active
in
3712 | 0xff08 -> (* backspace *)
3713 if emptystr m_qsearch
3716 let qsearch = withoutlastutf8 m_qsearch
in
3720 G.postRedisplay "listview empty qsearch";
3721 set1 m_active m_first
"";
3725 match search m_active
qsearch ~
-1 with
3727 state.text <- qsearch ^
" [not found]";
3730 state.text <- qsearch;
3731 active, firstof m_first
active
3733 G.postRedisplay "listview backspace qsearch";
3734 set1 active first qsearch
3737 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3738 let pattern = m_qsearch ^ toutf8
key in
3740 match search m_active
pattern 1 with
3742 state.text <- pattern ^
" [not found]";
3745 state.text <- pattern;
3746 active, firstof m_first
active
3748 G.postRedisplay "listview qsearch add";
3749 set1 active first pattern;
3751 | 0xff1b -> (* escape *)
3753 if emptystr m_qsearch
3755 G.postRedisplay "list view escape";
3758 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3760 | None
-> m_prev_uioh
3765 G.postRedisplay "list view kill qsearch";
3766 source#setqsearch
"";
3767 coe {< m_qsearch
= "" >}
3770 | 0xff0d | 0xff8d -> (* (kp) enter *)
3772 let self = {< m_qsearch
= "" >} in
3773 source#setqsearch
"";
3775 G.postRedisplay "listview enter";
3776 if m_active
>= 0 && m_active
< source#getitemcount
3778 source#exit
(coe self) false m_active m_first m_pan
"";
3781 source#exit
(coe self) true m_active m_first m_pan
"";
3784 begin match opt with
3785 | None
-> m_prev_uioh
3789 | 0xff9f | 0xffff -> (* (kp) delete *)
3792 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3793 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3794 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3795 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3797 | 0xff53 | 0xff98 -> (* (kp) right *)
3799 G.postRedisplay "listview right";
3800 coe {< m_pan
= m_pan
- 1 >}
3802 | 0xff51 | 0xff96 -> (* (kp) left *)
3804 G.postRedisplay "listview left";
3805 coe {< m_pan
= m_pan
+ 1 >}
3807 | 0xff50 | 0xff95 -> (* (kp) home *)
3808 let active = find 0 1 in
3809 G.postRedisplay "listview home";
3812 | 0xff57 | 0xff9c -> (* (kp) end *)
3813 let first = max
0 (itemcount - fstate.maxrows
) in
3814 let active = find (itemcount - 1) ~
-1 in
3815 G.postRedisplay "listview end";
3818 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3822 dolog
"listview unknown key %#x" key; coe self
3824 method key key mask
=
3825 match state.mode
with
3826 | Textentry te
-> textentrykeyboard key mask te
; coe self
3827 | _ -> self#key1
key mask
3829 method button button down
x y _ =
3832 | 1 when x > state.winw
- conf.scrollbw
->
3833 G.postRedisplay "listview scroll";
3836 let _, position, sh = self#
scrollph in
3837 if y > truncate
position && y < truncate
(position +. sh)
3839 state.mstate
<- Mscrolly
;
3843 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3844 let first = truncate
(s *. float source#getitemcount
) in
3845 let first = min source#getitemcount
first in
3846 Some
(coe {< m_first
= first; m_active
= first >})
3848 state.mstate
<- Mnone
;
3851 | 1 when not down
->
3852 begin match self#elemunder
y with
3854 G.postRedisplay "listview click";
3856 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3860 | n when (n == 4 || n == 5) && not down
->
3861 let len = source#getitemcount
in
3863 if n = 5 && m_first
+ fstate.maxrows
>= len
3867 let first = m_first
+ (if n == 4 then -1 else 1) in
3868 bound first 0 (len - 1)
3870 G.postRedisplay "listview wheel";
3871 Some
(coe {< m_first
= first >})
3872 | n when (n = 6 || n = 7) && not down
->
3873 let inc = if n = 7 then -1 else 1 in
3874 G.postRedisplay "listview hwheel";
3875 Some
(coe {< m_pan
= m_pan
+ inc >})
3880 | None
-> m_prev_uioh
3883 method multiclick
_ x y = self#button
1 true x y
3886 match state.mstate
with
3888 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3889 let first = truncate
(s *. float source#getitemcount
) in
3890 let first = min source#getitemcount
first in
3891 G.postRedisplay "listview motion";
3892 coe {< m_first
= first; m_active
= first >}
3895 method pmotion
x y =
3896 if x < state.winw
- conf.scrollbw
3899 match self#elemunder
y with
3900 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3901 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3905 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3910 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3914 method infochanged
_ = ()
3916 method scrollpw
= (0, 0.0, 0.0)
3918 let nfs = fstate.fontsize
+ 1 in
3919 let y = m_first
* nfs in
3920 let itemcount = source#getitemcount
in
3921 let maxi = max
0 (itemcount - fstate.maxrows
) in
3922 let maxy = maxi * nfs in
3923 let p, h = scrollph y maxy in
3926 method modehash
= modehash
3927 method eformsgs
= false
3930 class outlinelistview ~source
=
3931 let settext autonarrow
s =
3933 then state.text <- "[" ^
s ^
"]"
3934 else state.text <- s
3938 ~source
:(source
:> lvsource
)
3940 ~modehash
:(findkeyhash conf "outline")
3943 val m_autonarrow
= false
3945 method key key mask
=
3947 if emptystr
state.text
3949 else fstate.maxrows - 2
3951 let calcfirst first active =
3954 let rows = active - first in
3955 if rows > maxrows then active - maxrows else first
3959 let active = m_active
+ incr in
3960 let active = bound active 0 (source#getitemcount
- 1) in
3961 let first = calcfirst m_first
active in
3962 G.postRedisplay "outline navigate";
3963 coe {< m_active
= active; m_first
= first >}
3965 let navscroll first =
3967 let dist = m_active
- first in
3973 else first + maxrows
3976 G.postRedisplay "outline navscroll";
3977 coe {< m_first
= first; m_active
= active >}
3979 let ctrl = Wsi.withctrl mask
in
3981 | 97 when ctrl -> (* ctrl-a *)
3983 then source#denarrow
3984 else source#narrow m_qsearch
;
3985 settext (not m_autonarrow
) m_qsearch
;
3986 G.postRedisplay "toggle auto narrowing";
3987 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3989 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3991 G.postRedisplay "toggle auto narrowing";
3992 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3994 | 110 when ctrl -> (* ctrl-n *)
3995 source#narrow m_qsearch
;
3997 then source#add_narrow_pattern m_qsearch
;
3998 G.postRedisplay "outline ctrl-n";
3999 coe {< m_first
= 0; m_active
= 0 >}
4001 | 115 when ctrl -> (* ctrl-s *)
4002 let active = source#calcactive
(getanchor ()) in
4003 let first = firstof m_first
active in
4004 G.postRedisplay "outline ctrl-s";
4005 coe {< m_first
= first; m_active
= active >}
4007 | 117 when ctrl -> (* ctrl-u *)
4008 source#del_narrow_pattern
;
4009 let pattern = source#renarrow
in
4010 G.postRedisplay "outline ctrl-u";
4012 if emptystr
pattern then "" else "Narrowed to " ^
pattern
4014 settext m_autonarrow
text;
4015 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4017 | 108 when ctrl -> (* ctrl-l *)
4018 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
4019 G.postRedisplay "outline ctrl-l";
4020 coe {< m_first
= first >}
4022 | 0xff1b -> (* escape *)
4023 let o = super#
key key mask
in
4026 if nonemptystr m_qsearch
4028 source#add_narrow_pattern m_qsearch
;
4034 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
4035 if nonemptystr m_qsearch
4036 then source#add_narrow_pattern m_qsearch
;
4039 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
4040 let pattern = m_qsearch ^ toutf8
key in
4041 G.postRedisplay "outlinelistview autonarrow add";
4042 source#narrow
pattern;
4043 settext true pattern;
4044 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4046 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4047 if emptystr m_qsearch
4050 let pattern = withoutlastutf8 m_qsearch
in
4051 G.postRedisplay "outlinelistview autonarrow backspace";
4052 ignore
(source#renarrow
);
4053 source#narrow
pattern;
4054 settext true pattern;
4055 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4057 | 0xff9f | 0xffff -> (* (kp) delete *)
4058 source#remove m_active
;
4059 G.postRedisplay "outline delete";
4060 let active = max
0 (m_active
-1) in
4061 coe {< m_first
= firstof m_first
active;
4062 m_active
= active >}
4064 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4065 navscroll (max
0 (m_first
- 1))
4067 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4068 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4070 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4071 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4072 | 0xff55 | 0xff9a -> (* (kp) prior *)
4073 navigate ~
-(fstate.maxrows)
4074 | 0xff56 | 0xff9b -> (* (kp) next *)
4075 navigate fstate.maxrows
4077 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4081 G.postRedisplay "outline ctrl right";
4082 {< m_pan
= m_pan
+ 1 >}
4084 else self#updownlevel
1
4088 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4092 G.postRedisplay "outline ctrl left";
4093 {< m_pan
= m_pan
- 1 >}
4095 else self#updownlevel ~
-1
4099 | 0xff50 | 0xff95 -> (* (kp) home *)
4100 G.postRedisplay "outline home";
4101 coe {< m_first
= 0; m_active
= 0 >}
4103 | 0xff57 | 0xff9c -> (* (kp) end *)
4104 let active = source#getitemcount
- 1 in
4105 let first = max
0 (active - fstate.maxrows) in
4106 G.postRedisplay "outline end";
4107 coe {< m_active
= active; m_first
= first >}
4109 | _ -> super#
key key mask
4112 let gotounder under =
4113 let getpath filename
=
4115 if nonemptystr filename
4117 if Filename.is_relative filename
4119 let dir = Filename.dirname
state.path in
4121 if Filename.is_implicit
dir
4122 then Filename.concat
(Sys.getcwd
()) dir
4125 Filename.concat
dir filename
4129 if Sys.file_exists
path
4134 | Ulinkgoto
(pageno, top) ->
4138 gotopage1 pageno top;
4144 | Uremote
(filename
, pageno) ->
4145 let path = getpath filename
in
4150 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
4151 try popen command []
4153 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
4156 let anchor = getanchor () in
4157 let ranchor = state.path, state.password
, anchor, state.origin
in
4159 state.anchor <- (pageno, 0.0, 0.0);
4160 state.ranchors
<- ranchor :: state.ranchors
;
4163 else showtext '
!'
("Could not find " ^ filename
)
4165 | Uremotedest
(filename
, destname
) ->
4166 let path = getpath filename
in
4171 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
4172 try popen command []
4175 "failed to execute `%s': %s\n" command (exntos exn
);
4178 let anchor = getanchor () in
4179 let ranchor = state.path, state.password
, anchor, state.origin
in
4181 state.nameddest
<- destname
;
4182 state.ranchors
<- ranchor :: state.ranchors
;
4185 else showtext '
!'
("Could not find " ^ filename
)
4187 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4190 let gotooutline (_, _, kind
) =
4194 let (pageno, y, _) = anchor in
4196 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4199 | Ouri
uri -> gotounder (Ulinkuri
uri)
4200 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
4201 | Oremote remote
-> gotounder (Uremote remote
)
4202 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
4205 let outlinesource usebookmarks
=
4208 inherit lvsourcebase
4209 val mutable m_items
= empty
4210 val mutable m_orig_items
= empty
4211 val mutable m_narrow_patterns
= []
4212 val mutable m_hadremovals
= false
4214 method getitemcount
=
4215 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4218 if n == Array.length m_items
&& m_hadremovals
4220 ("[Confirm removal]", 0)
4222 let s, n, _ = m_items
.(n) in
4225 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4226 ignore
(uioh
, first, qsearch);
4227 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4229 if m_narrow_patterns
= []
4235 if not
confrimremoval
4237 gotooutline m_items
.(active);
4241 state.bookmarks
<- Array.to_list m_items
;
4242 m_orig_items
<- m_items
;
4245 else m_items
<- items;
4249 method hasaction
_ = true
4252 if Array.length m_items
!= Array.length m_orig_items
4255 match m_narrow_patterns
with
4257 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
4259 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4262 method narrow
pattern =
4263 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4267 let rec loop accu n =
4269 then m_items
<- Array.of_list
accu
4271 let (s, _, _) as o = m_items
.(n) in
4273 if (try ignore
(Str.search_forward
re s 0); true
4274 with Not_found
-> false)
4280 loop [] (Array.length m_items
- 1)
4285 then Array.of_list
state.bookmarks
4288 m_items
<- m_orig_items
4293 if m >= 0 && m < Array.length m_items
4295 m_hadremovals
<- true;
4296 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4297 let n = if n >= m then n+1 else n in
4302 method add_narrow_pattern
pattern =
4303 m_narrow_patterns
<- pattern :: m_narrow_patterns
4305 method del_narrow_pattern
=
4306 match m_narrow_patterns
with
4307 | _ :: rest
-> m_narrow_patterns
<- rest
4312 match m_narrow_patterns
with
4313 | pattern :: [] -> self#narrow
pattern; pattern
4315 List.fold_left
(fun accu pattern ->
4316 self#narrow
pattern;
4317 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
4319 method calcactive
anchor =
4320 let rely = getanchory anchor in
4321 let rec loop n best bestd
=
4322 if n = Array.length m_items
4325 let _, _, kind
= m_items
.(n) in
4328 let orely = getanchory anchor in
4329 let d = abs
(orely - rely) in
4332 else loop (n+1) best bestd
4333 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
4334 loop (n+1) best bestd
4338 method reset
anchor items =
4339 m_hadremovals
<- false;
4340 if m_orig_items
== empty
4342 m_orig_items
<- items;
4343 if m_narrow_patterns
== []
4344 then m_items
<- items;
4346 let active = self#calcactive
anchor in
4348 m_first
<- firstof m_first
active
4352 let enterselector usebookmarks
=
4353 let source = outlinesource usebookmarks
in
4357 then Array.of_list
state.bookmarks
4360 if Array.length
outlines = 0
4362 showtext ' ' errmsg
;
4365 state.text <- source#greetmsg
;
4366 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4367 let anchor = getanchor () in
4368 source#reset
anchor outlines;
4369 state.uioh
<- coe (new outlinelistview ~
source);
4370 G.postRedisplay "enter selector";
4374 let enteroutlinemode =
4375 let f = enterselector false in
4376 fun ()-> f "Document has no outline";
4379 let enterbookmarkmode =
4380 let f = enterselector true in
4381 fun () -> f "Document has no bookmarks (yet)";
4384 let color_of_string s =
4385 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4386 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4390 let color_to_string (r, g, b) =
4391 let r = truncate
(r *. 256.0)
4392 and g = truncate
(g *. 256.0)
4393 and b = truncate
(b *. 256.0) in
4394 Printf.sprintf
"%d/%d/%d" r g b
4397 let irect_of_string s =
4398 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4401 let irect_to_string (x0,y0,x1,y1) =
4402 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4405 let makecheckers () =
4406 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4408 converted by Issac Trotts. July 25, 2002 *)
4409 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4410 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4411 let id = GlTex.gen_texture
() in
4412 GlTex.bind_texture `texture_2d
id;
4413 GlPix.store
(`unpack_alignment
1);
4414 GlTex.image2d
image;
4415 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4416 [ `mag_filter `nearest
; `min_filter `nearest
];
4420 let setcheckers enabled
=
4421 match state.texid
with
4423 if enabled
then state.texid
<- Some
(makecheckers ())
4428 GlTex.delete_texture texid
;
4429 state.texid
<- None
;
4433 let int_of_string_with_suffix s =
4434 let l = String.length
s in
4438 let suffix = Char.lowercase
s.[l-1] in
4440 | 'k'
-> String.sub
s 0 (l-1), 10
4441 | '
m'
-> String.sub
s 0 (l-1), 20
4442 | '
g'
-> String.sub
s 0 (l-1), 30
4446 let n = int_of_string
s1 in
4447 let m = n lsl shift
in
4449 then raise
(Failure
"value too large")
4453 let string_with_suffix_of_int n =
4457 let units = [(30, "G"); (20, "M"); (10, "K")] in
4460 let h = n mod 1000 in
4463 then string_of_int
h ^
s
4465 let s = Printf.sprintf
"_%03d%s" h s in
4471 let rec find = function
4473 | (shift
, suffix) :: rest
->
4474 if (n land ((1 lsl shift
) - 1)) = 0
4475 then prettyint (n lsr shift
) ^
suffix
4481 let defghyllscroll = (40, 8, 32);;
4482 let fastghyllscroll = (5,1,2);;
4483 let neatghyllscroll = (10,1,9);;
4484 let ghyllscroll_of_string s =
4486 | "default" -> Some
defghyllscroll
4487 | "fast" -> Some
(5,1,2)
4488 | "neat" -> Some
(10,1,9)
4489 | "" | "none" -> None
4491 let (n,a,b) as nab
=
4492 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4493 if n <= a || n <= b || a >= b
4494 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4499 let ghyllscroll_to_string ((n, a, b) as nab
) =
4500 (**) if nab
= defghyllscroll then "default"
4501 else if nab
= fastghyllscroll then "fast"
4502 else if nab
= neatghyllscroll then "neat"
4503 else Printf.sprintf
"%d,%d,%d" n a b;
4506 let describe_location () =
4507 let fn = page_of_y state.y in
4508 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4509 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4513 else (100. *. (float state.y /. float maxy))
4517 Printf.sprintf
"page %d of %d [%.2f%%]"
4518 (fn+1) state.pagecount
percent
4521 "pages %d-%d of %d [%.2f%%]"
4522 (fn+1) (ln+1) state.pagecount
percent
4525 let setpresentationmode v
=
4526 let n = page_of_y state.y in
4527 state.anchor <- (n, 0.0, 1.0);
4528 conf.presentation
<- v
;
4529 if conf.fitmodel
= FitPage
4530 then reqlayout conf.angle
conf.fitmodel
;
4535 let btos b = if b then "\xe2\x88\x9a" else "" in
4536 let showextended = ref false in
4537 let leave mode
= function
4538 | Confirm
-> state.mode
<- mode
4539 | Cancel
-> state.mode
<- mode
in
4542 val mutable m_first_time
= true
4543 val mutable m_l
= []
4544 val mutable m_a
= [||]
4545 val mutable m_prev_uioh
= nouioh
4546 val mutable m_prev_mode
= View
4548 inherit lvsourcebase
4550 method reset prev_mode prev_uioh
=
4551 m_a
<- Array.of_list
(List.rev m_l
);
4553 m_prev_mode
<- prev_mode
;
4554 m_prev_uioh
<- prev_uioh
;
4558 if n >= Array.length m_a
4562 | _, _, _, Action
_ -> m_active
<- n
4566 m_first_time
<- false;
4569 method int name get
set =
4571 (name, `
int get
, 1, Action
(
4574 try set (int_of_string
s)
4576 state.text <- Printf.sprintf
"bad integer `%s': %s"
4580 let te = name ^
": ", "", None
, intentry, ondone, true in
4581 state.mode
<- Textentry
(te, leave m_prev_mode
);
4585 method int_with_suffix
name get
set =
4587 (name, `intws get
, 1, Action
(
4590 try set (int_of_string_with_suffix s)
4592 state.text <- Printf.sprintf
"bad integer `%s': %s"
4597 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4599 state.mode
<- Textentry
(te, leave m_prev_mode
);
4603 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4605 (name, `
bool (btos, get
), offset
, Action
(
4612 method color
name get
set =
4614 (name, `color get
, 1, Action
(
4616 let invalid = (nan
, nan
, nan
) in
4619 try color_of_string s
4621 state.text <- Printf.sprintf
"bad color `%s': %s"
4628 let te = name ^
": ", "", None
, textentry, ondone, true in
4629 state.text <- color_to_string (get
());
4630 state.mode
<- Textentry
(te, leave m_prev_mode
);
4634 method string name get
set =
4636 (name, `
string get
, 1, Action
(
4638 let ondone s = set s in
4639 let te = name ^
": ", "", None
, textentry, ondone, true in
4640 state.mode
<- Textentry
(te, leave m_prev_mode
);
4644 method colorspace
name get
set =
4646 (name, `
string get
, 1, Action
(
4650 inherit lvsourcebase
4653 m_active
<- CSTE.to_int conf.colorspace
;
4656 method getitemcount
=
4657 Array.length
CSTE.names
4660 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4661 ignore
(uioh
, first, pan
, qsearch);
4662 if not cancel
then set active;
4664 method hasaction
_ = true
4668 let modehash = findkeyhash conf "info" in
4669 coe (new listview ~
source ~trusted
:true ~
modehash)
4672 method paxmark
name get
set =
4674 (name, `
string get
, 1, Action
(
4678 inherit lvsourcebase
4681 m_active
<- MTE.to_int conf.paxmark
;
4684 method getitemcount
= Array.length
MTE.names
4685 method getitem
n = (MTE.names.(n), 0)
4686 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4687 ignore
(uioh
, first, pan
, qsearch);
4688 if not cancel
then set active;
4690 method hasaction
_ = true
4694 let modehash = findkeyhash conf "info" in
4695 coe (new listview ~
source ~trusted
:true ~
modehash)
4698 method fitmodel
name get
set =
4700 (name, `
string get
, 1, Action
(
4704 inherit lvsourcebase
4707 m_active
<- FMTE.to_int conf.fitmodel
;
4710 method getitemcount
= Array.length
FMTE.names
4711 method getitem
n = (FMTE.names.(n), 0)
4712 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4713 ignore
(uioh
, first, pan
, qsearch);
4714 if not cancel
then set active;
4716 method hasaction
_ = true
4720 let modehash = findkeyhash conf "info" in
4721 coe (new listview ~
source ~trusted
:true ~
modehash)
4724 method caption
s offset
=
4725 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4727 method caption2
s f offset
=
4728 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4730 method getitemcount
= Array.length m_a
4733 let tostr = function
4734 | `
int f -> string_of_int
(f ())
4735 | `intws
f -> string_with_suffix_of_int (f ())
4737 | `color
f -> color_to_string (f ())
4738 | `
bool (btos, f) -> btos (f ())
4741 let name, t
, offset
, _ = m_a
.(n) in
4742 ((let s = tostr t
in
4744 then Printf.sprintf
"%s\t%s" name s
4748 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4752 m_qsearch
<- qsearch;
4754 match m_a
.(active) with
4755 | _, _, _, Action
f -> f uioh
4767 method hasaction
n =
4769 | _, _, _, Action
_ -> true
4773 let rec fillsrc prevmode prevuioh
=
4774 let sep () = src#caption
"" 0 in
4775 let colorp name get
set =
4777 (fun () -> color_to_string (get
()))
4780 let c = color_of_string v in
4783 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4786 let oldmode = state.mode
in
4787 let birdseye = isbirdseye state.mode
in
4789 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4791 src#
bool "presentation mode"
4792 (fun () -> conf.presentation
)
4793 (fun v -> setpresentationmode v);
4795 src#
bool "ignore case in searches"
4796 (fun () -> conf.icase
)
4797 (fun v -> conf.icase
<- v);
4800 (fun () -> conf.preload)
4801 (fun v -> conf.preload <- v);
4803 src#
bool "highlight links"
4804 (fun () -> conf.hlinks
)
4805 (fun v -> conf.hlinks
<- v);
4807 src#
bool "under info"
4808 (fun () -> conf.underinfo
)
4809 (fun v -> conf.underinfo
<- v);
4811 src#
bool "persistent bookmarks"
4812 (fun () -> conf.savebmarks
)
4813 (fun v -> conf.savebmarks
<- v);
4815 src#fitmodel
"fit model"
4816 (fun () -> FMTE.to_string conf.fitmodel
)
4817 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4819 src#
bool "trim margins"
4820 (fun () -> conf.trimmargins
)
4821 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4823 src#
bool "persistent location"
4824 (fun () -> conf.jumpback
)
4825 (fun v -> conf.jumpback
<- v);
4828 src#
int "inter-page space"
4829 (fun () -> conf.interpagespace
)
4831 conf.interpagespace
<- n;
4832 docolumns conf.columns
;
4834 match state.layout with
4839 state.maxy <- calcheight ();
4840 let y = getpagey pageno in
4845 (fun () -> conf.pagebias
)
4846 (fun v -> conf.pagebias
<- v);
4848 src#
int "scroll step"
4849 (fun () -> conf.scrollstep
)
4850 (fun n -> conf.scrollstep
<- n);
4852 src#
int "horizontal scroll step"
4853 (fun () -> conf.hscrollstep
)
4854 (fun v -> conf.hscrollstep
<- v);
4856 src#
int "auto scroll step"
4858 match state.autoscroll
with
4860 | _ -> conf.autoscrollstep
)
4862 let n = boundastep state.winh
n in
4863 if state.autoscroll
<> None
4864 then state.autoscroll
<- Some
n;
4865 conf.autoscrollstep
<- n);
4868 (fun () -> truncate
(conf.zoom *. 100.))
4869 (fun v -> setzoom ((float v) /. 100.));
4872 (fun () -> conf.angle
)
4873 (fun v -> reqlayout v conf.fitmodel
);
4875 src#
int "scroll bar width"
4876 (fun () -> conf.scrollbw
)
4879 reshape state.winw
state.winh
;
4882 src#
int "scroll handle height"
4883 (fun () -> conf.scrollh
)
4884 (fun v -> conf.scrollh
<- v;);
4886 src#
int "thumbnail width"
4887 (fun () -> conf.thumbw
)
4889 conf.thumbw
<- min
4096 v;
4892 leavebirdseye beye
false;
4897 let mode = state.mode in
4898 src#
string "columns"
4900 match conf.columns
with
4902 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4903 | Csplit
(count
, _) -> "-" ^ string_of_int count
4906 let n, a, b = multicolumns_of_string v in
4907 setcolumns mode n a b);
4910 src#caption
"Pixmap cache" 0;
4911 src#int_with_suffix
"size (advisory)"
4912 (fun () -> conf.memlimit
)
4913 (fun v -> conf.memlimit
<- v);
4916 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4917 (string_with_suffix_of_int state.memused
)
4918 (Hashtbl.length
state.tilemap
)) 1;
4921 src#caption
"Layout" 0;
4922 src#caption2
"Dimension"
4924 Printf.sprintf
"%dx%d (virtual %dx%d)"
4925 state.winw
state.winh
4930 src#caption2
"Position" (fun () ->
4931 Printf.sprintf
"%dx%d" state.x state.y
4934 src#caption2
"Position" (fun () -> describe_location ()) 1
4938 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4939 "Save these parameters as global defaults at exit"
4940 (fun () -> conf.bedefault
)
4941 (fun v -> conf.bedefault
<- v)
4945 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4946 src#
bool ~offset
:0 ~
btos "Extended parameters"
4947 (fun () -> !showextended)
4948 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4952 (fun () -> conf.checkers
)
4953 (fun v -> conf.checkers
<- v; setcheckers v);
4954 src#
bool "update cursor"
4955 (fun () -> conf.updatecurs
)
4956 (fun v -> conf.updatecurs
<- v);
4958 (fun () -> conf.verbose
)
4959 (fun v -> conf.verbose
<- v);
4960 src#
bool "invert colors"
4961 (fun () -> conf.invert
)
4962 (fun v -> conf.invert
<- v);
4964 (fun () -> conf.maxhfit
)
4965 (fun v -> conf.maxhfit
<- v);
4966 src#
bool "redirect stderr"
4967 (fun () -> conf.redirectstderr)
4968 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4970 (fun () -> conf.pax
!= None
)
4973 then conf.pax
<- Some
(ref (now (), 0, 0))
4974 else conf.pax
<- None
);
4975 src#
string "uri launcher"
4976 (fun () -> conf.urilauncher
)
4977 (fun v -> conf.urilauncher
<- v);
4978 src#
string "path launcher"
4979 (fun () -> conf.pathlauncher
)
4980 (fun v -> conf.pathlauncher
<- v);
4981 src#
string "tile size"
4982 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4985 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4986 conf.tilew
<- max
64 w;
4987 conf.tileh
<- max
64 h;
4990 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4993 src#
int "texture count"
4994 (fun () -> conf.texcount
)
4997 then conf.texcount
<- v
4998 else showtext '
!'
" Failed to set texture count please retry later"
5000 src#
int "slice height"
5001 (fun () -> conf.sliceheight
)
5003 conf.sliceheight
<- v;
5004 wcmd "sliceh %d" conf.sliceheight
;
5006 src#
int "anti-aliasing level"
5007 (fun () -> conf.aalevel
)
5009 conf.aalevel
<- bound v 0 8;
5010 state.anchor <- getanchor ();
5011 opendoc state.path state.password
;
5013 src#
string "page scroll scaling factor"
5014 (fun () -> string_of_float
conf.pgscale)
5017 let s = float_of_string
v in
5020 state.text <- Printf.sprintf
5021 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
5024 src#
int "ui font size"
5025 (fun () -> fstate.fontsize
)
5026 (fun v -> setfontsize (bound v 5 100));
5027 src#
int "hint font size"
5028 (fun () -> conf.hfsize
)
5029 (fun v -> conf.hfsize
<- bound v 5 100);
5030 colorp "background color"
5031 (fun () -> conf.bgcolor
)
5032 (fun v -> conf.bgcolor
<- v);
5033 src#
bool "crop hack"
5034 (fun () -> conf.crophack
)
5035 (fun v -> conf.crophack
<- v);
5036 src#
string "trim fuzz"
5037 (fun () -> irect_to_string conf.trimfuzz
)
5040 conf.trimfuzz
<- irect_of_string v;
5042 then settrim true conf.trimfuzz
;
5044 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
5046 src#
string "throttle"
5048 match conf.maxwait
with
5049 | None
-> "show place holder if page is not ready"
5052 then "wait for page to fully render"
5054 "wait " ^ string_of_float
time
5055 ^
" seconds before showing placeholder"
5059 let f = float_of_string
v in
5061 then conf.maxwait
<- None
5062 else conf.maxwait
<- Some
f
5064 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
5066 src#
string "ghyll scroll"
5068 match conf.ghyllscroll
with
5070 | Some nab
-> ghyllscroll_to_string nab
5073 try conf.ghyllscroll
<- ghyllscroll_of_string v
5075 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
5077 src#
string "selection command"
5078 (fun () -> conf.selcmd
)
5079 (fun v -> conf.selcmd
<- v);
5080 src#
string "synctex command"
5081 (fun () -> conf.stcmd
)
5082 (fun v -> conf.stcmd
<- v);
5083 src#
string "pax command"
5084 (fun () -> conf.paxcmd
)
5085 (fun v -> conf.paxcmd
<- v);
5086 src#colorspace
"color space"
5087 (fun () -> CSTE.to_string conf.colorspace
)
5089 conf.colorspace
<- CSTE.of_int v;
5093 src#paxmark
"pax mark method"
5094 (fun () -> MTE.to_string conf.paxmark
)
5095 (fun v -> conf.paxmark
<- MTE.of_int v);
5099 (fun () -> conf.usepbo
)
5100 (fun v -> conf.usepbo
<- v);
5101 src#
bool "mouse wheel scrolls pages"
5102 (fun () -> conf.wheelbypage
)
5103 (fun v -> conf.wheelbypage
<- v);
5104 src#
bool "open remote links in a new instance"
5105 (fun () -> conf.riani
)
5106 (fun v -> conf.riani
<- v);
5110 src#caption
"Document" 0;
5111 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
5112 src#caption2
"Pages"
5113 (fun () -> string_of_int
state.pagecount
) 1;
5114 src#caption2
"Dimensions"
5115 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5119 src#caption
"Trimmed margins" 0;
5120 src#caption2
"Dimensions"
5121 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5125 src#caption
"OpenGL" 0;
5126 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
5127 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
5130 src#caption
"Location" 0;
5131 if nonemptystr
state.origin
5132 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
5133 src#caption
("Path\t" ^ mbtoutf8
state.path) 1;
5135 src#reset prevmode prevuioh
;
5139 let prevmode = state.mode
5140 and prevuioh
= state.uioh in
5141 fillsrc prevmode prevuioh
;
5142 let source = (src :> lvsource
) in
5143 let modehash = findkeyhash conf "info" in
5144 state.uioh <- coe (object (self)
5145 inherit listview ~
source ~trusted
:true ~
modehash as super
5146 val mutable m_prevmemused
= 0
5147 method infochanged
= function
5149 if m_prevmemused
!= state.memused
5151 m_prevmemused
<- state.memused
;
5152 G.postRedisplay "memusedchanged";
5154 | Pdim
-> G.postRedisplay "pdimchanged"
5155 | Docinfo
-> fillsrc prevmode prevuioh
5157 method key key mask
=
5158 if not
(Wsi.withctrl mask
)
5161 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5162 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5163 | _ -> super#
key key mask
5164 else super#
key key mask
5166 G.postRedisplay "info";
5172 inherit lvsourcebase
5173 method getitemcount
= Array.length
state.help
5175 let s, l, _ = state.help
.(n) in
5178 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5182 m_qsearch
<- qsearch;
5183 match state.help
.(active) with
5184 | _, _, Action
f -> Some
(f uioh)
5194 method hasaction
n =
5195 match state.help
.(n) with
5196 | _, _, Action
_ -> true
5203 let modehash = findkeyhash conf "help" in
5204 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5205 G.postRedisplay "help";
5210 let re = Str.regexp
"[\r\n]" in
5212 inherit lvsourcebase
5213 val mutable m_items
= [||]
5215 method getitemcount
= 1 + Array.length m_items
5220 else m_items
.(n-1), 0
5222 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5227 then Buffer.clear
state.errmsgs
;
5228 m_qsearch
<- qsearch;
5235 method hasaction
n =
5239 state.newerrmsgs
<- false;
5240 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5241 m_items
<- Array.of_list
l
5249 let source = (msgsource :> lvsource
) in
5250 let modehash = findkeyhash conf "listview" in
5251 state.uioh <- coe (object
5252 inherit listview ~
source ~trusted
:false ~
modehash as super
5255 then msgsource#reset
;
5258 G.postRedisplay "msgs";
5261 let quickbookmark ?title
() =
5262 match state.layout with
5268 let sec = Unix.gettimeofday
() in
5269 let tm = Unix.localtime
sec in
5270 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5274 (tm.Unix.tm_year
+ 1900)
5277 | Some
title -> title
5279 state.bookmarks
<- (title, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5282 let setautoscrollspeed step goingdown
=
5283 let incr = max
1 ((abs step
) / 2) in
5284 let incr = if goingdown
then incr else -incr in
5285 let astep = boundastep state.winh
(step
+ incr) in
5286 state.autoscroll
<- Some
astep;
5290 match conf.columns
with
5292 | _ -> state.x != 0 || conf.zoom > 1.0
5295 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5297 let existsinrow pageno (columns
, coverA
, coverB
) p =
5298 let last = ((pageno - coverA
) mod columns
) + columns
in
5299 let rec any = function
5302 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5306 then (if l.pageno = last then false else any rest
)
5314 match state.layout with
5316 let pageno = page_of_y state.y in
5317 gotoghyll (getpagey (pageno+1))
5319 match conf.columns
with
5321 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5323 let y = clamp (pgscale state.winh
) in
5326 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5327 gotoghyll (getpagey pageno)
5328 | Cmulti
((c, _, _) as cl, _) ->
5329 if conf.presentation
5330 && (existsinrow l.pageno cl
5331 (fun l -> l.pageh
> l.pagey + l.pagevh))
5333 let y = clamp (pgscale state.winh
) in
5336 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5337 gotoghyll (getpagey pageno)
5339 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5341 let pagey, pageh
= getpageyh l.pageno in
5342 let pagey = pagey + pageh
* l.pagecol
in
5343 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5344 gotoghyll (pagey + pageh
+ ips)
5348 match state.layout with
5350 let pageno = page_of_y state.y in
5351 gotoghyll (getpagey (pageno-1))
5353 match conf.columns
with
5355 if conf.presentation
&& l.pagey != 0
5357 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5359 let pageno = max
0 (l.pageno-1) in
5360 gotoghyll (getpagey pageno)
5361 | Cmulti
((c, _, coverB
) as cl, _) ->
5362 if conf.presentation
&&
5363 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5365 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5368 if l.pageno = state.pagecount
- coverB
5372 let pageno = max
0 (l.pageno-decr) in
5373 gotoghyll (getpagey pageno)
5381 let pageno = max
0 (l.pageno-1) in
5382 let pagey, pageh
= getpageyh pageno in
5385 let pagey, pageh
= getpageyh l.pageno in
5386 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5391 let viewkeyboard key mask
=
5393 let mode = state.mode in
5394 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5397 G.postRedisplay "view:enttext"
5399 let ctrl = Wsi.withctrl mask
in
5401 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5407 | 0xff63 -> (* insert *)
5408 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5410 state.mode <- LinkNav
(Ltgendir
0);
5413 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5415 | 0xff1b | 113 -> (* escape / q *)
5416 begin match state.mstate
with
5418 state.mstate
<- Mnone
;
5419 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5420 G.postRedisplay "kill zoom rect";
5422 begin match state.mode with
5425 G.postRedisplay "esc leave linknav"
5427 match state.ranchors
with
5429 | (path, password
, anchor, origin
) :: rest
->
5430 state.ranchors
<- rest
;
5431 state.anchor <- anchor;
5432 state.origin
<- origin
;
5433 state.nameddest
<- "";
5434 opendoc path password
5438 | 0xff08 -> (* backspace *)
5439 gotoghyll (getnav ~
-1)
5447 Hashtbl.iter
(fun _ opaque
-> clearmark opaque
) state.pagemap
;
5448 G.postRedisplay "dehighlight";
5450 | 47 | 63 -> (* / ? *)
5451 let ondone isforw
s =
5452 cbput state.hists
.pat
s;
5453 state.searchpattern
<- s;
5456 let s = String.create
1 in
5457 s.[0] <- Char.chr
key;
5458 enttext (s, "", Some
(onhist state.hists
.pat
),
5459 textentry, ondone (key = 47), true)
5461 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5462 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5463 setzoom (conf.zoom +. incr)
5465 | 43 | 0xffab -> (* + *)
5468 try int_of_string
s with exc
->
5469 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5475 state.text <- "page bias is now " ^ string_of_int
n;
5478 enttext ("page bias: ", "", None
, intentry, ondone, true)
5480 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5481 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5482 setzoom (max
0.01 (conf.zoom -. decr))
5484 | 45 | 0xffad -> (* - *)
5485 let ondone msg
= state.text <- msg
in
5487 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5488 optentry state.mode, ondone, true
5491 | 48 when ctrl -> (* ctrl-0 *)
5499 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5501 match conf.columns
with
5502 | Csingle
_ | Cmulti
_ -> 1
5503 | Csplit
(n, _) -> n
5505 let h = state.winh
-
5506 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5508 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5509 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5512 | 51 when ctrl -> (* ctrl-3 *)
5514 match conf.fitmodel
with
5515 | FitWidth
-> FitProportional
5516 | FitProportional
-> FitPage
5517 | FitPage
-> FitWidth
5519 state.text <- "fit model: " ^
FMTE.to_string fm;
5520 reqlayout conf.angle
fm
5522 | 0xffc6 -> (* f9 *)
5525 | 57 when ctrl -> (* ctrl-9 *)
5528 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5529 when not
ctrl -> (* 0..9 *)
5532 try int_of_string
s with exc
->
5533 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5539 cbput state.hists
.pag
(string_of_int
n);
5540 gotopage1 (n + conf.pagebias
- 1) 0;
5543 let pageentry text key =
5544 match Char.unsafe_chr
key with
5545 | '
g'
-> TEdone
text
5546 | _ -> intentry text key
5548 let text = "x" in text.[0] <- Char.chr
key;
5549 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5552 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5553 reshape state.winw
state.winh
;
5556 state.bzoom
<- not
state.bzoom
;
5558 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5561 conf.hlinks
<- not
conf.hlinks
;
5562 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5563 G.postRedisplay "toggle highlightlinks";
5566 state.glinks
<- true;
5567 let mode = state.mode in
5568 state.mode <- Textentry
(
5569 (":", "", None
, linknentry, linkndone gotounder, false),
5571 state.glinks
<- false;
5575 G.postRedisplay "view:linkent(F)"
5578 state.glinks
<- true;
5579 let mode = state.mode in
5580 state.mode <- Textentry
(
5582 ":", "", None
, linknentry, linkndone (fun under ->
5583 selstring (undertext under);
5587 state.glinks
<- false;
5591 G.postRedisplay "view:linkent"
5594 begin match state.autoscroll
with
5596 conf.autoscrollstep
<- step
;
5597 state.autoscroll
<- None
5599 if conf.autoscrollstep
= 0
5600 then state.autoscroll
<- Some
1
5601 else state.autoscroll
<- Some
conf.autoscrollstep
5604 | 112 when ctrl -> (* ctrl-p *)
5608 setpresentationmode (not
conf.presentation
);
5609 showtext ' '
("presentation mode " ^
5610 if conf.presentation
then "on" else "off");
5613 if List.mem
Wsi.Fullscreen
state.winstate
5614 then Wsi.reshape conf.cwinw
conf.cwinh
5615 else Wsi.fullscreen
()
5617 | 112 | 78 -> (* p|N *)
5618 search state.searchpattern
false
5620 | 110 | 0xffc0 -> (* n|F3 *)
5621 search state.searchpattern
true
5624 begin match state.layout with
5627 gotoghyll (getpagey l.pageno)
5633 | 0xff9f | 0xffff -> (* delete *)
5637 showtext ' '
(describe_location ());
5640 begin match state.layout with
5643 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5648 enterbookmarkmode ()
5650 | 104 | 0xffbe -> (* h|F1 *)
5656 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5661 match state.layout with
5666 (s, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5669 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5673 showtext ' '
"Quick bookmark added";
5676 begin match state.layout with
5678 let rect = getpdimrect
l.pagedimno
in
5682 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5683 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5685 (truncate
(rect.(1) -. rect.(0)),
5686 truncate
(rect.(3) -. rect.(0)))
5688 let w = truncate
((float w)*.conf.zoom)
5689 and h = truncate
((float h)*.conf.zoom) in
5692 state.anchor <- getanchor ();
5693 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5695 G.postRedisplay "z";
5702 state.roam
<- noroam;
5703 | 60 | 62 -> (* < > *)
5704 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5706 | 91 | 93 -> (* [ ] *)
5708 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5710 G.postRedisplay "brightness";
5712 | 99 when state.mode = View
-> (* [alt-]c *)
5717 let m = (wadjsb state.winw
- state.w) / 2 in
5719 gotoy_and_clear_text state.y
5723 match state.prevcolumns
with
5724 | None
-> (1, 0, 0), 1.0
5725 | Some
(columns
, z
) ->
5728 | Csplit
(c, _) -> -c, 0, 0
5729 | Cmulti
((c, a, b), _) -> c, a, b
5730 | Csingle
_ -> 1, 0, 0
5734 setcolumns View
c a b;
5737 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5738 -> (* ctrl-shift- (kp) [up|down] *)
5739 let zoom, x = state.prevzoom
in
5743 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5744 begin match state.autoscroll
with
5746 begin match state.mode with
5747 | Birdseye beye
-> upbirdseye 1 beye
5750 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5752 if not
(Wsi.withshift mask
) && conf.presentation
5754 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5758 setautoscrollspeed n false
5761 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5762 begin match state.autoscroll
with
5764 begin match state.mode with
5765 | Birdseye beye
-> downbirdseye 1 beye
5768 then gotoy_and_clear_text (clamp (state.winh
/2))
5770 if not
(Wsi.withshift mask
) && conf.presentation
5772 else gotoy_and_clear_text (clamp conf.scrollstep
)
5776 setautoscrollspeed n true
5779 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5780 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5786 else conf.hscrollstep
5788 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5789 state.x <- panbound (state.x + dx);
5790 gotoy_and_clear_text state.y
5793 G.postRedisplay "left/right"
5796 | 0xff55 | 0xff9a -> (* (kp) prior *)
5800 match state.layout with
5802 | l :: _ -> state.y - l.pagey
5804 clamp (pgscale (-state.winh
))
5808 | 0xff56 | 0xff9b -> (* (kp) next *)
5812 match List.rev
state.layout with
5814 | l :: _ -> getpagey l.pageno
5816 clamp (pgscale state.winh
)
5820 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5822 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5823 gotoghyll (clamp state.maxy)
5826 when Wsi.withalt mask
-> (* alt-(kp) right *)
5827 gotoghyll (getnav 1)
5829 when Wsi.withalt mask
-> (* alt-(kp) left *)
5830 gotoghyll (getnav ~
-1)
5835 | 118 when conf.debug
-> (* v *)
5838 match getopaque l.pageno with
5841 let x0, y0, x1, y1 = pagebbox opaque
in
5842 let a,b = float x0, float y0 in
5843 let c,d = float x1, float y0 in
5844 let e,f = float x1, float y1 in
5845 let h,j
= float x0, float y1 in
5846 let rect = (a,b,c,d,e,f,h,j
) in
5848 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5850 G.postRedisplay "v";
5853 vlog "huh? %s" (Wsi.keyname
key)
5856 let linknavkeyboard key mask
linknav =
5857 let getpage pageno =
5858 let rec loop = function
5860 | l :: _ when l.pageno = pageno -> Some
l
5861 | _ :: rest
-> loop rest
5862 in loop state.layout
5864 let doexact (pageno, n) =
5865 match getopaque pageno, getpage pageno with
5866 | Some opaque
, Some
l ->
5867 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5869 let under = getlink opaque
n in
5870 G.postRedisplay "link gotounder";
5876 | 0xff50 -> (* home *)
5877 Some
(findlink opaque LDfirst
), -1
5879 | 0xff57 -> (* end *)
5880 Some
(findlink opaque LDlast
), 1
5882 | 0xff51 -> (* left *)
5883 Some
(findlink opaque
(LDleft
n)), -1
5885 | 0xff53 -> (* right *)
5886 Some
(findlink opaque
(LDright
n)), 1
5888 | 0xff52 -> (* up *)
5889 Some
(findlink opaque
(LDup
n)), -1
5891 | 0xff54 -> (* down *)
5892 Some
(findlink opaque
(LDdown
n)), 1
5897 begin match findpwl
l.pageno dir with
5901 state.mode <- LinkNav
(Ltgendir
dir);
5902 let y, h = getpageyh pageno in
5905 then y + h - state.winh
5910 begin match getopaque pageno, getpage pageno with
5911 | Some opaque
, Some
_ ->
5913 let ld = if dir > 0 then LDfirst
else LDlast
in
5916 begin match link with
5918 showlinktype (getlink opaque
m);
5919 state.mode <- LinkNav
(Ltexact
(pageno, m));
5920 G.postRedisplay "linknav jpage";
5927 begin match opt with
5928 | Some Lnotfound
-> pwl l dir;
5929 | Some
(Lfound
m) ->
5933 let _, y0, _, y1 = getlinkrect opaque
m in
5935 then gotopage1 l.pageno y0
5937 let d = fstate.fontsize
+ 1 in
5938 if y1 - l.pagey > l.pagevh - d
5939 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5940 else G.postRedisplay "linknav";
5942 showlinktype (getlink opaque
m);
5943 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5946 | None
-> viewkeyboard key mask
5948 | _ -> viewkeyboard key mask
5953 G.postRedisplay "leave linknav"
5957 | Ltgendir
_ -> viewkeyboard key mask
5958 | Ltexact exact
-> doexact exact
5961 let keyboard key mask
=
5962 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5963 then wcmd "interrupt"
5964 else state.uioh <- state.uioh#
key key mask
5967 let birdseyekeyboard key mask
5968 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5970 match conf.columns
with
5972 | Cmulti
((c, _, _), _) -> c
5973 | Csplit
_ -> failwith
"bird's eye split mode"
5975 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5977 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5978 let y, h = getpageyh pageno in
5979 let top = (state.winh
- h) / 2 in
5980 gotoy (max
0 (y - top))
5981 | 0xff0d (* enter *)
5982 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5983 | 0xff1b -> leavebirdseye beye
true (* escape *)
5984 | 0xff52 -> upbirdseye incr beye
(* up *)
5985 | 0xff54 -> downbirdseye incr beye
(* down *)
5986 | 0xff51 -> upbirdseye 1 beye
(* left *)
5987 | 0xff53 -> downbirdseye 1 beye
(* right *)
5989 | 0xff55 -> (* prior *)
5990 begin match state.layout with
5994 state.mode <- Birdseye
(
5995 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5997 gotopage1 l.pageno 0;
6000 let layout = layout (state.y-state.winh
) (pgh state.layout) in
6002 | [] -> gotoy (clamp (-state.winh
))
6004 state.mode <- Birdseye
(
6005 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6007 gotopage1 l.pageno 0
6010 | [] -> gotoy (clamp (-state.winh
))
6013 | 0xff56 -> (* next *)
6014 begin match List.rev
state.layout with
6016 let layout = layout (state.y + (pgh state.layout)) state.winh
in
6017 begin match layout with
6019 let incr = l.pageh
- l.pagevh in
6024 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
6026 G.postRedisplay "birdseye pagedown";
6028 else gotoy (clamp (incr + conf.interpagespace
*2));
6032 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
6033 gotopage1 l.pageno 0;
6036 | [] -> gotoy (clamp state.winh
)
6039 | 0xff50 -> (* home *)
6040 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
6043 | 0xff57 -> (* end *)
6044 let pageno = state.pagecount
- 1 in
6045 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
6046 if not
(pagevisible state.layout pageno)
6049 match List.rev
state.pdims
with
6051 | (_, _, h, _) :: _ -> h
6053 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
6054 else G.postRedisplay "birdseye end";
6055 | _ -> viewkeyboard key mask
6060 match state.mode with
6061 | Textentry
_ -> scalecolor 0.4
6063 | View
-> scalecolor 1.0
6064 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6065 if l.pageno = hooverpageno
6068 if l.pageno = pageno
6076 let postdrawpage l linkindexbase
=
6077 match getopaque l.pageno with
6079 if tileready l l.pagex
l.pagey
6081 let x = l.pagedispx - l.pagex
6082 and y = l.pagedispy - l.pagey in
6084 match conf.columns
with
6085 | Csingle
_ | Cmulti
_ ->
6086 (if conf.hlinks
then 1 else 0)
6088 && not
(isbirdseye state.mode) then 2 else 0)
6092 match state.mode with
6093 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6096 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6101 let scrollindicator () =
6102 let sbw, ph
, sh = state.uioh#
scrollph in
6103 let sbh, pw, sw = state.uioh#scrollpw
in
6105 GlDraw.color (0.64, 0.64, 0.64);
6107 (float (state.winw
- sbw)) 0.
6108 (float state.winw
) (float state.winh
)
6111 0. (float (state.winh
- sbh))
6112 (float (wadjsb state.winw
- 1)) (float state.winh
)
6114 GlDraw.color (0.0, 0.0, 0.0);
6117 (float (state.winw
- sbw)) ph
6118 (float state.winw
) (ph
+. sh)
6121 pw (float (state.winh
- sbh))
6122 (pw +. sw) (float state.winh
)
6127 match state.mstate
with
6128 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6131 | Msel
((x0, y0), (x1, y1)) ->
6132 let rec loop = function
6134 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6135 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6136 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6137 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6139 match getopaque l.pageno with
6141 let x0, y0 = pagetranslatepoint l x0 y0 in
6142 let x1, y1 = pagetranslatepoint l x1 y1 in
6143 seltext opaque
(x0, y0, x1, y1);
6151 let showrects = function [] -> () | rects
->
6153 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6154 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6156 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6158 if l.pageno = pageno
6160 let dx = float (l.pagedispx - l.pagex
) in
6161 let dy = float (l.pagedispy - l.pagey) in
6162 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6163 Raw.sets_float
state.vraw ~pos
:0
6168 GlArray.vertex `two
state.vraw
;
6169 GlArray.draw_arrays `triangle_strip
0 4;
6178 GlClear.color (scalecolor2 conf.bgcolor
);
6179 GlClear.clear
[`
color];
6180 List.iter
drawpage state.layout;
6182 match state.mode with
6183 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6184 begin match getopaque pageno with
6186 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6193 | None
-> state.rects
6198 let rec postloop linkindexbase
= function
6200 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6201 postloop linkindexbase rest
6205 postloop 0 state.layout;
6207 begin match state.mstate
with
6208 | Mzoomrect
((x0, y0), (x1, y1)) ->
6210 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6211 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6212 filledrect (float x0) (float y0) (float x1) (float y1);
6221 let zoomrect x y x1 y1 =
6224 and y0 = min
y y1 in
6225 gotoy (state.y + y0);
6226 state.anchor <- getanchor ();
6227 let zoom = (float state.w) /. float (x1 - x0) in
6229 match conf.fitmodel
, conf.columns
with
6230 | FitPage
, Csplit
_ ->
6231 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6234 let adjw = wadjsb state.winw
in
6236 then (adjw - state.w) / 2
6239 state.x <- (state.x + margin) - x0;
6241 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6242 state.mstate
<- Mnone
;
6246 let g opaque
l px py =
6247 match rectofblock opaque
px py with
6249 let x0 = a.(0) -. 20. in
6250 let x1 = a.(1) +. 20. in
6251 let y0 = a.(2) -. 20. in
6252 let zoom = (float state.w) /. (x1 -. x0) in
6253 let pagey = getpagey l.pageno in
6254 gotoy_and_clear_text (pagey + truncate
y0);
6255 state.anchor <- getanchor ();
6256 let margin = (state.w - l.pagew
)/2 in
6257 state.x <- -truncate
x0 - margin;
6262 match conf.columns
with
6264 showtext '
!'
"block zooming does not work properly in split columns mode"
6265 | _ -> onppundermouse g x y ()
6269 let winw = wadjsb state.winw - 1 in
6270 let s = float x /. float winw in
6271 let destx = truncate
(float (state.w + winw) *. s) in
6272 state.x <- winw - destx;
6273 gotoy_and_clear_text state.y;
6274 state.mstate
<- Mscrollx
;
6278 let s = float y /. float state.winh
in
6279 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6280 gotoy_and_clear_text desty;
6281 state.mstate
<- Mscrolly
;
6284 let viewmulticlick clicks
x y mask
=
6285 let g opaque
l px py =
6293 if markunder opaque
px py mark
6296 match getopaque l.pageno with
6299 match Ne.pipe () with
6303 "can not create mark pipe: %s"
6306 let dopipe (r, w) cmd
=
6307 let doclose what fd
=
6308 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
6311 popen cmd
[r, 0; w, -1];
6313 doclose "viewmulticlick pipe/w" w;
6314 dolog
"can not execute %S: %s" cmd
(exntos exn
);
6316 copysel
w opaque
false;
6317 G.postRedisplay "viewmulticlick";
6318 doclose "viewmulticlick pipe/r" r;
6320 state.roam
<- (fun () ->
6321 match Ne.pipe () with
6325 "can not create mark pipe: %s"
6328 dopipe rw
conf.paxcmd
);
6329 if not
(Wsi.withctrl mask
) then dopipe rw
conf.selcmd
6334 G.postRedisplay "viewmulticlick";
6335 onppundermouse g x y (fun () -> showtext '
!'
"Daisy whoopsie") ();
6338 let viewmouse button down
x y mask
=
6340 | n when (n == 4 || n == 5) && not down
->
6341 if Wsi.withctrl mask
6343 match state.mstate
with
6344 | Mzoom
(oldn
, i
) ->
6352 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6354 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6356 let zoom = conf.zoom -. incr in
6358 state.mstate
<- Mzoom
(n, 0);
6360 state.mstate
<- Mzoom
(n, i
+1);
6362 else state.mstate
<- Mzoom
(n, 0)
6364 | _ -> state.mstate
<- Mzoom
(n, 0)
6367 match state.autoscroll
with
6368 | Some step
-> setautoscrollspeed step
(n=4)
6370 if conf.wheelbypage
|| conf.presentation
6379 then -conf.scrollstep
6380 else conf.scrollstep
6382 let incr = incr * 2 in
6383 let y = clamp incr in
6384 gotoy_and_clear_text y
6387 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6389 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6390 gotoy_and_clear_text state.y
6392 | 1 when Wsi.withshift mask
->
6393 state.mstate
<- Mnone
;
6396 match unproject x y with
6397 | Some
(pageno, ux
, uy
) ->
6398 let cmd = Printf.sprintf
6400 conf.stcmd
state.path pageno ux uy
6406 | 1 when Wsi.withctrl mask
->
6409 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6410 state.mstate
<- Mpan
(x, y)
6413 state.mstate
<- Mnone
6418 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6420 state.mstate
<- Mzoomrect
(p, p)
6423 match state.mstate
with
6424 | Mzoomrect
((x0, y0), _) ->
6425 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6426 then zoomrect x0 y0 x y
6428 state.mstate
<- Mnone
;
6429 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6430 G.postRedisplay "kill accidental zoom rect";
6433 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6434 state.mstate
<- Mnone
6437 | 1 when x > state.winw - vscrollw () ->
6440 let _, position, sh = state.uioh#
scrollph in
6441 if y > truncate
position && y < truncate
(position +. sh)
6442 then state.mstate
<- Mscrolly
6445 state.mstate
<- Mnone
6447 | 1 when y > state.winh
- hscrollh () ->
6450 let _, position, sw = state.uioh#scrollpw
in
6451 if x > truncate
position && x < truncate
(position +. sw)
6452 then state.mstate
<- Mscrollx
6455 state.mstate
<- Mnone
6457 | 1 when state.bzoom
-> if not down
then zoomblock x y
6460 let dest = if down
then getunder x y else Unone
in
6461 begin match dest with
6464 | Uremote
_ | Uremotedest
_
6465 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6468 | Unone
when down
->
6469 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6470 state.mstate
<- Mpan
(x, y);
6472 | Unone
| Utext
_ ->
6475 if conf.angle
mod 360 = 0
6477 state.mstate
<- Msel
((x, y), (x, y));
6478 G.postRedisplay "mouse select";
6482 match state.mstate
with
6485 | Mzoom
_ | Mscrollx
| Mscrolly
->
6486 state.mstate
<- Mnone
6488 | Mzoomrect
((x0, y0), _) ->
6492 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6493 state.mstate
<- Mnone
6495 | Msel
((x0, y0), (x1, y1)) ->
6496 let rec loop = function
6500 let a0 = l.pagedispy in
6501 let a1 = a0 + l.pagevh in
6502 let b0 = l.pagedispx in
6503 let b1 = b0 + l.pagevw in
6504 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6505 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6509 match getopaque l.pageno with
6512 match Ne.pipe () with
6516 "can not create sel pipe: %s"
6519 let doclose what fd
=
6520 Ne.clo fd
(fun msg
->
6521 dolog
"%s close failed: %s" what msg
)
6524 popen conf.selcmd
[r, 0; w, -1];
6526 dolog
"can not execute %S: %s"
6527 conf.selcmd
(exntos exn
);
6528 doclose "Msel pipe/w" w;
6530 copysel
w opaque
true;
6531 G.postRedisplay "copysel";
6532 doclose "Msel pipe/r" r;
6538 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6539 state.mstate
<- Mnone
;
6546 let birdseyemouse button down
x y mask
6547 (conf, leftx
, _, hooverpageno
, anchor) =
6550 let rec loop = function
6553 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6554 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6556 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6562 | _ -> viewmouse button down
x y mask
6568 method key key mask
=
6569 begin match state.mode with
6570 | Textentry
textentry -> textentrykeyboard key mask
textentry
6571 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6572 | View
-> viewkeyboard key mask
6573 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6577 method button button bstate
x y mask
=
6578 begin match state.mode with
6580 | View
-> viewmouse button bstate
x y mask
6581 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6586 method multiclick clicks
x y mask
=
6587 begin match state.mode with
6589 | View
-> viewmulticlick clicks
x y mask
6596 begin match state.mode with
6598 | View
| Birdseye
_ | LinkNav
_ ->
6599 match state.mstate
with
6600 | Mzoom
_ | Mnone
-> ()
6605 state.mstate
<- Mpan
(x, y);
6607 then state.x <- panbound (state.x + dx);
6609 gotoy_and_clear_text y
6612 state.mstate
<- Msel
(a, (x, y));
6613 G.postRedisplay "motion select";
6616 let y = min
state.winh
(max
0 y) in
6620 let x = min
state.winw (max
0 x) in
6623 | Mzoomrect
(p0
, _) ->
6624 state.mstate
<- Mzoomrect
(p0
, (x, y));
6625 G.postRedisplay "motion zoomrect";
6629 method pmotion
x y =
6630 begin match state.mode with
6631 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6632 let rec loop = function
6634 if hooverpageno
!= -1
6636 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6637 G.postRedisplay "pmotion birdseye no hoover";
6640 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6641 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6643 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6644 G.postRedisplay "pmotion birdseye hoover";
6654 match state.mstate
with
6655 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6662 let past, _, _ = !r in
6664 let delta = now -. past in
6667 else r := (now, x, y)
6671 method infochanged
_ = ()
6674 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6677 then 0.0, float state.winh
6678 else scrollph state.y maxy
6683 let winw = wadjsb state.winw in
6684 let fwinw = float winw in
6686 let sw = fwinw /. float state.w in
6687 let sw = fwinw *. sw in
6688 max
sw (float conf.scrollh
)
6691 let maxx = state.w + winw in
6692 let x = winw - state.x in
6693 let percent = float x /. float maxx in
6694 (fwinw -. sw) *. percent
6696 hscrollh (), position, sw
6700 match state.mode with
6701 | LinkNav
_ -> "links"
6702 | Textentry
_ -> "textentry"
6703 | Birdseye
_ -> "birdseye"
6706 findkeyhash conf modename
6708 method eformsgs
= true
6715 let fontpath = ref "";;
6718 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6721 let l = String.length
s in
6722 let b = Buffer.create
l in
6728 try Sys.getenv
"HOME"
6731 ("Can not determine home directory location: " ^ exntos exn
);
6735 let modifier_of_string = function
6736 | "alt" -> Wsi.altmask
6737 | "shift" -> Wsi.shiftmask
6738 | "ctrl" | "control" -> Wsi.ctrlmask
6739 | "meta" -> Wsi.metamask
6744 let r = Str.regexp
"-" in
6746 let elems = Str.full_split
r s in
6749 let m1 = modifier_of_string s in
6751 then (Wsi.namekey
s, m)
6754 | Str.Delim
s when n land 1 = 0 -> g s
6756 | Str.Delim
_ -> (k
, m)
6758 let rec loop n k
m = function
6761 let k, m = f n k m x in
6767 let keys_of_string =
6768 let r = Str.regexp
"[ \t]" in
6770 let elems = Str.split
r s in
6771 List.map
key_of_string elems
6774 let copykeyhashes c =
6775 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6778 let config_of c attrs
=
6782 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6783 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6784 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6785 | "preload" -> { c with preload = bool_of_string
v }
6786 | "page-bias" -> { c with pagebias
= int_of_string
v }
6787 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6788 | "horizontal-scroll-step" ->
6789 { c with hscrollstep
= max
(int_of_string
v) 1 }
6790 | "auto-scroll-step" ->
6791 { c with autoscrollstep
= max
0 (int_of_string
v) }
6792 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6793 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6796 match String.lowercase
v with
6797 | "true" -> Some infinity
6799 | f -> Some
(float_of_string
f)
6801 { c with maxwait
= mw}
6802 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6803 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6804 | "vertical-margin" ->
6805 { c with interpagespace
= max
0 (int_of_string
v) }
6807 let zoom = float_of_string
v /. 100. in
6808 let zoom = max
zoom 0.0 in
6809 { c with zoom = zoom }
6810 | "presentation" -> { c with presentation
= bool_of_string
v }
6811 | "rotation-angle" -> { c with angle
= int_of_string
v }
6812 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6813 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6814 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6815 | "proportional-display" ->
6818 then FitProportional
6821 { c with fitmodel
= fm }
6822 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6823 | "pixmap-cache-size" ->
6824 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6825 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6826 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6827 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6828 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6829 | "background-color" -> { c with bgcolor
= color_of_string v }
6830 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6831 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6832 | "mupdf-store-size" ->
6833 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6834 | "checkers" -> { c with checkers
= bool_of_string
v }
6835 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6836 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6837 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6838 | "uri-launcher" -> { c with urilauncher
= unent v }
6839 | "path-launcher" -> { c with pathlauncher
= unent v }
6840 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6841 | "invert-colors" -> { c with invert
= bool_of_string
v }
6842 | "brightness" -> { c with colorscale
= float_of_string
v }
6843 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6844 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6846 let (n, _, _) as nab
= multicolumns_of_string v in
6848 then { c with columns
= Csplit
(-n, [||]) }
6849 else { c with columns
= Cmulti
(nab
, [||]) }
6850 | "birds-eye-columns" ->
6851 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6852 | "selection-command" -> { c with selcmd
= unent v }
6853 | "synctex-command" -> { c with stcmd
= unent v }
6854 | "pax-command" -> { c with paxcmd
= unent v }
6855 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6856 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6857 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6858 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6859 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6860 | "horizontal-scrollbar-visible" ->
6863 then c.scrollb
lor scrollbhv
6864 else c.scrollb
land (lnot
scrollbhv)
6866 { c with scrollb
= b }
6867 | "vertical-scrollbar-visible" ->
6870 then c.scrollb
lor scrollbvv
6871 else c.scrollb
land (lnot
scrollbvv)
6873 { c with scrollb
= b }
6874 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6878 then Some
(ref (0.0, 0, 0))
6880 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6883 prerr_endline
("Error processing attribute (`" ^
6884 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6887 let rec fold c = function
6890 let c = apply c k v in
6893 fold { c with keyhashes
= copykeyhashes c } attrs
;
6896 let fromstring f pos
n v d =
6899 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6900 n v pos
(exntos exn
)
6905 let bookmark_of attrs
=
6906 let rec fold title page
rely visy
= function
6907 | ("title", v) :: rest
-> fold v page
rely visy rest
6908 | ("page", v) :: rest
-> fold title v rely visy rest
6909 | ("rely", v) :: rest
-> fold title page
v visy rest
6910 | ("visy", v) :: rest
-> fold title page
rely v rest
6911 | _ :: rest
-> fold title page
rely visy rest
6912 | [] -> title, page
, rely, visy
6914 fold "invalid" "0" "0" "0" attrs
6918 let rec fold path page
rely pan visy
= function
6919 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6920 | ("page", v) :: rest
-> fold path v rely pan visy rest
6921 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6922 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6923 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6924 | _ :: rest
-> fold path page
rely pan visy rest
6925 | [] -> path, page
, rely, pan
, visy
6927 fold "" "0" "0" "0" "0" attrs
6931 let rec fold rs ls
= function
6932 | ("out", v) :: rest
-> fold v ls rest
6933 | ("in", v) :: rest
-> fold rs
v rest
6934 | _ :: rest
-> fold ls rs rest
6940 let setconf dst
src =
6941 dst
.scrollbw
<- src.scrollbw
;
6942 dst
.scrollh
<- src.scrollh
;
6943 dst
.icase
<- src.icase
;
6944 dst
.preload <- src.preload;
6945 dst
.pagebias
<- src.pagebias
;
6946 dst
.verbose
<- src.verbose
;
6947 dst
.scrollstep
<- src.scrollstep
;
6948 dst
.maxhfit
<- src.maxhfit
;
6949 dst
.crophack
<- src.crophack
;
6950 dst
.autoscrollstep
<- src.autoscrollstep
;
6951 dst
.maxwait
<- src.maxwait
;
6952 dst
.hlinks
<- src.hlinks
;
6953 dst
.underinfo
<- src.underinfo
;
6954 dst
.interpagespace
<- src.interpagespace
;
6955 dst
.zoom <- src.zoom;
6956 dst
.presentation
<- src.presentation
;
6957 dst
.angle
<- src.angle
;
6958 dst
.cwinw
<- src.cwinw
;
6959 dst
.cwinh
<- src.cwinh
;
6960 dst
.savebmarks
<- src.savebmarks
;
6961 dst
.memlimit
<- src.memlimit
;
6962 dst
.fitmodel
<- src.fitmodel
;
6963 dst
.texcount
<- src.texcount
;
6964 dst
.sliceheight
<- src.sliceheight
;
6965 dst
.thumbw
<- src.thumbw
;
6966 dst
.jumpback
<- src.jumpback
;
6967 dst
.bgcolor
<- src.bgcolor
;
6968 dst
.tilew
<- src.tilew
;
6969 dst
.tileh
<- src.tileh
;
6970 dst
.mustoresize
<- src.mustoresize
;
6971 dst
.checkers
<- src.checkers
;
6972 dst
.aalevel
<- src.aalevel
;
6973 dst
.trimmargins
<- src.trimmargins
;
6974 dst
.trimfuzz
<- src.trimfuzz
;
6975 dst
.urilauncher
<- src.urilauncher
;
6976 dst
.colorspace
<- src.colorspace
;
6977 dst
.invert
<- src.invert
;
6978 dst
.colorscale
<- src.colorscale
;
6979 dst
.redirectstderr <- src.redirectstderr;
6980 dst
.ghyllscroll
<- src.ghyllscroll
;
6981 dst
.columns
<- src.columns
;
6982 dst
.beyecolumns
<- src.beyecolumns
;
6983 dst
.selcmd
<- src.selcmd
;
6984 dst
.updatecurs
<- src.updatecurs
;
6985 dst
.pathlauncher
<- src.pathlauncher
;
6986 dst
.keyhashes
<- copykeyhashes src;
6987 dst
.hfsize
<- src.hfsize
;
6988 dst
.hscrollstep
<- src.hscrollstep
;
6989 dst
.pgscale <- src.pgscale;
6990 dst
.usepbo
<- src.usepbo
;
6991 dst
.wheelbypage
<- src.wheelbypage
;
6992 dst
.stcmd
<- src.stcmd
;
6993 dst
.paxcmd
<- src.paxcmd
;
6994 dst
.scrollb
<- src.scrollb
;
6995 dst
.riani
<- src.riani
;
6996 dst
.paxmark
<- src.paxmark
;
7000 else Some
((ref (0.0, 0, 0)));
7004 let h = Hashtbl.create
10 in
7005 let dc = { defconf with angle
= defconf.angle
} in
7006 let rec toplevel v t spos
_ =
7008 | Vdata
| Vcdata
| Vend
-> v
7009 | Vopen
("llppconfig", _, closed
) ->
7012 else { v with f = llppconfig
}
7014 error
"unexpected subelement at top level" s spos
7015 | Vclose
_ -> error
"unexpected close at top level" s spos
7017 and llppconfig
v t spos
_ =
7019 | Vdata
| Vcdata
-> v
7020 | Vend
-> error
"unexpected end of input in llppconfig" s spos
7021 | Vopen
("defaults", attrs
, closed
) ->
7022 let c = config_of dc attrs
in
7026 else { v with f = defaults
}
7028 | Vopen
("ui-font", attrs
, closed
) ->
7029 let rec getsize size
= function
7031 | ("size", v) :: rest
->
7033 fromstring int_of_string spos
"size" v fstate.fontsize
in
7035 | l -> getsize size l
7037 fstate.fontsize
<- getsize fstate.fontsize attrs
;
7040 else { v with f = uifont
(Buffer.create
10) }
7042 | Vopen
("doc", attrs
, closed
) ->
7043 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
7044 let path = unent pathent
7045 and pageno = fromstring int_of_string spos
"page" spage
0
7046 and rely = fromstring float_of_string spos
"rely" srely
0.0
7047 and pan
= fromstring int_of_string spos
"pan" span
0
7048 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7049 let c = config_of dc attrs
in
7050 let anchor = (pageno, rely, visy
) in
7052 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
7053 else { v with f = doc
path pan
anchor c [] }
7056 error
"unexpected subelement in llppconfig" s spos
7058 | Vclose
"llppconfig" -> { v with f = toplevel }
7059 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
7061 and defaults
v t spos
_ =
7063 | Vdata
| Vcdata
-> v
7064 | Vend
-> error
"unexpected end of input in defaults" s spos
7065 | Vopen
("keymap", attrs
, closed
) ->
7067 try List.assoc
"mode" attrs
7068 with Not_found
-> "global" in
7073 let h = findkeyhash dc modename in
7074 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7077 { v with f = pkeymap
ret KeyMap.empty }
7079 | Vopen
(_, _, _) ->
7080 error
"unexpected subelement in defaults" s spos
7082 | Vclose
"defaults" ->
7083 { v with f = llppconfig
}
7085 | Vclose
_ -> error
"unexpected close in defaults" s spos
7087 and uifont
b v t spos
epos =
7090 Buffer.add_substring
b s spos
(epos - spos
);
7092 | Vopen
(_, _, _) ->
7093 error
"unexpected subelement in ui-font" s spos
7094 | Vclose
"ui-font" ->
7095 if emptystr
!fontpath
7096 then fontpath := Buffer.contents
b;
7097 { v with f = llppconfig
}
7098 | Vclose
_ -> error
"unexpected close in ui-font" s spos
7099 | Vend
-> error
"unexpected end of input in ui-font" s spos
7101 and doc
path pan
anchor c bookmarks
v t spos
_ =
7103 | Vdata
| Vcdata
-> v
7104 | Vend
-> error
"unexpected end of input in doc" s spos
7105 | Vopen
("bookmarks", _, closed
) ->
7108 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
7110 | Vopen
("keymap", attrs
, closed
) ->
7112 try List.assoc
"mode" attrs
7113 with Not_found
-> "global"
7119 let h = findkeyhash c modename in
7120 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7121 doc
path pan
anchor c bookmarks
7123 { v with f = pkeymap
ret KeyMap.empty }
7125 | Vopen
(_, _, _) ->
7126 error
"unexpected subelement in doc" s spos
7129 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7130 { v with f = llppconfig
}
7132 | Vclose
_ -> error
"unexpected close in doc" s spos
7134 and pkeymap
ret keymap
v t spos
_ =
7136 | Vdata
| Vcdata
-> v
7137 | Vend
-> error
"unexpected end of input in keymap" s spos
7138 | Vopen
("map", attrs
, closed
) ->
7139 let r, l = map_of attrs
in
7140 let kss = fromstring keys_of_string spos
"in" r [] in
7141 let lss = fromstring keys_of_string spos
"out" l [] in
7145 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7146 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7149 then { v with f = pkeymap
ret keymap }
7152 { v with f = skip
"map" f }
7155 error
"unexpected subelement in keymap" s spos
7157 | Vclose
"keymap" ->
7158 { v with f = ret keymap }
7160 | Vclose
_ -> error
"unexpected close in keymap" s spos
7162 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7164 | Vdata
| Vcdata
-> v
7165 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7166 | Vopen
("item", attrs
, closed
) ->
7167 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7168 let page = fromstring int_of_string spos
"page" spage
0
7169 and rely = fromstring float_of_string spos
"rely" srely
0.0
7170 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7172 (unent titleent, 0, Oanchor
(page, rely, visy
)) :: bookmarks
7175 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7178 { v with f = skip
"item" f }
7181 error
"unexpected subelement in bookmarks" s spos
7183 | Vclose
"bookmarks" ->
7184 { v with f = doc
path pan
anchor c bookmarks }
7186 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7188 and skip tag
f v t spos
_ =
7190 | Vdata
| Vcdata
-> v
7192 error
("unexpected end of input in skipped " ^ tag
) s spos
7193 | Vopen
(tag'
, _, closed
) ->
7197 let f'
() = { v with f = skip tag
f } in
7198 { v with f = skip tag'
f'
}
7202 else error
("unexpected close in skipped " ^ tag
) s spos
7205 parse
{ f = toplevel; accu = () } s;
7211 let len = in_channel_length ic
in
7212 let s = String.create
len in
7213 really_input ic
s 0 len;
7216 | Parse_error
(msg
, s, pos
) ->
7217 let subs = subs s pos
in
7218 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7221 failwith
("config load error: " ^ exntos exn
)
7227 let dir = Filename.concat
home ".config" in
7228 if Sys.is_directory
dir then dir else home
7231 Filename.concat
dir "llpp.conf"
7234 let confpath = ref defconfpath;;
7237 if Sys.file_exists
!confpath
7240 (try Some
(open_in_bin
!confpath)
7243 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7254 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7263 f (Hashtbl.create
0, defconf)
7268 let pc, pb
, px, pa
=
7271 if emptystr
state.origin
7275 Hashtbl.find h (Filename.basename
key)
7276 with Not_found
-> dc, [], 0, emptyanchor
7280 state.bookmarks <- pb
;
7283 then state.anchor <- pa
;
7284 cbput state.hists
.nav pa
;
7290 let add_attrs bb always
dc c =
7293 then Printf.bprintf bb
"\n %s='%b'" s a
7296 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7299 then Printf.bprintf bb
"\n %s='%d'" s a
7302 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7305 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7308 then Printf.bprintf bb
"\n %s='%f'" s a
7312 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7316 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7320 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7324 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7329 | Some
(_N
, _A
, _B
) ->
7330 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7335 Printf.bprintf bb
"\n %s='none'" s
7345 else string_of_float
f
7347 Printf.bprintf bb
"\n %s='%s'" s v
7352 | Cmulti
((n, a, b), _) when n > 1 ->
7353 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7354 | Csplit
(n, _) when n > 1 ->
7355 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7361 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7366 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7370 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7374 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7376 oi
"width" c.cwinw
dc.cwinw
;
7377 oi
"height" c.cwinh
dc.cwinh
;
7378 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7379 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7380 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7381 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7382 ob "case-insensitive-search" c.icase
dc.icase
;
7383 ob "preload" c.preload dc.preload;
7384 oi
"page-bias" c.pagebias
dc.pagebias
;
7385 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7386 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7387 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7388 ob "crop-hack" c.crophack
dc.crophack
;
7389 oW
"throttle" c.maxwait
dc.maxwait
;
7390 ob "highlight-links" c.hlinks
dc.hlinks
;
7391 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7392 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7393 oz
"zoom" c.zoom dc.zoom;
7394 ob "presentation" c.presentation
dc.presentation
;
7395 oi
"rotation-angle" c.angle
dc.angle
;
7396 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7397 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7398 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7399 oi
"tex-count" c.texcount
dc.texcount
;
7400 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7401 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7402 ob "persistent-location" c.jumpback
dc.jumpback
;
7403 oc
"background-color" c.bgcolor
dc.bgcolor
;
7404 oi
"tile-width" c.tilew
dc.tilew
;
7405 oi
"tile-height" c.tileh
dc.tileh
;
7406 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7407 ob "checkers" c.checkers
dc.checkers
;
7408 oi
"aalevel" c.aalevel
dc.aalevel
;
7409 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7410 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7411 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7412 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7413 oC
"color-space" c.colorspace
dc.colorspace
;
7414 ob "invert-colors" c.invert
dc.invert
;
7415 oF
"brightness" c.colorscale
dc.colorscale
;
7416 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7417 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7418 oco
"columns" c.columns
dc.columns
;
7419 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7420 os
"selection-command" c.selcmd
dc.selcmd
;
7421 os
"synctex-command" c.stcmd
dc.stcmd
;
7422 os
"pax-command" c.paxcmd
dc.paxcmd
;
7423 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7424 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7425 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7426 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7427 ob "use-pbo" c.usepbo
dc.usepbo
;
7428 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7429 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7430 op
"point-and-x" c.pax
dc.pax
;
7431 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7434 let keymapsbuf always
dc c =
7435 let bb = Buffer.create
16 in
7436 let rec loop = function
7438 | (modename, h) :: rest
->
7439 let dh = findkeyhash dc modename in
7440 if always
|| h <> dh
7442 if Hashtbl.length
h > 0
7444 if Buffer.length
bb > 0
7445 then Buffer.add_char
bb '
\n'
;
7446 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7447 Hashtbl.iter
(fun i
o ->
7448 let isdifferent = always
||
7450 let dO = Hashtbl.find dh i
in
7452 with Not_found
-> true
7457 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7458 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7459 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7460 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7461 Buffer.add_string
bb (Wsi.keyname
k);
7464 let rec loop = function
7466 | km
:: [] -> addkm km
7467 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7471 Buffer.add_string
bb "<map in='";
7475 Buffer.add_string
bb "' out='";
7477 Buffer.add_string
bb "'/>\n"
7480 Buffer.add_string
bb "' out='";
7482 Buffer.add_string
bb "'/>\n"
7484 | KMmulti
(ins, kms
) ->
7485 Buffer.add_char
bb ' '
;
7487 Buffer.add_string
bb "' out='";
7489 Buffer.add_string
bb "'/>\n"
7491 Buffer.add_string
bb "</keymap>";
7501 let uifontsize = fstate.fontsize
in
7502 let bb = Buffer.create
32768 in
7503 let relx = float state.x /. float state.winw in
7505 let cx w = truncate
(relx *. float w) in
7507 (fun (w, h, x) ws
->
7509 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7510 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7511 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7513 (state.winw, state.winh
, state.x) state.winstate
7518 let dc = if conf.bedefault
then conf else dc in
7519 Buffer.add_string
bb "<llppconfig>\n";
7521 if nonemptystr
!fontpath
7523 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7529 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7532 Buffer.add_string
bb "<defaults";
7533 add_attrs bb true dc dc;
7534 let kb = keymapsbuf true dc dc in
7535 if Buffer.length
kb > 0
7537 Buffer.add_string
bb ">\n";
7538 Buffer.add_buffer
bb kb;
7539 Buffer.add_string
bb "\n</defaults>\n";
7541 else Buffer.add_string
bb "/>\n";
7543 let adddoc path pan
anchor c bookmarks =
7544 if bookmarks == [] && c = dc && anchor = emptyanchor
7547 Printf.bprintf
bb "<doc path='%s'"
7548 (enent
path 0 (String.length
path));
7550 if anchor <> emptyanchor
7552 let n, rely, visy
= anchor in
7553 Printf.bprintf
bb " page='%d'" n;
7556 Printf.bprintf
bb " rely='%f'" rely
7558 if abs_float visy
> 1e-6
7560 Printf.bprintf
bb " visy='%f'" visy
7565 then Printf.bprintf
bb " pan='%d'" pan
;
7567 add_attrs bb false dc c;
7568 let kb = keymapsbuf false dc c in
7570 begin match bookmarks with
7572 if Buffer.length
kb > 0
7574 Buffer.add_string
bb ">\n";
7575 Buffer.add_buffer
bb kb;
7576 Buffer.add_string
bb "\n</doc>\n";
7578 else Buffer.add_string
bb "/>\n"
7580 Buffer.add_string
bb ">\n<bookmarks>\n";
7581 List.iter
(fun (title, _, kind
) ->
7582 begin match kind
with
7583 | Oanchor
(page, rely, visy
) ->
7585 "<item title='%s' page='%d'"
7586 (enent
title 0 (String.length
title))
7591 Printf.bprintf
bb " rely='%f'" rely
7593 if abs_float visy
> 1e-6
7595 Printf.bprintf
bb " visy='%f'" visy
7597 | Onone
| Ouri
_ | Oremote
_ | Oremotedest
_ | Olaunch
_ ->
7598 failwith
"unexpected link in bookmarks"
7600 Buffer.add_string
bb "/>\n";
7602 Buffer.add_string
bb "</bookmarks>";
7603 if Buffer.length
kb > 0
7605 Buffer.add_string
bb "\n";
7606 Buffer.add_buffer
bb kb;
7608 Buffer.add_string
bb "\n</doc>\n";
7614 match state.mode with
7615 | Birdseye
(c, pan, _, _, _) ->
7617 match conf.columns
with
7618 | Cmulti
((c, _, _), _) -> Some
c
7622 match c.columns
with
7623 | Cmulti
(c, _) -> Cmulti
(c, [||])
7624 | Csingle
_ -> Csingle
[||]
7625 | Csplit
_ -> failwith
"quit from bird's eye while split"
7627 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7630 let basename = Filename.basename
7631 (if emptystr
state.origin
then state.path else state.origin
)
7633 adddoc basename pan (getanchor ())
7635 let autoscrollstep =
7636 match state.autoscroll
with
7638 | None
-> conf.autoscrollstep
7640 match state.mode with
7641 | Birdseye
(bc
, _, _, _, _) ->
7644 presentation
= bc
.presentation
;
7645 interpagespace
= bc
.interpagespace
;
7646 maxwait
= bc
.maxwait
;
7647 autoscrollstep = autoscrollstep }
7648 | _ -> { conf with autoscrollstep = autoscrollstep }
7650 (if conf.savebmarks
then state.bookmarks else []);
7652 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7654 then adddoc path x anchor c bookmarks
7656 Buffer.add_string
bb "</llppconfig>\n";
7659 if load1 f && Buffer.length
bb > 0
7662 let tmp = !confpath ^
".tmp" in
7663 let oc = open_out_bin
tmp in
7664 Buffer.output_buffer
oc bb;
7666 Unix.rename
tmp !confpath;
7669 ("error while saving configuration: " ^ exntos exn
)
7673 let adderrmsg src msg
=
7674 Buffer.add_string
state.errmsgs msg
;
7675 state.newerrmsgs
<- true;
7679 let adderrfmt src fmt
=
7680 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7684 let cl = splitatspace cmds
in
7686 try Scanf.sscanf
s fmt
f
7688 adderrfmt "remote exec"
7689 "error processing '%S': %s\n" cmds
(exntos exn
)
7692 | "reload" :: [] -> reload ()
7693 | "goto" :: args :: [] ->
7694 scan args "%u %f %f"
7696 let cmd, _ = state.geomcmds
in
7698 then gotopagexy pageno x y
7701 gotopagexy pageno x y;
7704 state.reprf
<- f state.reprf
7706 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7707 | "gotor" :: args :: [] ->
7709 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
7710 | "gotord" :: args :: [] ->
7712 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
7713 | "rect" :: args :: [] ->
7714 scan args "%u %u %f %f %f %f"
7715 (fun pageno color x0 y0 x1 y1 ->
7716 onpagerect pageno (fun w h ->
7717 let _,w1,h1
,_ = getpagedim pageno in
7718 let sw = float w1 /. float w
7719 and sh = float h1
/. float h in
7723 and y1s
= y1 *. sh in
7724 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7726 state.rects <- (pageno, color, rect) :: state.rects;
7727 G.postRedisplay "rect";
7730 | "activatewin" :: [] -> Wsi.activatewin
()
7731 | "quit" :: [] -> raise Quit
7733 adderrfmt "remote command"
7734 "error processing remote command: %S\n" cmds
;
7738 let scratch = String.create
80 in
7739 let buf = Buffer.create
80 in
7742 try Some
(Unix.read fd
scratch 0 80)
7744 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7745 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7748 match tempfr () with
7754 if Buffer.length
buf > 0
7756 let s = Buffer.contents
buf in
7766 let pos = String.index_from
scratch ppos '
\n'
in
7767 if pos >= n then -1 else pos
7768 with Not_found
-> -1
7772 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7773 let s = Buffer.contents
buf in
7779 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7785 let remoteopen path =
7786 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7788 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7793 let trimcachepath = ref "" in
7794 let rcmdpath = ref "" in
7795 let pageno = ref None
in
7796 selfexec := Sys.executable_name
;
7799 [("-p", Arg.String
(fun s -> state.password
<- s),
7800 "<password> Set password");
7804 Config.fontpath := s;
7805 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7807 "<path> Set path to the user interface font");
7811 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7812 Config.confpath := s),
7813 "<path> Set path to the configuration file");
7815 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
7816 "<page-number> Jump to page");
7818 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7819 "<path> Set path to the trim cache file");
7821 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7822 "<named-destination> Set named destination");
7824 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7825 ("-cxack", Arg.Set
cxack, " Cut corners");
7827 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7828 "<path> Set path to the remote commands source");
7830 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7831 "<original-path> Set original path");
7833 ("-v", Arg.Unit
(fun () ->
7835 "%s\nconfiguration path: %s\n"
7839 exit
0), " Print version and exit");
7842 (fun s -> state.path <- s)
7843 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7846 then selfexec := !selfexec ^
" -wtmode";
7848 if emptystr
state.path
7849 then (prerr_endline
"file name missing"; exit
1);
7851 if not
(Config.load ())
7852 then prerr_endline
"failed to load configuration";
7853 begin match !pageno with
7854 | Some
pageno -> state.anchor <- (pageno, 0.0, 0.0)
7858 let wsfd, winw, winh
= Wsi.init
(object (self)
7859 val mutable m_hack
= false
7860 val mutable m_clicks
= 0
7861 val mutable m_click_x
= 0
7862 val mutable m_click_y
= 0
7863 val mutable m_lastclicktime
= infinity
7865 method private cleanup
=
7866 Hashtbl.iter
(fun _ opaque
-> clearmark opaque
) state.pagemap
;
7867 method expose
= if not m_hack
then G.postRedisplay "expose"
7868 method visible
= self#cleanup
; G.postRedisplay "visible"
7869 method display = m_hack
<- false; display ()
7870 method reshape w h =
7872 m_hack
<- w < state.winw && h < state.winh
;
7874 method mouse
b d x y m =
7877 (* http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx *)
7883 if abs
x - m_click_x
> 10
7884 || abs
y - m_click_y
> 10
7885 || abs_float
(t -. m_lastclicktime
) > 0.3
7887 m_clicks
<- m_clicks
+ 1;
7888 m_lastclicktime
<- t;
7892 state.uioh <- state.uioh#button
b d x y m;
7894 else state.uioh <- state.uioh#multiclick m_clicks
x y m
7898 m_lastclicktime
<- infinity
;
7899 state.uioh <- state.uioh#button
b d x y m
7903 state.uioh <- state.uioh#button
b d x y m
7906 state.mpos
<- (x, y);
7907 state.uioh <- state.uioh#motion
x y
7908 method pmotion
x y =
7909 state.mpos
<- (x, y);
7910 state.uioh <- state.uioh#pmotion
x y
7912 let mascm = m land (
7913 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7919 match state.keystate
with
7921 let km = k, mascm in
7924 let modehash = state.uioh#
modehash in
7925 try Hashtbl.find modehash km
7927 try Hashtbl.find (findkeyhash conf "global") km
7928 with Not_found
-> KMinsrt
(k, m)
7930 | KMinsrt
(k, m) -> keyboard k m
7931 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7932 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7934 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7935 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7936 state.keystate
<- KSnone
7937 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7938 state.keystate
<- KSinto
(keys
, insrt
)
7940 state.keystate
<- KSnone
7943 state.mpos
<- (x, y);
7944 state.uioh <- state.uioh#pmotion
x y
7945 method leave = state.mpos
<- (-1, -1)
7946 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7947 method quit
= raise Quit
7948 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7953 List.exists
GlMisc.check_extension
7954 [ "GL_ARB_texture_rectangle"
7955 ; "GL_EXT_texture_recangle"
7956 ; "GL_NV_texture_rectangle" ]
7958 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7961 let r = GlMisc.get_string `renderer
in
7962 let p = "Mesa DRI Intel(" in
7963 let l = String.length
p in
7964 String.length
r > l && String.sub
r 0 l = p
7967 defconf.sliceheight
<- 1024;
7968 defconf.texcount
<- 32;
7969 defconf.usepbo
<- true;
7973 match Ne.pipe () with
7975 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7979 match Ne.pipe () with
7981 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7991 setcheckers conf.checkers
;
7993 if conf.redirectstderr
7996 let s = Buffer.contents
state.errmsgs ^
7997 (match state.errfd
with
7999 let s = String.create
(80*24) in
8002 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
8004 then Unix.read fd
s 0 (String.length
s)
8010 else String.sub
s 0 n
8014 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
8015 with exn
-> print_endline
(exntos exn
)
8020 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
8021 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
8022 !Config.fontpath, !trimcachepath,
8023 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
8025 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
8028 state.text <- "Opening " ^
(mbtoutf8
state.path);
8030 opendoc state.path state.password
;
8034 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
8037 if nonemptystr
!rcmdpath
8038 then remoteopen !rcmdpath
8043 let rec loop deadline
=
8045 match state.errfd
with
8046 | None
-> [state.sr
; state.wsfd]
8047 | Some fd
-> [state.sr
; state.wsfd; fd
]
8052 | Some fd
-> fd
:: r
8056 state.redisplay
<- false;
8063 if deadline
= infinity
8065 else max
0.0 (deadline
-. now)
8070 try Unix.select
r [] [] timeout
8071 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
8077 if state.ghyll
== noghyll
8079 match state.autoscroll
with
8080 | Some step
when step
!= 0 ->
8081 let y = state.y + step
in
8085 else if y >= state.maxy then 0 else y
8088 if state.mode = View
8089 then state.text <- "";
8092 else deadline
+. 0.01
8097 let rec checkfds = function
8099 | fd
:: rest
when fd
= state.sr
->
8100 let cmd = readcmd state.sr
in
8104 | fd
:: rest
when fd
= state.wsfd ->
8108 | fd
:: rest
when Some fd
= !optrfd ->
8109 begin match remote fd
with
8110 | None
-> optrfd := remoteopen !rcmdpath;
8111 | opt -> optrfd := opt
8116 let s = String.create
80 in
8117 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
8118 if conf.redirectstderr
8120 Buffer.add_substring
state.errmsgs
s 0 n;
8121 state.newerrmsgs
<- true;
8122 state.redisplay
<- true;
8125 prerr_string
(String.sub
s 0 n);
8133 if deadline
= infinity
8137 match state.autoscroll
with
8138 | Some step
when step
!= 0 -> deadline1
8139 | _ -> if state.ghyll
== noghyll then infinity
else deadline1