8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
11 | Ulaunch
of launchcommand
13 | Uremote
of (filename
* pageno
)
14 | Uremotedest
of (filename
* destname
)
16 and launchcommand
= string
19 and destname
= string;;
28 type params
= (angle
* fitmodel
* trimparams
29 * texcount
* sliceheight
* memsize
30 * colorspace
* fontpath
* trimcachepath
39 and trimmargins
= bool
40 and interpagespace
= int
47 and trimcachepath
= string
50 and irect
= (int * int * int * int)
51 and trimparams
= (trimmargins
* irect
)
52 and colorspace
= | Rgb
| Bgr
| Gray
53 and fitmodel
= | FitWidth
| FitProportional
| FitPage
63 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
72 | LDfirstvisible
of (int * int * int)
87 | KMmulti
of key list
* key list
89 and keyhash
= (key
, keymap
) Hashtbl.t
92 | KSinto
of (key list
* key list
)
95 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
96 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
98 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
100 external init
: pipe
-> params
-> unit = "ml_init";;
101 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
102 external copysel
: Unix.file_descr
-> opaque
-> bool -> unit = "ml_copysel";;
103 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
104 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
105 external markunder
: string -> int -> int -> mark
-> bool = "ml_markunder";;
106 external clearmark
: string -> unit = "ml_clearmark";;
107 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
108 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
109 external measurestr
: int -> string -> float = "ml_measure_string";;
110 external postprocess
:
111 opaque
-> int -> int -> int -> (int * string * int) -> int
113 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
114 external platform
: unit -> platform
= "ml_platform";;
115 external setaalevel
: int -> unit = "ml_setaalevel";;
116 external realloctexts
: int -> bool = "ml_realloctexts";;
117 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
118 external getlink
: opaque
-> int -> under
= "ml_getlink";;
119 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
120 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
121 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
122 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
123 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
124 external freepbo
: string -> unit = "ml_freepbo";;
125 external unmappbo
: string -> unit = "ml_unmappbo";;
126 external pbousable
: unit -> bool = "ml_pbo_usable";;
127 external unproject
: opaque
-> int -> int -> (int * int) option
129 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
130 external rectofblock
: opaque
-> int -> int -> float array
option
132 external fz_version
: unit -> string = "ml_fz_version";;
133 external begintiles
: unit -> unit = "ml_begintiles";;
134 external endtiles
: unit -> unit = "ml_endtiles";;
136 let platform_to_string = function
137 | Punknown
-> "unknown"
141 | Pfreebsd
-> "FreeBSD"
142 | Pdragonflybsd
-> "DragonflyBSD"
143 | Popenbsd
-> "OpenBSD"
144 | Pnetbsd
-> "NetBSD"
145 | Pcygwin
-> "Cygwin"
148 let platform = platform ();;
150 let now = Unix.gettimeofday
;;
152 let selfexec = ref "";;
155 if platform = Pcygwin
157 let sh = "/bin/sh" in
158 let args = [|sh; "-c"; cmd
|] in
159 let rec std si so se
= function
161 | (fd
, 0) :: rest
-> std fd so se rest
162 | (fd
, -1) :: rest
->
163 Unix.set_close_on_exec fd
;
166 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
168 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
169 ignore
(Unix.create_process
sh args si so se
)
174 type mpos
= int * int
176 | Msel
of (mpos
* mpos
)
178 | Mscrolly
| Mscrollx
179 | Mzoom
of (int * int)
180 | Mzoomrect
of (mpos
* mpos
)
184 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
185 and onkey
= string -> int -> te
186 and ondone
= string -> unit
187 and histcancel
= unit -> unit
188 and onhist
= ((histcmd
-> string) * histcancel
)
189 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
190 and cancelonempty
= bool
195 | TEswitch
of textentry
206 let bound v minv maxv
=
207 max minv
(min maxv v
);
211 { store
= Array.create n v
218 let cbcap b
= Array.length b
.store
;;
223 b
.wc
<- (b
.wc
+ 1) mod cap;
225 b
.len
<- min
(b
.len
+ 1) cap;
228 let cbempty b
= b
.len
= 0;;
230 let cbgetg b circular dir
=
234 let rc = b
.rc + dir
in
246 else bound rc 0 (b
.len
-1)
252 let cbget b
= cbgetg b
false;;
253 let cbgetc b
= cbgetg b
true;;
255 let drawstring size x y s
=
257 Gl.enable `texture_2d
;
258 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
259 ignore
(drawstr size x y s
);
261 Gl.disable `texture_2d
;
264 let drawstring1 size x y s
=
268 let drawstring2 size x y fmt
=
269 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
288 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
289 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
290 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
291 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
292 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
293 dolog
" column %d" l
.pagecol
;
297 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
299 dolog
" x0,y0=(% f, % f)" x0 y0
;
300 dolog
" x1,y1=(% f, % f)" x1 y1
;
301 dolog
" x2,y2=(% f, % f)" x2 y2
;
302 dolog
" x3,y3=(% f, % f)" x3 y3
;
306 type multicolumns
= multicol
* pagegeom
307 and singlecolumn
= pagegeom
308 and splitcolumns
= columncount
* pagegeom
309 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
310 and multicol
= columncount
* covercount
* covercount
312 and columncount
= int
313 and covercount
= int;;
320 { mutable scrollbw
: int
321 ; mutable scrollh
: int
322 ; mutable scrollb
: scrollb
323 ; mutable icase
: bool
324 ; mutable preload
: bool
325 ; mutable pagebias
: int
326 ; mutable verbose
: bool
327 ; mutable debug
: bool
328 ; mutable scrollstep
: int
329 ; mutable hscrollstep
: int
330 ; mutable maxhfit
: bool
331 ; mutable crophack
: bool
332 ; mutable autoscrollstep
: int
333 ; mutable maxwait
: float option
334 ; mutable hlinks
: bool
335 ; mutable underinfo
: bool
336 ; mutable interpagespace
: interpagespace
337 ; mutable zoom
: float
338 ; mutable presentation
: bool
339 ; mutable angle
: angle
340 ; mutable cwinw
: int
341 ; mutable cwinh
: int
342 ; mutable savebmarks
: bool
343 ; mutable fitmodel
: fitmodel
344 ; mutable trimmargins
: trimmargins
345 ; mutable trimfuzz
: irect
346 ; mutable memlimit
: memsize
347 ; mutable texcount
: texcount
348 ; mutable sliceheight
: sliceheight
349 ; mutable thumbw
: width
350 ; mutable jumpback
: bool
351 ; mutable bgcolor
: (float * float * float)
352 ; mutable bedefault
: bool
353 ; mutable tilew
: int
354 ; mutable tileh
: int
355 ; mutable mustoresize
: memsize
356 ; mutable checkers
: bool
357 ; mutable aalevel
: int
358 ; mutable urilauncher
: string
359 ; mutable pathlauncher
: string
360 ; mutable colorspace
: colorspace
361 ; mutable invert
: bool
362 ; mutable colorscale
: float
363 ; mutable redirectstderr
: bool
364 ; mutable ghyllscroll
: (int * int * int) option
365 ; mutable columns
: columns
366 ; mutable beyecolumns
: columncount
option
367 ; mutable selcmd
: string
368 ; mutable paxcmd
: string
369 ; mutable updatecurs
: bool
370 ; mutable keyhashes
: (string * keyhash
) list
371 ; mutable hfsize
: int
372 ; mutable pgscale
: float
373 ; mutable usepbo
: bool
374 ; mutable wheelbypage
: bool
375 ; mutable stcmd
: string
376 ; mutable riani
: bool
377 ; mutable pax
: (float * int * int) ref option
378 ; mutable paxmark
: mark
381 | Csingle
of singlecolumn
382 | Cmulti
of multicolumns
383 | Csplit
of splitcolumns
386 type anchor
= pageno
* top
* dtop
;;
391 | Olaunch
of launchcommand
392 | Oremote
of (filename
* pageno
)
393 | Oremotedest
of (filename
* destname
)
394 and outline
= (caption
* outlinelevel
* outlinekind
)
395 and outlinelevel
= int
398 type rect
= float * float * float * float * float * float * float * float;;
400 type tile
= opaque
* pixmapsize
* elapsed
401 and elapsed
= float;;
402 type pagemapkey
= pageno
* gen
;;
403 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
407 let emptyanchor = (0, 0.0, 0.0);;
409 type infochange
= | Memused
| Docinfo
| Pdim
;;
411 class type uioh
= object
412 method display
: unit
413 method key
: int -> int -> uioh
414 method button
: int -> bool -> int -> int -> int -> uioh
415 method motion
: int -> int -> uioh
416 method pmotion
: int -> int -> uioh
417 method infochanged
: infochange
-> unit
418 method scrollpw
: (int * float * float)
419 method scrollph
: (int * float * float)
420 method modehash
: keyhash
421 method eformsgs
: bool
425 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
426 | Textentry
of (textentry
* onleave
)
428 | LinkNav
of linktarget
429 and onleave
= leavetextentrystatus
-> unit
430 and leavetextentrystatus
= | Cancel
| Confirm
431 and helpitem
= string * int * action
434 | Action
of (uioh
-> uioh
)
436 | Ltexact
of (pageno
* int)
440 let isbirdseye = function Birdseye _
-> true | _
-> false;;
441 let istextentry = function Textentry _
-> true | _
-> false;;
445 | Loading
of (page
* gen
)
447 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
449 | Outlining
of outline list
452 let emptykeyhash = Hashtbl.create
0;;
453 let nouioh : uioh
= object (self
)
455 method key _ _
= self
456 method button _ _ _ _ _
= self
457 method motion _ _
= self
458 method pmotion _ _
= self
459 method infochanged _
= ()
460 method scrollpw
= (0, nan
, nan
)
461 method scrollph
= (0, nan
, nan
)
462 method modehash
= emptykeyhash
463 method eformsgs
= false
467 { mutable sr
: Unix.file_descr
468 ; mutable sw
: Unix.file_descr
469 ; mutable wsfd
: Unix.file_descr
470 ; mutable errfd
: Unix.file_descr
option
471 ; mutable stderr
: Unix.file_descr
472 ; mutable errmsgs
: Buffer.t
473 ; mutable newerrmsgs
: bool
477 ; mutable anchor
: anchor
478 ; mutable ranchors
: (string * string * anchor
* string) list
480 ; mutable layout
: page list
481 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
482 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
483 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
484 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
485 ; mutable pagecount
: int
486 ; mutable currently
: currently
487 ; mutable mstate
: mstate
488 ; mutable searchpattern
: string
489 ; mutable rects
: (pageno
* recttype
* rect
) list
490 ; mutable rects1
: (pageno
* recttype
* rect
) list
491 ; mutable text
: string
492 ; mutable winstate
: Wsi.winstate list
493 ; mutable mode
: mode
494 ; mutable uioh
: uioh
495 ; mutable outlines
: outline array
496 ; mutable bookmarks
: outline list
497 ; mutable path
: string
498 ; mutable password
: string
499 ; mutable nameddest
: string
500 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
501 ; mutable memused
: memsize
503 ; mutable throttle
: (page list
* int * float) option
504 ; mutable autoscroll
: int option
505 ; mutable ghyll
: (int option -> unit)
506 ; mutable help
: helpitem array
507 ; mutable docinfo
: (int * string) list
508 ; mutable texid
: GlTex.texture_id
option
510 ; mutable prevzoom
: (float * int)
511 ; mutable progress
: float
512 ; mutable redisplay
: bool
513 ; mutable mpos
: mpos
514 ; mutable keystate
: keystate
515 ; mutable glinks
: bool
516 ; mutable prevcolumns
: (columns
* float) option
519 ; mutable reprf
: (unit -> unit)
520 ; mutable origin
: string
521 ; mutable roam
: (unit -> unit)
522 ; mutable bzoom
: bool
523 ; mutable traw
: [`
float] Raw.t
524 ; mutable vraw
: [`
float] Raw.t
527 { pat
: string circbuf
528 ; pag
: string circbuf
529 ; nav
: anchor circbuf
530 ; sel
: string circbuf
537 ; scrollb
= scrollbhv lor scrollbvv
553 ; presentation
= false
558 ; fitmodel
= FitProportional
559 ; trimmargins
= false
560 ; trimfuzz
= (0,0,0,0)
561 ; memlimit
= 32 lsl 20
566 ; bgcolor
= (0.5, 0.5, 0.5)
570 ; mustoresize
= 256 lsl 20
575 | Plinux
| Pfreebsd
| Pdragonflybsd
576 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
577 | Posx
-> "open \"%s\""
578 | Pcygwin
-> "cygstart \"%s\""
579 | Punknown
-> "echo %s")
580 ; pathlauncher
= "lp \"%s\""
583 | Plinux
| Pfreebsd
| Pdragonflybsd
584 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
592 ; redirectstderr
= false
594 ; columns
= Csingle
[||]
600 ; wheelbypage
= false
601 ; stcmd
= "echo SyncTex"
604 ; paxmark
= Mark_word
606 let mk n
= (n
, Hashtbl.create
1) in
620 let wtmode = ref false;;
621 let cxack = ref false;;
623 let findkeyhash c name
=
624 try List.assoc name c
.keyhashes
625 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
628 let conf = { defconf with angle
= defconf.angle
};;
630 let pgscale h
= truncate
(float h
*. conf.pgscale);;
633 { mutable fontsize
: int
634 ; mutable wwidth
: float
635 ; mutable maxrows
: int
647 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
648 let len = String.length s
in
649 if colonpos >= 0 && colonpos + 3 < len
651 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
654 try String.rindex_from s
colonpos ' '
658 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
661 | "http" | "ftp" | "mailto" ->
663 try String.index_from s
colonpos ' '
664 with Not_found
-> len
666 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
674 if emptystr
conf.urilauncher
675 then print_endline uri
677 let url = geturl uri
in
679 then Printf.eprintf
"obtained empty url from uri %S" uri
681 let re = Str.regexp
"%s" in
682 let command = Str.global_replace
re url conf.urilauncher
in
686 "failed to execute `%s': %s\n" command (exntos exn
);
692 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
693 Help.version (fz_version
()) Sys.ocaml_version
694 (platform_to_string platform) Sys.word_size
698 let strings = version () :: "" :: Help.keys
in
701 let url = geturl s
in
703 then (s
, 0, Action
(fun u
-> gotouri url; u
))
704 else (s
, 0, Noaction
)
709 let firstgeomcmds = "", [];;
710 let noreprf () = ();;
717 ; stderr
= Unix.stderr
718 ; errmsgs
= Buffer.create
0
723 ; anchor
= emptyanchor
727 ; tilelru
= Queue.create
()
728 ; pagemap
= Hashtbl.create
10
729 ; tilemap
= Hashtbl.create
10
745 ; geomcmds
= firstgeomcmds
747 { nav
= cbnew 10 emptyanchor
760 ; prevzoom
= (1.0, 0)
772 ; roam
= (fun () -> ())
774 ; traw
= Raw.create_static `
float 8
775 ; vraw
= Raw.create_static `
float 8
780 if (conf.scrollb
land scrollbhv = 0)
781 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
787 if (conf.scrollb
land scrollbvv = 0)
792 let wadjsb w
= w
- vscrollw ();;
795 fstate.fontsize
<- n
;
796 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
797 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
803 Printf.kprintf prerr_endline fmt
805 Printf.kprintf ignore fmt
809 if emptystr
conf.pathlauncher
810 then print_endline
state.path
812 let re = Str.regexp
"%s" in
813 let command = Str.global_replace
re state.path
conf.pathlauncher
in
816 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
822 type 'a t
= | Res
of 'a
| Exn
of exn
;;
825 try Res
(Unix.pipe ())
830 try tempfailureretry
Unix.close fd
831 with exn
-> f
(exntos exn
)
835 try Res
(tempfailureretry
Unix.dup fd
)
840 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
845 let redirectstderr () =
846 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
847 if conf.redirectstderr
849 match Ne.pipe () with
851 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
854 begin match Ne.dup Unix.stderr
with
856 dolog
"failed to dup stderr: %s" (exntos exn
);
857 Ne.clo r
(clofail "pipe/r");
858 Ne.clo w
(clofail "pipe/w");
860 | Ne.Res dupstderr
->
861 begin match Ne.dup2 w
Unix.stderr
with
863 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
864 Ne.clo dupstderr
(clofail "stderr duplicate");
865 Ne.clo r
(clofail "redir pipe/r");
866 Ne.clo w
(clofail "redir pipe/w");
869 state.stderr
<- dupstderr
;
870 state.errfd
<- Some r
;
874 state.newerrmsgs
<- false;
875 begin match state.errfd
with
877 begin match Ne.dup2 state.stderr
Unix.stderr
with
879 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
881 Ne.clo fd
(clofail "dup of stderr");
886 prerr_string
(Buffer.contents
state.errmsgs
);
888 Buffer.clear
state.errmsgs
;
894 let postRedisplay who
=
896 then prerr_endline
("redisplay for " ^ who
);
897 state.redisplay
<- true;
901 let getopaque pageno
=
902 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
903 with Not_found
-> None
906 let putopaque pageno opaque
=
907 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
910 let pagetranslatepoint l x y
=
911 let dy = y
- l
.pagedispy
in
912 let y = dy + l
.pagey
in
913 let dx = x
- l
.pagedispx
in
914 let x = dx + l
.pagex
in
918 let onppundermouse g
x y d
=
921 begin match getopaque l
.pageno
with
923 let x0 = l
.pagedispx
in
924 let x1 = x0 + l
.pagevw
in
925 let y0 = l
.pagedispy
in
926 let y1 = y0 + l
.pagevh
in
927 if y >= y0 && y <= y1 && x >= x0 && x <= x1
929 let px, py
= pagetranslatepoint l
x y in
930 match g opaque l
px py
with
943 let g opaque l
px py
=
946 match rectofblock opaque
px py
with
948 let rect = (a
.(0),a
.(2),a
.(1),a
.(2),a
.(1),a
.(3),a
.(0),a
.(3)) in
949 state.rects
<- [l
.pageno
, l
.pageno
mod 3, rect];
950 G.postRedisplay "getunder";
953 match whatsunder opaque
px py
with
955 | under
-> Some under
957 onppundermouse g x y Unone
962 match unproject opaque
x y with
963 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
966 onppundermouse g x y None
;
970 state.text
<- Printf.sprintf
"%c%s" c s
;
971 G.postRedisplay "showtext";
975 let g opaque l
px py
=
976 if markunder opaque
px py
conf.paxmark
979 match getopaque l
.pageno
with
982 match Ne.pipe () with
986 "can not create mark pipe: %s"
989 let doclose what fd
=
990 Ne.clo fd
(fun msg
->
991 dolog
"%s close failed: %s" what msg
)
994 popen conf.paxcmd
[r
, 0; w
, -1];
995 copysel w opaque
false;
997 G.postRedisplay "paxunder";
999 dolog
"can not execute %S: %s"
1000 conf.paxcmd
(exntos exn
);
1007 G.postRedisplay "paxunder";
1008 if conf.paxmark
= Mark_page
1011 match getopaque l
.pageno
with
1013 | Some opaque
-> clearmark opaque
) state.layout
;
1015 onppundermouse g x y (fun () -> showtext '
!'
"Whoopsie daisy");
1019 match Ne.pipe () with
1021 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
1024 try popen conf.selcmd
[r
, 0; w
, -1]; true
1027 (Printf.sprintf
"failed to execute %s: %s"
1028 conf.selcmd
(exntos exn
));
1032 Ne.clo fd
(fun msg
->
1033 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
1039 let l = String.length s
in
1040 let n = tempfailureretry
(Unix.write w s
0) l in
1045 "failed to write %d characters to sel pipe, wrote %d"
1050 (Printf.sprintf
"failed to write to sel pipe: %s"
1059 let undertext = function
1062 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
1063 | Utext s
-> "font: " ^ s
1064 | Uunexpected s
-> "unexpected: " ^ s
1065 | Ulaunch s
-> "launch: " ^ s
1066 | Unamed s
-> "named: " ^ s
1067 | Uremote
(filename
, pageno
) ->
1068 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
1069 | Uremotedest
(filename
, destname
) ->
1070 Printf.sprintf
"%s: destination %S" filename destname
1073 let updateunder x y =
1074 match getunder x y with
1075 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
1077 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
1078 Wsi.setcursor
Wsi.CURSOR_INFO
1079 | Ulinkgoto
(pageno
, _
) ->
1081 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
1082 Wsi.setcursor
Wsi.CURSOR_INFO
1084 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
1085 Wsi.setcursor
Wsi.CURSOR_TEXT
1087 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
1088 Wsi.setcursor
Wsi.CURSOR_INHERIT
1090 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
1091 Wsi.setcursor
Wsi.CURSOR_INHERIT
1093 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
1094 Wsi.setcursor
Wsi.CURSOR_INHERIT
1095 | Uremote
(filename
, pageno
) ->
1096 if conf.underinfo
then showtext 'r'
1097 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
1098 Wsi.setcursor
Wsi.CURSOR_INFO
1099 | Uremotedest
(filename
, destname
) ->
1100 if conf.underinfo
then showtext 'r'
1101 (Printf.sprintf
"emote destination: %s (%S)" filename destname
);
1102 Wsi.setcursor
Wsi.CURSOR_INFO
1105 let showlinktype under
=
1111 let s = undertext under
in
1116 let b = Buffer.create
(String.length
s + 1) in
1117 Buffer.add_string
b s;
1118 Buffer.add_char
b c
;
1122 module type TextEnumType
=
1126 val names
: string array
1129 module TextEnumMake
(Ten
: TextEnumType
) =
1131 let names = Ten.names;;
1132 let to_int (t
: Ten.t
) = Obj.magic t
;;
1133 let to_string t
= names.(to_int t
);;
1134 let of_int n : Ten.t
= Obj.magic
n;;
1137 if i
= Array.length
names
1138 then failwith
("invalid " ^
Ten.name ^
": " ^
s)
1140 if Ten.names.(i
) = s
1147 module CSTE
= TextEnumMake
(struct
1148 type t
= colorspace
;;
1149 let name = "colorspace";;
1150 let names = [|"rgb"; "bgr"; "gray"|];;
1153 module MTE
= TextEnumMake
(struct
1156 let names = [|"page"; "block"; "line"; "word"|];;
1159 module FMTE
= TextEnumMake
(struct
1161 let name = "fitmodel";;
1162 let names = [|"width"; "proportional"; "page"|];;
1165 let intentry_with_suffix text key
=
1167 if key
>= 32 && key
< 127
1171 match Char.lowercase
c with
1173 let text = addchar text c in
1176 | 'k'
| 'm'
| '
g'
->
1177 let text = addchar text c in
1181 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1185 let multicolumns_to_string (n, a
, b) =
1187 then Printf.sprintf
"%d" n
1188 else Printf.sprintf
"%d,%d,%d" n a
b;
1191 let multicolumns_of_string s =
1193 (int_of_string
s, 0, 0)
1195 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1197 then failwith
"subtly broken"; (n, a
, b)
1203 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1204 if n != 4 then error
"incomplete read(len) = %d" n;
1206 lor (Char.code
s.[0] lsl 24)
1207 lor (Char.code
s.[1] lsl 16)
1208 lor (Char.code
s.[2] lsl 8)
1209 lor (Char.code
s.[3] lsl 0)
1211 let s = String.create
len in
1212 let n = tempfailureretry
(Unix.read fd
s 0) len in
1213 if n != len then error
"incomplete read(data) %d vs %d" n len;
1217 let btod b = if b then 1 else 0;;
1220 let b = Buffer.create
16 in
1221 Buffer.add_string
b "llll";
1224 let s = Buffer.contents
b in
1225 let n = String.length
s in
1227 (* dolog "wcmd %S" (String.sub s 4 len); *)
1228 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1229 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1230 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1231 s.[3] <- Char.chr
(len land 0xff);
1232 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1233 if n'
!= n then error
"write failed %d vs %d" n'
n;
1238 let d = state.winh
- h
in
1239 max
conf.interpagespace
((d + 1) / 2)
1242 let rowyh (c, coverA
, coverB
) b n =
1243 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1245 let _, _, vy
, (_, _, h
, _) = b.(n) in
1248 let n'
= n - coverA
in
1251 let e = min
state.pagecount
(s + c) in
1252 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1253 let _, _, y, (_, _, h
, _) = b.(m
) in
1254 let miny = min
miny y in
1255 let maxh = max
maxh h
in
1256 find (m
+1) miny maxh
1261 match conf.columns
with
1262 | Cmulti
((_, _, _) as cl
, b) ->
1263 if Array.length
b > 0
1265 let y, h
= rowyh cl
b (Array.length
b - 1) in
1266 y + h
+ (if conf.presentation
then calcips h
else 0)
1269 if Array.length
b > 0
1271 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1272 y + h
+ (if conf.presentation
then calcips h
else 0)
1275 if Array.length
b > 0
1277 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1282 let getpageywh pageno
=
1283 let pageno = bound pageno 0 (state.pagecount
-1) in
1284 match conf.columns
with
1286 if Array.length
b = 0
1289 let (_, _, y, (_, w
, h
, _)) = b.(pageno) in
1291 if conf.presentation
1297 if Array.length
b = 0
1300 let y, h
= rowyh cl
b pageno in
1301 let (_, _, _, (_, w
, _, _)) = b.(pageno) in
1303 if conf.presentation
1309 if Array.length
b = 0
1313 let (_, _, y, (_, w
, h
, _)) = b.(n) in
1317 let getpageyh pageno =
1318 let y,_,h
= getpageywh pageno in
1322 let getpagedim pageno =
1325 | (n, _, _, _) as pdim
:: rest
->
1327 then (if n = pageno then pdim
else ppdim
)
1332 f (-1, -1, -1, -1) state.pdims
1335 let getpagey pageno = fst
(getpageyh pageno);;
1337 let nogeomcmds cmds
=
1339 | s, [] -> emptystr
s
1344 let ((c, coverA
, coverB
) as cl
), b =
1345 match conf.columns
with
1346 | Csingle
b -> (1, 0, 0), b
1347 | Cmulti
(c, b) -> c, b
1348 | Csplit
(_, b) -> (1, 0, 0), b
1350 if Array.length
b = 0
1353 let rec bsearch nmin nmax
=
1355 then bound nmin
0 (state.pagecount
-1)
1357 let n = (nmax
+ nmin
) / 2 in
1358 let vy, h
= rowyh cl
b n in
1360 if conf.presentation
1362 let ips = calcips h
in
1363 let y0 = vy - ips in
1364 let y1 = vy + h
+ ips in
1368 then 0, vy + h
+ conf.interpagespace
1370 let y0 = vy - conf.interpagespace
in
1371 y0, y0 + h
+ conf.interpagespace
1374 if y >= y0 && y < y1
1381 if n < state.pagecount
- coverB
1382 then ((n-coverA
)/c)*c + coverA
1389 then bsearch (n+1) nmax
1390 else bsearch nmin
(n-1)
1393 bsearch 0 (state.pagecount
-1);
1396 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1397 let sh = sh - (hscrollh ()) in
1398 let rec fold accu
n =
1399 if n = Array.length
b
1402 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1405 || n = state.pagecount
- coverB
1406 || (n - coverA
) mod columns
= columns
- 1)
1412 let pagey = max
0 (y - vy) in
1413 let pagedispy = if pagey > 0 then 0 else vy - y in
1414 let pagedispx, pagex
=
1416 if n = coverA
- 1 || n = state.pagecount
- coverB
1417 then state.x + (wadjsb state.winw
- w
) / 2
1418 else dx + xoff
+ state.x
1425 let vw = wadjsb state.winw
- pagedispx in
1426 let pw = w
- pagex
in
1429 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1430 if pagevw > 0 && pagevh > 0
1434 ; pagedimno
= pdimno
1441 ; pagedispx = pagedispx
1442 ; pagedispy = pagedispy
1454 if Array.length
b = 0
1456 else List.rev
(fold [] (page_of_y y))
1459 let layoutS (columns
, b) y sh =
1460 let sh = sh - hscrollh () in
1461 let rec fold accu n =
1462 if n = Array.length
b
1465 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1472 let x = xoff
+ state.x in
1473 let pagey = max
0 (y - vy) in
1474 let pagedispy = if pagey > 0 then 0 else vy - y in
1475 let pagedispx, pagex
=
1489 let pagecolw = pagew
/columns
in
1491 if pagecolw < state.winw
1492 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1496 let vw = wadjsb state.winw
- pagedispx in
1497 let pw = pagew
- pagex
in
1500 let pagevw = min
pagevw pagecolw in
1501 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1502 if pagevw > 0 && pagevh > 0
1505 { pageno = n/columns
1506 ; pagedimno
= pdimno
1513 ; pagedispx = pagedispx
1514 ; pagedispy = pagedispy
1515 ; pagecol
= n mod columns
1526 List.rev
(fold [] 0)
1530 if nogeomcmds state.geomcmds
1532 match conf.columns
with
1533 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1534 | Cmulti
c -> layoutN c y sh
1535 | Csplit
s -> layoutS s y sh
1540 let y = state.y + incr
in
1542 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1547 let tilex = l.pagex
mod conf.tilew
in
1548 let tiley = l.pagey mod conf.tileh
in
1550 let col = l.pagex
/ conf.tilew
in
1551 let row = l.pagey / conf.tileh
in
1553 let rec rowloop row y0 dispy h
=
1557 let dh = conf.tileh
- y0 in
1558 let dh = min h
dh in
1559 let rec colloop col x0 dispx w
=
1563 let dw = conf.tilew
- x0 in
1564 let dw = min w
dw in
1566 f col row dispx dispy
x0 y0 dw dh;
1567 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1570 colloop col tilex l.pagedispx l.pagevw;
1571 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1574 if l.pagevw > 0 && l.pagevh > 0
1575 then rowloop row tiley l.pagedispy l.pagevh;
1578 let gettileopaque l col row =
1580 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1582 try Some
(Hashtbl.find state.tilemap
key)
1583 with Not_found
-> None
1586 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1587 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1588 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1591 let filledrect x0 y0 x1 y1 =
1592 GlArray.disable `texture_coord
;
1593 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1594 GlArray.vertex `two
state.vraw
;
1595 GlArray.draw_arrays `triangle_strip
0 4;
1596 GlArray.enable `texture_coord
;
1599 let linerect x0 y0 x1 y1 =
1600 GlArray.disable `texture_coord
;
1601 Raw.sets_float
state.vraw ~pos
:0 [| x0; y0; x0; y1; x1; y1; x1; y0 |];
1602 GlArray.vertex `two
state.vraw
;
1603 GlArray.draw_arrays `line_loop
0 4;
1604 GlArray.enable `texture_coord
;
1607 let drawtiles l color
=
1610 let f col row x y tilex tiley w h
=
1611 match gettileopaque l col row with
1612 | Some
(opaque
, _, t
) ->
1613 let params = x, y, w
, h
, tilex, tiley in
1617 GlFunc.blend_func `zero `one_minus_src_color
;
1619 drawtile
params opaque
;
1621 then Gl.disable `blend
;
1625 let s = Printf.sprintf
1629 let w = measurestr
fstate.fontsize
s in
1630 GlDraw.color
(0.0, 0.0, 0.0);
1631 filledrect (float (x-2))
1634 (float (y + fstate.fontsize
+ 2));
1635 GlDraw.color
(1.0, 1.0, 1.0);
1636 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1643 let lw = wadjsb state.winw
- x in
1646 let lh = state.winh
- y in
1649 begin match state.texid
with
1651 Gl.enable `texture_2d
;
1652 GlTex.bind_texture `texture_2d id
;
1655 and x1 = float (x+w)
1656 and y1 = float (y+h
) in
1658 let tw = float w /. 16.0
1659 and th
= float h
/. 16.0 in
1660 let tx0 = float tilex /. 16.0
1661 and ty0
= float tiley /. 16.0 in
1663 and ty1
= ty0
+. th
in
1664 Raw.sets_float
state.vraw ~pos
:0
1665 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
1666 Raw.sets_float
state.traw ~pos
:0
1667 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
1668 GlArray.vertex `two
state.vraw
;
1669 GlArray.tex_coord `two
state.traw
;
1670 GlArray.draw_arrays `triangle_strip
0 4;
1673 GlDraw.color
(1.0, 1.0, 1.0);
1674 filledrect (float x) (float y) (float (x+w)) (float (y+h
));
1676 if w > 128 && h
> fstate.fontsize
+ 10
1678 GlDraw.color
(0.0, 0.0, 0.0);
1681 then (col*conf.tilew
, row*conf.tileh
)
1684 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r
;
1693 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1695 let tilevisible1 l x y =
1697 and ax1
= l.pagex
+ l.pagevw
1699 and ay1
= l.pagey + l.pagevh in
1703 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1704 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1706 let rx0 = max
ax0 bx0
1707 and ry0
= max ay0 by0
1708 and rx1
= min ax1
bx1
1709 and ry1
= min ay1 by1
in
1711 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1712 nonemptyintersection
1715 let tilevisible layout n x y =
1716 let rec findpageinlayout m
= function
1717 | l :: rest
when l.pageno = n ->
1718 tilevisible1 l x y || (
1719 match conf.columns
with
1720 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1723 | _ :: rest
-> findpageinlayout 0 rest
1726 findpageinlayout 0 layout;
1729 let tileready l x y =
1730 tilevisible1 l x y &&
1731 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1734 let tilepage n p
layout =
1735 let rec loop = function
1739 let f col row _ _ _ _ _ _ =
1740 if state.currently
= Idle
1742 match gettileopaque l col row with
1745 let x = col*conf.tilew
1746 and y = row*conf.tileh
in
1748 let w = l.pagew
- x in
1752 let h = l.pageh
- y in
1757 then getpbo
w h conf.colorspace
1760 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1763 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1764 conf.tilew
, conf.tileh
1773 if nogeomcmds state.geomcmds
1777 let preloadlayout y =
1778 let y = if y < state.winh
then 0 else y - state.winh
in
1779 let h = state.winh
*3 in
1784 let rec loop pages
=
1785 if state.currently
!= Idle
1790 begin match getopaque l.pageno with
1792 wcmd "page %d %d" l.pageno l.pagedimno
;
1793 state.currently
<- Loading
(l, state.gen
);
1795 tilepage l.pageno opaque pages
;
1800 if nogeomcmds state.geomcmds
1806 if conf.preload && state.currently
= Idle
1807 then load (preloadlayout state.y);
1810 let layoutready layout =
1811 let rec fold all ls
=
1812 all
&& match ls
with
1814 let seen = ref false in
1815 let allvisible = ref true in
1816 let foo col row _ _ _ _ _ _ =
1818 allvisible := !allvisible &&
1819 begin match gettileopaque l col row with
1825 fold (!seen && !allvisible) rest
1828 let alltilesvisible = fold true layout in
1833 let y = bound y 0 state.maxy
in
1834 let y, layout, proceed
=
1835 match conf.maxwait
with
1836 | Some time
when state.ghyll
== noghyll ->
1837 begin match state.throttle
with
1839 let layout = layout y state.winh
in
1840 let ready = layoutready layout in
1844 state.throttle
<- Some
(layout, y, now ());
1846 else G.postRedisplay "gotoy showall (None)";
1848 | Some
(_, _, started
) ->
1849 let dt = now () -. started
in
1852 state.throttle
<- None
;
1853 let layout = layout y state.winh
in
1855 G.postRedisplay "maxwait";
1862 let layout = layout y state.winh
in
1863 if not
!wtmode || layoutready layout
1864 then G.postRedisplay "gotoy ready";
1870 state.layout <- layout;
1871 begin match state.mode
with
1872 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1873 let rec loop = function
1875 state.mode
<- LinkNav
(Ltgendir
0)
1876 | l :: _ when l.pageno = pageno ->
1877 begin match getopaque pageno with
1879 state.mode
<- LinkNav
(Ltgendir
0)
1881 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1882 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1883 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1884 then state.mode
<- LinkNav
(Ltgendir
0)
1886 | _ :: rest
-> loop rest
1891 begin match state.mode
with
1892 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1893 if not
(pagevisible layout pageno)
1895 match state.layout with
1898 state.mode
<- Birdseye
(
1899 conf, leftx
, l.pageno, hooverpageno
, anchor
1902 | LinkNav
(Ltgendir dir
as lt
) ->
1904 let rec loop = function
1907 match getopaque l.pageno with
1913 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1915 if dir
> 0 then LDfirst
else LDlast
1921 | Lnotfound
-> loop rest
1923 showlinktype (getlink opaque
n);
1924 Ltexact
(l.pageno, n)
1928 state.mode
<- LinkNav
linknav
1933 state.ghyll
<- noghyll;
1936 let mx, my
= state.mpos
in
1941 let conttiling pageno opaque
=
1942 tilepage pageno opaque
1943 (if conf.preload then preloadlayout state.y else state.layout)
1946 let gotoy_and_clear_text y =
1947 if not
conf.verbose
then state.text <- "";
1953 let coloff = l.pagecol
* l.pageh
in
1954 float (l.pagey + coloff) /. float l.pageh
1961 if conf.presentation
1962 then float l.pagedispy /. float (calcips l.pageh
)
1963 else float l.pagedispy /. float conf.interpagespace
1966 (l.pageno, top, dtop)
1970 match state.layout with
1971 | l :: _ -> getanchor1 l
1973 let n = page_of_y state.y in
1977 let y, h = getpageyh n in
1978 let dy = y - state.y in
1980 if conf.presentation
1982 let ips = calcips h in
1983 float (dy + ips) /. float ips
1985 float dy /. float conf.interpagespace
1990 let getanchory (n, top, dtop) =
1991 let y, h = getpageyh n in
1992 if conf.presentation
1994 let ips = calcips h in
1995 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1997 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
2000 let gotoanchor anchor
=
2001 gotoy (getanchory anchor
);
2005 cbput state.hists
.nav
(getanchor ());
2009 let anchor = cbgetc state.hists
.nav dir
in
2014 let scroll f n a
b =
2015 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
2017 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
2019 then s (float f /. float a
)
2022 then 1.0 -. s ((float (f-b) /. float (n-b)))
2028 let ins = float a
*. 0.5
2029 and outs
= float (n-b) *. 0.5 in
2031 ins +. outs
+. float ones
2033 let rec set (_N
, _A
, _B
) y sy
=
2034 let sum = summa _N _A _B
in
2035 let dy = float (y - sy
) in
2039 then state.ghyll
<- noghyll
2042 let s = scroll n _N _A _B
in
2043 let y1 = y1 +. ((s *. dy) /. sum) in
2044 gotoy_and_clear_text (truncate
y1);
2045 state.ghyll
<- gf (n+1) y1;
2049 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
2051 gf 0 (float state.y)
2054 match conf.ghyllscroll
with
2056 gotoy_and_clear_text y
2058 if state.ghyll
== noghyll
2059 then set nab
y state.y
2060 else state.ghyll
(Some
y)
2063 let gotopage n top =
2064 let y, h = getpageyh n in
2065 let y = y + (truncate
(top *. float h)) in
2069 let gotopage1 n top =
2070 let y = getpagey n in
2075 let invalidate s f =
2080 match state.geomcmds
with
2081 | ps
, [] when emptystr ps
->
2083 state.geomcmds
<- s, [];
2086 state.geomcmds
<- ps
, [s, f];
2088 | ps
, (s'
, _) :: rest
when s'
= s ->
2089 state.geomcmds
<- ps
, ((s, f) :: rest
);
2092 state.geomcmds
<- ps
, ((s, f) :: cmds
);
2096 Hashtbl.iter
(fun _ opaque
->
2097 wcmd "freepage %s" opaque
;
2099 Hashtbl.clear
state.pagemap
;
2103 if not
(Queue.is_empty
state.tilelru
)
2105 Queue.iter
(fun (k
, p
, s) ->
2106 wcmd "freetile %s" p
;
2107 state.memused
<- state.memused
- s;
2108 Hashtbl.remove
state.tilemap k
;
2110 state.uioh#infochanged Memused
;
2111 Queue.clear
state.tilelru
;
2117 let h = truncate
(float h*.conf.zoom
) in
2118 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2122 let opendoc path password
=
2124 state.password
<- password
;
2125 state.gen
<- state.gen
+ 1;
2126 state.docinfo
<- [];
2129 setaalevel
conf.aalevel
;
2131 if emptystr
state.origin
2135 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2136 wcmd "open %d %d %s\000%s\000" (btod !wtmode) (btod !cxack) path password
;
2137 invalidate "reqlayout"
2139 wcmd "reqlayout %d %d %d %s\000"
2140 conf.angle
(FMTE.to_int conf.fitmodel
)
2141 (stateh state.winh
) state.nameddest
2146 state.anchor <- getanchor ();
2147 opendoc state.path
state.password
;
2151 let c = c *. conf.colorscale
in
2155 let scalecolor2 (r
, g, b) =
2156 (r
*. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2159 let docolumns = function
2161 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2162 let rec loop pageno pdimno pdim
y ph pdims
=
2163 if pageno = state.pagecount
2166 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2168 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2169 pdimno+1, pdim
, rest
2173 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2175 (if conf.presentation
2176 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2177 else (if pageno = 0 then 0 else conf.interpagespace
)
2180 a.(pageno) <- (pdimno, x, y, pdim
);
2181 loop (pageno+1) pdimno pdim
(y + h) h pdims
2183 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2184 conf.columns
<- Csingle
a;
2186 | Cmulti
((columns
, coverA
, coverB
), _) ->
2187 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2188 let rec loop pageno pdimno pdim
x y rowh pdims
=
2189 let rec fixrow m
= if m
= pageno then () else
2190 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2193 let y = y + (rowh
- h) / 2 in
2194 a.(m
) <- (pdimno, x, y, pdim
);
2198 if pageno = state.pagecount
2199 then fixrow (((pageno - 1) / columns
) * columns
)
2201 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2203 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2204 pdimno+1, pdim
, rest
2209 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2211 let x = (wadjsb state.winw
- w) / 2 in
2213 if conf.presentation
then calcips h else conf.interpagespace
in
2214 x, y + ips + rowh
, h
2217 if (pageno - coverA
) mod columns
= 0
2219 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2221 if conf.presentation
2223 let ips = calcips h in
2224 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2226 y + (if pageno = 0 then 0 else conf.interpagespace
)
2230 else x, y, max rowh
h
2234 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2237 if pageno = columns
&& conf.presentation
2239 let ips = calcips rowh
in
2240 for i
= 0 to pred columns
2242 let (pdimno, x, y, pdim
) = a.(i
) in
2243 a.(i
) <- (pdimno, x, y+ips, pdim
)
2249 fixrow (pageno - columns
);
2254 a.(pageno) <- (pdimno, x, y, pdim
);
2255 let x = x + w + xoff
*2 + conf.interpagespace
in
2256 loop (pageno+1) pdimno pdim
x y rowh' pdims
2258 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2259 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2262 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2263 let rec loop pageno pdimno pdim
y pdims
=
2264 if pageno = state.pagecount
2267 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2269 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2270 pdimno+1, pdim
, rest
2275 let rec loop1 n x y =
2276 if n = c then y else (
2277 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2278 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2281 let y = loop1 0 0 y in
2282 loop (pageno+1) pdimno pdim
y pdims
2284 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2285 conf.columns
<- Csplit
(c, a);
2289 docolumns conf.columns
;
2290 state.maxy
<- calcheight ();
2291 if state.reprf
== noreprf
2293 match state.mode
with
2294 | Birdseye
(_, _, pageno, _, _) ->
2295 let y, h = getpageyh pageno in
2296 let top = (state.winh
- h) / 2 in
2297 gotoy (max
0 (y - top))
2298 | _ -> gotoanchor state.anchor
2302 state.reprf
<- noreprf;
2307 GlDraw.viewport
0 0 w h;
2308 let firsttime = state.geomcmds
== firstgeomcmds in
2309 if not
firsttime && nogeomcmds state.geomcmds
2310 then state.anchor <- getanchor ();
2313 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2316 setfontsize fstate.fontsize
;
2317 GlMat.mode `modelview
;
2318 GlMat.load_identity
();
2320 GlMat.mode `projection
;
2321 GlMat.load_identity
();
2322 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2323 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2324 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2329 else float state.x /. float state.w
2331 invalidate "geometry"
2335 then state.x <- truncate
(relx *. float w);
2337 match conf.columns
with
2339 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2340 | Csplit
(c, _) -> w * c
2342 wcmd "geometry %d %d %d"
2343 w (stateh h) (FMTE.to_int conf.fitmodel
)
2348 let len = String.length
state.text in
2351 match state.mode
with
2352 | Textentry
_ | View
| LinkNav
_ ->
2353 let h, _, _ = state.uioh#scrollpw
in
2358 filledrect x (float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2359 (x+.w) (float (state.winh
- hscrollh))
2362 let w = float (wadjsb state.winw
- 1) in
2363 if state.progress
>= 0.0 && state.progress
< 1.0
2365 GlDraw.color
(0.3, 0.3, 0.3);
2366 let w1 = w *. state.progress
in
2368 GlDraw.color
(0.0, 0.0, 0.0);
2372 GlDraw.color
(0.0, 0.0, 0.0);
2376 GlDraw.color
(1.0, 1.0, 1.0);
2377 drawstring fstate.fontsize
2378 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2381 match state.mode
with
2382 | Textentry
((prefix
, text, _, _, _, _), _) ->
2386 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2388 Printf.sprintf
"%s%s_" prefix
text
2397 if not
(istextentry state.mode
) && state.uioh#eformsgs
2399 let s1 = "(press 'e' to review error messasges)" in
2400 if nonemptystr
s then s ^
" " ^
s1 else s1
2410 let len = Queue.length
state.tilelru
in
2412 match state.throttle
with
2415 then preloadlayout state.y
2417 | Some
(layout, _, _) ->
2421 if state.memused
<= conf.memlimit
2426 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2427 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2428 let (_, pw, ph
, _) = getpagedim n in
2431 && colorspace
= conf.colorspace
2432 && angle
= conf.angle
2436 let x = col*conf.tilew
2437 and y = row*conf.tileh
in
2438 tilevisible (Lazy.force_val
layout) n x y
2440 then Queue.push lruitem
state.tilelru
2443 wcmd "freetile %s" p
;
2444 state.memused
<- state.memused
- s;
2445 state.uioh#infochanged Memused
;
2446 Hashtbl.remove
state.tilemap k
;
2454 let logcurrently = function
2455 | Idle
-> dolog
"Idle"
2456 | Loading
(l, gen
) ->
2457 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2458 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2460 "Tiling %d[%d,%d] page=%s cs=%s angle"
2461 l.pageno col row pageopaque
2462 (CSTE.to_string colorspace
)
2464 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2465 angle gen
conf.angle
state.gen
2467 conf.tilew
conf.tileh
2474 let r = Str.regexp
" " in
2475 fun s -> Str.bounded_split
r s 2;
2478 let onpagerect pageno f =
2480 match conf.columns
with
2481 | Cmulti
(_, b) -> b
2483 | Csplit
(_, b) -> b
2485 if pageno >= 0 && pageno < Array.length
b
2487 let (_, _, _, (w, h, _, _)) = b.(pageno) in
2491 let gotopagexy1 pageno x y =
2492 let _,w1,h1
,leftx
= getpagedim pageno in
2493 let top = y /. (float h1
) in
2494 let left = x /. (float w1) in
2495 let py, w, h = getpageywh pageno in
2496 let wh = state.winh
- hscrollh () in
2497 let x = left *. (float w) in
2498 let x = leftx
+ state.x + truncate
x in
2500 if x < 0 || x >= wadjsb state.winw
2504 let pdy = truncate
(top *. float h) in
2505 let y'
= py + pdy in
2506 let dy = y'
- state.y in
2508 if x != state.x || not
(dy > 0 && dy < wh)
2510 if conf.presentation
2512 if abs
(py - y'
) > wh
2519 if state.x != sx || state.y != sy
2524 let ww = wadjsb state.winw
in
2526 and qy
= pdy / wh in
2528 and y = py + qy
* wh in
2529 let x = if -x + ww > w1 then -(w1-ww) else x
2530 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2532 if conf.presentation
2534 if abs
(py - y'
) > wh
2544 gotoy_and_clear_text y;
2546 else gotoy_and_clear_text state.y;
2549 let gotopagexy pageno x y =
2550 match state.mode
with
2551 | Birdseye
_ -> gotopage pageno 0.0
2552 | _ -> gotopagexy1 pageno x y
2556 (* dolog "%S" cmds; *)
2557 let cl = splitatspace cmds
in
2559 try Scanf.sscanf
s fmt
f
2561 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2566 state.uioh#infochanged Pdim
;
2569 | "clearrects" :: [] ->
2570 state.rects
<- state.rects1
;
2571 G.postRedisplay "clearrects";
2573 | "continue" :: args :: [] ->
2574 let n = scan args "%u" (fun n -> n) in
2575 state.pagecount
<- n;
2576 begin match state.currently
with
2578 state.currently
<- Idle
;
2579 state.outlines
<- Array.of_list
(List.rev
l)
2583 let cur, cmds
= state.geomcmds
in
2585 then failwith
"umpossible";
2587 begin match List.rev cmds
with
2589 state.geomcmds
<- "", [];
2593 state.geomcmds
<- s, List.rev rest
;
2595 if conf.maxwait
= None
&& not
!wtmode
2596 then G.postRedisplay "continue";
2598 | "title" :: args :: [] ->
2601 | "msg" :: args :: [] ->
2604 | "vmsg" :: args :: [] ->
2606 then showtext ' '
args
2608 | "emsg" :: args :: [] ->
2609 Buffer.add_string
state.errmsgs
args;
2610 state.newerrmsgs
<- true;
2611 G.postRedisplay "error message"
2613 | "progress" :: args :: [] ->
2614 let progress, text =
2617 f, String.sub
args pos
(String.length
args - pos
))
2620 state.progress <- progress;
2621 G.postRedisplay "progress"
2623 | "firstmatch" :: args :: [] ->
2624 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2625 scan args "%u %d %f %f %f %f %f %f %f %f"
2626 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2627 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2629 let y = (getpagey pageno) + truncate
y0 in
2632 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2634 | "match" :: args :: [] ->
2635 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2636 scan args "%u %d %f %f %f %f %f %f %f %f"
2637 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2638 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2641 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2643 | "page" :: args :: [] ->
2644 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2645 begin match state.currently
with
2646 | Loading
(l, gen
) ->
2647 vlog "page %d took %f sec" l.pageno t
;
2648 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2649 begin match state.throttle
with
2651 let preloadedpages =
2653 then preloadlayout state.y
2658 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2659 IntSet.empty
preloadedpages
2662 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2663 if not
(IntSet.mem
pageno set)
2665 wcmd "freepage %s" opaque
;
2671 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2674 state.currently
<- Idle
;
2677 tilepage l.pageno pageopaque state.layout;
2679 load preloadedpages;
2680 if pagevisible state.layout l.pageno
2681 && layoutready state.layout
2682 then G.postRedisplay "page";
2685 | Some
(layout, _, _) ->
2686 state.currently
<- Idle
;
2687 tilepage l.pageno pageopaque layout;
2692 dolog
"Inconsistent loading state";
2693 logcurrently state.currently
;
2697 | "tile" :: args :: [] ->
2698 let (x, y, opaque
, size
, t
) =
2699 scan args "%u %u %s %u %f"
2700 (fun x y p size t
-> (x, y, p
, size
, t
))
2702 begin match state.currently
with
2703 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2704 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2707 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2709 wcmd "freetile %s" opaque
;
2710 state.currently
<- Idle
;
2714 puttileopaque l col row gen cs angle opaque size t
;
2715 state.memused
<- state.memused
+ size
;
2716 state.uioh#infochanged Memused
;
2718 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2719 opaque
, size
) state.tilelru
;
2722 match state.throttle
with
2723 | None
-> state.layout
2724 | Some
(layout, _, _) -> layout
2727 state.currently
<- Idle
;
2729 && conf.colorspace
= cs
2730 && conf.angle
= angle
2731 && tilevisible layout l.pageno x y
2732 then conttiling l.pageno pageopaque;
2734 begin match state.throttle
with
2736 preload state.layout;
2738 && conf.colorspace
= cs
2739 && conf.angle
= angle
2740 && tilevisible state.layout l.pageno x y
2741 && (not
!wtmode || layoutready state.layout)
2742 then G.postRedisplay "tile nothrottle";
2744 | Some
(layout, y, _) ->
2745 let ready = layoutready layout in
2749 state.layout <- layout;
2750 state.throttle
<- None
;
2751 G.postRedisplay "throttle";
2758 dolog
"Inconsistent tiling state";
2759 logcurrently state.currently
;
2763 | "pdim" :: args :: [] ->
2764 let (n, w, h, _) as pdim
=
2765 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2768 match conf.fitmodel
, conf.columns
with
2769 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2772 state.uioh#infochanged Pdim
;
2773 state.pdims
<- pdim :: state.pdims
2775 | "o" :: args :: [] ->
2776 let (l, n, t
, h, pos
) =
2777 scan args "%u %u %d %u %n"
2778 (fun l n t
h pos
-> l, n, t
, h, pos
)
2780 let s = String.sub
args pos
(String.length
args - pos
) in
2781 let outline = (s, l, Oanchor
(n, float t
/. float h, 0.0)) in
2782 begin match state.currently
with
2783 | Outlining outlines
->
2784 state.currently
<- Outlining
(outline :: outlines
)
2786 state.currently
<- Outlining
[outline]
2788 dolog
"invalid outlining state";
2789 logcurrently currently
2792 | "ou" :: args :: [] ->
2794 scan args "%u %u %n" (fun l len pos
-> l, len, pos
)
2796 let s = String.sub
args pos
len in
2797 let pos2 = pos
+ len + 1 in
2798 let uri = String.sub
args pos2 (String.length
args - pos2) in
2799 let outline = (s, l, Ouri
uri) in
2800 begin match state.currently
with
2801 | Outlining outlines
->
2802 state.currently
<- Outlining
(outline :: outlines
)
2804 state.currently
<- Outlining
[outline]
2806 dolog
"invalid outlining state";
2807 logcurrently currently
2810 | "a" :: args :: [] ->
2812 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2814 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2816 | "info" :: args :: [] ->
2817 state.docinfo
<- (1, args) :: state.docinfo
2819 | "infoend" :: [] ->
2820 state.uioh#infochanged Docinfo
;
2821 state.docinfo
<- List.rev
state.docinfo
2824 error
"unknown cmd `%S'" cmds
2829 let action = function
2830 | HCprev
-> cbget cb ~
-1
2831 | HCnext
-> cbget cb
1
2832 | HCfirst
-> cbget cb ~
-(cb
.rc)
2833 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2834 and cancel
() = cb
.rc <- rc
2838 let search pattern forward
=
2839 match conf.columns
with
2841 showtext '
!'
"searching does not work properly in split columns mode"
2843 if nonemptystr pattern
2846 match state.layout with
2849 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2851 wcmd "search %d %d %d %d,%s\000"
2852 (btod conf.icase
) pn py (btod forward
) pattern
;
2855 let intentry text key =
2857 if key >= 32 && key < 127
2863 let text = addchar text c in
2867 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2871 let linknentry text key =
2873 if key >= 32 && key < 127
2879 let text = addchar text c in
2883 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2891 let l = String.length
s in
2892 let rec loop pos
n = if pos
= l then n else
2893 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2894 loop (pos
+1) (n*26 + m)
2897 let rec loop n = function
2900 match getopaque l.pageno with
2901 | None
-> loop n rest
2903 let m = getlinkcount opaque
in
2906 let under = getlink opaque
n in
2909 else loop (n-m) rest
2911 loop n state.layout;
2915 let textentry text key =
2916 if key land 0xff00 = 0xff00
2918 else TEcont
(text ^ toutf8
key)
2921 let reqlayout angle fitmodel
=
2922 match state.throttle
with
2924 if nogeomcmds state.geomcmds
2925 then state.anchor <- getanchor ();
2926 conf.angle
<- angle
mod 360;
2929 match state.mode
with
2930 | LinkNav
_ -> state.mode
<- View
2933 conf.fitmodel
<- fitmodel
;
2934 invalidate "reqlayout"
2936 wcmd "reqlayout %d %d %d"
2937 conf.angle
(FMTE.to_int conf.fitmodel
) (stateh state.winh
)
2942 let settrim trimmargins trimfuzz
=
2943 if nogeomcmds state.geomcmds
2944 then state.anchor <- getanchor ();
2945 conf.trimmargins
<- trimmargins
;
2946 conf.trimfuzz
<- trimfuzz
;
2947 let x0, y0, x1, y1 = trimfuzz
in
2948 invalidate "settrim"
2950 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2955 match state.throttle
with
2957 let zoom = max
0.0001 zoom in
2958 if zoom <> conf.zoom
2960 state.prevzoom
<- (conf.zoom, state.x);
2962 reshape state.winw
state.winh
;
2963 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2966 | Some
(layout, y, started
) ->
2968 match conf.maxwait
with
2972 let dt = now () -. started
in
2980 let setcolumns mode columns coverA coverB
=
2981 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2985 then showtext '
!'
"split mode doesn't work in bird's eye"
2987 conf.columns
<- Csplit
(-columns
, [||]);
2995 conf.columns
<- Csingle
[||];
3000 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
3004 reshape state.winw
state.winh
;
3007 let enterbirdseye () =
3008 let zoom = float conf.thumbw
/. float state.winw
in
3009 let birdseyepageno =
3010 let cy = state.winh
/ 2 in
3014 let rec fold best
= function
3017 let d = cy - (l.pagedispy + l.pagevh/2)
3018 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
3019 if abs
d < abs dbest
3026 state.mode
<- Birdseye
(
3027 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
3030 conf.presentation
<- false;
3031 conf.interpagespace
<- 10;
3032 conf.hlinks
<- false;
3033 conf.fitmodel
<- FitProportional
;
3035 state.mstate
<- Mnone
;
3036 conf.maxwait
<- None
;
3038 match conf.beyecolumns
with
3041 Cmulti
((c, 0, 0), [||])
3042 | None
-> Csingle
[||]
3044 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3047 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
3052 reshape state.winw
state.winh
;
3055 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
3057 conf.zoom <- c.zoom;
3058 conf.presentation
<- c.presentation
;
3059 conf.interpagespace
<- c.interpagespace
;
3060 conf.maxwait
<- c.maxwait
;
3061 conf.hlinks
<- c.hlinks
;
3062 conf.fitmodel
<- c.fitmodel
;
3063 conf.beyecolumns
<- (
3064 match conf.columns
with
3065 | Cmulti
((c, _, _), _) -> Some
c
3067 | Csplit
_ -> failwith
"leaving bird's eye split mode"
3070 match c.columns
with
3071 | Cmulti
(c, _) -> Cmulti
(c, [||])
3072 | Csingle
_ -> Csingle
[||]
3073 | Csplit
(c, _) -> Csplit
(c, [||])
3077 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
3080 reshape state.winw
state.winh
;
3081 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
3085 let togglebirdseye () =
3086 match state.mode
with
3087 | Birdseye vals
-> leavebirdseye vals
true
3088 | View
-> enterbirdseye ()
3092 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3093 let pageno = max
0 (pageno - incr
) in
3094 let rec loop = function
3095 | [] -> gotopage1 pageno 0
3096 | l :: _ when l.pageno = pageno ->
3097 if l.pagedispy >= 0 && l.pagey = 0
3098 then G.postRedisplay "upbirdseye"
3099 else gotopage1 pageno 0
3100 | _ :: rest
-> loop rest
3103 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
3106 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
3107 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
3108 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
3109 let rec loop = function
3111 let y, h = getpageyh pageno in
3112 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
3114 | l :: _ when l.pageno = pageno ->
3115 if l.pagevh != l.pageh
3116 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
3117 else G.postRedisplay "downbirdseye"
3118 | _ :: rest
-> loop rest
3123 let optentry mode
_ key =
3124 let btos b = if b then "on" else "off" in
3125 if key >= 32 && key < 127
3127 let c = Char.chr
key in
3131 try conf.scrollstep
<- int_of_string
s with exc
->
3132 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3134 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3139 conf.autoscrollstep
<- int_of_string
s;
3140 if state.autoscroll
<> None
3141 then state.autoscroll
<- Some
conf.autoscrollstep
3143 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3145 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3150 let n, a, b = multicolumns_of_string s in
3151 setcolumns mode
n a b;
3153 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3155 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3160 let zoom = float (int_of_string
s) /. 100.0 in
3163 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3165 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3170 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3172 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3173 begin match mode
with
3175 leavebirdseye beye
false;
3180 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3182 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3187 Some
(int_of_string
s)
3189 state.text <- Printf.sprintf
"bad integer `%s': %s"
3193 | Some angle
-> reqlayout angle
conf.fitmodel
3196 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3199 conf.icase
<- not
conf.icase
;
3200 TEdone
("case insensitive search " ^
(btos conf.icase
))
3203 conf.preload <- not
conf.preload;
3205 TEdone
("preload " ^
(btos conf.preload))
3208 conf.verbose
<- not
conf.verbose
;
3209 TEdone
("verbose " ^
(btos conf.verbose
))
3212 conf.debug
<- not
conf.debug
;
3213 TEdone
("debug " ^
(btos conf.debug
))
3216 conf.maxhfit
<- not
conf.maxhfit
;
3217 state.maxy
<- calcheight ();
3218 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3221 conf.crophack
<- not
conf.crophack
;
3222 TEdone
("crophack " ^
btos conf.crophack
)
3226 match conf.maxwait
with
3228 conf.maxwait
<- Some infinity
;
3229 "always wait for page to complete"
3231 conf.maxwait
<- None
;
3232 "show placeholder if page is not ready"
3237 conf.underinfo
<- not
conf.underinfo
;
3238 TEdone
("underinfo " ^
btos conf.underinfo
)
3241 conf.savebmarks
<- not
conf.savebmarks
;
3242 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3248 match state.layout with
3253 conf.interpagespace
<- int_of_string
s;
3254 docolumns conf.columns
;
3255 state.maxy
<- calcheight ();
3256 let y = getpagey pageno in
3259 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3261 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3265 match conf.fitmodel
with
3266 | FitProportional
-> FitWidth
3267 | _ -> FitProportional
3269 reqlayout conf.angle
fm;
3270 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3273 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3274 TEdone
("trim margins " ^
btos conf.trimmargins
)
3277 conf.invert
<- not
conf.invert
;
3278 TEdone
("invert colors " ^
btos conf.invert
)
3282 cbput state.hists
.sel
s;
3285 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3286 textentry, ondone, true)
3290 then conf.pax
<- Some
(ref (0.0, 0, 0))
3291 else conf.pax
<- None
;
3292 TEdone
("PAX " ^
btos (conf.pax
!= None
))
3295 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3301 class type lvsource
= object
3302 method getitemcount
: int
3303 method getitem
: int -> (string * int)
3304 method hasaction
: int -> bool
3313 method getactive
: int
3314 method getfirst
: int
3315 method getqsearch
: string
3316 method setqsearch
: string -> unit
3320 class virtual lvsourcebase
= object
3321 val mutable m_active
= 0
3322 val mutable m_first
= 0
3323 val mutable m_qsearch
= ""
3324 val mutable m_pan
= 0
3325 method getactive
= m_active
3326 method getfirst
= m_first
3327 method getqsearch
= m_qsearch
3328 method getpan
= m_pan
3329 method setqsearch
s = m_qsearch
<- s
3332 let withoutlastutf8 s =
3333 let len = String.length
s in
3341 let b = Char.code
s.[pos
] in
3342 if b land 0b11000000 = 0b11000000
3347 if Char.code
s.[len-1] land 0x80 = 0
3351 String.sub
s 0 first;
3354 let textentrykeyboard
3355 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3357 if key >= 0xffb0 && key <= 0xffb9
3358 then key - 0xffb0 + 48 else key
3361 state.mode
<- Textentry
(te
, onleave
);
3364 G.postRedisplay "textentrykeyboard enttext";
3366 let histaction cmd
=
3369 | Some
(action, _) ->
3370 state.mode
<- Textentry
(
3371 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3373 G.postRedisplay "textentry histaction"
3376 | 0xff08 -> (* backspace *)
3377 if emptystr
text && cancelonempty
3380 G.postRedisplay "textentrykeyboard after cancel";
3383 let s = withoutlastutf8 text in
3384 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3386 | 0xff0d | 0xff8d -> (* (kp) enter *)
3389 G.postRedisplay "textentrykeyboard after confirm"
3391 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3392 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3393 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3394 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3396 | 0xff1b -> (* escape*)
3399 begin match opthist
with
3401 | Some
(_, onhistcancel
) -> onhistcancel
()
3405 G.postRedisplay "textentrykeyboard after cancel2"
3408 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3411 | 0xff9f | 0xffff -> () (* delete *)
3414 && key land 0xff00 != 0xff00 (* keyboard *)
3415 && key land 0xfe00 != 0xfe00 (* xkb *)
3416 && key land 0xfd00 != 0xfd00 (* 3270 *)
3418 begin match onkey
text key with
3422 G.postRedisplay "textentrykeyboard after confirm2";
3425 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3429 G.postRedisplay "textentrykeyboard after cancel3"
3432 state.mode
<- Textentry
(te
, onleave
);
3433 G.postRedisplay "textentrykeyboard switch";
3437 vlog "unhandled key %s" (Wsi.keyname
key)
3440 let firstof first active
=
3441 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3442 then max
0 (active
- (fstate.maxrows
/2))
3446 let calcfirst first active
=
3449 let rows = active
- first in
3450 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3454 let scrollph y maxy
=
3455 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3456 let sh = float state.winh
/. sh in
3457 let sh = max
sh (float conf.scrollh
) in
3459 let percent = float y /. float maxy
in
3460 let position = (float state.winh
-. sh) *. percent in
3463 if position +. sh > float state.winh
3464 then float state.winh
-. sh
3470 let coe s = (s :> uioh
);;
3472 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3474 val m_pan
= source#getpan
3475 val m_first
= source#getfirst
3476 val m_active
= source#getactive
3477 val m_qsearch
= source#getqsearch
3478 val m_prev_uioh
= state.uioh
3480 method private elemunder
y =
3481 let n = y / (fstate.fontsize
+1) in
3482 if m_first
+ n < source#getitemcount
3484 if source#hasaction
(m_first
+ n)
3485 then Some
(m_first
+ n)
3492 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3493 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3494 filledrect 0. 0. (float state.winw
) (float state.winh
);
3495 GlDraw.color
(1., 1., 1.);
3496 Gl.enable `texture_2d
;
3497 let fs = fstate.fontsize
in
3499 let ww = fstate.wwidth
in
3500 let tabw = 30.0*.ww in
3501 let itemcount = source#getitemcount
in
3503 if (row - m_first
) > fstate.maxrows
3506 if row >= 0 && row < itemcount
3508 let (s, level
) = source#getitem
row in
3509 let y = (row - m_first
) * nfs in
3510 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3513 Gl.disable `texture_2d
;
3514 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3515 GlDraw.color
(1., 1., 1.) ~
alpha;
3516 linerect 1. (float (y + 1))
3517 (float (state.winw
- conf.scrollbw
- 1)) (float (y + fs + 3));
3518 GlDraw.color
(1., 1., 1.);
3519 Gl.enable `texture_2d
;
3522 let drawtabularstring s =
3523 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3526 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3529 let len = String.length
s - tabpos - 1 in
3530 let s1 = String.sub
s 0 tabpos
3531 and s2
= String.sub
s (tabpos + 1) len in
3532 let nx = drawstr x s1 in
3534 let x = x +. (max
tabw sw) in
3541 let _ = drawtabularstring s in
3548 Gl.disable `texture_2d
;
3550 method updownlevel incr
=
3551 let len = source#getitemcount
in
3553 if m_active
>= 0 && m_active
< len
3554 then snd
(source#getitem m_active
)
3558 if i
= len then i
-1 else if i
= -1 then 0 else
3559 let _, l = source#getitem i
in
3560 if l != curlevel then i
else flow (i
+incr
)
3562 let active = flow m_active
in
3563 let first = calcfirst m_first
active in
3564 G.postRedisplay "outline updownlevel";
3565 {< m_active
= active; m_first
= first >}
3567 method private key1
key mask
=
3568 let set1 active first qsearch
=
3569 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3571 let search active pattern incr
=
3572 let active = if active = -1 then m_first
else active in
3575 if n >= 0 && n < source#getitemcount
3577 let s, _ = source#getitem
n in
3579 (try ignore
(Str.search_forward
re s 0); true
3580 with Not_found
-> false)
3582 else loop (n + incr
)
3589 let re = Str.regexp_case_fold pattern
in
3595 let itemcount = source#getitemcount
in
3596 let find start incr
=
3598 if i
= -1 || i
= itemcount
3601 if source#hasaction i
3603 else find (i
+ incr
)
3608 let set active first =
3609 let first = bound first 0 (itemcount - fstate.maxrows
) in
3611 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3614 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3616 let incr1 = if incr
> 0 then 1 else -1 in
3617 if isvisible m_first m_active
3620 let next = m_active
+ incr
in
3622 if next < 0 || next >= itemcount
3624 else find next incr1
3626 if abs
(m_active
- next) > fstate.maxrows
3632 let first = m_first
+ incr
in
3633 let first = bound first 0 (itemcount - fstate.maxrows
) in
3635 let next = m_active
+ incr
in
3636 let next = bound next 0 (itemcount - 1) in
3643 if isvisible first next
3650 let first = min
next m_first
in
3652 if abs
(next - first) > fstate.maxrows
3658 let first = m_first
+ incr
in
3659 let first = bound first 0 (itemcount - 1) in
3661 let next = m_active
+ incr
in
3662 let next = bound next 0 (itemcount - 1) in
3663 let next = find next incr1 in
3665 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3667 let active = if m_active
= -1 then next else m_active
in
3672 if isvisible first active
3678 G.postRedisplay "listview navigate";
3682 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3683 let incr = if key = 0x72 then -1 else 1 in
3685 match search (m_active
+ incr) m_qsearch
incr with
3687 state.text <- m_qsearch ^
" [not found]";
3690 state.text <- m_qsearch
;
3691 active, firstof m_first
active
3693 G.postRedisplay "listview ctrl-r/s";
3694 set1 active first m_qsearch
;
3696 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3697 if m_active
>= 0 && m_active
< source#getitemcount
3699 let s, _ = source#getitem m_active
in
3704 | 0xff08 -> (* backspace *)
3705 if emptystr m_qsearch
3708 let qsearch = withoutlastutf8 m_qsearch
in
3712 G.postRedisplay "listview empty qsearch";
3713 set1 m_active m_first
"";
3717 match search m_active
qsearch ~
-1 with
3719 state.text <- qsearch ^
" [not found]";
3722 state.text <- qsearch;
3723 active, firstof m_first
active
3725 G.postRedisplay "listview backspace qsearch";
3726 set1 active first qsearch
3729 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3730 let pattern = m_qsearch ^ toutf8
key in
3732 match search m_active
pattern 1 with
3734 state.text <- pattern ^
" [not found]";
3737 state.text <- pattern;
3738 active, firstof m_first
active
3740 G.postRedisplay "listview qsearch add";
3741 set1 active first pattern;
3743 | 0xff1b -> (* escape *)
3745 if emptystr m_qsearch
3747 G.postRedisplay "list view escape";
3750 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3752 | None
-> m_prev_uioh
3757 G.postRedisplay "list view kill qsearch";
3758 source#setqsearch
"";
3759 coe {< m_qsearch
= "" >}
3762 | 0xff0d | 0xff8d -> (* (kp) enter *)
3764 let self = {< m_qsearch
= "" >} in
3765 source#setqsearch
"";
3767 G.postRedisplay "listview enter";
3768 if m_active
>= 0 && m_active
< source#getitemcount
3770 source#exit
(coe self) false m_active m_first m_pan
"";
3773 source#exit
(coe self) true m_active m_first m_pan
"";
3776 begin match opt with
3777 | None
-> m_prev_uioh
3781 | 0xff9f | 0xffff -> (* (kp) delete *)
3784 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3785 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3786 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3787 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3789 | 0xff53 | 0xff98 -> (* (kp) right *)
3791 G.postRedisplay "listview right";
3792 coe {< m_pan
= m_pan
- 1 >}
3794 | 0xff51 | 0xff96 -> (* (kp) left *)
3796 G.postRedisplay "listview left";
3797 coe {< m_pan
= m_pan
+ 1 >}
3799 | 0xff50 | 0xff95 -> (* (kp) home *)
3800 let active = find 0 1 in
3801 G.postRedisplay "listview home";
3804 | 0xff57 | 0xff9c -> (* (kp) end *)
3805 let first = max
0 (itemcount - fstate.maxrows
) in
3806 let active = find (itemcount - 1) ~
-1 in
3807 G.postRedisplay "listview end";
3810 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3814 dolog
"listview unknown key %#x" key; coe self
3816 method key key mask
=
3817 match state.mode
with
3818 | Textentry te
-> textentrykeyboard key mask te
; coe self
3819 | _ -> self#key1
key mask
3821 method button button down
x y _ =
3824 | 1 when x > state.winw
- conf.scrollbw
->
3825 G.postRedisplay "listview scroll";
3828 let _, position, sh = self#
scrollph in
3829 if y > truncate
position && y < truncate
(position +. sh)
3831 state.mstate
<- Mscrolly
;
3835 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3836 let first = truncate
(s *. float source#getitemcount
) in
3837 let first = min source#getitemcount
first in
3838 Some
(coe {< m_first
= first; m_active
= first >})
3840 state.mstate
<- Mnone
;
3843 | 1 when not down
->
3844 begin match self#elemunder
y with
3846 G.postRedisplay "listview click";
3848 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3852 | n when (n == 4 || n == 5) && not down
->
3853 let len = source#getitemcount
in
3855 if n = 5 && m_first
+ fstate.maxrows
>= len
3859 let first = m_first
+ (if n == 4 then -1 else 1) in
3860 bound first 0 (len - 1)
3862 G.postRedisplay "listview wheel";
3863 Some
(coe {< m_first
= first >})
3864 | n when (n = 6 || n = 7) && not down
->
3865 let inc = if n = 7 then -1 else 1 in
3866 G.postRedisplay "listview hwheel";
3867 Some
(coe {< m_pan
= m_pan
+ inc >})
3872 | None
-> m_prev_uioh
3876 match state.mstate
with
3878 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3879 let first = truncate
(s *. float source#getitemcount
) in
3880 let first = min source#getitemcount
first in
3881 G.postRedisplay "listview motion";
3882 coe {< m_first
= first; m_active
= first >}
3885 method pmotion
x y =
3886 if x < state.winw
- conf.scrollbw
3889 match self#elemunder
y with
3890 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3891 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3895 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3900 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3904 method infochanged
_ = ()
3906 method scrollpw
= (0, 0.0, 0.0)
3908 let nfs = fstate.fontsize
+ 1 in
3909 let y = m_first
* nfs in
3910 let itemcount = source#getitemcount
in
3911 let maxi = max
0 (itemcount - fstate.maxrows
) in
3912 let maxy = maxi * nfs in
3913 let p, h = scrollph y maxy in
3916 method modehash
= modehash
3917 method eformsgs
= false
3920 class outlinelistview ~source
=
3921 let settext autonarrow
s =
3923 then state.text <- "[" ^
s ^
"]"
3924 else state.text <- s
3928 ~source
:(source
:> lvsource
)
3930 ~modehash
:(findkeyhash conf "outline")
3933 val m_autonarrow
= false
3935 method key key mask
=
3937 if emptystr
state.text
3939 else fstate.maxrows - 2
3941 let calcfirst first active =
3944 let rows = active - first in
3945 if rows > maxrows then active - maxrows else first
3949 let active = m_active
+ incr in
3950 let active = bound active 0 (source#getitemcount
- 1) in
3951 let first = calcfirst m_first
active in
3952 G.postRedisplay "outline navigate";
3953 coe {< m_active
= active; m_first
= first >}
3955 let navscroll first =
3957 let dist = m_active
- first in
3963 else first + maxrows
3966 G.postRedisplay "outline navscroll";
3967 coe {< m_first
= first; m_active
= active >}
3969 let ctrl = Wsi.withctrl mask
in
3971 | 97 when ctrl -> (* ctrl-a *)
3973 then source#denarrow
3974 else source#narrow m_qsearch
;
3975 settext (not m_autonarrow
) m_qsearch
;
3976 G.postRedisplay "toggle auto narrowing";
3977 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
3979 | 47 when emptystr m_qsearch
&& not m_autonarrow
-> (* / *)
3981 G.postRedisplay "toggle auto narrowing";
3982 coe {< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
3984 | 110 when ctrl -> (* ctrl-n *)
3985 source#narrow m_qsearch
;
3987 then source#add_narrow_pattern m_qsearch
;
3988 G.postRedisplay "outline ctrl-n";
3989 coe {< m_first
= 0; m_active
= 0 >}
3991 | 115 when ctrl -> (* ctrl-s *)
3992 let active = source#calcactive
(getanchor ()) in
3993 let first = firstof m_first
active in
3994 G.postRedisplay "outline ctrl-s";
3995 coe {< m_first
= first; m_active
= active >}
3997 | 117 when ctrl -> (* ctrl-u *)
3998 source#del_narrow_pattern
;
3999 let pattern = source#renarrow
in
4000 G.postRedisplay "outline ctrl-u";
4002 if emptystr
pattern then "" else "Narrowed to " ^
pattern
4004 settext m_autonarrow
text;
4005 coe {< m_first
= 0; m_active
= 0; m_qsearch
= "" >}
4007 | 108 when ctrl -> (* ctrl-l *)
4008 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
4009 G.postRedisplay "outline ctrl-l";
4010 coe {< m_first
= first >}
4012 | 0xff1b -> (* escape *)
4013 let o = super#
key key mask
in
4016 if nonemptystr m_qsearch
4018 source#add_narrow_pattern m_qsearch
;
4024 | 0xff0d | 0xff8d when m_autonarrow
-> (* (kp) enter *)
4025 if nonemptystr m_qsearch
4026 then source#add_narrow_pattern m_qsearch
;
4029 | key when m_autonarrow
&& (key != 0 && key land 0xff00 != 0xff00) ->
4030 let pattern = m_qsearch ^ toutf8
key in
4031 G.postRedisplay "outlinelistview autonarrow add";
4032 source#narrow
pattern;
4033 settext true pattern;
4034 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4036 | key when m_autonarrow
&& key = 0xff08 -> (* backspace *)
4037 if emptystr m_qsearch
4040 let pattern = withoutlastutf8 m_qsearch
in
4041 G.postRedisplay "outlinelistview autonarrow backspace";
4042 ignore
(source#renarrow
);
4043 source#narrow
pattern;
4044 settext true pattern;
4045 coe {< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
4047 | 0xff9f | 0xffff -> (* (kp) delete *)
4048 source#remove m_active
;
4049 G.postRedisplay "outline delete";
4050 let active = max
0 (m_active
-1) in
4051 coe {< m_first
= firstof m_first
active;
4052 m_active
= active >}
4054 | 0xff52 | 0xff97 when ctrl -> (* ctrl-(kp) up *)
4055 navscroll (max
0 (m_first
- 1))
4057 | 0xff54 | 0xff99 when ctrl -> (* ctrl-(kp) down *)
4058 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
4060 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
4061 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
4062 | 0xff55 | 0xff9a -> (* (kp) prior *)
4063 navigate ~
-(fstate.maxrows)
4064 | 0xff56 | 0xff9b -> (* (kp) next *)
4065 navigate fstate.maxrows
4067 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
4071 G.postRedisplay "outline ctrl right";
4072 {< m_pan
= m_pan
+ 1 >}
4074 else self#updownlevel
1
4078 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
4082 G.postRedisplay "outline ctrl left";
4083 {< m_pan
= m_pan
- 1 >}
4085 else self#updownlevel ~
-1
4089 | 0xff50 | 0xff95 -> (* (kp) home *)
4090 G.postRedisplay "outline home";
4091 coe {< m_first
= 0; m_active
= 0 >}
4093 | 0xff57 | 0xff9c -> (* (kp) end *)
4094 let active = source#getitemcount
- 1 in
4095 let first = max
0 (active - fstate.maxrows) in
4096 G.postRedisplay "outline end";
4097 coe {< m_active
= active; m_first
= first >}
4099 | _ -> super#
key key mask
4102 let gotounder under =
4103 let getpath filename
=
4105 if nonemptystr filename
4107 if Filename.is_relative filename
4109 let dir = Filename.dirname
state.path in
4111 if Filename.is_implicit
dir
4112 then Filename.concat
(Sys.getcwd
()) dir
4115 Filename.concat
dir filename
4119 if Sys.file_exists
path
4124 | Ulinkgoto
(pageno, top) ->
4128 gotopage1 pageno top;
4134 | Uremote
(filename
, pageno) ->
4135 let path = getpath filename
in
4140 let command = !selfexec ^
" " ^
path in
4141 try popen command []
4144 "failed to execute `%s': %s\n" command (exntos exn
);
4147 let anchor = getanchor () in
4148 let ranchor = state.path, state.password
, anchor, state.origin
in
4150 state.anchor <- (pageno, 0.0, 0.0);
4151 state.ranchors
<- ranchor :: state.ranchors
;
4154 else showtext '
!'
("Could not find " ^ filename
)
4156 | Uremotedest
(filename
, destname
) ->
4157 let path = getpath filename
in
4162 let command = !selfexec ^
" " ^
path ^
" -dest " ^ destname
in
4163 try popen command []
4166 "failed to execute `%s': %s\n" command (exntos exn
);
4169 let anchor = getanchor () in
4170 let ranchor = state.path, state.password
, anchor, state.origin
in
4172 state.nameddest
<- destname
;
4173 state.ranchors
<- ranchor :: state.ranchors
;
4176 else showtext '
!'
("Could not find " ^ filename
)
4178 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4181 let gotooutline (_, _, kind
) =
4185 let (pageno, y, _) = anchor in
4187 (if conf.presentation
then (pageno, y, 1.0) else anchor)
4189 Ulinkgoto
(pageno, y)
4190 | Ouri
uri -> Ulinkuri
uri
4191 | Olaunch cmd
-> Ulaunch cmd
4192 | Oremote remote
-> Uremote remote
4193 | Oremotedest remotedest
-> Uremotedest remotedest
4198 let outlinesource usebookmarks
=
4201 inherit lvsourcebase
4202 val mutable m_items
= empty
4203 val mutable m_orig_items
= empty
4204 val mutable m_narrow_patterns
= []
4205 val mutable m_hadremovals
= false
4207 method getitemcount
=
4208 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
4211 if n == Array.length m_items
&& m_hadremovals
4213 ("[Confirm removal]", 0)
4215 let s, n, _ = m_items
.(n) in
4218 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4219 ignore
(uioh
, first, qsearch);
4220 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
4222 if m_narrow_patterns
= []
4228 if not
confrimremoval
4230 gotooutline m_items
.(active);
4234 state.bookmarks
<- Array.to_list m_items
;
4235 m_orig_items
<- m_items
;
4238 else m_items
<- items;
4242 method hasaction
_ = true
4245 if Array.length m_items
!= Array.length m_orig_items
4248 match m_narrow_patterns
with
4250 | many
-> String.concat
"\xe2\x80\xa6" (List.rev many
)
4252 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
4255 method narrow
pattern =
4256 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
4260 let rec loop accu n =
4262 then m_items
<- Array.of_list
accu
4264 let (s, _, _) as o = m_items
.(n) in
4266 if (try ignore
(Str.search_forward
re s 0); true
4267 with Not_found
-> false)
4273 loop [] (Array.length m_items
- 1)
4278 then Array.of_list
state.bookmarks
4281 m_items
<- m_orig_items
4286 if m >= 0 && m < Array.length m_items
4288 m_hadremovals
<- true;
4289 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
4290 let n = if n >= m then n+1 else n in
4295 method add_narrow_pattern
pattern =
4296 m_narrow_patterns
<- pattern :: m_narrow_patterns
4298 method del_narrow_pattern
=
4299 match m_narrow_patterns
with
4300 | _ :: rest
-> m_narrow_patterns
<- rest
4305 match m_narrow_patterns
with
4306 | pattern :: [] -> self#narrow
pattern; pattern
4308 List.fold_left
(fun accu pattern ->
4309 self#narrow
pattern;
4310 pattern ^
"\xe2\x80\xa6" ^
accu) "" list
4312 method calcactive
anchor =
4313 let rely = getanchory anchor in
4314 let rec loop n best bestd
=
4315 if n = Array.length m_items
4318 let _, _, kind
= m_items
.(n) in
4321 let orely = getanchory anchor in
4322 let d = abs
(orely - rely) in
4325 else loop (n+1) best bestd
4326 | Oremote
_ | Olaunch
_ | Oremotedest
_ | Ouri
_ ->
4327 loop (n+1) best bestd
4331 method reset
anchor items =
4332 m_hadremovals
<- false;
4333 if m_orig_items
== empty
4335 m_orig_items
<- items;
4336 if m_narrow_patterns
== []
4337 then m_items
<- items;
4339 let active = self#calcactive
anchor in
4341 m_first
<- firstof m_first
active
4345 let enterselector usebookmarks
=
4346 let source = outlinesource usebookmarks
in
4350 then Array.of_list
state.bookmarks
4353 if Array.length
outlines = 0
4355 showtext ' ' errmsg
;
4358 state.text <- source#greetmsg
;
4359 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4360 let anchor = getanchor () in
4361 source#reset
anchor outlines;
4362 state.uioh
<- coe (new outlinelistview ~
source);
4363 G.postRedisplay "enter selector";
4367 let enteroutlinemode =
4368 let f = enterselector false in
4369 fun ()-> f "Document has no outline";
4372 let enterbookmarkmode =
4373 let f = enterselector true in
4374 fun () -> f "Document has no bookmarks (yet)";
4377 let color_of_string s =
4378 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4379 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4383 let color_to_string (r, g, b) =
4384 let r = truncate
(r *. 256.0)
4385 and g = truncate
(g *. 256.0)
4386 and b = truncate
(b *. 256.0) in
4387 Printf.sprintf
"%d/%d/%d" r g b
4390 let irect_of_string s =
4391 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4394 let irect_to_string (x0,y0,x1,y1) =
4395 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4398 let makecheckers () =
4399 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4401 converted by Issac Trotts. July 25, 2002 *)
4402 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4403 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4404 let id = GlTex.gen_texture
() in
4405 GlTex.bind_texture `texture_2d
id;
4406 GlPix.store
(`unpack_alignment
1);
4407 GlTex.image2d
image;
4408 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4409 [ `mag_filter `nearest
; `min_filter `nearest
];
4413 let setcheckers enabled
=
4414 match state.texid
with
4416 if enabled
then state.texid
<- Some
(makecheckers ())
4421 GlTex.delete_texture texid
;
4422 state.texid
<- None
;
4426 let int_of_string_with_suffix s =
4427 let l = String.length
s in
4431 let suffix = Char.lowercase
s.[l-1] in
4433 | 'k'
-> String.sub
s 0 (l-1), 10
4434 | '
m'
-> String.sub
s 0 (l-1), 20
4435 | '
g'
-> String.sub
s 0 (l-1), 30
4439 let n = int_of_string
s1 in
4440 let m = n lsl shift
in
4442 then raise
(Failure
"value too large")
4446 let string_with_suffix_of_int n =
4450 let units = [(30, "G"); (20, "M"); (10, "K")] in
4453 let h = n mod 1000 in
4456 then string_of_int
h ^
s
4458 let s = Printf.sprintf
"_%03d%s" h s in
4464 let rec find = function
4466 | (shift
, suffix) :: rest
->
4467 if (n land ((1 lsl shift
) - 1)) = 0
4468 then prettyint (n lsr shift
) ^
suffix
4474 let defghyllscroll = (40, 8, 32);;
4475 let fastghyllscroll = (5,1,2);;
4476 let neatghyllscroll = (10,1,9);;
4477 let ghyllscroll_of_string s =
4479 | "default" -> Some
defghyllscroll
4480 | "fast" -> Some
(5,1,2)
4481 | "neat" -> Some
(10,1,9)
4482 | "" | "none" -> None
4484 let (n,a,b) as nab
=
4485 Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b) in
4486 if n <= a || n <= b || a >= b
4487 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
4492 let ghyllscroll_to_string ((n, a, b) as nab
) =
4493 (**) if nab
= defghyllscroll then "default"
4494 else if nab
= fastghyllscroll then "fast"
4495 else if nab
= neatghyllscroll then "neat"
4496 else Printf.sprintf
"%d,%d,%d" n a b;
4499 let describe_location () =
4500 let fn = page_of_y state.y in
4501 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4502 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4506 else (100. *. (float state.y /. float maxy))
4510 Printf.sprintf
"page %d of %d [%.2f%%]"
4511 (fn+1) state.pagecount
percent
4514 "pages %d-%d of %d [%.2f%%]"
4515 (fn+1) (ln+1) state.pagecount
percent
4518 let setpresentationmode v
=
4519 let n = page_of_y state.y in
4520 state.anchor <- (n, 0.0, 1.0);
4521 conf.presentation
<- v
;
4522 if conf.fitmodel
= FitPage
4523 then reqlayout conf.angle
conf.fitmodel
;
4528 let btos b = if b then "\xe2\x88\x9a" else "" in
4529 let showextended = ref false in
4530 let leave mode
= function
4531 | Confirm
-> state.mode
<- mode
4532 | Cancel
-> state.mode
<- mode
in
4535 val mutable m_first_time
= true
4536 val mutable m_l
= []
4537 val mutable m_a
= [||]
4538 val mutable m_prev_uioh
= nouioh
4539 val mutable m_prev_mode
= View
4541 inherit lvsourcebase
4543 method reset prev_mode prev_uioh
=
4544 m_a
<- Array.of_list
(List.rev m_l
);
4546 m_prev_mode
<- prev_mode
;
4547 m_prev_uioh
<- prev_uioh
;
4551 if n >= Array.length m_a
4555 | _, _, _, Action
_ -> m_active
<- n
4559 m_first_time
<- false;
4562 method int name get
set =
4564 (name, `
int get
, 1, Action
(
4567 try set (int_of_string
s)
4569 state.text <- Printf.sprintf
"bad integer `%s': %s"
4573 let te = name ^
": ", "", None
, intentry, ondone, true in
4574 state.mode
<- Textentry
(te, leave m_prev_mode
);
4578 method int_with_suffix
name get
set =
4580 (name, `intws get
, 1, Action
(
4583 try set (int_of_string_with_suffix s)
4585 state.text <- Printf.sprintf
"bad integer `%s': %s"
4590 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4592 state.mode
<- Textentry
(te, leave m_prev_mode
);
4596 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4598 (name, `
bool (btos, get
), offset
, Action
(
4605 method color
name get
set =
4607 (name, `color get
, 1, Action
(
4609 let invalid = (nan
, nan
, nan
) in
4612 try color_of_string s
4614 state.text <- Printf.sprintf
"bad color `%s': %s"
4621 let te = name ^
": ", "", None
, textentry, ondone, true in
4622 state.text <- color_to_string (get
());
4623 state.mode
<- Textentry
(te, leave m_prev_mode
);
4627 method string name get
set =
4629 (name, `
string get
, 1, Action
(
4631 let ondone s = set s in
4632 let te = name ^
": ", "", None
, textentry, ondone, true in
4633 state.mode
<- Textentry
(te, leave m_prev_mode
);
4637 method colorspace
name get
set =
4639 (name, `
string get
, 1, Action
(
4643 inherit lvsourcebase
4646 m_active
<- CSTE.to_int conf.colorspace
;
4649 method getitemcount
=
4650 Array.length
CSTE.names
4653 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4654 ignore
(uioh
, first, pan
, qsearch);
4655 if not cancel
then set active;
4657 method hasaction
_ = true
4661 let modehash = findkeyhash conf "info" in
4662 coe (new listview ~
source ~trusted
:true ~
modehash)
4665 method paxmark
name get
set =
4667 (name, `
string get
, 1, Action
(
4671 inherit lvsourcebase
4674 m_active
<- MTE.to_int conf.paxmark
;
4677 method getitemcount
= Array.length
MTE.names
4678 method getitem
n = (MTE.names.(n), 0)
4679 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4680 ignore
(uioh
, first, pan
, qsearch);
4681 if not cancel
then set active;
4683 method hasaction
_ = true
4687 let modehash = findkeyhash conf "info" in
4688 coe (new listview ~
source ~trusted
:true ~
modehash)
4691 method fitmodel
name get
set =
4693 (name, `
string get
, 1, Action
(
4697 inherit lvsourcebase
4700 m_active
<- FMTE.to_int conf.fitmodel
;
4703 method getitemcount
= Array.length
FMTE.names
4704 method getitem
n = (FMTE.names.(n), 0)
4705 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4706 ignore
(uioh
, first, pan
, qsearch);
4707 if not cancel
then set active;
4709 method hasaction
_ = true
4713 let modehash = findkeyhash conf "info" in
4714 coe (new listview ~
source ~trusted
:true ~
modehash)
4717 method caption
s offset
=
4718 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4720 method caption2
s f offset
=
4721 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4723 method getitemcount
= Array.length m_a
4726 let tostr = function
4727 | `
int f -> string_of_int
(f ())
4728 | `intws
f -> string_with_suffix_of_int (f ())
4730 | `color
f -> color_to_string (f ())
4731 | `
bool (btos, f) -> btos (f ())
4734 let name, t
, offset
, _ = m_a
.(n) in
4735 ((let s = tostr t
in
4737 then Printf.sprintf
"%s\t%s" name s
4741 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4745 m_qsearch
<- qsearch;
4747 match m_a
.(active) with
4748 | _, _, _, Action
f -> f uioh
4760 method hasaction
n =
4762 | _, _, _, Action
_ -> true
4766 let rec fillsrc prevmode prevuioh
=
4767 let sep () = src#caption
"" 0 in
4768 let colorp name get
set =
4770 (fun () -> color_to_string (get
()))
4773 let c = color_of_string v in
4776 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4779 let oldmode = state.mode
in
4780 let birdseye = isbirdseye state.mode
in
4782 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4784 src#
bool "presentation mode"
4785 (fun () -> conf.presentation
)
4786 (fun v -> setpresentationmode v);
4788 src#
bool "ignore case in searches"
4789 (fun () -> conf.icase
)
4790 (fun v -> conf.icase
<- v);
4793 (fun () -> conf.preload)
4794 (fun v -> conf.preload <- v);
4796 src#
bool "highlight links"
4797 (fun () -> conf.hlinks
)
4798 (fun v -> conf.hlinks
<- v);
4800 src#
bool "under info"
4801 (fun () -> conf.underinfo
)
4802 (fun v -> conf.underinfo
<- v);
4804 src#
bool "persistent bookmarks"
4805 (fun () -> conf.savebmarks
)
4806 (fun v -> conf.savebmarks
<- v);
4808 src#fitmodel
"fit model"
4809 (fun () -> FMTE.to_string conf.fitmodel
)
4810 (fun v -> reqlayout conf.angle
(FMTE.of_int v));
4812 src#
bool "trim margins"
4813 (fun () -> conf.trimmargins
)
4814 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4816 src#
bool "persistent location"
4817 (fun () -> conf.jumpback
)
4818 (fun v -> conf.jumpback
<- v);
4821 src#
int "inter-page space"
4822 (fun () -> conf.interpagespace
)
4824 conf.interpagespace
<- n;
4825 docolumns conf.columns
;
4827 match state.layout with
4832 state.maxy <- calcheight ();
4833 let y = getpagey pageno in
4838 (fun () -> conf.pagebias
)
4839 (fun v -> conf.pagebias
<- v);
4841 src#
int "scroll step"
4842 (fun () -> conf.scrollstep
)
4843 (fun n -> conf.scrollstep
<- n);
4845 src#
int "horizontal scroll step"
4846 (fun () -> conf.hscrollstep
)
4847 (fun v -> conf.hscrollstep
<- v);
4849 src#
int "auto scroll step"
4851 match state.autoscroll
with
4853 | _ -> conf.autoscrollstep
)
4855 if state.autoscroll
<> None
4856 then state.autoscroll
<- Some
n;
4857 conf.autoscrollstep
<- n);
4860 (fun () -> truncate
(conf.zoom *. 100.))
4861 (fun v -> setzoom ((float v) /. 100.));
4864 (fun () -> conf.angle
)
4865 (fun v -> reqlayout v conf.fitmodel
);
4867 src#
int "scroll bar width"
4868 (fun () -> conf.scrollbw
)
4871 reshape state.winw
state.winh
;
4874 src#
int "scroll handle height"
4875 (fun () -> conf.scrollh
)
4876 (fun v -> conf.scrollh
<- v;);
4878 src#
int "thumbnail width"
4879 (fun () -> conf.thumbw
)
4881 conf.thumbw
<- min
4096 v;
4884 leavebirdseye beye
false;
4889 let mode = state.mode in
4890 src#
string "columns"
4892 match conf.columns
with
4894 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4895 | Csplit
(count
, _) -> "-" ^ string_of_int count
4898 let n, a, b = multicolumns_of_string v in
4899 setcolumns mode n a b);
4902 src#caption
"Pixmap cache" 0;
4903 src#int_with_suffix
"size (advisory)"
4904 (fun () -> conf.memlimit
)
4905 (fun v -> conf.memlimit
<- v);
4908 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4909 (string_with_suffix_of_int state.memused
)
4910 (Hashtbl.length
state.tilemap
)) 1;
4913 src#caption
"Layout" 0;
4914 src#caption2
"Dimension"
4916 Printf.sprintf
"%dx%d (virtual %dx%d)"
4917 state.winw
state.winh
4922 src#caption2
"Position" (fun () ->
4923 Printf.sprintf
"%dx%d" state.x state.y
4926 src#caption2
"Position" (fun () -> describe_location ()) 1
4930 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4931 "Save these parameters as global defaults at exit"
4932 (fun () -> conf.bedefault
)
4933 (fun v -> conf.bedefault
<- v)
4937 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4938 src#
bool ~offset
:0 ~
btos "Extended parameters"
4939 (fun () -> !showextended)
4940 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4944 (fun () -> conf.checkers
)
4945 (fun v -> conf.checkers
<- v; setcheckers v);
4946 src#
bool "update cursor"
4947 (fun () -> conf.updatecurs
)
4948 (fun v -> conf.updatecurs
<- v);
4950 (fun () -> conf.verbose
)
4951 (fun v -> conf.verbose
<- v);
4952 src#
bool "invert colors"
4953 (fun () -> conf.invert
)
4954 (fun v -> conf.invert
<- v);
4956 (fun () -> conf.maxhfit
)
4957 (fun v -> conf.maxhfit
<- v);
4958 src#
bool "redirect stderr"
4959 (fun () -> conf.redirectstderr)
4960 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4962 (fun () -> conf.pax
!= None
)
4965 then conf.pax
<- Some
(ref (now (), 0, 0))
4966 else conf.pax
<- None
);
4967 src#
string "uri launcher"
4968 (fun () -> conf.urilauncher
)
4969 (fun v -> conf.urilauncher
<- v);
4970 src#
string "path launcher"
4971 (fun () -> conf.pathlauncher
)
4972 (fun v -> conf.pathlauncher
<- v);
4973 src#
string "tile size"
4974 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4977 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4978 conf.tilew
<- max
64 w;
4979 conf.tileh
<- max
64 h;
4982 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4985 src#
int "texture count"
4986 (fun () -> conf.texcount
)
4989 then conf.texcount
<- v
4990 else showtext '
!'
" Failed to set texture count please retry later"
4992 src#
int "slice height"
4993 (fun () -> conf.sliceheight
)
4995 conf.sliceheight
<- v;
4996 wcmd "sliceh %d" conf.sliceheight
;
4998 src#
int "anti-aliasing level"
4999 (fun () -> conf.aalevel
)
5001 conf.aalevel
<- bound v 0 8;
5002 state.anchor <- getanchor ();
5003 opendoc state.path state.password
;
5005 src#
string "page scroll scaling factor"
5006 (fun () -> string_of_float
conf.pgscale)
5009 let s = float_of_string
v in
5012 state.text <- Printf.sprintf
5013 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
5016 src#
int "ui font size"
5017 (fun () -> fstate.fontsize
)
5018 (fun v -> setfontsize (bound v 5 100));
5019 src#
int "hint font size"
5020 (fun () -> conf.hfsize
)
5021 (fun v -> conf.hfsize
<- bound v 5 100);
5022 colorp "background color"
5023 (fun () -> conf.bgcolor
)
5024 (fun v -> conf.bgcolor
<- v);
5025 src#
bool "crop hack"
5026 (fun () -> conf.crophack
)
5027 (fun v -> conf.crophack
<- v);
5028 src#
string "trim fuzz"
5029 (fun () -> irect_to_string conf.trimfuzz
)
5032 conf.trimfuzz
<- irect_of_string v;
5034 then settrim true conf.trimfuzz
;
5036 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
5038 src#
string "throttle"
5040 match conf.maxwait
with
5041 | None
-> "show place holder if page is not ready"
5044 then "wait for page to fully render"
5046 "wait " ^ string_of_float
time
5047 ^
" seconds before showing placeholder"
5051 let f = float_of_string
v in
5053 then conf.maxwait
<- None
5054 else conf.maxwait
<- Some
f
5056 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
5058 src#
string "ghyll scroll"
5060 match conf.ghyllscroll
with
5062 | Some nab
-> ghyllscroll_to_string nab
5065 try conf.ghyllscroll
<- ghyllscroll_of_string v
5067 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
5069 src#
string "selection command"
5070 (fun () -> conf.selcmd
)
5071 (fun v -> conf.selcmd
<- v);
5072 src#
string "synctex command"
5073 (fun () -> conf.stcmd
)
5074 (fun v -> conf.stcmd
<- v);
5075 src#
string "pax command"
5076 (fun () -> conf.paxcmd
)
5077 (fun v -> conf.paxcmd
<- v);
5078 src#colorspace
"color space"
5079 (fun () -> CSTE.to_string conf.colorspace
)
5081 conf.colorspace
<- CSTE.of_int v;
5085 src#paxmark
"pax mark method"
5086 (fun () -> MTE.to_string conf.paxmark
)
5087 (fun v -> conf.paxmark
<- MTE.of_int v);
5091 (fun () -> conf.usepbo
)
5092 (fun v -> conf.usepbo
<- v);
5093 src#
bool "mouse wheel scrolls pages"
5094 (fun () -> conf.wheelbypage
)
5095 (fun v -> conf.wheelbypage
<- v);
5096 src#
bool "open remote links in a new instance"
5097 (fun () -> conf.riani
)
5098 (fun v -> conf.riani
<- v);
5102 src#caption
"Document" 0;
5103 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
5104 src#caption2
"Pages"
5105 (fun () -> string_of_int
state.pagecount
) 1;
5106 src#caption2
"Dimensions"
5107 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5111 src#caption
"Trimmed margins" 0;
5112 src#caption2
"Dimensions"
5113 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
5117 src#caption
"OpenGL" 0;
5118 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
5119 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
5122 src#caption
"Location" 0;
5123 if nonemptystr
state.origin
5124 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
5125 src#caption
("Path\t" ^ mbtoutf8
state.path) 1;
5127 src#reset prevmode prevuioh
;
5131 let prevmode = state.mode
5132 and prevuioh
= state.uioh in
5133 fillsrc prevmode prevuioh
;
5134 let source = (src :> lvsource
) in
5135 let modehash = findkeyhash conf "info" in
5136 state.uioh <- coe (object (self)
5137 inherit listview ~
source ~trusted
:true ~
modehash as super
5138 val mutable m_prevmemused
= 0
5139 method infochanged
= function
5141 if m_prevmemused
!= state.memused
5143 m_prevmemused
<- state.memused
;
5144 G.postRedisplay "memusedchanged";
5146 | Pdim
-> G.postRedisplay "pdimchanged"
5147 | Docinfo
-> fillsrc prevmode prevuioh
5149 method key key mask
=
5150 if not
(Wsi.withctrl mask
)
5153 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
5154 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
5155 | _ -> super#
key key mask
5156 else super#
key key mask
5158 G.postRedisplay "info";
5164 inherit lvsourcebase
5165 method getitemcount
= Array.length
state.help
5167 let s, l, _ = state.help
.(n) in
5170 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5174 m_qsearch
<- qsearch;
5175 match state.help
.(active) with
5176 | _, _, Action
f -> Some
(f uioh)
5186 method hasaction
n =
5187 match state.help
.(n) with
5188 | _, _, Action
_ -> true
5195 let modehash = findkeyhash conf "help" in
5196 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
5197 G.postRedisplay "help";
5202 let re = Str.regexp
"[\r\n]" in
5204 inherit lvsourcebase
5205 val mutable m_items
= [||]
5207 method getitemcount
= 1 + Array.length m_items
5212 else m_items
.(n-1), 0
5214 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
5219 then Buffer.clear
state.errmsgs
;
5220 m_qsearch
<- qsearch;
5227 method hasaction
n =
5231 state.newerrmsgs
<- false;
5232 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
5233 m_items
<- Array.of_list
l
5241 let source = (msgsource :> lvsource
) in
5242 let modehash = findkeyhash conf "listview" in
5243 state.uioh <- coe (object
5244 inherit listview ~
source ~trusted
:false ~
modehash as super
5247 then msgsource#reset
;
5250 G.postRedisplay "msgs";
5253 let quickbookmark ?title
() =
5254 match state.layout with
5260 let sec = Unix.gettimeofday
() in
5261 let tm = Unix.localtime
sec in
5262 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
5266 (tm.Unix.tm_year
+ 1900)
5269 | Some
title -> title
5271 state.bookmarks
<- (title, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5274 let setautoscrollspeed step goingdown
=
5275 let incr = max
1 ((abs step
) / 2) in
5276 let incr = if goingdown
then incr else -incr in
5277 let astep = step
+ incr in
5278 state.autoscroll
<- Some
astep;
5282 match conf.columns
with
5284 | _ -> state.x != 0 || conf.zoom > 1.0
5287 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
5289 let existsinrow pageno (columns
, coverA
, coverB
) p =
5290 let last = ((pageno - coverA
) mod columns
) + columns
in
5291 let rec any = function
5294 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
5298 then (if l.pageno = last then false else any rest
)
5306 match state.layout with
5308 let pageno = page_of_y state.y in
5309 gotoghyll (getpagey (pageno+1))
5311 match conf.columns
with
5313 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
5315 let y = clamp (pgscale state.winh
) in
5318 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5319 gotoghyll (getpagey pageno)
5320 | Cmulti
((c, _, _) as cl, _) ->
5321 if conf.presentation
5322 && (existsinrow l.pageno cl
5323 (fun l -> l.pageh
> l.pagey + l.pagevh))
5325 let y = clamp (pgscale state.winh
) in
5328 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5329 gotoghyll (getpagey pageno)
5331 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5333 let pagey, pageh
= getpageyh l.pageno in
5334 let pagey = pagey + pageh
* l.pagecol
in
5335 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5336 gotoghyll (pagey + pageh
+ ips)
5340 match state.layout with
5342 let pageno = page_of_y state.y in
5343 gotoghyll (getpagey (pageno-1))
5345 match conf.columns
with
5347 if conf.presentation
&& l.pagey != 0
5349 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5351 let pageno = max
0 (l.pageno-1) in
5352 gotoghyll (getpagey pageno)
5353 | Cmulti
((c, _, coverB
) as cl, _) ->
5354 if conf.presentation
&&
5355 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5357 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5360 if l.pageno = state.pagecount
- coverB
5364 let pageno = max
0 (l.pageno-decr) in
5365 gotoghyll (getpagey pageno)
5373 let pageno = max
0 (l.pageno-1) in
5374 let pagey, pageh
= getpageyh pageno in
5377 let pagey, pageh
= getpageyh l.pageno in
5378 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5383 let viewkeyboard key mask
=
5385 let mode = state.mode in
5386 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5389 G.postRedisplay "view:enttext"
5391 let ctrl = Wsi.withctrl mask
in
5393 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5399 | 0xff63 -> (* insert *)
5400 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5402 state.mode <- LinkNav
(Ltgendir
0);
5405 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5407 | 0xff1b | 113 -> (* escape / q *)
5408 begin match state.mstate
with
5410 state.mstate
<- Mnone
;
5411 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5412 G.postRedisplay "kill zoom rect";
5414 begin match state.mode with
5417 G.postRedisplay "esc leave linknav"
5419 match state.ranchors
with
5421 | (path, password
, anchor, origin
) :: rest
->
5422 state.ranchors
<- rest
;
5423 state.anchor <- anchor;
5424 state.origin
<- origin
;
5425 state.nameddest
<- "";
5426 opendoc path password
5430 | 0xff08 -> (* backspace *)
5431 gotoghyll (getnav ~
-1)
5439 G.postRedisplay "dehighlight";
5441 | 47 | 63 -> (* / ? *)
5442 let ondone isforw
s =
5443 cbput state.hists
.pat
s;
5444 state.searchpattern
<- s;
5447 let s = String.create
1 in
5448 s.[0] <- Char.chr
key;
5449 enttext (s, "", Some
(onhist state.hists
.pat
),
5450 textentry, ondone (key = 47), true)
5452 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5453 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5454 setzoom (conf.zoom +. incr)
5456 | 43 | 0xffab -> (* + *)
5459 try int_of_string
s with exc
->
5460 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5466 state.text <- "page bias is now " ^ string_of_int
n;
5469 enttext ("page bias: ", "", None
, intentry, ondone, true)
5471 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5472 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5473 setzoom (max
0.01 (conf.zoom -. decr))
5475 | 45 | 0xffad -> (* - *)
5476 let ondone msg
= state.text <- msg
in
5478 "option [acfhilpstvxACFPRSZTISM]: ", "", None
,
5479 optentry state.mode, ondone, true
5482 | 48 when ctrl -> (* ctrl-0 *)
5490 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5492 match conf.columns
with
5493 | Csingle
_ | Cmulti
_ -> 1
5494 | Csplit
(n, _) -> n
5496 let h = state.winh
-
5497 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5499 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5500 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5503 | 51 when ctrl -> (* ctrl-3 *)
5505 match conf.fitmodel
with
5506 | FitWidth
-> FitProportional
5507 | FitProportional
-> FitPage
5508 | FitPage
-> FitWidth
5510 state.text <- "fit model: " ^
FMTE.to_string fm;
5511 reqlayout conf.angle
fm
5513 | 0xffc6 -> (* f9 *)
5516 | 57 when ctrl -> (* ctrl-9 *)
5519 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5520 when not
ctrl -> (* 0..9 *)
5523 try int_of_string
s with exc
->
5524 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5530 cbput state.hists
.pag
(string_of_int
n);
5531 gotopage1 (n + conf.pagebias
- 1) 0;
5534 let pageentry text key =
5535 match Char.unsafe_chr
key with
5536 | '
g'
-> TEdone
text
5537 | _ -> intentry text key
5539 let text = "x" in text.[0] <- Char.chr
key;
5540 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5543 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5544 reshape state.winw
state.winh
;
5547 state.bzoom
<- not
state.bzoom
;
5549 showtext ' '
("block zoom " ^
if state.bzoom
then "on" else "off")
5552 conf.hlinks
<- not
conf.hlinks
;
5553 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5554 G.postRedisplay "toggle highlightlinks";
5557 state.glinks
<- true;
5558 let mode = state.mode in
5559 state.mode <- Textentry
(
5560 (":", "", None
, linknentry, linkndone gotounder, false),
5562 state.glinks
<- false;
5566 G.postRedisplay "view:linkent(F)"
5569 state.glinks
<- true;
5570 let mode = state.mode in
5571 state.mode <- Textentry
(
5573 ":", "", None
, linknentry, linkndone (fun under ->
5574 selstring (undertext under);
5578 state.glinks
<- false;
5582 G.postRedisplay "view:linkent"
5585 begin match state.autoscroll
with
5587 conf.autoscrollstep
<- step
;
5588 state.autoscroll
<- None
5590 if conf.autoscrollstep
= 0
5591 then state.autoscroll
<- Some
1
5592 else state.autoscroll
<- Some
conf.autoscrollstep
5595 | 112 when ctrl -> (* ctrl-p *)
5599 setpresentationmode (not
conf.presentation
);
5600 showtext ' '
("presentation mode " ^
5601 if conf.presentation
then "on" else "off");
5604 if List.mem
Wsi.Fullscreen
state.winstate
5605 then Wsi.reshape conf.cwinw
conf.cwinh
5606 else Wsi.fullscreen
()
5608 | 112 | 78 -> (* p|N *)
5609 search state.searchpattern
false
5611 | 110 | 0xffc0 -> (* n|F3 *)
5612 search state.searchpattern
true
5615 begin match state.layout with
5618 gotoghyll (getpagey l.pageno)
5624 | 0xff9f | 0xffff -> (* delete *)
5628 showtext ' '
(describe_location ());
5631 begin match state.layout with
5634 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5639 enterbookmarkmode ()
5641 | 104 | 0xffbe -> (* h|F1 *)
5647 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5652 match state.layout with
5657 (s, 0, Oanchor
(getanchor1 l)) :: state.bookmarks
5660 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5664 showtext ' '
"Quick bookmark added";
5667 begin match state.layout with
5669 let rect = getpdimrect
l.pagedimno
in
5673 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5674 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5676 (truncate
(rect.(1) -. rect.(0)),
5677 truncate
(rect.(3) -. rect.(0)))
5679 let w = truncate
((float w)*.conf.zoom)
5680 and h = truncate
((float h)*.conf.zoom) in
5683 state.anchor <- getanchor ();
5684 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5686 G.postRedisplay "z";
5691 | 120 -> state.roam
() (* x *)
5692 | 60 | 62 -> (* < > *)
5693 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5695 | 91 | 93 -> (* [ ] *)
5697 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5699 G.postRedisplay "brightness";
5701 | 99 when state.mode = View
-> (* [alt-]c *)
5706 let m = (wadjsb state.winw
- state.w) / 2 in
5708 gotoy_and_clear_text state.y
5712 match state.prevcolumns
with
5713 | None
-> (1, 0, 0), 1.0
5714 | Some
(columns
, z
) ->
5717 | Csplit
(c, _) -> -c, 0, 0
5718 | Cmulti
((c, a, b), _) -> c, a, b
5719 | Csingle
_ -> 1, 0, 0
5723 setcolumns View
c a b;
5726 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
5727 -> (* ctrl-shift- (kp) [up|down] *)
5728 let zoom, x = state.prevzoom
in
5732 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5733 begin match state.autoscroll
with
5735 begin match state.mode with
5736 | Birdseye beye
-> upbirdseye 1 beye
5739 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5741 if not
(Wsi.withshift mask
) && conf.presentation
5743 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5747 setautoscrollspeed n false
5750 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5751 begin match state.autoscroll
with
5753 begin match state.mode with
5754 | Birdseye beye
-> downbirdseye 1 beye
5757 then gotoy_and_clear_text (clamp (state.winh
/2))
5759 if not
(Wsi.withshift mask
) && conf.presentation
5761 else gotoy_and_clear_text (clamp conf.scrollstep
)
5765 setautoscrollspeed n true
5768 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5769 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5775 else conf.hscrollstep
5777 let dx = if key = 0xff51 || key = 0xff96 then dx else -dx in
5778 state.x <- panbound (state.x + dx);
5779 gotoy_and_clear_text state.y
5782 G.postRedisplay "left/right"
5785 | 0xff55 | 0xff9a -> (* (kp) prior *)
5789 match state.layout with
5791 | l :: _ -> state.y - l.pagey
5793 clamp (pgscale (-state.winh
))
5797 | 0xff56 | 0xff9b -> (* (kp) next *)
5801 match List.rev
state.layout with
5803 | l :: _ -> getpagey l.pageno
5805 clamp (pgscale state.winh
)
5809 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5811 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5812 gotoghyll (clamp state.maxy)
5815 when Wsi.withalt mask
-> (* alt-(kp) right *)
5816 gotoghyll (getnav 1)
5818 when Wsi.withalt mask
-> (* alt-(kp) left *)
5819 gotoghyll (getnav ~
-1)
5824 | 118 when conf.debug
-> (* v *)
5827 match getopaque l.pageno with
5830 let x0, y0, x1, y1 = pagebbox opaque
in
5831 let a,b = float x0, float y0 in
5832 let c,d = float x1, float y0 in
5833 let e,f = float x1, float y1 in
5834 let h,j
= float x0, float y1 in
5835 let rect = (a,b,c,d,e,f,h,j
) in
5837 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5839 G.postRedisplay "v";
5842 vlog "huh? %s" (Wsi.keyname
key)
5845 let linknavkeyboard key mask
linknav =
5846 let getpage pageno =
5847 let rec loop = function
5849 | l :: _ when l.pageno = pageno -> Some
l
5850 | _ :: rest
-> loop rest
5851 in loop state.layout
5853 let doexact (pageno, n) =
5854 match getopaque pageno, getpage pageno with
5855 | Some opaque
, Some
l ->
5856 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5858 let under = getlink opaque
n in
5859 G.postRedisplay "link gotounder";
5865 | 0xff50 -> (* home *)
5866 Some
(findlink opaque LDfirst
), -1
5868 | 0xff57 -> (* end *)
5869 Some
(findlink opaque LDlast
), 1
5871 | 0xff51 -> (* left *)
5872 Some
(findlink opaque
(LDleft
n)), -1
5874 | 0xff53 -> (* right *)
5875 Some
(findlink opaque
(LDright
n)), 1
5877 | 0xff52 -> (* up *)
5878 Some
(findlink opaque
(LDup
n)), -1
5880 | 0xff54 -> (* down *)
5881 Some
(findlink opaque
(LDdown
n)), 1
5886 begin match findpwl
l.pageno dir with
5890 state.mode <- LinkNav
(Ltgendir
dir);
5891 let y, h = getpageyh pageno in
5894 then y + h - state.winh
5899 begin match getopaque pageno, getpage pageno with
5900 | Some opaque
, Some
_ ->
5902 let ld = if dir > 0 then LDfirst
else LDlast
in
5905 begin match link with
5907 showlinktype (getlink opaque
m);
5908 state.mode <- LinkNav
(Ltexact
(pageno, m));
5909 G.postRedisplay "linknav jpage";
5916 begin match opt with
5917 | Some Lnotfound
-> pwl l dir;
5918 | Some
(Lfound
m) ->
5922 let _, y0, _, y1 = getlinkrect opaque
m in
5924 then gotopage1 l.pageno y0
5926 let d = fstate.fontsize
+ 1 in
5927 if y1 - l.pagey > l.pagevh - d
5928 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5929 else G.postRedisplay "linknav";
5931 showlinktype (getlink opaque
m);
5932 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5935 | None
-> viewkeyboard key mask
5937 | _ -> viewkeyboard key mask
5942 G.postRedisplay "leave linknav"
5946 | Ltgendir
_ -> viewkeyboard key mask
5947 | Ltexact exact
-> doexact exact
5950 let keyboard key mask
=
5951 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5952 then wcmd "interrupt"
5953 else state.uioh <- state.uioh#
key key mask
5956 let birdseyekeyboard key mask
5957 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5959 match conf.columns
with
5961 | Cmulti
((c, _, _), _) -> c
5962 | Csplit
_ -> failwith
"bird's eye split mode"
5964 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5966 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5967 let y, h = getpageyh pageno in
5968 let top = (state.winh
- h) / 2 in
5969 gotoy (max
0 (y - top))
5970 | 0xff0d (* enter *)
5971 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5972 | 0xff1b -> leavebirdseye beye
true (* escape *)
5973 | 0xff52 -> upbirdseye incr beye
(* up *)
5974 | 0xff54 -> downbirdseye incr beye
(* down *)
5975 | 0xff51 -> upbirdseye 1 beye
(* left *)
5976 | 0xff53 -> downbirdseye 1 beye
(* right *)
5978 | 0xff55 -> (* prior *)
5979 begin match state.layout with
5983 state.mode <- Birdseye
(
5984 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5986 gotopage1 l.pageno 0;
5989 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5991 | [] -> gotoy (clamp (-state.winh
))
5993 state.mode <- Birdseye
(
5994 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5996 gotopage1 l.pageno 0
5999 | [] -> gotoy (clamp (-state.winh
))
6002 | 0xff56 -> (* next *)
6003 begin match List.rev
state.layout with
6005 let layout = layout (state.y + (pgh state.layout)) state.winh
in
6006 begin match layout with
6008 let incr = l.pageh
- l.pagevh in
6013 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
6015 G.postRedisplay "birdseye pagedown";
6017 else gotoy (clamp (incr + conf.interpagespace
*2));
6021 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
6022 gotopage1 l.pageno 0;
6025 | [] -> gotoy (clamp state.winh
)
6028 | 0xff50 -> (* home *)
6029 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
6032 | 0xff57 -> (* end *)
6033 let pageno = state.pagecount
- 1 in
6034 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
6035 if not
(pagevisible state.layout pageno)
6038 match List.rev
state.pdims
with
6040 | (_, _, h, _) :: _ -> h
6042 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
6043 else G.postRedisplay "birdseye end";
6044 | _ -> viewkeyboard key mask
6049 match state.mode with
6050 | Textentry
_ -> scalecolor 0.4
6052 | View
-> scalecolor 1.0
6053 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
6054 if l.pageno = hooverpageno
6057 if l.pageno = pageno
6065 let postdrawpage l linkindexbase
=
6066 match getopaque l.pageno with
6068 if tileready l l.pagex
l.pagey
6070 let x = l.pagedispx - l.pagex
6071 and y = l.pagedispy - l.pagey in
6073 match conf.columns
with
6074 | Csingle
_ | Cmulti
_ ->
6075 (if conf.hlinks
then 1 else 0)
6077 && not
(isbirdseye state.mode) then 2 else 0)
6081 match state.mode with
6082 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
6085 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
6090 let scrollindicator () =
6091 let sbw, ph
, sh = state.uioh#
scrollph in
6092 let sbh, pw, sw = state.uioh#scrollpw
in
6094 GlDraw.color (0.64, 0.64, 0.64);
6096 (float (state.winw
- sbw)) 0.
6097 (float state.winw
) (float state.winh
)
6100 0. (float (state.winh
- sbh))
6101 (float (wadjsb state.winw
- 1)) (float state.winh
)
6103 GlDraw.color (0.0, 0.0, 0.0);
6106 (float (state.winw
- sbw)) ph
6107 (float state.winw
) (ph
+. sh)
6110 pw (float (state.winh
- sbh))
6111 (pw +. sw) (float state.winh
)
6116 match state.mstate
with
6117 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
6120 | Msel
((x0, y0), (x1, y1)) ->
6121 let rec loop = function
6123 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
6124 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
6125 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
6126 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
6128 match getopaque l.pageno with
6130 let x0, y0 = pagetranslatepoint l x0 y0 in
6131 let x1, y1 = pagetranslatepoint l x1 y1 in
6132 seltext opaque
(x0, y0, x1, y1);
6140 let showrects = function [] -> () | rects
->
6142 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
6143 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6145 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
6147 if l.pageno = pageno
6149 let dx = float (l.pagedispx - l.pagex
) in
6150 let dy = float (l.pagedispy - l.pagey) in
6151 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
6152 Raw.sets_float
state.vraw ~pos
:0
6157 GlArray.vertex `two
state.vraw
;
6158 GlArray.draw_arrays `triangle_strip
0 4;
6167 GlClear.color (scalecolor2 conf.bgcolor
);
6168 GlClear.clear
[`
color];
6169 List.iter
drawpage state.layout;
6171 match state.mode with
6172 | LinkNav
(Ltexact
(pageno, linkno
)) ->
6173 begin match getopaque pageno with
6175 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
6182 | None
-> state.rects
6187 let rec postloop linkindexbase
= function
6189 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
6190 postloop linkindexbase rest
6194 postloop 0 state.layout;
6196 begin match state.mstate
with
6197 | Mzoomrect
((x0, y0), (x1, y1)) ->
6199 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
6200 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
6201 filledrect (float x0) (float y0) (float x1) (float y1);
6210 let zoomrect x y x1 y1 =
6213 and y0 = min
y y1 in
6214 gotoy (state.y + y0);
6215 state.anchor <- getanchor ();
6216 let zoom = (float state.w) /. float (x1 - x0) in
6218 match conf.fitmodel
, conf.columns
with
6219 | FitPage
, Csplit
_ ->
6220 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
6223 let adjw = wadjsb state.winw
in
6225 then (adjw - state.w) / 2
6228 state.x <- (state.x + margin) - x0;
6230 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6231 state.mstate
<- Mnone
;
6235 let g opaque
l px py =
6236 match rectofblock opaque
px py with
6238 let x0 = a.(0) -. 20. in
6239 let x1 = a.(1) +. 20. in
6240 let y0 = a.(2) -. 20. in
6241 let zoom = (float state.w) /. (x1 -. x0) in
6242 let pagey = getpagey l.pageno in
6243 gotoy_and_clear_text (pagey + truncate
y0);
6244 state.anchor <- getanchor ();
6245 let margin = (state.w - l.pagew
)/2 in
6246 state.x <- -truncate
x0 - margin;
6251 match conf.columns
with
6253 showtext '
!'
"block zooming does not work properly in split columns mode"
6254 | _ -> onppundermouse g x y ()
6258 let winw = wadjsb state.winw - 1 in
6259 let s = float x /. float winw in
6260 let destx = truncate
(float (state.w + winw) *. s) in
6261 state.x <- winw - destx;
6262 gotoy_and_clear_text state.y;
6263 state.mstate
<- Mscrollx
;
6267 let s = float y /. float state.winh
in
6268 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
6269 gotoy_and_clear_text desty;
6270 state.mstate
<- Mscrolly
;
6273 let viewmouse button down
x y mask
=
6275 | n when (n == 4 || n == 5) && not down
->
6276 if Wsi.withctrl mask
6278 match state.mstate
with
6279 | Mzoom
(oldn
, i
) ->
6287 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
6289 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
6291 let zoom = conf.zoom -. incr in
6293 state.mstate
<- Mzoom
(n, 0);
6295 state.mstate
<- Mzoom
(n, i
+1);
6297 else state.mstate
<- Mzoom
(n, 0)
6299 | _ -> state.mstate
<- Mzoom
(n, 0)
6302 match state.autoscroll
with
6303 | Some step
-> setautoscrollspeed step
(n=4)
6305 if conf.wheelbypage
|| conf.presentation
6314 then -conf.scrollstep
6315 else conf.scrollstep
6317 let incr = incr * 2 in
6318 let y = clamp incr in
6319 gotoy_and_clear_text y
6322 | n when (n = 6 || n = 7) && not down
&& canpan () ->
6324 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
6325 gotoy_and_clear_text state.y
6327 | 1 when Wsi.withshift mask
->
6328 state.mstate
<- Mnone
;
6331 match unproject x y with
6332 | Some
(pageno, ux
, uy
) ->
6333 let cmd = Printf.sprintf
6335 conf.stcmd
state.path pageno ux uy
6341 | 1 when Wsi.withctrl mask
->
6344 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6345 state.mstate
<- Mpan
(x, y)
6348 state.mstate
<- Mnone
6353 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6355 state.mstate
<- Mzoomrect
(p, p)
6358 match state.mstate
with
6359 | Mzoomrect
((x0, y0), _) ->
6360 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6361 then zoomrect x0 y0 x y
6363 state.mstate
<- Mnone
;
6364 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6365 G.postRedisplay "kill accidental zoom rect";
6368 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6369 state.mstate
<- Mnone
6372 | 1 when x > state.winw - vscrollw () ->
6375 let _, position, sh = state.uioh#
scrollph in
6376 if y > truncate
position && y < truncate
(position +. sh)
6377 then state.mstate
<- Mscrolly
6380 state.mstate
<- Mnone
6382 | 1 when y > state.winh
- hscrollh () ->
6385 let _, position, sw = state.uioh#scrollpw
in
6386 if x > truncate
position && x < truncate
(position +. sw)
6387 then state.mstate
<- Mscrollx
6390 state.mstate
<- Mnone
6392 | 1 when state.bzoom
-> if not down
then zoomblock x y
6395 let dest = if down
then getunder x y else Unone
in
6396 begin match dest with
6399 | Uremote
_ | Uremotedest
_
6400 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6403 | Unone
when down
->
6404 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6405 state.mstate
<- Mpan
(x, y);
6407 | Unone
| Utext
_ ->
6410 if conf.angle
mod 360 = 0
6412 state.mstate
<- Msel
((x, y), (x, y));
6413 G.postRedisplay "mouse select";
6417 match state.mstate
with
6420 | Mzoom
_ | Mscrollx
| Mscrolly
->
6421 state.mstate
<- Mnone
6423 | Mzoomrect
((x0, y0), _) ->
6427 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6428 state.mstate
<- Mnone
6430 | Msel
((x0, y0), (x1, y1)) ->
6431 let rec loop = function
6435 let a0 = l.pagedispy in
6436 let a1 = a0 + l.pagevh in
6437 let b0 = l.pagedispx in
6438 let b1 = b0 + l.pagevw in
6439 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6440 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6444 match getopaque l.pageno with
6447 match Ne.pipe () with
6451 "can not create sel pipe: %s"
6454 let doclose what fd
=
6455 Ne.clo fd
(fun msg
->
6456 dolog
"%s close failed: %s" what msg
)
6459 popen conf.selcmd
[r, 0; w, -1];
6460 copysel
w opaque
true;
6462 G.postRedisplay "copysel";
6464 dolog
"can not execute %S: %s"
6465 conf.selcmd
(exntos exn
);
6473 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6474 state.mstate
<- Mnone
;
6481 let birdseyemouse button down
x y mask
6482 (conf, leftx
, _, hooverpageno
, anchor) =
6485 let rec loop = function
6488 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6489 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6491 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6497 | _ -> viewmouse button down
x y mask
6503 method key key mask
=
6504 begin match state.mode with
6505 | Textentry
textentry -> textentrykeyboard key mask
textentry
6506 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6507 | View
-> viewkeyboard key mask
6508 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6512 method button button bstate
x y mask
=
6513 begin match state.mode with
6515 | View
-> viewmouse button bstate
x y mask
6516 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6522 begin match state.mode with
6524 | View
| Birdseye
_ | LinkNav
_ ->
6525 match state.mstate
with
6526 | Mzoom
_ | Mnone
-> ()
6531 state.mstate
<- Mpan
(x, y);
6533 then state.x <- panbound (state.x + dx);
6535 gotoy_and_clear_text y
6538 state.mstate
<- Msel
(a, (x, y));
6539 G.postRedisplay "motion select";
6542 let y = min
state.winh
(max
0 y) in
6546 let x = min
state.winw (max
0 x) in
6549 | Mzoomrect
(p0
, _) ->
6550 state.mstate
<- Mzoomrect
(p0
, (x, y));
6551 G.postRedisplay "motion zoomrect";
6555 method pmotion
x y =
6556 begin match state.mode with
6557 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6558 let rec loop = function
6560 if hooverpageno
!= -1
6562 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6563 G.postRedisplay "pmotion birdseye no hoover";
6566 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6567 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6569 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6570 G.postRedisplay "pmotion birdseye hoover";
6580 match state.mstate
with
6581 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6588 let past, _, _ = !r in
6590 let delta = now -. past in
6593 else r := (now, x, y)
6597 method infochanged
_ = ()
6600 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6603 then 0.0, float state.winh
6604 else scrollph state.y maxy
6609 let winw = wadjsb state.winw in
6610 let fwinw = float winw in
6612 let sw = fwinw /. float state.w in
6613 let sw = fwinw *. sw in
6614 max
sw (float conf.scrollh
)
6617 let maxx = state.w + winw in
6618 let x = winw - state.x in
6619 let percent = float x /. float maxx in
6620 (fwinw -. sw) *. percent
6622 hscrollh (), position, sw
6626 match state.mode with
6627 | LinkNav
_ -> "links"
6628 | Textentry
_ -> "textentry"
6629 | Birdseye
_ -> "birdseye"
6632 findkeyhash conf modename
6634 method eformsgs
= true
6641 let fontpath = ref "";;
6644 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6647 let l = String.length
s in
6648 let b = Buffer.create
l in
6654 try Sys.getenv
"HOME"
6657 ("Can not determine home directory location: " ^ exntos exn
);
6661 let modifier_of_string = function
6662 | "alt" -> Wsi.altmask
6663 | "shift" -> Wsi.shiftmask
6664 | "ctrl" | "control" -> Wsi.ctrlmask
6665 | "meta" -> Wsi.metamask
6670 let r = Str.regexp
"-" in
6672 let elems = Str.full_split
r s in
6675 let m1 = modifier_of_string s in
6677 then (Wsi.namekey
s, m)
6680 | Str.Delim
s when n land 1 = 0 -> g s
6682 | Str.Delim
_ -> (k
, m)
6684 let rec loop n k
m = function
6687 let k, m = f n k m x in
6693 let keys_of_string =
6694 let r = Str.regexp
"[ \t]" in
6696 let elems = Str.split
r s in
6697 List.map
key_of_string elems
6700 let copykeyhashes c =
6701 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6704 let config_of c attrs
=
6708 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6709 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6710 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6711 | "preload" -> { c with preload = bool_of_string
v }
6712 | "page-bias" -> { c with pagebias
= int_of_string
v }
6713 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6714 | "horizontal-scroll-step" ->
6715 { c with hscrollstep
= max
(int_of_string
v) 1 }
6716 | "auto-scroll-step" ->
6717 { c with autoscrollstep
= max
0 (int_of_string
v) }
6718 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6719 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6722 match String.lowercase
v with
6723 | "true" -> Some infinity
6725 | f -> Some
(float_of_string
f)
6727 { c with maxwait
= mw}
6728 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6729 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6730 | "vertical-margin" ->
6731 { c with interpagespace
= max
0 (int_of_string
v) }
6733 let zoom = float_of_string
v /. 100. in
6734 let zoom = max
zoom 0.0 in
6735 { c with zoom = zoom }
6736 | "presentation" -> { c with presentation
= bool_of_string
v }
6737 | "rotation-angle" -> { c with angle
= int_of_string
v }
6738 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6739 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6740 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6741 | "proportional-display" ->
6744 then FitProportional
6747 { c with fitmodel
= fm }
6748 | "fit-model" -> { c with fitmodel
= FMTE.of_string v }
6749 | "pixmap-cache-size" ->
6750 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6751 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6752 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6753 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6754 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6755 | "background-color" -> { c with bgcolor
= color_of_string v }
6756 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6757 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6758 | "mupdf-store-size" ->
6759 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6760 | "checkers" -> { c with checkers
= bool_of_string
v }
6761 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6762 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6763 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6764 | "uri-launcher" -> { c with urilauncher
= unent v }
6765 | "path-launcher" -> { c with pathlauncher
= unent v }
6766 | "color-space" -> { c with colorspace
= CSTE.of_string v }
6767 | "invert-colors" -> { c with invert
= bool_of_string
v }
6768 | "brightness" -> { c with colorscale
= float_of_string
v }
6769 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6770 | "ghyllscroll" -> { c with ghyllscroll
= ghyllscroll_of_string v }
6772 let (n, _, _) as nab
= multicolumns_of_string v in
6774 then { c with columns
= Csplit
(-n, [||]) }
6775 else { c with columns
= Cmulti
(nab
, [||]) }
6776 | "birds-eye-columns" ->
6777 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6778 | "selection-command" -> { c with selcmd
= unent v }
6779 | "synctex-command" -> { c with stcmd
= unent v }
6780 | "pax-command" -> { c with paxcmd
= unent v }
6781 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6782 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6783 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6784 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6785 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6786 | "horizontal-scrollbar-visible" ->
6789 then c.scrollb
lor scrollbhv
6790 else c.scrollb
land (lnot
scrollbhv)
6792 { c with scrollb
= b }
6793 | "vertical-scrollbar-visible" ->
6796 then c.scrollb
lor scrollbvv
6797 else c.scrollb
land (lnot
scrollbvv)
6799 { c with scrollb
= b }
6800 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6804 then Some
(ref (0.0, 0, 0))
6806 | "point-and-x-mark" -> { c with paxmark
= MTE.of_string v }
6809 prerr_endline
("Error processing attribute (`" ^
6810 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6813 let rec fold c = function
6816 let c = apply c k v in
6819 fold { c with keyhashes
= copykeyhashes c } attrs
;
6822 let fromstring f pos
n v d =
6825 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6826 n v pos
(exntos exn
)
6831 let bookmark_of attrs
=
6832 let rec fold title page
rely visy
= function
6833 | ("title", v) :: rest
-> fold v page
rely visy rest
6834 | ("page", v) :: rest
-> fold title v rely visy rest
6835 | ("rely", v) :: rest
-> fold title page
v visy rest
6836 | ("visy", v) :: rest
-> fold title page
rely v rest
6837 | _ :: rest
-> fold title page
rely visy rest
6838 | [] -> title, page
, rely, visy
6840 fold "invalid" "0" "0" "0" attrs
6844 let rec fold path page
rely pan visy
= function
6845 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6846 | ("page", v) :: rest
-> fold path v rely pan visy rest
6847 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6848 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6849 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6850 | _ :: rest
-> fold path page
rely pan visy rest
6851 | [] -> path, page
, rely, pan
, visy
6853 fold "" "0" "0" "0" "0" attrs
6857 let rec fold rs ls
= function
6858 | ("out", v) :: rest
-> fold v ls rest
6859 | ("in", v) :: rest
-> fold rs
v rest
6860 | _ :: rest
-> fold ls rs rest
6866 let setconf dst
src =
6867 dst
.scrollbw
<- src.scrollbw
;
6868 dst
.scrollh
<- src.scrollh
;
6869 dst
.icase
<- src.icase
;
6870 dst
.preload <- src.preload;
6871 dst
.pagebias
<- src.pagebias
;
6872 dst
.verbose
<- src.verbose
;
6873 dst
.scrollstep
<- src.scrollstep
;
6874 dst
.maxhfit
<- src.maxhfit
;
6875 dst
.crophack
<- src.crophack
;
6876 dst
.autoscrollstep
<- src.autoscrollstep
;
6877 dst
.maxwait
<- src.maxwait
;
6878 dst
.hlinks
<- src.hlinks
;
6879 dst
.underinfo
<- src.underinfo
;
6880 dst
.interpagespace
<- src.interpagespace
;
6881 dst
.zoom <- src.zoom;
6882 dst
.presentation
<- src.presentation
;
6883 dst
.angle
<- src.angle
;
6884 dst
.cwinw
<- src.cwinw
;
6885 dst
.cwinh
<- src.cwinh
;
6886 dst
.savebmarks
<- src.savebmarks
;
6887 dst
.memlimit
<- src.memlimit
;
6888 dst
.fitmodel
<- src.fitmodel
;
6889 dst
.texcount
<- src.texcount
;
6890 dst
.sliceheight
<- src.sliceheight
;
6891 dst
.thumbw
<- src.thumbw
;
6892 dst
.jumpback
<- src.jumpback
;
6893 dst
.bgcolor
<- src.bgcolor
;
6894 dst
.tilew
<- src.tilew
;
6895 dst
.tileh
<- src.tileh
;
6896 dst
.mustoresize
<- src.mustoresize
;
6897 dst
.checkers
<- src.checkers
;
6898 dst
.aalevel
<- src.aalevel
;
6899 dst
.trimmargins
<- src.trimmargins
;
6900 dst
.trimfuzz
<- src.trimfuzz
;
6901 dst
.urilauncher
<- src.urilauncher
;
6902 dst
.colorspace
<- src.colorspace
;
6903 dst
.invert
<- src.invert
;
6904 dst
.colorscale
<- src.colorscale
;
6905 dst
.redirectstderr <- src.redirectstderr;
6906 dst
.ghyllscroll
<- src.ghyllscroll
;
6907 dst
.columns
<- src.columns
;
6908 dst
.beyecolumns
<- src.beyecolumns
;
6909 dst
.selcmd
<- src.selcmd
;
6910 dst
.updatecurs
<- src.updatecurs
;
6911 dst
.pathlauncher
<- src.pathlauncher
;
6912 dst
.keyhashes
<- copykeyhashes src;
6913 dst
.hfsize
<- src.hfsize
;
6914 dst
.hscrollstep
<- src.hscrollstep
;
6915 dst
.pgscale <- src.pgscale;
6916 dst
.usepbo
<- src.usepbo
;
6917 dst
.wheelbypage
<- src.wheelbypage
;
6918 dst
.stcmd
<- src.stcmd
;
6919 dst
.paxcmd
<- src.paxcmd
;
6920 dst
.scrollb
<- src.scrollb
;
6921 dst
.riani
<- src.riani
;
6922 dst
.paxmark
<- src.paxmark
;
6926 else Some
((ref (0.0, 0, 0)));
6930 let h = Hashtbl.create
10 in
6931 let dc = { defconf with angle
= defconf.angle
} in
6932 let rec toplevel v t spos
_ =
6934 | Vdata
| Vcdata
| Vend
-> v
6935 | Vopen
("llppconfig", _, closed
) ->
6938 else { v with f = llppconfig
}
6940 error
"unexpected subelement at top level" s spos
6941 | Vclose
_ -> error
"unexpected close at top level" s spos
6943 and llppconfig
v t spos
_ =
6945 | Vdata
| Vcdata
-> v
6946 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6947 | Vopen
("defaults", attrs
, closed
) ->
6948 let c = config_of dc attrs
in
6952 else { v with f = defaults
}
6954 | Vopen
("ui-font", attrs
, closed
) ->
6955 let rec getsize size
= function
6957 | ("size", v) :: rest
->
6959 fromstring int_of_string spos
"size" v fstate.fontsize
in
6961 | l -> getsize size l
6963 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6966 else { v with f = uifont
(Buffer.create
10) }
6968 | Vopen
("doc", attrs
, closed
) ->
6969 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6970 let path = unent pathent
6971 and pageno = fromstring int_of_string spos
"page" spage
0
6972 and rely = fromstring float_of_string spos
"rely" srely
0.0
6973 and pan
= fromstring int_of_string spos
"pan" span
0
6974 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6975 let c = config_of dc attrs
in
6976 let anchor = (pageno, rely, visy
) in
6978 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6979 else { v with f = doc
path pan
anchor c [] }
6982 error
"unexpected subelement in llppconfig" s spos
6984 | Vclose
"llppconfig" -> { v with f = toplevel }
6985 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6987 and defaults
v t spos
_ =
6989 | Vdata
| Vcdata
-> v
6990 | Vend
-> error
"unexpected end of input in defaults" s spos
6991 | Vopen
("keymap", attrs
, closed
) ->
6993 try List.assoc
"mode" attrs
6994 with Not_found
-> "global" in
6999 let h = findkeyhash dc modename in
7000 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7003 { v with f = pkeymap
ret KeyMap.empty }
7005 | Vopen
(_, _, _) ->
7006 error
"unexpected subelement in defaults" s spos
7008 | Vclose
"defaults" ->
7009 { v with f = llppconfig
}
7011 | Vclose
_ -> error
"unexpected close in defaults" s spos
7013 and uifont
b v t spos
epos =
7016 Buffer.add_substring
b s spos
(epos - spos
);
7018 | Vopen
(_, _, _) ->
7019 error
"unexpected subelement in ui-font" s spos
7020 | Vclose
"ui-font" ->
7021 if emptystr
!fontpath
7022 then fontpath := Buffer.contents
b;
7023 { v with f = llppconfig
}
7024 | Vclose
_ -> error
"unexpected close in ui-font" s spos
7025 | Vend
-> error
"unexpected end of input in ui-font" s spos
7027 and doc
path pan
anchor c bookmarks
v t spos
_ =
7029 | Vdata
| Vcdata
-> v
7030 | Vend
-> error
"unexpected end of input in doc" s spos
7031 | Vopen
("bookmarks", _, closed
) ->
7034 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
7036 | Vopen
("keymap", attrs
, closed
) ->
7038 try List.assoc
"mode" attrs
7039 with Not_found
-> "global"
7045 let h = findkeyhash c modename in
7046 KeyMap.iter
(Hashtbl.replace
h) keymap
;
7047 doc
path pan
anchor c bookmarks
7049 { v with f = pkeymap
ret KeyMap.empty }
7051 | Vopen
(_, _, _) ->
7052 error
"unexpected subelement in doc" s spos
7055 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
7056 { v with f = llppconfig
}
7058 | Vclose
_ -> error
"unexpected close in doc" s spos
7060 and pkeymap
ret keymap
v t spos
_ =
7062 | Vdata
| Vcdata
-> v
7063 | Vend
-> error
"unexpected end of input in keymap" s spos
7064 | Vopen
("map", attrs
, closed
) ->
7065 let r, l = map_of attrs
in
7066 let kss = fromstring keys_of_string spos
"in" r [] in
7067 let lss = fromstring keys_of_string spos
"out" l [] in
7071 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
7072 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
7075 then { v with f = pkeymap
ret keymap }
7078 { v with f = skip
"map" f }
7081 error
"unexpected subelement in keymap" s spos
7083 | Vclose
"keymap" ->
7084 { v with f = ret keymap }
7086 | Vclose
_ -> error
"unexpected close in keymap" s spos
7088 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
7090 | Vdata
| Vcdata
-> v
7091 | Vend
-> error
"unexpected end of input in bookmarks" s spos
7092 | Vopen
("item", attrs
, closed
) ->
7093 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
7094 let page = fromstring int_of_string spos
"page" spage
0
7095 and rely = fromstring float_of_string spos
"rely" srely
0.0
7096 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
7098 (unent titleent, 0, Oanchor
(page, rely, visy
)) :: bookmarks
7101 then { v with f = pbookmarks
path pan
anchor c bookmarks }
7104 { v with f = skip
"item" f }
7107 error
"unexpected subelement in bookmarks" s spos
7109 | Vclose
"bookmarks" ->
7110 { v with f = doc
path pan
anchor c bookmarks }
7112 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
7114 and skip tag
f v t spos
_ =
7116 | Vdata
| Vcdata
-> v
7118 error
("unexpected end of input in skipped " ^ tag
) s spos
7119 | Vopen
(tag'
, _, closed
) ->
7123 let f'
() = { v with f = skip tag
f } in
7124 { v with f = skip tag'
f'
}
7128 else error
("unexpected close in skipped " ^ tag
) s spos
7131 parse
{ f = toplevel; accu = () } s;
7137 let len = in_channel_length ic
in
7138 let s = String.create
len in
7139 really_input ic
s 0 len;
7142 | Parse_error
(msg
, s, pos
) ->
7143 let subs = subs s pos
in
7144 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
7147 failwith
("config load error: " ^ exntos exn
)
7153 let dir = Filename.concat
home ".config" in
7154 if Sys.is_directory
dir then dir else home
7157 Filename.concat
dir "llpp.conf"
7160 let confpath = ref defconfpath;;
7163 if Sys.file_exists
!confpath
7166 (try Some
(open_in_bin
!confpath)
7169 ("Error opening configuration file `" ^
!confpath ^
"': " ^
7180 ("Error loading configuration from `" ^
!confpath ^
"': " ^
7189 f (Hashtbl.create
0, defconf)
7194 let pc, pb
, px, pa
=
7197 if emptystr
state.origin
7201 Hashtbl.find h (Filename.basename
key)
7202 with Not_found
-> dc, [], 0, emptyanchor
7206 state.bookmarks <- pb
;
7209 then state.anchor <- pa
;
7210 cbput state.hists
.nav pa
;
7216 let add_attrs bb always
dc c =
7219 then Printf.bprintf bb
"\n %s='%b'" s a
7222 then Printf.bprintf bb
"\n %s='%b'" s (a != None
)
7225 then Printf.bprintf bb
"\n %s='%d'" s a
7228 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
7231 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
7234 then Printf.bprintf bb
"\n %s='%f'" s a
7238 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
7242 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a)
7246 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
7250 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
7255 | Some
(_N
, _A
, _B
) ->
7256 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
7261 Printf.bprintf bb
"\n %s='none'" s
7271 else string_of_float
f
7273 Printf.bprintf bb
"\n %s='%s'" s v
7278 | Cmulti
((n, a, b), _) when n > 1 ->
7279 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
7280 | Csplit
(n, _) when n > 1 ->
7281 Printf.bprintf bb
"\n %s='%d'" s ~
-n
7287 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
7292 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a)
7296 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
7300 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a)
7302 oi
"width" c.cwinw
dc.cwinw
;
7303 oi
"height" c.cwinh
dc.cwinh
;
7304 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
7305 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
7306 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
7307 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
7308 ob "case-insensitive-search" c.icase
dc.icase
;
7309 ob "preload" c.preload dc.preload;
7310 oi
"page-bias" c.pagebias
dc.pagebias
;
7311 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
7312 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
7313 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
7314 ob "crop-hack" c.crophack
dc.crophack
;
7315 oW
"throttle" c.maxwait
dc.maxwait
;
7316 ob "highlight-links" c.hlinks
dc.hlinks
;
7317 ob "under-cursor-info" c.underinfo
dc.underinfo
;
7318 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
7319 oz
"zoom" c.zoom dc.zoom;
7320 ob "presentation" c.presentation
dc.presentation
;
7321 oi
"rotation-angle" c.angle
dc.angle
;
7322 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
7323 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
7324 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
7325 oi
"tex-count" c.texcount
dc.texcount
;
7326 oi
"slice-height" c.sliceheight
dc.sliceheight
;
7327 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
7328 ob "persistent-location" c.jumpback
dc.jumpback
;
7329 oc
"background-color" c.bgcolor
dc.bgcolor
;
7330 oi
"tile-width" c.tilew
dc.tilew
;
7331 oi
"tile-height" c.tileh
dc.tileh
;
7332 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
7333 ob "checkers" c.checkers
dc.checkers
;
7334 oi
"aalevel" c.aalevel
dc.aalevel
;
7335 ob "trim-margins" c.trimmargins
dc.trimmargins
;
7336 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
7337 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
7338 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
7339 oC
"color-space" c.colorspace
dc.colorspace
;
7340 ob "invert-colors" c.invert
dc.invert
;
7341 oF
"brightness" c.colorscale
dc.colorscale
;
7342 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
7343 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
7344 oco
"columns" c.columns
dc.columns
;
7345 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
7346 os
"selection-command" c.selcmd
dc.selcmd
;
7347 os
"synctex-command" c.stcmd
dc.stcmd
;
7348 os
"pax-command" c.paxcmd
dc.paxcmd
;
7349 ob "update-cursor" c.updatecurs
dc.updatecurs
;
7350 oi
"hint-font-size" c.hfsize
dc.hfsize
;
7351 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
7352 oF
"page-scroll-scale" c.pgscale dc.pgscale;
7353 ob "use-pbo" c.usepbo
dc.usepbo
;
7354 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
7355 ob "remote-in-a-new-instance" c.riani
dc.riani
;
7356 op
"point-and-x" c.pax
dc.pax
;
7357 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
7360 let keymapsbuf always
dc c =
7361 let bb = Buffer.create
16 in
7362 let rec loop = function
7364 | (modename, h) :: rest
->
7365 let dh = findkeyhash dc modename in
7366 if always
|| h <> dh
7368 if Hashtbl.length
h > 0
7370 if Buffer.length
bb > 0
7371 then Buffer.add_char
bb '
\n'
;
7372 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7373 Hashtbl.iter
(fun i
o ->
7374 let isdifferent = always
||
7376 let dO = Hashtbl.find dh i
in
7378 with Not_found
-> true
7383 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7384 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7385 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7386 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7387 Buffer.add_string
bb (Wsi.keyname
k);
7390 let rec loop = function
7392 | km
:: [] -> addkm km
7393 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7397 Buffer.add_string
bb "<map in='";
7401 Buffer.add_string
bb "' out='";
7403 Buffer.add_string
bb "'/>\n"
7406 Buffer.add_string
bb "' out='";
7408 Buffer.add_string
bb "'/>\n"
7410 | KMmulti
(ins, kms
) ->
7411 Buffer.add_char
bb ' '
;
7413 Buffer.add_string
bb "' out='";
7415 Buffer.add_string
bb "'/>\n"
7417 Buffer.add_string
bb "</keymap>";
7427 let uifontsize = fstate.fontsize
in
7428 let bb = Buffer.create
32768 in
7429 let relx = float state.x /. float state.winw in
7431 let cx w = truncate
(relx *. float w) in
7433 (fun (w, h, x) ws
->
7435 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7436 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7437 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7439 (state.winw, state.winh
, state.x) state.winstate
7444 let dc = if conf.bedefault
then conf else dc in
7445 Buffer.add_string
bb "<llppconfig>\n";
7447 if nonemptystr
!fontpath
7449 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7455 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7458 Buffer.add_string
bb "<defaults";
7459 add_attrs bb true dc dc;
7460 let kb = keymapsbuf true dc dc in
7461 if Buffer.length
kb > 0
7463 Buffer.add_string
bb ">\n";
7464 Buffer.add_buffer
bb kb;
7465 Buffer.add_string
bb "\n</defaults>\n";
7467 else Buffer.add_string
bb "/>\n";
7469 let adddoc path pan
anchor c bookmarks =
7470 if bookmarks == [] && c = dc && anchor = emptyanchor
7473 Printf.bprintf
bb "<doc path='%s'"
7474 (enent
path 0 (String.length
path));
7476 if anchor <> emptyanchor
7478 let n, rely, visy
= anchor in
7479 Printf.bprintf
bb " page='%d'" n;
7482 Printf.bprintf
bb " rely='%f'" rely
7484 if abs_float visy
> 1e-6
7486 Printf.bprintf
bb " visy='%f'" visy
7491 then Printf.bprintf
bb " pan='%d'" pan
;
7493 add_attrs bb false dc c;
7494 let kb = keymapsbuf false dc c in
7496 begin match bookmarks with
7498 if Buffer.length
kb > 0
7500 Buffer.add_string
bb ">\n";
7501 Buffer.add_buffer
bb kb;
7502 Buffer.add_string
bb "\n</doc>\n";
7504 else Buffer.add_string
bb "/>\n"
7506 Buffer.add_string
bb ">\n<bookmarks>\n";
7507 List.iter
(fun (title, _, kind
) ->
7508 begin match kind
with
7509 | Oanchor
(page, rely, visy
) ->
7511 "<item title='%s' page='%d'"
7512 (enent
title 0 (String.length
title))
7517 Printf.bprintf
bb " rely='%f'" rely
7519 if abs_float visy
> 1e-6
7521 Printf.bprintf
bb " visy='%f'" visy
7523 | Ouri
_ | Oremote
_ | Oremotedest
_ | Olaunch
_ ->
7524 failwith
"unexpected link in bookmarks"
7526 Buffer.add_string
bb "/>\n";
7528 Buffer.add_string
bb "</bookmarks>";
7529 if Buffer.length
kb > 0
7531 Buffer.add_string
bb "\n";
7532 Buffer.add_buffer
bb kb;
7534 Buffer.add_string
bb "\n</doc>\n";
7540 match state.mode with
7541 | Birdseye
(c, pan, _, _, _) ->
7543 match conf.columns
with
7544 | Cmulti
((c, _, _), _) -> Some
c
7548 match c.columns
with
7549 | Cmulti
(c, _) -> Cmulti
(c, [||])
7550 | Csingle
_ -> Csingle
[||]
7551 | Csplit
_ -> failwith
"quit from bird's eye while split"
7553 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7556 let basename = Filename.basename
7557 (if emptystr
state.origin
then state.path else state.origin
)
7559 adddoc basename pan (getanchor ())
7561 let autoscrollstep =
7562 match state.autoscroll
with
7564 | None
-> conf.autoscrollstep
7566 match state.mode with
7567 | Birdseye
(bc
, _, _, _, _) ->
7570 presentation
= bc
.presentation
;
7571 interpagespace
= bc
.interpagespace
;
7572 maxwait
= bc
.maxwait
;
7573 autoscrollstep = autoscrollstep }
7574 | _ -> { conf with autoscrollstep = autoscrollstep }
7576 (if conf.savebmarks
then state.bookmarks else []);
7578 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7580 then adddoc path x anchor c bookmarks
7582 Buffer.add_string
bb "</llppconfig>\n";
7585 if load1 f && Buffer.length
bb > 0
7588 let tmp = !confpath ^
".tmp" in
7589 let oc = open_out_bin
tmp in
7590 Buffer.output_buffer
oc bb;
7592 Unix.rename
tmp !confpath;
7595 ("error while saving configuration: " ^ exntos exn
)
7599 let adderrmsg src msg
=
7600 Buffer.add_string
state.errmsgs msg
;
7601 state.newerrmsgs
<- true;
7605 let adderrfmt src fmt
=
7606 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7610 let cl = splitatspace cmds
in
7612 try Scanf.sscanf
s fmt
f
7614 adderrfmt "remote exec"
7615 "error processing '%S': %s\n" cmds
(exntos exn
)
7618 | "reload" :: [] -> reload ()
7619 | "goto" :: args :: [] ->
7620 scan args "%u %f %f"
7622 let cmd, _ = state.geomcmds
in
7624 then gotopagexy pageno x y
7627 gotopagexy pageno x y;
7630 state.reprf
<- f state.reprf
7632 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7633 | "rect" :: args :: [] ->
7634 scan args "%u %u %f %f %f %f"
7635 (fun pageno color x0 y0 x1 y1 ->
7636 onpagerect pageno (fun w h ->
7637 let _,w1,h1
,_ = getpagedim pageno in
7638 let sw = float w1 /. float w
7639 and sh = float h1
/. float h in
7643 and y1s
= y1 *. sh in
7644 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7646 state.rects <- (pageno, color, rect) :: state.rects;
7647 G.postRedisplay "rect";
7650 | "activatewin" :: [] -> Wsi.activatewin
()
7651 | "quit" :: [] -> raise Quit
7653 adderrfmt "remote command"
7654 "error processing remote command: %S\n" cmds
;
7658 let scratch = String.create
80 in
7659 let buf = Buffer.create
80 in
7662 try Some
(Unix.read fd
scratch 0 80)
7664 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7665 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7668 match tempfr () with
7674 if Buffer.length
buf > 0
7676 let s = Buffer.contents
buf in
7686 let pos = String.index_from
scratch ppos '
\n'
in
7687 if pos >= n then -1 else pos
7688 with Not_found
-> -1
7692 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7693 let s = Buffer.contents
buf in
7699 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7705 let remoteopen path =
7706 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7708 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7713 let trimcachepath = ref "" in
7714 let rcmdpath = ref "" in
7715 selfexec := Sys.executable_name
;
7718 [("-p", Arg.String
(fun s -> state.password
<- s),
7719 "<password> Set password");
7723 Config.fontpath := s;
7724 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7726 "<path> Set path to the user interface font");
7730 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7731 Config.confpath := s),
7732 "<path> Set path to the configuration file");
7734 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7735 "<path> Set path to the trim cache file");
7737 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7738 "<named-destination> Set named destination");
7740 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7741 ("-cxack", Arg.Set
cxack, " Cut corners");
7743 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7744 "<path> Set path to the remote commands source");
7746 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7747 "<original-path> Set original path");
7749 ("-v", Arg.Unit
(fun () ->
7751 "%s\nconfiguration path: %s\n"
7755 exit
0), " Print version and exit");
7758 (fun s -> state.path <- s)
7759 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7762 then selfexec := !selfexec ^
" -wtmode";
7764 if emptystr
state.path
7765 then (prerr_endline
"file name missing"; exit
1);
7767 if not
(Config.load ())
7768 then prerr_endline
"failed to load configuration";
7770 let wsfd, winw, winh
= Wsi.init
(object
7771 val mutable m_hack
= false
7772 method expose
= if not m_hack
then G.postRedisplay "expose"
7773 method visible
= G.postRedisplay "visible"
7774 method display = m_hack
<- false; display ()
7775 method reshape w h =
7776 m_hack
<- w < state.winw && h < state.winh
;
7778 method mouse
b d x y m = state.uioh <- state.uioh#button
b d x y m
7780 state.mpos
<- (x, y);
7781 state.uioh <- state.uioh#motion
x y
7782 method pmotion
x y =
7783 state.mpos
<- (x, y);
7784 state.uioh <- state.uioh#pmotion
x y
7786 let mascm = m land (
7787 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7789 match state.keystate
with
7791 let km = k, mascm in
7794 let modehash = state.uioh#
modehash in
7795 try Hashtbl.find modehash km
7797 try Hashtbl.find (findkeyhash conf "global") km
7798 with Not_found
-> KMinsrt
(k, m)
7800 | KMinsrt
(k, m) -> keyboard k m
7801 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7802 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7804 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7805 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7806 state.keystate
<- KSnone
7807 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7808 state.keystate
<- KSinto
(keys
, insrt
)
7810 state.keystate
<- KSnone
7813 state.mpos
<- (x, y);
7814 state.uioh <- state.uioh#pmotion
x y
7815 method leave = state.mpos
<- (-1, -1)
7816 method winstate wsl
= state.winstate
<- wsl
; m_hack
<- false
7817 method quit
= raise Quit
7818 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7823 List.exists
GlMisc.check_extension
7824 [ "GL_ARB_texture_rectangle"
7825 ; "GL_EXT_texture_recangle"
7826 ; "GL_NV_texture_rectangle" ]
7828 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7831 let r = GlMisc.get_string `renderer
in
7832 let p = "Mesa DRI Intel(" in
7833 let l = String.length
p in
7834 String.length
r > l && String.sub
r 0 l = p
7837 defconf.sliceheight
<- 1024;
7838 defconf.texcount
<- 32;
7839 defconf.usepbo
<- true;
7843 match Ne.pipe () with
7845 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7849 match Ne.pipe () with
7851 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7861 setcheckers conf.checkers
;
7863 if conf.redirectstderr
7866 let s = Buffer.contents
state.errmsgs ^
7867 (match state.errfd
with
7869 let s = String.create
(80*24) in
7872 let r, _, _ = Unix.select
[fd
] [] [] 0.0 in
7874 then Unix.read fd
s 0 (String.length
s)
7880 else String.sub
s 0 n
7884 try ignore
(Unix.write
state.stderr
s 0 (String.length
s))
7885 with exn
-> print_endline
(exntos exn
)
7890 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7891 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7892 !Config.fontpath, !trimcachepath,
7893 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7895 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
7898 state.text <- "Opening " ^
(mbtoutf8
state.path);
7900 opendoc state.path state.password
;
7904 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7907 if nonemptystr
!rcmdpath
7908 then remoteopen !rcmdpath
7913 let rec loop deadline
=
7915 match state.errfd
with
7916 | None
-> [state.sr
; state.wsfd]
7917 | Some fd
-> [state.sr
; state.wsfd; fd
]
7922 | Some fd
-> fd
:: r
7926 state.redisplay
<- false;
7933 if deadline
= infinity
7935 else max
0.0 (deadline
-. now)
7940 try Unix.select
r [] [] timeout
7941 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7947 if state.ghyll
== noghyll
7949 match state.autoscroll
with
7950 | Some step
when step
!= 0 ->
7951 let y = state.y + step
in
7955 else if y >= state.maxy then 0 else y
7958 if state.mode = View
7959 then state.text <- "";
7962 else deadline
+. 0.01
7967 let rec checkfds = function
7969 | fd
:: rest
when fd
= state.sr
->
7970 let cmd = readcmd state.sr
in
7974 | fd
:: rest
when fd
= state.wsfd ->
7978 | fd
:: rest
when Some fd
= !optrfd ->
7979 begin match remote fd
with
7980 | None
-> optrfd := remoteopen !rcmdpath;
7981 | opt -> optrfd := opt
7986 let s = String.create
80 in
7987 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7988 if conf.redirectstderr
7990 Buffer.add_substring
state.errmsgs
s 0 n;
7991 state.newerrmsgs
<- true;
7992 state.redisplay
<- true;
7995 prerr_string
(String.sub
s 0 n);
8003 if deadline
= infinity
8007 match state.autoscroll
with
8008 | Some step
when step
!= 0 -> deadline1
8009 | _ -> if state.ghyll
== noghyll then infinity
else deadline1