8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 type params
= (angle
* fitmodel
* trimparams
17 * texcount
* sliceheight
* memsize
18 * colorspace
* fontpath
* trimcachepath
28 and trimmargins
= bool
29 and interpagespace
= int
36 and trimcachepath
= string
39 and irect
= (int * int * int * int)
40 and trimparams
= (trimmargins
* irect
)
41 and colorspace
= | Rgb
| Bgr
| Gray
42 and fitmodel
= | FitWidth
| FitProportional
| FitPage
50 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
59 | LDfirstvisible
of (int * int * int)
74 | KMmulti
of key list
* key list
76 and keyhash
= (key
, keymap
) Hashtbl.t
79 | KSinto
of (key list
* key list
)
82 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
83 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
85 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
87 external init
: pipe
-> params
-> unit = "ml_init";;
88 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
89 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
90 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
91 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
92 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
93 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
94 external measurestr
: int -> string -> float = "ml_measure_string";;
95 external postprocess
:
96 opaque
-> int -> int -> int -> (int * string * int) -> int
98 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
99 external platform
: unit -> platform
= "ml_platform";;
100 external setaalevel
: int -> unit = "ml_setaalevel";;
101 external realloctexts
: int -> bool = "ml_realloctexts";;
102 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
103 external getlink
: opaque
-> int -> under
= "ml_getlink";;
104 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
105 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
106 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
107 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
108 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
109 external freepbo
: string -> unit = "ml_freepbo";;
110 external unmappbo
: string -> unit = "ml_unmappbo";;
111 external pbousable
: unit -> bool = "ml_pbo_usable";;
112 external unproject
: opaque
-> int -> int -> (int * int) option
114 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
116 let platform_to_string = function
117 | Punknown
-> "unknown"
121 | Pfreebsd
-> "FreeBSD"
122 | Pdragonflybsd
-> "DragonflyBSD"
123 | Popenbsd
-> "OpenBSD"
124 | Pnetbsd
-> "NetBSD"
125 | Pcygwin
-> "Cygwin"
128 let platform = platform ();;
130 let now = Unix.gettimeofday
;;
133 if platform = Pcygwin
135 let sh = "/bin/sh" in
136 let args = [|sh; "-c"; cmd
|] in
137 let rec std si so se
= function
139 | (fd
, 0) :: rest
-> std fd so se rest
140 | (fd
, -1) :: rest
->
141 Unix.set_close_on_exec fd
;
144 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
146 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
147 ignore
(Unix.create_process
sh args si so se
)
152 type mpos
= int * int
154 | Msel
of (mpos
* mpos
)
156 | Mscrolly
| Mscrollx
157 | Mzoom
of (int * int)
158 | Mzoomrect
of (mpos
* mpos
)
162 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
163 and onkey
= string -> int -> te
164 and ondone
= string -> unit
165 and histcancel
= unit -> unit
166 and onhist
= ((histcmd
-> string) * histcancel
)
167 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
168 and cancelonempty
= bool
173 | TEswitch
of textentry
184 let bound v minv maxv
=
185 max minv
(min maxv v
);
189 { store
= Array.create n v
196 let cbcap b
= Array.length b
.store
;;
201 b
.wc
<- (b
.wc
+ 1) mod cap;
203 b
.len
<- min
(b
.len
+ 1) cap;
206 let cbempty b
= b
.len
= 0;;
208 let cbgetg b circular dir
=
212 let rc = b
.rc + dir
in
224 else bound rc 0 (b
.len
-1)
230 let cbget b
= cbgetg b
false;;
231 let cbgetc b
= cbgetg b
true;;
233 let drawstring size x y s
=
235 Gl.enable `texture_2d
;
236 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
237 ignore
(drawstr size x y s
);
239 Gl.disable `texture_2d
;
242 let drawstring1 size x y s
=
246 let drawstring2 size x y fmt
=
247 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
266 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
267 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
268 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
269 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
270 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
271 dolog
" column %d" l
.pagecol
;
275 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
277 dolog
" x0,y0=(% f, % f)" x0 y0
;
278 dolog
" x1,y1=(% f, % f)" x1 y1
;
279 dolog
" x2,y2=(% f, % f)" x2 y2
;
280 dolog
" x3,y3=(% f, % f)" x3 y3
;
284 type multicolumns
= multicol
* pagegeom
285 and singlecolumn
= pagegeom
286 and splitcolumns
= columncount
* pagegeom
287 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
288 and multicol
= columncount
* covercount
* covercount
290 and columncount
= int
291 and covercount
= int;;
298 { mutable scrollbw
: int
299 ; mutable scrollh
: int
300 ; mutable scrollb
: scrollb
301 ; mutable icase
: bool
302 ; mutable preload
: bool
303 ; mutable pagebias
: int
304 ; mutable verbose
: bool
305 ; mutable debug
: bool
306 ; mutable scrollstep
: int
307 ; mutable hscrollstep
: int
308 ; mutable maxhfit
: bool
309 ; mutable crophack
: bool
310 ; mutable autoscrollstep
: int
311 ; mutable maxwait
: float option
312 ; mutable hlinks
: bool
313 ; mutable underinfo
: bool
314 ; mutable interpagespace
: interpagespace
315 ; mutable zoom
: float
316 ; mutable presentation
: bool
317 ; mutable angle
: angle
318 ; mutable cwinw
: int
319 ; mutable cwinh
: int
320 ; mutable savebmarks
: bool
321 ; mutable fitmodel
: fitmodel
322 ; mutable trimmargins
: trimmargins
323 ; mutable trimfuzz
: irect
324 ; mutable memlimit
: memsize
325 ; mutable texcount
: texcount
326 ; mutable sliceheight
: sliceheight
327 ; mutable thumbw
: width
328 ; mutable jumpback
: bool
329 ; mutable bgcolor
: (float * float * float)
330 ; mutable bedefault
: bool
331 ; mutable tilew
: int
332 ; mutable tileh
: int
333 ; mutable mustoresize
: memsize
334 ; mutable checkers
: bool
335 ; mutable aalevel
: int
336 ; mutable urilauncher
: string
337 ; mutable pathlauncher
: string
338 ; mutable colorspace
: colorspace
339 ; mutable invert
: bool
340 ; mutable colorscale
: float
341 ; mutable redirectstderr
: bool
342 ; mutable ghyllscroll
: (int * int * int) option
343 ; mutable columns
: columns
344 ; mutable beyecolumns
: columncount
option
345 ; mutable selcmd
: string
346 ; mutable updatecurs
: bool
347 ; mutable keyhashes
: (string * keyhash
) list
348 ; mutable hfsize
: int
349 ; mutable pgscale
: float
350 ; mutable usepbo
: bool
351 ; mutable wheelbypage
: bool
352 ; mutable stcmd
: string
355 | Csingle
of singlecolumn
356 | Cmulti
of multicolumns
357 | Csplit
of splitcolumns
360 type anchor
= pageno
* top
* dtop
;;
362 type outline
= string * int * anchor
;;
364 type rect
= float * float * float * float * float * float * float * float;;
366 type tile
= opaque
* pixmapsize
* elapsed
367 and elapsed
= float;;
368 type pagemapkey
= pageno
* gen
;;
369 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
373 let emptyanchor = (0, 0.0, 0.0);;
375 type infochange
= | Memused
| Docinfo
| Pdim
;;
377 class type uioh
= object
378 method display
: unit
379 method key
: int -> int -> uioh
380 method button
: int -> bool -> int -> int -> int -> uioh
381 method motion
: int -> int -> uioh
382 method pmotion
: int -> int -> uioh
383 method infochanged
: infochange
-> unit
384 method scrollpw
: (int * float * float)
385 method scrollph
: (int * float * float)
386 method modehash
: keyhash
387 method eformsgs
: bool
391 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
392 | Textentry
of (textentry
* onleave
)
394 | LinkNav
of linktarget
395 and onleave
= leavetextentrystatus
-> unit
396 and leavetextentrystatus
= | Cancel
| Confirm
397 and helpitem
= string * int * action
400 | Action
of (uioh
-> uioh
)
402 | Ltexact
of (pageno
* int)
406 let isbirdseye = function Birdseye _
-> true | _
-> false;;
407 let istextentry = function Textentry _
-> true | _
-> false;;
411 | Loading
of (page
* gen
)
413 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
415 | Outlining
of outline list
418 let emptykeyhash = Hashtbl.create
0;;
419 let nouioh : uioh
= object (self
)
421 method key _ _
= self
422 method button _ _ _ _ _
= self
423 method motion _ _
= self
424 method pmotion _ _
= self
425 method infochanged _
= ()
426 method scrollpw
= (0, nan
, nan
)
427 method scrollph
= (0, nan
, nan
)
428 method modehash
= emptykeyhash
429 method eformsgs
= false
433 { mutable sr
: Unix.file_descr
434 ; mutable sw
: Unix.file_descr
435 ; mutable wsfd
: Unix.file_descr
436 ; mutable errfd
: Unix.file_descr
option
437 ; mutable stderr
: Unix.file_descr
438 ; mutable errmsgs
: Buffer.t
439 ; mutable newerrmsgs
: bool
443 ; mutable anchor
: anchor
444 ; mutable ranchors
: (string * string * anchor
* string) list
446 ; mutable layout
: page list
447 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
448 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
449 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
450 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
451 ; mutable pagecount
: int
452 ; mutable currently
: currently
453 ; mutable mstate
: mstate
454 ; mutable searchpattern
: string
455 ; mutable rects
: (pageno
* recttype
* rect
) list
456 ; mutable rects1
: (pageno
* recttype
* rect
) list
457 ; mutable text
: string
458 ; mutable winstate
: Wsi.winstate list
459 ; mutable mode
: mode
460 ; mutable uioh
: uioh
461 ; mutable outlines
: outline array
462 ; mutable bookmarks
: outline list
463 ; mutable path
: string
464 ; mutable password
: string
465 ; mutable nameddest
: string
466 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
467 ; mutable memused
: memsize
469 ; mutable throttle
: (page list
* int * float) option
470 ; mutable autoscroll
: int option
471 ; mutable ghyll
: (int option -> unit)
472 ; mutable help
: helpitem array
473 ; mutable docinfo
: (int * string) list
474 ; mutable texid
: GlTex.texture_id
option
476 ; mutable prevzoom
: float
477 ; mutable progress
: float
478 ; mutable redisplay
: bool
479 ; mutable mpos
: mpos
480 ; mutable keystate
: keystate
481 ; mutable glinks
: bool
482 ; mutable prevcolumns
: (columns
* float) option
485 ; mutable reprf
: (unit -> unit)
486 ; mutable origin
: string
489 { pat
: string circbuf
490 ; pag
: string circbuf
491 ; nav
: anchor circbuf
492 ; sel
: string circbuf
499 ; scrollb
= scrollbhv lor scrollbvv
515 ; presentation
= false
520 ; fitmodel
= FitProportional
521 ; trimmargins
= false
522 ; trimfuzz
= (0,0,0,0)
523 ; memlimit
= 32 lsl 20
528 ; bgcolor
= (0.5, 0.5, 0.5)
532 ; mustoresize
= 256 lsl 20
537 | Plinux
| Pfreebsd
| Pdragonflybsd
538 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
539 | Posx
-> "open \"%s\""
540 | Pcygwin
-> "cygstart \"%s\""
541 | Punknown
-> "echo %s")
542 ; pathlauncher
= "lp \"%s\""
545 | Plinux
| Pfreebsd
| Pdragonflybsd
546 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
553 ; redirectstderr
= false
555 ; columns
= Csingle
[||]
561 ; wheelbypage
= false
562 ; stcmd
= "echo SyncTex"
564 let mk n
= (n
, Hashtbl.create
1) in
578 let wtmode = ref false;;
580 let findkeyhash c name
=
581 try List.assoc name c
.keyhashes
582 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
585 let conf = { defconf with angle
= defconf.angle
};;
587 let pgscale h
= truncate
(float h
*. conf.pgscale);;
590 { mutable fontsize
: int
591 ; mutable wwidth
: float
592 ; mutable maxrows
: int
604 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
605 let len = String.length s
in
606 if colonpos >= 0 && colonpos + 3 < len
608 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
611 try String.rindex_from s
colonpos ' '
615 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
618 | "http" | "ftp" | "mailto" ->
620 try String.index_from s
colonpos ' '
621 with Not_found
-> len
623 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
631 if String.length
conf.urilauncher
= 0
632 then print_endline uri
634 let url = geturl uri
in
635 if String.length
url = 0
636 then print_endline uri
638 let re = Str.regexp
"%s" in
639 let command = Str.global_replace
re url conf.urilauncher
in
643 "failed to execute `%s': %s\n" command (exntos exn
);
649 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
650 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
654 let strings = version () :: "" :: Help.keys
in
657 let url = geturl s
in
658 if String.length
url > 0
659 then (s
, 0, Action
(fun u
-> gotouri url; u
))
660 else (s
, 0, Noaction
)
665 let firstgeomcmds = "", [];;
666 let noreprf () = ();;
673 ; stderr
= Unix.stderr
674 ; errmsgs
= Buffer.create
0
679 ; anchor
= emptyanchor
683 ; tilelru
= Queue.create
()
684 ; pagemap
= Hashtbl.create
10
685 ; tilemap
= Hashtbl.create
10
701 ; geomcmds
= firstgeomcmds
703 { nav
= cbnew 10 emptyanchor
732 if (conf.scrollb
land scrollbhv = 0)
733 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
739 if (conf.scrollb
land scrollbvv = 0)
744 let wadjsb w
= w
- vscrollw ();;
747 fstate.fontsize
<- n
;
748 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
749 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
755 Printf.kprintf prerr_endline fmt
757 Printf.kprintf ignore fmt
761 if String.length
conf.pathlauncher
= 0
762 then print_endline
state.path
764 let re = Str.regexp
"%s" in
765 let command = Str.global_replace
re state.path
conf.pathlauncher
in
768 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
774 type 'a t
= | Res
of 'a
| Exn
of exn
;;
777 try Res
(Unix.pipe ())
782 try tempfailureretry
Unix.close fd
783 with exn
-> f
(exntos exn
)
787 try Res
(tempfailureretry
Unix.dup fd
)
792 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
797 let redirectstderr () =
798 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
799 if conf.redirectstderr
801 match Ne.pipe () with
803 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
806 begin match Ne.dup Unix.stderr
with
808 dolog
"failed to dup stderr: %s" (exntos exn
);
809 Ne.clo r
(clofail "pipe/r");
810 Ne.clo w
(clofail "pipe/w");
812 | Ne.Res dupstderr
->
813 begin match Ne.dup2 w
Unix.stderr
with
815 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
816 Ne.clo dupstderr
(clofail "stderr duplicate");
817 Ne.clo r
(clofail "redir pipe/r");
818 Ne.clo w
(clofail "redir pipe/w");
821 state.stderr
<- dupstderr
;
822 state.errfd
<- Some r
;
826 state.newerrmsgs
<- false;
827 begin match state.errfd
with
829 begin match Ne.dup2 state.stderr
Unix.stderr
with
831 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
833 Ne.clo fd
(clofail "dup of stderr");
838 prerr_string
(Buffer.contents
state.errmsgs
);
840 Buffer.clear
state.errmsgs
;
846 let postRedisplay who
=
848 then prerr_endline
("redisplay for " ^ who
);
849 state.redisplay
<- true;
853 let getopaque pageno
=
854 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
855 with Not_found
-> None
858 let putopaque pageno opaque
=
859 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
862 let pagetranslatepoint l x y
=
863 let dy = y
- l
.pagedispy
in
864 let y = dy + l
.pagey
in
865 let dx = x
- l
.pagedispx
in
866 let x = dx + l
.pagex
in
870 let onppundermouse g
x y d
=
873 begin match getopaque l
.pageno
with
875 let x0 = l
.pagedispx
in
876 let x1 = x0 + l
.pagevw
in
877 let y0 = l
.pagedispy
in
878 let y1 = y0 + l
.pagevh
in
879 if y >= y0 && y <= y1 && x >= x0 && x <= x1
881 let px, py
= pagetranslatepoint l
x y in
882 match g opaque l
px py
with
895 let g opaque _
px py
=
896 match whatsunder opaque
px py
with
898 | under
-> Some under
900 onppundermouse g x y Unone
905 match unproject opaque
x y with
906 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
909 onppundermouse g x y None
;
913 state.text
<- Printf.sprintf
"%c%s" c s
;
914 G.postRedisplay "showtext";
918 match Ne.pipe () with
920 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
923 try popen conf.selcmd
[r
, 0; w
, -1]; true
926 (Printf.sprintf
"failed to execute %s: %s"
927 conf.selcmd
(exntos exn
));
931 Ne.clo fd
(fun msg
->
932 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
938 let l = String.length s
in
939 let n = tempfailureretry
(Unix.write w s
0) l in
944 "failed to write %d characters to sel pipe, wrote %d"
949 (Printf.sprintf
"failed to write to sel pipe: %s"
958 let undertext = function
961 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
962 | Utext s
-> "font: " ^ s
963 | Uunexpected s
-> "unexpected: " ^ s
964 | Ulaunch s
-> "launch: " ^ s
965 | Unamed s
-> "named: " ^ s
966 | Uremote
(filename
, pageno
) ->
967 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
970 let updateunder x y =
971 match getunder x y with
972 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
974 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
975 Wsi.setcursor
Wsi.CURSOR_INFO
976 | Ulinkgoto
(pageno
, _
) ->
978 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
979 Wsi.setcursor
Wsi.CURSOR_INFO
981 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
982 Wsi.setcursor
Wsi.CURSOR_TEXT
984 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
985 Wsi.setcursor
Wsi.CURSOR_INHERIT
987 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
988 Wsi.setcursor
Wsi.CURSOR_INHERIT
990 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
991 Wsi.setcursor
Wsi.CURSOR_INHERIT
992 | Uremote
(filename
, pageno
) ->
993 if conf.underinfo
then showtext 'r'
994 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
995 Wsi.setcursor
Wsi.CURSOR_INFO
998 let showlinktype under
=
1004 let s = undertext under
in
1009 let b = Buffer.create
(String.length
s + 1) in
1010 Buffer.add_string
b s;
1011 Buffer.add_char
b c
;
1015 let colorspace_of_string s =
1016 match String.lowercase
s with
1020 | _
-> failwith
"invalid colorspace"
1023 let int_of_colorspace = function
1029 let colorspace_of_int = function
1033 | n -> failwith
("invalid colorspace index " ^ string_of_int
n)
1036 let colorspace_to_string = function
1042 let fitmodel_of_string s =
1043 match String.lowercase
s with
1044 | "width" -> FitWidth
1045 | "proportional" -> FitProportional
1047 | _
-> failwith
"invalid fit model"
1050 let int_of_fitmodel = function
1052 | FitProportional
-> 1
1056 let fitmodel_of_int = function
1058 | 1 -> FitProportional
1060 | n -> failwith
("invalid fit model index " ^ string_of_int
n)
1063 let fitmodel_to_string = function
1064 | FitWidth
-> "width"
1065 | FitProportional
-> "proportional"
1069 let intentry_with_suffix text key
=
1071 if key
>= 32 && key
< 127
1075 match Char.lowercase
c with
1077 let text = addchar text c in
1080 | 'k'
| 'm'
| '
g'
->
1081 let text = addchar text c in
1085 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1089 let multicolumns_to_string (n, a
, b) =
1091 then Printf.sprintf
"%d" n
1092 else Printf.sprintf
"%d,%d,%d" n a
b;
1095 let multicolumns_of_string s =
1097 (int_of_string
s, 0, 0)
1099 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1101 then failwith
"subtly broken"; (n, a
, b)
1107 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1108 if n != 4 then failwith
"incomplete read(len)";
1110 lor (Char.code
s.[0] lsl 24)
1111 lor (Char.code
s.[1] lsl 16)
1112 lor (Char.code
s.[2] lsl 8)
1113 lor (Char.code
s.[3] lsl 0)
1115 let s = String.create
len in
1116 let n = tempfailureretry
(Unix.read fd
s 0) len in
1117 if n != len then failwith
"incomplete read(data)";
1121 let btod b = if b then 1 else 0;;
1124 let b = Buffer.create
16 in
1125 Buffer.add_string
b "llll";
1128 let s = Buffer.contents
b in
1129 let n = String.length
s in
1131 (* dolog "wcmd %S" (String.sub s 4 len); *)
1132 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1133 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1134 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1135 s.[3] <- Char.chr
(len land 0xff);
1136 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1137 if n'
!= n then failwith
"write failed";
1142 let d = state.winh
- h
in
1143 max
conf.interpagespace
((d + 1) / 2)
1146 let rowyh (c, coverA
, coverB
) b n =
1147 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1149 let _, _, vy
, (_, _, h
, _) = b.(n) in
1152 let n'
= n - coverA
in
1155 let e = min
state.pagecount
(s + c) in
1156 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1157 let _, _, y, (_, _, h
, _) = b.(m
) in
1158 let miny = min
miny y in
1159 let maxh = max
maxh h
in
1160 find (m
+1) miny maxh
1165 match conf.columns
with
1166 | Cmulti
((_, _, _) as cl
, b) ->
1167 if Array.length
b > 0
1169 let y, h
= rowyh cl
b (Array.length
b - 1) in
1170 y + h
+ (if conf.presentation
then calcips h
else 0)
1173 if Array.length
b > 0
1175 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1176 y + h
+ (if conf.presentation
then calcips h
else 0)
1179 if Array.length
b > 0
1181 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1186 let getpageyh pageno
=
1187 let pageno = bound pageno 0 (state.pagecount
-1) in
1188 match conf.columns
with
1190 if Array.length
b = 0
1193 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1195 if conf.presentation
1201 if Array.length
b = 0
1204 let y, h
= rowyh cl
b pageno in
1206 if conf.presentation
1212 if Array.length
b = 0
1216 let (_, _, y, (_, _, h
, _)) = b.(n) in
1220 let getpagedim pageno =
1223 | (n, _, _, _) as pdim
:: rest
->
1225 then (if n = pageno then pdim
else ppdim
)
1230 f (-1, -1, -1, -1) state.pdims
1233 let getpagey pageno = fst
(getpageyh pageno);;
1235 let nogeomcmds cmds
=
1237 | s, [] -> String.length
s = 0
1242 let ((c, coverA
, coverB
) as cl
), b =
1243 match conf.columns
with
1244 | Csingle
b -> (1, 0, 0), b
1245 | Cmulti
(c, b) -> c, b
1246 | Csplit
(_, b) -> (1, 0, 0), b
1248 if Array.length
b = 0
1251 let rec bsearch nmin nmax
=
1253 then bound nmin
0 (state.pagecount
-1)
1255 let n = (nmax
+ nmin
) / 2 in
1256 let vy, h
= rowyh cl
b n in
1258 if conf.presentation
1260 let ips = calcips h
in
1261 let y0 = vy - ips in
1262 let y1 = vy + h
+ ips in
1266 then 0, vy + h
+ conf.interpagespace
1268 let y0 = vy - conf.interpagespace
in
1269 y0, y0 + h
+ conf.interpagespace
1272 if y >= y0 && y < y1
1279 if n < state.pagecount
- coverB
1280 then ((n-coverA
)/c)*c + coverA
1287 then bsearch (n+1) nmax
1288 else bsearch nmin
(n-1)
1291 let r = bsearch 0 (state.pagecount
-1) in
1295 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1296 let sh = sh - (hscrollh ()) in
1297 let rec fold accu
n =
1298 if n = Array.length
b
1301 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1304 || n = state.pagecount
- coverB
1305 || (n - coverA
) mod columns
= columns
- 1)
1311 let pagey = max
0 (y - vy) in
1312 let pagedispy = if pagey > 0 then 0 else vy - y in
1313 let pagedispx, pagex
=
1315 if n = coverA
- 1 || n = state.pagecount
- coverB
1316 then state.x + (wadjsb state.winw
- w
) / 2
1317 else dx + xoff
+ state.x
1324 let vw = wadjsb state.winw
- pagedispx in
1325 let pw = w
- pagex
in
1328 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1329 if pagevw > 0 && pagevh > 0
1333 ; pagedimno
= pdimno
1340 ; pagedispx = pagedispx
1341 ; pagedispy = pagedispy
1353 List.rev
(fold [] (page_of_y y));
1356 let layoutS (columns
, b) y sh =
1357 let sh = sh - hscrollh () in
1358 let rec fold accu n =
1359 if n = Array.length
b
1362 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1369 let x = xoff
+ state.x in
1370 let pagey = max
0 (y - vy) in
1371 let pagedispy = if pagey > 0 then 0 else vy - y in
1372 let pagedispx, pagex
=
1386 let pagecolw = pagew
/columns
in
1388 if pagecolw < state.winw
1389 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1393 let vw = wadjsb state.winw
- pagedispx in
1394 let pw = pagew
- pagex
in
1397 let pagevw = min
pagevw pagecolw in
1398 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1399 if pagevw > 0 && pagevh > 0
1402 { pageno = n/columns
1403 ; pagedimno
= pdimno
1410 ; pagedispx = pagedispx
1411 ; pagedispy = pagedispy
1412 ; pagecol
= n mod columns
1423 List.rev
(fold [] 0)
1427 if nogeomcmds state.geomcmds
1429 match conf.columns
with
1430 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1431 | Cmulti
c -> layoutN c y sh
1432 | Csplit
s -> layoutS s y sh
1437 let y = state.y + incr
in
1439 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1444 let tilex = l.pagex
mod conf.tilew
in
1445 let tiley = l.pagey mod conf.tileh
in
1447 let col = l.pagex
/ conf.tilew
in
1448 let row = l.pagey / conf.tileh
in
1450 let rec rowloop row y0 dispy h
=
1454 let dh = conf.tileh
- y0 in
1455 let dh = min h
dh in
1456 let rec colloop col x0 dispx w
=
1460 let dw = conf.tilew
- x0 in
1461 let dw = min w
dw in
1463 f col row dispx dispy
x0 y0 dw dh;
1464 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1467 colloop col tilex l.pagedispx l.pagevw;
1468 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1471 if l.pagevw > 0 && l.pagevh > 0
1472 then rowloop row tiley l.pagedispy l.pagevh;
1475 let gettileopaque l col row =
1477 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1479 try Some
(Hashtbl.find state.tilemap
key)
1480 with Not_found
-> None
1483 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1484 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1485 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1488 let drawtiles l color
=
1490 let f col row x y tilex tiley w h
=
1491 match gettileopaque l col row with
1492 | Some
(opaque
, _, t
) ->
1493 let params = x, y, w
, h
, tilex, tiley in
1497 GlFunc.blend_func `zero `one_minus_src_color
;
1499 drawtile
params opaque
;
1501 then Gl.disable `blend
;
1504 let s = Printf.sprintf
1508 let w = measurestr
fstate.fontsize
s in
1509 GlMisc.push_attrib
[`current
];
1510 GlDraw.color
(0.0, 0.0, 0.0);
1512 (float (x-2), float (y-2))
1513 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1514 GlDraw.color
(1.0, 1.0, 1.0);
1515 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1516 GlMisc.pop_attrib
();
1521 let lw = wadjsb state.winw
- x in
1524 let lh = state.winh
- y in
1527 begin match state.texid
with
1529 Gl.enable `texture_2d
;
1530 GlTex.bind_texture `texture_2d id
;
1533 and x1 = float (x+w)
1534 and y1 = float (y+h
) in
1536 let tw = float w /. 16.0
1537 and th
= float h
/. 16.0 in
1538 let tx0 = float tilex /. 16.0
1539 and ty0
= float tiley /. 16.0 in
1541 and ty1
= ty0
+. th
in
1542 GlDraw.begins `quads
;
1543 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1544 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1545 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1546 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1549 Gl.disable `texture_2d
;
1551 GlDraw.color
(1.0, 1.0, 1.0);
1554 (float (x+w), float (y+h
));
1556 if w > 128 && h
> fstate.fontsize
+ 10
1558 GlDraw.color
(0.0, 0.0, 0.0);
1561 then (col*conf.tilew
, row*conf.tileh
)
1564 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1571 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1573 let tilevisible1 l x y =
1575 and ax1
= l.pagex
+ l.pagevw
1577 and ay1
= l.pagey + l.pagevh in
1581 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1582 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1584 let rx0 = max
ax0 bx0
1585 and ry0
= max ay0 by0
1586 and rx1
= min ax1
bx1
1587 and ry1
= min ay1 by1
in
1589 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1590 nonemptyintersection
1593 let tilevisible layout n x y =
1594 let rec findpageinlayout m
= function
1595 | l :: rest
when l.pageno = n ->
1596 tilevisible1 l x y || (
1597 match conf.columns
with
1598 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1601 | _ :: rest
-> findpageinlayout 0 rest
1604 findpageinlayout 0 layout;
1607 let tileready l x y =
1608 tilevisible1 l x y &&
1609 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1612 let tilepage n p
layout =
1613 let rec loop = function
1617 let f col row _ _ _ _ _ _ =
1618 if state.currently
= Idle
1620 match gettileopaque l col row with
1623 let x = col*conf.tilew
1624 and y = row*conf.tileh
in
1626 let w = l.pagew
- x in
1630 let h = l.pageh
- y in
1635 then getpbo
w h conf.colorspace
1638 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1641 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1642 conf.tilew
, conf.tileh
1651 if nogeomcmds state.geomcmds
1655 let preloadlayout y =
1656 let y = if y < state.winh
then 0 else y - state.winh
in
1657 let h = state.winh
*3 in
1662 let rec loop pages
=
1663 if state.currently
!= Idle
1668 begin match getopaque l.pageno with
1670 wcmd "page %d %d" l.pageno l.pagedimno
;
1671 state.currently
<- Loading
(l, state.gen
);
1673 tilepage l.pageno opaque pages
;
1678 if nogeomcmds state.geomcmds
1684 if conf.preload && state.currently
= Idle
1685 then load (preloadlayout state.y);
1688 let layoutready layout =
1689 let rec fold all ls
=
1690 all
&& match ls
with
1692 let seen = ref false in
1693 let allvisible = ref true in
1694 let foo col row _ _ _ _ _ _ =
1696 allvisible := !allvisible &&
1697 begin match gettileopaque l col row with
1703 fold (!seen && !allvisible) rest
1706 let alltilesvisible = fold true layout in
1711 let y = bound y 0 state.maxy
in
1712 let y, layout, proceed
=
1713 match conf.maxwait
with
1714 | Some time
when state.ghyll
== noghyll ->
1715 begin match state.throttle
with
1717 let layout = layout y state.winh
in
1718 let ready = layoutready layout in
1722 state.throttle
<- Some
(layout, y, now ());
1724 else G.postRedisplay "gotoy showall (None)";
1726 | Some
(_, _, started
) ->
1727 let dt = now () -. started
in
1730 state.throttle
<- None
;
1731 let layout = layout y state.winh
in
1733 G.postRedisplay "maxwait";
1740 let layout = layout y state.winh
in
1741 if not
!wtmode || layoutready layout
1742 then G.postRedisplay "gotoy ready";
1748 state.layout <- layout;
1749 begin match state.mode
with
1750 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1751 let rec loop = function
1753 state.mode
<- LinkNav
(Ltgendir
0)
1754 | l :: _ when l.pageno = pageno ->
1755 begin match getopaque pageno with
1757 state.mode
<- LinkNav
(Ltgendir
0)
1759 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1760 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1761 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1762 then state.mode
<- LinkNav
(Ltgendir
0)
1764 | _ :: rest
-> loop rest
1769 begin match state.mode
with
1770 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1771 if not
(pagevisible layout pageno)
1773 match state.layout with
1776 state.mode
<- Birdseye
(
1777 conf, leftx
, l.pageno, hooverpageno
, anchor
1780 | LinkNav
(Ltgendir dir
as lt
) ->
1782 let rec loop = function
1785 match getopaque l.pageno with
1791 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1793 if dir
> 0 then LDfirst
else LDlast
1799 | Lnotfound
-> loop rest
1801 showlinktype (getlink opaque
n);
1802 Ltexact
(l.pageno, n)
1806 state.mode
<- LinkNav
linknav
1811 state.ghyll
<- noghyll;
1814 let mx, my
= state.mpos
in
1819 let conttiling pageno opaque
=
1820 tilepage pageno opaque
1821 (if conf.preload then preloadlayout state.y else state.layout)
1824 let gotoy_and_clear_text y =
1825 if not
conf.verbose
then state.text <- "";
1831 let coloff = l.pagecol
* l.pageh
in
1832 float (l.pagey + coloff) /. float l.pageh
1839 if conf.presentation
1840 then float l.pagedispy /. float (calcips l.pageh
)
1841 else float l.pagedispy /. float conf.interpagespace
1844 (l.pageno, top, dtop)
1848 match state.layout with
1849 | l :: _ -> getanchor1 l
1851 let n = page_of_y state.y in
1855 let y, h = getpageyh n in
1856 let dy = y - state.y in
1858 if conf.presentation
1860 let ips = calcips h in
1861 float (dy + ips) /. float ips
1863 float dy /. float conf.interpagespace
1868 let getanchory (n, top, dtop) =
1869 let y, h = getpageyh n in
1870 if conf.presentation
1872 let ips = calcips h in
1873 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1875 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1878 let gotoanchor anchor
=
1879 gotoy (getanchory anchor
);
1883 cbput state.hists
.nav
(getanchor ());
1887 let anchor = cbgetc state.hists
.nav dir
in
1892 let scroll f n a
b =
1893 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1895 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1897 then s (float f /. float a
)
1900 then 1.0 -. s ((float (f-b) /. float (n-b)))
1906 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1907 let iv x = x**3.-.0.5*.x**4. in
1909 let ins = float a
*. iv1
1910 and outs
= float (n-b) *. iv1 in
1912 ins +. outs
+. float ones
1914 let rec set (_N
, _A
, _B
) y sy
=
1915 let sum = summa
1.0 _N _A _B
in
1916 let dy = float (y - sy
) in
1920 then state.ghyll
<- noghyll
1923 let s = scroll n _N _A _B
in
1924 let y1 = y1 +. ((s *. dy) /. sum) in
1925 gotoy_and_clear_text (truncate
y1);
1926 state.ghyll
<- gf (n+1) y1;
1930 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1932 gf 0 (float state.y)
1935 match conf.ghyllscroll
with
1937 gotoy_and_clear_text y
1939 if state.ghyll
== noghyll
1940 then set nab
y state.y
1941 else state.ghyll
(Some
y)
1944 let gotopage n top =
1945 let y, h = getpageyh n in
1946 let y = y + (truncate
(top *. float h)) in
1950 let gotopage1 n top =
1951 let y = getpagey n in
1956 let invalidate s f =
1961 match state.geomcmds
with
1962 | ps
, [] when String.length ps
= 0 ->
1964 state.geomcmds
<- s, [];
1967 state.geomcmds
<- ps
, [s, f];
1969 | ps
, (s'
, _) :: rest
when s'
= s ->
1970 state.geomcmds
<- ps
, ((s, f) :: rest
);
1973 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1977 Hashtbl.iter
(fun _ opaque
->
1978 wcmd "freepage %s" opaque
;
1980 Hashtbl.clear
state.pagemap
;
1984 if not
(Queue.is_empty
state.tilelru
)
1986 Queue.iter
(fun (k
, p
, s) ->
1987 wcmd "freetile %s" p
;
1988 state.memused
<- state.memused
- s;
1989 Hashtbl.remove
state.tilemap k
;
1991 state.uioh#infochanged Memused
;
1992 Queue.clear
state.tilelru
;
1998 let h = truncate
(float h*.conf.zoom
) in
1999 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2003 let opendoc path password
=
2005 state.password
<- password
;
2006 state.gen
<- state.gen
+ 1;
2007 state.docinfo
<- [];
2010 setaalevel
conf.aalevel
;
2012 if String.length
state.origin
= 0
2016 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2017 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
2018 invalidate "reqlayout"
2020 wcmd "reqlayout %d %d %d %s\000"
2021 conf.angle
(int_of_fitmodel conf.fitmodel
)
2022 (stateh state.winh
) state.nameddest
2027 state.anchor <- getanchor ();
2028 opendoc state.path
state.password
;
2032 let c = c *. conf.colorscale
in
2036 let scalecolor2 (r, g, b) =
2037 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2040 let docolumns = function
2042 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2043 let rec loop pageno pdimno pdim
y ph pdims
=
2044 if pageno = state.pagecount
2047 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2049 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2050 pdimno+1, pdim
, rest
2054 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2056 (if conf.presentation
2057 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2058 else (if pageno = 0 then 0 else conf.interpagespace
)
2061 a.(pageno) <- (pdimno, x, y, pdim
);
2062 loop (pageno+1) pdimno pdim
(y + h) h pdims
2064 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2065 conf.columns
<- Csingle
a;
2067 | Cmulti
((columns
, coverA
, coverB
), _) ->
2068 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2069 let rec loop pageno pdimno pdim
x y rowh pdims
=
2070 let rec fixrow m
= if m
= pageno then () else
2071 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2074 let y = y + (rowh
- h) / 2 in
2075 a.(m
) <- (pdimno, x, y, pdim
);
2079 if pageno = state.pagecount
2080 then fixrow (((pageno - 1) / columns
) * columns
)
2082 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2084 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2085 pdimno+1, pdim
, rest
2090 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2092 let x = (wadjsb state.winw
- w) / 2 in
2094 if conf.presentation
then calcips h else conf.interpagespace
in
2095 x, y + ips + rowh
, h
2098 if (pageno - coverA
) mod columns
= 0
2100 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2102 if conf.presentation
2104 let ips = calcips h in
2105 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2107 y + (if pageno = 0 then 0 else conf.interpagespace
)
2111 else x, y, max rowh
h
2115 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2118 if pageno = columns
&& conf.presentation
2120 let ips = calcips rowh
in
2121 for i
= 0 to pred columns
2123 let (pdimno, x, y, pdim
) = a.(i
) in
2124 a.(i
) <- (pdimno, x, y+ips, pdim
)
2130 fixrow (pageno - columns
);
2135 a.(pageno) <- (pdimno, x, y, pdim
);
2136 let x = x + w + xoff
*2 + conf.interpagespace
in
2137 loop (pageno+1) pdimno pdim
x y rowh' pdims
2139 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2140 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2143 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2144 let rec loop pageno pdimno pdim
y pdims
=
2145 if pageno = state.pagecount
2148 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2150 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2151 pdimno+1, pdim
, rest
2156 let rec loop1 n x y =
2157 if n = c then y else (
2158 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2159 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2162 let y = loop1 0 0 y in
2163 loop (pageno+1) pdimno pdim
y pdims
2165 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2166 conf.columns
<- Csplit
(c, a);
2170 docolumns conf.columns
;
2171 state.maxy
<- calcheight ();
2172 if state.reprf
== noreprf
2174 match state.mode
with
2175 | Birdseye
(_, _, pageno, _, _) ->
2176 let y, h = getpageyh pageno in
2177 let top = (state.winh
- h) / 2 in
2178 gotoy (max
0 (y - top))
2179 | _ -> gotoanchor state.anchor
2183 state.reprf
<- noreprf;
2188 GlDraw.viewport
0 0 w h;
2189 let firsttime = state.geomcmds
== firstgeomcmds in
2190 if not
firsttime && nogeomcmds state.geomcmds
2191 then state.anchor <- getanchor ();
2194 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2197 setfontsize fstate.fontsize
;
2198 GlMat.mode `modelview
;
2199 GlMat.load_identity
();
2201 GlMat.mode `projection
;
2202 GlMat.load_identity
();
2203 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2204 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2205 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2210 else float state.x /. float state.w
2212 invalidate "geometry"
2216 then state.x <- truncate
(relx *. float w);
2218 match conf.columns
with
2220 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2221 | Csplit
(c, _) -> w * c
2223 wcmd "geometry %d %d %d"
2224 w (stateh h) (int_of_fitmodel conf.fitmodel
)
2229 let len = String.length
state.text in
2232 match state.mode
with
2233 | Textentry
_ | View
| LinkNav
_ ->
2234 let h, _, _ = state.uioh#scrollpw
in
2240 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2241 (x+.w, float (state.winh
- hscrollh))
2244 let w = float (wadjsb state.winw
- 1) in
2245 if state.progress
>= 0.0 && state.progress
< 1.0
2247 GlDraw.color
(0.3, 0.3, 0.3);
2248 let w1 = w *. state.progress
in
2250 GlDraw.color
(0.0, 0.0, 0.0);
2254 GlDraw.color
(0.0, 0.0, 0.0);
2258 GlDraw.color
(1.0, 1.0, 1.0);
2259 drawstring fstate.fontsize
2260 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2263 match state.mode
with
2264 | Textentry
((prefix
, text, _, _, _, _), _) ->
2268 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2270 Printf.sprintf
"%s%s_" prefix
text
2279 if not
(istextentry state.mode
) && state.uioh#eformsgs
2281 let s1 = "(press 'e' to review error messasges)" in
2282 if String.length
s > 0 then s ^
" " ^
s1 else s1
2287 if String.length
s > 0
2292 let len = Queue.length
state.tilelru
in
2294 match state.throttle
with
2297 then preloadlayout state.y
2299 | Some
(layout, _, _) ->
2303 if state.memused
<= conf.memlimit
2308 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2309 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2310 let (_, pw, ph
, _) = getpagedim n in
2313 && colorspace
= conf.colorspace
2314 && angle
= conf.angle
2318 let x = col*conf.tilew
2319 and y = row*conf.tileh
in
2320 tilevisible (Lazy.force_val
layout) n x y
2322 then Queue.push lruitem
state.tilelru
2325 wcmd "freetile %s" p
;
2326 state.memused
<- state.memused
- s;
2327 state.uioh#infochanged Memused
;
2328 Hashtbl.remove
state.tilemap k
;
2336 let logcurrently = function
2337 | Idle
-> dolog
"Idle"
2338 | Loading
(l, gen
) ->
2339 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2340 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2342 "Tiling %d[%d,%d] page=%s cs=%s angle"
2343 l.pageno col row pageopaque
2344 (colorspace_to_string colorspace
)
2346 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2347 angle gen
conf.angle
state.gen
2349 conf.tilew
conf.tileh
2356 let r = Str.regexp
" " in
2357 fun s -> Str.bounded_split
r s 2;
2360 let onpagerect pageno f =
2362 match conf.columns
with
2363 | Cmulti
(_, b) -> b
2365 | Csplit
(_, b) -> b
2367 if pageno >= 0 && pageno < Array.length
b
2369 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2370 let r = getpdimrect
pdimno in
2371 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2374 let gotopagexy1 pageno x y =
2375 onpagerect pageno (fun w h ->
2377 let _,w1,_,leftx
= getpagedim pageno in
2378 let wh = state.winh
- hscrollh () in
2379 let sw = float w1 /. w in
2381 let x = leftx
+ state.x + truncate
x in
2383 if x < 0 || x >= wadjsb state.winw
2387 let py, h = getpageyh pageno in
2388 let pdy = truncate
(top *. float h) in
2389 let y'
= py + pdy in
2390 let dy = y'
- state.y in
2392 if x != state.x || not
(dy > 0 && dy < wh)
2394 if conf.presentation
2396 if abs
(py - y'
) > wh
2403 if state.x != sx || state.y != sy
2408 let ww = wadjsb state.winw
in
2410 and qy
= pdy / wh in
2412 and y = py + qy
* wh in
2413 let x = if -x + ww > w1 then -(w1-ww) else x
2414 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2416 if conf.presentation
2418 if abs
(py - y'
) > wh
2428 gotoy_and_clear_text y;
2430 else gotoy_and_clear_text state.y;
2434 let gotopagexy pageno x y =
2435 match state.mode
with
2436 | Birdseye
_ -> gotopage pageno 0.0
2437 | _ -> gotopagexy1 pageno x y
2441 (* dolog "%S" cmds; *)
2442 let cl = splitatspace cmds
in
2444 try Scanf.sscanf
s fmt
f
2446 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2451 state.uioh#infochanged Pdim
;
2454 | "clearrects" :: [] ->
2455 state.rects
<- state.rects1
;
2456 G.postRedisplay "clearrects";
2458 | "continue" :: args :: [] ->
2459 let n = scan args "%u" (fun n -> n) in
2460 state.pagecount
<- n;
2461 begin match state.currently
with
2463 state.currently
<- Idle
;
2464 state.outlines
<- Array.of_list
(List.rev
l)
2468 let cur, cmds
= state.geomcmds
in
2469 if String.length
cur = 0
2470 then failwith
"umpossible";
2472 begin match List.rev cmds
with
2474 state.geomcmds
<- "", [];
2478 state.geomcmds
<- s, List.rev rest
;
2480 if conf.maxwait
= None
&& not
!wtmode
2481 then G.postRedisplay "continue";
2483 | "title" :: args :: [] ->
2486 | "msg" :: args :: [] ->
2489 | "vmsg" :: args :: [] ->
2491 then showtext ' '
args
2493 | "emsg" :: args :: [] ->
2494 Buffer.add_string
state.errmsgs
args;
2495 state.newerrmsgs
<- true;
2496 G.postRedisplay "error message"
2498 | "progress" :: args :: [] ->
2499 let progress, text =
2502 f, String.sub
args pos
(String.length
args - pos
))
2505 state.progress <- progress;
2506 G.postRedisplay "progress"
2508 | "firstmatch" :: args :: [] ->
2509 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2510 scan args "%u %d %f %f %f %f %f %f %f %f"
2511 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2512 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2514 let y = (getpagey pageno) + truncate
y0 in
2517 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2519 | "match" :: args :: [] ->
2520 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2521 scan args "%u %d %f %f %f %f %f %f %f %f"
2522 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2523 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2526 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2528 | "page" :: args :: [] ->
2529 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2530 begin match state.currently
with
2531 | Loading
(l, gen
) ->
2532 vlog "page %d took %f sec" l.pageno t
;
2533 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2534 begin match state.throttle
with
2536 let preloadedpages =
2538 then preloadlayout state.y
2543 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2544 IntSet.empty
preloadedpages
2547 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2548 if not
(IntSet.mem
pageno set)
2550 wcmd "freepage %s" opaque
;
2556 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2559 state.currently
<- Idle
;
2562 tilepage l.pageno pageopaque state.layout;
2564 load preloadedpages;
2565 if pagevisible state.layout l.pageno
2566 && layoutready state.layout
2567 then G.postRedisplay "page";
2570 | Some
(layout, _, _) ->
2571 state.currently
<- Idle
;
2572 tilepage l.pageno pageopaque layout;
2577 dolog
"Inconsistent loading state";
2578 logcurrently state.currently
;
2582 | "tile" :: args :: [] ->
2583 let (x, y, opaque
, size
, t
) =
2584 scan args "%u %u %s %u %f"
2585 (fun x y p size t
-> (x, y, p
, size
, t
))
2587 begin match state.currently
with
2588 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2589 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2592 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2594 wcmd "freetile %s" opaque
;
2595 state.currently
<- Idle
;
2599 puttileopaque l col row gen cs angle opaque size t
;
2600 state.memused
<- state.memused
+ size
;
2601 state.uioh#infochanged Memused
;
2603 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2604 opaque
, size
) state.tilelru
;
2607 match state.throttle
with
2608 | None
-> state.layout
2609 | Some
(layout, _, _) -> layout
2612 state.currently
<- Idle
;
2614 && conf.colorspace
= cs
2615 && conf.angle
= angle
2616 && tilevisible layout l.pageno x y
2617 then conttiling l.pageno pageopaque;
2619 begin match state.throttle
with
2621 preload state.layout;
2623 && conf.colorspace
= cs
2624 && conf.angle
= angle
2625 && tilevisible state.layout l.pageno x y
2626 && (not
!wtmode || layoutready state.layout)
2627 then G.postRedisplay "tile nothrottle";
2629 | Some
(layout, y, _) ->
2630 let ready = layoutready layout in
2634 state.layout <- layout;
2635 state.throttle
<- None
;
2636 G.postRedisplay "throttle";
2643 dolog
"Inconsistent tiling state";
2644 logcurrently state.currently
;
2648 | "pdim" :: args :: [] ->
2649 let (n, w, h, _) as pdim
=
2650 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2653 match conf.fitmodel
, conf.columns
with
2654 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2657 state.uioh#infochanged Pdim
;
2658 state.pdims
<- pdim :: state.pdims
2660 | "o" :: args :: [] ->
2661 let (l, n, t
, h, pos
) =
2662 scan args "%u %u %d %u %n"
2663 (fun l n t
h pos
-> l, n, t
, h, pos
)
2665 let s = String.sub
args pos
(String.length
args - pos
) in
2666 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2667 begin match state.currently
with
2668 | Outlining outlines
->
2669 state.currently
<- Outlining
(outline :: outlines
)
2671 state.currently
<- Outlining
[outline]
2673 dolog
"invalid outlining state";
2674 logcurrently currently
2677 | "a" :: args :: [] ->
2679 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2681 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2683 | "info" :: args :: [] ->
2684 state.docinfo
<- (1, args) :: state.docinfo
2686 | "infoend" :: [] ->
2687 state.uioh#infochanged Docinfo
;
2688 state.docinfo
<- List.rev
state.docinfo
2691 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2696 let action = function
2697 | HCprev
-> cbget cb ~
-1
2698 | HCnext
-> cbget cb
1
2699 | HCfirst
-> cbget cb ~
-(cb
.rc)
2700 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2701 and cancel
() = cb
.rc <- rc
2705 let search pattern forward
=
2706 match conf.columns
with
2708 showtext '
!'
"searching does not work properly in split columns mode"
2710 if String.length pattern
> 0
2713 match state.layout with
2716 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2718 wcmd "search %d %d %d %d,%s\000"
2719 (btod conf.icase
) pn py (btod forward
) pattern
;
2722 let intentry text key =
2724 if key >= 32 && key < 127
2730 let text = addchar text c in
2734 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2738 let linknentry text key =
2740 if key >= 32 && key < 127
2746 let text = addchar text c in
2750 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2755 if String.length
s > 0
2758 let l = String.length
s in
2759 let rec loop pos
n = if pos
= l then n else
2760 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2761 loop (pos
+1) (n*26 + m)
2764 let rec loop n = function
2767 match getopaque l.pageno with
2768 | None
-> loop n rest
2770 let m = getlinkcount opaque
in
2773 let under = getlink opaque
n in
2776 else loop (n-m) rest
2778 loop n state.layout;
2782 let textentry text key =
2783 if key land 0xff00 = 0xff00
2785 else TEcont
(text ^ toutf8
key)
2788 let reqlayout angle fitmodel
=
2789 match state.throttle
with
2791 if nogeomcmds state.geomcmds
2792 then state.anchor <- getanchor ();
2793 conf.angle
<- angle
mod 360;
2796 match state.mode
with
2797 | LinkNav
_ -> state.mode
<- View
2800 conf.fitmodel
<- fitmodel
;
2801 invalidate "reqlayout"
2803 wcmd "reqlayout %d %d %d"
2804 conf.angle
(int_of_fitmodel conf.fitmodel
) (stateh state.winh
)
2809 let settrim trimmargins trimfuzz
=
2810 if nogeomcmds state.geomcmds
2811 then state.anchor <- getanchor ();
2812 conf.trimmargins
<- trimmargins
;
2813 conf.trimfuzz
<- trimfuzz
;
2814 let x0, y0, x1, y1 = trimfuzz
in
2815 invalidate "settrim"
2817 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2822 match state.throttle
with
2824 let zoom = max
0.0001 zoom in
2825 if zoom <> conf.zoom
2827 state.prevzoom
<- conf.zoom;
2829 reshape state.winw
state.winh
;
2830 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2833 | Some
(layout, y, started
) ->
2835 match conf.maxwait
with
2839 let dt = now () -. started
in
2847 let setcolumns mode columns coverA coverB
=
2848 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2852 then showtext '
!'
"split mode doesn't work in bird's eye"
2854 conf.columns
<- Csplit
(-columns
, [||]);
2862 conf.columns
<- Csingle
[||];
2867 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2871 reshape state.winw
state.winh
;
2874 let enterbirdseye () =
2875 let zoom = float conf.thumbw
/. float state.winw
in
2876 let birdseyepageno =
2877 let cy = state.winh
/ 2 in
2881 let rec fold best
= function
2884 let d = cy - (l.pagedispy + l.pagevh/2)
2885 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2886 if abs
d < abs dbest
2893 state.mode
<- Birdseye
(
2894 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2897 conf.presentation
<- false;
2898 conf.interpagespace
<- 10;
2899 conf.hlinks
<- false;
2900 conf.fitmodel
<- FitProportional
;
2902 state.mstate
<- Mnone
;
2903 conf.maxwait
<- None
;
2905 match conf.beyecolumns
with
2908 Cmulti
((c, 0, 0), [||])
2909 | None
-> Csingle
[||]
2911 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2914 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2919 reshape state.winw
state.winh
;
2922 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2924 conf.zoom <- c.zoom;
2925 conf.presentation
<- c.presentation
;
2926 conf.interpagespace
<- c.interpagespace
;
2927 conf.maxwait
<- c.maxwait
;
2928 conf.hlinks
<- c.hlinks
;
2929 conf.fitmodel
<- c.fitmodel
;
2930 conf.beyecolumns
<- (
2931 match conf.columns
with
2932 | Cmulti
((c, _, _), _) -> Some
c
2934 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2937 match c.columns
with
2938 | Cmulti
(c, _) -> Cmulti
(c, [||])
2939 | Csingle
_ -> Csingle
[||]
2940 | Csplit
(c, _) -> Csplit
(c, [||])
2945 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2948 reshape state.winw
state.winh
;
2949 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2952 let togglebirdseye () =
2953 match state.mode
with
2954 | Birdseye vals
-> leavebirdseye vals
true
2955 | View
-> enterbirdseye ()
2959 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2960 let pageno = max
0 (pageno - incr
) in
2961 let rec loop = function
2962 | [] -> gotopage1 pageno 0
2963 | l :: _ when l.pageno = pageno ->
2964 if l.pagedispy >= 0 && l.pagey = 0
2965 then G.postRedisplay "upbirdseye"
2966 else gotopage1 pageno 0
2967 | _ :: rest
-> loop rest
2970 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2973 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2974 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2975 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2976 let rec loop = function
2978 let y, h = getpageyh pageno in
2979 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2981 | l :: _ when l.pageno = pageno ->
2982 if l.pagevh != l.pageh
2983 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2984 else G.postRedisplay "downbirdseye"
2985 | _ :: rest
-> loop rest
2990 let optentry mode
_ key =
2991 let btos b = if b then "on" else "off" in
2992 if key >= 32 && key < 127
2994 let c = Char.chr
key in
2998 try conf.scrollstep
<- int_of_string
s with exc
->
2999 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3001 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3006 conf.autoscrollstep
<- int_of_string
s;
3007 if state.autoscroll
<> None
3008 then state.autoscroll
<- Some
conf.autoscrollstep
3010 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3012 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3017 let n, a, b = multicolumns_of_string s in
3018 setcolumns mode
n a b;
3020 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3022 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3027 let zoom = float (int_of_string
s) /. 100.0 in
3030 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3032 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3037 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3039 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3040 begin match mode
with
3042 leavebirdseye beye
false;
3047 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3049 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3054 Some
(int_of_string
s)
3056 state.text <- Printf.sprintf
"bad integer `%s': %s"
3060 | Some angle
-> reqlayout angle
conf.fitmodel
3063 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3066 conf.icase
<- not
conf.icase
;
3067 TEdone
("case insensitive search " ^
(btos conf.icase
))
3070 conf.preload <- not
conf.preload;
3072 TEdone
("preload " ^
(btos conf.preload))
3075 conf.verbose
<- not
conf.verbose
;
3076 TEdone
("verbose " ^
(btos conf.verbose
))
3079 conf.debug
<- not
conf.debug
;
3080 TEdone
("debug " ^
(btos conf.debug
))
3083 conf.maxhfit
<- not
conf.maxhfit
;
3084 state.maxy
<- calcheight ();
3085 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3088 conf.crophack
<- not
conf.crophack
;
3089 TEdone
("crophack " ^
btos conf.crophack
)
3093 match conf.maxwait
with
3095 conf.maxwait
<- Some infinity
;
3096 "always wait for page to complete"
3098 conf.maxwait
<- None
;
3099 "show placeholder if page is not ready"
3104 conf.underinfo
<- not
conf.underinfo
;
3105 TEdone
("underinfo " ^
btos conf.underinfo
)
3108 conf.savebmarks
<- not
conf.savebmarks
;
3109 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3115 match state.layout with
3120 conf.interpagespace
<- int_of_string
s;
3121 docolumns conf.columns
;
3122 state.maxy
<- calcheight ();
3123 let y = getpagey pageno in
3126 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3128 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3132 match conf.fitmodel
with
3133 | FitProportional
-> FitWidth
3134 | _ -> FitProportional
3136 reqlayout conf.angle
fm;
3137 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3140 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3141 TEdone
("trim margins " ^
btos conf.trimmargins
)
3144 conf.invert
<- not
conf.invert
;
3145 TEdone
("invert colors " ^
btos conf.invert
)
3149 cbput state.hists
.sel
s;
3152 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3153 textentry, ondone, true)
3156 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3162 class type lvsource
= object
3163 method getitemcount
: int
3164 method getitem
: int -> (string * int)
3165 method hasaction
: int -> bool
3174 method getactive
: int
3175 method getfirst
: int
3176 method getqsearch
: string
3177 method setqsearch
: string -> unit
3181 class virtual lvsourcebase
= object
3182 val mutable m_active
= 0
3183 val mutable m_first
= 0
3184 val mutable m_qsearch
= ""
3185 val mutable m_pan
= 0
3186 method getactive
= m_active
3187 method getfirst
= m_first
3188 method getqsearch
= m_qsearch
3189 method getpan
= m_pan
3190 method setqsearch
s = m_qsearch
<- s
3193 let withoutlastutf8 s =
3194 let len = String.length
s in
3202 let b = Char.code
s.[pos
] in
3203 if b land 0b11000000 = 0b11000000
3208 if Char.code
s.[len-1] land 0x80 = 0
3212 String.sub
s 0 first;
3215 let textentrykeyboard
3216 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3218 if key >= 0xffb0 && key <= 0xffb9
3219 then key - 0xffb0 + 48 else key
3222 state.mode
<- Textentry
(te
, onleave
);
3225 G.postRedisplay "textentrykeyboard enttext";
3227 let histaction cmd
=
3230 | Some
(action, _) ->
3231 state.mode
<- Textentry
(
3232 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3234 G.postRedisplay "textentry histaction"
3237 | 0xff08 -> (* backspace *)
3238 let s = withoutlastutf8 text in
3239 let len = String.length
s in
3240 if cancelonempty
&& len = 0
3243 G.postRedisplay "textentrykeyboard after cancel";
3246 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3249 | 0xff0d | 0xff8d -> (* (kp) enter *)
3252 G.postRedisplay "textentrykeyboard after confirm"
3254 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3255 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3256 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3257 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3259 | 0xff1b -> (* escape*)
3260 if String.length
text = 0
3262 begin match opthist
with
3264 | Some
(_, onhistcancel
) -> onhistcancel
()
3268 G.postRedisplay "textentrykeyboard after cancel2"
3271 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3274 | 0xff9f | 0xffff -> () (* delete *)
3277 && key land 0xff00 != 0xff00 (* keyboard *)
3278 && key land 0xfe00 != 0xfe00 (* xkb *)
3279 && key land 0xfd00 != 0xfd00 (* 3270 *)
3281 begin match onkey
text key with
3285 G.postRedisplay "textentrykeyboard after confirm2";
3288 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3292 G.postRedisplay "textentrykeyboard after cancel3"
3295 state.mode
<- Textentry
(te
, onleave
);
3296 G.postRedisplay "textentrykeyboard switch";
3300 vlog "unhandled key %s" (Wsi.keyname
key)
3303 let firstof first active
=
3304 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3305 then max
0 (active
- (fstate.maxrows
/2))
3309 let calcfirst first active
=
3312 let rows = active
- first in
3313 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3317 let scrollph y maxy
=
3318 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3319 let sh = float state.winh
/. sh in
3320 let sh = max
sh (float conf.scrollh
) in
3322 let percent = float y /. float maxy
in
3323 let position = (float state.winh
-. sh) *. percent in
3326 if position +. sh > float state.winh
3327 then float state.winh
-. sh
3333 let coe s = (s :> uioh
);;
3335 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3337 val m_pan
= source#getpan
3338 val m_first
= source#getfirst
3339 val m_active
= source#getactive
3340 val m_qsearch
= source#getqsearch
3341 val m_prev_uioh
= state.uioh
3343 method private elemunder
y =
3344 let n = y / (fstate.fontsize
+1) in
3345 if m_first
+ n < source#getitemcount
3347 if source#hasaction
(m_first
+ n)
3348 then Some
(m_first
+ n)
3355 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3356 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3357 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3358 GlDraw.color
(1., 1., 1.);
3359 Gl.enable `texture_2d
;
3360 let fs = fstate.fontsize
in
3362 let ww = fstate.wwidth
in
3363 let tabw = 30.0*.ww in
3364 let itemcount = source#getitemcount
in
3366 if (row - m_first
) > fstate.maxrows
3369 if row >= 0 && row < itemcount
3371 let (s, level
) = source#getitem
row in
3372 let y = (row - m_first
) * nfs in
3373 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3376 Gl.disable `texture_2d
;
3377 GlDraw.polygon_mode `both `line
;
3378 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3379 GlDraw.color
(1., 1., 1.) ~
alpha;
3380 GlDraw.rect (1., float (y + 1))
3381 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3382 GlDraw.polygon_mode `both `fill
;
3383 GlDraw.color
(1., 1., 1.);
3384 Gl.enable `texture_2d
;
3387 let drawtabularstring s =
3388 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3391 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3394 let len = String.length
s - tabpos - 1 in
3395 let s1 = String.sub
s 0 tabpos
3396 and s2
= String.sub
s (tabpos + 1) len in
3397 let nx = drawstr x s1 in
3399 let x = x +. (max
tabw sw) in
3406 let _ = drawtabularstring s in
3413 Gl.disable `texture_2d
;
3415 method updownlevel incr
=
3416 let len = source#getitemcount
in
3418 if m_active
>= 0 && m_active
< len
3419 then snd
(source#getitem m_active
)
3423 if i
= len then i
-1 else if i
= -1 then 0 else
3424 let _, l = source#getitem i
in
3425 if l != curlevel then i
else flow (i
+incr
)
3427 let active = flow m_active
in
3428 let first = calcfirst m_first
active in
3429 G.postRedisplay "outline updownlevel";
3430 {< m_active
= active; m_first
= first >}
3432 method private key1
key mask
=
3433 let set1 active first qsearch
=
3434 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3436 let search active pattern incr
=
3437 let active = if active = -1 then m_first
else active in
3440 if n >= 0 && n < source#getitemcount
3442 let s, _ = source#getitem
n in
3444 (try ignore
(Str.search_forward
re s 0); true
3445 with Not_found
-> false)
3447 else loop (n + incr
)
3454 let re = Str.regexp_case_fold pattern
in
3460 let itemcount = source#getitemcount
in
3461 let find start incr
=
3463 if i
= -1 || i
= itemcount
3466 if source#hasaction i
3468 else find (i
+ incr
)
3473 let set active first =
3474 let first = bound first 0 (itemcount - fstate.maxrows
) in
3476 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3479 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3481 let incr1 = if incr
> 0 then 1 else -1 in
3482 if isvisible m_first m_active
3485 let next = m_active
+ incr
in
3487 if next < 0 || next >= itemcount
3489 else find next incr1
3491 if abs
(m_active
- next) > fstate.maxrows
3497 let first = m_first
+ incr
in
3498 let first = bound first 0 (itemcount - fstate.maxrows
) in
3500 let next = m_active
+ incr
in
3501 let next = bound next 0 (itemcount - 1) in
3508 if isvisible first next
3515 let first = min
next m_first
in
3517 if abs
(next - first) > fstate.maxrows
3523 let first = m_first
+ incr
in
3524 let first = bound first 0 (itemcount - 1) in
3526 let next = m_active
+ incr
in
3527 let next = bound next 0 (itemcount - 1) in
3528 let next = find next incr1 in
3530 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3532 let active = if m_active
= -1 then next else m_active
in
3537 if isvisible first active
3543 G.postRedisplay "listview navigate";
3547 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3548 let incr = if key = 0x72 then -1 else 1 in
3550 match search (m_active
+ incr) m_qsearch
incr with
3552 state.text <- m_qsearch ^
" [not found]";
3555 state.text <- m_qsearch
;
3556 active, firstof m_first
active
3558 G.postRedisplay "listview ctrl-r/s";
3559 set1 active first m_qsearch
;
3561 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3562 if m_active
>= 0 && m_active
< source#getitemcount
3564 let s, _ = source#getitem m_active
in
3569 | 0xff08 -> (* backspace *)
3570 if String.length m_qsearch
= 0
3573 let qsearch = withoutlastutf8 m_qsearch
in
3574 let len = String.length
qsearch in
3578 G.postRedisplay "listview empty qsearch";
3579 set1 m_active m_first
"";
3583 match search m_active
qsearch ~
-1 with
3585 state.text <- qsearch ^
" [not found]";
3588 state.text <- qsearch;
3589 active, firstof m_first
active
3591 G.postRedisplay "listview backspace qsearch";
3592 set1 active first qsearch
3595 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3596 let pattern = m_qsearch ^ toutf8
key in
3598 match search m_active
pattern 1 with
3600 state.text <- pattern ^
" [not found]";
3603 state.text <- pattern;
3604 active, firstof m_first
active
3606 G.postRedisplay "listview qsearch add";
3607 set1 active first pattern;
3609 | 0xff1b -> (* escape *)
3611 if String.length m_qsearch
= 0
3613 G.postRedisplay "list view escape";
3616 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3618 | None
-> m_prev_uioh
3623 G.postRedisplay "list view kill qsearch";
3624 source#setqsearch
"";
3625 coe {< m_qsearch
= "" >}
3628 | 0xff0d | 0xff8d -> (* (kp) enter *)
3630 let self = {< m_qsearch
= "" >} in
3631 source#setqsearch
"";
3633 G.postRedisplay "listview enter";
3634 if m_active
>= 0 && m_active
< source#getitemcount
3636 source#exit
(coe self) false m_active m_first m_pan
"";
3639 source#exit
(coe self) true m_active m_first m_pan
"";
3642 begin match opt with
3643 | None
-> m_prev_uioh
3647 | 0xff9f | 0xffff -> (* (kp) delete *)
3650 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3651 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3652 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3653 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3655 | 0xff53 | 0xff98 -> (* (kp) right *)
3657 G.postRedisplay "listview right";
3658 coe {< m_pan
= m_pan
- 1 >}
3660 | 0xff51 | 0xff96 -> (* (kp) left *)
3662 G.postRedisplay "listview left";
3663 coe {< m_pan
= m_pan
+ 1 >}
3665 | 0xff50 | 0xff95 -> (* (kp) home *)
3666 let active = find 0 1 in
3667 G.postRedisplay "listview home";
3670 | 0xff57 | 0xff9c -> (* (kp) end *)
3671 let first = max
0 (itemcount - fstate.maxrows
) in
3672 let active = find (itemcount - 1) ~
-1 in
3673 G.postRedisplay "listview end";
3676 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3680 dolog
"listview unknown key %#x" key; coe self
3682 method key key mask
=
3683 match state.mode
with
3684 | Textentry te
-> textentrykeyboard key mask te
; coe self
3685 | _ -> self#key1
key mask
3687 method button button down
x y _ =
3690 | 1 when x > state.winw
- conf.scrollbw
->
3691 G.postRedisplay "listview scroll";
3694 let _, position, sh = self#
scrollph in
3695 if y > truncate
position && y < truncate
(position +. sh)
3697 state.mstate
<- Mscrolly
;
3701 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3702 let first = truncate
(s *. float source#getitemcount
) in
3703 let first = min source#getitemcount
first in
3704 Some
(coe {< m_first
= first; m_active
= first >})
3706 state.mstate
<- Mnone
;
3709 | 1 when not down
->
3710 begin match self#elemunder
y with
3712 G.postRedisplay "listview click";
3714 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3718 | n when (n == 4 || n == 5) && not down
->
3719 let len = source#getitemcount
in
3721 if n = 5 && m_first
+ fstate.maxrows
>= len
3725 let first = m_first
+ (if n == 4 then -1 else 1) in
3726 bound first 0 (len - 1)
3728 G.postRedisplay "listview wheel";
3729 Some
(coe {< m_first
= first >})
3730 | n when (n = 6 || n = 7) && not down
->
3731 let inc = m_first
+ (if n = 7 then -1 else 1) in
3732 G.postRedisplay "listview hwheel";
3733 Some
(coe {< m_pan
= m_pan
+ inc >})
3738 | None
-> m_prev_uioh
3742 match state.mstate
with
3744 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3745 let first = truncate
(s *. float source#getitemcount
) in
3746 let first = min source#getitemcount
first in
3747 G.postRedisplay "listview motion";
3748 coe {< m_first
= first; m_active
= first >}
3751 method pmotion
x y =
3752 if x < state.winw
- conf.scrollbw
3755 match self#elemunder
y with
3756 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3757 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3761 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3766 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3770 method infochanged
_ = ()
3772 method scrollpw
= (0, 0.0, 0.0)
3774 let nfs = fstate.fontsize
+ 1 in
3775 let y = m_first
* nfs in
3776 let itemcount = source#getitemcount
in
3777 let maxi = max
0 (itemcount - fstate.maxrows
) in
3778 let maxy = maxi * nfs in
3779 let p, h = scrollph y maxy in
3782 method modehash
= modehash
3783 method eformsgs
= false
3786 class outlinelistview ~source
=
3789 ~source
:(source
:> lvsource
)
3791 ~modehash
:(findkeyhash conf "outline")
3794 method key key mask
=
3795 let calcfirst first active =
3798 let rows = active - first in
3800 if String.length
state.text = 0
3802 else fstate.maxrows - 2
3804 if rows > maxrows then active - maxrows else first
3808 let active = m_active
+ incr in
3809 let active = bound active 0 (source#getitemcount
- 1) in
3810 let first = calcfirst m_first
active in
3811 G.postRedisplay "outline navigate";
3812 coe {< m_active
= active; m_first
= first >}
3814 let ctrl = Wsi.withctrl mask
in
3816 | 110 when ctrl -> (* ctrl-n *)
3817 source#narrow m_qsearch
;
3818 G.postRedisplay "outline ctrl-n";
3819 coe {< m_first
= 0; m_active
= 0 >}
3821 | 117 when ctrl -> (* ctrl-u *)
3823 G.postRedisplay "outline ctrl-u";
3825 coe {< m_first
= 0; m_active
= 0 >}
3827 | 108 when ctrl -> (* ctrl-l *)
3828 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3829 G.postRedisplay "outline ctrl-l";
3830 coe {< m_first
= first >}
3832 | 0xff9f | 0xffff -> (* (kp) delete *)
3833 source#remove m_active
;
3834 G.postRedisplay "outline delete";
3835 let active = max
0 (m_active
-1) in
3836 coe {< m_first
= firstof m_first
active;
3837 m_active
= active >}
3839 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3840 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3841 | 0xff55 | 0xff9a -> (* (kp) prior *)
3842 navigate ~
-(fstate.maxrows)
3843 | 0xff56 | 0xff9b -> (* (kp) next *)
3844 navigate fstate.maxrows
3846 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3850 G.postRedisplay "outline ctrl right";
3851 {< m_pan
= m_pan
+ 1 >}
3853 else self#updownlevel
1
3857 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3861 G.postRedisplay "outline ctrl left";
3862 {< m_pan
= m_pan
- 1 >}
3864 else self#updownlevel ~
-1
3868 | 0xff50 | 0xff95 -> (* (kp) home *)
3869 G.postRedisplay "outline home";
3870 coe {< m_first
= 0; m_active
= 0 >}
3872 | 0xff57 | 0xff9c -> (* (kp) end *)
3873 let active = source#getitemcount
- 1 in
3874 let first = max
0 (active - fstate.maxrows) in
3875 G.postRedisplay "outline end";
3876 coe {< m_active
= active; m_first
= first >}
3878 | _ -> super#
key key mask
3881 let outlinesource usebookmarks
=
3884 inherit lvsourcebase
3885 val mutable m_items
= empty
3886 val mutable m_orig_items
= empty
3887 val mutable m_prev_items
= empty
3888 val mutable m_narrow_pattern
= ""
3889 val mutable m_hadremovals
= false
3891 method getitemcount
=
3892 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3895 if n == Array.length m_items
&& m_hadremovals
3897 ("[Confirm removal]", 0)
3899 let s, n, _ = m_items
.(n) in
3902 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3903 ignore
(uioh
, first, qsearch);
3904 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3906 if String.length m_narrow_pattern
= 0
3912 if not
confrimremoval
3914 let _, _, anchor = m_items
.(active) in
3915 gotoghyll (getanchory anchor);
3919 state.bookmarks
<- Array.to_list m_items
;
3920 m_orig_items
<- m_items
;
3923 else m_items
<- items;
3927 method hasaction
_ = true
3930 if Array.length m_items
!= Array.length m_orig_items
3931 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3934 method narrow
pattern =
3935 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3939 let rec loop accu n =
3942 m_narrow_pattern
<- pattern;
3943 m_items
<- Array.of_list
accu
3946 let (s, _, _) as o = m_items
.(n) in
3948 if (try ignore
(Str.search_forward
re s 0); true
3949 with Not_found
-> false)
3955 loop [] (Array.length m_items
- 1)
3960 then Array.of_list
state.bookmarks
3963 m_items
<- m_orig_items
3968 if m >= 0 && m < Array.length m_items
3970 m_hadremovals
<- true;
3971 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3972 let n = if n >= m then n+1 else n in
3977 method reset
anchor items =
3978 m_hadremovals
<- false;
3979 if m_orig_items
== empty || m_prev_items
!= items
3981 m_orig_items
<- items;
3982 if String.length m_narrow_pattern
= 0
3983 then m_items
<- items;
3985 m_prev_items
<- items;
3986 let rely = getanchory anchor in
3988 let rec loop n best bestd
=
3989 if n = Array.length m_items
3992 let (_, _, anchor) = m_items
.(n) in
3993 let orely = getanchory anchor in
3994 let d = abs
(orely - rely) in
3997 else loop (n+1) best bestd
4002 m_first
<- firstof m_first
active
4006 let enterselector usebookmarks
=
4007 let source = outlinesource usebookmarks
in
4011 then Array.of_list
state.bookmarks
4014 if Array.length
outlines = 0
4016 showtext ' ' errmsg
;
4019 state.text <- source#greetmsg
;
4020 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4021 let anchor = getanchor () in
4022 source#reset
anchor outlines;
4023 state.uioh
<- coe (new outlinelistview ~
source);
4024 G.postRedisplay "enter selector";
4028 let enteroutlinemode =
4029 let f = enterselector false in
4030 fun ()-> f "Document has no outline";
4033 let enterbookmarkmode =
4034 let f = enterselector true in
4035 fun () -> f "Document has no bookmarks (yet)";
4038 let color_of_string s =
4039 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4040 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4044 let color_to_string (r, g, b) =
4045 let r = truncate
(r *. 256.0)
4046 and g = truncate
(g *. 256.0)
4047 and b = truncate
(b *. 256.0) in
4048 Printf.sprintf
"%d/%d/%d" r g b
4051 let irect_of_string s =
4052 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4055 let irect_to_string (x0,y0,x1,y1) =
4056 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4059 let makecheckers () =
4060 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4062 converted by Issac Trotts. July 25, 2002 *)
4063 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4064 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4065 let id = GlTex.gen_texture
() in
4066 GlTex.bind_texture `texture_2d
id;
4067 GlPix.store
(`unpack_alignment
1);
4068 GlTex.image2d
image;
4069 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4070 [ `mag_filter `nearest
; `min_filter `nearest
];
4074 let setcheckers enabled
=
4075 match state.texid
with
4077 if enabled
then state.texid
<- Some
(makecheckers ())
4082 GlTex.delete_texture texid
;
4083 state.texid
<- None
;
4087 let int_of_string_with_suffix s =
4088 let l = String.length
s in
4092 let suffix = Char.lowercase
s.[l-1] in
4094 | 'k'
-> String.sub
s 0 (l-1), 10
4095 | '
m'
-> String.sub
s 0 (l-1), 20
4096 | '
g'
-> String.sub
s 0 (l-1), 30
4100 let n = int_of_string
s1 in
4101 let m = n lsl shift
in
4103 then raise
(Failure
"value too large")
4107 let string_with_suffix_of_int n =
4112 if n land ((1 lsl 30) - 1) = 0
4115 if n land ((1 lsl 20) - 1) = 0
4118 if n land ((1 lsl 10) - 1) = 0
4125 let h = n mod 1000 in
4128 then string_of_int
h ^
s
4130 let s = Printf.sprintf
"_%03d%s" h s in
4137 let defghyllscroll = (40, 8, 32);;
4138 let ghyllscroll_of_string s =
4139 let (n, a, b) as nab
=
4142 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4144 if n <= a || n <= b || a >= b
4145 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4149 let ghyllscroll_to_string ((n, a, b) as nab
) =
4150 if nab
= defghyllscroll
4152 else Printf.sprintf
"%d,%d,%d" n a b;
4155 let describe_location () =
4156 let fn = page_of_y state.y in
4157 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4158 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4162 else (100. *. (float state.y /. float maxy))
4166 Printf.sprintf
"page %d of %d [%.2f%%]"
4167 (fn+1) state.pagecount
percent
4170 "pages %d-%d of %d [%.2f%%]"
4171 (fn+1) (ln+1) state.pagecount
percent
4174 let setpresentationmode v
=
4175 let n = page_of_y state.y in
4176 state.anchor <- (n, 0.0, 1.0);
4177 conf.presentation
<- v
;
4178 if conf.fitmodel
= FitPage
4179 then reqlayout conf.angle
conf.fitmodel
;
4184 let btos b = if b then "\xe2\x88\x9a" else "" in
4185 let showextended = ref false in
4186 let leave mode
= function
4187 | Confirm
-> state.mode
<- mode
4188 | Cancel
-> state.mode
<- mode
in
4191 val mutable m_first_time
= true
4192 val mutable m_l
= []
4193 val mutable m_a
= [||]
4194 val mutable m_prev_uioh
= nouioh
4195 val mutable m_prev_mode
= View
4197 inherit lvsourcebase
4199 method reset prev_mode prev_uioh
=
4200 m_a
<- Array.of_list
(List.rev m_l
);
4202 m_prev_mode
<- prev_mode
;
4203 m_prev_uioh
<- prev_uioh
;
4207 if n >= Array.length m_a
4211 | _, _, _, Action
_ -> m_active
<- n
4215 m_first_time
<- false;
4218 method int name get
set =
4220 (name
, `
int get
, 1, Action
(
4223 try set (int_of_string
s)
4225 state.text <- Printf.sprintf
"bad integer `%s': %s"
4229 let te = name ^
": ", "", None
, intentry, ondone, true in
4230 state.mode
<- Textentry
(te, leave m_prev_mode
);
4234 method int_with_suffix name get
set =
4236 (name
, `intws get
, 1, Action
(
4239 try set (int_of_string_with_suffix s)
4241 state.text <- Printf.sprintf
"bad integer `%s': %s"
4246 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4248 state.mode
<- Textentry
(te, leave m_prev_mode
);
4252 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4254 (name
, `
bool (btos, get
), offset
, Action
(
4261 method color name get
set =
4263 (name
, `color get
, 1, Action
(
4265 let invalid = (nan
, nan
, nan
) in
4268 try color_of_string s
4270 state.text <- Printf.sprintf
"bad color `%s': %s"
4277 let te = name ^
": ", "", None
, textentry, ondone, true in
4278 state.text <- color_to_string (get
());
4279 state.mode
<- Textentry
(te, leave m_prev_mode
);
4283 method string name get
set =
4285 (name
, `
string get
, 1, Action
(
4287 let ondone s = set s in
4288 let te = name ^
": ", "", None
, textentry, ondone, true in
4289 state.mode
<- Textentry
(te, leave m_prev_mode
);
4293 method colorspace name get
set =
4295 (name
, `
string get
, 1, Action
(
4298 let vals = [| "rgb"; "bgr"; "gray" |] in
4300 inherit lvsourcebase
4303 m_active
<- int_of_colorspace conf.colorspace
;
4306 method getitemcount
= Array.length
vals
4307 method getitem
n = (vals.(n), 0)
4308 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4309 ignore
(uioh
, first, pan
, qsearch);
4310 if not cancel
then set active;
4312 method hasaction
_ = true
4316 let modehash = findkeyhash conf "info" in
4317 coe (new listview ~
source ~trusted
:true ~
modehash)
4320 method fitmodel name get
set =
4322 (name
, `
string get
, 1, Action
(
4325 let vals = [| "fit width"; "proportional"; "fit page" |] in
4327 inherit lvsourcebase
4330 m_active
<- int_of_fitmodel conf.fitmodel
;
4333 method getitemcount
= Array.length
vals
4334 method getitem
n = (vals.(n), 0)
4335 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4336 ignore
(uioh
, first, pan
, qsearch);
4337 if not cancel
then set active;
4339 method hasaction
_ = true
4343 let modehash = findkeyhash conf "info" in
4344 coe (new listview ~
source ~trusted
:true ~
modehash)
4347 method caption
s offset
=
4348 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4350 method caption2
s f offset
=
4351 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4353 method getitemcount
= Array.length m_a
4356 let tostr = function
4357 | `
int f -> string_of_int
(f ())
4358 | `intws
f -> string_with_suffix_of_int (f ())
4360 | `color
f -> color_to_string (f ())
4361 | `
bool (btos, f) -> btos (f ())
4364 let name, t
, offset
, _ = m_a
.(n) in
4365 ((let s = tostr t
in
4366 if String.length
s > 0
4367 then Printf.sprintf
"%s\t%s" name s
4371 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4375 m_qsearch
<- qsearch;
4377 match m_a
.(active) with
4378 | _, _, _, Action
f -> f uioh
4390 method hasaction
n =
4392 | _, _, _, Action
_ -> true
4396 let rec fillsrc prevmode prevuioh
=
4397 let sep () = src#caption
"" 0 in
4398 let colorp name get
set =
4400 (fun () -> color_to_string (get
()))
4403 let c = color_of_string v in
4406 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4409 let oldmode = state.mode
in
4410 let birdseye = isbirdseye state.mode
in
4412 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4414 src#
bool "presentation mode"
4415 (fun () -> conf.presentation
)
4416 (fun v -> setpresentationmode v);
4418 src#
bool "ignore case in searches"
4419 (fun () -> conf.icase
)
4420 (fun v -> conf.icase
<- v);
4423 (fun () -> conf.preload)
4424 (fun v -> conf.preload <- v);
4426 src#
bool "highlight links"
4427 (fun () -> conf.hlinks
)
4428 (fun v -> conf.hlinks
<- v);
4430 src#
bool "under info"
4431 (fun () -> conf.underinfo
)
4432 (fun v -> conf.underinfo
<- v);
4434 src#
bool "persistent bookmarks"
4435 (fun () -> conf.savebmarks
)
4436 (fun v -> conf.savebmarks
<- v);
4438 src#fitmodel
"fit model"
4439 (fun () -> fitmodel_to_string conf.fitmodel
)
4440 (fun v -> reqlayout conf.angle
(fitmodel_of_int v));
4442 src#
bool "trim margins"
4443 (fun () -> conf.trimmargins
)
4444 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4446 src#
bool "persistent location"
4447 (fun () -> conf.jumpback
)
4448 (fun v -> conf.jumpback
<- v);
4451 src#
int "inter-page space"
4452 (fun () -> conf.interpagespace
)
4454 conf.interpagespace
<- n;
4455 docolumns conf.columns
;
4457 match state.layout with
4462 state.maxy <- calcheight ();
4463 let y = getpagey pageno in
4468 (fun () -> conf.pagebias
)
4469 (fun v -> conf.pagebias
<- v);
4471 src#
int "scroll step"
4472 (fun () -> conf.scrollstep
)
4473 (fun n -> conf.scrollstep
<- n);
4475 src#
int "horizontal scroll step"
4476 (fun () -> conf.hscrollstep
)
4477 (fun v -> conf.hscrollstep
<- v);
4479 src#
int "auto scroll step"
4481 match state.autoscroll
with
4483 | _ -> conf.autoscrollstep
)
4485 if state.autoscroll
<> None
4486 then state.autoscroll
<- Some
n;
4487 conf.autoscrollstep
<- n);
4490 (fun () -> truncate
(conf.zoom *. 100.))
4491 (fun v -> setzoom ((float v) /. 100.));
4494 (fun () -> conf.angle
)
4495 (fun v -> reqlayout v conf.fitmodel
);
4497 src#
int "scroll bar width"
4498 (fun () -> conf.scrollbw
)
4501 reshape state.winw
state.winh
;
4504 src#
int "scroll handle height"
4505 (fun () -> conf.scrollh
)
4506 (fun v -> conf.scrollh
<- v;);
4508 src#
int "thumbnail width"
4509 (fun () -> conf.thumbw
)
4511 conf.thumbw
<- min
4096 v;
4514 leavebirdseye beye
false;
4519 let mode = state.mode in
4520 src#
string "columns"
4522 match conf.columns
with
4524 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4525 | Csplit
(count
, _) -> "-" ^ string_of_int count
4528 let n, a, b = multicolumns_of_string v in
4529 setcolumns mode n a b);
4532 src#caption
"Pixmap cache" 0;
4533 src#int_with_suffix
"size (advisory)"
4534 (fun () -> conf.memlimit
)
4535 (fun v -> conf.memlimit
<- v);
4538 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4539 (string_with_suffix_of_int state.memused
)
4540 (Hashtbl.length
state.tilemap
)) 1;
4543 src#caption
"Layout" 0;
4544 src#caption2
"Dimension"
4546 Printf.sprintf
"%dx%d (virtual %dx%d)"
4547 state.winw
state.winh
4552 src#caption2
"Position" (fun () ->
4553 Printf.sprintf
"%dx%d" state.x state.y
4556 src#caption2
"Position" (fun () -> describe_location ()) 1
4560 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4561 "Save these parameters as global defaults at exit"
4562 (fun () -> conf.bedefault
)
4563 (fun v -> conf.bedefault
<- v)
4567 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4568 src#
bool ~offset
:0 ~
btos "Extended parameters"
4569 (fun () -> !showextended)
4570 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4574 (fun () -> conf.checkers
)
4575 (fun v -> conf.checkers
<- v; setcheckers v);
4576 src#
bool "update cursor"
4577 (fun () -> conf.updatecurs
)
4578 (fun v -> conf.updatecurs
<- v);
4580 (fun () -> conf.verbose
)
4581 (fun v -> conf.verbose
<- v);
4582 src#
bool "invert colors"
4583 (fun () -> conf.invert
)
4584 (fun v -> conf.invert
<- v);
4586 (fun () -> conf.maxhfit
)
4587 (fun v -> conf.maxhfit
<- v);
4588 src#
bool "redirect stderr"
4589 (fun () -> conf.redirectstderr)
4590 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4591 src#
string "uri launcher"
4592 (fun () -> conf.urilauncher
)
4593 (fun v -> conf.urilauncher
<- v);
4594 src#
string "path launcher"
4595 (fun () -> conf.pathlauncher
)
4596 (fun v -> conf.pathlauncher
<- v);
4597 src#
string "tile size"
4598 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4601 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4602 conf.tilew
<- max
64 w;
4603 conf.tileh
<- max
64 h;
4606 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4609 src#
int "texture count"
4610 (fun () -> conf.texcount
)
4613 then conf.texcount
<- v
4614 else showtext '
!'
" Failed to set texture count please retry later"
4616 src#
int "slice height"
4617 (fun () -> conf.sliceheight
)
4619 conf.sliceheight
<- v;
4620 wcmd "sliceh %d" conf.sliceheight
;
4622 src#
int "anti-aliasing level"
4623 (fun () -> conf.aalevel
)
4625 conf.aalevel
<- bound v 0 8;
4626 state.anchor <- getanchor ();
4627 opendoc state.path
state.password
;
4629 src#
string "page scroll scaling factor"
4630 (fun () -> string_of_float
conf.pgscale)
4633 let s = float_of_string
v in
4636 state.text <- Printf.sprintf
4637 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4640 src#
int "ui font size"
4641 (fun () -> fstate.fontsize
)
4642 (fun v -> setfontsize (bound v 5 100));
4643 src#
int "hint font size"
4644 (fun () -> conf.hfsize
)
4645 (fun v -> conf.hfsize
<- bound v 5 100);
4646 colorp "background color"
4647 (fun () -> conf.bgcolor
)
4648 (fun v -> conf.bgcolor
<- v);
4649 src#
bool "crop hack"
4650 (fun () -> conf.crophack
)
4651 (fun v -> conf.crophack
<- v);
4652 src#
string "trim fuzz"
4653 (fun () -> irect_to_string conf.trimfuzz
)
4656 conf.trimfuzz
<- irect_of_string v;
4658 then settrim true conf.trimfuzz
;
4660 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4662 src#
string "throttle"
4664 match conf.maxwait
with
4665 | None
-> "show place holder if page is not ready"
4668 then "wait for page to fully render"
4670 "wait " ^ string_of_float
time
4671 ^
" seconds before showing placeholder"
4675 let f = float_of_string
v in
4677 then conf.maxwait
<- None
4678 else conf.maxwait
<- Some
f
4680 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4682 src#
string "ghyll scroll"
4684 match conf.ghyllscroll
with
4686 | Some nab
-> ghyllscroll_to_string nab
4691 if String.length
v = 0
4693 else Some
(ghyllscroll_of_string v)
4695 conf.ghyllscroll
<- gs
4697 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4699 src#
string "selection command"
4700 (fun () -> conf.selcmd
)
4701 (fun v -> conf.selcmd
<- v);
4702 src#
string "synctex command"
4703 (fun () -> conf.stcmd
)
4704 (fun v -> conf.stcmd
<- v);
4705 src#colorspace
"color space"
4706 (fun () -> colorspace_to_string conf.colorspace
)
4708 conf.colorspace
<- colorspace_of_int v;
4715 (fun () -> conf.usepbo
)
4716 (fun v -> conf.usepbo
<- v);
4717 src#
bool "mouse wheel scrolls pages"
4718 (fun () -> conf.wheelbypage
)
4719 (fun v -> conf.wheelbypage
<- v);
4723 src#caption
"Document" 0;
4724 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4725 src#caption2
"Pages"
4726 (fun () -> string_of_int
state.pagecount
) 1;
4727 src#caption2
"Dimensions"
4728 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4732 src#caption
"Trimmed margins" 0;
4733 src#caption2
"Dimensions"
4734 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4738 src#caption
"OpenGL" 0;
4739 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4740 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4743 src#caption
"Location" 0;
4744 if String.length
state.origin
> 0
4745 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4746 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4748 src#reset prevmode prevuioh
;
4752 let prevmode = state.mode
4753 and prevuioh
= state.uioh in
4754 fillsrc prevmode prevuioh
;
4755 let source = (src :> lvsource
) in
4756 let modehash = findkeyhash conf "info" in
4757 state.uioh <- coe (object (self)
4758 inherit listview ~
source ~trusted
:true ~
modehash as super
4759 val mutable m_prevmemused
= 0
4760 method infochanged
= function
4762 if m_prevmemused
!= state.memused
4764 m_prevmemused
<- state.memused
;
4765 G.postRedisplay "memusedchanged";
4767 | Pdim
-> G.postRedisplay "pdimchanged"
4768 | Docinfo
-> fillsrc prevmode prevuioh
4770 method key key mask
=
4771 if not
(Wsi.withctrl mask
)
4774 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4775 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4776 | _ -> super#
key key mask
4777 else super#
key key mask
4779 G.postRedisplay "info";
4785 inherit lvsourcebase
4786 method getitemcount
= Array.length
state.help
4788 let s, l, _ = state.help
.(n) in
4791 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4795 m_qsearch
<- qsearch;
4796 match state.help
.(active) with
4797 | _, _, Action
f -> Some
(f uioh)
4807 method hasaction
n =
4808 match state.help
.(n) with
4809 | _, _, Action
_ -> true
4816 let modehash = findkeyhash conf "help" in
4817 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4818 G.postRedisplay "help";
4823 let re = Str.regexp
"[\r\n]" in
4825 inherit lvsourcebase
4826 val mutable m_items
= [||]
4828 method getitemcount
= 1 + Array.length m_items
4833 else m_items
.(n-1), 0
4835 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4840 then Buffer.clear
state.errmsgs
;
4841 m_qsearch
<- qsearch;
4848 method hasaction
n =
4852 state.newerrmsgs
<- false;
4853 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4854 m_items
<- Array.of_list
l
4862 let source = (msgsource :> lvsource
) in
4863 let modehash = findkeyhash conf "listview" in
4864 state.uioh <- coe (object
4865 inherit listview ~
source ~trusted
:false ~
modehash as super
4868 then msgsource#reset
;
4871 G.postRedisplay "msgs";
4874 let quickbookmark ?title
() =
4875 match state.layout with
4881 let sec = Unix.gettimeofday
() in
4882 let tm = Unix.localtime
sec in
4883 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4887 (tm.Unix.tm_year
+ 1900)
4890 | Some
title -> title
4892 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4895 let setautoscrollspeed step goingdown
=
4896 let incr = max
1 ((abs step
) / 2) in
4897 let incr = if goingdown
then incr else -incr in
4898 let astep = step
+ incr in
4899 state.autoscroll
<- Some
astep;
4902 let gotounder = function
4903 | Ulinkgoto
(pageno, top) ->
4907 gotopage1 pageno top;
4913 | Uremote
(filename
, pageno) ->
4915 if Sys.file_exists filename
4918 let dir = Filename.dirname
state.path in
4919 let path = Filename.concat
dir filename
in
4920 if Sys.file_exists
path
4924 if String.length
path > 0
4926 let anchor = getanchor () in
4927 let ranchor = state.path, state.password
, anchor, state.origin
in
4929 state.anchor <- (pageno, 0.0, 0.0);
4930 state.ranchors
<- ranchor :: state.ranchors
;
4933 else showtext '
!'
("Could not find " ^ filename
)
4935 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4939 match conf.columns
with
4941 | _ -> state.x != 0 || conf.zoom > 1.0
4944 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
4946 let existsinrow pageno (columns
, coverA
, coverB
) p =
4947 let last = ((pageno - coverA
) mod columns
) + columns
in
4948 let rec any = function
4951 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4955 then (if l.pageno = last then false else any rest
)
4963 match state.layout with
4965 let pageno = page_of_y state.y in
4966 gotoghyll (getpagey (pageno+1))
4968 match conf.columns
with
4970 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4972 let y = clamp (pgscale state.winh
) in
4975 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4976 gotoghyll (getpagey pageno)
4977 | Cmulti
((c, _, _) as cl, _) ->
4978 if conf.presentation
4979 && (existsinrow l.pageno cl
4980 (fun l -> l.pageh
> l.pagey + l.pagevh))
4982 let y = clamp (pgscale state.winh
) in
4985 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4986 gotoghyll (getpagey pageno)
4988 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4990 let pagey, pageh
= getpageyh l.pageno in
4991 let pagey = pagey + pageh
* l.pagecol
in
4992 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4993 gotoghyll (pagey + pageh
+ ips)
4997 match state.layout with
4999 let pageno = page_of_y state.y in
5000 gotoghyll (getpagey (pageno-1))
5002 match conf.columns
with
5004 if conf.presentation
&& l.pagey != 0
5006 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5008 let pageno = max
0 (l.pageno-1) in
5009 gotoghyll (getpagey pageno)
5010 | Cmulti
((c, _, coverB
) as cl, _) ->
5011 if conf.presentation
&&
5012 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5014 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5017 if l.pageno = state.pagecount
- coverB
5021 let pageno = max
0 (l.pageno-decr) in
5022 gotoghyll (getpagey pageno)
5030 let pageno = max
0 (l.pageno-1) in
5031 let pagey, pageh
= getpageyh pageno in
5034 let pagey, pageh
= getpageyh l.pageno in
5035 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5040 let viewkeyboard key mask
=
5042 let mode = state.mode in
5043 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5046 G.postRedisplay "view:enttext"
5048 let ctrl = Wsi.withctrl mask
in
5050 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5056 | 0xff63 -> (* insert *)
5057 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5059 state.mode <- LinkNav
(Ltgendir
0);
5062 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5064 | 0xff1b | 113 -> (* escape / q *)
5065 begin match state.mstate
with
5067 state.mstate
<- Mnone
;
5068 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5069 G.postRedisplay "kill zoom rect";
5071 begin match state.mode with
5074 G.postRedisplay "esc leave linknav"
5076 match state.ranchors
with
5078 | (path, password
, anchor, origin
) :: rest
->
5079 state.ranchors
<- rest
;
5080 state.anchor <- anchor;
5081 state.origin
<- origin
;
5082 opendoc path password
5086 | 0xff08 -> (* backspace *)
5087 gotoghyll (getnav ~
-1)
5095 G.postRedisplay "dehighlight";
5097 | 47 | 63 -> (* / ? *)
5098 let ondone isforw
s =
5099 cbput state.hists
.pat
s;
5100 state.searchpattern
<- s;
5103 let s = String.create
1 in
5104 s.[0] <- Char.chr
key;
5105 enttext (s, "", Some
(onhist state.hists
.pat
),
5106 textentry, ondone (key = 47), true)
5108 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5109 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5110 setzoom (conf.zoom +. incr)
5112 | 43 | 0xffab -> (* + *)
5115 try int_of_string
s with exc
->
5116 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5122 state.text <- "page bias is now " ^ string_of_int
n;
5125 enttext ("page bias: ", "", None
, intentry, ondone, true)
5127 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5128 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5129 setzoom (max
0.01 (conf.zoom -. decr))
5131 | 45 | 0xffad -> (* - *)
5132 let ondone msg
= state.text <- msg
in
5134 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
5135 optentry state.mode, ondone, true
5138 | 48 when ctrl -> (* ctrl-0 *)
5146 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5148 match conf.columns
with
5149 | Csingle
_ | Cmulti
_ -> 1
5150 | Csplit
(n, _) -> n
5152 let h = state.winh
-
5153 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5155 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5156 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5159 | 51 when ctrl -> (* ctrl-3 *)
5161 match conf.fitmodel
with
5162 | FitWidth
-> FitProportional
5163 | FitProportional
-> FitPage
5164 | FitPage
-> FitWidth
5166 state.text <- "fit model: " ^
fitmodel_to_string fm;
5167 reqlayout conf.angle
fm
5169 | 0xffc6 -> (* f9 *)
5172 | 57 when ctrl -> (* ctrl-9 *)
5175 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5176 when not
ctrl -> (* 0..9 *)
5179 try int_of_string
s with exc
->
5180 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5186 cbput state.hists
.pag
(string_of_int
n);
5187 gotopage1 (n + conf.pagebias
- 1) 0;
5190 let pageentry text key =
5191 match Char.unsafe_chr
key with
5192 | '
g'
-> TEdone
text
5193 | _ -> intentry text key
5195 let text = "x" in text.[0] <- Char.chr
key;
5196 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5199 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5200 reshape state.winw
state.winh
;
5203 conf.hlinks
<- not
conf.hlinks
;
5204 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5205 G.postRedisplay "toggle highlightlinks";
5208 state.glinks
<- true;
5209 let mode = state.mode in
5210 state.mode <- Textentry
(
5211 (":", "", None
, linknentry, linkndone gotounder, false),
5213 state.glinks
<- false;
5217 G.postRedisplay "view:linkent(F)"
5220 state.glinks
<- true;
5221 let mode = state.mode in
5222 state.mode <- Textentry
(
5224 ":", "", None
, linknentry, linkndone (fun under ->
5225 selstring (undertext under);
5229 state.glinks
<- false;
5233 G.postRedisplay "view:linkent"
5236 begin match state.autoscroll
with
5238 conf.autoscrollstep
<- step
;
5239 state.autoscroll
<- None
5241 if conf.autoscrollstep
= 0
5242 then state.autoscroll
<- Some
1
5243 else state.autoscroll
<- Some
conf.autoscrollstep
5246 | 112 when ctrl -> (* ctrl-p *)
5250 setpresentationmode (not
conf.presentation
);
5251 showtext ' '
("presentation mode " ^
5252 if conf.presentation
then "on" else "off");
5255 if List.mem
Wsi.Fullscreen
state.winstate
5256 then Wsi.reshape conf.cwinw
conf.cwinh
5257 else Wsi.fullscreen
()
5259 | 112 | 78 -> (* p|N *)
5260 search state.searchpattern
false
5262 | 110 | 0xffc0 -> (* n|F3 *)
5263 search state.searchpattern
true
5266 begin match state.layout with
5269 gotoghyll (getpagey l.pageno)
5275 | 0xff9f | 0xffff -> (* delete *)
5279 showtext ' '
(describe_location ());
5282 begin match state.layout with
5285 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5290 enterbookmarkmode ()
5292 | 104 | 0xffbe -> (* h|F1 *)
5298 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5303 match state.layout with
5305 if String.length
s > 0
5307 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5310 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5314 showtext ' '
"Quick bookmark added";
5317 begin match state.layout with
5319 let rect = getpdimrect
l.pagedimno
in
5323 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5324 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5326 (truncate
(rect.(1) -. rect.(0)),
5327 truncate
(rect.(3) -. rect.(0)))
5329 let w = truncate
((float w)*.conf.zoom)
5330 and h = truncate
((float h)*.conf.zoom) in
5333 state.anchor <- getanchor ();
5334 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5336 G.postRedisplay "z";
5341 | 60 | 62 -> (* < > *)
5342 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5344 | 91 | 93 -> (* [ ] *)
5346 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5348 G.postRedisplay "brightness";
5350 | 99 when state.mode = View
-> (* [alt]-c *)
5355 let m = (wadjsb state.winw
- state.w) / 2 in
5357 gotoy_and_clear_text state.y
5361 match state.prevcolumns
with
5362 | None
-> (1, 0, 0), 1.0
5363 | Some
(columns
, z
) ->
5366 | Csplit
(c, _) -> -c, 0, 0
5367 | Cmulti
((c, a, b), _) -> c, a, b
5368 | Csingle
_ -> 1, 0, 0
5372 setcolumns View
c a b;
5375 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5376 setzoom state.prevzoom
5378 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5379 begin match state.autoscroll
with
5381 begin match state.mode with
5382 | Birdseye beye
-> upbirdseye 1 beye
5385 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5387 if not
(Wsi.withshift mask
) && conf.presentation
5389 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5393 setautoscrollspeed n false
5396 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5397 begin match state.autoscroll
with
5399 begin match state.mode with
5400 | Birdseye beye
-> downbirdseye 1 beye
5403 then gotoy_and_clear_text (clamp (state.winh
/2))
5405 if not
(Wsi.withshift mask
) && conf.presentation
5407 else gotoy_and_clear_text (clamp conf.scrollstep
)
5411 setautoscrollspeed n true
5414 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5415 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5421 else conf.hscrollstep
5423 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5424 state.x <- panbound (state.x + dx);
5425 gotoy_and_clear_text state.y
5428 G.postRedisplay "left/right"
5431 | 0xff55 | 0xff9a -> (* (kp) prior *)
5435 match state.layout with
5437 | l :: _ -> state.y - l.pagey
5439 clamp (pgscale (-state.winh
))
5443 | 0xff56 | 0xff9b -> (* (kp) next *)
5447 match List.rev
state.layout with
5449 | l :: _ -> getpagey l.pageno
5451 clamp (pgscale state.winh
)
5455 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5457 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5458 gotoghyll (clamp state.maxy)
5461 when Wsi.withalt mask
-> (* alt-(kp) right *)
5462 gotoghyll (getnav 1)
5464 when Wsi.withalt mask
-> (* alt-(kp) left *)
5465 gotoghyll (getnav ~
-1)
5470 | 118 when conf.debug
-> (* v *)
5473 match getopaque l.pageno with
5476 let x0, y0, x1, y1 = pagebbox opaque
in
5477 let a,b = float x0, float y0 in
5478 let c,d = float x1, float y0 in
5479 let e,f = float x1, float y1 in
5480 let h,j
= float x0, float y1 in
5481 let rect = (a,b,c,d,e,f,h,j
) in
5483 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5485 G.postRedisplay "v";
5488 vlog "huh? %s" (Wsi.keyname
key)
5491 let linknavkeyboard key mask
linknav =
5492 let getpage pageno =
5493 let rec loop = function
5495 | l :: _ when l.pageno = pageno -> Some
l
5496 | _ :: rest
-> loop rest
5497 in loop state.layout
5499 let doexact (pageno, n) =
5500 match getopaque pageno, getpage pageno with
5501 | Some opaque
, Some
l ->
5502 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5504 let under = getlink opaque
n in
5505 G.postRedisplay "link gotounder";
5511 | 0xff50 -> (* home *)
5512 Some
(findlink opaque LDfirst
), -1
5514 | 0xff57 -> (* end *)
5515 Some
(findlink opaque LDlast
), 1
5517 | 0xff51 -> (* left *)
5518 Some
(findlink opaque
(LDleft
n)), -1
5520 | 0xff53 -> (* right *)
5521 Some
(findlink opaque
(LDright
n)), 1
5523 | 0xff52 -> (* up *)
5524 Some
(findlink opaque
(LDup
n)), -1
5526 | 0xff54 -> (* down *)
5527 Some
(findlink opaque
(LDdown
n)), 1
5532 begin match findpwl
l.pageno dir with
5536 state.mode <- LinkNav
(Ltgendir
dir);
5537 let y, h = getpageyh pageno in
5540 then y + h - state.winh
5545 begin match getopaque pageno, getpage pageno with
5546 | Some opaque
, Some
_ ->
5548 let ld = if dir > 0 then LDfirst
else LDlast
in
5551 begin match link with
5553 showlinktype (getlink opaque
m);
5554 state.mode <- LinkNav
(Ltexact
(pageno, m));
5555 G.postRedisplay "linknav jpage";
5562 begin match opt with
5563 | Some Lnotfound
-> pwl l dir;
5564 | Some
(Lfound
m) ->
5568 let _, y0, _, y1 = getlinkrect opaque
m in
5570 then gotopage1 l.pageno y0
5572 let d = fstate.fontsize
+ 1 in
5573 if y1 - l.pagey > l.pagevh - d
5574 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5575 else G.postRedisplay "linknav";
5577 showlinktype (getlink opaque
m);
5578 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5581 | None
-> viewkeyboard key mask
5583 | _ -> viewkeyboard key mask
5588 G.postRedisplay "leave linknav"
5592 | Ltgendir
_ -> viewkeyboard key mask
5593 | Ltexact exact
-> doexact exact
5596 let keyboard key mask
=
5597 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5598 then wcmd "interrupt"
5599 else state.uioh <- state.uioh#
key key mask
5602 let birdseyekeyboard key mask
5603 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5605 match conf.columns
with
5607 | Cmulti
((c, _, _), _) -> c
5608 | Csplit
_ -> failwith
"bird's eye split mode"
5610 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5612 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5613 let y, h = getpageyh pageno in
5614 let top = (state.winh
- h) / 2 in
5615 gotoy (max
0 (y - top))
5616 | 0xff0d (* enter *)
5617 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5618 | 0xff1b -> leavebirdseye beye
true (* escape *)
5619 | 0xff52 -> upbirdseye incr beye
(* up *)
5620 | 0xff54 -> downbirdseye incr beye
(* down *)
5621 | 0xff51 -> upbirdseye 1 beye
(* left *)
5622 | 0xff53 -> downbirdseye 1 beye
(* right *)
5624 | 0xff55 -> (* prior *)
5625 begin match state.layout with
5629 state.mode <- Birdseye
(
5630 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5632 gotopage1 l.pageno 0;
5635 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5637 | [] -> gotoy (clamp (-state.winh
))
5639 state.mode <- Birdseye
(
5640 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5642 gotopage1 l.pageno 0
5645 | [] -> gotoy (clamp (-state.winh
))
5648 | 0xff56 -> (* next *)
5649 begin match List.rev
state.layout with
5651 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5652 begin match layout with
5654 let incr = l.pageh
- l.pagevh in
5659 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5661 G.postRedisplay "birdseye pagedown";
5663 else gotoy (clamp (incr + conf.interpagespace
*2));
5667 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5668 gotopage1 l.pageno 0;
5671 | [] -> gotoy (clamp state.winh
)
5674 | 0xff50 -> (* home *)
5675 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5678 | 0xff57 -> (* end *)
5679 let pageno = state.pagecount
- 1 in
5680 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5681 if not
(pagevisible state.layout pageno)
5684 match List.rev
state.pdims
with
5686 | (_, _, h, _) :: _ -> h
5688 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5689 else G.postRedisplay "birdseye end";
5690 | _ -> viewkeyboard key mask
5695 match state.mode with
5696 | Textentry
_ -> scalecolor 0.4
5698 | View
-> scalecolor 1.0
5699 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5700 if l.pageno = hooverpageno
5703 if l.pageno = pageno
5711 let postdrawpage l linkindexbase
=
5712 match getopaque l.pageno with
5714 if tileready l l.pagex
l.pagey
5716 let x = l.pagedispx - l.pagex
5717 and y = l.pagedispy - l.pagey in
5719 match conf.columns
with
5720 | Csingle
_ | Cmulti
_ ->
5721 (if conf.hlinks
then 1 else 0)
5723 && not
(isbirdseye state.mode) then 2 else 0)
5727 match state.mode with
5728 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5731 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5736 let scrollindicator () =
5737 let sbw, ph
, sh = state.uioh#
scrollph in
5738 let sbh, pw, sw = state.uioh#scrollpw
in
5740 GlDraw.color (0.64, 0.64, 0.64);
5742 (float (state.winw
- sbw), 0.)
5743 (float state.winw
, float state.winh
)
5746 (0., float (state.winh
- sbh))
5747 (float (wadjsb state.winw
- 1), float state.winh
)
5749 GlDraw.color (0.0, 0.0, 0.0);
5752 (float (state.winw
- sbw), ph
)
5753 (float state.winw
, ph
+. sh)
5756 (pw, float (state.winh
- sbh))
5757 (pw +. sw, float state.winh
)
5762 match state.mstate
with
5763 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5766 | Msel
((x0, y0), (x1, y1)) ->
5767 let rec loop = function
5769 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5770 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5771 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5772 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5774 match getopaque l.pageno with
5776 let x0, y0 = pagetranslatepoint l x0 y0 in
5777 let x1, y1 = pagetranslatepoint l x1 y1 in
5778 seltext opaque
(x0, y0, x1, y1);
5786 let showrects rects
=
5788 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5789 GlDraw.polygon_mode `both `fill
;
5790 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5792 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5794 if l.pageno = pageno
5796 let dx = float (l.pagedispx - l.pagex
) in
5797 let dy = float (l.pagedispy - l.pagey) in
5798 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5799 GlDraw.begins `quads
;
5801 GlDraw.vertex2
(x0+.dx, y0+.dy);
5802 GlDraw.vertex2
(x1+.dx, y1+.dy);
5803 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5804 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5815 GlClear.color (scalecolor2 conf.bgcolor
);
5816 GlClear.clear
[`
color];
5817 List.iter
drawpage state.layout;
5819 match state.mode with
5820 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5821 begin match getopaque pageno with
5823 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5830 | None
-> state.rects
5835 let rec postloop linkindexbase
= function
5837 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5838 postloop linkindexbase rest
5842 postloop 0 state.layout;
5844 begin match state.mstate
with
5845 | Mzoomrect
((x0, y0), (x1, y1)) ->
5847 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5848 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5849 GlDraw.rect (float x0, float y0)
5850 (float x1, float y1);
5859 let zoomrect x y x1 y1 =
5862 and y0 = min
y y1 in
5863 gotoy (state.y + y0);
5864 state.anchor <- getanchor ();
5865 let zoom = (float state.w) /. float (x1 - x0) in
5867 match conf.fitmodel
, conf.columns
with
5868 | FitPage
, Csplit
_ ->
5869 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5872 let adjw = wadjsb state.winw
in
5874 then (adjw - state.w) / 2
5877 state.x <- (state.x + margin) - x0;
5879 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5880 state.mstate
<- Mnone
;
5884 let winw = wadjsb state.winw - 1 in
5885 let s = float x /. float winw in
5886 let destx = truncate
(float (state.w + winw) *. s) in
5887 state.x <- winw - destx;
5888 gotoy_and_clear_text state.y;
5889 state.mstate
<- Mscrollx
;
5893 let s = float y /. float state.winh
in
5894 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5895 gotoy_and_clear_text desty;
5896 state.mstate
<- Mscrolly
;
5899 let viewmouse button down
x y mask
=
5901 | n when (n == 4 || n == 5) && not down
->
5902 if Wsi.withctrl mask
5904 match state.mstate
with
5905 | Mzoom
(oldn
, i
) ->
5913 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5915 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5917 let zoom = conf.zoom -. incr in
5919 state.mstate
<- Mzoom
(n, 0);
5921 state.mstate
<- Mzoom
(n, i
+1);
5923 else state.mstate
<- Mzoom
(n, 0)
5925 | _ -> state.mstate
<- Mzoom
(n, 0)
5928 match state.autoscroll
with
5929 | Some step
-> setautoscrollspeed step
(n=4)
5931 if conf.wheelbypage
|| conf.presentation
5940 then -conf.scrollstep
5941 else conf.scrollstep
5943 let incr = incr * 2 in
5944 let y = clamp incr in
5945 gotoy_and_clear_text y
5948 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5950 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
5951 gotoy_and_clear_text state.y
5953 | 1 when Wsi.withshift mask
->
5954 state.mstate
<- Mnone
;
5957 match unproject x y with
5958 | Some
(pageno, ux
, uy
) ->
5959 let cmd = Printf.sprintf
5961 conf.stcmd
state.path pageno ux uy
5967 | 1 when Wsi.withctrl mask
->
5970 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5971 state.mstate
<- Mpan
(x, y)
5974 state.mstate
<- Mnone
5979 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5981 state.mstate
<- Mzoomrect
(p, p)
5984 match state.mstate
with
5985 | Mzoomrect
((x0, y0), _) ->
5986 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5987 then zoomrect x0 y0 x y
5989 state.mstate
<- Mnone
;
5990 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5991 G.postRedisplay "kill accidental zoom rect";
5994 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5995 state.mstate
<- Mnone
5998 | 1 when x > state.winw - vscrollw () ->
6001 let _, position, sh = state.uioh#
scrollph in
6002 if y > truncate
position && y < truncate
(position +. sh)
6003 then state.mstate
<- Mscrolly
6006 state.mstate
<- Mnone
6008 | 1 when y > state.winh
- hscrollh () ->
6011 let _, position, sw = state.uioh#scrollpw
in
6012 if x > truncate
position && x < truncate
(position +. sw)
6013 then state.mstate
<- Mscrollx
6016 state.mstate
<- Mnone
6019 let dest = if down
then getunder x y else Unone
in
6020 begin match dest with
6024 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6027 | Unone
when down
->
6028 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6029 state.mstate
<- Mpan
(x, y);
6031 | Unone
| Utext
_ ->
6034 if conf.angle
mod 360 = 0
6036 state.mstate
<- Msel
((x, y), (x, y));
6037 G.postRedisplay "mouse select";
6041 match state.mstate
with
6044 | Mzoom
_ | Mscrollx
| Mscrolly
->
6045 state.mstate
<- Mnone
6047 | Mzoomrect
((x0, y0), _) ->
6051 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6052 state.mstate
<- Mnone
6054 | Msel
((x0, y0), (x1, y1)) ->
6055 let rec loop = function
6059 let a0 = l.pagedispy in
6060 let a1 = a0 + l.pagevh in
6061 let b0 = l.pagedispx in
6062 let b1 = b0 + l.pagevw in
6063 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6064 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6068 match getopaque l.pageno with
6071 match Ne.pipe () with
6075 "can not create sel pipe: %s"
6078 let doclose what fd
=
6079 Ne.clo fd
(fun msg
->
6080 dolog
"%s close failed: %s" what msg
)
6083 popen conf.selcmd
[r, 0; w, -1];
6086 G.postRedisplay "copysel";
6088 dolog
"can not execute %S: %s"
6089 conf.selcmd
(exntos exn
);
6097 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6098 state.mstate
<- Mnone
;
6105 let birdseyemouse button down
x y mask
6106 (conf, leftx
, _, hooverpageno
, anchor) =
6109 let rec loop = function
6112 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6113 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6115 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6121 | _ -> viewmouse button down
x y mask
6124 let mouse button down
x y mask
=
6125 state.uioh <- state.uioh#button button down
x y mask
;
6129 state.uioh <- state.uioh#
motion x y
6133 state.uioh <- state.uioh#
pmotion x y;
6139 method key key mask
=
6140 begin match state.mode with
6141 | Textentry
textentry -> textentrykeyboard key mask
textentry
6142 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6143 | View
-> viewkeyboard key mask
6144 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6148 method button button bstate
x y mask
=
6149 begin match state.mode with
6151 | View
-> viewmouse button bstate
x y mask
6152 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6158 begin match state.mode with
6160 | View
| Birdseye
_ | LinkNav
_ ->
6161 match state.mstate
with
6162 | Mzoom
_ | Mnone
-> ()
6167 state.mstate
<- Mpan
(x, y);
6169 then state.x <- panbound (state.x + dx);
6171 gotoy_and_clear_text y
6174 state.mstate
<- Msel
(a, (x, y));
6175 G.postRedisplay "motion select";
6178 let y = min
state.winh
(max
0 y) in
6182 let x = min
state.winw (max
0 x) in
6185 | Mzoomrect
(p0
, _) ->
6186 state.mstate
<- Mzoomrect
(p0
, (x, y));
6187 G.postRedisplay "motion zoomrect";
6191 method pmotion x y =
6192 begin match state.mode with
6193 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6194 let rec loop = function
6196 if hooverpageno
!= -1
6198 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6199 G.postRedisplay "pmotion birdseye no hoover";
6202 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6203 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6205 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6206 G.postRedisplay "pmotion birdseye hoover";
6216 match state.mstate
with
6217 | Mnone
-> updateunder x y
6218 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6223 method infochanged
_ = ()
6226 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6229 then 0.0, float state.winh
6230 else scrollph state.y maxy
6235 let winw = wadjsb state.winw in
6236 let fwinw = float winw in
6238 let sw = fwinw /. float state.w in
6239 let sw = fwinw *. sw in
6240 max
sw (float conf.scrollh
)
6243 let maxx = state.w + winw in
6244 let x = winw - state.x in
6245 let percent = float x /. float maxx in
6246 (fwinw -. sw) *. percent
6248 hscrollh (), position, sw
6252 match state.mode with
6253 | LinkNav
_ -> "links"
6254 | Textentry
_ -> "textentry"
6255 | Birdseye
_ -> "birdseye"
6258 findkeyhash conf modename
6260 method eformsgs
= true
6267 let fontpath = ref "";;
6270 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6273 let l = String.length
s in
6274 let b = Buffer.create
l in
6280 try Sys.getenv
"HOME"
6283 ("Can not determine home directory location: " ^ exntos exn
);
6287 let modifier_of_string = function
6288 | "alt" -> Wsi.altmask
6289 | "shift" -> Wsi.shiftmask
6290 | "ctrl" | "control" -> Wsi.ctrlmask
6291 | "meta" -> Wsi.metamask
6296 let r = Str.regexp
"-" in
6298 let elems = Str.full_split
r s in
6301 let m1 = modifier_of_string s in
6303 then (Wsi.namekey
s, m)
6306 | Str.Delim
s when n land 1 = 0 -> g s
6308 | Str.Delim
_ -> (k
, m)
6310 let rec loop n k
m = function
6313 let k, m = f n k m x in
6319 let keys_of_string =
6320 let r = Str.regexp
"[ \t]" in
6322 let elems = Str.split
r s in
6323 List.map
key_of_string elems
6326 let copykeyhashes c =
6327 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6330 let config_of c attrs
=
6334 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6335 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6336 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6337 | "preload" -> { c with preload = bool_of_string
v }
6338 | "page-bias" -> { c with pagebias
= int_of_string
v }
6339 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6340 | "horizontal-scroll-step" ->
6341 { c with hscrollstep
= max
(int_of_string
v) 1 }
6342 | "auto-scroll-step" ->
6343 { c with autoscrollstep
= max
0 (int_of_string
v) }
6344 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6345 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6348 match String.lowercase
v with
6349 | "true" -> Some infinity
6351 | f -> Some
(float_of_string
f)
6353 { c with maxwait
= mw}
6354 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6355 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6356 | "vertical-margin" ->
6357 { c with interpagespace
= max
0 (int_of_string
v) }
6359 let zoom = float_of_string
v /. 100. in
6360 let zoom = max
zoom 0.0 in
6361 { c with zoom = zoom }
6362 | "presentation" -> { c with presentation
= bool_of_string
v }
6363 | "rotation-angle" -> { c with angle
= int_of_string
v }
6364 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6365 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6366 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6367 | "proportional-display" ->
6370 then FitProportional
6373 { c with fitmodel
= fm }
6374 | "fit-model" -> { c with fitmodel
= fitmodel_of_string v }
6375 | "pixmap-cache-size" ->
6376 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6377 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6378 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6379 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6380 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6381 | "background-color" -> { c with bgcolor
= color_of_string v }
6382 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6383 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6384 | "mupdf-store-size" ->
6385 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6386 | "checkers" -> { c with checkers
= bool_of_string
v }
6387 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6388 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6389 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6390 | "uri-launcher" -> { c with urilauncher
= unent v }
6391 | "path-launcher" -> { c with pathlauncher
= unent v }
6392 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6393 | "invert-colors" -> { c with invert
= bool_of_string
v }
6394 | "brightness" -> { c with colorscale
= float_of_string
v }
6395 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6397 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6399 let (n, _, _) as nab
= multicolumns_of_string v in
6401 then { c with columns
= Csplit
(-n, [||]) }
6402 else { c with columns
= Cmulti
(nab
, [||]) }
6403 | "birds-eye-columns" ->
6404 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6405 | "selection-command" -> { c with selcmd
= unent v }
6406 | "synctex-command" -> { c with stcmd
= unent v }
6407 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6408 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6409 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6410 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6411 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6412 | "horizontal-scrollbar-visible" ->
6415 then c.scrollb
lor scrollbhv
6416 else c.scrollb
land (lnot
scrollbhv)
6418 { c with scrollb
= b }
6419 | "vertical-scrollbar-visible" ->
6422 then c.scrollb
lor scrollbvv
6423 else c.scrollb
land (lnot
scrollbvv)
6425 { c with scrollb
= b }
6428 prerr_endline
("Error processing attribute (`" ^
6429 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6432 let rec fold c = function
6435 let c = apply c k v in
6438 fold { c with keyhashes
= copykeyhashes c } attrs
;
6441 let fromstring f pos
n v d =
6444 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6445 n v pos
(exntos exn
)
6450 let bookmark_of attrs
=
6451 let rec fold title page
rely visy
= function
6452 | ("title", v) :: rest
-> fold v page
rely visy rest
6453 | ("page", v) :: rest
-> fold title v rely visy rest
6454 | ("rely", v) :: rest
-> fold title page
v visy rest
6455 | ("visy", v) :: rest
-> fold title page
rely v rest
6456 | _ :: rest
-> fold title page
rely visy rest
6457 | [] -> title, page
, rely, visy
6459 fold "invalid" "0" "0" "0" attrs
6463 let rec fold path page
rely pan visy
= function
6464 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6465 | ("page", v) :: rest
-> fold path v rely pan visy rest
6466 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6467 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6468 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6469 | _ :: rest
-> fold path page
rely pan visy rest
6470 | [] -> path, page
, rely, pan
, visy
6472 fold "" "0" "0" "0" "0" attrs
6476 let rec fold rs ls
= function
6477 | ("out", v) :: rest
-> fold v ls rest
6478 | ("in", v) :: rest
-> fold rs
v rest
6479 | _ :: rest
-> fold ls rs rest
6485 let setconf dst
src =
6486 dst
.scrollbw
<- src.scrollbw
;
6487 dst
.scrollh
<- src.scrollh
;
6488 dst
.icase
<- src.icase
;
6489 dst
.preload <- src.preload;
6490 dst
.pagebias
<- src.pagebias
;
6491 dst
.verbose
<- src.verbose
;
6492 dst
.scrollstep
<- src.scrollstep
;
6493 dst
.maxhfit
<- src.maxhfit
;
6494 dst
.crophack
<- src.crophack
;
6495 dst
.autoscrollstep
<- src.autoscrollstep
;
6496 dst
.maxwait
<- src.maxwait
;
6497 dst
.hlinks
<- src.hlinks
;
6498 dst
.underinfo
<- src.underinfo
;
6499 dst
.interpagespace
<- src.interpagespace
;
6500 dst
.zoom <- src.zoom;
6501 dst
.presentation
<- src.presentation
;
6502 dst
.angle
<- src.angle
;
6503 dst
.cwinw
<- src.cwinw
;
6504 dst
.cwinh
<- src.cwinh
;
6505 dst
.savebmarks
<- src.savebmarks
;
6506 dst
.memlimit
<- src.memlimit
;
6507 dst
.fitmodel
<- src.fitmodel
;
6508 dst
.texcount
<- src.texcount
;
6509 dst
.sliceheight
<- src.sliceheight
;
6510 dst
.thumbw
<- src.thumbw
;
6511 dst
.jumpback
<- src.jumpback
;
6512 dst
.bgcolor
<- src.bgcolor
;
6513 dst
.tilew
<- src.tilew
;
6514 dst
.tileh
<- src.tileh
;
6515 dst
.mustoresize
<- src.mustoresize
;
6516 dst
.checkers
<- src.checkers
;
6517 dst
.aalevel
<- src.aalevel
;
6518 dst
.trimmargins
<- src.trimmargins
;
6519 dst
.trimfuzz
<- src.trimfuzz
;
6520 dst
.urilauncher
<- src.urilauncher
;
6521 dst
.colorspace
<- src.colorspace
;
6522 dst
.invert
<- src.invert
;
6523 dst
.colorscale
<- src.colorscale
;
6524 dst
.redirectstderr <- src.redirectstderr;
6525 dst
.ghyllscroll
<- src.ghyllscroll
;
6526 dst
.columns
<- src.columns
;
6527 dst
.beyecolumns
<- src.beyecolumns
;
6528 dst
.selcmd
<- src.selcmd
;
6529 dst
.updatecurs
<- src.updatecurs
;
6530 dst
.pathlauncher
<- src.pathlauncher
;
6531 dst
.keyhashes
<- copykeyhashes src;
6532 dst
.hfsize
<- src.hfsize
;
6533 dst
.hscrollstep
<- src.hscrollstep
;
6534 dst
.pgscale <- src.pgscale;
6535 dst
.usepbo
<- src.usepbo
;
6536 dst
.wheelbypage
<- src.wheelbypage
;
6537 dst
.stcmd
<- src.stcmd
;
6538 dst
.scrollb
<- src.scrollb
;
6542 let h = Hashtbl.create
10 in
6543 let dc = { defconf with angle
= defconf.angle
} in
6544 let rec toplevel v t spos
_ =
6546 | Vdata
| Vcdata
| Vend
-> v
6547 | Vopen
("llppconfig", _, closed
) ->
6550 else { v with f = llppconfig
}
6552 error
"unexpected subelement at top level" s spos
6553 | Vclose
_ -> error
"unexpected close at top level" s spos
6555 and llppconfig
v t spos
_ =
6557 | Vdata
| Vcdata
-> v
6558 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6559 | Vopen
("defaults", attrs
, closed
) ->
6560 let c = config_of dc attrs
in
6564 else { v with f = defaults
}
6566 | Vopen
("ui-font", attrs
, closed
) ->
6567 let rec getsize size
= function
6569 | ("size", v) :: rest
->
6571 fromstring int_of_string spos
"size" v fstate.fontsize
in
6573 | l -> getsize size l
6575 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6578 else { v with f = uifont
(Buffer.create
10) }
6580 | Vopen
("doc", attrs
, closed
) ->
6581 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6582 let path = unent pathent
6583 and pageno = fromstring int_of_string spos
"page" spage
0
6584 and rely = fromstring float_of_string spos
"rely" srely
0.0
6585 and pan
= fromstring int_of_string spos
"pan" span
0
6586 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6587 let c = config_of dc attrs
in
6588 let anchor = (pageno, rely, visy
) in
6590 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6591 else { v with f = doc
path pan
anchor c [] }
6594 error
"unexpected subelement in llppconfig" s spos
6596 | Vclose
"llppconfig" -> { v with f = toplevel }
6597 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6599 and defaults
v t spos
_ =
6601 | Vdata
| Vcdata
-> v
6602 | Vend
-> error
"unexpected end of input in defaults" s spos
6603 | Vopen
("keymap", attrs
, closed
) ->
6605 try List.assoc
"mode" attrs
6606 with Not_found
-> "global" in
6611 let h = findkeyhash dc modename in
6612 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6615 { v with f = pkeymap
ret KeyMap.empty }
6617 | Vopen
(_, _, _) ->
6618 error
"unexpected subelement in defaults" s spos
6620 | Vclose
"defaults" ->
6621 { v with f = llppconfig
}
6623 | Vclose
_ -> error
"unexpected close in defaults" s spos
6625 and uifont
b v t spos
epos =
6628 Buffer.add_substring
b s spos
(epos - spos
);
6630 | Vopen
(_, _, _) ->
6631 error
"unexpected subelement in ui-font" s spos
6632 | Vclose
"ui-font" ->
6633 if String.length
!fontpath = 0
6634 then fontpath := Buffer.contents
b;
6635 { v with f = llppconfig
}
6636 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6637 | Vend
-> error
"unexpected end of input in ui-font" s spos
6639 and doc
path pan
anchor c bookmarks
v t spos
_ =
6641 | Vdata
| Vcdata
-> v
6642 | Vend
-> error
"unexpected end of input in doc" s spos
6643 | Vopen
("bookmarks", _, closed
) ->
6646 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6648 | Vopen
("keymap", attrs
, closed
) ->
6650 try List.assoc
"mode" attrs
6651 with Not_found
-> "global"
6657 let h = findkeyhash c modename in
6658 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6659 doc
path pan
anchor c bookmarks
6661 { v with f = pkeymap
ret KeyMap.empty }
6663 | Vopen
(_, _, _) ->
6664 error
"unexpected subelement in doc" s spos
6667 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6668 { v with f = llppconfig
}
6670 | Vclose
_ -> error
"unexpected close in doc" s spos
6672 and pkeymap
ret keymap
v t spos
_ =
6674 | Vdata
| Vcdata
-> v
6675 | Vend
-> error
"unexpected end of input in keymap" s spos
6676 | Vopen
("map", attrs
, closed
) ->
6677 let r, l = map_of attrs
in
6678 let kss = fromstring keys_of_string spos
"in" r [] in
6679 let lss = fromstring keys_of_string spos
"out" l [] in
6683 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6684 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6687 then { v with f = pkeymap
ret keymap }
6690 { v with f = skip
"map" f }
6693 error
"unexpected subelement in keymap" s spos
6695 | Vclose
"keymap" ->
6696 { v with f = ret keymap }
6698 | Vclose
_ -> error
"unexpected close in keymap" s spos
6700 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6702 | Vdata
| Vcdata
-> v
6703 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6704 | Vopen
("item", attrs
, closed
) ->
6705 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6706 let page = fromstring int_of_string spos
"page" spage
0
6707 and rely = fromstring float_of_string spos
"rely" srely
0.0
6708 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6710 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6713 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6716 { v with f = skip
"item" f }
6719 error
"unexpected subelement in bookmarks" s spos
6721 | Vclose
"bookmarks" ->
6722 { v with f = doc
path pan
anchor c bookmarks }
6724 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6726 and skip tag
f v t spos
_ =
6728 | Vdata
| Vcdata
-> v
6730 error
("unexpected end of input in skipped " ^ tag
) s spos
6731 | Vopen
(tag'
, _, closed
) ->
6735 let f'
() = { v with f = skip tag
f } in
6736 { v with f = skip tag'
f'
}
6740 else error
("unexpected close in skipped " ^ tag
) s spos
6743 parse
{ f = toplevel; accu = () } s;
6749 let len = in_channel_length ic
in
6750 let s = String.create
len in
6751 really_input ic
s 0 len;
6754 | Parse_error
(msg
, s, pos
) ->
6755 let subs = subs s pos
in
6756 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6757 failwith
("parse error: " ^
s)
6760 failwith
("config load error: " ^ exntos exn
)
6766 let dir = Filename.concat
home ".config" in
6767 if Sys.is_directory
dir then dir else home
6770 Filename.concat
dir "llpp.conf"
6773 let confpath = ref defconfpath;;
6776 if Sys.file_exists
!confpath
6779 (try Some
(open_in_bin
!confpath)
6782 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6793 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6802 f (Hashtbl.create
0, defconf)
6807 let pc, pb
, px, pa
=
6810 if String.length
state.origin
= 0
6814 Hashtbl.find h (Filename.basename
key)
6815 with Not_found
-> dc, [], 0, emptyanchor
6819 state.bookmarks <- pb
;
6822 then state.anchor <- pa
;
6823 cbput state.hists
.nav pa
;
6829 let add_attrs bb always
dc c =
6832 then Printf.bprintf bb
"\n %s='%b'" s a
6835 then Printf.bprintf bb
"\n %s='%d'" s a
6838 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6841 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6844 then Printf.bprintf bb
"\n %s='%f'" s a
6848 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6852 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6856 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6860 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6866 | Some
(_N
, _A
, _B
) ->
6867 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6877 else string_of_float
f
6879 Printf.bprintf bb
"\n %s='%s'" s v
6884 | Cmulti
((n, a, b), _) when n > 1 ->
6885 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6886 | Csplit
(n, _) when n > 1 ->
6887 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6893 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6898 Printf.bprintf bb
"\n %s='%s'" s (fitmodel_to_string a)
6902 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
6904 oi
"width" c.cwinw
dc.cwinw
;
6905 oi
"height" c.cwinh
dc.cwinh
;
6906 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6907 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6908 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
6909 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
6910 ob "case-insensitive-search" c.icase
dc.icase
;
6911 ob "preload" c.preload dc.preload;
6912 oi
"page-bias" c.pagebias
dc.pagebias
;
6913 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6914 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6915 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6916 ob "crop-hack" c.crophack
dc.crophack
;
6917 oW
"throttle" c.maxwait
dc.maxwait
;
6918 ob "highlight-links" c.hlinks
dc.hlinks
;
6919 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6920 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6921 oz
"zoom" c.zoom dc.zoom;
6922 ob "presentation" c.presentation
dc.presentation
;
6923 oi
"rotation-angle" c.angle
dc.angle
;
6924 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6925 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
6926 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6927 oi
"tex-count" c.texcount
dc.texcount
;
6928 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6929 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6930 ob "persistent-location" c.jumpback
dc.jumpback
;
6931 oc
"background-color" c.bgcolor
dc.bgcolor
;
6932 oi
"tile-width" c.tilew
dc.tilew
;
6933 oi
"tile-height" c.tileh
dc.tileh
;
6934 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6935 ob "checkers" c.checkers
dc.checkers
;
6936 oi
"aalevel" c.aalevel
dc.aalevel
;
6937 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6938 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6939 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6940 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6941 oC
"color-space" c.colorspace
dc.colorspace
;
6942 ob "invert-colors" c.invert
dc.invert
;
6943 oF
"brightness" c.colorscale
dc.colorscale
;
6944 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6945 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6946 oco
"columns" c.columns
dc.columns
;
6947 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6948 os
"selection-command" c.selcmd
dc.selcmd
;
6949 os
"synctex-command" c.stcmd
dc.stcmd
;
6950 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6951 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6952 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6953 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6954 ob "use-pbo" c.usepbo
dc.usepbo
;
6955 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6958 let keymapsbuf always
dc c =
6959 let bb = Buffer.create
16 in
6960 let rec loop = function
6962 | (modename, h) :: rest
->
6963 let dh = findkeyhash dc modename in
6964 if always
|| h <> dh
6966 if Hashtbl.length
h > 0
6968 if Buffer.length
bb > 0
6969 then Buffer.add_char
bb '
\n'
;
6970 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6971 Hashtbl.iter
(fun i
o ->
6972 let isdifferent = always
||
6974 let dO = Hashtbl.find dh i
in
6976 with Not_found
-> true
6981 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6982 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6983 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6984 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6985 Buffer.add_string
bb (Wsi.keyname
k);
6988 let rec loop = function
6990 | km
:: [] -> addkm km
6991 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6995 Buffer.add_string
bb "<map in='";
6999 Buffer.add_string
bb "' out='";
7001 Buffer.add_string
bb "'/>\n"
7004 Buffer.add_string
bb "' out='";
7006 Buffer.add_string
bb "'/>\n"
7008 | KMmulti
(ins, kms
) ->
7009 Buffer.add_char
bb ' '
;
7011 Buffer.add_string
bb "' out='";
7013 Buffer.add_string
bb "'/>\n"
7015 Buffer.add_string
bb "</keymap>";
7025 let uifontsize = fstate.fontsize
in
7026 let bb = Buffer.create
32768 in
7027 let relx = float state.x /. float state.winw in
7029 let cx w = truncate
(relx *. float w) in
7031 (fun (w, h, x) ws
->
7033 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7034 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7035 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7037 (state.winw, state.winh
, state.x) state.winstate
7042 let dc = if conf.bedefault
then conf else dc in
7043 Buffer.add_string
bb "<llppconfig>\n";
7045 if String.length
!fontpath > 0
7047 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7053 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7056 Buffer.add_string
bb "<defaults ";
7057 add_attrs bb true dc dc;
7058 let kb = keymapsbuf true dc dc in
7059 if Buffer.length
kb > 0
7061 Buffer.add_string
bb ">\n";
7062 Buffer.add_buffer
bb kb;
7063 Buffer.add_string
bb "\n</defaults>\n";
7065 else Buffer.add_string
bb "/>\n";
7067 let adddoc path pan
anchor c bookmarks =
7068 if bookmarks == [] && c = dc && anchor = emptyanchor
7071 Printf.bprintf
bb "<doc path='%s'"
7072 (enent
path 0 (String.length
path));
7074 if anchor <> emptyanchor
7076 let n, rely, visy
= anchor in
7077 Printf.bprintf
bb " page='%d'" n;
7080 Printf.bprintf
bb " rely='%f'" rely
7082 if abs_float visy
> 1e-6
7084 Printf.bprintf
bb " visy='%f'" visy
7089 then Printf.bprintf
bb " pan='%d'" pan
;
7091 add_attrs bb false dc c;
7092 let kb = keymapsbuf false dc c in
7094 begin match bookmarks with
7096 if Buffer.length
kb > 0
7098 Buffer.add_string
bb ">\n";
7099 Buffer.add_buffer
bb kb;
7100 Buffer.add_string
bb "\n</doc>\n";
7102 else Buffer.add_string
bb "/>\n"
7104 Buffer.add_string
bb ">\n<bookmarks>\n";
7105 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7107 "<item title='%s' page='%d'"
7108 (enent
title 0 (String.length
title))
7113 Printf.bprintf
bb " rely='%f'" rely
7115 if abs_float visy
> 1e-6
7117 Printf.bprintf
bb " visy='%f'" visy
7119 Buffer.add_string
bb "/>\n";
7121 Buffer.add_string
bb "</bookmarks>";
7122 if Buffer.length
kb > 0
7124 Buffer.add_string
bb "\n";
7125 Buffer.add_buffer
bb kb;
7127 Buffer.add_string
bb "\n</doc>\n";
7133 match state.mode with
7134 | Birdseye
(c, pan, _, _, _) ->
7136 match conf.columns
with
7137 | Cmulti
((c, _, _), _) -> Some
c
7141 match c.columns
with
7142 | Cmulti
(c, _) -> Cmulti
(c, [||])
7143 | Csingle
_ -> Csingle
[||]
7144 | Csplit
_ -> failwith
"quit from bird's eye while split"
7146 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7149 let basename = Filename.basename
7150 (if String.length
state.origin
= 0 then state.path else state.origin
)
7152 adddoc basename pan (getanchor ())
7154 let autoscrollstep =
7155 match state.autoscroll
with
7157 | None
-> conf.autoscrollstep
7159 match state.mode with
7160 | Birdseye
(bc
, _, _, _, _) ->
7163 presentation
= bc
.presentation
;
7164 interpagespace
= bc
.interpagespace
;
7165 maxwait
= bc
.maxwait
;
7166 autoscrollstep = autoscrollstep }
7167 | _ -> { conf with autoscrollstep = autoscrollstep }
7169 (if conf.savebmarks
then state.bookmarks else []);
7171 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7173 then adddoc path x anchor c bookmarks
7175 Buffer.add_string
bb "</llppconfig>\n";
7178 if load1 f && Buffer.length
bb > 0
7181 let tmp = !confpath ^
".tmp" in
7182 let oc = open_out_bin
tmp in
7183 Buffer.output_buffer
oc bb;
7185 Unix.rename
tmp !confpath;
7188 ("error while saving configuration: " ^ exntos exn
)
7192 let adderrmsg src msg
=
7193 Buffer.add_string
state.errmsgs msg
;
7194 state.newerrmsgs
<- true;
7198 let adderrfmt src fmt
=
7199 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7203 let cl = splitatspace cmds
in
7205 try Scanf.sscanf
s fmt
f
7207 adderrfmt "remote exec"
7208 "error processing '%S': %s\n" cmds
(exntos exn
)
7211 | "reload" :: [] -> reload ()
7212 | "goto" :: args :: [] ->
7213 scan args "%u %f %f"
7215 let cmd, _ = state.geomcmds
in
7216 if String.length
cmd = 0
7217 then gotopagexy pageno x y
7220 gotopagexy pageno x y;
7223 state.reprf
<- f state.reprf
7225 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7226 | "rect" :: args :: [] ->
7227 scan args "%u %u %f %f %f %f"
7228 (fun pageno color x0 y0 x1 y1 ->
7229 onpagerect pageno (fun w h ->
7230 let _,w1,h1
,_ = getpagedim pageno in
7231 let sw = float w1 /. w
7232 and sh = float h1
/. h in
7236 and y1s
= y1 *. sh in
7237 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7239 state.rects <- (pageno, color, rect) :: state.rects;
7240 G.postRedisplay "rect";
7243 | "activatewin" :: [] -> Wsi.activatewin
()
7244 | "quit" :: [] -> raise Quit
7246 adderrfmt "remote command"
7247 "error processing remote command: %S\n" cmds
;
7251 let scratch = String.create
80 in
7252 let buf = Buffer.create
80 in
7255 try Some
(Unix.read fd
scratch 0 80)
7257 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7258 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7261 match tempfr () with
7267 if Buffer.length
buf > 0
7269 let s = Buffer.contents
buf in
7279 let pos = String.index_from
scratch ppos '
\n'
in
7280 if pos >= n then -1 else pos
7281 with Not_found
-> -1
7285 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7286 let s = Buffer.contents
buf in
7292 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7298 let remoteopen path =
7299 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7301 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7306 let trimcachepath = ref "" in
7307 let rcmdpath = ref "" in
7310 [("-p", Arg.String
(fun s -> state.password
<- s),
7311 "<password> Set password");
7313 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7314 "<path> Set path to the user interface font");
7316 ("-c", Arg.String
(fun s -> Config.confpath := s),
7317 "<path> Set path to the configuration file");
7319 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7320 "<path> Set path to the trim cache file");
7322 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7323 "<named-destination> Set named destination");
7325 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7327 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7328 "<path> Set path to the remote commands source");
7330 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7331 "<original-path> Set original path");
7333 ("-v", Arg.Unit
(fun () ->
7335 "%s\nconfiguration path: %s\n"
7339 exit
0), " Print version and exit");
7342 (fun s -> state.path <- s)
7343 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7345 if String.length
state.path = 0
7346 then (prerr_endline
"file name missing"; exit
1);
7348 if not
(Config.load ())
7349 then prerr_endline
"failed to load configuration";
7351 let wsfd, winw, winh
= Wsi.init
(object (self)
7352 val mutable m_hack
= false
7355 then G.postRedisplay "expose"
7356 method visible
= self#expose
7357 method display = m_hack
<- false; display ()
7358 method reshape w h = m_hack
<- true; reshape w h
7359 method mouse b d x y m = mouse b d x y m
7360 method motion x y = state.mpos
<- (x, y); motion x y
7361 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7363 let mascm = m land (
7364 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7366 match state.keystate
with
7368 let km = k, mascm in
7371 let modehash = state.uioh#
modehash in
7372 try Hashtbl.find modehash km
7374 try Hashtbl.find (findkeyhash conf "global") km
7375 with Not_found
-> KMinsrt
(k, m)
7377 | KMinsrt
(k, m) -> keyboard k m
7378 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7379 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7381 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7382 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7383 state.keystate
<- KSnone
7384 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7385 state.keystate
<- KSinto
(keys
, insrt
)
7387 state.keystate
<- KSnone
7389 method enter
x y = state.mpos
<- (x, y); pmotion x y
7390 method leave = state.mpos
<- (-1, -1)
7391 method winstate wsl
= state.winstate
<- wsl
7392 method quit
= raise Quit
7393 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7398 List.exists
GlMisc.check_extension
7399 [ "GL_ARB_texture_rectangle"
7400 ; "GL_EXT_texture_recangle"
7401 ; "GL_NV_texture_rectangle" ]
7403 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7406 let r = GlMisc.get_string `renderer
in
7407 let p = "Mesa DRI Intel(" in
7408 let l = String.length
p in
7409 String.length
r > l && String.sub
r 0 l = p
7411 then defconf.sliceheight
<- 1024;
7414 match Ne.pipe () with
7416 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7420 match Ne.pipe () with
7422 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7432 setcheckers conf.checkers
;
7436 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7437 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7438 !Config.fontpath, !trimcachepath,
7439 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7443 state.text <- "Opening " ^
(mbtoutf8
state.path);
7445 opendoc state.path state.password
;
7449 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7452 if String.length
!rcmdpath > 0
7453 then remoteopen !rcmdpath
7458 let rec loop deadline
=
7460 match state.errfd
with
7461 | None
-> [state.sr
; state.wsfd]
7462 | Some fd
-> [state.sr
; state.wsfd; fd
]
7467 | Some fd
-> fd
:: r
7471 state.redisplay
<- false;
7478 if deadline
= infinity
7480 else max
0.0 (deadline
-. now)
7485 try Unix.select
r [] [] timeout
7486 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7492 if state.ghyll
== noghyll
7494 match state.autoscroll
with
7495 | Some step
when step
!= 0 ->
7496 let y = state.y + step
in
7500 else if y >= state.maxy then 0 else y
7503 if state.mode = View
7504 then state.text <- "";
7507 else deadline
+. 0.01
7512 let rec checkfds = function
7514 | fd
:: rest
when fd
= state.sr
->
7515 let cmd = readcmd state.sr
in
7519 | fd
:: rest
when fd
= state.wsfd ->
7523 | fd
:: rest
when Some fd
= !optrfd ->
7524 begin match remote fd
with
7525 | None
-> optrfd := remoteopen !rcmdpath;
7526 | opt -> optrfd := opt
7531 let s = String.create
80 in
7532 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7533 if conf.redirectstderr
7535 Buffer.add_substring
state.errmsgs
s 0 n;
7536 state.newerrmsgs
<- true;
7537 state.redisplay
<- true;
7540 prerr_string
(String.sub
s 0 n);
7548 if deadline
= infinity
7552 match state.autoscroll
with
7553 | Some step
when step
!= 0 -> deadline1
7554 | _ -> if state.ghyll
== noghyll then infinity
else deadline1