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;;
294 { mutable scrollbw
: int
295 ; mutable scrollh
: int
296 ; mutable icase
: bool
297 ; mutable preload
: bool
298 ; mutable pagebias
: int
299 ; mutable verbose
: bool
300 ; mutable debug
: bool
301 ; mutable scrollstep
: int
302 ; mutable hscrollstep
: int
303 ; mutable maxhfit
: bool
304 ; mutable crophack
: bool
305 ; mutable autoscrollstep
: int
306 ; mutable maxwait
: float option
307 ; mutable hlinks
: bool
308 ; mutable underinfo
: bool
309 ; mutable interpagespace
: interpagespace
310 ; mutable zoom
: float
311 ; mutable presentation
: bool
312 ; mutable angle
: angle
313 ; mutable cwinw
: int
314 ; mutable cwinh
: int
316 ; mutable savebmarks
: bool
317 ; mutable fitmodel
: fitmodel
318 ; mutable trimmargins
: trimmargins
319 ; mutable trimfuzz
: irect
320 ; mutable memlimit
: memsize
321 ; mutable texcount
: texcount
322 ; mutable sliceheight
: sliceheight
323 ; mutable thumbw
: width
324 ; mutable jumpback
: bool
325 ; mutable bgcolor
: (float * float * float)
326 ; mutable bedefault
: bool
327 ; mutable scrollbarinpm
: bool
328 ; mutable tilew
: int
329 ; mutable tileh
: int
330 ; mutable mustoresize
: memsize
331 ; mutable checkers
: bool
332 ; mutable aalevel
: int
333 ; mutable urilauncher
: string
334 ; mutable pathlauncher
: string
335 ; mutable colorspace
: colorspace
336 ; mutable invert
: bool
337 ; mutable colorscale
: float
338 ; mutable redirectstderr
: bool
339 ; mutable ghyllscroll
: (int * int * int) option
340 ; mutable columns
: columns
341 ; mutable beyecolumns
: columncount
option
342 ; mutable selcmd
: string
343 ; mutable updatecurs
: bool
344 ; mutable keyhashes
: (string * keyhash
) list
345 ; mutable hfsize
: int
346 ; mutable pgscale
: float
347 ; mutable usepbo
: bool
348 ; mutable wheelbypage
: bool
349 ; mutable stcmd
: string
352 | Csingle
of singlecolumn
353 | Cmulti
of multicolumns
354 | Csplit
of splitcolumns
357 type anchor
= pageno
* top
* dtop
;;
359 type outline
= string * int * anchor
;;
361 type rect
= float * float * float * float * float * float * float * float;;
363 type tile
= opaque
* pixmapsize
* elapsed
364 and elapsed
= float;;
365 type pagemapkey
= pageno
* gen
;;
366 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
370 let emptyanchor = (0, 0.0, 0.0);;
372 type infochange
= | Memused
| Docinfo
| Pdim
;;
374 class type uioh
= object
375 method display
: unit
376 method key
: int -> int -> uioh
377 method button
: int -> bool -> int -> int -> int -> uioh
378 method motion
: int -> int -> uioh
379 method pmotion
: int -> int -> uioh
380 method infochanged
: infochange
-> unit
381 method scrollpw
: (int * float * float)
382 method scrollph
: (int * float * float)
383 method modehash
: keyhash
384 method eformsgs
: bool
388 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
389 | Textentry
of (textentry
* onleave
)
391 | LinkNav
of linktarget
392 and onleave
= leavetextentrystatus
-> unit
393 and leavetextentrystatus
= | Cancel
| Confirm
394 and helpitem
= string * int * action
397 | Action
of (uioh
-> uioh
)
399 | Ltexact
of (pageno
* int)
403 let isbirdseye = function Birdseye _
-> true | _
-> false;;
404 let istextentry = function Textentry _
-> true | _
-> false;;
408 | Loading
of (page
* gen
)
410 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
412 | Outlining
of outline list
415 let emptykeyhash = Hashtbl.create
0;;
416 let nouioh : uioh
= object (self
)
418 method key _ _
= self
419 method button _ _ _ _ _
= self
420 method motion _ _
= self
421 method pmotion _ _
= self
422 method infochanged _
= ()
423 method scrollpw
= (0, nan
, nan
)
424 method scrollph
= (0, nan
, nan
)
425 method modehash
= emptykeyhash
426 method eformsgs
= false
430 { mutable sr
: Unix.file_descr
431 ; mutable sw
: Unix.file_descr
432 ; mutable wsfd
: Unix.file_descr
433 ; mutable errfd
: Unix.file_descr
option
434 ; mutable stderr
: Unix.file_descr
435 ; mutable errmsgs
: Buffer.t
436 ; mutable newerrmsgs
: bool
440 ; mutable scrollw
: int
441 ; mutable hscrollh
: int
442 ; mutable anchor
: anchor
443 ; mutable ranchors
: (string * string * anchor
* string) list
445 ; mutable layout
: page list
446 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
447 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
448 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
449 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
450 ; mutable pagecount
: int
451 ; mutable currently
: currently
452 ; mutable mstate
: mstate
453 ; mutable searchpattern
: string
454 ; mutable rects
: (pageno
* recttype
* rect
) list
455 ; mutable rects1
: (pageno
* recttype
* rect
) list
456 ; mutable text
: string
457 ; mutable winstate
: Wsi.winstate list
458 ; mutable mode
: mode
459 ; mutable uioh
: uioh
460 ; mutable outlines
: outline array
461 ; mutable bookmarks
: outline list
462 ; mutable path
: string
463 ; mutable password
: string
464 ; mutable nameddest
: string
465 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
466 ; mutable memused
: memsize
468 ; mutable throttle
: (page list
* int * float) option
469 ; mutable autoscroll
: int option
470 ; mutable ghyll
: (int option -> unit)
471 ; mutable help
: helpitem array
472 ; mutable docinfo
: (int * string) list
473 ; mutable texid
: GlTex.texture_id
option
475 ; mutable prevzoom
: float
476 ; mutable progress
: float
477 ; mutable redisplay
: bool
478 ; mutable mpos
: mpos
479 ; mutable keystate
: keystate
480 ; mutable glinks
: bool
481 ; mutable prevcolumns
: (columns
* float) option
484 ; mutable reprf
: (unit -> unit)
485 ; mutable origin
: string
488 { pat
: string circbuf
489 ; pag
: string circbuf
490 ; nav
: anchor circbuf
491 ; sel
: string circbuf
513 ; presentation
= false
519 ; fitmodel
= FitProportional
520 ; trimmargins
= false
521 ; trimfuzz
= (0,0,0,0)
522 ; memlimit
= 32 lsl 20
527 ; bgcolor
= (0.5, 0.5, 0.5)
529 ; scrollbarinpm
= true
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
681 ; anchor
= emptyanchor
685 ; tilelru
= Queue.create
()
686 ; pagemap
= Hashtbl.create
10
687 ; tilemap
= Hashtbl.create
10
703 ; geomcmds
= firstgeomcmds
705 { nav
= cbnew 10 emptyanchor
734 fstate.fontsize
<- n
;
735 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
736 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
742 Printf.kprintf prerr_endline fmt
744 Printf.kprintf ignore fmt
748 if String.length
conf.pathlauncher
= 0
749 then print_endline
state.path
751 let re = Str.regexp
"%s" in
752 let command = Str.global_replace
re state.path
conf.pathlauncher
in
755 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
761 type 'a t
= | Res
of 'a
| Exn
of exn
;;
764 try Res
(Unix.pipe ())
769 try tempfailureretry
Unix.close fd
770 with exn
-> f
(exntos exn
)
774 try Res
(tempfailureretry
Unix.dup fd
)
779 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
784 let redirectstderr () =
785 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
786 if conf.redirectstderr
788 match Ne.pipe () with
790 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
793 begin match Ne.dup Unix.stderr
with
795 dolog
"failed to dup stderr: %s" (exntos exn
);
796 Ne.clo r
(clofail "pipe/r");
797 Ne.clo w
(clofail "pipe/w");
799 | Ne.Res dupstderr
->
800 begin match Ne.dup2 w
Unix.stderr
with
802 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
803 Ne.clo dupstderr
(clofail "stderr duplicate");
804 Ne.clo r
(clofail "redir pipe/r");
805 Ne.clo w
(clofail "redir pipe/w");
808 state.stderr
<- dupstderr
;
809 state.errfd
<- Some r
;
813 state.newerrmsgs
<- false;
814 begin match state.errfd
with
816 begin match Ne.dup2 state.stderr
Unix.stderr
with
818 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
820 Ne.clo fd
(clofail "dup of stderr");
825 prerr_string
(Buffer.contents
state.errmsgs
);
827 Buffer.clear
state.errmsgs
;
833 let postRedisplay who
=
835 then prerr_endline
("redisplay for " ^ who
);
836 state.redisplay
<- true;
840 let getopaque pageno
=
841 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
842 with Not_found
-> None
845 let putopaque pageno opaque
=
846 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
849 let pagetranslatepoint l x y
=
850 let dy = y
- l
.pagedispy
in
851 let y = dy + l
.pagey
in
852 let dx = x
- l
.pagedispx
in
853 let x = dx + l
.pagex
in
857 let onppundermouse g
x y d
=
860 begin match getopaque l
.pageno
with
862 let x0 = l
.pagedispx
in
863 let x1 = x0 + l
.pagevw
in
864 let y0 = l
.pagedispy
in
865 let y1 = y0 + l
.pagevh
in
866 if y >= y0 && y <= y1 && x >= x0 && x <= x1
868 let px, py
= pagetranslatepoint l
x y in
869 match g opaque l
px py
with
882 let g opaque _
px py
=
883 match whatsunder opaque
px py
with
885 | under
-> Some under
887 onppundermouse g x y Unone
892 match unproject opaque
x y with
893 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
896 onppundermouse g x y None
;
900 state.text
<- Printf.sprintf
"%c%s" c s
;
901 G.postRedisplay "showtext";
905 match Ne.pipe () with
907 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
910 try popen conf.selcmd
[r
, 0; w
, -1]; true
913 (Printf.sprintf
"failed to execute %s: %s"
914 conf.selcmd
(exntos exn
));
918 Ne.clo fd
(fun msg
->
919 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
925 let l = String.length s
in
926 let n = tempfailureretry
(Unix.write w s
0) l in
931 "failed to write %d characters to sel pipe, wrote %d"
936 (Printf.sprintf
"failed to write to sel pipe: %s"
945 let undertext = function
948 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
949 | Utext s
-> "font: " ^ s
950 | Uunexpected s
-> "unexpected: " ^ s
951 | Ulaunch s
-> "launch: " ^ s
952 | Unamed s
-> "named: " ^ s
953 | Uremote
(filename
, pageno
) ->
954 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
957 let updateunder x y =
958 match getunder x y with
959 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
961 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
962 Wsi.setcursor
Wsi.CURSOR_INFO
963 | Ulinkgoto
(pageno
, _
) ->
965 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
966 Wsi.setcursor
Wsi.CURSOR_INFO
968 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
969 Wsi.setcursor
Wsi.CURSOR_TEXT
971 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
972 Wsi.setcursor
Wsi.CURSOR_INHERIT
974 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
975 Wsi.setcursor
Wsi.CURSOR_INHERIT
977 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
978 Wsi.setcursor
Wsi.CURSOR_INHERIT
979 | Uremote
(filename
, pageno
) ->
980 if conf.underinfo
then showtext 'r'
981 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
982 Wsi.setcursor
Wsi.CURSOR_INFO
985 let showlinktype under
=
991 let s = undertext under
in
996 let b = Buffer.create
(String.length
s + 1) in
997 Buffer.add_string
b s;
1002 let colorspace_of_string s =
1003 match String.lowercase
s with
1007 | _
-> failwith
"invalid colorspace"
1010 let int_of_colorspace = function
1016 let colorspace_of_int = function
1020 | n -> failwith
("invalid colorspace index " ^ string_of_int
n)
1023 let colorspace_to_string = function
1029 let fitmodel_of_string s =
1030 match String.lowercase
s with
1031 | "width" -> FitWidth
1032 | "proportional" -> FitProportional
1034 | _
-> failwith
"invalid fit model"
1037 let int_of_fitmodel = function
1039 | FitProportional
-> 1
1043 let fitmodel_of_int = function
1045 | 1 -> FitProportional
1047 | n -> failwith
("invalid fit model index " ^ string_of_int
n)
1050 let fitmodel_to_string = function
1051 | FitWidth
-> "width"
1052 | FitProportional
-> "proportional"
1056 let intentry_with_suffix text key
=
1058 if key
>= 32 && key
< 127
1062 match Char.lowercase
c with
1064 let text = addchar text c in
1067 | 'k'
| 'm'
| '
g'
->
1068 let text = addchar text c in
1072 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1076 let multicolumns_to_string (n, a
, b) =
1078 then Printf.sprintf
"%d" n
1079 else Printf.sprintf
"%d,%d,%d" n a
b;
1082 let multicolumns_of_string s =
1084 (int_of_string
s, 0, 0)
1086 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1088 then failwith
"subtly broken"; (n, a
, b)
1094 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1095 if n != 4 then failwith
"incomplete read(len)";
1097 lor (Char.code
s.[0] lsl 24)
1098 lor (Char.code
s.[1] lsl 16)
1099 lor (Char.code
s.[2] lsl 8)
1100 lor (Char.code
s.[3] lsl 0)
1102 let s = String.create
len in
1103 let n = tempfailureretry
(Unix.read fd
s 0) len in
1104 if n != len then failwith
"incomplete read(data)";
1108 let btod b = if b then 1 else 0;;
1111 let b = Buffer.create
16 in
1112 Buffer.add_string
b "llll";
1115 let s = Buffer.contents
b in
1116 let n = String.length
s in
1118 (* dolog "wcmd %S" (String.sub s 4 len); *)
1119 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1120 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1121 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1122 s.[3] <- Char.chr
(len land 0xff);
1123 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1124 if n'
!= n then failwith
"write failed";
1129 let d = state.winh
- h
in
1130 max
conf.interpagespace
((d + 1) / 2)
1133 let rowyh (c, coverA
, coverB
) b n =
1134 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1136 let _, _, vy
, (_, _, h
, _) = b.(n) in
1139 let n'
= n - coverA
in
1142 let e = min
state.pagecount
(s + c) in
1143 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1144 let _, _, y, (_, _, h
, _) = b.(m
) in
1145 let miny = min
miny y in
1146 let maxh = max
maxh h
in
1147 find (m
+1) miny maxh
1152 match conf.columns
with
1153 | Cmulti
((_, _, _) as cl
, b) ->
1154 if Array.length
b > 0
1156 let y, h
= rowyh cl
b (Array.length
b - 1) in
1157 y + h
+ (if conf.presentation
then calcips h
else 0)
1160 if Array.length
b > 0
1162 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1163 y + h
+ (if conf.presentation
then calcips h
else 0)
1166 if Array.length
b > 0
1168 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1173 let getpageyh pageno
=
1174 let pageno = bound pageno 0 (state.pagecount
-1) in
1175 match conf.columns
with
1177 if Array.length
b = 0
1180 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1182 if conf.presentation
1188 if Array.length
b = 0
1191 let y, h
= rowyh cl
b pageno in
1193 if conf.presentation
1199 if Array.length
b = 0
1203 let (_, _, y, (_, _, h
, _)) = b.(n) in
1207 let getpagedim pageno =
1210 | (n, _, _, _) as pdim
:: rest
->
1212 then (if n = pageno then pdim
else ppdim
)
1217 f (-1, -1, -1, -1) state.pdims
1220 let getpagey pageno = fst
(getpageyh pageno);;
1222 let nogeomcmds cmds
=
1224 | s, [] -> String.length
s = 0
1229 let ((c, coverA
, coverB
) as cl
), b =
1230 match conf.columns
with
1231 | Csingle
b -> (1, 0, 0), b
1232 | Cmulti
(c, b) -> c, b
1233 | Csplit
(_, b) -> (1, 0, 0), b
1235 if Array.length
b = 0
1238 let rec bsearch nmin nmax
=
1240 then bound nmin
0 (state.pagecount
-1)
1242 let n = (nmax
+ nmin
) / 2 in
1243 let vy, h
= rowyh cl
b n in
1245 if conf.presentation
1247 let ips = calcips h
in
1248 let y0 = vy - ips in
1249 let y1 = vy + h
+ ips in
1253 then 0, vy + h
+ conf.interpagespace
1255 let y0 = vy - conf.interpagespace
in
1256 y0, y0 + h
+ conf.interpagespace
1259 if y >= y0 && y < y1
1266 if n < state.pagecount
- coverB
1267 then ((n-coverA
)/c)*c + coverA
1274 then bsearch (n+1) nmax
1275 else bsearch nmin
(n-1)
1278 let r = bsearch 0 (state.pagecount
-1) in
1282 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1283 let sh = sh - state.hscrollh
in
1284 let rec fold accu
n =
1285 if n = Array.length
b
1288 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1291 || n = state.pagecount
- coverB
1292 || (n - coverA
) mod columns
= columns
- 1)
1298 let pagey = max
0 (y - vy) in
1299 let pagedispy = if pagey > 0 then 0 else vy - y in
1300 let pagedispx, pagex
=
1302 if n = coverA
- 1 || n = state.pagecount
- coverB
1303 then state.x + (state.winw
- state.scrollw
- w
) / 2
1304 else dx + xoff
+ state.x
1311 let vw = state.winw
- state.scrollw
- pagedispx in
1312 let pw = w
- pagex
in
1315 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1316 if pagevw > 0 && pagevh > 0
1320 ; pagedimno
= pdimno
1327 ; pagedispx = pagedispx
1328 ; pagedispy = pagedispy
1340 List.rev
(fold [] (page_of_y y));
1343 let layoutS (columns
, b) y sh =
1344 let sh = sh - state.hscrollh
in
1345 let rec fold accu n =
1346 if n = Array.length
b
1349 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1356 let x = xoff
+ state.x in
1357 let pagey = max
0 (y - vy) in
1358 let pagedispy = if pagey > 0 then 0 else vy - y in
1359 let pagedispx, pagex
=
1373 let pagecolw = pagew
/columns
in
1375 if pagecolw < state.winw
1376 then pagedispx + ((state.winw
- state.scrollw
- pagecolw) / 2)
1380 let vw = state.winw
- pagedispx - state.scrollw
in
1381 let pw = pagew
- pagex
in
1384 let pagevw = min
pagevw pagecolw in
1385 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1386 if pagevw > 0 && pagevh > 0
1389 { pageno = n/columns
1390 ; pagedimno
= pdimno
1397 ; pagedispx = pagedispx
1398 ; pagedispy = pagedispy
1399 ; pagecol
= n mod columns
1410 List.rev
(fold [] 0)
1414 if nogeomcmds state.geomcmds
1416 match conf.columns
with
1417 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1418 | Cmulti
c -> layoutN c y sh
1419 | Csplit
s -> layoutS s y sh
1424 let y = state.y + incr
in
1426 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1431 let tilex = l.pagex
mod conf.tilew
in
1432 let tiley = l.pagey mod conf.tileh
in
1434 let col = l.pagex
/ conf.tilew
in
1435 let row = l.pagey / conf.tileh
in
1437 let rec rowloop row y0 dispy h
=
1441 let dh = conf.tileh
- y0 in
1442 let dh = min h
dh in
1443 let rec colloop col x0 dispx w
=
1447 let dw = conf.tilew
- x0 in
1448 let dw = min w
dw in
1450 f col row dispx dispy
x0 y0 dw dh;
1451 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1454 colloop col tilex l.pagedispx l.pagevw;
1455 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1458 if l.pagevw > 0 && l.pagevh > 0
1459 then rowloop row tiley l.pagedispy l.pagevh;
1462 let gettileopaque l col row =
1464 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1466 try Some
(Hashtbl.find state.tilemap
key)
1467 with Not_found
-> None
1470 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1471 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1472 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1475 let drawtiles l color
=
1477 let f col row x y tilex tiley w h
=
1478 match gettileopaque l col row with
1479 | Some
(opaque
, _, t
) ->
1480 let params = x, y, w
, h
, tilex, tiley in
1484 GlFunc.blend_func `zero `one_minus_src_color
;
1486 drawtile
params opaque
;
1488 then Gl.disable `blend
;
1491 let s = Printf.sprintf
1495 let w = measurestr
fstate.fontsize
s in
1496 GlMisc.push_attrib
[`current
];
1497 GlDraw.color
(0.0, 0.0, 0.0);
1499 (float (x-2), float (y-2))
1500 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1501 GlDraw.color
(1.0, 1.0, 1.0);
1502 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1503 GlMisc.pop_attrib
();
1508 let lw = state.winw
- state.scrollw
- x in
1511 let lh = state.winh
- y in
1514 begin match state.texid
with
1516 Gl.enable `texture_2d
;
1517 GlTex.bind_texture `texture_2d id
;
1520 and x1 = float (x+w)
1521 and y1 = float (y+h
) in
1523 let tw = float w /. 16.0
1524 and th
= float h
/. 16.0 in
1525 let tx0 = float tilex /. 16.0
1526 and ty0
= float tiley /. 16.0 in
1528 and ty1
= ty0
+. th
in
1529 GlDraw.begins `quads
;
1530 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1531 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1532 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1533 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1536 Gl.disable `texture_2d
;
1538 GlDraw.color
(1.0, 1.0, 1.0);
1541 (float (x+w), float (y+h
));
1543 if w > 128 && h
> fstate.fontsize
+ 10
1545 GlDraw.color
(0.0, 0.0, 0.0);
1548 then (col*conf.tilew
, row*conf.tileh
)
1551 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1558 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1560 let tilevisible1 l x y =
1562 and ax1
= l.pagex
+ l.pagevw
1564 and ay1
= l.pagey + l.pagevh in
1568 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1569 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1571 let rx0 = max
ax0 bx0
1572 and ry0
= max ay0 by0
1573 and rx1
= min ax1
bx1
1574 and ry1
= min ay1 by1
in
1576 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1577 nonemptyintersection
1580 let tilevisible layout n x y =
1581 let rec findpageinlayout m
= function
1582 | l :: rest
when l.pageno = n ->
1583 tilevisible1 l x y || (
1584 match conf.columns
with
1585 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1588 | _ :: rest
-> findpageinlayout 0 rest
1591 findpageinlayout 0 layout;
1594 let tileready l x y =
1595 tilevisible1 l x y &&
1596 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1599 let tilepage n p
layout =
1600 let rec loop = function
1604 let f col row _ _ _ _ _ _ =
1605 if state.currently
= Idle
1607 match gettileopaque l col row with
1610 let x = col*conf.tilew
1611 and y = row*conf.tileh
in
1613 let w = l.pagew
- x in
1617 let h = l.pageh
- y in
1622 then getpbo
w h conf.colorspace
1625 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1628 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1629 conf.tilew
, conf.tileh
1638 if nogeomcmds state.geomcmds
1642 let preloadlayout y =
1643 let y = if y < state.winh
then 0 else y - state.winh
in
1644 let h = state.winh
*3 in
1649 let rec loop pages
=
1650 if state.currently
!= Idle
1655 begin match getopaque l.pageno with
1657 wcmd "page %d %d" l.pageno l.pagedimno
;
1658 state.currently
<- Loading
(l, state.gen
);
1660 tilepage l.pageno opaque pages
;
1665 if nogeomcmds state.geomcmds
1671 if conf.preload && state.currently
= Idle
1672 then load (preloadlayout state.y);
1675 let layoutready layout =
1676 let rec fold all ls
=
1677 all
&& match ls
with
1679 let seen = ref false in
1680 let allvisible = ref true in
1681 let foo col row _ _ _ _ _ _ =
1683 allvisible := !allvisible &&
1684 begin match gettileopaque l col row with
1690 fold (!seen && !allvisible) rest
1693 let alltilesvisible = fold true layout in
1698 let y = bound y 0 state.maxy
in
1699 let y, layout, proceed
=
1700 match conf.maxwait
with
1701 | Some time
when state.ghyll
== noghyll ->
1702 begin match state.throttle
with
1704 let layout = layout y state.winh
in
1705 let ready = layoutready layout in
1709 state.throttle
<- Some
(layout, y, now ());
1711 else G.postRedisplay "gotoy showall (None)";
1713 | Some
(_, _, started
) ->
1714 let dt = now () -. started
in
1717 state.throttle
<- None
;
1718 let layout = layout y state.winh
in
1720 G.postRedisplay "maxwait";
1727 let layout = layout y state.winh
in
1728 if not
!wtmode || layoutready layout
1729 then G.postRedisplay "gotoy ready";
1735 state.layout <- layout;
1736 begin match state.mode
with
1737 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1738 let rec loop = function
1740 state.mode
<- LinkNav
(Ltgendir
0)
1741 | l :: _ when l.pageno = pageno ->
1742 begin match getopaque pageno with
1744 state.mode
<- LinkNav
(Ltgendir
0)
1746 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1747 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1748 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1749 then state.mode
<- LinkNav
(Ltgendir
0)
1751 | _ :: rest
-> loop rest
1756 begin match state.mode
with
1757 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1758 if not
(pagevisible layout pageno)
1760 match state.layout with
1763 state.mode
<- Birdseye
(
1764 conf, leftx
, l.pageno, hooverpageno
, anchor
1767 | LinkNav
(Ltgendir dir
as lt
) ->
1769 let rec loop = function
1772 match getopaque l.pageno with
1778 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1780 if dir
> 0 then LDfirst
else LDlast
1786 | Lnotfound
-> loop rest
1788 showlinktype (getlink opaque
n);
1789 Ltexact
(l.pageno, n)
1793 state.mode
<- LinkNav
linknav
1798 state.ghyll
<- noghyll;
1801 let mx, my
= state.mpos
in
1806 let conttiling pageno opaque
=
1807 tilepage pageno opaque
1808 (if conf.preload then preloadlayout state.y else state.layout)
1811 let gotoy_and_clear_text y =
1812 if not
conf.verbose
then state.text <- "";
1818 let coloff = l.pagecol
* l.pageh
in
1819 float (l.pagey + coloff) /. float l.pageh
1826 if conf.presentation
1827 then float l.pagedispy /. float (calcips l.pageh
)
1828 else float l.pagedispy /. float conf.interpagespace
1830 (l.pageno, top, dtop)
1834 match state.layout with
1835 | l :: _ -> getanchor1 l
1837 let n = page_of_y state.y in
1841 let y, h = getpageyh n in
1842 let dy = y - state.y in
1844 if conf.presentation
1846 let ips = calcips h in
1847 float (dy + ips) /. float ips
1849 float dy /. float conf.interpagespace
1854 let getanchory (n, top, dtop) =
1855 let y, h = getpageyh n in
1856 if conf.presentation
1858 let ips = calcips h in
1859 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1861 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1864 let gotoanchor anchor
=
1865 gotoy (getanchory anchor
);
1869 cbput state.hists
.nav
(getanchor ());
1873 let anchor = cbgetc state.hists
.nav dir
in
1878 let scroll f n a
b =
1879 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1881 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1883 then s (float f /. float a
)
1886 then 1.0 -. s ((float (f-b) /. float (n-b)))
1893 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1894 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1896 let ins = float a
*. iv1
1897 and outs
= float (n-b) *. iv1 in
1899 ins +. outs
+. float ones
1901 let rec set (_N
, _A
, _B
) y sy
=
1902 let sum = summa
1.0 _N _A _B
in
1903 let dy = float (y - sy
) in
1907 then state.ghyll
<- noghyll
1910 let s = scroll n _N _A _B
in
1911 let y1 = y1 +. ((s *. dy) /. sum) in
1912 gotoy_and_clear_text (truncate
y1);
1913 state.ghyll
<- gf (n+1) y1;
1917 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1919 gf 0 (float state.y)
1922 match conf.ghyllscroll
with
1924 gotoy_and_clear_text y
1926 if state.ghyll
== noghyll
1927 then set nab
y state.y
1928 else state.ghyll
(Some
y)
1931 let gotopage n top =
1932 let y, h = getpageyh n in
1933 let y = y + (truncate
(top *. float h)) in
1937 let gotopage1 n top =
1938 let y = getpagey n in
1943 let invalidate s f =
1948 match state.geomcmds
with
1949 | ps
, [] when String.length ps
= 0 ->
1951 state.geomcmds
<- s, [];
1954 state.geomcmds
<- ps
, [s, f];
1956 | ps
, (s'
, _) :: rest
when s'
= s ->
1957 state.geomcmds
<- ps
, ((s, f) :: rest
);
1960 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1964 Hashtbl.iter
(fun _ opaque
->
1965 wcmd "freepage %s" opaque
;
1967 Hashtbl.clear
state.pagemap
;
1971 if not
(Queue.is_empty
state.tilelru
)
1973 Queue.iter
(fun (k
, p
, s) ->
1974 wcmd "freetile %s" p
;
1975 state.memused
<- state.memused
- s;
1976 Hashtbl.remove
state.tilemap k
;
1978 state.uioh#infochanged Memused
;
1979 Queue.clear
state.tilelru
;
1984 let opendoc path password
=
1986 state.password
<- password
;
1987 state.gen
<- state.gen
+ 1;
1988 state.docinfo
<- [];
1991 setaalevel
conf.aalevel
;
1993 if String.length
state.origin
= 0
1997 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1998 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
1999 invalidate "reqlayout"
2001 wcmd "reqlayout %d %d %s\000"
2002 conf.angle
(int_of_fitmodel conf.fitmodel
) state.nameddest
;
2007 state.anchor <- getanchor ();
2008 opendoc state.path
state.password
;
2012 let c = c *. conf.colorscale
in
2016 let scalecolor2 (r, g, b) =
2017 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2020 let docolumns = function
2022 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2023 let rec loop pageno pdimno pdim
y ph pdims
=
2024 if pageno = state.pagecount
2027 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2029 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2030 pdimno+1, pdim
, rest
2034 let x = max
0 (((state.winw
- state.scrollw
- w) / 2) - xoff
) in
2036 (if conf.presentation
2037 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2038 else (if pageno = 0 then 0 else conf.interpagespace
)
2041 a.(pageno) <- (pdimno, x, y, pdim
);
2042 loop (pageno+1) pdimno pdim
(y + h) h pdims
2044 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2045 conf.columns
<- Csingle
a;
2047 | Cmulti
((columns
, coverA
, coverB
), _) ->
2048 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2049 let rec loop pageno pdimno pdim
x y rowh pdims
=
2050 let rec fixrow m
= if m
= pageno then () else
2051 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2054 let y = y + (rowh
- h) / 2 in
2055 a.(m
) <- (pdimno, x, y, pdim
);
2059 if pageno = state.pagecount
2060 then fixrow (((pageno - 1) / columns
) * columns
)
2062 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2064 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2065 pdimno+1, pdim
, rest
2070 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2072 let x = (state.winw
- state.scrollw
- w) / 2 in
2074 if conf.presentation
then calcips h else conf.interpagespace
in
2075 x, y + ips + rowh
, h
2078 if (pageno - coverA
) mod columns
= 0
2080 let x = max
0 (state.winw
- state.scrollw
- state.w) / 2 in
2082 if conf.presentation
2084 let ips = calcips h in
2085 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2087 y + (if pageno = 0 then 0 else conf.interpagespace
)
2091 else x, y, max rowh
h
2095 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2098 if pageno = columns
&& conf.presentation
2100 let ips = calcips rowh
in
2101 for i
= 0 to pred columns
2103 let (pdimno, x, y, pdim
) = a.(i
) in
2104 a.(i
) <- (pdimno, x, y+ips, pdim
)
2110 fixrow (pageno - columns
);
2115 a.(pageno) <- (pdimno, x, y, pdim
);
2116 let x = x + w + xoff
*2 + conf.interpagespace
in
2117 loop (pageno+1) pdimno pdim
x y rowh' pdims
2119 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2120 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2123 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2124 let rec loop pageno pdimno pdim
y pdims
=
2125 if pageno = state.pagecount
2128 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2130 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2131 pdimno+1, pdim
, rest
2136 let rec loop1 n x y =
2137 if n = c then y else (
2138 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2139 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2142 let y = loop1 0 0 y in
2143 loop (pageno+1) pdimno pdim
y pdims
2145 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2146 conf.columns
<- Csplit
(c, a);
2150 docolumns conf.columns
;
2151 state.maxy
<- calcheight ();
2153 if state.x = 0 && state.w <= state.winw
- state.scrollw
2157 if state.reprf
== noreprf
2159 match state.mode
with
2160 | Birdseye
(_, _, pageno, _, _) ->
2161 let y, h = getpageyh pageno in
2162 let top = (state.winh
- h) / 2 in
2163 gotoy (max
0 (y - top))
2164 | _ -> gotoanchor state.anchor
2168 state.reprf
<- noreprf;
2173 GlDraw.viewport
0 0 w h;
2174 let firsttime = state.geomcmds
== firstgeomcmds in
2175 if not
firsttime && nogeomcmds state.geomcmds
2176 then state.anchor <- getanchor ();
2179 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2182 setfontsize fstate.fontsize
;
2183 GlMat.mode `modelview
;
2184 GlMat.load_identity
();
2186 GlMat.mode `projection
;
2187 GlMat.load_identity
();
2188 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2189 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2190 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2195 else float state.x /. float state.w
2197 invalidate "geometry"
2201 then state.x <- truncate
(relx *. float w);
2203 match conf.columns
with
2205 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2206 | Csplit
(c, _) -> w * c
2208 wcmd "geometry %d %d %d"
2209 w ((truncate
(float h*.conf.zoom
)) - 2*conf.interpagespace
)
2210 (int_of_fitmodel conf.fitmodel
)
2215 let len = String.length
state.text in
2218 match state.mode
with
2221 let h, _, _ = state.uioh#scrollpw
in
2227 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2228 (x+.w, float (state.winh
- hscrollh))
2231 let w = float (state.winw
- state.scrollw
- 1) in
2232 if state.progress
>= 0.0 && state.progress
< 1.0
2234 GlDraw.color
(0.3, 0.3, 0.3);
2235 let w1 = w *. state.progress
in
2237 GlDraw.color
(0.0, 0.0, 0.0);
2241 GlDraw.color
(0.0, 0.0, 0.0);
2245 GlDraw.color
(1.0, 1.0, 1.0);
2246 drawstring fstate.fontsize
2247 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2250 match state.mode
with
2251 | Textentry
((prefix
, text, _, _, _, _), _) ->
2255 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2257 Printf.sprintf
"%s%s_" prefix
text
2266 if not
(istextentry state.mode
) && state.uioh#eformsgs
2268 let s1 = "(press 'e' to review error messasges)" in
2269 if String.length
s > 0 then s ^
" " ^
s1 else s1
2274 if String.length
s > 0
2279 let len = Queue.length
state.tilelru
in
2281 match state.throttle
with
2284 then preloadlayout state.y
2286 | Some
(layout, _, _) ->
2290 if state.memused
<= conf.memlimit
2295 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2296 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2297 let (_, pw, ph
, _) = getpagedim n in
2300 && colorspace
= conf.colorspace
2301 && angle
= conf.angle
2305 let x = col*conf.tilew
2306 and y = row*conf.tileh
in
2307 tilevisible (Lazy.force_val
layout) n x y
2309 then Queue.push lruitem
state.tilelru
2312 wcmd "freetile %s" p
;
2313 state.memused
<- state.memused
- s;
2314 state.uioh#infochanged Memused
;
2315 Hashtbl.remove
state.tilemap k
;
2323 let logcurrently = function
2324 | Idle
-> dolog
"Idle"
2325 | Loading
(l, gen
) ->
2326 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2327 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2329 "Tiling %d[%d,%d] page=%s cs=%s angle"
2330 l.pageno col row pageopaque
2331 (colorspace_to_string colorspace
)
2333 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2334 angle gen
conf.angle
state.gen
2336 conf.tilew
conf.tileh
2343 let r = Str.regexp
" " in
2344 fun s -> Str.bounded_split
r s 2;
2347 let onpagerect pageno f =
2349 match conf.columns
with
2350 | Cmulti
(_, b) -> b
2352 | Csplit
(_, b) -> b
2354 if pageno >= 0 && pageno < Array.length
b
2356 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2357 let r = getpdimrect
pdimno in
2358 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2361 let gotopagexy1 pageno x y =
2362 onpagerect pageno (fun w h ->
2364 let _,w1,_,leftx
= getpagedim pageno in
2365 let wh = state.winh
- state.hscrollh in
2366 let sw = float w1 /. w in
2368 let x = leftx
+ state.x + truncate
x in
2370 if x < 0 || x >= state.winw
- state.scrollw
2374 let py, h = getpageyh pageno in
2375 let pdy = truncate
(top *. float h) in
2376 let y'
= py + pdy in
2377 let dy = y'
- state.y in
2379 if x != state.x || not
(dy > 0 && dy < wh)
2381 if conf.presentation
2383 if abs
(py - y'
) > wh
2390 if state.x != sx || state.y != sy
2395 let ww = state.winw
- state.scrollw
in
2397 and qy
= pdy / wh in
2399 and y = py + qy
* wh in
2400 let x = if -x + ww > w1 then -(w1-ww) else x
2401 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2403 if conf.presentation
2405 if abs
(py - y'
) > wh
2416 if x = 0 && state.w <= state.winw
- state.scrollw
2420 gotoy_and_clear_text y;
2422 else gotoy_and_clear_text state.y;
2426 let gotopagexy pageno x y =
2427 match state.mode
with
2428 | Birdseye
_ -> gotopage pageno 0.0
2429 | _ -> gotopagexy1 pageno x y
2433 (* dolog "%S" cmds; *)
2434 let cl = splitatspace cmds
in
2436 try Scanf.sscanf
s fmt
f
2438 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2443 state.uioh#infochanged Pdim
;
2446 | "clearrects" :: [] ->
2447 state.rects
<- state.rects1
;
2448 G.postRedisplay "clearrects";
2450 | "continue" :: args :: [] ->
2451 let n = scan args "%u" (fun n -> n) in
2452 state.pagecount
<- n;
2453 begin match state.currently
with
2455 state.currently
<- Idle
;
2456 state.outlines
<- Array.of_list
(List.rev
l)
2460 let cur, cmds
= state.geomcmds
in
2461 if String.length
cur = 0
2462 then failwith
"umpossible";
2464 begin match List.rev cmds
with
2466 state.geomcmds
<- "", [];
2470 state.geomcmds
<- s, List.rev rest
;
2472 if conf.maxwait
= None
&& not
!wtmode
2473 then G.postRedisplay "continue";
2475 | "title" :: args :: [] ->
2478 | "msg" :: args :: [] ->
2481 | "vmsg" :: args :: [] ->
2483 then showtext ' '
args
2485 | "emsg" :: args :: [] ->
2486 Buffer.add_string
state.errmsgs
args;
2487 state.newerrmsgs
<- true;
2488 G.postRedisplay "error message"
2490 | "progress" :: args :: [] ->
2491 let progress, text =
2494 f, String.sub
args pos
(String.length
args - pos
))
2497 state.progress <- progress;
2498 G.postRedisplay "progress"
2500 | "firstmatch" :: args :: [] ->
2501 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2502 scan args "%u %d %f %f %f %f %f %f %f %f"
2503 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2504 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2506 let y = (getpagey pageno) + truncate
y0 in
2509 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2511 | "match" :: args :: [] ->
2512 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2513 scan args "%u %d %f %f %f %f %f %f %f %f"
2514 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2515 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2518 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2520 | "page" :: args :: [] ->
2521 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2522 begin match state.currently
with
2523 | Loading
(l, gen
) ->
2524 vlog "page %d took %f sec" l.pageno t
;
2525 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2526 begin match state.throttle
with
2528 let preloadedpages =
2530 then preloadlayout state.y
2535 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2536 IntSet.empty
preloadedpages
2539 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2540 if not
(IntSet.mem
pageno set)
2542 wcmd "freepage %s" opaque
;
2548 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2551 state.currently
<- Idle
;
2554 tilepage l.pageno pageopaque state.layout;
2556 load preloadedpages;
2557 if pagevisible state.layout l.pageno
2558 && layoutready state.layout
2559 then G.postRedisplay "page";
2562 | Some
(layout, _, _) ->
2563 state.currently
<- Idle
;
2564 tilepage l.pageno pageopaque layout;
2569 dolog
"Inconsistent loading state";
2570 logcurrently state.currently
;
2574 | "tile" :: args :: [] ->
2575 let (x, y, opaque
, size
, t
) =
2576 scan args "%u %u %s %u %f"
2577 (fun x y p size t
-> (x, y, p
, size
, t
))
2579 begin match state.currently
with
2580 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2581 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2584 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2586 wcmd "freetile %s" opaque
;
2587 state.currently
<- Idle
;
2591 puttileopaque l col row gen cs angle opaque size t
;
2592 state.memused
<- state.memused
+ size
;
2593 state.uioh#infochanged Memused
;
2595 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2596 opaque
, size
) state.tilelru
;
2599 match state.throttle
with
2600 | None
-> state.layout
2601 | Some
(layout, _, _) -> layout
2604 state.currently
<- Idle
;
2606 && conf.colorspace
= cs
2607 && conf.angle
= angle
2608 && tilevisible layout l.pageno x y
2609 then conttiling l.pageno pageopaque;
2611 begin match state.throttle
with
2613 preload state.layout;
2615 && conf.colorspace
= cs
2616 && conf.angle
= angle
2617 && tilevisible state.layout l.pageno x y
2618 && (not
!wtmode || layoutready state.layout)
2619 then G.postRedisplay "tile nothrottle";
2621 | Some
(layout, y, _) ->
2622 let ready = layoutready layout in
2626 state.layout <- layout;
2627 state.throttle
<- None
;
2628 G.postRedisplay "throttle";
2635 dolog
"Inconsistent tiling state";
2636 logcurrently state.currently
;
2640 | "pdim" :: args :: [] ->
2641 let (n, w, h, _) as pdim
=
2642 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2645 match conf.fitmodel
, conf.columns
with
2646 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2649 state.uioh#infochanged Pdim
;
2650 state.pdims
<- pdim :: state.pdims
2652 | "o" :: args :: [] ->
2653 let (l, n, t
, h, pos
) =
2654 scan args "%u %u %d %u %n"
2655 (fun l n t
h pos
-> l, n, t
, h, pos
)
2657 let s = String.sub
args pos
(String.length
args - pos
) in
2658 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2659 begin match state.currently
with
2660 | Outlining outlines
->
2661 state.currently
<- Outlining
(outline :: outlines
)
2663 state.currently
<- Outlining
[outline]
2665 dolog
"invalid outlining state";
2666 logcurrently currently
2669 | "a" :: args :: [] ->
2671 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2673 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2675 | "info" :: args :: [] ->
2676 state.docinfo
<- (1, args) :: state.docinfo
2678 | "infoend" :: [] ->
2679 state.uioh#infochanged Docinfo
;
2680 state.docinfo
<- List.rev
state.docinfo
2683 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2688 let action = function
2689 | HCprev
-> cbget cb ~
-1
2690 | HCnext
-> cbget cb
1
2691 | HCfirst
-> cbget cb ~
-(cb
.rc)
2692 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2693 and cancel
() = cb
.rc <- rc
2697 let search pattern forward
=
2698 match conf.columns
with
2700 showtext '
!'
"searching does not work properly in split columns mode"
2702 if String.length pattern
> 0
2705 match state.layout with
2708 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2710 wcmd "search %d %d %d %d,%s\000"
2711 (btod conf.icase
) pn py (btod forward
) pattern
;
2714 let intentry text key =
2716 if key >= 32 && key < 127
2722 let text = addchar text c in
2726 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2730 let linknentry text key =
2732 if key >= 32 && key < 127
2738 let text = addchar text c in
2742 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2747 if String.length
s > 0
2750 let l = String.length
s in
2751 let rec loop pos
n = if pos
= l then n else
2752 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2753 loop (pos
+1) (n*26 + m)
2756 let rec loop n = function
2759 match getopaque l.pageno with
2760 | None
-> loop n rest
2762 let m = getlinkcount opaque
in
2765 let under = getlink opaque
n in
2768 else loop (n-m) rest
2770 loop n state.layout;
2774 let textentry text key =
2775 if key land 0xff00 = 0xff00
2777 else TEcont
(text ^ toutf8
key)
2780 let reqlayout angle fitmodel
=
2781 match state.throttle
with
2783 if nogeomcmds state.geomcmds
2784 then state.anchor <- getanchor ();
2785 conf.angle
<- angle
mod 360;
2788 match state.mode
with
2789 | LinkNav
_ -> state.mode
<- View
2792 conf.fitmodel
<- fitmodel
;
2793 invalidate "reqlayout"
2795 wcmd "reqlayout %d %d" conf.angle
(int_of_fitmodel conf.fitmodel
)
2800 let settrim trimmargins trimfuzz
=
2801 if nogeomcmds state.geomcmds
2802 then state.anchor <- getanchor ();
2803 conf.trimmargins
<- trimmargins
;
2804 conf.trimfuzz
<- trimfuzz
;
2805 let x0, y0, x1, y1 = trimfuzz
in
2806 invalidate "settrim"
2808 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2813 match state.throttle
with
2815 let zoom = max
0.0001 zoom in
2816 if zoom <> conf.zoom
2818 state.prevzoom
<- conf.zoom;
2820 reshape state.winw
state.winh
;
2821 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2824 | Some
(layout, y, started
) ->
2826 match conf.maxwait
with
2830 let dt = now () -. started
in
2838 let setcolumns mode columns coverA coverB
=
2839 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2843 then showtext '
!'
"split mode doesn't work in bird's eye"
2845 conf.columns
<- Csplit
(-columns
, [||]);
2853 conf.columns
<- Csingle
[||];
2858 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2862 reshape state.winw
state.winh
;
2865 let enterbirdseye () =
2866 let zoom = float conf.thumbw
/. float state.winw
in
2867 let birdseyepageno =
2868 let cy = state.winh
/ 2 in
2872 let rec fold best
= function
2875 let d = cy - (l.pagedispy + l.pagevh/2)
2876 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2877 if abs
d < abs dbest
2884 state.mode
<- Birdseye
(
2885 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2888 conf.presentation
<- false;
2889 conf.interpagespace
<- 10;
2890 conf.hlinks
<- false;
2891 conf.fitmodel
<- FitProportional
;
2893 state.mstate
<- Mnone
;
2894 conf.maxwait
<- None
;
2896 match conf.beyecolumns
with
2899 Cmulti
((c, 0, 0), [||])
2900 | None
-> Csingle
[||]
2902 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2905 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2910 reshape state.winw
state.winh
;
2913 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2915 conf.zoom <- c.zoom;
2916 conf.presentation
<- c.presentation
;
2917 conf.interpagespace
<- c.interpagespace
;
2918 conf.maxwait
<- c.maxwait
;
2919 conf.hlinks
<- c.hlinks
;
2920 conf.fitmodel
<- c.fitmodel
;
2921 conf.beyecolumns
<- (
2922 match conf.columns
with
2923 | Cmulti
((c, _, _), _) -> Some
c
2925 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2928 match c.columns
with
2929 | Cmulti
(c, _) -> Cmulti
(c, [||])
2930 | Csingle
_ -> Csingle
[||]
2931 | Csplit
(c, _) -> Csplit
(c, [||])
2936 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2939 reshape state.winw
state.winh
;
2940 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2943 let togglebirdseye () =
2944 match state.mode
with
2945 | Birdseye vals
-> leavebirdseye vals
true
2946 | View
-> enterbirdseye ()
2950 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2951 let pageno = max
0 (pageno - incr
) in
2952 let rec loop = function
2953 | [] -> gotopage1 pageno 0
2954 | l :: _ when l.pageno = pageno ->
2955 if l.pagedispy >= 0 && l.pagey = 0
2956 then G.postRedisplay "upbirdseye"
2957 else gotopage1 pageno 0
2958 | _ :: rest
-> loop rest
2961 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2964 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2965 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2966 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2967 let rec loop = function
2969 let y, h = getpageyh pageno in
2970 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2972 | l :: _ when l.pageno = pageno ->
2973 if l.pagevh != l.pageh
2974 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2975 else G.postRedisplay "downbirdseye"
2976 | _ :: rest
-> loop rest
2981 let optentry mode
_ key =
2982 let btos b = if b then "on" else "off" in
2983 if key >= 32 && key < 127
2985 let c = Char.chr
key in
2989 try conf.scrollstep
<- int_of_string
s with exc
->
2990 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2992 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2997 conf.autoscrollstep
<- int_of_string
s;
2998 if state.autoscroll
<> None
2999 then state.autoscroll
<- Some
conf.autoscrollstep
3001 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3003 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3008 let n, a, b = multicolumns_of_string s in
3009 setcolumns mode
n a b;
3011 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3013 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3018 let zoom = float (int_of_string
s) /. 100.0 in
3021 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3023 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3028 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3030 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3031 begin match mode
with
3033 leavebirdseye beye
false;
3038 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3040 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3045 Some
(int_of_string
s)
3047 state.text <- Printf.sprintf
"bad integer `%s': %s"
3051 | Some angle
-> reqlayout angle
conf.fitmodel
3054 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3057 conf.icase
<- not
conf.icase
;
3058 TEdone
("case insensitive search " ^
(btos conf.icase
))
3061 conf.preload <- not
conf.preload;
3063 TEdone
("preload " ^
(btos conf.preload))
3066 conf.verbose
<- not
conf.verbose
;
3067 TEdone
("verbose " ^
(btos conf.verbose
))
3070 conf.debug
<- not
conf.debug
;
3071 TEdone
("debug " ^
(btos conf.debug
))
3074 conf.maxhfit
<- not
conf.maxhfit
;
3075 state.maxy
<- calcheight ();
3076 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3079 conf.crophack
<- not
conf.crophack
;
3080 TEdone
("crophack " ^
btos conf.crophack
)
3084 match conf.maxwait
with
3086 conf.maxwait
<- Some infinity
;
3087 "always wait for page to complete"
3089 conf.maxwait
<- None
;
3090 "show placeholder if page is not ready"
3095 conf.underinfo
<- not
conf.underinfo
;
3096 TEdone
("underinfo " ^
btos conf.underinfo
)
3099 conf.savebmarks
<- not
conf.savebmarks
;
3100 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3106 match state.layout with
3111 conf.interpagespace
<- int_of_string
s;
3112 docolumns conf.columns
;
3113 state.maxy
<- calcheight ();
3114 let y = getpagey pageno in
3117 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3119 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3123 match conf.fitmodel
with
3124 | FitProportional
-> FitWidth
3125 | _ -> FitProportional
3127 reqlayout conf.angle
fm;
3128 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3131 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3132 TEdone
("trim margins " ^
btos conf.trimmargins
)
3135 conf.invert
<- not
conf.invert
;
3136 TEdone
("invert colors " ^
btos conf.invert
)
3140 cbput state.hists
.sel
s;
3143 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3144 textentry, ondone, true)
3147 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3153 class type lvsource
= object
3154 method getitemcount
: int
3155 method getitem
: int -> (string * int)
3156 method hasaction
: int -> bool
3165 method getactive
: int
3166 method getfirst
: int
3167 method getqsearch
: string
3168 method setqsearch
: string -> unit
3172 class virtual lvsourcebase
= object
3173 val mutable m_active
= 0
3174 val mutable m_first
= 0
3175 val mutable m_qsearch
= ""
3176 val mutable m_pan
= 0
3177 method getactive
= m_active
3178 method getfirst
= m_first
3179 method getqsearch
= m_qsearch
3180 method getpan
= m_pan
3181 method setqsearch
s = m_qsearch
<- s
3184 let withoutlastutf8 s =
3185 let len = String.length
s in
3193 let b = Char.code
s.[pos
] in
3194 if b land 0b11000000 = 0b11000000
3199 if Char.code
s.[len-1] land 0x80 = 0
3203 String.sub
s 0 first;
3206 let textentrykeyboard
3207 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3209 if key >= 0xffb0 && key <= 0xffb9
3210 then key - 0xffb0 + 48 else key
3213 state.mode
<- Textentry
(te
, onleave
);
3216 G.postRedisplay "textentrykeyboard enttext";
3218 let histaction cmd
=
3221 | Some
(action, _) ->
3222 state.mode
<- Textentry
(
3223 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3225 G.postRedisplay "textentry histaction"
3228 | 0xff08 -> (* backspace *)
3229 let s = withoutlastutf8 text in
3230 let len = String.length
s in
3231 if cancelonempty
&& len = 0
3234 G.postRedisplay "textentrykeyboard after cancel";
3237 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3240 | 0xff0d | 0xff8d -> (* (kp) enter *)
3243 G.postRedisplay "textentrykeyboard after confirm"
3245 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3246 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3247 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3248 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3250 | 0xff1b -> (* escape*)
3251 if String.length
text = 0
3253 begin match opthist
with
3255 | Some
(_, onhistcancel
) -> onhistcancel
()
3259 G.postRedisplay "textentrykeyboard after cancel2"
3262 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3265 | 0xff9f | 0xffff -> () (* delete *)
3268 && key land 0xff00 != 0xff00 (* keyboard *)
3269 && key land 0xfe00 != 0xfe00 (* xkb *)
3270 && key land 0xfd00 != 0xfd00 (* 3270 *)
3272 begin match onkey
text key with
3276 G.postRedisplay "textentrykeyboard after confirm2";
3279 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3283 G.postRedisplay "textentrykeyboard after cancel3"
3286 state.mode
<- Textentry
(te
, onleave
);
3287 G.postRedisplay "textentrykeyboard switch";
3291 vlog "unhandled key %s" (Wsi.keyname
key)
3294 let firstof first active
=
3295 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3296 then max
0 (active
- (fstate.maxrows
/2))
3300 let calcfirst first active
=
3303 let rows = active
- first in
3304 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3308 let scrollph y maxy
=
3309 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3310 let sh = float state.winh
/. sh in
3311 let sh = max
sh (float conf.scrollh
) in
3313 let percent = float y /. float maxy
in
3314 let position = (float state.winh
-. sh) *. percent in
3317 if position +. sh > float state.winh
3318 then float state.winh
-. sh
3324 let coe s = (s :> uioh
);;
3326 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3328 val m_pan
= source#getpan
3329 val m_first
= source#getfirst
3330 val m_active
= source#getactive
3331 val m_qsearch
= source#getqsearch
3332 val m_prev_uioh
= state.uioh
3334 method private elemunder
y =
3335 let n = y / (fstate.fontsize
+1) in
3336 if m_first
+ n < source#getitemcount
3338 if source#hasaction
(m_first
+ n)
3339 then Some
(m_first
+ n)
3346 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3347 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3348 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3349 GlDraw.color
(1., 1., 1.);
3350 Gl.enable `texture_2d
;
3351 let fs = fstate.fontsize
in
3353 let ww = fstate.wwidth
in
3354 let tabw = 30.0*.ww in
3355 let itemcount = source#getitemcount
in
3357 if (row - m_first
) > fstate.maxrows
3360 if row >= 0 && row < itemcount
3362 let (s, level
) = source#getitem
row in
3363 let y = (row - m_first
) * nfs in
3364 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3367 Gl.disable `texture_2d
;
3368 GlDraw.polygon_mode `both `line
;
3369 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3370 GlDraw.color
(1., 1., 1.) ~
alpha;
3371 GlDraw.rect (1., float (y + 1))
3372 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3373 GlDraw.polygon_mode `both `fill
;
3374 GlDraw.color
(1., 1., 1.);
3375 Gl.enable `texture_2d
;
3378 let drawtabularstring s =
3379 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3382 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3385 let len = String.length
s - tabpos - 1 in
3386 let s1 = String.sub
s 0 tabpos
3387 and s2
= String.sub
s (tabpos + 1) len in
3388 let nx = drawstr x s1 in
3390 let x = x +. (max
tabw sw) in
3397 let _ = drawtabularstring s in
3404 Gl.disable `texture_2d
;
3406 method updownlevel incr
=
3407 let len = source#getitemcount
in
3409 if m_active
>= 0 && m_active
< len
3410 then snd
(source#getitem m_active
)
3414 if i
= len then i
-1 else if i
= -1 then 0 else
3415 let _, l = source#getitem i
in
3416 if l != curlevel then i
else flow (i
+incr
)
3418 let active = flow m_active
in
3419 let first = calcfirst m_first
active in
3420 G.postRedisplay "outline updownlevel";
3421 {< m_active
= active; m_first
= first >}
3423 method private key1
key mask
=
3424 let set1 active first qsearch
=
3425 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3427 let search active pattern incr
=
3428 let active = if active = -1 then m_first
else active in
3431 if n >= 0 && n < source#getitemcount
3433 let s, _ = source#getitem
n in
3435 (try ignore
(Str.search_forward
re s 0); true
3436 with Not_found
-> false)
3438 else loop (n + incr
)
3445 let re = Str.regexp_case_fold pattern
in
3451 let itemcount = source#getitemcount
in
3452 let find start incr
=
3454 if i
= -1 || i
= itemcount
3457 if source#hasaction i
3459 else find (i
+ incr
)
3464 let set active first =
3465 let first = bound first 0 (itemcount - fstate.maxrows
) in
3467 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3470 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3472 let incr1 = if incr
> 0 then 1 else -1 in
3473 if isvisible m_first m_active
3476 let next = m_active
+ incr
in
3478 if next < 0 || next >= itemcount
3480 else find next incr1
3482 if abs
(m_active
- next) > fstate.maxrows
3488 let first = m_first
+ incr
in
3489 let first = bound first 0 (itemcount - 1) in
3491 let next = m_active
+ incr
in
3492 let next = bound next 0 (itemcount - 1) in
3499 if isvisible first next
3506 let first = min
next m_first
in
3508 if abs
(next - first) > fstate.maxrows
3514 let first = m_first
+ incr
in
3515 let first = bound first 0 (itemcount - 1) in
3517 let next = m_active
+ incr
in
3518 let next = bound next 0 (itemcount - 1) in
3519 let next = find next incr1 in
3521 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3523 let active = if m_active
= -1 then next else m_active
in
3528 if isvisible first active
3534 G.postRedisplay "listview navigate";
3538 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3539 let incr = if key = 0x72 then -1 else 1 in
3541 match search (m_active
+ incr) m_qsearch
incr with
3543 state.text <- m_qsearch ^
" [not found]";
3546 state.text <- m_qsearch
;
3547 active, firstof m_first
active
3549 G.postRedisplay "listview ctrl-r/s";
3550 set1 active first m_qsearch
;
3552 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3553 if m_active
>= 0 && m_active
< source#getitemcount
3555 let s, _ = source#getitem m_active
in
3560 | 0xff08 -> (* backspace *)
3561 if String.length m_qsearch
= 0
3564 let qsearch = withoutlastutf8 m_qsearch
in
3565 let len = String.length
qsearch in
3569 G.postRedisplay "listview empty qsearch";
3570 set1 m_active m_first
"";
3574 match search m_active
qsearch ~
-1 with
3576 state.text <- qsearch ^
" [not found]";
3579 state.text <- qsearch;
3580 active, firstof m_first
active
3582 G.postRedisplay "listview backspace qsearch";
3583 set1 active first qsearch
3586 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3587 let pattern = m_qsearch ^ toutf8
key in
3589 match search m_active
pattern 1 with
3591 state.text <- pattern ^
" [not found]";
3594 state.text <- pattern;
3595 active, firstof m_first
active
3597 G.postRedisplay "listview qsearch add";
3598 set1 active first pattern;
3600 | 0xff1b -> (* escape *)
3602 if String.length m_qsearch
= 0
3604 G.postRedisplay "list view escape";
3607 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3609 | None
-> m_prev_uioh
3614 G.postRedisplay "list view kill qsearch";
3615 source#setqsearch
"";
3616 coe {< m_qsearch
= "" >}
3619 | 0xff0d | 0xff8d -> (* (kp) enter *)
3621 let self = {< m_qsearch
= "" >} in
3622 source#setqsearch
"";
3624 G.postRedisplay "listview enter";
3625 if m_active
>= 0 && m_active
< source#getitemcount
3627 source#exit
(coe self) false m_active m_first m_pan
"";
3630 source#exit
(coe self) true m_active m_first m_pan
"";
3633 begin match opt with
3634 | None
-> m_prev_uioh
3638 | 0xff9f | 0xffff -> (* (kp) delete *)
3641 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3642 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3643 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3644 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3646 | 0xff53 | 0xff98 -> (* (kp) right *)
3648 G.postRedisplay "listview right";
3649 coe {< m_pan
= m_pan
- 1 >}
3651 | 0xff51 | 0xff96 -> (* (kp) left *)
3653 G.postRedisplay "listview left";
3654 coe {< m_pan
= m_pan
+ 1 >}
3656 | 0xff50 | 0xff95 -> (* (kp) home *)
3657 let active = find 0 1 in
3658 G.postRedisplay "listview home";
3661 | 0xff57 | 0xff9c -> (* (kp) end *)
3662 let first = max
0 (itemcount - fstate.maxrows
) in
3663 let active = find (itemcount - 1) ~
-1 in
3664 G.postRedisplay "listview end";
3667 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3671 dolog
"listview unknown key %#x" key; coe self
3673 method key key mask
=
3674 match state.mode
with
3675 | Textentry te
-> textentrykeyboard key mask te
; coe self
3676 | _ -> self#key1
key mask
3678 method button button down
x y _ =
3681 | 1 when x > state.winw
- conf.scrollbw
->
3682 G.postRedisplay "listview scroll";
3685 let _, position, sh = self#
scrollph in
3686 if y > truncate
position && y < truncate
(position +. sh)
3688 state.mstate
<- Mscrolly
;
3692 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3693 let first = truncate
(s *. float source#getitemcount
) in
3694 let first = min source#getitemcount
first in
3695 Some
(coe {< m_first
= first; m_active
= first >})
3697 state.mstate
<- Mnone
;
3700 | 1 when not down
->
3701 begin match self#elemunder
y with
3703 G.postRedisplay "listview click";
3705 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3709 | n when (n == 4 || n == 5) && not down
->
3710 let len = source#getitemcount
in
3712 if n = 5 && m_first
+ fstate.maxrows
>= len
3716 let first = m_first
+ (if n == 4 then -1 else 1) in
3717 bound first 0 (len - 1)
3719 G.postRedisplay "listview wheel";
3720 Some
(coe {< m_first
= first >})
3721 | n when (n = 6 || n = 7) && not down
->
3722 let inc = m_first
+ (if n = 7 then -1 else 1) in
3723 G.postRedisplay "listview hwheel";
3724 Some
(coe {< m_pan
= m_pan
+ inc >})
3729 | None
-> m_prev_uioh
3733 match state.mstate
with
3735 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3736 let first = truncate
(s *. float source#getitemcount
) in
3737 let first = min source#getitemcount
first in
3738 G.postRedisplay "listview motion";
3739 coe {< m_first
= first; m_active
= first >}
3742 method pmotion
x y =
3743 if x < state.winw
- conf.scrollbw
3746 match self#elemunder
y with
3747 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3748 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3752 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3757 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3761 method infochanged
_ = ()
3763 method scrollpw
= (0, 0.0, 0.0)
3765 let nfs = fstate.fontsize
+ 1 in
3766 let y = m_first
* nfs in
3767 let itemcount = source#getitemcount
in
3768 let maxi = max
0 (itemcount - fstate.maxrows
) in
3769 let maxy = maxi * nfs in
3770 let p, h = scrollph y maxy in
3773 method modehash
= modehash
3774 method eformsgs
= false
3777 class outlinelistview ~source
=
3780 ~source
:(source
:> lvsource
)
3782 ~modehash
:(findkeyhash conf "outline")
3785 method key key mask
=
3786 let calcfirst first active =
3789 let rows = active - first in
3791 if String.length
state.text = 0
3793 else fstate.maxrows - 2
3795 if rows > maxrows then active - maxrows else first
3799 let active = m_active
+ incr in
3800 let active = bound active 0 (source#getitemcount
- 1) in
3801 let first = calcfirst m_first
active in
3802 G.postRedisplay "outline navigate";
3803 coe {< m_active
= active; m_first
= first >}
3805 let ctrl = Wsi.withctrl mask
in
3807 | 110 when ctrl -> (* ctrl-n *)
3808 source#narrow m_qsearch
;
3809 G.postRedisplay "outline ctrl-n";
3810 coe {< m_first
= 0; m_active
= 0 >}
3812 | 117 when ctrl -> (* ctrl-u *)
3814 G.postRedisplay "outline ctrl-u";
3816 coe {< m_first
= 0; m_active
= 0 >}
3818 | 108 when ctrl -> (* ctrl-l *)
3819 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3820 G.postRedisplay "outline ctrl-l";
3821 coe {< m_first
= first >}
3823 | 0xff9f | 0xffff -> (* (kp) delete *)
3824 source#remove m_active
;
3825 G.postRedisplay "outline delete";
3826 let active = max
0 (m_active
-1) in
3827 coe {< m_first
= firstof m_first
active;
3828 m_active
= active >}
3830 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3831 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3832 | 0xff55 | 0xff9a -> (* (kp) prior *)
3833 navigate ~
-(fstate.maxrows)
3834 | 0xff56 | 0xff9b -> (* (kp) next *)
3835 navigate fstate.maxrows
3837 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3841 G.postRedisplay "outline ctrl right";
3842 {< m_pan
= m_pan
+ 1 >}
3844 else self#updownlevel
1
3848 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3852 G.postRedisplay "outline ctrl left";
3853 {< m_pan
= m_pan
- 1 >}
3855 else self#updownlevel ~
-1
3859 | 0xff50 | 0xff95 -> (* (kp) home *)
3860 G.postRedisplay "outline home";
3861 coe {< m_first
= 0; m_active
= 0 >}
3863 | 0xff57 | 0xff9c -> (* (kp) end *)
3864 let active = source#getitemcount
- 1 in
3865 let first = max
0 (active - fstate.maxrows) in
3866 G.postRedisplay "outline end";
3867 coe {< m_active
= active; m_first
= first >}
3869 | _ -> super#
key key mask
3872 let outlinesource usebookmarks
=
3875 inherit lvsourcebase
3876 val mutable m_items
= empty
3877 val mutable m_orig_items
= empty
3878 val mutable m_prev_items
= empty
3879 val mutable m_narrow_pattern
= ""
3880 val mutable m_hadremovals
= false
3882 method getitemcount
=
3883 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3886 if n == Array.length m_items
&& m_hadremovals
3888 ("[Confirm removal]", 0)
3890 let s, n, _ = m_items
.(n) in
3893 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3894 ignore
(uioh
, first, qsearch);
3895 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3897 if String.length m_narrow_pattern
= 0
3903 if not
confrimremoval
3905 let _, _, anchor = m_items
.(active) in
3906 gotoghyll (getanchory anchor);
3910 state.bookmarks
<- Array.to_list m_items
;
3911 m_orig_items
<- m_items
;
3914 else m_items
<- items;
3918 method hasaction
_ = true
3921 if Array.length m_items
!= Array.length m_orig_items
3922 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3925 method narrow
pattern =
3926 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3930 let rec loop accu n =
3933 m_narrow_pattern
<- pattern;
3934 m_items
<- Array.of_list
accu
3937 let (s, _, _) as o = m_items
.(n) in
3939 if (try ignore
(Str.search_forward
re s 0); true
3940 with Not_found
-> false)
3946 loop [] (Array.length m_items
- 1)
3951 then Array.of_list
state.bookmarks
3954 m_items
<- m_orig_items
3959 if m >= 0 && m < Array.length m_items
3961 m_hadremovals
<- true;
3962 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3963 let n = if n >= m then n+1 else n in
3968 method reset
anchor items =
3969 m_hadremovals
<- false;
3970 if m_orig_items
== empty || m_prev_items
!= items
3972 m_orig_items
<- items;
3973 if String.length m_narrow_pattern
= 0
3974 then m_items
<- items;
3976 m_prev_items
<- items;
3977 let rely = getanchory anchor in
3979 let rec loop n best bestd
=
3980 if n = Array.length m_items
3983 let (_, _, anchor) = m_items
.(n) in
3984 let orely = getanchory anchor in
3985 let d = abs
(orely - rely) in
3988 else loop (n+1) best bestd
3993 m_first
<- firstof m_first
active
3997 let enterselector usebookmarks
=
3998 let source = outlinesource usebookmarks
in
4002 then Array.of_list
state.bookmarks
4005 if Array.length
outlines = 0
4007 showtext ' ' errmsg
;
4010 state.text <- source#greetmsg
;
4011 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4012 let anchor = getanchor () in
4013 source#reset
anchor outlines;
4014 state.uioh
<- coe (new outlinelistview ~
source);
4015 G.postRedisplay "enter selector";
4019 let enteroutlinemode =
4020 let f = enterselector false in
4021 fun ()-> f "Document has no outline";
4024 let enterbookmarkmode =
4025 let f = enterselector true in
4026 fun () -> f "Document has no bookmarks (yet)";
4029 let color_of_string s =
4030 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4031 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4035 let color_to_string (r, g, b) =
4036 let r = truncate
(r *. 256.0)
4037 and g = truncate
(g *. 256.0)
4038 and b = truncate
(b *. 256.0) in
4039 Printf.sprintf
"%d/%d/%d" r g b
4042 let irect_of_string s =
4043 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4046 let irect_to_string (x0,y0,x1,y1) =
4047 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4050 let makecheckers () =
4051 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4053 converted by Issac Trotts. July 25, 2002 *)
4054 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4055 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4056 let id = GlTex.gen_texture
() in
4057 GlTex.bind_texture `texture_2d
id;
4058 GlPix.store
(`unpack_alignment
1);
4059 GlTex.image2d
image;
4060 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4061 [ `mag_filter `nearest
; `min_filter `nearest
];
4065 let setcheckers enabled
=
4066 match state.texid
with
4068 if enabled
then state.texid
<- Some
(makecheckers ())
4073 GlTex.delete_texture texid
;
4074 state.texid
<- None
;
4078 let int_of_string_with_suffix s =
4079 let l = String.length
s in
4083 let suffix = Char.lowercase
s.[l-1] in
4085 | 'k'
-> String.sub
s 0 (l-1), 10
4086 | '
m'
-> String.sub
s 0 (l-1), 20
4087 | '
g'
-> String.sub
s 0 (l-1), 30
4091 let n = int_of_string
s1 in
4092 let m = n lsl shift
in
4094 then raise
(Failure
"value too large")
4098 let string_with_suffix_of_int n =
4103 if n land ((1 lsl 30) - 1) = 0
4106 if n land ((1 lsl 20) - 1) = 0
4109 if n land ((1 lsl 10) - 1) = 0
4116 let h = n mod 1000 in
4119 then string_of_int
h ^
s
4121 let s = Printf.sprintf
"_%03d%s" h s in
4128 let defghyllscroll = (40, 8, 32);;
4129 let ghyllscroll_of_string s =
4130 let (n, a, b) as nab
=
4133 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4135 if n <= a || n <= b || a >= b
4136 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4140 let ghyllscroll_to_string ((n, a, b) as nab
) =
4141 if nab
= defghyllscroll
4143 else Printf.sprintf
"%d,%d,%d" n a b;
4146 let describe_location () =
4147 let fn = page_of_y state.y in
4148 let ln = page_of_y (state.y + state.winh
- state.hscrollh - 1) in
4149 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4153 else (100. *. (float state.y /. float maxy))
4157 Printf.sprintf
"page %d of %d [%.2f%%]"
4158 (fn+1) state.pagecount
percent
4161 "pages %d-%d of %d [%.2f%%]"
4162 (fn+1) (ln+1) state.pagecount
percent
4165 let setpresentationmode v
=
4166 let n = page_of_y state.y in
4167 state.anchor <- (n, 0.0, 1.0);
4168 conf.presentation
<- v
;
4169 if conf.presentation
4171 if not
conf.scrollbarinpm
4172 then state.scrollw
<- 0;
4174 else state.scrollw
<- conf.scrollbw
;
4179 let btos b = if b then "\xe2\x88\x9a" else "" in
4180 let showextended = ref false in
4181 let leave mode
= function
4182 | Confirm
-> state.mode
<- mode
4183 | Cancel
-> state.mode
<- mode
in
4186 val mutable m_first_time
= true
4187 val mutable m_l
= []
4188 val mutable m_a
= [||]
4189 val mutable m_prev_uioh
= nouioh
4190 val mutable m_prev_mode
= View
4192 inherit lvsourcebase
4194 method reset prev_mode prev_uioh
=
4195 m_a
<- Array.of_list
(List.rev m_l
);
4197 m_prev_mode
<- prev_mode
;
4198 m_prev_uioh
<- prev_uioh
;
4202 if n >= Array.length m_a
4206 | _, _, _, Action
_ -> m_active
<- n
4210 m_first_time
<- false;
4213 method int name get
set =
4215 (name
, `
int get
, 1, Action
(
4218 try set (int_of_string
s)
4220 state.text <- Printf.sprintf
"bad integer `%s': %s"
4224 let te = name ^
": ", "", None
, intentry, ondone, true in
4225 state.mode
<- Textentry
(te, leave m_prev_mode
);
4229 method int_with_suffix name get
set =
4231 (name
, `intws get
, 1, Action
(
4234 try set (int_of_string_with_suffix s)
4236 state.text <- Printf.sprintf
"bad integer `%s': %s"
4241 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4243 state.mode
<- Textentry
(te, leave m_prev_mode
);
4247 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4249 (name
, `
bool (btos, get
), offset
, Action
(
4256 method color name get
set =
4258 (name
, `color get
, 1, Action
(
4260 let invalid = (nan
, nan
, nan
) in
4263 try color_of_string s
4265 state.text <- Printf.sprintf
"bad color `%s': %s"
4272 let te = name ^
": ", "", None
, textentry, ondone, true in
4273 state.text <- color_to_string (get
());
4274 state.mode
<- Textentry
(te, leave m_prev_mode
);
4278 method string name get
set =
4280 (name
, `
string get
, 1, Action
(
4282 let ondone s = set s in
4283 let te = name ^
": ", "", None
, textentry, ondone, true in
4284 state.mode
<- Textentry
(te, leave m_prev_mode
);
4288 method colorspace name get
set =
4290 (name
, `
string get
, 1, Action
(
4293 let vals = [| "rgb"; "bgr"; "gray" |] in
4295 inherit lvsourcebase
4298 m_active
<- int_of_colorspace conf.colorspace
;
4301 method getitemcount
= Array.length
vals
4302 method getitem
n = (vals.(n), 0)
4303 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4304 ignore
(uioh
, first, pan
, qsearch);
4305 if not cancel
then set active;
4307 method hasaction
_ = true
4311 let modehash = findkeyhash conf "info" in
4312 coe (new listview ~
source ~trusted
:true ~
modehash)
4315 method fitmodel name get
set =
4317 (name
, `
string get
, 1, Action
(
4320 let vals = [| "fit width"; "proportional"; "fit page" |] in
4322 inherit lvsourcebase
4325 m_active
<- int_of_fitmodel conf.fitmodel
;
4328 method getitemcount
= Array.length
vals
4329 method getitem
n = (vals.(n), 0)
4330 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4331 ignore
(uioh
, first, pan
, qsearch);
4332 if not cancel
then set active;
4334 method hasaction
_ = true
4338 let modehash = findkeyhash conf "info" in
4339 coe (new listview ~
source ~trusted
:true ~
modehash)
4342 method caption
s offset
=
4343 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4345 method caption2
s f offset
=
4346 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4348 method getitemcount
= Array.length m_a
4351 let tostr = function
4352 | `
int f -> string_of_int
(f ())
4353 | `intws
f -> string_with_suffix_of_int (f ())
4355 | `color
f -> color_to_string (f ())
4356 | `
bool (btos, f) -> btos (f ())
4359 let name, t
, offset
, _ = m_a
.(n) in
4360 ((let s = tostr t
in
4361 if String.length
s > 0
4362 then Printf.sprintf
"%s\t%s" name s
4366 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4370 m_qsearch
<- qsearch;
4372 match m_a
.(active) with
4373 | _, _, _, Action
f -> f uioh
4385 method hasaction
n =
4387 | _, _, _, Action
_ -> true
4391 let rec fillsrc prevmode prevuioh
=
4392 let sep () = src#caption
"" 0 in
4393 let colorp name get
set =
4395 (fun () -> color_to_string (get
()))
4398 let c = color_of_string v in
4401 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4404 let oldmode = state.mode
in
4405 let birdseye = isbirdseye state.mode
in
4407 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4409 src#
bool "presentation mode"
4410 (fun () -> conf.presentation
)
4411 (fun v -> setpresentationmode v);
4413 src#
bool "ignore case in searches"
4414 (fun () -> conf.icase
)
4415 (fun v -> conf.icase
<- v);
4418 (fun () -> conf.preload)
4419 (fun v -> conf.preload <- v);
4421 src#
bool "highlight links"
4422 (fun () -> conf.hlinks
)
4423 (fun v -> conf.hlinks
<- v);
4425 src#
bool "under info"
4426 (fun () -> conf.underinfo
)
4427 (fun v -> conf.underinfo
<- v);
4429 src#
bool "persistent bookmarks"
4430 (fun () -> conf.savebmarks
)
4431 (fun v -> conf.savebmarks
<- v);
4433 src#fitmodel
"fit model"
4434 (fun () -> fitmodel_to_string conf.fitmodel
)
4435 (fun v -> reqlayout conf.angle
(fitmodel_of_int v));
4437 src#
bool "trim margins"
4438 (fun () -> conf.trimmargins
)
4439 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4441 src#
bool "persistent location"
4442 (fun () -> conf.jumpback
)
4443 (fun v -> conf.jumpback
<- v);
4446 src#
int "inter-page space"
4447 (fun () -> conf.interpagespace
)
4449 conf.interpagespace
<- n;
4450 docolumns conf.columns
;
4452 match state.layout with
4457 state.maxy <- calcheight ();
4458 let y = getpagey pageno in
4463 (fun () -> conf.pagebias
)
4464 (fun v -> conf.pagebias
<- v);
4466 src#
int "scroll step"
4467 (fun () -> conf.scrollstep
)
4468 (fun n -> conf.scrollstep
<- n);
4470 src#
int "horizontal scroll step"
4471 (fun () -> conf.hscrollstep
)
4472 (fun v -> conf.hscrollstep
<- v);
4474 src#
int "auto scroll step"
4476 match state.autoscroll
with
4478 | _ -> conf.autoscrollstep
)
4480 if state.autoscroll
<> None
4481 then state.autoscroll
<- Some
n;
4482 conf.autoscrollstep
<- n);
4485 (fun () -> truncate
(conf.zoom *. 100.))
4486 (fun v -> setzoom ((float v) /. 100.));
4489 (fun () -> conf.angle
)
4490 (fun v -> reqlayout v conf.fitmodel
);
4492 src#
int "scroll bar width"
4493 (fun () -> state.scrollw
)
4497 reshape state.winw
state.winh
;
4500 src#
int "scroll handle height"
4501 (fun () -> conf.scrollh
)
4502 (fun v -> conf.scrollh
<- v;);
4504 src#
int "thumbnail width"
4505 (fun () -> conf.thumbw
)
4507 conf.thumbw
<- min
4096 v;
4510 leavebirdseye beye
false;
4515 let mode = state.mode in
4516 src#
string "columns"
4518 match conf.columns
with
4520 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4521 | Csplit
(count
, _) -> "-" ^ string_of_int count
4524 let n, a, b = multicolumns_of_string v in
4525 setcolumns mode n a b);
4528 src#caption
"Presentation mode" 0;
4529 src#
bool "scrollbar visible"
4530 (fun () -> conf.scrollbarinpm
)
4532 if v != conf.scrollbarinpm
4534 conf.scrollbarinpm
<- v;
4535 if conf.presentation
4537 state.scrollw
<- if v then conf.scrollbw
else 0;
4538 reshape state.winw
state.winh
;
4544 src#caption
"Pixmap cache" 0;
4545 src#int_with_suffix
"size (advisory)"
4546 (fun () -> conf.memlimit
)
4547 (fun v -> conf.memlimit
<- v);
4550 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4551 (string_with_suffix_of_int state.memused
)
4552 (Hashtbl.length
state.tilemap
)) 1;
4555 src#caption
"Layout" 0;
4556 src#caption2
"Dimension"
4558 Printf.sprintf
"%dx%d (virtual %dx%d)"
4559 state.winw
state.winh
4564 src#caption2
"Position" (fun () ->
4565 Printf.sprintf
"%dx%d" state.x state.y
4568 src#caption2
"Position" (fun () -> describe_location ()) 1
4572 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4573 "Save these parameters as global defaults at exit"
4574 (fun () -> conf.bedefault
)
4575 (fun v -> conf.bedefault
<- v)
4579 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4580 src#
bool ~offset
:0 ~
btos "Extended parameters"
4581 (fun () -> !showextended)
4582 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4586 (fun () -> conf.checkers
)
4587 (fun v -> conf.checkers
<- v; setcheckers v);
4588 src#
bool "update cursor"
4589 (fun () -> conf.updatecurs
)
4590 (fun v -> conf.updatecurs
<- v);
4592 (fun () -> conf.verbose
)
4593 (fun v -> conf.verbose
<- v);
4594 src#
bool "invert colors"
4595 (fun () -> conf.invert
)
4596 (fun v -> conf.invert
<- v);
4598 (fun () -> conf.maxhfit
)
4599 (fun v -> conf.maxhfit
<- v);
4600 src#
bool "redirect stderr"
4601 (fun () -> conf.redirectstderr)
4602 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4603 src#
string "uri launcher"
4604 (fun () -> conf.urilauncher
)
4605 (fun v -> conf.urilauncher
<- v);
4606 src#
string "path launcher"
4607 (fun () -> conf.pathlauncher
)
4608 (fun v -> conf.pathlauncher
<- v);
4609 src#
string "tile size"
4610 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4613 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4614 conf.tilew
<- max
64 w;
4615 conf.tileh
<- max
64 h;
4618 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4621 src#
int "texture count"
4622 (fun () -> conf.texcount
)
4625 then conf.texcount
<- v
4626 else showtext '
!'
" Failed to set texture count please retry later"
4628 src#
int "slice height"
4629 (fun () -> conf.sliceheight
)
4631 conf.sliceheight
<- v;
4632 wcmd "sliceh %d" conf.sliceheight
;
4634 src#
int "anti-aliasing level"
4635 (fun () -> conf.aalevel
)
4637 conf.aalevel
<- bound v 0 8;
4638 state.anchor <- getanchor ();
4639 opendoc state.path
state.password
;
4641 src#
string "page scroll scaling factor"
4642 (fun () -> string_of_float
conf.pgscale)
4645 let s = float_of_string
v in
4648 state.text <- Printf.sprintf
4649 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4652 src#
int "ui font size"
4653 (fun () -> fstate.fontsize
)
4654 (fun v -> setfontsize (bound v 5 100));
4655 src#
int "hint font size"
4656 (fun () -> conf.hfsize
)
4657 (fun v -> conf.hfsize
<- bound v 5 100);
4658 colorp "background color"
4659 (fun () -> conf.bgcolor
)
4660 (fun v -> conf.bgcolor
<- v);
4661 src#
bool "crop hack"
4662 (fun () -> conf.crophack
)
4663 (fun v -> conf.crophack
<- v);
4664 src#
string "trim fuzz"
4665 (fun () -> irect_to_string conf.trimfuzz
)
4668 conf.trimfuzz
<- irect_of_string v;
4670 then settrim true conf.trimfuzz
;
4672 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4674 src#
string "throttle"
4676 match conf.maxwait
with
4677 | None
-> "show place holder if page is not ready"
4680 then "wait for page to fully render"
4682 "wait " ^ string_of_float
time
4683 ^
" seconds before showing placeholder"
4687 let f = float_of_string
v in
4689 then conf.maxwait
<- None
4690 else conf.maxwait
<- Some
f
4692 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4694 src#
string "ghyll scroll"
4696 match conf.ghyllscroll
with
4698 | Some nab
-> ghyllscroll_to_string nab
4703 if String.length
v = 0
4705 else Some
(ghyllscroll_of_string v)
4707 conf.ghyllscroll
<- gs
4709 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4711 src#
string "selection command"
4712 (fun () -> conf.selcmd
)
4713 (fun v -> conf.selcmd
<- v);
4714 src#
string "synctex command"
4715 (fun () -> conf.stcmd
)
4716 (fun v -> conf.stcmd
<- v);
4717 src#colorspace
"color space"
4718 (fun () -> colorspace_to_string conf.colorspace
)
4720 conf.colorspace
<- colorspace_of_int v;
4727 (fun () -> conf.usepbo
)
4728 (fun v -> conf.usepbo
<- v);
4729 src#
bool "mouse wheel scrolls pages"
4730 (fun () -> conf.wheelbypage
)
4731 (fun v -> conf.wheelbypage
<- v);
4735 src#caption
"Document" 0;
4736 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4737 src#caption2
"Pages"
4738 (fun () -> string_of_int
state.pagecount
) 1;
4739 src#caption2
"Dimensions"
4740 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4744 src#caption
"Trimmed margins" 0;
4745 src#caption2
"Dimensions"
4746 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4750 src#caption
"OpenGL" 0;
4751 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4752 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4755 src#caption
"Location" 0;
4756 if String.length
state.origin
> 0
4757 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4758 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4760 src#reset prevmode prevuioh
;
4764 let prevmode = state.mode
4765 and prevuioh
= state.uioh in
4766 fillsrc prevmode prevuioh
;
4767 let source = (src :> lvsource
) in
4768 let modehash = findkeyhash conf "info" in
4769 state.uioh <- coe (object (self)
4770 inherit listview ~
source ~trusted
:true ~
modehash as super
4771 val mutable m_prevmemused
= 0
4772 method infochanged
= function
4774 if m_prevmemused
!= state.memused
4776 m_prevmemused
<- state.memused
;
4777 G.postRedisplay "memusedchanged";
4779 | Pdim
-> G.postRedisplay "pdimchanged"
4780 | Docinfo
-> fillsrc prevmode prevuioh
4782 method key key mask
=
4783 if not
(Wsi.withctrl mask
)
4786 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4787 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4788 | _ -> super#
key key mask
4789 else super#
key key mask
4791 G.postRedisplay "info";
4797 inherit lvsourcebase
4798 method getitemcount
= Array.length
state.help
4800 let s, l, _ = state.help
.(n) in
4803 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4807 m_qsearch
<- qsearch;
4808 match state.help
.(active) with
4809 | _, _, Action
f -> Some
(f uioh)
4819 method hasaction
n =
4820 match state.help
.(n) with
4821 | _, _, Action
_ -> true
4828 let modehash = findkeyhash conf "help" in
4829 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4830 G.postRedisplay "help";
4835 let re = Str.regexp
"[\r\n]" in
4837 inherit lvsourcebase
4838 val mutable m_items
= [||]
4840 method getitemcount
= 1 + Array.length m_items
4845 else m_items
.(n-1), 0
4847 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4852 then Buffer.clear
state.errmsgs
;
4853 m_qsearch
<- qsearch;
4860 method hasaction
n =
4864 state.newerrmsgs
<- false;
4865 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4866 m_items
<- Array.of_list
l
4874 let source = (msgsource :> lvsource
) in
4875 let modehash = findkeyhash conf "listview" in
4876 state.uioh <- coe (object
4877 inherit listview ~
source ~trusted
:false ~
modehash as super
4880 then msgsource#reset
;
4883 G.postRedisplay "msgs";
4886 let quickbookmark ?title
() =
4887 match state.layout with
4893 let sec = Unix.gettimeofday
() in
4894 let tm = Unix.localtime
sec in
4895 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4899 (tm.Unix.tm_year
+ 1900)
4902 | Some
title -> title
4904 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4907 let setautoscrollspeed step goingdown
=
4908 let incr = max
1 ((abs step
) / 2) in
4909 let incr = if goingdown
then incr else -incr in
4910 let astep = step
+ incr in
4911 state.autoscroll
<- Some
astep;
4914 let gotounder = function
4915 | Ulinkgoto
(pageno, top) ->
4919 gotopage1 pageno top;
4925 | Uremote
(filename
, pageno) ->
4927 if Sys.file_exists filename
4930 let dir = Filename.dirname
state.path in
4931 let path = Filename.concat
dir filename
in
4932 if Sys.file_exists
path
4936 if String.length
path > 0
4938 let anchor = getanchor () in
4939 let ranchor = state.path, state.password
, anchor, state.origin
in
4941 state.anchor <- (pageno, 0.0, 0.0);
4942 state.ranchors
<- ranchor :: state.ranchors
;
4945 else showtext '
!'
("Could not find " ^ filename
)
4947 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4951 match conf.columns
with
4953 | _ -> state.x != 0 || conf.zoom > 1.0
4956 let panbound x = bound x (-state.w) (state.winw
- state.scrollw
);;
4958 let existsinrow pageno (columns
, coverA
, coverB
) p =
4959 let last = ((pageno - coverA
) mod columns
) + columns
in
4960 let rec any = function
4963 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4967 then (if l.pageno = last then false else any rest
)
4975 match state.layout with
4977 let pageno = page_of_y state.y in
4978 gotoghyll (getpagey (pageno+1))
4980 match conf.columns
with
4982 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4984 let y = clamp (pgscale state.winh
) in
4987 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4988 gotoghyll (getpagey pageno)
4989 | Cmulti
((c, _, _) as cl, _) ->
4990 if conf.presentation
4991 && (existsinrow l.pageno cl
4992 (fun l -> l.pageh
> l.pagey + l.pagevh))
4994 let y = clamp (pgscale state.winh
) in
4997 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4998 gotoghyll (getpagey pageno)
5000 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5002 let pagey, pageh
= getpageyh l.pageno in
5003 let pagey = pagey + pageh
* l.pagecol
in
5004 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5005 gotoghyll (pagey + pageh
+ ips)
5009 match state.layout with
5011 let pageno = page_of_y state.y in
5012 gotoghyll (getpagey (pageno-1))
5014 match conf.columns
with
5016 if conf.presentation
&& l.pagey != 0
5018 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5020 let pageno = max
0 (l.pageno-1) in
5021 gotoghyll (getpagey pageno)
5022 | Cmulti
((c, _, coverB
) as cl, _) ->
5023 if conf.presentation
&&
5024 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5026 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5029 if l.pageno = state.pagecount
- coverB
5033 let pageno = max
0 (l.pageno-decr) in
5034 gotoghyll (getpagey pageno)
5042 let pageno = max
0 (l.pageno-1) in
5043 let pagey, pageh
= getpageyh pageno in
5046 let pagey, pageh
= getpageyh l.pageno in
5047 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5052 let viewkeyboard key mask
=
5054 let mode = state.mode in
5055 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5058 G.postRedisplay "view:enttext"
5060 let ctrl = Wsi.withctrl mask
in
5062 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5068 | 0xff63 -> (* insert *)
5069 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5071 state.mode <- LinkNav
(Ltgendir
0);
5074 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5076 | 0xff1b | 113 -> (* escape / q *)
5077 begin match state.mstate
with
5079 state.mstate
<- Mnone
;
5080 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5081 G.postRedisplay "kill zoom rect";
5083 begin match state.mode with
5086 G.postRedisplay "esc leave linknav"
5088 match state.ranchors
with
5090 | (path, password
, anchor, origin
) :: rest
->
5091 state.ranchors
<- rest
;
5092 state.anchor <- anchor;
5093 state.origin
<- origin
;
5094 opendoc path password
5098 | 0xff08 -> (* backspace *)
5099 gotoghyll (getnav ~
-1)
5107 G.postRedisplay "dehighlight";
5109 | 47 | 63 -> (* / ? *)
5110 let ondone isforw
s =
5111 cbput state.hists
.pat
s;
5112 state.searchpattern
<- s;
5115 let s = String.create
1 in
5116 s.[0] <- Char.chr
key;
5117 enttext (s, "", Some
(onhist state.hists
.pat
),
5118 textentry, ondone (key = 47), true)
5120 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5121 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5122 setzoom (conf.zoom +. incr)
5124 | 43 | 0xffab -> (* + *)
5127 try int_of_string
s with exc
->
5128 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5134 state.text <- "page bias is now " ^ string_of_int
n;
5137 enttext ("page bias: ", "", None
, intentry, ondone, true)
5139 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5140 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5141 setzoom (max
0.01 (conf.zoom -. decr))
5143 | 45 | 0xffad -> (* - *)
5144 let ondone msg
= state.text <- msg
in
5146 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
5147 optentry state.mode, ondone, true
5150 | 48 when ctrl -> (* ctrl-0 *)
5155 if state.w <= state.winw
- state.scrollw
5163 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5165 match conf.columns
with
5166 | Csingle
_ | Cmulti
_ -> 1
5167 | Csplit
(n, _) -> n
5169 let h = state.winh
-
5170 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5172 let zoom = zoomforh
state.winw
h state.scrollw
cols in
5173 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5176 | 51 when ctrl -> (* ctrl-3 *)
5178 match conf.fitmodel
with
5179 | FitWidth
-> FitProportional
5180 | FitProportional
-> FitPage
5181 | FitPage
-> FitWidth
5183 state.text <- "fit model: " ^
fitmodel_to_string fm;
5184 reqlayout conf.angle
fm
5186 | 0xffc6 -> (* f9 *)
5189 | 57 when ctrl -> (* ctrl-9 *)
5192 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5193 when not
ctrl -> (* 0..9 *)
5196 try int_of_string
s with exc
->
5197 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5203 cbput state.hists
.pag
(string_of_int
n);
5204 gotopage1 (n + conf.pagebias
- 1) 0;
5207 let pageentry text key =
5208 match Char.unsafe_chr
key with
5209 | '
g'
-> TEdone
text
5210 | _ -> intentry text key
5212 let text = "x" in text.[0] <- Char.chr
key;
5213 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5216 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5217 reshape state.winw
state.winh
;
5220 conf.hlinks
<- not
conf.hlinks
;
5221 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5222 G.postRedisplay "toggle highlightlinks";
5225 state.glinks
<- true;
5226 let mode = state.mode in
5227 state.mode <- Textentry
(
5228 (":", "", None
, linknentry, linkndone gotounder, false),
5230 state.glinks
<- false;
5234 G.postRedisplay "view:linkent(F)"
5237 state.glinks
<- true;
5238 let mode = state.mode in
5239 state.mode <- Textentry
(
5241 ":", "", None
, linknentry, linkndone (fun under ->
5242 selstring (undertext under);
5246 state.glinks
<- false;
5250 G.postRedisplay "view:linkent"
5253 begin match state.autoscroll
with
5255 conf.autoscrollstep
<- step
;
5256 state.autoscroll
<- None
5258 if conf.autoscrollstep
= 0
5259 then state.autoscroll
<- Some
1
5260 else state.autoscroll
<- Some
conf.autoscrollstep
5263 | 112 when ctrl -> (* ctrl-p *)
5267 setpresentationmode (not
conf.presentation
);
5268 showtext ' '
("presentation mode " ^
5269 if conf.presentation
then "on" else "off");
5272 if List.mem
Wsi.Fullscreen
state.winstate
5273 then Wsi.reshape conf.cwinw
conf.cwinh
5274 else Wsi.fullscreen
()
5276 | 112 | 78 -> (* p|N *)
5277 search state.searchpattern
false
5279 | 110 | 0xffc0 -> (* n|F3 *)
5280 search state.searchpattern
true
5283 begin match state.layout with
5286 gotoghyll (getpagey l.pageno)
5292 | 0xff9f | 0xffff -> (* delete *)
5296 showtext ' '
(describe_location ());
5299 begin match state.layout with
5302 Wsi.reshape (l.pagew
+ state.scrollw
) l.pageh
;
5307 enterbookmarkmode ()
5309 | 104 | 0xffbe -> (* h|F1 *)
5315 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5320 match state.layout with
5322 if String.length
s > 0
5324 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5327 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5331 showtext ' '
"Quick bookmark added";
5334 begin match state.layout with
5336 let rect = getpdimrect
l.pagedimno
in
5340 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5341 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5343 (truncate
(rect.(1) -. rect.(0)),
5344 truncate
(rect.(3) -. rect.(0)))
5346 let w = truncate
((float w)*.conf.zoom)
5347 and h = truncate
((float h)*.conf.zoom) in
5350 state.anchor <- getanchor ();
5351 Wsi.reshape (w + state.scrollw
) (h + conf.interpagespace
)
5353 G.postRedisplay "z";
5358 | 60 | 62 -> (* < > *)
5359 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5361 | 91 | 93 -> (* [ ] *)
5363 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5365 G.postRedisplay "brightness";
5367 | 99 when state.mode = View
-> (* c *)
5369 match state.prevcolumns
with
5370 | None
-> (1, 0, 0), 1.0
5371 | Some
(columns
, z
) ->
5374 | Csplit
(c, _) -> -c, 0, 0
5375 | Cmulti
((c, a, b), _) -> c, a, b
5376 | Csingle
_ -> 1, 0, 0
5380 setcolumns View
c a b;
5383 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5384 setzoom state.prevzoom
5386 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5387 begin match state.autoscroll
with
5389 begin match state.mode with
5390 | Birdseye beye
-> upbirdseye 1 beye
5393 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5395 if not
(Wsi.withshift mask
) && conf.presentation
5397 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5401 setautoscrollspeed n false
5404 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5405 begin match state.autoscroll
with
5407 begin match state.mode with
5408 | Birdseye beye
-> downbirdseye 1 beye
5411 then gotoy_and_clear_text (clamp (state.winh
/2))
5413 if not
(Wsi.withshift mask
) && conf.presentation
5415 else gotoy_and_clear_text (clamp conf.scrollstep
)
5419 setautoscrollspeed n true
5422 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5423 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5429 else conf.hscrollstep
5431 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5432 state.x <- panbound (state.x + dx);
5433 gotoy_and_clear_text state.y
5436 G.postRedisplay "left/right"
5439 | 0xff55 | 0xff9a -> (* (kp) prior *)
5443 match state.layout with
5445 | l :: _ -> state.y - l.pagey
5447 clamp (pgscale (-state.winh
))
5451 | 0xff56 | 0xff9b -> (* (kp) next *)
5455 match List.rev
state.layout with
5457 | l :: _ -> getpagey l.pageno
5459 clamp (pgscale state.winh
)
5463 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5465 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5466 gotoghyll (clamp state.maxy)
5469 when Wsi.withalt mask
-> (* alt-(kp) right *)
5470 gotoghyll (getnav 1)
5472 when Wsi.withalt mask
-> (* alt-(kp) left *)
5473 gotoghyll (getnav ~
-1)
5478 | 118 when conf.debug
-> (* v *)
5481 match getopaque l.pageno with
5484 let x0, y0, x1, y1 = pagebbox opaque
in
5485 let a,b = float x0, float y0 in
5486 let c,d = float x1, float y0 in
5487 let e,f = float x1, float y1 in
5488 let h,j
= float x0, float y1 in
5489 let rect = (a,b,c,d,e,f,h,j
) in
5491 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5493 G.postRedisplay "v";
5496 vlog "huh? %s" (Wsi.keyname
key)
5499 let linknavkeyboard key mask
linknav =
5500 let getpage pageno =
5501 let rec loop = function
5503 | l :: _ when l.pageno = pageno -> Some
l
5504 | _ :: rest
-> loop rest
5505 in loop state.layout
5507 let doexact (pageno, n) =
5508 match getopaque pageno, getpage pageno with
5509 | Some opaque
, Some
l ->
5510 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5512 let under = getlink opaque
n in
5513 G.postRedisplay "link gotounder";
5519 | 0xff50 -> (* home *)
5520 Some
(findlink opaque LDfirst
), -1
5522 | 0xff57 -> (* end *)
5523 Some
(findlink opaque LDlast
), 1
5525 | 0xff51 -> (* left *)
5526 Some
(findlink opaque
(LDleft
n)), -1
5528 | 0xff53 -> (* right *)
5529 Some
(findlink opaque
(LDright
n)), 1
5531 | 0xff52 -> (* up *)
5532 Some
(findlink opaque
(LDup
n)), -1
5534 | 0xff54 -> (* down *)
5535 Some
(findlink opaque
(LDdown
n)), 1
5540 begin match findpwl
l.pageno dir with
5544 state.mode <- LinkNav
(Ltgendir
dir);
5545 let y, h = getpageyh pageno in
5548 then y + h - state.winh
5553 begin match getopaque pageno, getpage pageno with
5554 | Some opaque
, Some
_ ->
5556 let ld = if dir > 0 then LDfirst
else LDlast
in
5559 begin match link with
5561 showlinktype (getlink opaque
m);
5562 state.mode <- LinkNav
(Ltexact
(pageno, m));
5563 G.postRedisplay "linknav jpage";
5570 begin match opt with
5571 | Some Lnotfound
-> pwl l dir;
5572 | Some
(Lfound
m) ->
5576 let _, y0, _, y1 = getlinkrect opaque
m in
5578 then gotopage1 l.pageno y0
5580 let d = fstate.fontsize
+ 1 in
5581 if y1 - l.pagey > l.pagevh - d
5582 then gotopage1 l.pageno (y1 - state.winh
- state.hscrollh + d)
5583 else G.postRedisplay "linknav";
5585 showlinktype (getlink opaque
m);
5586 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5589 | None
-> viewkeyboard key mask
5591 | _ -> viewkeyboard key mask
5596 G.postRedisplay "leave linknav"
5600 | Ltgendir
_ -> viewkeyboard key mask
5601 | Ltexact exact
-> doexact exact
5604 let keyboard key mask
=
5605 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5606 then wcmd "interrupt"
5607 else state.uioh <- state.uioh#
key key mask
5610 let birdseyekeyboard key mask
5611 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5613 match conf.columns
with
5615 | Cmulti
((c, _, _), _) -> c
5616 | Csplit
_ -> failwith
"bird's eye split mode"
5618 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5620 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5621 let y, h = getpageyh pageno in
5622 let top = (state.winh
- h) / 2 in
5623 gotoy (max
0 (y - top))
5624 | 0xff0d (* enter *)
5625 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5626 | 0xff1b -> leavebirdseye beye
true (* escape *)
5627 | 0xff52 -> upbirdseye incr beye
(* up *)
5628 | 0xff54 -> downbirdseye incr beye
(* down *)
5629 | 0xff51 -> upbirdseye 1 beye
(* left *)
5630 | 0xff53 -> downbirdseye 1 beye
(* right *)
5632 | 0xff55 -> (* prior *)
5633 begin match state.layout with
5637 state.mode <- Birdseye
(
5638 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5640 gotopage1 l.pageno 0;
5643 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5645 | [] -> gotoy (clamp (-state.winh
))
5647 state.mode <- Birdseye
(
5648 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5650 gotopage1 l.pageno 0
5653 | [] -> gotoy (clamp (-state.winh
))
5656 | 0xff56 -> (* next *)
5657 begin match List.rev
state.layout with
5659 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5660 begin match layout with
5662 let incr = l.pageh
- l.pagevh in
5667 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5669 G.postRedisplay "birdseye pagedown";
5671 else gotoy (clamp (incr + conf.interpagespace
*2));
5675 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5676 gotopage1 l.pageno 0;
5679 | [] -> gotoy (clamp state.winh
)
5682 | 0xff50 -> (* home *)
5683 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5686 | 0xff57 -> (* end *)
5687 let pageno = state.pagecount
- 1 in
5688 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5689 if not
(pagevisible state.layout pageno)
5692 match List.rev
state.pdims
with
5694 | (_, _, h, _) :: _ -> h
5696 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5697 else G.postRedisplay "birdseye end";
5698 | _ -> viewkeyboard key mask
5703 match state.mode with
5704 | Textentry
_ -> scalecolor 0.4
5706 | View
-> scalecolor 1.0
5707 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5708 if l.pageno = hooverpageno
5711 if l.pageno = pageno
5719 let postdrawpage l linkindexbase
=
5720 match getopaque l.pageno with
5722 if tileready l l.pagex
l.pagey
5724 let x = l.pagedispx - l.pagex
5725 and y = l.pagedispy - l.pagey in
5727 match conf.columns
with
5728 | Csingle
_ | Cmulti
_ ->
5729 (if conf.hlinks
then 1 else 0)
5731 && not
(isbirdseye state.mode) then 2 else 0)
5735 match state.mode with
5736 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5739 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5744 let scrollindicator () =
5745 let sbw, ph
, sh = state.uioh#
scrollph in
5746 let sbh, pw, sw = state.uioh#scrollpw
in
5748 GlDraw.color (0.64, 0.64, 0.64);
5750 (float (state.winw
- sbw), 0.)
5751 (float state.winw
, float state.winh
)
5754 (0., float (state.winh
- sbh))
5755 (float (state.winw
- state.scrollw
- 1), float state.winh
)
5757 GlDraw.color (0.0, 0.0, 0.0);
5760 (float (state.winw
- sbw), ph
)
5761 (float state.winw
, ph
+. sh)
5764 (pw, float (state.winh
- sbh))
5765 (pw +. sw, float state.winh
)
5770 match state.mstate
with
5771 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5774 | Msel
((x0, y0), (x1, y1)) ->
5775 let rec loop = function
5777 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5778 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5779 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5780 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5782 match getopaque l.pageno with
5784 let x0, y0 = pagetranslatepoint l x0 y0 in
5785 let x1, y1 = pagetranslatepoint l x1 y1 in
5786 seltext opaque
(x0, y0, x1, y1);
5794 let showrects rects
=
5796 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5797 GlDraw.polygon_mode `both `fill
;
5798 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5800 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5802 if l.pageno = pageno
5804 let dx = float (l.pagedispx - l.pagex
) in
5805 let dy = float (l.pagedispy - l.pagey) in
5806 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5807 GlDraw.begins `quads
;
5809 GlDraw.vertex2
(x0+.dx, y0+.dy);
5810 GlDraw.vertex2
(x1+.dx, y1+.dy);
5811 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5812 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5823 GlClear.color (scalecolor2 conf.bgcolor
);
5824 GlClear.clear
[`
color];
5825 List.iter
drawpage state.layout;
5827 match state.mode with
5828 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5829 begin match getopaque pageno with
5831 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5838 | None
-> state.rects
5843 let rec postloop linkindexbase
= function
5845 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5846 postloop linkindexbase rest
5850 postloop 0 state.layout;
5852 begin match state.mstate
with
5853 | Mzoomrect
((x0, y0), (x1, y1)) ->
5855 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5856 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5857 GlDraw.rect (float x0, float y0)
5858 (float x1, float y1);
5867 let zoomrect x y x1 y1 =
5870 and y0 = min
y y1 in
5871 gotoy (state.y + y0);
5872 state.anchor <- getanchor ();
5873 let zoom = (float state.w) /. float (x1 - x0) in
5875 match conf.fitmodel
, conf.columns
with
5876 | FitPage
, Csplit
_ ->
5877 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5880 if state.w < state.winw
- state.scrollw
5881 then (state.winw
- state.scrollw
- state.w) / 2
5884 state.x <- (state.x + margin) - x0;
5886 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5887 state.mstate
<- Mnone
;
5891 let winw = state.winw - state.scrollw
- 1 in
5892 let s = float x /. float winw in
5893 let destx = truncate
(float (state.w + winw) *. s) in
5894 state.x <- winw - destx;
5895 gotoy_and_clear_text state.y;
5896 state.mstate
<- Mscrollx
;
5900 let s = float y /. float state.winh
in
5901 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5902 gotoy_and_clear_text desty;
5903 state.mstate
<- Mscrolly
;
5906 let viewmouse button down
x y mask
=
5908 | n when (n == 4 || n == 5) && not down
->
5909 if Wsi.withctrl mask
5911 match state.mstate
with
5912 | Mzoom
(oldn
, i
) ->
5920 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5922 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5924 let zoom = conf.zoom -. incr in
5926 state.mstate
<- Mzoom
(n, 0);
5928 state.mstate
<- Mzoom
(n, i
+1);
5930 else state.mstate
<- Mzoom
(n, 0)
5932 | _ -> state.mstate
<- Mzoom
(n, 0)
5935 match state.autoscroll
with
5936 | Some step
-> setautoscrollspeed step
(n=4)
5938 if conf.wheelbypage
|| conf.presentation
5947 then -conf.scrollstep
5948 else conf.scrollstep
5950 let incr = incr * 2 in
5951 let y = clamp incr in
5952 gotoy_and_clear_text y
5955 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5957 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
5958 gotoy_and_clear_text state.y
5960 | 1 when Wsi.withshift mask
->
5961 state.mstate
<- Mnone
;
5964 match unproject x y with
5965 | Some
(pageno, ux
, uy
) ->
5966 let cmd = Printf.sprintf
5968 conf.stcmd
state.path pageno ux uy
5974 | 1 when Wsi.withctrl mask
->
5977 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5978 state.mstate
<- Mpan
(x, y)
5981 state.mstate
<- Mnone
5986 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5988 state.mstate
<- Mzoomrect
(p, p)
5991 match state.mstate
with
5992 | Mzoomrect
((x0, y0), _) ->
5993 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5994 then zoomrect x0 y0 x y
5996 state.mstate
<- Mnone
;
5997 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5998 G.postRedisplay "kill accidental zoom rect";
6001 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6002 state.mstate
<- Mnone
6005 | 1 when x > state.winw - state.scrollw
->
6008 let _, position, sh = state.uioh#
scrollph in
6009 if y > truncate
position && y < truncate
(position +. sh)
6010 then state.mstate
<- Mscrolly
6013 state.mstate
<- Mnone
6015 | 1 when y > state.winh
- state.hscrollh ->
6018 let _, position, sw = state.uioh#scrollpw
in
6019 if x > truncate
position && x < truncate
(position +. sw)
6020 then state.mstate
<- Mscrollx
6023 state.mstate
<- Mnone
6026 let dest = if down
then getunder x y else Unone
in
6027 begin match dest with
6031 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6034 | Unone
when down
->
6035 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6036 state.mstate
<- Mpan
(x, y);
6038 | Unone
| Utext
_ ->
6041 if conf.angle
mod 360 = 0
6043 state.mstate
<- Msel
((x, y), (x, y));
6044 G.postRedisplay "mouse select";
6048 match state.mstate
with
6051 | Mzoom
_ | Mscrollx
| Mscrolly
->
6052 state.mstate
<- Mnone
6054 | Mzoomrect
((x0, y0), _) ->
6058 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6059 state.mstate
<- Mnone
6061 | Msel
((x0, y0), (x1, y1)) ->
6062 let rec loop = function
6066 let a0 = l.pagedispy in
6067 let a1 = a0 + l.pagevh in
6068 let b0 = l.pagedispx in
6069 let b1 = b0 + l.pagevw in
6070 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6071 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6075 match getopaque l.pageno with
6078 match Ne.pipe () with
6082 "can not create sel pipe: %s"
6085 let doclose what fd
=
6086 Ne.clo fd
(fun msg
->
6087 dolog
"%s close failed: %s" what msg
)
6090 popen conf.selcmd
[r, 0; w, -1];
6093 G.postRedisplay "copysel";
6095 dolog
"can not execute %S: %s"
6096 conf.selcmd
(exntos exn
);
6104 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6105 state.mstate
<- Mnone
;
6112 let birdseyemouse button down
x y mask
6113 (conf, leftx
, _, hooverpageno
, anchor) =
6116 let rec loop = function
6119 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6120 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6122 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6128 | _ -> viewmouse button down
x y mask
6131 let mouse button down
x y mask
=
6132 state.uioh <- state.uioh#button button down
x y mask
;
6136 state.uioh <- state.uioh#
motion x y
6140 state.uioh <- state.uioh#
pmotion x y;
6146 method key key mask
=
6147 begin match state.mode with
6148 | Textentry
textentry -> textentrykeyboard key mask
textentry
6149 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6150 | View
-> viewkeyboard key mask
6151 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6155 method button button bstate
x y mask
=
6156 begin match state.mode with
6158 | View
-> viewmouse button bstate
x y mask
6159 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6165 begin match state.mode with
6167 | View
| Birdseye
_ | LinkNav
_ ->
6168 match state.mstate
with
6169 | Mzoom
_ | Mnone
-> ()
6174 state.mstate
<- Mpan
(x, y);
6176 then state.x <- panbound (state.x + dx);
6178 gotoy_and_clear_text y
6181 state.mstate
<- Msel
(a, (x, y));
6182 G.postRedisplay "motion select";
6185 let y = min
state.winh
(max
0 y) in
6189 let x = min
state.winw (max
0 x) in
6192 | Mzoomrect
(p0
, _) ->
6193 state.mstate
<- Mzoomrect
(p0
, (x, y));
6194 G.postRedisplay "motion zoomrect";
6198 method pmotion x y =
6199 begin match state.mode with
6200 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6201 let rec loop = function
6203 if hooverpageno
!= -1
6205 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6206 G.postRedisplay "pmotion birdseye no hoover";
6209 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6210 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6212 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6213 G.postRedisplay "pmotion birdseye hoover";
6223 match state.mstate
with
6224 | Mnone
-> updateunder x y
6225 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6230 method infochanged
_ = ()
6233 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6236 then 0.0, float state.winh
6237 else scrollph state.y maxy
6242 let winw = state.winw - state.scrollw
in
6243 let fwinw = float winw in
6245 let sw = fwinw /. float state.w in
6246 let sw = fwinw *. sw in
6247 max
sw (float conf.scrollh
)
6250 let maxx = state.w + winw in
6251 let x = winw - state.x in
6252 let percent = float x /. float maxx in
6253 (fwinw -. sw) *. percent
6255 state.hscrollh, position, sw
6259 match state.mode with
6260 | LinkNav
_ -> "links"
6261 | Textentry
_ -> "textentry"
6262 | Birdseye
_ -> "birdseye"
6265 findkeyhash conf modename
6267 method eformsgs
= true
6274 let fontpath = ref "";;
6277 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6280 let l = String.length
s in
6281 let b = Buffer.create
l in
6287 try Sys.getenv
"HOME"
6290 ("Can not determine home directory location: " ^ exntos exn
);
6294 let modifier_of_string = function
6295 | "alt" -> Wsi.altmask
6296 | "shift" -> Wsi.shiftmask
6297 | "ctrl" | "control" -> Wsi.ctrlmask
6298 | "meta" -> Wsi.metamask
6303 let r = Str.regexp
"-" in
6305 let elems = Str.full_split
r s in
6308 let m1 = modifier_of_string s in
6310 then (Wsi.namekey
s, m)
6313 | Str.Delim
s when n land 1 = 0 -> g s
6315 | Str.Delim
_ -> (k
, m)
6317 let rec loop n k
m = function
6320 let k, m = f n k m x in
6326 let keys_of_string =
6327 let r = Str.regexp
"[ \t]" in
6329 let elems = Str.split
r s in
6330 List.map
key_of_string elems
6333 let copykeyhashes c =
6334 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6337 let config_of c attrs
=
6341 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6342 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6343 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6344 | "preload" -> { c with preload = bool_of_string
v }
6345 | "page-bias" -> { c with pagebias
= int_of_string
v }
6346 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6347 | "horizontal-scroll-step" ->
6348 { c with hscrollstep
= max
(int_of_string
v) 1 }
6349 | "auto-scroll-step" ->
6350 { c with autoscrollstep
= max
0 (int_of_string
v) }
6351 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6352 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6355 match String.lowercase
v with
6356 | "true" -> Some infinity
6358 | f -> Some
(float_of_string
f)
6360 { c with maxwait
= mw}
6361 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6362 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6363 | "vertical-margin" ->
6364 { c with interpagespace
= max
0 (int_of_string
v) }
6366 let zoom = float_of_string
v /. 100. in
6367 let zoom = max
zoom 0.0 in
6368 { c with zoom = zoom }
6369 | "presentation" -> { c with presentation
= bool_of_string
v }
6370 | "rotation-angle" -> { c with angle
= int_of_string
v }
6371 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6372 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6373 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6374 | "proportional-display" ->
6377 then FitProportional
6380 { c with fitmodel
= fm }
6381 | "fit-model" -> { c with fitmodel
= fitmodel_of_string v }
6382 | "pixmap-cache-size" ->
6383 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6384 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6385 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6386 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6387 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6388 | "background-color" -> { c with bgcolor
= color_of_string v }
6389 | "scrollbar-in-presentation" ->
6390 { c with scrollbarinpm
= bool_of_string
v }
6391 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6392 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6393 | "mupdf-store-size" ->
6394 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6395 | "checkers" -> { c with checkers
= bool_of_string
v }
6396 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6397 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6398 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6399 | "uri-launcher" -> { c with urilauncher
= unent v }
6400 | "path-launcher" -> { c with pathlauncher
= unent v }
6401 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6402 | "invert-colors" -> { c with invert
= bool_of_string
v }
6403 | "brightness" -> { c with colorscale
= float_of_string
v }
6404 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6406 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6408 let (n, _, _) as nab
= multicolumns_of_string v in
6410 then { c with columns
= Csplit
(-n, [||]) }
6411 else { c with columns
= Cmulti
(nab
, [||]) }
6412 | "birds-eye-columns" ->
6413 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6414 | "selection-command" -> { c with selcmd
= unent v }
6415 | "synctex-command" -> { c with stcmd
= unent v }
6416 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6417 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6418 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6419 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6420 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6423 prerr_endline
("Error processing attribute (`" ^
6424 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6427 let rec fold c = function
6430 let c = apply c k v in
6433 fold { c with keyhashes
= copykeyhashes c } attrs
;
6436 let fromstring f pos
n v d =
6439 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6440 n v pos
(exntos exn
)
6445 let bookmark_of attrs
=
6446 let rec fold title page
rely visy
= function
6447 | ("title", v) :: rest
-> fold v page
rely visy rest
6448 | ("page", v) :: rest
-> fold title v rely visy rest
6449 | ("rely", v) :: rest
-> fold title page
v visy rest
6450 | ("visy", v) :: rest
-> fold title page
rely v rest
6451 | _ :: rest
-> fold title page
rely visy rest
6452 | [] -> title, page
, rely, visy
6454 fold "invalid" "0" "0" "0" attrs
6458 let rec fold path page
rely pan visy
= function
6459 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6460 | ("page", v) :: rest
-> fold path v rely pan visy rest
6461 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6462 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6463 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6464 | _ :: rest
-> fold path page
rely pan visy rest
6465 | [] -> path, page
, rely, pan
, visy
6467 fold "" "0" "0" "0" "0" attrs
6471 let rec fold rs ls
= function
6472 | ("out", v) :: rest
-> fold v ls rest
6473 | ("in", v) :: rest
-> fold rs
v rest
6474 | _ :: rest
-> fold ls rs rest
6480 let setconf dst
src =
6481 dst
.scrollbw
<- src.scrollbw
;
6482 dst
.scrollh
<- src.scrollh
;
6483 dst
.icase
<- src.icase
;
6484 dst
.preload <- src.preload;
6485 dst
.pagebias
<- src.pagebias
;
6486 dst
.verbose
<- src.verbose
;
6487 dst
.scrollstep
<- src.scrollstep
;
6488 dst
.maxhfit
<- src.maxhfit
;
6489 dst
.crophack
<- src.crophack
;
6490 dst
.autoscrollstep
<- src.autoscrollstep
;
6491 dst
.maxwait
<- src.maxwait
;
6492 dst
.hlinks
<- src.hlinks
;
6493 dst
.underinfo
<- src.underinfo
;
6494 dst
.interpagespace
<- src.interpagespace
;
6495 dst
.zoom <- src.zoom;
6496 dst
.presentation
<- src.presentation
;
6497 dst
.angle
<- src.angle
;
6498 dst
.cwinw
<- src.cwinw
;
6499 dst
.cwinh
<- src.cwinh
;
6500 dst
.savebmarks
<- src.savebmarks
;
6501 dst
.memlimit
<- src.memlimit
;
6502 dst
.fitmodel
<- src.fitmodel
;
6503 dst
.texcount
<- src.texcount
;
6504 dst
.sliceheight
<- src.sliceheight
;
6505 dst
.thumbw
<- src.thumbw
;
6506 dst
.jumpback
<- src.jumpback
;
6507 dst
.bgcolor
<- src.bgcolor
;
6508 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6509 dst
.tilew
<- src.tilew
;
6510 dst
.tileh
<- src.tileh
;
6511 dst
.mustoresize
<- src.mustoresize
;
6512 dst
.checkers
<- src.checkers
;
6513 dst
.aalevel
<- src.aalevel
;
6514 dst
.trimmargins
<- src.trimmargins
;
6515 dst
.trimfuzz
<- src.trimfuzz
;
6516 dst
.urilauncher
<- src.urilauncher
;
6517 dst
.colorspace
<- src.colorspace
;
6518 dst
.invert
<- src.invert
;
6519 dst
.colorscale
<- src.colorscale
;
6520 dst
.redirectstderr <- src.redirectstderr;
6521 dst
.ghyllscroll
<- src.ghyllscroll
;
6522 dst
.columns
<- src.columns
;
6523 dst
.beyecolumns
<- src.beyecolumns
;
6524 dst
.selcmd
<- src.selcmd
;
6525 dst
.updatecurs
<- src.updatecurs
;
6526 dst
.pathlauncher
<- src.pathlauncher
;
6527 dst
.keyhashes
<- copykeyhashes src;
6528 dst
.hfsize
<- src.hfsize
;
6529 dst
.hscrollstep
<- src.hscrollstep
;
6530 dst
.pgscale <- src.pgscale;
6531 dst
.usepbo
<- src.usepbo
;
6532 dst
.wheelbypage
<- src.wheelbypage
;
6533 dst
.stcmd
<- src.stcmd
;
6537 let h = Hashtbl.create
10 in
6538 let dc = { defconf with angle
= defconf.angle
} in
6539 let rec toplevel v t spos
_ =
6541 | Vdata
| Vcdata
| Vend
-> v
6542 | Vopen
("llppconfig", _, closed
) ->
6545 else { v with f = llppconfig
}
6547 error
"unexpected subelement at top level" s spos
6548 | Vclose
_ -> error
"unexpected close at top level" s spos
6550 and llppconfig
v t spos
_ =
6552 | Vdata
| Vcdata
-> v
6553 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6554 | Vopen
("defaults", attrs
, closed
) ->
6555 let c = config_of dc attrs
in
6559 else { v with f = defaults
}
6561 | Vopen
("ui-font", attrs
, closed
) ->
6562 let rec getsize size
= function
6564 | ("size", v) :: rest
->
6566 fromstring int_of_string spos
"size" v fstate.fontsize
in
6568 | l -> getsize size l
6570 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6573 else { v with f = uifont
(Buffer.create
10) }
6575 | Vopen
("doc", attrs
, closed
) ->
6576 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6577 let path = unent pathent
6578 and pageno = fromstring int_of_string spos
"page" spage
0
6579 and rely = fromstring float_of_string spos
"rely" srely
0.0
6580 and pan
= fromstring int_of_string spos
"pan" span
0
6581 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6582 let c = config_of dc attrs
in
6583 let anchor = (pageno, rely, visy
) in
6585 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6586 else { v with f = doc
path pan
anchor c [] }
6589 error
"unexpected subelement in llppconfig" s spos
6591 | Vclose
"llppconfig" -> { v with f = toplevel }
6592 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6594 and defaults
v t spos
_ =
6596 | Vdata
| Vcdata
-> v
6597 | Vend
-> error
"unexpected end of input in defaults" s spos
6598 | Vopen
("keymap", attrs
, closed
) ->
6600 try List.assoc
"mode" attrs
6601 with Not_found
-> "global" in
6606 let h = findkeyhash dc modename in
6607 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6610 { v with f = pkeymap
ret KeyMap.empty }
6612 | Vopen
(_, _, _) ->
6613 error
"unexpected subelement in defaults" s spos
6615 | Vclose
"defaults" ->
6616 { v with f = llppconfig
}
6618 | Vclose
_ -> error
"unexpected close in defaults" s spos
6620 and uifont
b v t spos
epos =
6623 Buffer.add_substring
b s spos
(epos - spos
);
6625 | Vopen
(_, _, _) ->
6626 error
"unexpected subelement in ui-font" s spos
6627 | Vclose
"ui-font" ->
6628 if String.length
!fontpath = 0
6629 then fontpath := Buffer.contents
b;
6630 { v with f = llppconfig
}
6631 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6632 | Vend
-> error
"unexpected end of input in ui-font" s spos
6634 and doc
path pan
anchor c bookmarks
v t spos
_ =
6636 | Vdata
| Vcdata
-> v
6637 | Vend
-> error
"unexpected end of input in doc" s spos
6638 | Vopen
("bookmarks", _, closed
) ->
6641 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6643 | Vopen
("keymap", attrs
, closed
) ->
6645 try List.assoc
"mode" attrs
6646 with Not_found
-> "global"
6652 let h = findkeyhash c modename in
6653 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6654 doc
path pan
anchor c bookmarks
6656 { v with f = pkeymap
ret KeyMap.empty }
6658 | Vopen
(_, _, _) ->
6659 error
"unexpected subelement in doc" s spos
6662 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6663 { v with f = llppconfig
}
6665 | Vclose
_ -> error
"unexpected close in doc" s spos
6667 and pkeymap
ret keymap
v t spos
_ =
6669 | Vdata
| Vcdata
-> v
6670 | Vend
-> error
"unexpected end of input in keymap" s spos
6671 | Vopen
("map", attrs
, closed
) ->
6672 let r, l = map_of attrs
in
6673 let kss = fromstring keys_of_string spos
"in" r [] in
6674 let lss = fromstring keys_of_string spos
"out" l [] in
6678 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6679 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6682 then { v with f = pkeymap
ret keymap }
6685 { v with f = skip
"map" f }
6688 error
"unexpected subelement in keymap" s spos
6690 | Vclose
"keymap" ->
6691 { v with f = ret keymap }
6693 | Vclose
_ -> error
"unexpected close in keymap" s spos
6695 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6697 | Vdata
| Vcdata
-> v
6698 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6699 | Vopen
("item", attrs
, closed
) ->
6700 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6701 let page = fromstring int_of_string spos
"page" spage
0
6702 and rely = fromstring float_of_string spos
"rely" srely
0.0
6703 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6705 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6708 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6711 { v with f = skip
"item" f }
6714 error
"unexpected subelement in bookmarks" s spos
6716 | Vclose
"bookmarks" ->
6717 { v with f = doc
path pan
anchor c bookmarks }
6719 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6721 and skip tag
f v t spos
_ =
6723 | Vdata
| Vcdata
-> v
6725 error
("unexpected end of input in skipped " ^ tag
) s spos
6726 | Vopen
(tag'
, _, closed
) ->
6730 let f'
() = { v with f = skip tag
f } in
6731 { v with f = skip tag'
f'
}
6735 else error
("unexpected close in skipped " ^ tag
) s spos
6738 parse
{ f = toplevel; accu = () } s;
6744 let len = in_channel_length ic
in
6745 let s = String.create
len in
6746 really_input ic
s 0 len;
6749 | Parse_error
(msg
, s, pos
) ->
6750 let subs = subs s pos
in
6751 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6752 failwith
("parse error: " ^
s)
6755 failwith
("config load error: " ^ exntos exn
)
6761 let dir = Filename.concat
home ".config" in
6762 if Sys.is_directory
dir then dir else home
6765 Filename.concat
dir "llpp.conf"
6768 let confpath = ref defconfpath;;
6771 if Sys.file_exists
!confpath
6774 (try Some
(open_in_bin
!confpath)
6777 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6788 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6797 f (Hashtbl.create
0, defconf)
6802 let pc, pb
, px, pa
=
6805 if String.length
state.origin
= 0
6809 Hashtbl.find h (Filename.basename
key)
6810 with Not_found
-> dc, [], 0, emptyanchor
6814 state.bookmarks <- pb
;
6816 state.scrollw
<- conf.scrollbw
;
6818 then state.anchor <- pa
;
6819 cbput state.hists
.nav pa
;
6825 let add_attrs bb always
dc c =
6828 then Printf.bprintf bb
"\n %s='%b'" s a
6831 then Printf.bprintf bb
"\n %s='%d'" s a
6834 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6837 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6840 then Printf.bprintf bb
"\n %s='%f'" s a
6844 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6848 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6852 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6856 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6862 | Some
(_N
, _A
, _B
) ->
6863 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6873 else string_of_float
f
6875 Printf.bprintf bb
"\n %s='%s'" s v
6880 | Cmulti
((n, a, b), _) when n > 1 ->
6881 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6882 | Csplit
(n, _) when n > 1 ->
6883 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6889 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6894 Printf.bprintf bb
"\n %s='%s'" s (fitmodel_to_string a)
6896 oi
"width" c.cwinw
dc.cwinw
;
6897 oi
"height" c.cwinh
dc.cwinh
;
6898 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6899 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6900 ob "case-insensitive-search" c.icase
dc.icase
;
6901 ob "preload" c.preload dc.preload;
6902 oi
"page-bias" c.pagebias
dc.pagebias
;
6903 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6904 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6905 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6906 ob "crop-hack" c.crophack
dc.crophack
;
6907 oW
"throttle" c.maxwait
dc.maxwait
;
6908 ob "highlight-links" c.hlinks
dc.hlinks
;
6909 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6910 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6911 oz
"zoom" c.zoom dc.zoom;
6912 ob "presentation" c.presentation
dc.presentation
;
6913 oi
"rotation-angle" c.angle
dc.angle
;
6914 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6915 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
6916 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6917 oi
"tex-count" c.texcount
dc.texcount
;
6918 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6919 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6920 ob "persistent-location" c.jumpback
dc.jumpback
;
6921 oc
"background-color" c.bgcolor
dc.bgcolor
;
6922 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6923 oi
"tile-width" c.tilew
dc.tilew
;
6924 oi
"tile-height" c.tileh
dc.tileh
;
6925 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6926 ob "checkers" c.checkers
dc.checkers
;
6927 oi
"aalevel" c.aalevel
dc.aalevel
;
6928 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6929 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6930 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6931 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6932 oC
"color-space" c.colorspace
dc.colorspace
;
6933 ob "invert-colors" c.invert
dc.invert
;
6934 oF
"brightness" c.colorscale
dc.colorscale
;
6935 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6936 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6937 oco
"columns" c.columns
dc.columns
;
6938 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6939 os
"selection-command" c.selcmd
dc.selcmd
;
6940 os
"synctex-command" c.stcmd
dc.stcmd
;
6941 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6942 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6943 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6944 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6945 ob "use-pbo" c.usepbo
dc.usepbo
;
6946 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6949 let keymapsbuf always
dc c =
6950 let bb = Buffer.create
16 in
6951 let rec loop = function
6953 | (modename, h) :: rest
->
6954 let dh = findkeyhash dc modename in
6955 if always
|| h <> dh
6957 if Hashtbl.length
h > 0
6959 if Buffer.length
bb > 0
6960 then Buffer.add_char
bb '
\n'
;
6961 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6962 Hashtbl.iter
(fun i
o ->
6963 let isdifferent = always
||
6965 let dO = Hashtbl.find dh i
in
6967 with Not_found
-> true
6972 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6973 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6974 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6975 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6976 Buffer.add_string
bb (Wsi.keyname
k);
6979 let rec loop = function
6981 | km
:: [] -> addkm km
6982 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6986 Buffer.add_string
bb "<map in='";
6990 Buffer.add_string
bb "' out='";
6992 Buffer.add_string
bb "'/>\n"
6995 Buffer.add_string
bb "' out='";
6997 Buffer.add_string
bb "'/>\n"
6999 | KMmulti
(ins, kms
) ->
7000 Buffer.add_char
bb ' '
;
7002 Buffer.add_string
bb "' out='";
7004 Buffer.add_string
bb "'/>\n"
7006 Buffer.add_string
bb "</keymap>";
7016 let uifontsize = fstate.fontsize
in
7017 let bb = Buffer.create
32768 in
7020 (fun (w, h, _) ws
->
7022 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, conf.cx
)
7023 | Wsi.MaxVert
-> (w, conf.cwinh
, conf.cx
)
7024 | Wsi.MaxHorz
-> (conf.cwinw
, h, conf.cx
)
7026 (state.winw, state.winh
, state.x) state.winstate
7031 let dc = if conf.bedefault
then conf else dc in
7032 Buffer.add_string
bb "<llppconfig>\n";
7034 if String.length
!fontpath > 0
7036 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7042 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7045 Buffer.add_string
bb "<defaults ";
7046 add_attrs bb true dc dc;
7047 let kb = keymapsbuf true dc dc in
7048 if Buffer.length
kb > 0
7050 Buffer.add_string
bb ">\n";
7051 Buffer.add_buffer
bb kb;
7052 Buffer.add_string
bb "\n</defaults>\n";
7054 else Buffer.add_string
bb "/>\n";
7056 let adddoc path pan
anchor c bookmarks =
7057 if bookmarks == [] && c = dc && anchor = emptyanchor
7060 Printf.bprintf
bb "<doc path='%s'"
7061 (enent
path 0 (String.length
path));
7063 if anchor <> emptyanchor
7065 let n, rely, visy
= anchor in
7066 Printf.bprintf
bb " page='%d'" n;
7069 Printf.bprintf
bb " rely='%f'" rely
7071 if abs_float visy
> 1e-6
7073 Printf.bprintf
bb " visy='%f'" visy
7078 then Printf.bprintf
bb " pan='%d'" pan
;
7080 add_attrs bb false dc c;
7081 let kb = keymapsbuf false dc c in
7083 begin match bookmarks with
7085 if Buffer.length
kb > 0
7087 Buffer.add_string
bb ">\n";
7088 Buffer.add_buffer
bb kb;
7089 Buffer.add_string
bb "\n</doc>\n";
7091 else Buffer.add_string
bb "/>\n"
7093 Buffer.add_string
bb ">\n<bookmarks>\n";
7094 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7096 "<item title='%s' page='%d'"
7097 (enent
title 0 (String.length
title))
7102 Printf.bprintf
bb " rely='%f'" rely
7104 if abs_float visy
> 1e-6
7106 Printf.bprintf
bb " visy='%f'" visy
7108 Buffer.add_string
bb "/>\n";
7110 Buffer.add_string
bb "</bookmarks>";
7111 if Buffer.length
kb > 0
7113 Buffer.add_string
bb "\n";
7114 Buffer.add_buffer
bb kb;
7116 Buffer.add_string
bb "\n</doc>\n";
7122 match state.mode with
7123 | Birdseye
(c, pan, _, _, _) ->
7125 match conf.columns
with
7126 | Cmulti
((c, _, _), _) -> Some
c
7130 match c.columns
with
7131 | Cmulti
(c, _) -> Cmulti
(c, [||])
7132 | Csingle
_ -> Csingle
[||]
7133 | Csplit
_ -> failwith
"quit from bird's eye while split"
7135 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7138 let basename = Filename.basename
7139 (if String.length
state.origin
= 0 then state.path else state.origin
)
7141 adddoc basename pan (getanchor ())
7143 let autoscrollstep =
7144 match state.autoscroll
with
7146 | None
-> conf.autoscrollstep
7148 match state.mode with
7149 | Birdseye
(bc
, _, _, _, _) ->
7152 presentation
= bc
.presentation
;
7153 interpagespace
= bc
.interpagespace
;
7154 maxwait
= bc
.maxwait
;
7155 autoscrollstep = autoscrollstep }
7156 | _ -> { conf with autoscrollstep = autoscrollstep }
7158 (if conf.savebmarks
then state.bookmarks else []);
7160 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7162 then adddoc path x anchor c bookmarks
7164 Buffer.add_string
bb "</llppconfig>\n";
7167 if load1 f && Buffer.length
bb > 0
7170 let tmp = !confpath ^
".tmp" in
7171 let oc = open_out_bin
tmp in
7172 Buffer.output_buffer
oc bb;
7174 Unix.rename
tmp !confpath;
7177 ("error while saving configuration: " ^ exntos exn
)
7181 let adderrmsg src msg
=
7182 Buffer.add_string
state.errmsgs msg
;
7183 state.newerrmsgs
<- true;
7187 let adderrfmt src fmt
=
7188 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7192 let cl = splitatspace cmds
in
7194 try Scanf.sscanf
s fmt
f
7196 adderrfmt "remote exec"
7197 "error processing '%S': %s\n" cmds
(exntos exn
)
7200 | "reload" :: [] -> reload ()
7201 | "goto" :: args :: [] ->
7202 scan args "%u %f %f"
7204 let cmd, _ = state.geomcmds
in
7205 if String.length
cmd = 0
7206 then gotopagexy pageno x y
7209 gotopagexy pageno x y;
7212 state.reprf
<- f state.reprf
7214 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7215 | "rect" :: args :: [] ->
7216 scan args "%u %u %f %f %f %f"
7217 (fun pageno color x0 y0 x1 y1 ->
7218 onpagerect pageno (fun w h ->
7219 let _,w1,h1
,_ = getpagedim pageno in
7220 let sw = float w1 /. w
7221 and sh = float h1
/. h in
7225 and y1s
= y1 *. sh in
7226 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7228 state.rects <- (pageno, color, rect) :: state.rects;
7229 G.postRedisplay "rect";
7232 | "activatewin" :: [] -> Wsi.activatewin
()
7233 | "quit" :: [] -> raise Quit
7235 adderrfmt "remote command"
7236 "error processing remote command: %S\n" cmds
;
7240 let scratch = String.create
80 in
7241 let buf = Buffer.create
80 in
7244 try Some
(Unix.read fd
scratch 0 80)
7246 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7247 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7250 match tempfr () with
7256 if Buffer.length
buf > 0
7258 let s = Buffer.contents
buf in
7268 let pos = String.index_from
scratch ppos '
\n'
in
7269 if pos >= n then -1 else pos
7270 with Not_found
-> -1
7274 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7275 let s = Buffer.contents
buf in
7281 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7287 let remoteopen path =
7288 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7290 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7295 let trimcachepath = ref "" in
7296 let rcmdpath = ref "" in
7299 [("-p", Arg.String
(fun s -> state.password
<- s),
7300 "<password> Set password");
7302 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7303 "<path> Set path to the user interface font");
7305 ("-c", Arg.String
(fun s -> Config.confpath := s),
7306 "<path> Set path to the configuration file");
7308 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7309 "<path> Set path to the trim cache file");
7311 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7312 "<named-destination> Set named destination");
7314 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7316 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7317 "<path> Set path to the remote commands source");
7319 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7320 "<original path> Set original path");
7322 ("-v", Arg.Unit
(fun () ->
7324 "%s\nconfiguration path: %s\n"
7328 exit
0), " Print version and exit");
7331 (fun s -> state.path <- s)
7332 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7334 if String.length
state.path = 0
7335 then (prerr_endline
"file name missing"; exit
1);
7337 if not
(Config.load ())
7338 then prerr_endline
"failed to load configuration";
7340 let globalkeyhash = findkeyhash conf "global" in
7341 let wsfd, winw, winh
= Wsi.init
(object
7343 if nogeomcmds state.geomcmds
|| platform == Posx
7346 GlClear.color (scalecolor2 conf.bgcolor
);
7347 GlClear.clear
[`
color];
7349 method display = display ()
7350 method reshape w h = reshape w h
7351 method mouse b d x y m = mouse b d x y m
7352 method motion x y = state.mpos
<- (x, y); motion x y
7353 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7355 let mascm = m land (
7356 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7358 match state.keystate
with
7360 let km = k, mascm in
7363 let modehash = state.uioh#
modehash in
7364 try Hashtbl.find modehash km
7366 try Hashtbl.find globalkeyhash km
7367 with Not_found
-> KMinsrt
(k, m)
7369 | KMinsrt
(k, m) -> keyboard k m
7370 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7371 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7373 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7374 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7375 state.keystate
<- KSnone
7376 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7377 state.keystate
<- KSinto
(keys
, insrt
)
7379 state.keystate
<- KSnone
7381 method enter
x y = state.mpos
<- (x, y); pmotion x y
7382 method leave = state.mpos
<- (-1, -1)
7383 method winstate wsl
=
7385 (function | Wsi.MaxVert
| Wsi.MaxHorz
| Wsi.Fullscreen
-> true) wsl
7386 then conf.cx
<- state.x;
7387 state.winstate
<- wsl
7388 method quit
= raise Quit
7389 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7394 List.exists
GlMisc.check_extension
7395 [ "GL_ARB_texture_rectangle"
7396 ; "GL_EXT_texture_recangle"
7397 ; "GL_NV_texture_rectangle" ]
7399 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7402 match Ne.pipe () with
7404 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7408 match Ne.pipe () with
7410 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7420 setcheckers conf.checkers
;
7424 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7425 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7426 !Config.fontpath, !trimcachepath,
7427 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7431 state.text <- "Opening " ^
(mbtoutf8
state.path);
7433 opendoc state.path state.password
;
7436 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7439 if String.length
!rcmdpath > 0
7440 then remoteopen !rcmdpath
7445 let rec loop deadline
=
7447 match state.errfd
with
7448 | None
-> [state.sr
; state.wsfd]
7449 | Some fd
-> [state.sr
; state.wsfd; fd
]
7454 | Some fd
-> fd
:: r
7458 state.redisplay
<- false;
7465 if deadline
= infinity
7467 else max
0.0 (deadline
-. now)
7472 try Unix.select
r [] [] timeout
7473 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7479 if state.ghyll
== noghyll
7481 match state.autoscroll
with
7482 | Some step
when step
!= 0 ->
7483 let y = state.y + step
in
7487 else if y >= state.maxy then 0 else y
7490 if state.mode = View
7491 then state.text <- "";
7494 else deadline
+. 0.01
7499 let rec checkfds = function
7501 | fd
:: rest
when fd
= state.sr
->
7502 let cmd = readcmd state.sr
in
7506 | fd
:: rest
when fd
= state.wsfd ->
7510 | fd
:: rest
when Some fd
= !optrfd ->
7511 begin match remote fd
with
7512 | None
-> optrfd := remoteopen !rcmdpath;
7513 | opt -> optrfd := opt
7518 let s = String.create
80 in
7519 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7520 if conf.redirectstderr
7522 Buffer.add_substring
state.errmsgs
s 0 n;
7523 state.newerrmsgs
<- true;
7524 state.redisplay
<- true;
7527 prerr_string
(String.sub
s 0 n);
7535 if deadline
= infinity
7539 match state.autoscroll
with
7540 | Some step
when step
!= 0 -> deadline1
7541 | _ -> if state.ghyll
== noghyll then infinity
else deadline1