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
-> 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
->
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
;;
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.res Unix.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";
978 let pipesel opaque cmd
=
979 match Ne.res Unix.pipe
with
982 (Printf.sprintf
"pipesel can not create pipe: %s" (exntos exn
));
984 let doclose what fd
=
985 Ne.clo fd
(fun msg
-> dolog
"%s close failed: %s" what msg
)
988 popen cmd
[r
, 0; w
, -1];
990 doclose "pipesel pipe/w" w
;
991 dolog
"can not execute %S: %s" cmd
(exntos exn
);
994 G.postRedisplay "pipesel";
995 doclose "pipesel pipe/r" r
;
999 let g opaque l
px py
=
1000 if markunder opaque
px py
conf.paxmark
1003 match getopaque l
.pageno
with
1005 | Some opaque
-> pipesel conf.paxcmd opaque
1010 G.postRedisplay "paxunder";
1011 if conf.paxmark
= Mark_page
1014 match getopaque l
.pageno
with
1016 | Some opaque
-> clearmark opaque
) state.layout
;
1018 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1022 match Ne.res Unix.pipe
with
1024 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1027 Ne.clo fd
(fun msg
->
1028 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1032 try popen conf.selcmd
[r
, 0; w
, -1]; true
1034 clo "selstring pipe/w" w
;
1036 (Printf.sprintf
"failed to execute %s: %s"
1037 conf.selcmd
(exntos exn
));
1043 let l = String.length s
in
1044 let n = tempfailureretry
(Unix.write w s
0) l in
1049 "failed to write %d characters to sel pipe, wrote %d"
1054 (Printf.sprintf
"failed to write to sel pipe: %s"
1059 clo "selstring pipe/r" r
;
1062 let undertext = function
1065 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1066 | Utext s
-> "font: " ^ s
1067 | Uunexpected s
-> "unexpected: " ^ s
1068 | Ulaunch s
-> "launch: " ^ s
1069 | Unamed s
-> "named: " ^ s
1070 | Uremote
(filename
, pageno
) ->
1071 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1072 | Uremotedest
(filename
, destname
) ->
1073 Printf.sprintf
"%s: destination %S" filename destname
1076 let updateunder x y =
1077 match getunder x y with
1078 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1080 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1081 Wsi.setcursor
Wsi.CURSOR_INFO
1082 | Ulinkgoto
(pageno
, _
) ->
1084 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1085 Wsi.setcursor
Wsi.CURSOR_INFO
1087 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1088 Wsi.setcursor
Wsi.CURSOR_TEXT
1090 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1091 Wsi.setcursor
Wsi.CURSOR_INHERIT
1093 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1094 Wsi.setcursor
Wsi.CURSOR_INHERIT
1096 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1097 Wsi.setcursor
Wsi.CURSOR_INHERIT
1098 | Uremote
(filename
, pageno
) ->
1099 if conf.underinfo
then showtext 'r'
1100 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1101 Wsi.setcursor
Wsi.CURSOR_INFO
1102 | Uremotedest
(filename
, destname
) ->
1103 if conf.underinfo
then showtext 'r'
1104 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1105 Wsi.setcursor
Wsi.CURSOR_INFO
1108 let showlinktype under
=
1114 let s = undertext under
in
1119 let b = Buffer.create
(String.length
s + 1) in
1120 Buffer.add_string
b s;
1121 Buffer.add_char
b c
;
1125 module type TextEnumType
=
1129 val names
: string array
1132 module TextEnumMake
(Ten
: TextEnumType
) =
1134 let names = Ten.names;;
1135 let to_int (t
: Ten.t
) = Obj.magic t
;;
1136 let to_string t
= names.(to_int t
);;
1137 let of_int n : Ten.t
= Obj.magic
n;;
1140 if i
= Array.length
names
1141 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1143 if Ten.names.(i
) = s
1150 module CSTE
= TextEnumMake
(struct
1151 type t
= colorspace
;;
1152 let name = "colorspace";;
1153 let names = [|"rgb"; "bgr"; "gray"|];;
1156 module MTE
= TextEnumMake
(struct
1159 let names = [|"page"; "block"; "line"; "word"|];;
1162 module FMTE
= TextEnumMake
(struct
1164 let name = "fitmodel";;
1165 let names = [|"width"; "proportional"; "page"|];;
1168 let intentry_with_suffix text key
=
1170 if key
>= 32 && key
< 127
1174 match Char.lowercase
c with
1176 let text = addchar text c in
1179 | 'k'
| 'm'
| '
g'
->
1180 let text = addchar text c in
1184 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1188 let multicolumns_to_string (n, a
, b) =
1190 then Printf.sprintf
"%d" n
1191 else Printf.sprintf
"%d,%d,%d" n a
b;
1194 let multicolumns_of_string s =
1196 (int_of_string
s, 0, 0)
1198 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1200 then failwith
"subtly broken"; (n, a
, b)
1206 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1207 if n != 4 then error
"incomplete read(len) = %d" n;
1209 lor (Char.code
s.[0] lsl 24)
1210 lor (Char.code
s.[1] lsl 16)
1211 lor (Char.code
s.[2] lsl 8)
1212 lor (Char.code
s.[3] lsl 0)
1214 let s = String.create
len in
1215 let n = tempfailureretry
(Unix.read fd
s 0) len in
1216 if n != len then error
"incomplete read(data) %d vs %d" n len;
1220 let btod b = if b then 1 else 0;;
1223 let b = Buffer.create
16 in
1224 Buffer.add_string
b "llll";
1227 let s = Buffer.contents
b in
1228 let n = String.length
s in
1230 (* dolog "wcmd %S" (String.sub s 4 len); *)
1231 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1232 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1233 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1234 s.[3] <- Char.chr
(len land 0xff);
1235 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1236 if n'
!= n then error
"write failed %d vs %d" n'
n;
1241 let d = state.winh
- h
in
1242 max
conf.interpagespace
((d + 1) / 2)
1245 let rowyh (c, coverA
, coverB
) b n =
1246 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1248 let _, _, vy
, (_, _, h
, _) = b.(n) in
1251 let n'
= n - coverA
in
1254 let e = min
state.pagecount
(s + c) in
1255 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1256 let _, _, y, (_, _, h
, _) = b.(m
) in
1257 let miny = min
miny y in
1258 let maxh = max
maxh h
in
1259 find (m
+1) miny maxh
1264 match conf.columns
with
1265 | Cmulti
((_, _, _) as cl
, b) ->
1266 if Array.length
b > 0
1268 let y, h
= rowyh cl
b (Array.length
b - 1) in
1269 y + h
+ (if conf.presentation
then calcips h
else 0)
1272 if Array.length
b > 0
1274 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1275 y + h
+ (if conf.presentation
then calcips h
else 0)
1278 if Array.length
b > 0
1280 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1285 let getpageywh pageno
=
1286 let pageno = bound pageno 0 (state.pagecount
-1) in
1287 match conf.columns
with
1289 if Array.length
b = 0
1292 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1294 if conf.presentation
1300 if Array.length
b = 0
1303 let y, h
= rowyh cl
b pageno in
1304 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1306 if conf.presentation
1312 if Array.length
b = 0
1316 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1320 let getpageyh pageno =
1321 let y,_,h
= getpageywh pageno in
1325 let getpagedim pageno =
1328 | (n, _, _, _) as pdim
:: rest
->
1330 then (if n = pageno then pdim
else ppdim
)
1335 f (-1, -1, -1, -1) state.pdims
1338 let getpagey pageno = fst
(getpageyh pageno);;
1340 let nogeomcmds cmds
=
1342 | s, [] -> emptystr
s
1347 let ((c, coverA
, coverB
) as cl
), b =
1348 match conf.columns
with
1349 | Csingle
b -> (1, 0, 0), b
1350 | Cmulti
(c, b) -> c, b
1351 | Csplit
(_, b) -> (1, 0, 0), b
1353 if Array.length
b = 0
1356 let rec bsearch nmin nmax
=
1358 then bound nmin
0 (state.pagecount
-1)
1360 let n = (nmax
+ nmin
) / 2 in
1361 let vy, h
= rowyh cl
b n in
1363 if conf.presentation
1365 let ips = calcips h
in
1366 let y0 = vy - ips in
1367 let y1 = vy + h
+ ips in
1371 then 0, vy + h
+ conf.interpagespace
1373 let y0 = vy - conf.interpagespace
in
1374 y0, y0 + h
+ conf.interpagespace
1377 if y >= y0 && y < y1
1384 if n < state.pagecount
- coverB
1385 then ((n-coverA
)/c)*c + coverA
1392 then bsearch (n+1) nmax
1393 else bsearch nmin
(n-1)
1396 bsearch 0 (state.pagecount
-1);
1399 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1400 let sh = sh - (hscrollh ()) in
1401 let rec fold accu
n =
1402 if n = Array.length
b
1405 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1408 || n = state.pagecount
- coverB
1409 || (n - coverA
) mod columns
= columns
- 1)
1415 let pagey = max
0 (y - vy) in
1416 let pagedispy = if pagey > 0 then 0 else vy - y in
1417 let pagedispx, pagex
=
1419 if n = coverA
- 1 || n = state.pagecount
- coverB
1420 then state.x + (wadjsb state.winw
- w
) / 2
1421 else dx + xoff
+ state.x
1428 let vw = wadjsb state.winw
- pagedispx in
1429 let pw = w
- pagex
in
1432 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1433 if pagevw > 0 && pagevh > 0
1437 ; pagedimno
= pdimno
1444 ; pagedispx = pagedispx
1445 ; pagedispy = pagedispy
1457 if Array.length
b = 0
1459 else List.rev
(fold [] (page_of_y y))
1462 let layoutS (columns
, b) y sh =
1463 let sh = sh - hscrollh () in
1464 let rec fold accu n =
1465 if n = Array.length
b
1468 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1475 let x = xoff
+ state.x in
1476 let pagey = max
0 (y - vy) in
1477 let pagedispy = if pagey > 0 then 0 else vy - y in
1478 let pagedispx, pagex
=
1492 let pagecolw = pagew
/columns
in
1494 if pagecolw < state.winw
1495 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1499 let vw = wadjsb state.winw
- pagedispx in
1500 let pw = pagew
- pagex
in
1503 let pagevw = min
pagevw pagecolw in
1504 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1505 if pagevw > 0 && pagevh > 0
1508 { pageno = n/columns
1509 ; pagedimno
= pdimno
1516 ; pagedispx = pagedispx
1517 ; pagedispy = pagedispy
1518 ; pagecol
= n mod columns
1529 List.rev
(fold [] 0)
1533 if nogeomcmds state.geomcmds
1535 match conf.columns
with
1536 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1537 | Cmulti
c -> layoutN c y sh
1538 | Csplit
s -> layoutS s y sh
1543 let y = state.y + incr
in
1545 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1550 let tilex = l.pagex
mod conf.tilew
in
1551 let tiley = l.pagey mod conf.tileh
in
1553 let col = l.pagex
/ conf.tilew
in
1554 let row = l.pagey / conf.tileh
in
1556 let rec rowloop row y0 dispy h
=
1560 let dh = conf.tileh
- y0 in
1561 let dh = min h
dh in
1562 let rec colloop col x0 dispx w
=
1566 let dw = conf.tilew
- x0 in
1567 let dw = min w
dw in
1569 f col row dispx dispy
x0 y0 dw dh;
1570 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1573 colloop col tilex l.pagedispx l.pagevw;
1574 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1577 if l.pagevw > 0 && l.pagevh > 0
1578 then rowloop row tiley l.pagedispy l.pagevh;
1581 let gettileopaque l col row =
1583 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1585 try Some
(Hashtbl.find state.tilemap
key)
1586 with Not_found
-> None
1589 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1590 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1591 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1594 let filledrect x0 y0 x1 y1 =
1595 GlArray.disable `texture_coord
;
1596 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1597 GlArray.vertex `two
state.vraw
;
1598 GlArray.draw_arrays `triangle_strip
0 4;
1599 GlArray.enable `texture_coord
;
1602 let linerect x0 y0 x1 y1 =
1603 GlArray.disable `texture_coord
;
1604 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1605 GlArray.vertex `two
state.vraw
;
1606 GlArray.draw_arrays `line_loop
0 4;
1607 GlArray.enable `texture_coord
;
1610 let drawtiles l color
=
1613 let f col row x y tilex tiley w h
=
1614 match gettileopaque l col row with
1615 | Some
(opaque
, _, t
) ->
1616 let params = x, y, w
, h
, tilex, tiley in
1620 GlFunc.blend_func `zero `one_minus_src_color
;
1622 drawtile
params opaque
;
1624 then Gl.disable `blend
;
1628 let s = Printf.sprintf
1632 let w = measurestr
fstate.fontsize
s in
1633 GlDraw.color
(0.0, 0.0, 0.0);
1634 filledrect (float (x-2))
1637 (float (y + fstate.fontsize
+ 2));
1638 GlDraw.color
(1.0, 1.0, 1.0);
1639 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1646 let lw = wadjsb state.winw
- x in
1649 let lh = state.winh
- y in
1655 GlFunc.blend_func `zero `one_minus_src_color
;
1657 begin match state.texid
with
1659 Gl.enable `texture_2d
;
1660 GlTex.bind_texture `texture_2d id
;
1663 and x1 = float (x+w)
1664 and y1 = float (y+h
) in
1666 let tw = float w /. 16.0
1667 and th
= float h
/. 16.0 in
1668 let tx0 = float tilex /. 16.0
1669 and ty0
= float tiley /. 16.0 in
1671 and ty1
= ty0
+. th
in
1672 Raw.sets_float
state.vraw ~pos
:0
1673 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1674 Raw.sets_float
state.traw ~pos
:0
1675 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1676 GlArray.vertex `two
state.vraw
;
1677 GlArray.tex_coord `two
state.traw
;
1678 GlArray.draw_arrays `triangle_strip
0 4;
1681 GlDraw.color
(1.0, 1.0, 1.0);
1682 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1684 if w > 128 && h
> fstate.fontsize
+ 10
1686 let c = if conf.invert
then 1.0 else 0.0 in
1687 GlDraw.color
(c, c, c);
1690 then (col*conf.tilew
, row*conf.tileh
)
1693 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1702 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1704 let tilevisible1 l x y =
1706 and ax1
= l.pagex
+ l.pagevw
1708 and ay1
= l.pagey + l.pagevh in
1712 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1713 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1715 let rx0 = max
ax0 bx0
1716 and ry0
= max ay0 by0
1717 and rx1
= min ax1
bx1
1718 and ry1
= min ay1 by1
in
1720 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1721 nonemptyintersection
1724 let tilevisible layout n x y =
1725 let rec findpageinlayout m
= function
1726 | l :: rest
when l.pageno = n ->
1727 tilevisible1 l x y || (
1728 match conf.columns
with
1729 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1732 | _ :: rest
-> findpageinlayout 0 rest
1735 findpageinlayout 0 layout;
1738 let tileready l x y =
1739 tilevisible1 l x y &&
1740 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1743 let tilepage n p
layout =
1744 let rec loop = function
1748 let f col row _ _ _ _ _ _ =
1749 if state.currently
= Idle
1751 match gettileopaque l col row with
1754 let x = col*conf.tilew
1755 and y = row*conf.tileh
in
1757 let w = l.pagew
- x in
1761 let h = l.pageh
- y in
1766 then getpbo
w h conf.colorspace
1769 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1772 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1773 conf.tilew
, conf.tileh
1782 if nogeomcmds state.geomcmds
1786 let preloadlayout y =
1787 let y = if y < state.winh
then 0 else y - state.winh
in
1788 let h = state.winh
*3 in
1793 let rec loop pages
=
1794 if state.currently
!= Idle
1799 begin match getopaque l.pageno with
1801 wcmd "page %d %d" l.pageno l.pagedimno
;
1802 state.currently
<- Loading
(l, state.gen
);
1804 tilepage l.pageno opaque pages
;
1809 if nogeomcmds state.geomcmds
1815 if conf.preload && state.currently
= Idle
1816 then load (preloadlayout state.y);
1819 let layoutready layout =
1820 let rec fold all ls
=
1821 all
&& match ls
with
1823 let seen = ref false in
1824 let allvisible = ref true in
1825 let foo col row _ _ _ _ _ _ =
1827 allvisible := !allvisible &&
1828 begin match gettileopaque l col row with
1834 fold (!seen && !allvisible) rest
1837 let alltilesvisible = fold true layout in
1842 let y = bound y 0 state.maxy
in
1843 let y, layout, proceed
=
1844 match conf.maxwait
with
1845 | Some time
when state.ghyll
== noghyll ->
1846 begin match state.throttle
with
1848 let layout = layout y state.winh
in
1849 let ready = layoutready layout in
1853 state.throttle
<- Some
(layout, y, now ());
1855 else G.postRedisplay "gotoy showall (None)";
1857 | Some
(_, _, started
) ->
1858 let dt = now () -. started
in
1861 state.throttle
<- None
;
1862 let layout = layout y state.winh
in
1864 G.postRedisplay "maxwait";
1871 let layout = layout y state.winh
in
1872 if not
!wtmode || layoutready layout
1873 then G.postRedisplay "gotoy ready";
1879 state.layout <- layout;
1880 begin match state.mode
with
1881 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1882 let rec loop = function
1884 state.mode
<- LinkNav
(Ltgendir
0)
1885 | l :: _ when l.pageno = pageno ->
1886 begin match getopaque pageno with
1888 state.mode
<- LinkNav
(Ltgendir
0)
1890 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1891 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1892 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1893 then state.mode
<- LinkNav
(Ltgendir
0)
1895 | _ :: rest
-> loop rest
1900 begin match state.mode
with
1901 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1902 if not
(pagevisible layout pageno)
1904 match state.layout with
1907 state.mode
<- Birdseye
(
1908 conf, leftx
, l.pageno, hooverpageno
, anchor
1911 | LinkNav
(Ltgendir dir
as lt
) ->
1913 let rec loop = function
1916 match getopaque l.pageno with
1922 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1924 if dir
> 0 then LDfirst
else LDlast
1930 | Lnotfound
-> loop rest
1932 showlinktype (getlink opaque
n);
1933 Ltexact
(l.pageno, n)
1937 state.mode
<- LinkNav
linknav
1942 state.ghyll
<- noghyll;
1945 let mx, my
= state.mpos
in
1950 let conttiling pageno opaque
=
1951 tilepage pageno opaque
1952 (if conf.preload then preloadlayout state.y else state.layout)
1955 let gotoy_and_clear_text y =
1956 if not
conf.verbose
then state.text <- "";
1962 let coloff = l.pagecol
* l.pageh
in
1963 float (l.pagey + coloff) /. float l.pageh
1970 if conf.presentation
1971 then float l.pagedispy /. float (calcips l.pageh
)
1972 else float l.pagedispy /. float conf.interpagespace
1975 (l.pageno, top, dtop)
1979 match state.layout with
1980 | l :: _ -> getanchor1 l
1982 let n = page_of_y state.y in
1986 let y, h = getpageyh n in
1987 let dy = y - state.y in
1989 if conf.presentation
1991 let ips = calcips h in
1992 float (dy + ips) /. float ips
1994 float dy /. float conf.interpagespace
1999 let getanchory (n, top, dtop) =
2000 let y, h = getpageyh n in
2001 if conf.presentation
2003 let ips = calcips h in
2004 y + truncate
(top*.float h -. dtop*.float ips) + ips;
2006 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
2009 let gotoanchor anchor
=
2010 gotoy (getanchory anchor
);
2014 cbput state.hists
.nav
(getanchor ());
2018 let anchor = cbgetc state.hists
.nav dir
in
2023 let scroll f n a
b =
2024 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2026 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2028 then s (float f /. float a
)
2031 then 1.0 -. s ((float (f-b) /. float (n-b)))
2037 let ins = float a
*. 0.5
2038 and outs
= float (n-b) *. 0.5 in
2040 ins +. outs
+. float ones
2042 let rec set (_N
, _A
, _B
) y sy
=
2043 let sum = summa _N _A _B
in
2044 let dy = float (y - sy
) in
2048 then state.ghyll
<- noghyll
2051 let s = scroll n _N _A _B
in
2052 let y1 = y1 +. ((s *. dy) /. sum) in
2053 gotoy_and_clear_text (truncate
y1);
2054 state.ghyll
<- gf (n+1) y1;
2058 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2060 gf 0 (float state.y)
2063 match conf.ghyllscroll
with
2065 gotoy_and_clear_text y
2067 if state.ghyll
== noghyll
2068 then set nab
y state.y
2069 else state.ghyll
(Some
y)
2072 let gotopage n top =
2073 let y, h = getpageyh n in
2074 let y = y + (truncate
(top *. float h)) in
2078 let gotopage1 n top =
2079 let y = getpagey n in
2084 let invalidate s f =
2089 match state.geomcmds
with
2090 | ps
, [] when emptystr ps
->
2092 state.geomcmds
<- s, [];
2095 state.geomcmds
<- ps
, [s, f];
2097 | ps
, (s'
, _) :: rest
when s'
= s ->
2098 state.geomcmds
<- ps
, ((s, f) :: rest
);
2101 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2105 Hashtbl.iter
(fun _ opaque
->
2106 wcmd "freepage %s" opaque
;
2108 Hashtbl.clear
state.pagemap
;
2112 if not
(Queue.is_empty
state.tilelru
)
2114 Queue.iter
(fun (k
, p
, s) ->
2115 wcmd "freetile %s" p
;
2116 state.memused
<- state.memused
- s;
2117 Hashtbl.remove
state.tilemap k
;
2119 state.uioh#infochanged Memused
;
2120 Queue.clear
state.tilelru
;
2126 let h = truncate
(float h*.conf.zoom
) in
2127 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2131 let opendoc path password
=
2133 state.password
<- password
;
2134 state.gen
<- state.gen
+ 1;
2135 state.docinfo
<- [];
2138 setaalevel
conf.aalevel
;
2140 if emptystr
state.origin
2144 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2145 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2146 invalidate "reqlayout"
2148 wcmd "reqlayout %d %d %d %s\000"
2149 conf.angle
(FMTE.to_int conf.fitmodel
)
2150 (stateh state.winh
) state.nameddest
2155 state.anchor <- getanchor ();
2156 opendoc state.path
state.password
;
2160 let c = c *. conf.colorscale
in
2164 let scalecolor2 (r
, g, b) =
2165 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2168 let docolumns = function
2170 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2171 let rec loop pageno pdimno pdim
y ph pdims
=
2172 if pageno = state.pagecount
2175 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2177 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2178 pdimno+1, pdim
, rest
2182 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2184 (if conf.presentation
2185 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2186 else (if pageno = 0 then 0 else conf.interpagespace
)
2189 a.(pageno) <- (pdimno, x, y, pdim
);
2190 loop (pageno+1) pdimno pdim
(y + h) h pdims
2192 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2193 conf.columns
<- Csingle
a;
2195 | Cmulti
((columns
, coverA
, coverB
), _) ->
2196 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2197 let rec loop pageno pdimno pdim
x y rowh pdims
=
2198 let rec fixrow m
= if m
= pageno then () else
2199 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2202 let y = y + (rowh
- h) / 2 in
2203 a.(m
) <- (pdimno, x, y, pdim
);
2207 if pageno = state.pagecount
2208 then fixrow (((pageno - 1) / columns
) * columns
)
2210 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2212 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2213 pdimno+1, pdim
, rest
2218 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2220 let x = (wadjsb state.winw
- w) / 2 in
2222 if conf.presentation
then calcips h else conf.interpagespace
in
2223 x, y + ips + rowh
, h
2226 if (pageno - coverA
) mod columns
= 0
2228 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2230 if conf.presentation
2232 let ips = calcips h in
2233 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2235 y + (if pageno = 0 then 0 else conf.interpagespace
)
2239 else x, y, max rowh
h
2243 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2246 if pageno = columns
&& conf.presentation
2248 let ips = calcips rowh
in
2249 for i
= 0 to pred columns
2251 let (pdimno, x, y, pdim
) = a.(i
) in
2252 a.(i
) <- (pdimno, x, y+ips, pdim
)
2258 fixrow (pageno - columns
);
2263 a.(pageno) <- (pdimno, x, y, pdim
);
2264 let x = x + w + xoff
*2 + conf.interpagespace
in
2265 loop (pageno+1) pdimno pdim
x y rowh' pdims
2267 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2268 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2271 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2272 let rec loop pageno pdimno pdim
y pdims
=
2273 if pageno = state.pagecount
2276 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2278 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2279 pdimno+1, pdim
, rest
2284 let rec loop1 n x y =
2285 if n = c then y else (
2286 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2287 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2290 let y = loop1 0 0 y in
2291 loop (pageno+1) pdimno pdim
y pdims
2293 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2294 conf.columns
<- Csplit
(c, a);
2298 docolumns conf.columns
;
2299 state.maxy
<- calcheight ();
2300 if state.reprf
== noreprf
2302 match state.mode
with
2303 | Birdseye
(_, _, pageno, _, _) ->
2304 let y, h = getpageyh pageno in
2305 let top = (state.winh
- h) / 2 in
2306 gotoy (max
0 (y - top))
2307 | _ -> gotoanchor state.anchor
2311 state.reprf
<- noreprf;
2316 GlDraw.viewport
0 0 w h;
2317 let firsttime = state.geomcmds
== firstgeomcmds in
2318 if not
firsttime && nogeomcmds state.geomcmds
2319 then state.anchor <- getanchor ();
2322 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2325 setfontsize fstate.fontsize
;
2326 GlMat.mode `modelview
;
2327 GlMat.load_identity
();
2329 GlMat.mode `projection
;
2330 GlMat.load_identity
();
2331 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2332 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2333 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2338 else float state.x /. float state.w
2340 invalidate "geometry"
2344 then state.x <- truncate
(relx *. float w);
2346 match conf.columns
with
2348 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2349 | Csplit
(c, _) -> w * c
2351 wcmd "geometry %d %d %d"
2352 w (stateh h) (FMTE.to_int conf.fitmodel
)
2357 let len = String.length
state.text in
2360 match state.mode
with
2361 | Textentry
_ | View
| LinkNav
_ ->
2362 let h, _, _ = state.uioh#scrollpw
in
2367 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2368 (x+.w) (float (state.winh
- hscrollh))
2371 let w = float (wadjsb state.winw
- 1) in
2372 if state.progress
>= 0.0 && state.progress
< 1.0
2374 GlDraw.color
(0.3, 0.3, 0.3);
2375 let w1 = w *. state.progress
in
2377 GlDraw.color
(0.0, 0.0, 0.0);
2381 GlDraw.color
(0.0, 0.0, 0.0);
2385 GlDraw.color
(1.0, 1.0, 1.0);
2386 drawstring fstate.fontsize
2387 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2390 match state.mode
with
2391 | Textentry
((prefix
, text, _, _, _, _), _) ->
2395 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2397 Printf.sprintf
"%s%s_" prefix
text
2406 if not
(istextentry state.mode
) && state.uioh#eformsgs
2408 let s1 = "(press 'e' to review error messasges)" in
2409 if nonemptystr
s then s ^
" " ^
s1 else s1
2419 let len = Queue.length
state.tilelru
in
2421 match state.throttle
with
2424 then preloadlayout state.y
2426 | Some
(layout, _, _) ->
2430 if state.memused
<= conf.memlimit
2435 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2436 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2437 let (_, pw, ph
, _) = getpagedim n in
2440 && colorspace
= conf.colorspace
2441 && angle
= conf.angle
2445 let x = col*conf.tilew
2446 and y = row*conf.tileh
in
2447 tilevisible (Lazy.force_val
layout) n x y
2449 then Queue.push lruitem
state.tilelru
2452 wcmd "freetile %s" p
;
2453 state.memused
<- state.memused
- s;
2454 state.uioh#infochanged Memused
;
2455 Hashtbl.remove
state.tilemap k
;
2463 let logcurrently = function
2464 | Idle
-> dolog
"Idle"
2465 | Loading
(l, gen
) ->
2466 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2467 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2469 "Tiling %d[%d,%d] page=%s cs=%s angle"
2470 l.pageno col row pageopaque
2471 (CSTE.to_string colorspace
)
2473 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2474 angle gen
conf.angle
state.gen
2476 conf.tilew
conf.tileh
2483 let r = Str.regexp
" " in
2484 fun s -> Str.bounded_split
r s 2;
2487 let onpagerect pageno f =
2489 match conf.columns
with
2490 | Cmulti
(_, b) -> b
2492 | Csplit
(_, b) -> b
2494 if pageno >= 0 && pageno < Array.length
b
2496 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2500 let gotopagexy1 pageno x y =
2501 let _,w1,h1
,leftx
= getpagedim pageno in
2502 let top = y /. (float h1
) in
2503 let left = x /. (float w1) in
2504 let py, w, h = getpageywh pageno in
2505 let wh = state.winh
- hscrollh () in
2506 let x = left *. (float w) in
2507 let x = leftx
+ state.x + truncate
x in
2509 if x < 0 || x >= wadjsb state.winw
2513 let pdy = truncate
(top *. float h) in
2514 let y'
= py + pdy in
2515 let dy = y'
- state.y in
2517 if x != state.x || not
(dy > 0 && dy < wh)
2519 if conf.presentation
2521 if abs
(py - y'
) > wh
2528 if state.x != sx || state.y != sy
2533 let ww = wadjsb state.winw
in
2535 and qy
= pdy / wh in
2537 and y = py + qy
* wh in
2538 let x = if -x + ww > w1 then -(w1-ww) else x
2539 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2541 if conf.presentation
2543 if abs
(py - y'
) > wh
2553 gotoy_and_clear_text y;
2555 else gotoy_and_clear_text state.y;
2558 let gotopagexy pageno x y =
2559 match state.mode
with
2560 | Birdseye
_ -> gotopage pageno 0.0
2561 | _ -> gotopagexy1 pageno x y
2565 (* dolog "%S" cmds; *)
2566 let cl = splitatspace cmds
in
2568 try Scanf.sscanf
s fmt
f
2570 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2573 let addoutline outline
=
2574 match state.currently
with
2575 | Outlining outlines
->
2576 state.currently
<- Outlining
(outline
:: outlines
)
2577 | Idle
-> state.currently
<- Outlining
[outline
]
2579 dolog
"invalid outlining state";
2580 logcurrently currently
2584 state.uioh#infochanged Pdim
;
2587 | "clearrects" :: [] ->
2588 state.rects
<- state.rects1
;
2589 G.postRedisplay "clearrects";
2591 | "continue" :: args :: [] ->
2592 let n = scan args "%u" (fun n -> n) in
2593 state.pagecount
<- n;
2594 begin match state.currently
with
2596 state.currently
<- Idle
;
2597 state.outlines
<- Array.of_list
(List.rev
l)
2601 let cur, cmds
= state.geomcmds
in
2603 then failwith
"umpossible";
2605 begin match List.rev cmds
with
2607 state.geomcmds
<- "", [];
2611 state.geomcmds
<- s, List.rev rest
;
2613 if conf.maxwait
= None
&& not
!wtmode
2614 then G.postRedisplay "continue";
2616 | "title" :: args :: [] ->
2619 | "msg" :: args :: [] ->
2622 | "vmsg" :: args :: [] ->
2624 then showtext ' '
args
2626 | "emsg" :: args :: [] ->
2627 Buffer.add_string
state.errmsgs
args;
2628 state.newerrmsgs
<- true;
2629 G.postRedisplay "error message"
2631 | "progress" :: args :: [] ->
2632 let progress, text =
2635 f, String.sub
args pos
(String.length
args - pos
))
2638 state.progress <- progress;
2639 G.postRedisplay "progress"
2641 | "firstmatch" :: args :: [] ->
2642 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2643 scan args "%u %d %f %f %f %f %f %f %f %f"
2644 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2645 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2647 let y = (getpagey pageno) + truncate
y0 in
2650 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2652 | "match" :: args :: [] ->
2653 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2654 scan args "%u %d %f %f %f %f %f %f %f %f"
2655 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2656 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2659 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2661 | "page" :: args :: [] ->
2662 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2663 begin match state.currently
with
2664 | Loading
(l, gen
) ->
2665 vlog "page %d took %f sec" l.pageno t
;
2666 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2667 begin match state.throttle
with
2669 let preloadedpages =
2671 then preloadlayout state.y
2676 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2677 IntSet.empty
preloadedpages
2680 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2681 if not
(IntSet.mem
pageno set)
2683 wcmd "freepage %s" opaque
;
2689 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2692 state.currently
<- Idle
;
2695 tilepage l.pageno pageopaque state.layout;
2697 load preloadedpages;
2698 if pagevisible state.layout l.pageno
2699 && layoutready state.layout
2700 then G.postRedisplay "page";
2703 | Some
(layout, _, _) ->
2704 state.currently
<- Idle
;
2705 tilepage l.pageno pageopaque layout;
2710 dolog
"Inconsistent loading state";
2711 logcurrently state.currently
;
2715 | "tile" :: args :: [] ->
2716 let (x, y, opaque
, size
, t
) =
2717 scan args "%u %u %s %u %f"
2718 (fun x y p size t
-> (x, y, p
, size
, t
))
2720 begin match state.currently
with
2721 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2722 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2725 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2727 wcmd "freetile %s" opaque
;
2728 state.currently
<- Idle
;
2732 puttileopaque l col row gen cs angle opaque size t
;
2733 state.memused
<- state.memused
+ size
;
2734 state.uioh#infochanged Memused
;
2736 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2737 opaque
, size
) state.tilelru
;
2740 match state.throttle
with
2741 | None
-> state.layout
2742 | Some
(layout, _, _) -> layout
2745 state.currently
<- Idle
;
2747 && conf.colorspace
= cs
2748 && conf.angle
= angle
2749 && tilevisible layout l.pageno x y
2750 then conttiling l.pageno pageopaque;
2752 begin match state.throttle
with
2754 preload state.layout;
2756 && conf.colorspace
= cs
2757 && conf.angle
= angle
2758 && tilevisible state.layout l.pageno x y
2759 && (not
!wtmode || layoutready state.layout)
2760 then G.postRedisplay "tile nothrottle";
2762 | Some
(layout, y, _) ->
2763 let ready = layoutready layout in
2767 state.layout <- layout;
2768 state.throttle
<- None
;
2769 G.postRedisplay "throttle";
2776 dolog
"Inconsistent tiling state";
2777 logcurrently state.currently
;
2781 | "pdim" :: args :: [] ->
2782 let (n, w, h, _) as pdim
=
2783 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2786 match conf.fitmodel
, conf.columns
with
2787 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2790 state.uioh#infochanged Pdim
;
2791 state.pdims
<- pdim :: state.pdims
2793 | "o" :: args :: [] ->
2794 let (l, n, t
, h, pos
) =
2795 scan args "%u %u %d %u %n"
2796 (fun l n t
h pos
-> l, n, t
, h, pos
)
2798 let s = String.sub
args pos
(String.length
args - pos
) in
2799 addoutline (s, l, Oanchor
(n, float t
/. float h, 0.0))
2801 | "ou" :: args :: [] ->
2802 let (l, len, pos
) = scan args "%u %u %n" (fun l len pos
-> l, len, pos
) in
2803 let s = String.sub
args pos
len in
2804 let pos2 = pos
+ len + 1 in
2805 let uri = String.sub
args pos2 (String.length
args - pos2) in
2806 addoutline (s, l, Ouri
uri)
2808 | "on" :: args :: [] ->
2809 let (l, pos
) = scan args "%u %n" (fun l pos
-> l, pos
) in
2810 let s = String.sub
args pos
(String.length
args - pos
) in
2811 addoutline (s, l, Onone
)
2813 | "a" :: args :: [] ->
2815 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2817 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2819 | "info" :: args :: [] ->
2820 state.docinfo
<- (1, args) :: state.docinfo
2822 | "infoend" :: [] ->
2823 state.uioh#infochanged Docinfo
;
2824 state.docinfo
<- List.rev
state.docinfo
2827 error
"unknown cmd `%S'" cmds
2832 let action = function
2833 | HCprev
-> cbget cb ~
-1
2834 | HCnext
-> cbget cb
1
2835 | HCfirst
-> cbget cb ~
-(cb
.rc)
2836 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2837 and cancel
() = cb
.rc <- rc
2841 let search pattern forward
=
2842 match conf.columns
with
2844 showtext '
!'
"searching does not work properly in split columns mode"
2846 if nonemptystr pattern
2849 match state.layout with
2852 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2854 wcmd "search %d %d %d %d,%s\000"
2855 (btod conf.icase
) pn py (btod forward
) pattern
;
2858 let intentry text key =
2860 if key >= 32 && key < 127
2866 let text = addchar text c in
2870 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2874 let linknentry text key =
2876 if key >= 32 && key < 127
2882 let text = addchar text c in
2886 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2894 let l = String.length
s in
2895 let rec loop pos
n = if pos
= l then n else
2896 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2897 loop (pos
+1) (n*26 + m)
2900 let rec loop n = function
2903 match getopaque l.pageno with
2904 | None
-> loop n rest
2906 let m = getlinkcount opaque
in
2909 let under = getlink opaque
n in
2912 else loop (n-m) rest
2914 loop n state.layout;
2918 let textentry text key =
2919 if key land 0xff00 = 0xff00
2921 else TEcont
(text ^ toutf8
key)
2924 let reqlayout angle fitmodel
=
2925 match state.throttle
with
2927 if nogeomcmds state.geomcmds
2928 then state.anchor <- getanchor ();
2929 conf.angle
<- angle
mod 360;
2932 match state.mode
with
2933 | LinkNav
_ -> state.mode
<- View
2936 conf.fitmodel
<- fitmodel
;
2937 invalidate "reqlayout"
2939 wcmd "reqlayout %d %d %d"
2940 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2945 let settrim trimmargins trimfuzz
=
2946 if nogeomcmds state.geomcmds
2947 then state.anchor <- getanchor ();
2948 conf.trimmargins
<- trimmargins
;
2949 conf.trimfuzz
<- trimfuzz
;
2950 let x0, y0, x1, y1 = trimfuzz
in
2951 invalidate "settrim"
2953 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2958 match state.throttle
with
2960 let zoom = max
0.0001 zoom in
2961 if zoom <> conf.zoom
2963 state.prevzoom
<- (conf.zoom, state.x);
2965 reshape state.winw
state.winh
;
2966 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2969 | Some
(layout, y, started
) ->
2971 match conf.maxwait
with
2975 let dt = now () -. started
in
2983 let setcolumns mode columns coverA coverB
=
2984 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2988 then showtext '
!'
"split mode doesn't work in bird's eye"
2990 conf.columns
<- Csplit
(-columns
, [||]);
2998 conf.columns
<- Csingle
[||];
3003 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
3007 reshape state.winw
state.winh
;
3010 let enterbirdseye () =
3011 let zoom = float conf.thumbw
/. float state.winw
in
3012 let birdseyepageno =
3013 let cy = state.winh
/ 2 in
3017 let rec fold best
= function
3020 let d = cy - (l.pagedispy + l.pagevh/2)
3021 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
3022 if abs
d < abs dbest
3029 state.mode
<- Birdseye
(
3030 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
3033 conf.presentation
<- false;
3034 conf.interpagespace
<- 10;
3035 conf.hlinks
<- false;
3036 conf.fitmodel
<- FitProportional
;
3038 state.mstate
<- Mnone
;
3039 conf.maxwait
<- None
;
3041 match conf.beyecolumns
with
3044 Cmulti
((c, 0, 0), [||])
3045 | None
-> Csingle
[||]
3047 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3050 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3055 reshape state.winw
state.winh
;
3058 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3060 conf.zoom <- c.zoom;
3061 conf.presentation
<- c.presentation
;
3062 conf.interpagespace
<- c.interpagespace
;
3063 conf.maxwait
<- c.maxwait
;
3064 conf.hlinks
<- c.hlinks
;
3065 conf.fitmodel
<- c.fitmodel
;
3066 conf.beyecolumns
<- (
3067 match conf.columns
with
3068 | Cmulti
((c, _, _), _) -> Some
c
3070 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3073 match c.columns
with
3074 | Cmulti
(c, _) -> Cmulti
(c, [||])
3075 | Csingle
_ -> Csingle
[||]
3076 | Csplit
(c, _) -> Csplit
(c, [||])
3080 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3083 reshape state.winw
state.winh
;
3084 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3088 let togglebirdseye () =
3089 match state.mode
with
3090 | Birdseye vals
-> leavebirdseye vals
true
3091 | View
-> enterbirdseye ()
3095 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3096 let pageno = max
0 (pageno - incr
) in
3097 let rec loop = function
3098 | [] -> gotopage1 pageno 0
3099 | l :: _ when l.pageno = pageno ->
3100 if l.pagedispy >= 0 && l.pagey = 0
3101 then G.postRedisplay "upbirdseye"
3102 else gotopage1 pageno 0
3103 | _ :: rest
-> loop rest
3106 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3109 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3110 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3111 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3112 let rec loop = function
3114 let y, h = getpageyh pageno in
3115 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3117 | l :: _ when l.pageno = pageno ->
3118 if l.pagevh != l.pageh
3119 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3120 else G.postRedisplay "downbirdseye"
3121 | _ :: rest
-> loop rest
3126 let boundastep h step
=
3128 then bound step ~
-h 0
3132 let optentry mode
_ key =
3133 let btos b = if b then "on" else "off" in
3134 if key >= 32 && key < 127
3136 let c = Char.chr
key in
3140 try conf.scrollstep
<- int_of_string
s with exc
->
3141 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3143 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3148 conf.autoscrollstep
<- boundastep state.winh
(int_of_string
s);
3149 if state.autoscroll
<> None
3150 then state.autoscroll
<- Some
conf.autoscrollstep
3152 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3154 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3159 let n, a, b = multicolumns_of_string s in
3160 setcolumns mode
n a b;
3162 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3164 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3169 let zoom = float (int_of_string
s) /. 100.0 in
3172 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3174 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3179 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3181 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3182 begin match mode
with
3184 leavebirdseye beye
false;
3189 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3191 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3196 Some
(int_of_string
s)
3198 state.text <- Printf.sprintf
"bad integer `%s': %s"
3202 | Some angle
-> reqlayout angle
conf.fitmodel
3205 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3208 conf.icase
<- not
conf.icase
;
3209 TEdone
("case insensitive search " ^
(btos conf.icase
))
3212 conf.preload <- not
conf.preload;
3214 TEdone
("preload " ^
(btos conf.preload))
3217 conf.verbose
<- not
conf.verbose
;
3218 TEdone
("verbose " ^
(btos conf.verbose
))
3221 conf.debug
<- not
conf.debug
;
3222 TEdone
("debug " ^
(btos conf.debug
))
3225 conf.maxhfit
<- not
conf.maxhfit
;
3226 state.maxy
<- calcheight ();
3227 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3230 conf.crophack
<- not
conf.crophack
;
3231 TEdone
("crophack " ^
btos conf.crophack
)
3235 match conf.maxwait
with
3237 conf.maxwait
<- Some infinity
;
3238 "always wait for page to complete"
3240 conf.maxwait
<- None
;
3241 "show placeholder if page is not ready"
3246 conf.underinfo
<- not
conf.underinfo
;
3247 TEdone
("underinfo " ^
btos conf.underinfo
)
3250 conf.savebmarks
<- not
conf.savebmarks
;
3251 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3257 match state.layout with
3262 conf.interpagespace
<- int_of_string
s;
3263 docolumns conf.columns
;
3264 state.maxy
<- calcheight ();
3265 let y = getpagey pageno in
3268 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3270 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3274 match conf.fitmodel
with
3275 | FitProportional
-> FitWidth
3276 | _ -> FitProportional
3278 reqlayout conf.angle
fm;
3279 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3282 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3283 TEdone
("trim margins " ^
btos conf.trimmargins
)
3286 conf.invert
<- not
conf.invert
;
3287 TEdone
("invert colors " ^
btos conf.invert
)
3291 cbput state.hists
.sel
s;
3294 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3295 textentry, ondone, true)
3299 then conf.pax
<- Some
(ref (0.0, 0, 0))
3300 else conf.pax
<- None
;
3301 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3304 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3310 class type lvsource
= object
3311 method getitemcount
: int
3312 method getitem
: int -> (string * int)
3313 method hasaction
: int -> bool
3322 method getactive
: int
3323 method getfirst
: int
3324 method getqsearch
: string
3325 method setqsearch
: string -> unit
3329 class virtual lvsourcebase
= object
3330 val mutable m_active
= 0
3331 val mutable m_first
= 0
3332 val mutable m_qsearch
= ""
3333 val mutable m_pan
= 0
3334 method getactive
= m_active
3335 method getfirst
= m_first
3336 method getqsearch
= m_qsearch
3337 method getpan
= m_pan
3338 method setqsearch
s = m_qsearch
<- s
3341 let withoutlastutf8 s =
3342 let len = String.length
s in
3350 let b = Char.code
s.[pos
] in
3351 if b land 0b11000000 = 0b11000000
3356 if Char.code
s.[len-1] land 0x80 = 0
3360 String.sub
s 0 first;
3363 let textentrykeyboard
3364 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3366 if key >= 0xffb0 && key <= 0xffb9
3367 then key - 0xffb0 + 48 else key
3370 state.mode
<- Textentry
(te
, onleave
);
3373 G.postRedisplay "textentrykeyboard enttext";
3375 let histaction cmd
=
3378 | Some
(action, _) ->
3379 state.mode
<- Textentry
(
3380 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3382 G.postRedisplay "textentry histaction"
3385 | 0xff08 -> (* backspace *)
3386 if emptystr
text && cancelonempty
3389 G.postRedisplay "textentrykeyboard after cancel";
3392 let s = withoutlastutf8 text in
3393 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3395 | 0xff0d | 0xff8d -> (* (kp) enter *)
3398 G.postRedisplay "textentrykeyboard after confirm"
3400 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3401 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3402 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3403 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3405 | 0xff1b -> (* escape*)
3408 begin match opthist
with
3410 | Some
(_, onhistcancel
) -> onhistcancel
()
3414 G.postRedisplay "textentrykeyboard after cancel2"
3417 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3420 | 0xff9f | 0xffff -> () (* delete *)
3423 && key land 0xff00 != 0xff00 (* keyboard *)
3424 && key land 0xfe00 != 0xfe00 (* xkb *)
3425 && key land 0xfd00 != 0xfd00 (* 3270 *)
3427 begin match onkey
text key with
3431 G.postRedisplay "textentrykeyboard after confirm2";
3434 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3438 G.postRedisplay "textentrykeyboard after cancel3"
3441 state.mode
<- Textentry
(te
, onleave
);
3442 G.postRedisplay "textentrykeyboard switch";
3446 vlog "unhandled key %s" (Wsi.keyname
key)
3449 let firstof first active
=
3450 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3451 then max
0 (active
- (fstate.maxrows
/2))
3455 let calcfirst first active
=
3458 let rows = active
- first in
3459 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3463 let scrollph y maxy
=
3464 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3465 let sh = float state.winh
/. sh in
3466 let sh = max
sh (float conf.scrollh
) in
3468 let percent = float y /. float maxy
in
3469 let position = (float state.winh
-. sh) *. percent in
3472 if position +. sh > float state.winh
3473 then float state.winh
-. sh
3479 let coe s = (s :> uioh
);;
3481 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3483 val m_pan
= source#getpan
3484 val m_first
= source#getfirst
3485 val m_active
= source#getactive
3486 val m_qsearch
= source#getqsearch
3487 val m_prev_uioh
= state.uioh
3489 method private elemunder
y =
3490 let n = y / (fstate.fontsize
+1) in
3491 if m_first
+ n < source#getitemcount
3493 if source#hasaction
(m_first
+ n)
3494 then Some
(m_first
+ n)
3501 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3502 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3503 filledrect 0. 0. (float state.winw
) (float state.winh
);
3504 GlDraw.color
(1., 1., 1.);
3505 Gl.enable `texture_2d
;
3506 let fs = fstate.fontsize
in
3508 let ww = fstate.wwidth
in
3509 let tabw = 30.0*.ww in
3510 let itemcount = source#getitemcount
in
3512 if (row - m_first
) > fstate.maxrows
3515 if row >= 0 && row < itemcount
3517 let (s, level
) = source#getitem
row in
3518 let y = (row - m_first
) * nfs in
3519 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3522 Gl.disable `texture_2d
;
3523 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3524 GlDraw.color
(1., 1., 1.) ~
alpha;
3525 linerect 1. (float (y + 1))
3526 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3527 GlDraw.color
(1., 1., 1.);
3528 Gl.enable `texture_2d
;
3531 let drawtabularstring s =
3532 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3535 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3538 let len = String.length
s - tabpos - 1 in
3539 let s1 = String.sub
s 0 tabpos
3540 and s2
= String.sub
s (tabpos + 1) len in
3541 let nx = drawstr x s1 in
3543 let x = x +. (max
tabw sw) in
3550 let _ = drawtabularstring s in
3557 Gl.disable `texture_2d
;
3559 method updownlevel incr
=
3560 let len = source#getitemcount
in
3562 if m_active
>= 0 && m_active
< len
3563 then snd
(source#getitem m_active
)
3567 if i
= len then i
-1 else if i
= -1 then 0 else
3568 let _, l = source#getitem i
in
3569 if l != curlevel then i
else flow (i
+incr
)
3571 let active = flow m_active
in
3572 let first = calcfirst m_first
active in
3573 G.postRedisplay "outline updownlevel";
3574 {< m_active
= active; m_first
= first >}
3576 method private key1
key mask
=
3577 let set1 active first qsearch
=
3578 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3580 let search active pattern incr
=
3581 let active = if active = -1 then m_first
else active in
3584 if n >= 0 && n < source#getitemcount
3586 let s, _ = source#getitem
n in
3588 (try ignore
(Str.search_forward
re s 0); true
3589 with Not_found
-> false)
3591 else loop (n + incr
)
3598 let re = Str.regexp_case_fold pattern
in
3604 let itemcount = source#getitemcount
in
3605 let find start incr
=
3607 if i
= -1 || i
= itemcount
3610 if source#hasaction i
3612 else find (i
+ incr
)
3617 let set active first =
3618 let first = bound first 0 (itemcount - fstate.maxrows
) in
3620 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3623 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3625 let incr1 = if incr
> 0 then 1 else -1 in
3626 if isvisible m_first m_active
3629 let next = m_active
+ incr
in
3631 if next < 0 || next >= itemcount
3633 else find next incr1
3635 if abs
(m_active
- next) > fstate.maxrows
3641 let first = m_first
+ incr
in
3642 let first = bound first 0 (itemcount - fstate.maxrows
) in
3644 let next = m_active
+ incr
in
3645 let next = bound next 0 (itemcount - 1) in
3652 if isvisible first next
3659 let first = min
next m_first
in
3661 if abs
(next - first) > fstate.maxrows
3667 let first = m_first
+ incr
in
3668 let first = bound first 0 (itemcount - 1) in
3670 let next = m_active
+ incr
in
3671 let next = bound next 0 (itemcount - 1) in
3672 let next = find next incr1 in
3674 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3676 let active = if m_active
= -1 then next else m_active
in
3681 if isvisible first active
3687 G.postRedisplay "listview navigate";
3691 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3692 let incr = if key = 0x72 then -1 else 1 in
3694 match search (m_active
+ incr) m_qsearch
incr with
3696 state.text <- m_qsearch ^
" [not found]";
3699 state.text <- m_qsearch
;
3700 active, firstof m_first
active
3702 G.postRedisplay "listview ctrl-r/s";
3703 set1 active first m_qsearch
;
3705 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3706 if m_active
>= 0 && m_active
< source#getitemcount
3708 let s, _ = source#getitem m_active
in
3713 | 0xff08 -> (* backspace *)
3714 if emptystr m_qsearch
3717 let qsearch = withoutlastutf8 m_qsearch
in
3721 G.postRedisplay "listview empty qsearch";
3722 set1 m_active m_first
"";
3726 match search m_active
qsearch ~
-1 with
3728 state.text <- qsearch ^
" [not found]";
3731 state.text <- qsearch;
3732 active, firstof m_first
active
3734 G.postRedisplay "listview backspace qsearch";
3735 set1 active first qsearch
3738 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3739 let pattern = m_qsearch ^ toutf8
key in
3741 match search m_active
pattern 1 with
3743 state.text <- pattern ^
" [not found]";
3746 state.text <- pattern;
3747 active, firstof m_first
active
3749 G.postRedisplay "listview qsearch add";
3750 set1 active first pattern;
3752 | 0xff1b -> (* escape *)
3754 if emptystr m_qsearch
3756 G.postRedisplay "list view escape";
3759 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3761 | None
-> m_prev_uioh
3766 G.postRedisplay "list view kill qsearch";
3767 source#setqsearch
"";
3768 coe {< m_qsearch
= "" >}
3771 | 0xff0d | 0xff8d -> (* (kp) enter *)
3773 let self = {< m_qsearch
= "" >} in
3774 source#setqsearch
"";
3776 G.postRedisplay "listview enter";
3777 if m_active
>= 0 && m_active
< source#getitemcount
3779 source#exit
(coe self) false m_active m_first m_pan
"";
3782 source#exit
(coe self) true m_active m_first m_pan
"";
3785 begin match opt with
3786 | None
-> m_prev_uioh
3790 | 0xff9f | 0xffff -> (* (kp) delete *)
3793 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3794 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3795 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3796 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3798 | 0xff53 | 0xff98 -> (* (kp) right *)
3800 G.postRedisplay "listview right";
3801 coe {< m_pan
= m_pan
- 1 >}
3803 | 0xff51 | 0xff96 -> (* (kp) left *)
3805 G.postRedisplay "listview left";
3806 coe {< m_pan
= m_pan
+ 1 >}
3808 | 0xff50 | 0xff95 -> (* (kp) home *)
3809 let active = find 0 1 in
3810 G.postRedisplay "listview home";
3813 | 0xff57 | 0xff9c -> (* (kp) end *)
3814 let first = max
0 (itemcount - fstate.maxrows
) in
3815 let active = find (itemcount - 1) ~
-1 in
3816 G.postRedisplay "listview end";
3819 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3823 dolog
"listview unknown key %#x" key; coe self
3825 method key key mask
=
3826 match state.mode
with
3827 | Textentry te
-> textentrykeyboard key mask te
; coe self
3828 | _ -> self#key1
key mask
3830 method button button down
x y _ =
3833 | 1 when x > state.winw
- conf.scrollbw
->
3834 G.postRedisplay "listview scroll";
3837 let _, position, sh = self#
scrollph in
3838 if y > truncate
position && y < truncate
(position +. sh)
3840 state.mstate
<- Mscrolly
;
3844 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3845 let first = truncate
(s *. float source#getitemcount
) in
3846 let first = min source#getitemcount
first in
3847 Some
(coe {< m_first
= first; m_active
= first >})
3849 state.mstate
<- Mnone
;
3852 | 1 when not down
->
3853 begin match self#elemunder
y with
3855 G.postRedisplay "listview click";
3857 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3861 | n when (n == 4 || n == 5) && not down
->
3862 let len = source#getitemcount
in
3864 if n = 5 && m_first
+ fstate.maxrows
>= len
3868 let first = m_first
+ (if n == 4 then -1 else 1) in
3869 bound first 0 (len - 1)
3871 G.postRedisplay "listview wheel";
3872 Some
(coe {< m_first
= first >})
3873 | n when (n = 6 || n = 7) && not down
->
3874 let inc = if n = 7 then -1 else 1 in
3875 G.postRedisplay "listview hwheel";
3876 Some
(coe {< m_pan
= m_pan
+ inc >})
3881 | None
-> m_prev_uioh
3884 method multiclick
_ x y = self#button
1 true x y
3887 match state.mstate
with
3889 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3890 let first = truncate
(s *. float source#getitemcount
) in
3891 let first = min source#getitemcount
first in
3892 G.postRedisplay "listview motion";
3893 coe {< m_first
= first; m_active
= first >}
3896 method pmotion
x y =
3897 if x < state.winw
- conf.scrollbw
3900 match self#elemunder
y with
3901 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3902 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3906 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3911 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3915 method infochanged
_ = ()
3917 method scrollpw
= (0, 0.0, 0.0)
3919 let nfs = fstate.fontsize
+ 1 in
3920 let y = m_first
* nfs in
3921 let itemcount = source#getitemcount
in
3922 let maxi = max
0 (itemcount - fstate.maxrows
) in
3923 let maxy = maxi * nfs in
3924 let p, h = scrollph y maxy in
3927 method modehash
= modehash
3928 method eformsgs
= false
3931 class outlinelistview ~source
=
3932 let settext autonarrow
s =
3934 then state.text <- "[" ^
s ^
"]"
3935 else state.text <- s
3939 ~source
:(source
:> lvsource
)
3941 ~modehash
:(findkeyhash conf "outline")
3944 val m_autonarrow
= false
3946 method key key mask
=
3948 if emptystr
state.text
3950 else fstate.maxrows - 2
3952 let calcfirst first active =
3955 let rows = active - first in
3956 if rows > maxrows then active - maxrows else first
3960 let active = m_active
+ incr in
3961 let active = bound active 0 (source#getitemcount
- 1) in
3962 let first = calcfirst m_first
active in
3963 G.postRedisplay "outline navigate";
3964 coe {< m_active
= active; m_first
= first >}
3966 let navscroll first =
3968 let dist = m_active
- first in
3974 else first + maxrows
3977 G.postRedisplay "outline navscroll";
3978 coe {< m_first
= first; m_active
= active >}
3980 let ctrl = Wsi.withctrl mask
in
3982 | 97 when ctrl -> (* ctrl-a *)
3984 then source#denarrow
3985 else source#narrow m_qsearch
;
3986 settext (not m_autonarrow
) m_qsearch
;
3987 G.postRedisplay "toggle auto narrowing";
3988 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3990 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3992 G.postRedisplay "toggle auto narrowing";
3993 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3995 | 110 when ctrl -> (* ctrl-n *)
3996 source#narrow m_qsearch
;
3998 then source#add_narrow_pattern m_qsearch
;
3999 G.postRedisplay "outline ctrl-n";
4000 coe {< m_first
= 0; m_active
= 0 >}
4002 | 83 when ctrl -> (* ctrl-S *)
4003 let active = source#calcactive
(getanchor ()) in
4004 let first = firstof m_first
active in
4005 G.postRedisplay "outline ctrl-s";
4006 coe {< m_first
= first; m_active
= active >}
4008 | 117 when ctrl -> (* ctrl-u *)
4009 source#del_narrow_pattern
;
4010 let pattern = source#renarrow
in
4011 G.postRedisplay "outline ctrl-u";
4013 if emptystr
pattern then "" else "Narrowed to " ^
pattern
4015 settext m_autonarrow
text;
4016 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4018 | 108 when ctrl -> (* ctrl-l *)
4019 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
4020 G.postRedisplay "outline ctrl-l";
4021 coe {< m_first
= first >}
4023 | 0xff1b -> (* escape *)
4024 let o = super#
key key mask
in
4027 if nonemptystr m_qsearch
4029 source#add_narrow_pattern m_qsearch
;
4035 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
4036 if nonemptystr m_qsearch
4037 then source#add_narrow_pattern m_qsearch
;
4040 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
4041 let pattern = m_qsearch ^ toutf8
key in
4042 G.postRedisplay "outlinelistview autonarrow add";
4043 source#narrow
pattern;
4044 settext true pattern;
4045 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4047 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4048 if emptystr m_qsearch
4051 let pattern = withoutlastutf8 m_qsearch
in
4052 G.postRedisplay "outlinelistview autonarrow backspace";
4053 ignore
(source#renarrow
);
4054 source#narrow
pattern;
4055 settext true pattern;
4056 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4058 | 0xff9f | 0xffff -> (* (kp) delete *)
4059 source#remove m_active
;
4060 G.postRedisplay "outline delete";
4061 let active = max
0 (m_active
-1) in
4062 coe {< m_first
= firstof m_first
active;
4063 m_active
= active >}
4065 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4066 navscroll (max
0 (m_first
- 1))
4068 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4069 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4071 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4072 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4073 | 0xff55 | 0xff9a -> (* (kp) prior *)
4074 navigate ~
-(fstate.maxrows)
4075 | 0xff56 | 0xff9b -> (* (kp) next *)
4076 navigate fstate.maxrows
4078 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4082 G.postRedisplay "outline ctrl right";
4083 {< m_pan
= m_pan
+ 1 >}
4085 else self#updownlevel
1
4089 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4093 G.postRedisplay "outline ctrl left";
4094 {< m_pan
= m_pan
- 1 >}
4096 else self#updownlevel ~
-1
4100 | 0xff50 | 0xff95 -> (* (kp) home *)
4101 G.postRedisplay "outline home";
4102 coe {< m_first
= 0; m_active
= 0 >}
4104 | 0xff57 | 0xff9c -> (* (kp) end *)
4105 let active = source#getitemcount
- 1 in
4106 let first = max
0 (active - fstate.maxrows) in
4107 G.postRedisplay "outline end";
4108 coe {< m_active
= active; m_first
= first >}
4110 | _ -> super#
key key mask
4113 let gotounder under =
4114 let getpath filename
=
4116 if nonemptystr filename
4118 if Filename.is_relative filename
4120 let dir = Filename.dirname
state.path in
4122 if Filename.is_implicit
dir
4123 then Filename.concat
(Sys.getcwd
()) dir
4126 Filename.concat
dir filename
4130 if Sys.file_exists
path
4135 | Ulinkgoto
(pageno, top) ->
4139 gotopage1 pageno top;
4145 | Uremote
(filename
, pageno) ->
4146 let path = getpath filename
in
4151 let command = Printf.sprintf
"%s -page %d %S" !selfexec pageno path in
4152 try popen command []
4154 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
4157 let anchor = getanchor () in
4158 let ranchor = state.path, state.password
, anchor, state.origin
in
4160 state.anchor <- (pageno, 0.0, 0.0);
4161 state.ranchors
<- ranchor :: state.ranchors
;
4164 else showtext '
!'
("Could not find " ^ filename
)
4166 | Uremotedest
(filename
, destname
) ->
4167 let path = getpath filename
in
4172 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
4173 try popen command []
4176 "failed to execute `%s': %s\n" command (exntos exn
);
4179 let anchor = getanchor () in
4180 let ranchor = state.path, state.password
, anchor, state.origin
in
4182 state.nameddest
<- destname
;
4183 state.ranchors
<- ranchor :: state.ranchors
;
4186 else showtext '
!'
("Could not find " ^ filename
)
4188 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4191 let gotooutline (_, _, kind
) =
4195 let (pageno, y, _) = anchor in
4197 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4200 | Ouri
uri -> gotounder (Ulinkuri
uri)
4201 | Olaunch cmd
-> gotounder (Ulaunch cmd
)
4202 | Oremote remote
-> gotounder (Uremote remote
)
4203 | Oremotedest remotedest
-> gotounder (Uremotedest remotedest
)
4206 let outlinesource usebookmarks
=
4209 inherit lvsourcebase
4210 val mutable m_items
= empty
4211 val mutable m_orig_items
= empty
4212 val mutable m_narrow_patterns
= []
4213 val mutable m_hadremovals
= false
4215 method getitemcount
=
4216 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4219 if n == Array.length m_items
&& m_hadremovals
4221 ("[Confirm removal]", 0)
4223 let s, n, _ = m_items
.(n) in
4226 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4227 ignore
(uioh
, first, qsearch);
4228 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4230 if m_narrow_patterns
= []
4236 if not
confrimremoval
4238 gotooutline m_items
.(active);
4242 state.bookmarks
<- Array.to_list m_items
;
4243 m_orig_items
<- m_items
;
4246 else m_items
<- items;
4250 method hasaction
_ = true
4253 if Array.length m_items
!= Array.length m_orig_items
4256 match m_narrow_patterns
with
4258 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
4260 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4263 method narrow
pattern =
4264 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4268 let rec loop accu n =
4270 then m_items
<- Array.of_list
accu
4272 let (s, _, _) as o = m_items
.(n) in
4274 if (try ignore
(Str.search_forward
re s 0); true
4275 with Not_found
-> false)
4281 loop [] (Array.length m_items
- 1)
4286 then Array.of_list
state.bookmarks
4289 m_items
<- m_orig_items
4294 if m >= 0 && m < Array.length m_items
4296 m_hadremovals
<- true;
4297 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4298 let n = if n >= m then n+1 else n in
4303 method add_narrow_pattern
pattern =
4304 m_narrow_patterns
<- pattern :: m_narrow_patterns
4306 method del_narrow_pattern
=
4307 match m_narrow_patterns
with
4308 | _ :: rest
-> m_narrow_patterns
<- rest
4313 match m_narrow_patterns
with
4314 | pattern :: [] -> self#narrow
pattern; pattern
4316 List.fold_left
(fun accu pattern ->
4317 self#narrow
pattern;
4318 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
4320 method calcactive
anchor =
4321 let rely = getanchory anchor in
4322 let rec loop n best bestd
=
4323 if n = Array.length m_items
4326 let _, _, kind
= m_items
.(n) in
4329 let orely = getanchory anchor in
4330 let d = abs
(orely - rely) in
4333 else loop (n+1) best bestd
4334 | Onone
| Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
4335 loop (n+1) best bestd
4339 method reset
anchor items =
4340 m_hadremovals
<- false;
4341 if m_orig_items
== empty
4343 m_orig_items
<- items;
4344 if m_narrow_patterns
== []
4345 then m_items
<- items;
4347 let active = self#calcactive
anchor in
4349 m_first
<- firstof m_first
active
4353 let enterselector usebookmarks
=
4354 let source = outlinesource usebookmarks
in
4358 then Array.of_list
state.bookmarks
4361 if Array.length
outlines = 0
4363 showtext ' ' errmsg
;
4366 state.text <- source#greetmsg
;
4367 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4368 let anchor = getanchor () in
4369 source#reset
anchor outlines;
4370 state.uioh
<- coe (new outlinelistview ~
source);
4371 G.postRedisplay "enter selector";
4375 let enteroutlinemode =
4376 let f = enterselector false in
4377 fun ()-> f "Document has no outline";
4380 let enterbookmarkmode =
4381 let f = enterselector true in
4382 fun () -> f "Document has no bookmarks (yet)";
4385 let color_of_string s =
4386 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4387 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4391 let color_to_string (r, g, b) =
4392 let r = truncate
(r *. 256.0)
4393 and g = truncate
(g *. 256.0)
4394 and b = truncate
(b *. 256.0) in
4395 Printf.sprintf
"%d/%d/%d" r g b
4398 let irect_of_string s =
4399 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4402 let irect_to_string (x0,y0,x1,y1) =
4403 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4406 let makecheckers () =
4407 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4409 converted by Issac Trotts. July 25, 2002 *)
4410 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4411 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4412 let id = GlTex.gen_texture
() in
4413 GlTex.bind_texture `texture_2d
id;
4414 GlPix.store
(`unpack_alignment
1);
4415 GlTex.image2d
image;
4416 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4417 [ `mag_filter `nearest
; `min_filter `nearest
];
4421 let setcheckers enabled
=
4422 match state.texid
with
4424 if enabled
then state.texid
<- Some
(makecheckers ())
4429 GlTex.delete_texture texid
;
4430 state.texid
<- None
;
4434 let int_of_string_with_suffix s =
4435 let l = String.length
s in
4439 let suffix = Char.lowercase
s.[l-1] in
4441 | 'k'
-> String.sub
s 0 (l-1), 10
4442 | '
m'
-> String.sub
s 0 (l-1), 20
4443 | '
g'
-> String.sub
s 0 (l-1), 30
4447 let n = int_of_string
s1 in
4448 let m = n lsl shift
in
4450 then raise
(Failure
"value too large")
4454 let string_with_suffix_of_int n =
4458 let units = [(30, "G"); (20, "M"); (10, "K")] in
4461 let h = n mod 1000 in
4464 then string_of_int
h ^
s
4466 let s = Printf.sprintf
"_%03d%s" h s in
4472 let rec find = function
4474 | (shift
, suffix) :: rest
->
4475 if (n land ((1 lsl shift
) - 1)) = 0
4476 then prettyint (n lsr shift
) ^
suffix
4482 let defghyllscroll = (40, 8, 32);;
4483 let fastghyllscroll = (5,1,2);;
4484 let neatghyllscroll = (10,1,9);;
4485 let ghyllscroll_of_string s =
4487 | "default" -> Some
defghyllscroll
4488 | "fast" -> Some
(5,1,2)
4489 | "neat" -> Some
(10,1,9)
4490 | "" | "none" -> None
4492 let (n,a,b) as nab
=
4493 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4494 if n <= a || n <= b || a >= b
4495 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4500 let ghyllscroll_to_string ((n, a, b) as nab
) =
4501 (**) if nab
= defghyllscroll then "default"
4502 else if nab
= fastghyllscroll then "fast"
4503 else if nab
= neatghyllscroll then "neat"
4504 else Printf.sprintf
"%d,%d,%d" n a b;
4507 let describe_location () =
4508 let fn = page_of_y state.y in
4509 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4510 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4514 else (100. *. (float state.y /. float maxy))
4518 Printf.sprintf
"page %d of %d [%.2f%%]"
4519 (fn+1) state.pagecount
percent
4522 "pages %d-%d of %d [%.2f%%]"
4523 (fn+1) (ln+1) state.pagecount
percent
4526 let setpresentationmode v
=
4527 let n = page_of_y state.y in
4528 state.anchor <- (n, 0.0, 1.0);
4529 conf.presentation
<- v
;
4530 if conf.fitmodel
= FitPage
4531 then reqlayout conf.angle
conf.fitmodel
;
4536 let btos b = if b then "\xe2\x88\x9a" else "" in
4537 let showextended = ref false in
4538 let leave mode
= function
4539 | Confirm
-> state.mode
<- mode
4540 | Cancel
-> state.mode
<- mode
in
4543 val mutable m_first_time
= true
4544 val mutable m_l
= []
4545 val mutable m_a
= [||]
4546 val mutable m_prev_uioh
= nouioh
4547 val mutable m_prev_mode
= View
4549 inherit lvsourcebase
4551 method reset prev_mode prev_uioh
=
4552 m_a
<- Array.of_list
(List.rev m_l
);
4554 m_prev_mode
<- prev_mode
;
4555 m_prev_uioh
<- prev_uioh
;
4559 if n >= Array.length m_a
4563 | _, _, _, Action
_ -> m_active
<- n
4567 m_first_time
<- false;
4570 method int name get
set =
4572 (name, `
int get
, 1, Action
(
4575 try set (int_of_string
s)
4577 state.text <- Printf.sprintf
"bad integer `%s': %s"
4581 let te = name ^
": ", "", None
, intentry, ondone, true in
4582 state.mode
<- Textentry
(te, leave m_prev_mode
);
4586 method int_with_suffix
name get
set =
4588 (name, `intws get
, 1, Action
(
4591 try set (int_of_string_with_suffix s)
4593 state.text <- Printf.sprintf
"bad integer `%s': %s"
4598 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4600 state.mode
<- Textentry
(te, leave m_prev_mode
);
4604 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4606 (name, `
bool (btos, get
), offset
, Action
(
4613 method color
name get
set =
4615 (name, `color get
, 1, Action
(
4617 let invalid = (nan
, nan
, nan
) in
4620 try color_of_string s
4622 state.text <- Printf.sprintf
"bad color `%s': %s"
4629 let te = name ^
": ", "", None
, textentry, ondone, true in
4630 state.text <- color_to_string (get
());
4631 state.mode
<- Textentry
(te, leave m_prev_mode
);
4635 method string name get
set =
4637 (name, `
string get
, 1, Action
(
4639 let ondone s = set s in
4640 let te = name ^
": ", "", None
, textentry, ondone, true in
4641 state.mode
<- Textentry
(te, leave m_prev_mode
);
4645 method colorspace
name get
set =
4647 (name, `
string get
, 1, Action
(
4651 inherit lvsourcebase
4654 m_active
<- CSTE.to_int conf.colorspace
;
4657 method getitemcount
=
4658 Array.length
CSTE.names
4661 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4662 ignore
(uioh
, first, pan
, qsearch);
4663 if not cancel
then set active;
4665 method hasaction
_ = true
4669 let modehash = findkeyhash conf "info" in
4670 coe (new listview ~
source ~trusted
:true ~
modehash)
4673 method paxmark
name get
set =
4675 (name, `
string get
, 1, Action
(
4679 inherit lvsourcebase
4682 m_active
<- MTE.to_int conf.paxmark
;
4685 method getitemcount
= Array.length
MTE.names
4686 method getitem
n = (MTE.names.(n), 0)
4687 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4688 ignore
(uioh
, first, pan
, qsearch);
4689 if not cancel
then set active;
4691 method hasaction
_ = true
4695 let modehash = findkeyhash conf "info" in
4696 coe (new listview ~
source ~trusted
:true ~
modehash)
4699 method fitmodel
name get
set =
4701 (name, `
string get
, 1, Action
(
4705 inherit lvsourcebase
4708 m_active
<- FMTE.to_int conf.fitmodel
;
4711 method getitemcount
= Array.length
FMTE.names
4712 method getitem
n = (FMTE.names.(n), 0)
4713 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4714 ignore
(uioh
, first, pan
, qsearch);
4715 if not cancel
then set active;
4717 method hasaction
_ = true
4721 let modehash = findkeyhash conf "info" in
4722 coe (new listview ~
source ~trusted
:true ~
modehash)
4725 method caption
s offset
=
4726 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4728 method caption2
s f offset
=
4729 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4731 method getitemcount
= Array.length m_a
4734 let tostr = function
4735 | `
int f -> string_of_int
(f ())
4736 | `intws
f -> string_with_suffix_of_int (f ())
4738 | `color
f -> color_to_string (f ())
4739 | `
bool (btos, f) -> btos (f ())
4742 let name, t
, offset
, _ = m_a
.(n) in
4743 ((let s = tostr t
in
4745 then Printf.sprintf
"%s\t%s" name s
4749 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4753 m_qsearch
<- qsearch;
4755 match m_a
.(active) with
4756 | _, _, _, Action
f -> f uioh
4768 method hasaction
n =
4770 | _, _, _, Action
_ -> true
4774 let rec fillsrc prevmode prevuioh
=
4775 let sep () = src#caption
"" 0 in
4776 let colorp name get
set =
4778 (fun () -> color_to_string (get
()))
4781 let c = color_of_string v in
4784 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4787 let oldmode = state.mode
in
4788 let birdseye = isbirdseye state.mode
in
4790 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4792 src#
bool "presentation mode"
4793 (fun () -> conf.presentation
)
4794 (fun v -> setpresentationmode v);
4796 src#
bool "ignore case in searches"
4797 (fun () -> conf.icase
)
4798 (fun v -> conf.icase
<- v);
4801 (fun () -> conf.preload)
4802 (fun v -> conf.preload <- v);
4804 src#
bool "highlight links"
4805 (fun () -> conf.hlinks
)
4806 (fun v -> conf.hlinks
<- v);
4808 src#
bool "under info"
4809 (fun () -> conf.underinfo
)
4810 (fun v -> conf.underinfo
<- v);
4812 src#
bool "persistent bookmarks"
4813 (fun () -> conf.savebmarks
)
4814 (fun v -> conf.savebmarks
<- v);
4816 src#fitmodel
"fit model"
4817 (fun () -> FMTE.to_string conf.fitmodel
)
4818 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4820 src#
bool "trim margins"
4821 (fun () -> conf.trimmargins
)
4822 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4824 src#
bool "persistent location"
4825 (fun () -> conf.jumpback
)
4826 (fun v -> conf.jumpback
<- v);
4829 src#
int "inter-page space"
4830 (fun () -> conf.interpagespace
)
4832 conf.interpagespace
<- n;
4833 docolumns conf.columns
;
4835 match state.layout with
4840 state.maxy <- calcheight ();
4841 let y = getpagey pageno in
4846 (fun () -> conf.pagebias
)
4847 (fun v -> conf.pagebias
<- v);
4849 src#
int "scroll step"
4850 (fun () -> conf.scrollstep
)
4851 (fun n -> conf.scrollstep
<- n);
4853 src#
int "horizontal scroll step"
4854 (fun () -> conf.hscrollstep
)
4855 (fun v -> conf.hscrollstep
<- v);
4857 src#
int "auto scroll step"
4859 match state.autoscroll
with
4861 | _ -> conf.autoscrollstep
)
4863 let n = boundastep state.winh
n in
4864 if state.autoscroll
<> None
4865 then state.autoscroll
<- Some
n;
4866 conf.autoscrollstep
<- n);
4869 (fun () -> truncate
(conf.zoom *. 100.))
4870 (fun v -> setzoom ((float v) /. 100.));
4873 (fun () -> conf.angle
)
4874 (fun v -> reqlayout v conf.fitmodel
);
4876 src#
int "scroll bar width"
4877 (fun () -> conf.scrollbw
)
4880 reshape state.winw
state.winh
;
4883 src#
int "scroll handle height"
4884 (fun () -> conf.scrollh
)
4885 (fun v -> conf.scrollh
<- v;);
4887 src#
int "thumbnail width"
4888 (fun () -> conf.thumbw
)
4890 conf.thumbw
<- min
4096 v;
4893 leavebirdseye beye
false;
4898 let mode = state.mode in
4899 src#
string "columns"
4901 match conf.columns
with
4903 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4904 | Csplit
(count
, _) -> "-" ^ string_of_int count
4907 let n, a, b = multicolumns_of_string v in
4908 setcolumns mode n a b);
4911 src#caption
"Pixmap cache" 0;
4912 src#int_with_suffix
"size (advisory)"
4913 (fun () -> conf.memlimit
)
4914 (fun v -> conf.memlimit
<- v);
4917 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4918 (string_with_suffix_of_int state.memused
)
4919 (Hashtbl.length
state.tilemap
)) 1;
4922 src#caption
"Layout" 0;
4923 src#caption2
"Dimension"
4925 Printf.sprintf
"%dx%d (virtual %dx%d)"
4926 state.winw
state.winh
4931 src#caption2
"Position" (fun () ->
4932 Printf.sprintf
"%dx%d" state.x state.y
4935 src#caption2
"Position" (fun () -> describe_location ()) 1
4939 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4940 "Save these parameters as global defaults at exit"
4941 (fun () -> conf.bedefault
)
4942 (fun v -> conf.bedefault
<- v)
4946 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4947 src#
bool ~offset
:0 ~
btos "Extended parameters"
4948 (fun () -> !showextended)
4949 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4953 (fun () -> conf.checkers
)
4954 (fun v -> conf.checkers
<- v; setcheckers v);
4955 src#
bool "update cursor"
4956 (fun () -> conf.updatecurs
)
4957 (fun v -> conf.updatecurs
<- v);
4959 (fun () -> conf.verbose
)
4960 (fun v -> conf.verbose
<- v);
4961 src#
bool "invert colors"
4962 (fun () -> conf.invert
)
4963 (fun v -> conf.invert
<- v);
4965 (fun () -> conf.maxhfit
)
4966 (fun v -> conf.maxhfit
<- v);
4967 src#
bool "redirect stderr"
4968 (fun () -> conf.redirectstderr)
4969 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4971 (fun () -> conf.pax
!= None
)
4974 then conf.pax
<- Some
(ref (now (), 0, 0))
4975 else conf.pax
<- None
);
4976 src#
string "uri launcher"
4977 (fun () -> conf.urilauncher
)
4978 (fun v -> conf.urilauncher
<- v);
4979 src#
string "path launcher"
4980 (fun () -> conf.pathlauncher
)
4981 (fun v -> conf.pathlauncher
<- v);
4982 src#
string "tile size"
4983 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4986 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4987 conf.tilew
<- max
64 w;
4988 conf.tileh
<- max
64 h;
4991 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4994 src#
int "texture count"
4995 (fun () -> conf.texcount
)
4998 then conf.texcount
<- v
4999 else showtext '
!'
" Failed to set texture count please retry later"
5001 src#
int "slice height"
5002 (fun () -> conf.sliceheight
)
5004 conf.sliceheight
<- v;
5005 wcmd "sliceh %d" conf.sliceheight
;
5007 src#
int "anti-aliasing level"
5008 (fun () -> conf.aalevel
)
5010 conf.aalevel
<- bound v 0 8;
5011 state.anchor <- getanchor ();
5012 opendoc state.path state.password
;
5014 src#
string "page scroll scaling factor"
5015 (fun () -> string_of_float
conf.pgscale)
5018 let s = float_of_string
v in
5021 state.text <- Printf.sprintf
5022 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
5025 src#
int "ui font size"
5026 (fun () -> fstate.fontsize
)
5027 (fun v -> setfontsize (bound v 5 100));
5028 src#
int "hint font size"
5029 (fun () -> conf.hfsize
)
5030 (fun v -> conf.hfsize
<- bound v 5 100);
5031 colorp "background color"
5032 (fun () -> conf.bgcolor
)
5033 (fun v -> conf.bgcolor
<- v);
5034 src#
bool "crop hack"
5035 (fun () -> conf.crophack
)
5036 (fun v -> conf.crophack
<- v);
5037 src#
string "trim fuzz"
5038 (fun () -> irect_to_string conf.trimfuzz
)
5041 conf.trimfuzz
<- irect_of_string v;
5043 then settrim true conf.trimfuzz
;
5045 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
5047 src#
string "throttle"
5049 match conf.maxwait
with
5050 | None
-> "show place holder if page is not ready"
5053 then "wait for page to fully render"
5055 "wait " ^ string_of_float
time
5056 ^
" seconds before showing placeholder"
5060 let f = float_of_string
v in
5062 then conf.maxwait
<- None
5063 else conf.maxwait
<- Some
f
5065 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
5067 src#
string "ghyll scroll"
5069 match conf.ghyllscroll
with
5071 | Some nab
-> ghyllscroll_to_string nab
5074 try conf.ghyllscroll
<- ghyllscroll_of_string v
5076 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
5078 src#
string "selection command"
5079 (fun () -> conf.selcmd
)
5080 (fun v -> conf.selcmd
<- v);
5081 src#
string "synctex command"
5082 (fun () -> conf.stcmd
)
5083 (fun v -> conf.stcmd
<- v);
5084 src#
string "pax command"
5085 (fun () -> conf.paxcmd
)
5086 (fun v -> conf.paxcmd
<- v);
5087 src#colorspace
"color space"
5088 (fun () -> CSTE.to_string conf.colorspace
)
5090 conf.colorspace
<- CSTE.of_int v;
5094 src#paxmark
"pax mark method"
5095 (fun () -> MTE.to_string conf.paxmark
)
5096 (fun v -> conf.paxmark
<- MTE.of_int v);
5100 (fun () -> conf.usepbo
)
5101 (fun v -> conf.usepbo
<- v);
5102 src#
bool "mouse wheel scrolls pages"
5103 (fun () -> conf.wheelbypage
)
5104 (fun v -> conf.wheelbypage
<- v);
5105 src#
bool "open remote links in a new instance"
5106 (fun () -> conf.riani
)
5107 (fun v -> conf.riani
<- v);
5111 src#caption
"Document" 0;
5112 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
5113 src#caption2
"Pages"
5114 (fun () -> string_of_int
state.pagecount
) 1;
5115 src#caption2
"Dimensions"
5116 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5120 src#caption
"Trimmed margins" 0;
5121 src#caption2
"Dimensions"
5122 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5126 src#caption
"OpenGL" 0;
5127 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
5128 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
5131 src#caption
"Location" 0;
5132 if nonemptystr
state.origin
5133 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
5134 src#caption
("Path\t" ^ mbtoutf8
state.path) 1;
5136 src#reset prevmode prevuioh
;
5140 let prevmode = state.mode
5141 and prevuioh
= state.uioh in
5142 fillsrc prevmode prevuioh
;
5143 let source = (src :> lvsource
) in
5144 let modehash = findkeyhash conf "info" in
5145 state.uioh <- coe (object (self)
5146 inherit listview ~
source ~trusted
:true ~
modehash as super
5147 val mutable m_prevmemused
= 0
5148 method infochanged
= function
5150 if m_prevmemused
!= state.memused
5152 m_prevmemused
<- state.memused
;
5153 G.postRedisplay "memusedchanged";
5155 | Pdim
-> G.postRedisplay "pdimchanged"
5156 | Docinfo
-> fillsrc prevmode prevuioh
5158 method key key mask
=
5159 if not
(Wsi.withctrl mask
)
5162 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5163 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5164 | _ -> super#
key key mask
5165 else super#
key key mask
5167 G.postRedisplay "info";
5173 inherit lvsourcebase
5174 method getitemcount
= Array.length
state.help
5176 let s, l, _ = state.help
.(n) in
5179 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5183 m_qsearch
<- qsearch;
5184 match state.help
.(active) with
5185 | _, _, Action
f -> Some
(f uioh)
5195 method hasaction
n =
5196 match state.help
.(n) with
5197 | _, _, Action
_ -> true
5204 let modehash = findkeyhash conf "help" in
5205 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5206 G.postRedisplay "help";
5211 let re = Str.regexp
"[\r\n]" in
5213 inherit lvsourcebase
5214 val mutable m_items
= [||]
5216 method getitemcount
= 1 + Array.length m_items
5221 else m_items
.(n-1), 0
5223 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5228 then Buffer.clear
state.errmsgs
;
5229 m_qsearch
<- qsearch;
5236 method hasaction
n =
5240 state.newerrmsgs
<- false;
5241 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5242 m_items
<- Array.of_list
l
5250 let source = (msgsource :> lvsource
) in
5251 let modehash = findkeyhash conf "listview" in
5252 state.uioh <- coe (object
5253 inherit listview ~
source ~trusted
:false ~
modehash as super
5256 then msgsource#reset
;
5259 G.postRedisplay "msgs";
5262 let quickbookmark ?title
() =
5263 match state.layout with
5269 let sec = Unix.gettimeofday
() in
5270 let tm = Unix.localtime
sec in
5271 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5275 (tm.Unix.tm_year
+ 1900)
5278 | Some
title -> title
5280 state.bookmarks
<- (title, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5283 let setautoscrollspeed step goingdown
=
5284 let incr = max
1 ((abs step
) / 2) in
5285 let incr = if goingdown
then incr else -incr in
5286 let astep = boundastep state.winh
(step
+ incr) in
5287 state.autoscroll
<- Some
astep;
5291 match conf.columns
with
5293 | _ -> state.x != 0 || conf.zoom > 1.0
5296 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5298 let existsinrow pageno (columns
, coverA
, coverB
) p =
5299 let last = ((pageno - coverA
) mod columns
) + columns
in
5300 let rec any = function
5303 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5307 then (if l.pageno = last then false else any rest
)
5315 match state.layout with
5317 let pageno = page_of_y state.y in
5318 gotoghyll (getpagey (pageno+1))
5320 match conf.columns
with
5322 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5324 let y = clamp (pgscale state.winh
) in
5327 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5328 gotoghyll (getpagey pageno)
5329 | Cmulti
((c, _, _) as cl, _) ->
5330 if conf.presentation
5331 && (existsinrow l.pageno cl
5332 (fun l -> l.pageh
> l.pagey + l.pagevh))
5334 let y = clamp (pgscale state.winh
) in
5337 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5338 gotoghyll (getpagey pageno)
5340 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5342 let pagey, pageh
= getpageyh l.pageno in
5343 let pagey = pagey + pageh
* l.pagecol
in
5344 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5345 gotoghyll (pagey + pageh
+ ips)
5349 match state.layout with
5351 let pageno = page_of_y state.y in
5352 gotoghyll (getpagey (pageno-1))
5354 match conf.columns
with
5356 if conf.presentation
&& l.pagey != 0
5358 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5360 let pageno = max
0 (l.pageno-1) in
5361 gotoghyll (getpagey pageno)
5362 | Cmulti
((c, _, coverB
) as cl, _) ->
5363 if conf.presentation
&&
5364 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5366 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5369 if l.pageno = state.pagecount
- coverB
5373 let pageno = max
0 (l.pageno-decr) in
5374 gotoghyll (getpagey pageno)
5382 let pageno = max
0 (l.pageno-1) in
5383 let pagey, pageh
= getpageyh pageno in
5386 let pagey, pageh
= getpageyh l.pageno in
5387 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5392 let viewkeyboard key mask
=
5394 let mode = state.mode in
5395 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5398 G.postRedisplay "view:enttext"
5400 let ctrl = Wsi.withctrl mask
in
5402 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5408 | 0xff63 -> (* insert *)
5409 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5411 state.mode <- LinkNav
(Ltgendir
0);
5414 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5416 | 0xff1b | 113 -> (* escape / q *)
5417 begin match state.mstate
with
5419 state.mstate
<- Mnone
;
5420 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5421 G.postRedisplay "kill zoom rect";
5423 begin match state.mode with
5426 G.postRedisplay "esc leave linknav"
5428 match state.ranchors
with
5430 | (path, password
, anchor, origin
) :: rest
->
5431 state.ranchors
<- rest
;
5432 state.anchor <- anchor;
5433 state.origin
<- origin
;
5434 state.nameddest
<- "";
5435 opendoc path password
5439 | 0xff08 -> (* backspace *)
5440 gotoghyll (getnav ~
-1)
5448 Hashtbl.iter
(fun _ opaque
-> clearmark opaque
) state.pagemap
;
5449 G.postRedisplay "dehighlight";
5451 | 47 | 63 -> (* / ? *)
5452 let ondone isforw
s =
5453 cbput state.hists
.pat
s;
5454 state.searchpattern
<- s;
5457 let s = String.create
1 in
5458 s.[0] <- Char.chr
key;
5459 enttext (s, "", Some
(onhist state.hists
.pat
),
5460 textentry, ondone (key = 47), true)
5462 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5463 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5464 setzoom (conf.zoom +. incr)
5466 | 43 | 0xffab -> (* + *)
5469 try int_of_string
s with exc
->
5470 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5476 state.text <- "page bias is now " ^ string_of_int
n;
5479 enttext ("page bias: ", "", None
, intentry, ondone, true)
5481 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5482 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5483 setzoom (max
0.01 (conf.zoom -. decr))
5485 | 45 | 0xffad -> (* - *)
5486 let ondone msg
= state.text <- msg
in
5488 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5489 optentry state.mode, ondone, true
5492 | 48 when ctrl -> (* ctrl-0 *)
5500 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5502 match conf.columns
with
5503 | Csingle
_ | Cmulti
_ -> 1
5504 | Csplit
(n, _) -> n
5506 let h = state.winh
-
5507 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5509 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5510 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5513 | 51 when ctrl -> (* ctrl-3 *)
5515 match conf.fitmodel
with
5516 | FitWidth
-> FitProportional
5517 | FitProportional
-> FitPage
5518 | FitPage
-> FitWidth
5520 state.text <- "fit model: " ^
FMTE.to_string fm;
5521 reqlayout conf.angle
fm
5523 | 0xffc6 -> (* f9 *)
5526 | 57 when ctrl -> (* ctrl-9 *)
5529 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5530 when not
ctrl -> (* 0..9 *)
5533 try int_of_string
s with exc
->
5534 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5540 cbput state.hists
.pag
(string_of_int
n);
5541 gotopage1 (n + conf.pagebias
- 1) 0;
5544 let pageentry text key =
5545 match Char.unsafe_chr
key with
5546 | '
g'
-> TEdone
text
5547 | _ -> intentry text key
5549 let text = "x" in text.[0] <- Char.chr
key;
5550 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5553 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5554 reshape state.winw
state.winh
;
5557 state.bzoom
<- not
state.bzoom
;
5559 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5562 conf.hlinks
<- not
conf.hlinks
;
5563 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5564 G.postRedisplay "toggle highlightlinks";
5567 state.glinks
<- true;
5568 let mode = state.mode in
5569 state.mode <- Textentry
(
5570 (":", "", None
, linknentry, linkndone gotounder, false),
5572 state.glinks
<- false;
5576 G.postRedisplay "view:linkent(F)"
5579 state.glinks
<- true;
5580 let mode = state.mode in
5581 state.mode <- Textentry
(
5583 ":", "", None
, linknentry, linkndone (fun under ->
5584 selstring (undertext under);
5588 state.glinks
<- false;
5592 G.postRedisplay "view:linkent"
5595 begin match state.autoscroll
with
5597 conf.autoscrollstep
<- step
;
5598 state.autoscroll
<- None
5600 if conf.autoscrollstep
= 0
5601 then state.autoscroll
<- Some
1
5602 else state.autoscroll
<- Some
conf.autoscrollstep
5605 | 112 when ctrl -> (* ctrl-p *)
5609 setpresentationmode (not
conf.presentation
);
5610 showtext ' '
("presentation mode " ^
5611 if conf.presentation
then "on" else "off");
5614 if List.mem
Wsi.Fullscreen
state.winstate
5615 then Wsi.reshape conf.cwinw
conf.cwinh
5616 else Wsi.fullscreen
()
5618 | 112 | 78 -> (* p|N *)
5619 search state.searchpattern
false
5621 | 110 | 0xffc0 -> (* n|F3 *)
5622 search state.searchpattern
true
5625 begin match state.layout with
5628 gotoghyll (getpagey l.pageno)
5634 | 0xff9f | 0xffff -> (* delete *)
5638 showtext ' '
(describe_location ());
5641 begin match state.layout with
5644 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5649 enterbookmarkmode ()
5651 | 104 | 0xffbe -> (* h|F1 *)
5657 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5662 match state.layout with
5667 (s, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5670 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5674 showtext ' '
"Quick bookmark added";
5677 begin match state.layout with
5679 let rect = getpdimrect
l.pagedimno
in
5683 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5684 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5686 (truncate
(rect.(1) -. rect.(0)),
5687 truncate
(rect.(3) -. rect.(0)))
5689 let w = truncate
((float w)*.conf.zoom)
5690 and h = truncate
((float h)*.conf.zoom) in
5693 state.anchor <- getanchor ();
5694 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5696 G.postRedisplay "z";
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 let mode = state.mode in
5855 let onleave = function
5856 | Cancel
-> state.mode <- mode
5859 match getopaque l.pageno with
5860 | Some opaque
-> pipesel opaque
!cmd
5861 | None
-> ()) state.layout;
5864 let ondone s = cmd := s in
5866 "| ", !cmd, Some
(onhist state.hists
.sel
), textentry, ondone, true
5868 G.postRedisplay "|";
5869 state.mode <- Textentry
(te, onleave);
5872 vlog "huh? %s" (Wsi.keyname
key)
5875 let linknavkeyboard key mask
linknav =
5876 let getpage pageno =
5877 let rec loop = function
5879 | l :: _ when l.pageno = pageno -> Some
l
5880 | _ :: rest
-> loop rest
5881 in loop state.layout
5883 let doexact (pageno, n) =
5884 match getopaque pageno, getpage pageno with
5885 | Some opaque
, Some
l ->
5886 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5888 let under = getlink opaque
n in
5889 G.postRedisplay "link gotounder";
5895 | 0xff50 -> (* home *)
5896 Some
(findlink opaque LDfirst
), -1
5898 | 0xff57 -> (* end *)
5899 Some
(findlink opaque LDlast
), 1
5901 | 0xff51 -> (* left *)
5902 Some
(findlink opaque
(LDleft
n)), -1
5904 | 0xff53 -> (* right *)
5905 Some
(findlink opaque
(LDright
n)), 1
5907 | 0xff52 -> (* up *)
5908 Some
(findlink opaque
(LDup
n)), -1
5910 | 0xff54 -> (* down *)
5911 Some
(findlink opaque
(LDdown
n)), 1
5916 begin match findpwl
l.pageno dir with
5920 state.mode <- LinkNav
(Ltgendir
dir);
5921 let y, h = getpageyh pageno in
5924 then y + h - state.winh
5929 begin match getopaque pageno, getpage pageno with
5930 | Some opaque
, Some
_ ->
5932 let ld = if dir > 0 then LDfirst
else LDlast
in
5935 begin match link with
5937 showlinktype (getlink opaque
m);
5938 state.mode <- LinkNav
(Ltexact
(pageno, m));
5939 G.postRedisplay "linknav jpage";
5946 begin match opt with
5947 | Some Lnotfound
-> pwl l dir;
5948 | Some
(Lfound
m) ->
5952 let _, y0, _, y1 = getlinkrect opaque
m in
5954 then gotopage1 l.pageno y0
5956 let d = fstate.fontsize
+ 1 in
5957 if y1 - l.pagey > l.pagevh - d
5958 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5959 else G.postRedisplay "linknav";
5961 showlinktype (getlink opaque
m);
5962 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5965 | None
-> viewkeyboard key mask
5967 | _ -> viewkeyboard key mask
5972 G.postRedisplay "leave linknav"
5976 | Ltgendir
_ -> viewkeyboard key mask
5977 | Ltexact exact
-> doexact exact
5980 let keyboard key mask
=
5981 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5982 then wcmd "interrupt"
5983 else state.uioh <- state.uioh#
key key mask
5986 let birdseyekeyboard key mask
5987 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5989 match conf.columns
with
5991 | Cmulti
((c, _, _), _) -> c
5992 | Csplit
_ -> failwith
"bird's eye split mode"
5994 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5996 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5997 let y, h = getpageyh pageno in
5998 let top = (state.winh
- h) / 2 in
5999 gotoy (max
0 (y - top))
6000 | 0xff0d (* enter *)
6001 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
6002 | 0xff1b -> leavebirdseye beye
true (* escape *)
6003 | 0xff52 -> upbirdseye incr beye
(* up *)
6004 | 0xff54 -> downbirdseye incr beye
(* down *)
6005 | 0xff51 -> upbirdseye 1 beye
(* left *)
6006 | 0xff53 -> downbirdseye 1 beye
(* right *)
6008 | 0xff55 -> (* prior *)
6009 begin match state.layout with
6013 state.mode <- Birdseye
(
6014 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6016 gotopage1 l.pageno 0;
6019 let layout = layout (state.y-state.winh
) (pgh state.layout) in
6021 | [] -> gotoy (clamp (-state.winh
))
6023 state.mode <- Birdseye
(
6024 oconf
, leftx
, l.pageno, hooverpageno
, anchor
6026 gotopage1 l.pageno 0
6029 | [] -> gotoy (clamp (-state.winh
))
6032 | 0xff56 -> (* next *)
6033 begin match List.rev
state.layout with
6035 let layout = layout (state.y + (pgh state.layout)) state.winh
in
6036 begin match layout with
6038 let incr = l.pageh
- l.pagevh in
6043 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
6045 G.postRedisplay "birdseye pagedown";
6047 else gotoy (clamp (incr + conf.interpagespace
*2));
6051 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
6052 gotopage1 l.pageno 0;
6055 | [] -> gotoy (clamp state.winh
)
6058 | 0xff50 -> (* home *)
6059 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
6062 | 0xff57 -> (* end *)
6063 let pageno = state.pagecount
- 1 in
6064 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
6065 if not
(pagevisible state.layout pageno)
6068 match List.rev
state.pdims
with
6070 | (_, _, h, _) :: _ -> h
6072 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
6073 else G.postRedisplay "birdseye end";
6074 | _ -> viewkeyboard key mask
6079 match state.mode with
6080 | Textentry
_ -> scalecolor 0.4
6082 | View
-> scalecolor 1.0
6083 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6084 if l.pageno = hooverpageno
6087 if l.pageno = pageno
6095 let postdrawpage l linkindexbase
=
6096 match getopaque l.pageno with
6098 if tileready l l.pagex
l.pagey
6100 let x = l.pagedispx - l.pagex
6101 and y = l.pagedispy - l.pagey in
6103 match conf.columns
with
6104 | Csingle
_ | Cmulti
_ ->
6105 (if conf.hlinks
then 1 else 0)
6107 && not
(isbirdseye state.mode) then 2 else 0)
6111 match state.mode with
6112 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6115 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6120 let scrollindicator () =
6121 let sbw, ph
, sh = state.uioh#
scrollph in
6122 let sbh, pw, sw = state.uioh#scrollpw
in
6124 GlDraw.color (0.64, 0.64, 0.64);
6126 (float (state.winw
- sbw)) 0.
6127 (float state.winw
) (float state.winh
)
6130 0. (float (state.winh
- sbh))
6131 (float (wadjsb state.winw
- 1)) (float state.winh
)
6133 GlDraw.color (0.0, 0.0, 0.0);
6136 (float (state.winw
- sbw)) ph
6137 (float state.winw
) (ph
+. sh)
6140 pw (float (state.winh
- sbh))
6141 (pw +. sw) (float state.winh
)
6146 match state.mstate
with
6147 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6150 | Msel
((x0, y0), (x1, y1)) ->
6151 let identify opaque
l px py = Some
(opaque
, l.pageno, px, py) in
6152 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 ("", -1, 0, 0) in
6153 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 ("", -1, 0, 0) in
6154 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
6157 let showrects = function [] -> () | rects
->
6159 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6160 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6162 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6164 if l.pageno = pageno
6166 let dx = float (l.pagedispx - l.pagex
) in
6167 let dy = float (l.pagedispy - l.pagey) in
6168 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6169 Raw.sets_float
state.vraw ~pos
:0
6174 GlArray.vertex `two
state.vraw
;
6175 GlArray.draw_arrays `triangle_strip
0 4;
6184 GlClear.color (scalecolor2 conf.bgcolor
);
6185 GlClear.clear
[`
color];
6186 List.iter
drawpage state.layout;
6188 match state.mode with
6189 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6190 begin match getopaque pageno with
6192 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6199 | None
-> state.rects
6204 let rec postloop linkindexbase
= function
6206 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6207 postloop linkindexbase rest
6211 postloop 0 state.layout;
6213 begin match state.mstate
with
6214 | Mzoomrect
((x0, y0), (x1, y1)) ->
6216 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6217 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6218 filledrect (float x0) (float y0) (float x1) (float y1);
6227 let zoomrect x y x1 y1 =
6230 and y0 = min
y y1 in
6231 gotoy (state.y + y0);
6232 state.anchor <- getanchor ();
6233 let zoom = (float state.w) /. float (x1 - x0) in
6235 match conf.fitmodel
, conf.columns
with
6236 | FitPage
, Csplit
_ ->
6237 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6240 let adjw = wadjsb state.winw
in
6242 then (adjw - state.w) / 2
6245 state.x <- (state.x + margin) - x0;
6247 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6248 state.mstate
<- Mnone
;
6252 let g opaque
l px py =
6253 match rectofblock opaque
px py with
6255 let x0 = a.(0) -. 20. in
6256 let x1 = a.(1) +. 20. in
6257 let y0 = a.(2) -. 20. in
6258 let zoom = (float state.w) /. (x1 -. x0) in
6259 let pagey = getpagey l.pageno in
6260 gotoy_and_clear_text (pagey + truncate
y0);
6261 state.anchor <- getanchor ();
6262 let margin = (state.w - l.pagew
)/2 in
6263 state.x <- -truncate
x0 - margin;
6268 match conf.columns
with
6270 showtext '
!'
"block zooming does not work properly in split columns mode"
6271 | _ -> onppundermouse g x y ()
6275 let winw = wadjsb state.winw - 1 in
6276 let s = float x /. float winw in
6277 let destx = truncate
(float (state.w + winw) *. s) in
6278 state.x <- winw - destx;
6279 gotoy_and_clear_text state.y;
6280 state.mstate
<- Mscrollx
;
6284 let s = float y /. float state.winh
in
6285 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6286 gotoy_and_clear_text desty;
6287 state.mstate
<- Mscrolly
;
6290 let viewmulticlick clicks
x y mask
=
6291 let g opaque
l px py =
6299 if markunder opaque
px py mark
6303 match getopaque l.pageno with
6305 | Some opaque
-> pipesel opaque
cmd
6307 state.roam
<- (fun () -> dopipe conf.paxcmd
);
6308 if not
(Wsi.withctrl mask
) then dopipe conf.selcmd
;
6313 G.postRedisplay "viewmulticlick";
6314 onppundermouse g x y (fun () -> showtext '
!'
"Nothing to select") ();
6317 let viewmouse button down
x y mask
=
6319 | n when (n == 4 || n == 5) && not down
->
6320 if Wsi.withctrl mask
6322 match state.mstate
with
6323 | Mzoom
(oldn
, i
) ->
6331 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6333 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6335 let zoom = conf.zoom -. incr in
6337 state.mstate
<- Mzoom
(n, 0);
6339 state.mstate
<- Mzoom
(n, i
+1);
6341 else state.mstate
<- Mzoom
(n, 0)
6343 | _ -> state.mstate
<- Mzoom
(n, 0)
6346 match state.autoscroll
with
6347 | Some step
-> setautoscrollspeed step
(n=4)
6349 if conf.wheelbypage
|| conf.presentation
6358 then -conf.scrollstep
6359 else conf.scrollstep
6361 let incr = incr * 2 in
6362 let y = clamp incr in
6363 gotoy_and_clear_text y
6366 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6368 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6369 gotoy_and_clear_text state.y
6371 | 1 when Wsi.withshift mask
->
6372 state.mstate
<- Mnone
;
6375 match unproject x y with
6376 | Some
(pageno, ux
, uy
) ->
6377 let cmd = Printf.sprintf
6379 conf.stcmd
state.path pageno ux uy
6385 | 1 when Wsi.withctrl mask
->
6388 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6389 state.mstate
<- Mpan
(x, y)
6392 state.mstate
<- Mnone
6397 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6399 state.mstate
<- Mzoomrect
(p, p)
6402 match state.mstate
with
6403 | Mzoomrect
((x0, y0), _) ->
6404 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6405 then zoomrect x0 y0 x y
6407 state.mstate
<- Mnone
;
6408 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6409 G.postRedisplay "kill accidental zoom rect";
6412 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6413 state.mstate
<- Mnone
6416 | 1 when x > state.winw - vscrollw () ->
6419 let _, position, sh = state.uioh#
scrollph in
6420 if y > truncate
position && y < truncate
(position +. sh)
6421 then state.mstate
<- Mscrolly
6424 state.mstate
<- Mnone
6426 | 1 when y > state.winh
- hscrollh () ->
6429 let _, position, sw = state.uioh#scrollpw
in
6430 if x > truncate
position && x < truncate
(position +. sw)
6431 then state.mstate
<- Mscrollx
6434 state.mstate
<- Mnone
6436 | 1 when state.bzoom
-> if not down
then zoomblock x y
6439 let dest = if down
then getunder x y else Unone
in
6440 begin match dest with
6443 | Uremote
_ | Uremotedest
_
6444 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6447 | Unone
when down
->
6448 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6449 state.mstate
<- Mpan
(x, y);
6451 | Unone
| Utext
_ ->
6454 if conf.angle
mod 360 = 0
6456 state.mstate
<- Msel
((x, y), (x, y));
6457 G.postRedisplay "mouse select";
6461 match state.mstate
with
6464 | Mzoom
_ | Mscrollx
| Mscrolly
->
6465 state.mstate
<- Mnone
6467 | Mzoomrect
((x0, y0), _) ->
6471 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6472 state.mstate
<- Mnone
6474 | Msel
((x0, y0), (x1, y1)) ->
6475 let rec loop = function
6479 let a0 = l.pagedispy in
6480 let a1 = a0 + l.pagevh in
6481 let b0 = l.pagedispx in
6482 let b1 = b0 + l.pagevw in
6483 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6484 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6488 match getopaque l.pageno with
6491 match Ne.res Unix.pipe
with
6495 "can not create sel pipe: %s"
6498 let doclose what fd
=
6499 Ne.clo fd
(fun msg
->
6500 dolog
"%s close failed: %s" what msg
)
6503 popen cmd [r, 0; w, -1];
6505 dolog
"can not execute %S: %s"
6507 doclose "Msel pipe/w" w;
6510 G.postRedisplay "copysel";
6511 doclose "Msel pipe/r" r;
6513 dosel conf.selcmd
();
6514 state.roam
<- dosel conf.paxcmd
;
6519 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6520 state.mstate
<- Mnone
;
6527 let birdseyemouse button down
x y mask
6528 (conf, leftx
, _, hooverpageno
, anchor) =
6531 let rec loop = function
6534 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6535 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6537 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6543 | _ -> viewmouse button down
x y mask
6549 method key key mask
=
6550 begin match state.mode with
6551 | Textentry
textentry -> textentrykeyboard key mask
textentry
6552 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6553 | View
-> viewkeyboard key mask
6554 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6558 method button button bstate
x y mask
=
6559 begin match state.mode with
6561 | View
-> viewmouse button bstate
x y mask
6562 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6567 method multiclick clicks
x y mask
=
6568 begin match state.mode with
6570 | View
-> viewmulticlick clicks
x y mask
6577 begin match state.mode with
6579 | View
| Birdseye
_ | LinkNav
_ ->
6580 match state.mstate
with
6581 | Mzoom
_ | Mnone
-> ()
6586 state.mstate
<- Mpan
(x, y);
6588 then state.x <- panbound (state.x + dx);
6590 gotoy_and_clear_text y
6593 state.mstate
<- Msel
(a, (x, y));
6594 G.postRedisplay "motion select";
6597 let y = min
state.winh
(max
0 y) in
6601 let x = min
state.winw (max
0 x) in
6604 | Mzoomrect
(p0
, _) ->
6605 state.mstate
<- Mzoomrect
(p0
, (x, y));
6606 G.postRedisplay "motion zoomrect";
6610 method pmotion
x y =
6611 begin match state.mode with
6612 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6613 let rec loop = function
6615 if hooverpageno
!= -1
6617 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6618 G.postRedisplay "pmotion birdseye no hoover";
6621 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6622 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6624 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6625 G.postRedisplay "pmotion birdseye hoover";
6635 match state.mstate
with
6636 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6643 let past, _, _ = !r in
6645 let delta = now -. past in
6648 else r := (now, x, y)
6652 method infochanged
_ = ()
6655 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6658 then 0.0, float state.winh
6659 else scrollph state.y maxy
6664 let winw = wadjsb state.winw in
6665 let fwinw = float winw in
6667 let sw = fwinw /. float state.w in
6668 let sw = fwinw *. sw in
6669 max
sw (float conf.scrollh
)
6672 let maxx = state.w + winw in
6673 let x = winw - state.x in
6674 let percent = float x /. float maxx in
6675 (fwinw -. sw) *. percent
6677 hscrollh (), position, sw
6681 match state.mode with
6682 | LinkNav
_ -> "links"
6683 | Textentry
_ -> "textentry"
6684 | Birdseye
_ -> "birdseye"
6687 findkeyhash conf modename
6689 method eformsgs
= true
6696 let fontpath = ref "";;
6699 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6702 let l = String.length
s in
6703 let b = Buffer.create
l in
6709 try Sys.getenv
"HOME"
6712 ("Can not determine home directory location: " ^ exntos exn
);
6716 let modifier_of_string = function
6717 | "alt" -> Wsi.altmask
6718 | "shift" -> Wsi.shiftmask
6719 | "ctrl" | "control" -> Wsi.ctrlmask
6720 | "meta" -> Wsi.metamask
6725 let r = Str.regexp
"-" in
6727 let elems = Str.full_split
r s in
6730 let m1 = modifier_of_string s in
6732 then (Wsi.namekey
s, m)
6735 | Str.Delim
s when n land 1 = 0 -> g s
6737 | Str.Delim
_ -> (k
, m)
6739 let rec loop n k
m = function
6742 let k, m = f n k m x in
6748 let keys_of_string =
6749 let r = Str.regexp
"[ \t]" in
6751 let elems = Str.split
r s in
6752 List.map
key_of_string elems
6755 let copykeyhashes c =
6756 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6759 let config_of c attrs
=
6763 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6764 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6765 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6766 | "preload" -> { c with preload = bool_of_string
v }
6767 | "page-bias" -> { c with pagebias
= int_of_string
v }
6768 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6769 | "horizontal-scroll-step" ->
6770 { c with hscrollstep
= max
(int_of_string
v) 1 }
6771 | "auto-scroll-step" ->
6772 { c with autoscrollstep
= max
0 (int_of_string
v) }
6773 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6774 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6777 match String.lowercase
v with
6778 | "true" -> Some infinity
6780 | f -> Some
(float_of_string
f)
6782 { c with maxwait
= mw}
6783 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6784 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6785 | "vertical-margin" ->
6786 { c with interpagespace
= max
0 (int_of_string
v) }
6788 let zoom = float_of_string
v /. 100. in
6789 let zoom = max
zoom 0.0 in
6790 { c with zoom = zoom }
6791 | "presentation" -> { c with presentation
= bool_of_string
v }
6792 | "rotation-angle" -> { c with angle
= int_of_string
v }
6793 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6794 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6795 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6796 | "proportional-display" ->
6799 then FitProportional
6802 { c with fitmodel
= fm }
6803 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6804 | "pixmap-cache-size" ->
6805 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6806 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6807 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6808 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6809 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6810 | "background-color" -> { c with bgcolor
= color_of_string v }
6811 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6812 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6813 | "mupdf-store-size" ->
6814 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6815 | "checkers" -> { c with checkers
= bool_of_string
v }
6816 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6817 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6818 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6819 | "uri-launcher" -> { c with urilauncher
= unent v }
6820 | "path-launcher" -> { c with pathlauncher
= unent v }
6821 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6822 | "invert-colors" -> { c with invert
= bool_of_string
v }
6823 | "brightness" -> { c with colorscale
= float_of_string
v }
6824 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6825 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6827 let (n, _, _) as nab
= multicolumns_of_string v in
6829 then { c with columns
= Csplit
(-n, [||]) }
6830 else { c with columns
= Cmulti
(nab
, [||]) }
6831 | "birds-eye-columns" ->
6832 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6833 | "selection-command" -> { c with selcmd
= unent v }
6834 | "synctex-command" -> { c with stcmd
= unent v }
6835 | "pax-command" -> { c with paxcmd
= unent v }
6836 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6837 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6838 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6839 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6840 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6841 | "horizontal-scrollbar-visible" ->
6844 then c.scrollb
lor scrollbhv
6845 else c.scrollb
land (lnot
scrollbhv)
6847 { c with scrollb
= b }
6848 | "vertical-scrollbar-visible" ->
6851 then c.scrollb
lor scrollbvv
6852 else c.scrollb
land (lnot
scrollbvv)
6854 { c with scrollb
= b }
6855 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6859 then Some
(ref (0.0, 0, 0))
6861 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6864 prerr_endline
("Error processing attribute (`" ^
6865 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6868 let rec fold c = function
6871 let c = apply c k v in
6874 fold { c with keyhashes
= copykeyhashes c } attrs
;
6877 let fromstring f pos
n v d =
6880 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6881 n v pos
(exntos exn
)
6886 let bookmark_of attrs
=
6887 let rec fold title page
rely visy
= function
6888 | ("title", v) :: rest
-> fold v page
rely visy rest
6889 | ("page", v) :: rest
-> fold title v rely visy rest
6890 | ("rely", v) :: rest
-> fold title page
v visy rest
6891 | ("visy", v) :: rest
-> fold title page
rely v rest
6892 | _ :: rest
-> fold title page
rely visy rest
6893 | [] -> title, page
, rely, visy
6895 fold "invalid" "0" "0" "0" attrs
6899 let rec fold path page
rely pan visy
= function
6900 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6901 | ("page", v) :: rest
-> fold path v rely pan visy rest
6902 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6903 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6904 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6905 | _ :: rest
-> fold path page
rely pan visy rest
6906 | [] -> path, page
, rely, pan
, visy
6908 fold "" "0" "0" "0" "0" attrs
6912 let rec fold rs ls
= function
6913 | ("out", v) :: rest
-> fold v ls rest
6914 | ("in", v) :: rest
-> fold rs
v rest
6915 | _ :: rest
-> fold ls rs rest
6921 let setconf dst
src =
6922 dst
.scrollbw
<- src.scrollbw
;
6923 dst
.scrollh
<- src.scrollh
;
6924 dst
.icase
<- src.icase
;
6925 dst
.preload <- src.preload;
6926 dst
.pagebias
<- src.pagebias
;
6927 dst
.verbose
<- src.verbose
;
6928 dst
.scrollstep
<- src.scrollstep
;
6929 dst
.maxhfit
<- src.maxhfit
;
6930 dst
.crophack
<- src.crophack
;
6931 dst
.autoscrollstep
<- src.autoscrollstep
;
6932 dst
.maxwait
<- src.maxwait
;
6933 dst
.hlinks
<- src.hlinks
;
6934 dst
.underinfo
<- src.underinfo
;
6935 dst
.interpagespace
<- src.interpagespace
;
6936 dst
.zoom <- src.zoom;
6937 dst
.presentation
<- src.presentation
;
6938 dst
.angle
<- src.angle
;
6939 dst
.cwinw
<- src.cwinw
;
6940 dst
.cwinh
<- src.cwinh
;
6941 dst
.savebmarks
<- src.savebmarks
;
6942 dst
.memlimit
<- src.memlimit
;
6943 dst
.fitmodel
<- src.fitmodel
;
6944 dst
.texcount
<- src.texcount
;
6945 dst
.sliceheight
<- src.sliceheight
;
6946 dst
.thumbw
<- src.thumbw
;
6947 dst
.jumpback
<- src.jumpback
;
6948 dst
.bgcolor
<- src.bgcolor
;
6949 dst
.tilew
<- src.tilew
;
6950 dst
.tileh
<- src.tileh
;
6951 dst
.mustoresize
<- src.mustoresize
;
6952 dst
.checkers
<- src.checkers
;
6953 dst
.aalevel
<- src.aalevel
;
6954 dst
.trimmargins
<- src.trimmargins
;
6955 dst
.trimfuzz
<- src.trimfuzz
;
6956 dst
.urilauncher
<- src.urilauncher
;
6957 dst
.colorspace
<- src.colorspace
;
6958 dst
.invert
<- src.invert
;
6959 dst
.colorscale
<- src.colorscale
;
6960 dst
.redirectstderr <- src.redirectstderr;
6961 dst
.ghyllscroll
<- src.ghyllscroll
;
6962 dst
.columns
<- src.columns
;
6963 dst
.beyecolumns
<- src.beyecolumns
;
6964 dst
.selcmd
<- src.selcmd
;
6965 dst
.updatecurs
<- src.updatecurs
;
6966 dst
.pathlauncher
<- src.pathlauncher
;
6967 dst
.keyhashes
<- copykeyhashes src;
6968 dst
.hfsize
<- src.hfsize
;
6969 dst
.hscrollstep
<- src.hscrollstep
;
6970 dst
.pgscale <- src.pgscale;
6971 dst
.usepbo
<- src.usepbo
;
6972 dst
.wheelbypage
<- src.wheelbypage
;
6973 dst
.stcmd
<- src.stcmd
;
6974 dst
.paxcmd
<- src.paxcmd
;
6975 dst
.scrollb
<- src.scrollb
;
6976 dst
.riani
<- src.riani
;
6977 dst
.paxmark
<- src.paxmark
;
6981 else Some
((ref (0.0, 0, 0)));
6985 let h = Hashtbl.create
10 in
6986 let dc = { defconf with angle
= defconf.angle
} in
6987 let rec toplevel v t spos
_ =
6989 | Vdata
| Vcdata
| Vend
-> v
6990 | Vopen
("llppconfig", _, closed
) ->
6993 else { v with f = llppconfig
}
6995 error
"unexpected subelement at top level" s spos
6996 | Vclose
_ -> error
"unexpected close at top level" s spos
6998 and llppconfig
v t spos
_ =
7000 | Vdata
| Vcdata
-> v
7001 | Vend
-> error
"unexpected end of input in llppconfig" s spos
7002 | Vopen
("defaults", attrs
, closed
) ->
7003 let c = config_of dc attrs
in
7007 else { v with f = defaults
}
7009 | Vopen
("ui-font", attrs
, closed
) ->
7010 let rec getsize size
= function
7012 | ("size", v) :: rest
->
7014 fromstring int_of_string spos
"size" v fstate.fontsize
in
7016 | l -> getsize size l
7018 fstate.fontsize
<- getsize fstate.fontsize attrs
;
7021 else { v with f = uifont
(Buffer.create
10) }
7023 | Vopen
("doc", attrs
, closed
) ->
7024 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
7025 let path = unent pathent
7026 and pageno = fromstring int_of_string spos
"page" spage
0
7027 and rely = fromstring float_of_string spos
"rely" srely
0.0
7028 and pan
= fromstring int_of_string spos
"pan" span
0
7029 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7030 let c = config_of dc attrs
in
7031 let anchor = (pageno, rely, visy
) in
7033 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
7034 else { v with f = doc
path pan
anchor c [] }
7037 error
"unexpected subelement in llppconfig" s spos
7039 | Vclose
"llppconfig" -> { v with f = toplevel }
7040 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
7042 and defaults
v t spos
_ =
7044 | Vdata
| Vcdata
-> v
7045 | Vend
-> error
"unexpected end of input in defaults" s spos
7046 | Vopen
("keymap", attrs
, closed
) ->
7048 try List.assoc
"mode" attrs
7049 with Not_found
-> "global" in
7054 let h = findkeyhash dc modename in
7055 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7058 { v with f = pkeymap
ret KeyMap.empty }
7060 | Vopen
(_, _, _) ->
7061 error
"unexpected subelement in defaults" s spos
7063 | Vclose
"defaults" ->
7064 { v with f = llppconfig
}
7066 | Vclose
_ -> error
"unexpected close in defaults" s spos
7068 and uifont
b v t spos
epos =
7071 Buffer.add_substring
b s spos
(epos - spos
);
7073 | Vopen
(_, _, _) ->
7074 error
"unexpected subelement in ui-font" s spos
7075 | Vclose
"ui-font" ->
7076 if emptystr
!fontpath
7077 then fontpath := Buffer.contents
b;
7078 { v with f = llppconfig
}
7079 | Vclose
_ -> error
"unexpected close in ui-font" s spos
7080 | Vend
-> error
"unexpected end of input in ui-font" s spos
7082 and doc
path pan
anchor c bookmarks
v t spos
_ =
7084 | Vdata
| Vcdata
-> v
7085 | Vend
-> error
"unexpected end of input in doc" s spos
7086 | Vopen
("bookmarks", _, closed
) ->
7089 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
7091 | Vopen
("keymap", attrs
, closed
) ->
7093 try List.assoc
"mode" attrs
7094 with Not_found
-> "global"
7100 let h = findkeyhash c modename in
7101 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7102 doc
path pan
anchor c bookmarks
7104 { v with f = pkeymap
ret KeyMap.empty }
7106 | Vopen
(_, _, _) ->
7107 error
"unexpected subelement in doc" s spos
7110 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7111 { v with f = llppconfig
}
7113 | Vclose
_ -> error
"unexpected close in doc" s spos
7115 and pkeymap
ret keymap
v t spos
_ =
7117 | Vdata
| Vcdata
-> v
7118 | Vend
-> error
"unexpected end of input in keymap" s spos
7119 | Vopen
("map", attrs
, closed
) ->
7120 let r, l = map_of attrs
in
7121 let kss = fromstring keys_of_string spos
"in" r [] in
7122 let lss = fromstring keys_of_string spos
"out" l [] in
7126 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7127 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7130 then { v with f = pkeymap
ret keymap }
7133 { v with f = skip
"map" f }
7136 error
"unexpected subelement in keymap" s spos
7138 | Vclose
"keymap" ->
7139 { v with f = ret keymap }
7141 | Vclose
_ -> error
"unexpected close in keymap" s spos
7143 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7145 | Vdata
| Vcdata
-> v
7146 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7147 | Vopen
("item", attrs
, closed
) ->
7148 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7149 let page = fromstring int_of_string spos
"page" spage
0
7150 and rely = fromstring float_of_string spos
"rely" srely
0.0
7151 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7153 (unent titleent, 0, Oanchor
(page, rely, visy
)) :: bookmarks
7156 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7159 { v with f = skip
"item" f }
7162 error
"unexpected subelement in bookmarks" s spos
7164 | Vclose
"bookmarks" ->
7165 { v with f = doc
path pan
anchor c bookmarks }
7167 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7169 and skip tag
f v t spos
_ =
7171 | Vdata
| Vcdata
-> v
7173 error
("unexpected end of input in skipped " ^ tag
) s spos
7174 | Vopen
(tag'
, _, closed
) ->
7178 let f'
() = { v with f = skip tag
f } in
7179 { v with f = skip tag'
f'
}
7183 else error
("unexpected close in skipped " ^ tag
) s spos
7186 parse
{ f = toplevel; accu = () } s;
7192 let len = in_channel_length ic
in
7193 let s = String.create
len in
7194 really_input ic
s 0 len;
7197 | Parse_error
(msg
, s, pos
) ->
7198 let subs = subs s pos
in
7199 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7202 failwith
("config load error: " ^ exntos exn
)
7208 let dir = Filename.concat
home ".config" in
7209 if Sys.is_directory
dir then dir else home
7212 Filename.concat
dir "llpp.conf"
7215 let confpath = ref defconfpath;;
7218 if Sys.file_exists
!confpath
7221 (try Some
(open_in_bin
!confpath)
7224 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7235 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7244 f (Hashtbl.create
0, defconf)
7249 let pc, pb
, px, pa
=
7252 if emptystr
state.origin
7256 Hashtbl.find h (Filename.basename
key)
7257 with Not_found
-> dc, [], 0, emptyanchor
7261 state.bookmarks <- pb
;
7264 then state.anchor <- pa
;
7265 cbput state.hists
.nav pa
;
7271 let add_attrs bb always
dc c =
7274 then Printf.bprintf bb
"\n %s='%b'" s a
7277 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7280 then Printf.bprintf bb
"\n %s='%d'" s a
7283 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7286 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7289 then Printf.bprintf bb
"\n %s='%f'" s a
7293 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7297 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7301 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7305 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7310 | Some
(_N
, _A
, _B
) ->
7311 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7316 Printf.bprintf bb
"\n %s='none'" s
7326 else string_of_float
f
7328 Printf.bprintf bb
"\n %s='%s'" s v
7333 | Cmulti
((n, a, b), _) when n > 1 ->
7334 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7335 | Csplit
(n, _) when n > 1 ->
7336 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7342 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7347 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7351 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7355 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7357 oi
"width" c.cwinw
dc.cwinw
;
7358 oi
"height" c.cwinh
dc.cwinh
;
7359 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7360 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7361 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7362 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7363 ob "case-insensitive-search" c.icase
dc.icase
;
7364 ob "preload" c.preload dc.preload;
7365 oi
"page-bias" c.pagebias
dc.pagebias
;
7366 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7367 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7368 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7369 ob "crop-hack" c.crophack
dc.crophack
;
7370 oW
"throttle" c.maxwait
dc.maxwait
;
7371 ob "highlight-links" c.hlinks
dc.hlinks
;
7372 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7373 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7374 oz
"zoom" c.zoom dc.zoom;
7375 ob "presentation" c.presentation
dc.presentation
;
7376 oi
"rotation-angle" c.angle
dc.angle
;
7377 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7378 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7379 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7380 oi
"tex-count" c.texcount
dc.texcount
;
7381 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7382 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7383 ob "persistent-location" c.jumpback
dc.jumpback
;
7384 oc
"background-color" c.bgcolor
dc.bgcolor
;
7385 oi
"tile-width" c.tilew
dc.tilew
;
7386 oi
"tile-height" c.tileh
dc.tileh
;
7387 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7388 ob "checkers" c.checkers
dc.checkers
;
7389 oi
"aalevel" c.aalevel
dc.aalevel
;
7390 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7391 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7392 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7393 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7394 oC
"color-space" c.colorspace
dc.colorspace
;
7395 ob "invert-colors" c.invert
dc.invert
;
7396 oF
"brightness" c.colorscale
dc.colorscale
;
7397 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7398 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7399 oco
"columns" c.columns
dc.columns
;
7400 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7401 os
"selection-command" c.selcmd
dc.selcmd
;
7402 os
"synctex-command" c.stcmd
dc.stcmd
;
7403 os
"pax-command" c.paxcmd
dc.paxcmd
;
7404 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7405 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7406 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7407 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7408 ob "use-pbo" c.usepbo
dc.usepbo
;
7409 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7410 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7411 op
"point-and-x" c.pax
dc.pax
;
7412 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7415 let keymapsbuf always
dc c =
7416 let bb = Buffer.create
16 in
7417 let rec loop = function
7419 | (modename, h) :: rest
->
7420 let dh = findkeyhash dc modename in
7421 if always
|| h <> dh
7423 if Hashtbl.length
h > 0
7425 if Buffer.length
bb > 0
7426 then Buffer.add_char
bb '
\n'
;
7427 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7428 Hashtbl.iter
(fun i
o ->
7429 let isdifferent = always
||
7431 let dO = Hashtbl.find dh i
in
7433 with Not_found
-> true
7438 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7439 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7440 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7441 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7442 Buffer.add_string
bb (Wsi.keyname
k);
7445 let rec loop = function
7447 | km
:: [] -> addkm km
7448 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7452 Buffer.add_string
bb "<map in='";
7456 Buffer.add_string
bb "' out='";
7458 Buffer.add_string
bb "'/>\n"
7461 Buffer.add_string
bb "' out='";
7463 Buffer.add_string
bb "'/>\n"
7465 | KMmulti
(ins, kms
) ->
7466 Buffer.add_char
bb ' '
;
7468 Buffer.add_string
bb "' out='";
7470 Buffer.add_string
bb "'/>\n"
7472 Buffer.add_string
bb "</keymap>";
7482 let uifontsize = fstate.fontsize
in
7483 let bb = Buffer.create
32768 in
7484 let relx = float state.x /. float state.winw in
7486 let cx w = truncate
(relx *. float w) in
7488 (fun (w, h, x) ws
->
7490 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7491 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7492 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7494 (state.winw, state.winh
, state.x) state.winstate
7499 let dc = if conf.bedefault
then conf else dc in
7500 Buffer.add_string
bb "<llppconfig>\n";
7502 if nonemptystr
!fontpath
7504 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7510 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7513 Buffer.add_string
bb "<defaults";
7514 add_attrs bb true dc dc;
7515 let kb = keymapsbuf true dc dc in
7516 if Buffer.length
kb > 0
7518 Buffer.add_string
bb ">\n";
7519 Buffer.add_buffer
bb kb;
7520 Buffer.add_string
bb "\n</defaults>\n";
7522 else Buffer.add_string
bb "/>\n";
7524 let adddoc path pan
anchor c bookmarks =
7525 if bookmarks == [] && c = dc && anchor = emptyanchor
7528 Printf.bprintf
bb "<doc path='%s'"
7529 (enent
path 0 (String.length
path));
7531 if anchor <> emptyanchor
7533 let n, rely, visy
= anchor in
7534 Printf.bprintf
bb " page='%d'" n;
7537 Printf.bprintf
bb " rely='%f'" rely
7539 if abs_float visy
> 1e-6
7541 Printf.bprintf
bb " visy='%f'" visy
7546 then Printf.bprintf
bb " pan='%d'" pan
;
7548 add_attrs bb false dc c;
7549 let kb = keymapsbuf false dc c in
7551 begin match bookmarks with
7553 if Buffer.length
kb > 0
7555 Buffer.add_string
bb ">\n";
7556 Buffer.add_buffer
bb kb;
7557 Buffer.add_string
bb "\n</doc>\n";
7559 else Buffer.add_string
bb "/>\n"
7561 Buffer.add_string
bb ">\n<bookmarks>\n";
7562 List.iter
(fun (title, _, kind
) ->
7563 begin match kind
with
7564 | Oanchor
(page, rely, visy
) ->
7566 "<item title='%s' page='%d'"
7567 (enent
title 0 (String.length
title))
7572 Printf.bprintf
bb " rely='%f'" rely
7574 if abs_float visy
> 1e-6
7576 Printf.bprintf
bb " visy='%f'" visy
7578 | Onone
| Ouri
_ | Oremote
_ | Oremotedest
_ | Olaunch
_ ->
7579 failwith
"unexpected link in bookmarks"
7581 Buffer.add_string
bb "/>\n";
7583 Buffer.add_string
bb "</bookmarks>";
7584 if Buffer.length
kb > 0
7586 Buffer.add_string
bb "\n";
7587 Buffer.add_buffer
bb kb;
7589 Buffer.add_string
bb "\n</doc>\n";
7595 match state.mode with
7596 | Birdseye
(c, pan, _, _, _) ->
7598 match conf.columns
with
7599 | Cmulti
((c, _, _), _) -> Some
c
7603 match c.columns
with
7604 | Cmulti
(c, _) -> Cmulti
(c, [||])
7605 | Csingle
_ -> Csingle
[||]
7606 | Csplit
_ -> failwith
"quit from bird's eye while split"
7608 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7611 let basename = Filename.basename
7612 (if emptystr
state.origin
then state.path else state.origin
)
7614 adddoc basename pan (getanchor ())
7616 let autoscrollstep =
7617 match state.autoscroll
with
7619 | None
-> conf.autoscrollstep
7621 match state.mode with
7622 | Birdseye
(bc
, _, _, _, _) ->
7625 presentation
= bc
.presentation
;
7626 interpagespace
= bc
.interpagespace
;
7627 maxwait
= bc
.maxwait
;
7628 autoscrollstep = autoscrollstep }
7629 | _ -> { conf with autoscrollstep = autoscrollstep }
7631 (if conf.savebmarks
then state.bookmarks else []);
7633 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7635 then adddoc path x anchor c bookmarks
7637 Buffer.add_string
bb "</llppconfig>\n";
7640 if load1 f && Buffer.length
bb > 0
7643 let tmp = !confpath ^
".tmp" in
7644 let oc = open_out_bin
tmp in
7645 Buffer.output_buffer
oc bb;
7647 Unix.rename
tmp !confpath;
7650 ("error while saving configuration: " ^ exntos exn
)
7654 let adderrmsg src msg
=
7655 Buffer.add_string
state.errmsgs msg
;
7656 state.newerrmsgs
<- true;
7660 let adderrfmt src fmt
=
7661 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7665 let cl = splitatspace cmds
in
7667 try Scanf.sscanf
s fmt
f
7669 adderrfmt "remote exec"
7670 "error processing '%S': %s\n" cmds
(exntos exn
)
7673 | "reload" :: [] -> reload ()
7674 | "goto" :: args :: [] ->
7675 scan args "%u %f %f"
7677 let cmd, _ = state.geomcmds
in
7679 then gotopagexy pageno x y
7682 gotopagexy pageno x y;
7685 state.reprf
<- f state.reprf
7687 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7688 | "gotor" :: args :: [] ->
7690 (fun filename
pageno -> gotounder (Uremote
(filename
, pageno)))
7691 | "gotord" :: args :: [] ->
7693 (fun filename
dest -> gotounder (Uremotedest
(filename
, dest)))
7694 | "rect" :: args :: [] ->
7695 scan args "%u %u %f %f %f %f"
7696 (fun pageno color x0 y0 x1 y1 ->
7697 onpagerect pageno (fun w h ->
7698 let _,w1,h1
,_ = getpagedim pageno in
7699 let sw = float w1 /. float w
7700 and sh = float h1
/. float h in
7704 and y1s
= y1 *. sh in
7705 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7707 state.rects <- (pageno, color, rect) :: state.rects;
7708 G.postRedisplay "rect";
7711 | "activatewin" :: [] -> Wsi.activatewin
()
7712 | "quit" :: [] -> raise Quit
7714 adderrfmt "remote command"
7715 "error processing remote command: %S\n" cmds
;
7719 let scratch = String.create
80 in
7720 let buf = Buffer.create
80 in
7723 try Some
(Unix.read fd
scratch 0 80)
7725 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7726 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7729 match tempfr () with
7735 if Buffer.length
buf > 0
7737 let s = Buffer.contents
buf in
7747 let pos = String.index_from
scratch ppos '
\n'
in
7748 if pos >= n then -1 else pos
7749 with Not_found
-> -1
7753 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7754 let s = Buffer.contents
buf in
7760 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7766 let remoteopen path =
7767 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
7769 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7774 let trimcachepath = ref "" in
7775 let rcmdpath = ref "" in
7776 let pageno = ref None
in
7777 selfexec := Sys.executable_name
;
7780 [("-p", Arg.String
(fun s -> state.password
<- s),
7781 "<password> Set password");
7785 Config.fontpath := s;
7786 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7788 "<path> Set path to the user interface font");
7792 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7793 Config.confpath := s),
7794 "<path> Set path to the configuration file");
7796 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
7797 "<page-number> Jump to page");
7799 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7800 "<path> Set path to the trim cache file");
7802 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7803 "<named-destination> Set named destination");
7805 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7806 ("-cxack", Arg.Set
cxack, " Cut corners");
7808 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7809 "<path> Set path to the remote commands source");
7811 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7812 "<original-path> Set original path");
7814 ("-v", Arg.Unit
(fun () ->
7816 "%s\nconfiguration path: %s\n"
7820 exit
0), " Print version and exit");
7823 (fun s -> state.path <- s)
7824 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7827 then selfexec := !selfexec ^
" -wtmode";
7829 if emptystr
state.path
7830 then (prerr_endline
"file name missing"; exit
1);
7832 if not
(Config.load ())
7833 then prerr_endline
"failed to load configuration";
7834 begin match !pageno with
7835 | Some
pageno -> state.anchor <- (pageno, 0.0, 0.0)
7839 let wsfd, winw, winh
= Wsi.init
(object (self)
7840 val mutable m_hack
= false
7841 val mutable m_clicks
= 0
7842 val mutable m_click_x
= 0
7843 val mutable m_click_y
= 0
7844 val mutable m_lastclicktime
= infinity
7846 method private cleanup
=
7847 state.roam
<- noroam;
7848 Hashtbl.iter
(fun _ opaque
-> clearmark opaque
) state.pagemap
;
7849 method expose
= if not m_hack
then G.postRedisplay "expose"
7850 method visible
= G.postRedisplay "visible"
7851 method display = m_hack
<- false; display ()
7852 method reshape w h =
7854 m_hack
<- w < state.winw && h < state.winh
;
7856 method mouse
b d x y m =
7859 (* http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx *)
7865 if abs
x - m_click_x
> 10
7866 || abs
y - m_click_y
> 10
7867 || abs_float
(t -. m_lastclicktime
) > 0.3
7869 m_clicks
<- m_clicks
+ 1;
7870 m_lastclicktime
<- t;
7874 G.postRedisplay "cleanup";
7875 state.uioh <- state.uioh#button
b d x y m;
7877 else state.uioh <- state.uioh#multiclick m_clicks
x y m
7882 m_lastclicktime
<- infinity
;
7883 state.uioh <- state.uioh#button
b d x y m
7887 state.uioh <- state.uioh#button
b d x y m
7890 state.mpos
<- (x, y);
7891 state.uioh <- state.uioh#motion
x y
7892 method pmotion
x y =
7893 state.mpos
<- (x, y);
7894 state.uioh <- state.uioh#pmotion
x y
7896 let mascm = m land (
7897 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7900 let x = state.x and y = state.y in
7902 if x != state.x || y != state.y then self#cleanup
7904 match state.keystate
with
7906 let km = k, mascm in
7909 let modehash = state.uioh#
modehash in
7910 try Hashtbl.find modehash km
7912 try Hashtbl.find (findkeyhash conf "global") km
7913 with Not_found
-> KMinsrt
(k, m)
7915 | KMinsrt
(k, m) -> keyboard k m
7916 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7917 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7919 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7920 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7921 state.keystate
<- KSnone
7922 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7923 state.keystate
<- KSinto
(keys
, insrt
)
7925 state.keystate
<- KSnone
7928 state.mpos
<- (x, y);
7929 state.uioh <- state.uioh#pmotion
x y
7930 method leave = state.mpos
<- (-1, -1)
7931 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7932 method quit
= raise Quit
7933 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7938 List.exists
GlMisc.check_extension
7939 [ "GL_ARB_texture_rectangle"
7940 ; "GL_EXT_texture_recangle"
7941 ; "GL_NV_texture_rectangle" ]
7943 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7946 let r = GlMisc.get_string `renderer
in
7947 let p = "Mesa DRI Intel(" in
7948 let l = String.length
p in
7949 String.length
r > l && String.sub
r 0 l = p
7952 defconf.sliceheight
<- 1024;
7953 defconf.texcount
<- 32;
7954 defconf.usepbo
<- true;
7958 match Ne.res Unix.pipe
with
7960 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7964 match Ne.res Unix.pipe
with
7966 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7976 setcheckers conf.checkers
;
7978 if conf.redirectstderr
7981 let s = Buffer.contents
state.errmsgs ^
7982 (match state.errfd
with
7984 let s = String.create
(80*24) in
7987 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7989 then Unix.read fd
s 0 (String.length
s)
7995 else String.sub
s 0 n
7999 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
8000 with exn
-> print_endline
(exntos exn
)
8005 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
8006 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
8007 !Config.fontpath, !trimcachepath,
8008 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
8010 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
8013 state.text <- "Opening " ^
(mbtoutf8
state.path);
8015 opendoc state.path state.password
;
8019 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
8022 if nonemptystr
!rcmdpath
8023 then remoteopen !rcmdpath
8028 let rec loop deadline
=
8030 match state.errfd
with
8031 | None
-> [state.sr
; state.wsfd]
8032 | Some fd
-> [state.sr
; state.wsfd; fd
]
8037 | Some fd
-> fd
:: r
8041 state.redisplay
<- false;
8048 if deadline
= infinity
8050 else max
0.0 (deadline
-. now)
8055 try Unix.select
r [] [] timeout
8056 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
8062 if state.ghyll
== noghyll
8064 match state.autoscroll
with
8065 | Some step
when step
!= 0 ->
8066 let y = state.y + step
in
8070 else if y >= state.maxy then 0 else y
8073 if state.mode = View
8074 then state.text <- "";
8077 else deadline
+. 0.01
8082 let rec checkfds = function
8084 | fd
:: rest
when fd
= state.sr
->
8085 let cmd = readcmd state.sr
in
8089 | fd
:: rest
when fd
= state.wsfd ->
8093 | fd
:: rest
when Some fd
= !optrfd ->
8094 begin match remote fd
with
8095 | None
-> optrfd := remoteopen !rcmdpath;
8096 | opt -> optrfd := opt
8101 let s = String.create
80 in
8102 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
8103 if conf.redirectstderr
8105 Buffer.add_substring
state.errmsgs
s 0 n;
8106 state.newerrmsgs
<- true;
8107 state.redisplay
<- true;
8110 prerr_string
(String.sub
s 0 n);
8118 if deadline
= infinity
8122 match state.autoscroll
with
8123 | Some step
when step
!= 0 -> deadline1
8124 | _ -> if state.ghyll
== noghyll then infinity
else deadline1