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
315 ; mutable savebmarks
: bool
316 ; mutable fitmodel
: fitmodel
317 ; mutable trimmargins
: trimmargins
318 ; mutable trimfuzz
: irect
319 ; mutable memlimit
: memsize
320 ; mutable texcount
: texcount
321 ; mutable sliceheight
: sliceheight
322 ; mutable thumbw
: width
323 ; mutable jumpback
: bool
324 ; mutable bgcolor
: (float * float * float)
325 ; mutable bedefault
: bool
326 ; mutable scrollbarinpm
: bool
327 ; mutable tilew
: int
328 ; mutable tileh
: int
329 ; mutable mustoresize
: memsize
330 ; mutable checkers
: bool
331 ; mutable aalevel
: int
332 ; mutable urilauncher
: string
333 ; mutable pathlauncher
: string
334 ; mutable colorspace
: colorspace
335 ; mutable invert
: bool
336 ; mutable colorscale
: float
337 ; mutable redirectstderr
: bool
338 ; mutable ghyllscroll
: (int * int * int) option
339 ; mutable columns
: columns
340 ; mutable beyecolumns
: columncount
option
341 ; mutable selcmd
: string
342 ; mutable updatecurs
: bool
343 ; mutable keyhashes
: (string * keyhash
) list
344 ; mutable hfsize
: int
345 ; mutable pgscale
: float
346 ; mutable usepbo
: bool
347 ; mutable wheelbypage
: bool
348 ; mutable stcmd
: string
351 | Csingle
of singlecolumn
352 | Cmulti
of multicolumns
353 | Csplit
of splitcolumns
356 type anchor
= pageno
* top
* dtop
;;
358 type outline
= string * int * anchor
;;
360 type rect
= float * float * float * float * float * float * float * float;;
362 type tile
= opaque
* pixmapsize
* elapsed
363 and elapsed
= float;;
364 type pagemapkey
= pageno
* gen
;;
365 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
369 let emptyanchor = (0, 0.0, 0.0);;
371 type infochange
= | Memused
| Docinfo
| Pdim
;;
373 class type uioh
= object
374 method display
: unit
375 method key
: int -> int -> uioh
376 method button
: int -> bool -> int -> int -> int -> uioh
377 method motion
: int -> int -> uioh
378 method pmotion
: int -> int -> uioh
379 method infochanged
: infochange
-> unit
380 method scrollpw
: (int * float * float)
381 method scrollph
: (int * float * float)
382 method modehash
: keyhash
383 method eformsgs
: bool
387 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
388 | Textentry
of (textentry
* onleave
)
390 | LinkNav
of linktarget
391 and onleave
= leavetextentrystatus
-> unit
392 and leavetextentrystatus
= | Cancel
| Confirm
393 and helpitem
= string * int * action
396 | Action
of (uioh
-> uioh
)
398 | Ltexact
of (pageno
* int)
402 let isbirdseye = function Birdseye _
-> true | _
-> false;;
403 let istextentry = function Textentry _
-> true | _
-> false;;
407 | Loading
of (page
* gen
)
409 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
411 | Outlining
of outline list
414 let emptykeyhash = Hashtbl.create
0;;
415 let nouioh : uioh
= object (self
)
417 method key _ _
= self
418 method button _ _ _ _ _
= self
419 method motion _ _
= self
420 method pmotion _ _
= self
421 method infochanged _
= ()
422 method scrollpw
= (0, nan
, nan
)
423 method scrollph
= (0, nan
, nan
)
424 method modehash
= emptykeyhash
425 method eformsgs
= false
429 { mutable sr
: Unix.file_descr
430 ; mutable sw
: Unix.file_descr
431 ; mutable wsfd
: Unix.file_descr
432 ; mutable errfd
: Unix.file_descr
option
433 ; mutable stderr
: Unix.file_descr
434 ; mutable errmsgs
: Buffer.t
435 ; mutable newerrmsgs
: bool
439 ; mutable scrollw
: int
440 ; mutable hscrollh
: int
441 ; mutable anchor
: anchor
442 ; mutable ranchors
: (string * string * anchor
* string) list
444 ; mutable layout
: page list
445 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
446 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
447 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
448 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
449 ; mutable pagecount
: int
450 ; mutable currently
: currently
451 ; mutable mstate
: mstate
452 ; mutable searchpattern
: string
453 ; mutable rects
: (pageno
* recttype
* rect
) list
454 ; mutable rects1
: (pageno
* recttype
* rect
) list
455 ; mutable text
: string
456 ; mutable winstate
: Wsi.winstate list
457 ; mutable mode
: mode
458 ; mutable uioh
: uioh
459 ; mutable outlines
: outline array
460 ; mutable bookmarks
: outline list
461 ; mutable path
: string
462 ; mutable password
: string
463 ; mutable nameddest
: string
464 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
465 ; mutable memused
: memsize
467 ; mutable throttle
: (page list
* int * float) option
468 ; mutable autoscroll
: int option
469 ; mutable ghyll
: (int option -> unit)
470 ; mutable help
: helpitem array
471 ; mutable docinfo
: (int * string) list
472 ; mutable texid
: GlTex.texture_id
option
474 ; mutable prevzoom
: float
475 ; mutable progress
: float
476 ; mutable redisplay
: bool
477 ; mutable mpos
: mpos
478 ; mutable keystate
: keystate
479 ; mutable glinks
: bool
480 ; mutable prevcolumns
: (columns
* float) option
483 ; mutable reprf
: (unit -> unit)
484 ; mutable origin
: string
487 { pat
: string circbuf
488 ; pag
: string circbuf
489 ; nav
: anchor circbuf
490 ; sel
: string circbuf
512 ; presentation
= false
517 ; fitmodel
= FitProportional
518 ; trimmargins
= false
519 ; trimfuzz
= (0,0,0,0)
520 ; memlimit
= 32 lsl 20
525 ; bgcolor
= (0.5, 0.5, 0.5)
527 ; scrollbarinpm
= true
530 ; mustoresize
= 256 lsl 20
535 | Plinux
| Pfreebsd
| Pdragonflybsd
536 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
537 | Posx
-> "open \"%s\""
538 | Pcygwin
-> "cygstart \"%s\""
539 | Punknown
-> "echo %s")
540 ; pathlauncher
= "lp \"%s\""
543 | Plinux
| Pfreebsd
| Pdragonflybsd
544 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
551 ; redirectstderr
= false
553 ; columns
= Csingle
[||]
559 ; wheelbypage
= false
560 ; stcmd
= "echo SyncTex"
562 let mk n
= (n
, Hashtbl.create
1) in
576 let wtmode = ref false;;
578 let findkeyhash c name
=
579 try List.assoc name c
.keyhashes
580 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
583 let conf = { defconf with angle
= defconf.angle
};;
585 let pgscale h
= truncate
(float h
*. conf.pgscale);;
588 { mutable fontsize
: int
589 ; mutable wwidth
: float
590 ; mutable maxrows
: int
602 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
603 let len = String.length s
in
604 if colonpos >= 0 && colonpos + 3 < len
606 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
609 try String.rindex_from s
colonpos ' '
613 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
616 | "http" | "ftp" | "mailto" ->
618 try String.index_from s
colonpos ' '
619 with Not_found
-> len
621 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
629 if String.length
conf.urilauncher
= 0
630 then print_endline uri
632 let url = geturl uri
in
633 if String.length
url = 0
634 then print_endline uri
636 let re = Str.regexp
"%s" in
637 let command = Str.global_replace
re url conf.urilauncher
in
641 "failed to execute `%s': %s\n" command (exntos exn
);
647 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
648 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
652 let strings = version () :: "" :: Help.keys
in
655 let url = geturl s
in
656 if String.length
url > 0
657 then (s
, 0, Action
(fun u
-> gotouri url; u
))
658 else (s
, 0, Noaction
)
663 let firstgeomcmds = "", [];;
664 let noreprf () = ();;
671 ; stderr
= Unix.stderr
672 ; errmsgs
= Buffer.create
0
679 ; anchor
= emptyanchor
683 ; tilelru
= Queue.create
()
684 ; pagemap
= Hashtbl.create
10
685 ; tilemap
= Hashtbl.create
10
701 ; geomcmds
= firstgeomcmds
703 { nav
= cbnew 10 emptyanchor
732 fstate.fontsize
<- n
;
733 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
734 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
740 Printf.kprintf prerr_endline fmt
742 Printf.kprintf ignore fmt
746 if String.length
conf.pathlauncher
= 0
747 then print_endline
state.path
749 let re = Str.regexp
"%s" in
750 let command = Str.global_replace
re state.path
conf.pathlauncher
in
753 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
759 type 'a t
= | Res
of 'a
| Exn
of exn
;;
762 try Res
(Unix.pipe ())
767 try tempfailureretry
Unix.close fd
768 with exn
-> f
(exntos exn
)
772 try Res
(tempfailureretry
Unix.dup fd
)
777 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
782 let redirectstderr () =
783 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
784 if conf.redirectstderr
786 match Ne.pipe () with
788 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
791 begin match Ne.dup Unix.stderr
with
793 dolog
"failed to dup stderr: %s" (exntos exn
);
794 Ne.clo r
(clofail "pipe/r");
795 Ne.clo w
(clofail "pipe/w");
797 | Ne.Res dupstderr
->
798 begin match Ne.dup2 w
Unix.stderr
with
800 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
801 Ne.clo dupstderr
(clofail "stderr duplicate");
802 Ne.clo r
(clofail "redir pipe/r");
803 Ne.clo w
(clofail "redir pipe/w");
806 state.stderr
<- dupstderr
;
807 state.errfd
<- Some r
;
811 state.newerrmsgs
<- false;
812 begin match state.errfd
with
814 begin match Ne.dup2 state.stderr
Unix.stderr
with
816 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
818 Ne.clo fd
(clofail "dup of stderr");
823 prerr_string
(Buffer.contents
state.errmsgs
);
825 Buffer.clear
state.errmsgs
;
831 let postRedisplay who
=
833 then prerr_endline
("redisplay for " ^ who
);
834 state.redisplay
<- true;
838 let getopaque pageno
=
839 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
840 with Not_found
-> None
843 let putopaque pageno opaque
=
844 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
847 let pagetranslatepoint l x y
=
848 let dy = y
- l
.pagedispy
in
849 let y = dy + l
.pagey
in
850 let dx = x
- l
.pagedispx
in
851 let x = dx + l
.pagex
in
855 let onppundermouse g
x y d
=
858 begin match getopaque l
.pageno
with
860 let x0 = l
.pagedispx
in
861 let x1 = x0 + l
.pagevw
in
862 let y0 = l
.pagedispy
in
863 let y1 = y0 + l
.pagevh
in
864 if y >= y0 && y <= y1 && x >= x0 && x <= x1
866 let px, py
= pagetranslatepoint l
x y in
867 match g opaque l
px py
with
880 let g opaque _
px py
=
881 match whatsunder opaque
px py
with
883 | under
-> Some under
885 onppundermouse g x y Unone
890 match unproject opaque
x y with
891 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
894 onppundermouse g x y None
;
898 state.text
<- Printf.sprintf
"%c%s" c s
;
899 G.postRedisplay "showtext";
903 match Ne.pipe () with
905 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
908 try popen conf.selcmd
[r
, 0; w
, -1]; true
911 (Printf.sprintf
"failed to execute %s: %s"
912 conf.selcmd
(exntos exn
));
916 Ne.clo fd
(fun msg
->
917 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
923 let l = String.length s
in
924 let n = tempfailureretry
(Unix.write w s
0) l in
929 "failed to write %d characters to sel pipe, wrote %d"
934 (Printf.sprintf
"failed to write to sel pipe: %s"
943 let undertext = function
946 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
947 | Utext s
-> "font: " ^ s
948 | Uunexpected s
-> "unexpected: " ^ s
949 | Ulaunch s
-> "launch: " ^ s
950 | Unamed s
-> "named: " ^ s
951 | Uremote
(filename
, pageno
) ->
952 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
955 let updateunder x y =
956 match getunder x y with
957 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
959 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
960 Wsi.setcursor
Wsi.CURSOR_INFO
961 | Ulinkgoto
(pageno
, _
) ->
963 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
964 Wsi.setcursor
Wsi.CURSOR_INFO
966 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
967 Wsi.setcursor
Wsi.CURSOR_TEXT
969 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
970 Wsi.setcursor
Wsi.CURSOR_INHERIT
972 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
973 Wsi.setcursor
Wsi.CURSOR_INHERIT
975 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
976 Wsi.setcursor
Wsi.CURSOR_INHERIT
977 | Uremote
(filename
, pageno
) ->
978 if conf.underinfo
then showtext 'r'
979 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
980 Wsi.setcursor
Wsi.CURSOR_INFO
983 let showlinktype under
=
989 let s = undertext under
in
994 let b = Buffer.create
(String.length
s + 1) in
995 Buffer.add_string
b s;
1000 let colorspace_of_string s =
1001 match String.lowercase
s with
1005 | _
-> failwith
"invalid colorspace"
1008 let int_of_colorspace = function
1014 let colorspace_of_int = function
1018 | n -> failwith
("invalid colorspace index " ^ string_of_int
n)
1021 let colorspace_to_string = function
1027 let fitmodel_of_string s =
1028 match String.lowercase
s with
1029 | "width" -> FitWidth
1030 | "proportional" -> FitProportional
1032 | _
-> failwith
"invalid fit model"
1035 let int_of_fitmodel = function
1037 | FitProportional
-> 1
1041 let fitmodel_of_int = function
1043 | 1 -> FitProportional
1045 | n -> failwith
("invalid fit model index " ^ string_of_int
n)
1048 let fitmodel_to_string = function
1049 | FitWidth
-> "width"
1050 | FitProportional
-> "proportional"
1054 let intentry_with_suffix text key
=
1056 if key
>= 32 && key
< 127
1060 match Char.lowercase
c with
1062 let text = addchar text c in
1065 | 'k'
| 'm'
| '
g'
->
1066 let text = addchar text c in
1070 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1074 let multicolumns_to_string (n, a
, b) =
1076 then Printf.sprintf
"%d" n
1077 else Printf.sprintf
"%d,%d,%d" n a
b;
1080 let multicolumns_of_string s =
1082 (int_of_string
s, 0, 0)
1084 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1086 then failwith
"subtly broken"; (n, a
, b)
1092 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1093 if n != 4 then failwith
"incomplete read(len)";
1095 lor (Char.code
s.[0] lsl 24)
1096 lor (Char.code
s.[1] lsl 16)
1097 lor (Char.code
s.[2] lsl 8)
1098 lor (Char.code
s.[3] lsl 0)
1100 let s = String.create
len in
1101 let n = tempfailureretry
(Unix.read fd
s 0) len in
1102 if n != len then failwith
"incomplete read(data)";
1106 let btod b = if b then 1 else 0;;
1109 let b = Buffer.create
16 in
1110 Buffer.add_string
b "llll";
1113 let s = Buffer.contents
b in
1114 let n = String.length
s in
1116 (* dolog "wcmd %S" (String.sub s 4 len); *)
1117 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1118 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1119 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1120 s.[3] <- Char.chr
(len land 0xff);
1121 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1122 if n'
!= n then failwith
"write failed";
1127 let d = state.winh
- h
in
1128 max
conf.interpagespace
((d + 1) / 2)
1131 let rowyh (c, coverA
, coverB
) b n =
1132 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1134 let _, _, vy
, (_, _, h
, _) = b.(n) in
1137 let n'
= n - coverA
in
1140 let e = min
state.pagecount
(s + c) in
1141 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1142 let _, _, y, (_, _, h
, _) = b.(m
) in
1143 let miny = min
miny y in
1144 let maxh = max
maxh h
in
1145 find (m
+1) miny maxh
1150 match conf.columns
with
1151 | Cmulti
((_, _, _) as cl
, b) ->
1152 if Array.length
b > 0
1154 let y, h
= rowyh cl
b (Array.length
b - 1) in
1155 y + h
+ (if conf.presentation
then calcips h
else 0)
1158 if Array.length
b > 0
1160 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1161 y + h
+ (if conf.presentation
then calcips h
else 0)
1164 if Array.length
b > 0
1166 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1171 let getpageyh pageno
=
1172 let pageno = bound pageno 0 (state.pagecount
-1) in
1173 match conf.columns
with
1175 if Array.length
b = 0
1178 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1180 if conf.presentation
1186 if Array.length
b = 0
1189 let y, h
= rowyh cl
b pageno in
1191 if conf.presentation
1197 if Array.length
b = 0
1201 let (_, _, y, (_, _, h
, _)) = b.(n) in
1205 let getpagedim pageno =
1208 | (n, _, _, _) as pdim
:: rest
->
1210 then (if n = pageno then pdim
else ppdim
)
1215 f (-1, -1, -1, -1) state.pdims
1218 let getpagey pageno = fst
(getpageyh pageno);;
1220 let nogeomcmds cmds
=
1222 | s, [] -> String.length
s = 0
1227 let ((c, coverA
, coverB
) as cl
), b =
1228 match conf.columns
with
1229 | Csingle
b -> (1, 0, 0), b
1230 | Cmulti
(c, b) -> c, b
1231 | Csplit
(_, b) -> (1, 0, 0), b
1233 if Array.length
b = 0
1236 let rec bsearch nmin nmax
=
1238 then bound nmin
0 (state.pagecount
-1)
1240 let n = (nmax
+ nmin
) / 2 in
1241 let vy, h
= rowyh cl
b n in
1243 if conf.presentation
1245 let ips = calcips h
in
1246 let y0 = vy - ips in
1247 let y1 = vy + h
+ ips in
1251 then 0, vy + h
+ conf.interpagespace
1253 let y0 = vy - conf.interpagespace
in
1254 y0, y0 + h
+ conf.interpagespace
1257 if y >= y0 && y < y1
1264 if n < state.pagecount
- coverB
1265 then ((n-coverA
)/c)*c + coverA
1272 then bsearch (n+1) nmax
1273 else bsearch nmin
(n-1)
1276 let r = bsearch 0 (state.pagecount
-1) in
1280 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1281 let sh = sh - state.hscrollh
in
1282 let rec fold accu
n =
1283 if n = Array.length
b
1286 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1289 || n = state.pagecount
- coverB
1290 || (n - coverA
) mod columns
= columns
- 1)
1296 let pagey = max
0 (y - vy) in
1297 let pagedispy = if pagey > 0 then 0 else vy - y in
1298 let pagedispx, pagex
=
1300 if n = coverA
- 1 || n = state.pagecount
- coverB
1301 then state.x + (state.winw
- state.scrollw
- w
) / 2
1302 else dx + xoff
+ state.x
1309 let vw = state.winw
- state.scrollw
- pagedispx in
1310 let pw = w
- pagex
in
1313 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1314 if pagevw > 0 && pagevh > 0
1318 ; pagedimno
= pdimno
1325 ; pagedispx = pagedispx
1326 ; pagedispy = pagedispy
1338 List.rev
(fold [] (page_of_y y));
1341 let layoutS (columns
, b) y sh =
1342 let sh = sh - state.hscrollh
in
1343 let rec fold accu n =
1344 if n = Array.length
b
1347 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1354 let x = xoff
+ state.x in
1355 let pagey = max
0 (y - vy) in
1356 let pagedispy = if pagey > 0 then 0 else vy - y in
1357 let pagedispx, pagex
=
1371 let pagecolw = pagew
/columns
in
1373 if pagecolw < state.winw
1374 then pagedispx + ((state.winw
- state.scrollw
- pagecolw) / 2)
1378 let vw = state.winw
- pagedispx - state.scrollw
in
1379 let pw = pagew
- pagex
in
1382 let pagevw = min
pagevw pagecolw in
1383 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1384 if pagevw > 0 && pagevh > 0
1387 { pageno = n/columns
1388 ; pagedimno
= pdimno
1395 ; pagedispx = pagedispx
1396 ; pagedispy = pagedispy
1397 ; pagecol
= n mod columns
1408 List.rev
(fold [] 0)
1412 if nogeomcmds state.geomcmds
1414 match conf.columns
with
1415 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1416 | Cmulti
c -> layoutN c y sh
1417 | Csplit
s -> layoutS s y sh
1422 let y = state.y + incr
in
1424 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1429 let tilex = l.pagex
mod conf.tilew
in
1430 let tiley = l.pagey mod conf.tileh
in
1432 let col = l.pagex
/ conf.tilew
in
1433 let row = l.pagey / conf.tileh
in
1435 let rec rowloop row y0 dispy h
=
1439 let dh = conf.tileh
- y0 in
1440 let dh = min h
dh in
1441 let rec colloop col x0 dispx w
=
1445 let dw = conf.tilew
- x0 in
1446 let dw = min w
dw in
1448 f col row dispx dispy
x0 y0 dw dh;
1449 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1452 colloop col tilex l.pagedispx l.pagevw;
1453 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1456 if l.pagevw > 0 && l.pagevh > 0
1457 then rowloop row tiley l.pagedispy l.pagevh;
1460 let gettileopaque l col row =
1462 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1464 try Some
(Hashtbl.find state.tilemap
key)
1465 with Not_found
-> None
1468 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1469 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1470 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1473 let drawtiles l color
=
1475 let f col row x y tilex tiley w h
=
1476 match gettileopaque l col row with
1477 | Some
(opaque
, _, t
) ->
1478 let params = x, y, w
, h
, tilex, tiley in
1482 GlFunc.blend_func `zero `one_minus_src_color
;
1484 drawtile
params opaque
;
1486 then Gl.disable `blend
;
1489 let s = Printf.sprintf
1493 let w = measurestr
fstate.fontsize
s in
1494 GlMisc.push_attrib
[`current
];
1495 GlDraw.color
(0.0, 0.0, 0.0);
1497 (float (x-2), float (y-2))
1498 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1499 GlDraw.color
(1.0, 1.0, 1.0);
1500 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1501 GlMisc.pop_attrib
();
1506 let lw = state.winw
- state.scrollw
- x in
1509 let lh = state.winh
- y in
1512 begin match state.texid
with
1514 Gl.enable `texture_2d
;
1515 GlTex.bind_texture `texture_2d id
;
1518 and x1 = float (x+w)
1519 and y1 = float (y+h
) in
1521 let tw = float w /. 16.0
1522 and th
= float h
/. 16.0 in
1523 let tx0 = float tilex /. 16.0
1524 and ty0
= float tiley /. 16.0 in
1526 and ty1
= ty0
+. th
in
1527 GlDraw.begins `quads
;
1528 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1529 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1530 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1531 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1534 Gl.disable `texture_2d
;
1536 GlDraw.color
(1.0, 1.0, 1.0);
1539 (float (x+w), float (y+h
));
1541 if w > 128 && h
> fstate.fontsize
+ 10
1543 GlDraw.color
(0.0, 0.0, 0.0);
1546 then (col*conf.tilew
, row*conf.tileh
)
1549 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1556 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1558 let tilevisible1 l x y =
1560 and ax1
= l.pagex
+ l.pagevw
1562 and ay1
= l.pagey + l.pagevh in
1566 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1567 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1569 let rx0 = max
ax0 bx0
1570 and ry0
= max ay0 by0
1571 and rx1
= min ax1
bx1
1572 and ry1
= min ay1 by1
in
1574 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1575 nonemptyintersection
1578 let tilevisible layout n x y =
1579 let rec findpageinlayout m
= function
1580 | l :: rest
when l.pageno = n ->
1581 tilevisible1 l x y || (
1582 match conf.columns
with
1583 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1586 | _ :: rest
-> findpageinlayout 0 rest
1589 findpageinlayout 0 layout;
1592 let tileready l x y =
1593 tilevisible1 l x y &&
1594 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1597 let tilepage n p
layout =
1598 let rec loop = function
1602 let f col row _ _ _ _ _ _ =
1603 if state.currently
= Idle
1605 match gettileopaque l col row with
1608 let x = col*conf.tilew
1609 and y = row*conf.tileh
in
1611 let w = l.pagew
- x in
1615 let h = l.pageh
- y in
1620 then getpbo
w h conf.colorspace
1623 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1626 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1627 conf.tilew
, conf.tileh
1636 if nogeomcmds state.geomcmds
1640 let preloadlayout y =
1641 let y = if y < state.winh
then 0 else y - state.winh
in
1642 let h = state.winh
*3 in
1647 let rec loop pages
=
1648 if state.currently
!= Idle
1653 begin match getopaque l.pageno with
1655 wcmd "page %d %d" l.pageno l.pagedimno
;
1656 state.currently
<- Loading
(l, state.gen
);
1658 tilepage l.pageno opaque pages
;
1663 if nogeomcmds state.geomcmds
1669 if conf.preload && state.currently
= Idle
1670 then load (preloadlayout state.y);
1673 let layoutready layout =
1674 let rec fold all ls
=
1675 all
&& match ls
with
1677 let seen = ref false in
1678 let allvisible = ref true in
1679 let foo col row _ _ _ _ _ _ =
1681 allvisible := !allvisible &&
1682 begin match gettileopaque l col row with
1688 fold (!seen && !allvisible) rest
1691 let alltilesvisible = fold true layout in
1696 let y = bound y 0 state.maxy
in
1697 let y, layout, proceed
=
1698 match conf.maxwait
with
1699 | Some time
when state.ghyll
== noghyll ->
1700 begin match state.throttle
with
1702 let layout = layout y state.winh
in
1703 let ready = layoutready layout in
1707 state.throttle
<- Some
(layout, y, now ());
1709 else G.postRedisplay "gotoy showall (None)";
1711 | Some
(_, _, started
) ->
1712 let dt = now () -. started
in
1715 state.throttle
<- None
;
1716 let layout = layout y state.winh
in
1718 G.postRedisplay "maxwait";
1725 let layout = layout y state.winh
in
1726 if not
!wtmode || layoutready layout
1727 then G.postRedisplay "gotoy ready";
1733 state.layout <- layout;
1734 begin match state.mode
with
1735 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1736 let rec loop = function
1738 state.mode
<- LinkNav
(Ltgendir
0)
1739 | l :: _ when l.pageno = pageno ->
1740 begin match getopaque pageno with
1742 state.mode
<- LinkNav
(Ltgendir
0)
1744 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1745 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1746 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1747 then state.mode
<- LinkNav
(Ltgendir
0)
1749 | _ :: rest
-> loop rest
1754 begin match state.mode
with
1755 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1756 if not
(pagevisible layout pageno)
1758 match state.layout with
1761 state.mode
<- Birdseye
(
1762 conf, leftx
, l.pageno, hooverpageno
, anchor
1765 | LinkNav
(Ltgendir dir
as lt
) ->
1767 let rec loop = function
1770 match getopaque l.pageno with
1776 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1778 if dir
> 0 then LDfirst
else LDlast
1784 | Lnotfound
-> loop rest
1786 showlinktype (getlink opaque
n);
1787 Ltexact
(l.pageno, n)
1791 state.mode
<- LinkNav
linknav
1796 state.ghyll
<- noghyll;
1799 let mx, my
= state.mpos
in
1804 let conttiling pageno opaque
=
1805 tilepage pageno opaque
1806 (if conf.preload then preloadlayout state.y else state.layout)
1809 let gotoy_and_clear_text y =
1810 if not
conf.verbose
then state.text <- "";
1816 let coloff = l.pagecol
* l.pageh
in
1817 float (l.pagey + coloff) /. float l.pageh
1824 if conf.presentation
1825 then float l.pagedispy /. float (calcips l.pageh
)
1826 else float l.pagedispy /. float conf.interpagespace
1828 (l.pageno, top, dtop)
1832 match state.layout with
1833 | l :: _ -> getanchor1 l
1835 let n = page_of_y state.y in
1839 let y, h = getpageyh n in
1840 let dy = y - state.y in
1842 if conf.presentation
1844 let ips = calcips h in
1845 float (dy + ips) /. float ips
1847 float dy /. float conf.interpagespace
1852 let getanchory (n, top, dtop) =
1853 let y, h = getpageyh n in
1854 if conf.presentation
1856 let ips = calcips h in
1857 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1859 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1862 let gotoanchor anchor
=
1863 gotoy (getanchory anchor
);
1867 cbput state.hists
.nav
(getanchor ());
1871 let anchor = cbgetc state.hists
.nav dir
in
1876 let scroll f n a
b =
1877 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1879 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1881 then s (float f /. float a
)
1884 then 1.0 -. s ((float (f-b) /. float (n-b)))
1891 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1892 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1894 let ins = float a
*. iv1
1895 and outs
= float (n-b) *. iv1 in
1897 ins +. outs
+. float ones
1899 let rec set (_N
, _A
, _B
) y sy
=
1900 let sum = summa
1.0 _N _A _B
in
1901 let dy = float (y - sy
) in
1905 then state.ghyll
<- noghyll
1908 let s = scroll n _N _A _B
in
1909 let y1 = y1 +. ((s *. dy) /. sum) in
1910 gotoy_and_clear_text (truncate
y1);
1911 state.ghyll
<- gf (n+1) y1;
1915 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1917 gf 0 (float state.y)
1920 match conf.ghyllscroll
with
1922 gotoy_and_clear_text y
1924 if state.ghyll
== noghyll
1925 then set nab
y state.y
1926 else state.ghyll
(Some
y)
1929 let gotopage n top =
1930 let y, h = getpageyh n in
1931 let y = y + (truncate
(top *. float h)) in
1935 let gotopage1 n top =
1936 let y = getpagey n in
1941 let invalidate s f =
1946 match state.geomcmds
with
1947 | ps
, [] when String.length ps
= 0 ->
1949 state.geomcmds
<- s, [];
1952 state.geomcmds
<- ps
, [s, f];
1954 | ps
, (s'
, _) :: rest
when s'
= s ->
1955 state.geomcmds
<- ps
, ((s, f) :: rest
);
1958 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1962 Hashtbl.iter
(fun _ opaque
->
1963 wcmd "freepage %s" opaque
;
1965 Hashtbl.clear
state.pagemap
;
1969 if not
(Queue.is_empty
state.tilelru
)
1971 Queue.iter
(fun (k
, p
, s) ->
1972 wcmd "freetile %s" p
;
1973 state.memused
<- state.memused
- s;
1974 Hashtbl.remove
state.tilemap k
;
1976 state.uioh#infochanged Memused
;
1977 Queue.clear
state.tilelru
;
1982 let opendoc path password
=
1984 state.password
<- password
;
1985 state.gen
<- state.gen
+ 1;
1986 state.docinfo
<- [];
1989 setaalevel
conf.aalevel
;
1991 if String.length
state.origin
= 0
1995 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
1996 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
1997 invalidate "reqlayout"
1999 wcmd "reqlayout %d %d %f %s\000"
2000 conf.angle
(int_of_fitmodel conf.fitmodel
) conf.zoom
state.nameddest
;
2005 state.anchor <- getanchor ();
2006 opendoc state.path
state.password
;
2010 let c = c *. conf.colorscale
in
2014 let scalecolor2 (r, g, b) =
2015 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2018 let docolumns = function
2020 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2021 let rec loop pageno pdimno pdim
y ph pdims
=
2022 if pageno = state.pagecount
2025 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2027 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2028 pdimno+1, pdim
, rest
2032 let x = max
0 (((state.winw
- state.scrollw
- w) / 2) - xoff
) in
2034 (if conf.presentation
2035 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2036 else (if pageno = 0 then 0 else conf.interpagespace
)
2039 a.(pageno) <- (pdimno, x, y, pdim
);
2040 loop (pageno+1) pdimno pdim
(y + h) h pdims
2042 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2043 conf.columns
<- Csingle
a;
2045 | Cmulti
((columns
, coverA
, coverB
), _) ->
2046 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2047 let rec loop pageno pdimno pdim
x y rowh pdims
=
2048 let rec fixrow m
= if m
= pageno then () else
2049 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2052 let y = y + (rowh
- h) / 2 in
2053 a.(m
) <- (pdimno, x, y, pdim
);
2057 if pageno = state.pagecount
2058 then fixrow (((pageno - 1) / columns
) * columns
)
2060 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2062 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2063 pdimno+1, pdim
, rest
2068 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2070 let x = (state.winw
- state.scrollw
- w) / 2 in
2072 if conf.presentation
then calcips h else conf.interpagespace
in
2073 x, y + ips + rowh
, h
2076 if (pageno - coverA
) mod columns
= 0
2078 let x = max
0 (state.winw
- state.scrollw
- state.w) / 2 in
2080 if conf.presentation
2082 let ips = calcips h in
2083 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2085 y + (if pageno = 0 then 0 else conf.interpagespace
)
2089 else x, y, max rowh
h
2093 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2096 if pageno = columns
&& conf.presentation
2098 let ips = calcips rowh
in
2099 for i
= 0 to pred columns
2101 let (pdimno, x, y, pdim
) = a.(i
) in
2102 a.(i
) <- (pdimno, x, y+ips, pdim
)
2108 fixrow (pageno - columns
);
2113 a.(pageno) <- (pdimno, x, y, pdim
);
2114 let x = x + w + xoff
*2 + conf.interpagespace
in
2115 loop (pageno+1) pdimno pdim
x y rowh' pdims
2117 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2118 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2121 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2122 let rec loop pageno pdimno pdim
y pdims
=
2123 if pageno = state.pagecount
2126 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2128 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2129 pdimno+1, pdim
, rest
2134 let rec loop1 n x y =
2135 if n = c then y else (
2136 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2137 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2140 let y = loop1 0 0 y in
2141 loop (pageno+1) pdimno pdim
y pdims
2143 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2144 conf.columns
<- Csplit
(c, a);
2148 docolumns conf.columns
;
2149 state.maxy
<- calcheight ();
2151 if state.x = 0 && state.w <= state.winw
- state.scrollw
2155 if state.reprf
== noreprf
2157 match state.mode
with
2158 | Birdseye
(_, _, pageno, _, _) ->
2159 let y, h = getpageyh pageno in
2160 let top = (state.winh
- h) / 2 in
2161 gotoy (max
0 (y - top))
2162 | _ -> gotoanchor state.anchor
2166 state.reprf
<- noreprf;
2171 GlDraw.viewport
0 0 w h;
2172 let firsttime = state.geomcmds
== firstgeomcmds in
2173 if not
firsttime && nogeomcmds state.geomcmds
2174 then state.anchor <- getanchor ();
2177 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2180 setfontsize fstate.fontsize
;
2181 GlMat.mode `modelview
;
2182 GlMat.load_identity
();
2184 GlMat.mode `projection
;
2185 GlMat.load_identity
();
2186 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2187 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2188 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2193 else float state.x /. float state.w
2195 invalidate "geometry"
2199 then state.x <- truncate
(relx *. float w);
2201 match conf.columns
with
2203 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2204 | Csplit
(c, _) -> w * c
2206 wcmd "geometry %d %d %f %d"
2207 w (h - 2*conf.interpagespace
) conf.zoom
2208 (int_of_fitmodel conf.fitmodel
));
2212 let len = String.length
state.text in
2215 match state.mode
with
2218 let h, _, _ = state.uioh#scrollpw
in
2224 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2225 (x+.w, float (state.winh
- hscrollh))
2228 let w = float (state.winw
- state.scrollw
- 1) in
2229 if state.progress
>= 0.0 && state.progress
< 1.0
2231 GlDraw.color
(0.3, 0.3, 0.3);
2232 let w1 = w *. state.progress
in
2234 GlDraw.color
(0.0, 0.0, 0.0);
2238 GlDraw.color
(0.0, 0.0, 0.0);
2242 GlDraw.color
(1.0, 1.0, 1.0);
2243 drawstring fstate.fontsize
2244 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2247 match state.mode
with
2248 | Textentry
((prefix
, text, _, _, _, _), _) ->
2252 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2254 Printf.sprintf
"%s%s_" prefix
text
2263 if not
(istextentry state.mode
) && state.uioh#eformsgs
2265 let s1 = "(press 'e' to review error messasges)" in
2266 if String.length
s > 0 then s ^
" " ^
s1 else s1
2271 if String.length
s > 0
2276 let len = Queue.length
state.tilelru
in
2278 match state.throttle
with
2281 then preloadlayout state.y
2283 | Some
(layout, _, _) ->
2287 if state.memused
<= conf.memlimit
2292 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2293 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2294 let (_, pw, ph
, _) = getpagedim n in
2297 && colorspace
= conf.colorspace
2298 && angle
= conf.angle
2302 let x = col*conf.tilew
2303 and y = row*conf.tileh
in
2304 tilevisible (Lazy.force_val
layout) n x y
2306 then Queue.push lruitem
state.tilelru
2309 wcmd "freetile %s" p
;
2310 state.memused
<- state.memused
- s;
2311 state.uioh#infochanged Memused
;
2312 Hashtbl.remove
state.tilemap k
;
2320 let logcurrently = function
2321 | Idle
-> dolog
"Idle"
2322 | Loading
(l, gen
) ->
2323 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2324 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2326 "Tiling %d[%d,%d] page=%s cs=%s angle"
2327 l.pageno col row pageopaque
2328 (colorspace_to_string colorspace
)
2330 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2331 angle gen
conf.angle
state.gen
2333 conf.tilew
conf.tileh
2340 let r = Str.regexp
" " in
2341 fun s -> Str.bounded_split
r s 2;
2344 let onpagerect pageno f =
2346 match conf.columns
with
2347 | Cmulti
(_, b) -> b
2349 | Csplit
(_, b) -> b
2351 if pageno >= 0 && pageno < Array.length
b
2353 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2354 let r = getpdimrect
pdimno in
2355 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2358 let gotopagexy1 pageno x y =
2359 onpagerect pageno (fun w h ->
2361 let _,w1,_,leftx
= getpagedim pageno in
2362 let wh = state.winh
- state.hscrollh in
2363 let sw = float w1 /. w in
2365 let x = leftx
+ state.x + truncate
x in
2367 if x < 0 || x >= state.winw
- state.scrollw
2371 let py, h = getpageyh pageno in
2372 let pdy = truncate
(top *. float h) in
2373 let y'
= py + pdy in
2374 let dy = y'
- state.y in
2376 if x != state.x || not
(dy > 0 && dy < wh)
2378 if conf.presentation
2380 if abs
(py - y'
) > wh
2387 if state.x != sx || state.y != sy
2392 let ww = state.winw
- state.scrollw
in
2394 and qy
= pdy / wh in
2396 and y = py + qy
* wh in
2397 let x = if -x + ww > w1 then -(w1-ww) else x
2398 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2400 if conf.presentation
2402 if abs
(py - y'
) > wh
2413 if x = 0 && state.w <= state.winw
- state.scrollw
2417 gotoy_and_clear_text y;
2419 else gotoy_and_clear_text state.y;
2423 let gotopagexy pageno x y =
2424 match state.mode
with
2425 | Birdseye
_ -> gotopage pageno 0.0
2426 | _ -> gotopagexy1 pageno x y
2430 (* dolog "%S" cmds; *)
2431 let cl = splitatspace cmds
in
2433 try Scanf.sscanf
s fmt
f
2435 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2440 state.uioh#infochanged Pdim
;
2443 | "clearrects" :: [] ->
2444 state.rects
<- state.rects1
;
2445 G.postRedisplay "clearrects";
2447 | "continue" :: args :: [] ->
2448 let n = scan args "%u" (fun n -> n) in
2449 state.pagecount
<- n;
2450 begin match state.currently
with
2452 state.currently
<- Idle
;
2453 state.outlines
<- Array.of_list
(List.rev
l)
2457 let cur, cmds
= state.geomcmds
in
2458 if String.length
cur = 0
2459 then failwith
"umpossible";
2461 begin match List.rev cmds
with
2463 state.geomcmds
<- "", [];
2467 state.geomcmds
<- s, List.rev rest
;
2469 if conf.maxwait
= None
&& not
!wtmode
2470 then G.postRedisplay "continue";
2472 | "title" :: args :: [] ->
2475 | "msg" :: args :: [] ->
2478 | "vmsg" :: args :: [] ->
2480 then showtext ' '
args
2482 | "emsg" :: args :: [] ->
2483 Buffer.add_string
state.errmsgs
args;
2484 state.newerrmsgs
<- true;
2485 G.postRedisplay "error message"
2487 | "progress" :: args :: [] ->
2488 let progress, text =
2491 f, String.sub
args pos
(String.length
args - pos
))
2494 state.progress <- progress;
2495 G.postRedisplay "progress"
2497 | "firstmatch" :: args :: [] ->
2498 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2499 scan args "%u %d %f %f %f %f %f %f %f %f"
2500 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2501 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2503 let y = (getpagey pageno) + truncate
y0 in
2506 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2508 | "match" :: args :: [] ->
2509 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2510 scan args "%u %d %f %f %f %f %f %f %f %f"
2511 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2512 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2515 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2517 | "page" :: args :: [] ->
2518 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2519 begin match state.currently
with
2520 | Loading
(l, gen
) ->
2521 vlog "page %d took %f sec" l.pageno t
;
2522 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2523 begin match state.throttle
with
2525 let preloadedpages =
2527 then preloadlayout state.y
2532 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2533 IntSet.empty
preloadedpages
2536 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2537 if not
(IntSet.mem
pageno set)
2539 wcmd "freepage %s" opaque
;
2545 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2548 state.currently
<- Idle
;
2551 tilepage l.pageno pageopaque state.layout;
2553 load preloadedpages;
2554 if pagevisible state.layout l.pageno
2555 && layoutready state.layout
2556 then G.postRedisplay "page";
2559 | Some
(layout, _, _) ->
2560 state.currently
<- Idle
;
2561 tilepage l.pageno pageopaque layout;
2566 dolog
"Inconsistent loading state";
2567 logcurrently state.currently
;
2571 | "tile" :: args :: [] ->
2572 let (x, y, opaque
, size
, t
) =
2573 scan args "%u %u %s %u %f"
2574 (fun x y p size t
-> (x, y, p
, size
, t
))
2576 begin match state.currently
with
2577 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2578 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2581 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2583 wcmd "freetile %s" opaque
;
2584 state.currently
<- Idle
;
2588 puttileopaque l col row gen cs angle opaque size t
;
2589 state.memused
<- state.memused
+ size
;
2590 state.uioh#infochanged Memused
;
2592 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2593 opaque
, size
) state.tilelru
;
2596 match state.throttle
with
2597 | None
-> state.layout
2598 | Some
(layout, _, _) -> layout
2601 state.currently
<- Idle
;
2603 && conf.colorspace
= cs
2604 && conf.angle
= angle
2605 && tilevisible layout l.pageno x y
2606 then conttiling l.pageno pageopaque;
2608 begin match state.throttle
with
2610 preload state.layout;
2612 && conf.colorspace
= cs
2613 && conf.angle
= angle
2614 && tilevisible state.layout l.pageno x y
2615 && (not
!wtmode || layoutready state.layout)
2616 then G.postRedisplay "tile nothrottle";
2618 | Some
(layout, y, _) ->
2619 let ready = layoutready layout in
2623 state.layout <- layout;
2624 state.throttle
<- None
;
2625 G.postRedisplay "throttle";
2632 dolog
"Inconsistent tiling state";
2633 logcurrently state.currently
;
2637 | "pdim" :: args :: [] ->
2639 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2641 state.uioh#infochanged Pdim
;
2642 state.pdims
<- pdim :: state.pdims
2644 | "o" :: args :: [] ->
2645 let (l, n, t
, h, pos
) =
2646 scan args "%u %u %d %u %n"
2647 (fun l n t
h pos
-> l, n, t
, h, pos
)
2649 let s = String.sub
args pos
(String.length
args - pos
) in
2650 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2651 begin match state.currently
with
2652 | Outlining outlines
->
2653 state.currently
<- Outlining
(outline :: outlines
)
2655 state.currently
<- Outlining
[outline]
2657 dolog
"invalid outlining state";
2658 logcurrently currently
2661 | "a" :: args :: [] ->
2663 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2665 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2667 | "info" :: args :: [] ->
2668 state.docinfo
<- (1, args) :: state.docinfo
2670 | "infoend" :: [] ->
2671 state.uioh#infochanged Docinfo
;
2672 state.docinfo
<- List.rev
state.docinfo
2675 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2680 let action = function
2681 | HCprev
-> cbget cb ~
-1
2682 | HCnext
-> cbget cb
1
2683 | HCfirst
-> cbget cb ~
-(cb
.rc)
2684 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2685 and cancel
() = cb
.rc <- rc
2689 let search pattern forward
=
2690 if String.length pattern
> 0
2693 match state.layout with
2696 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2698 wcmd "search %d %d %d %d,%s\000"
2699 (btod conf.icase
) pn py (btod forward
) pattern
;
2702 let intentry text key =
2704 if key >= 32 && key < 127
2710 let text = addchar text c in
2714 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2718 let linknentry text key =
2720 if key >= 32 && key < 127
2726 let text = addchar text c in
2730 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2735 if String.length
s > 0
2738 let l = String.length
s in
2739 let rec loop pos
n = if pos
= l then n else
2740 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2741 loop (pos
+1) (n*26 + m)
2744 let rec loop n = function
2747 match getopaque l.pageno with
2748 | None
-> loop n rest
2750 let m = getlinkcount opaque
in
2753 let under = getlink opaque
n in
2756 else loop (n-m) rest
2758 loop n state.layout;
2762 let textentry text key =
2763 if key land 0xff00 = 0xff00
2765 else TEcont
(text ^ toutf8
key)
2768 let reqlayout angle fitmodel
=
2769 match state.throttle
with
2771 if nogeomcmds state.geomcmds
2772 then state.anchor <- getanchor ();
2773 conf.angle
<- angle
mod 360;
2776 match state.mode
with
2777 | LinkNav
_ -> state.mode
<- View
2780 conf.fitmodel
<- fitmodel
;
2781 invalidate "reqlayout"
2783 wcmd "reqlayout %d %d %f"
2784 conf.angle
(int_of_fitmodel fitmodel
) conf.zoom
);
2788 let settrim trimmargins trimfuzz
=
2789 if nogeomcmds state.geomcmds
2790 then state.anchor <- getanchor ();
2791 conf.trimmargins
<- trimmargins
;
2792 conf.trimfuzz
<- trimfuzz
;
2793 let x0, y0, x1, y1 = trimfuzz
in
2794 invalidate "settrim"
2796 wcmd "settrim %d %d %d %d %d %f"
2797 (btod conf.trimmargins
) x0 y0 x1 y1 conf.zoom
);
2802 match state.throttle
with
2804 let zoom = max
0.0001 zoom in
2805 if zoom <> conf.zoom
2807 state.prevzoom
<- conf.zoom;
2809 reshape state.winw
state.winh
;
2810 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2813 | Some
(layout, y, started
) ->
2815 match conf.maxwait
with
2819 let dt = now () -. started
in
2827 let setcolumns mode columns coverA coverB
=
2828 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2832 then showtext '
!'
"split mode doesn't work in bird's eye"
2834 conf.columns
<- Csplit
(-columns
, [||]);
2842 conf.columns
<- Csingle
[||];
2847 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2851 reshape state.winw
state.winh
;
2854 let enterbirdseye () =
2855 let zoom = float conf.thumbw
/. float state.winw
in
2856 let birdseyepageno =
2857 let cy = state.winh
/ 2 in
2861 let rec fold best
= function
2864 let d = cy - (l.pagedispy + l.pagevh/2)
2865 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2866 if abs
d < abs dbest
2873 state.mode
<- Birdseye
(
2874 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2877 conf.presentation
<- false;
2878 conf.interpagespace
<- 10;
2879 conf.hlinks
<- false;
2880 conf.fitmodel
<- FitProportional
;
2882 state.mstate
<- Mnone
;
2883 conf.maxwait
<- None
;
2885 match conf.beyecolumns
with
2888 Cmulti
((c, 0, 0), [||])
2889 | None
-> Csingle
[||]
2891 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2894 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2899 reshape state.winw
state.winh
;
2902 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2904 conf.zoom <- c.zoom;
2905 conf.presentation
<- c.presentation
;
2906 conf.interpagespace
<- c.interpagespace
;
2907 conf.maxwait
<- c.maxwait
;
2908 conf.hlinks
<- c.hlinks
;
2909 conf.fitmodel
<- c.fitmodel
;
2910 conf.beyecolumns
<- (
2911 match conf.columns
with
2912 | Cmulti
((c, _, _), _) -> Some
c
2914 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2917 match c.columns
with
2918 | Cmulti
(c, _) -> Cmulti
(c, [||])
2919 | Csingle
_ -> Csingle
[||]
2920 | Csplit
(c, _) -> Csplit
(c, [||])
2925 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2928 reshape state.winw
state.winh
;
2929 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2932 let togglebirdseye () =
2933 match state.mode
with
2934 | Birdseye vals
-> leavebirdseye vals
true
2935 | View
-> enterbirdseye ()
2939 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2940 let pageno = max
0 (pageno - incr
) in
2941 let rec loop = function
2942 | [] -> gotopage1 pageno 0
2943 | l :: _ when l.pageno = pageno ->
2944 if l.pagedispy >= 0 && l.pagey = 0
2945 then G.postRedisplay "upbirdseye"
2946 else gotopage1 pageno 0
2947 | _ :: rest
-> loop rest
2950 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2953 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2954 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2955 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2956 let rec loop = function
2958 let y, h = getpageyh pageno in
2959 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2961 | l :: _ when l.pageno = pageno ->
2962 if l.pagevh != l.pageh
2963 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2964 else G.postRedisplay "downbirdseye"
2965 | _ :: rest
-> loop rest
2970 let optentry mode
_ key =
2971 let btos b = if b then "on" else "off" in
2972 if key >= 32 && key < 127
2974 let c = Char.chr
key in
2978 try conf.scrollstep
<- int_of_string
s with exc
->
2979 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2981 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2986 conf.autoscrollstep
<- int_of_string
s;
2987 if state.autoscroll
<> None
2988 then state.autoscroll
<- Some
conf.autoscrollstep
2990 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
2992 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2997 let n, a, b = multicolumns_of_string s in
2998 setcolumns mode
n a b;
3000 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3002 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3007 let zoom = float (int_of_string
s) /. 100.0 in
3010 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3012 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3017 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3019 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3020 begin match mode
with
3022 leavebirdseye beye
false;
3027 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3029 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3034 Some
(int_of_string
s)
3036 state.text <- Printf.sprintf
"bad integer `%s': %s"
3040 | Some angle
-> reqlayout angle
conf.fitmodel
3043 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3046 conf.icase
<- not
conf.icase
;
3047 TEdone
("case insensitive search " ^
(btos conf.icase
))
3050 conf.preload <- not
conf.preload;
3052 TEdone
("preload " ^
(btos conf.preload))
3055 conf.verbose
<- not
conf.verbose
;
3056 TEdone
("verbose " ^
(btos conf.verbose
))
3059 conf.debug
<- not
conf.debug
;
3060 TEdone
("debug " ^
(btos conf.debug
))
3063 conf.maxhfit
<- not
conf.maxhfit
;
3064 state.maxy
<- calcheight ();
3065 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3068 conf.crophack
<- not
conf.crophack
;
3069 TEdone
("crophack " ^
btos conf.crophack
)
3073 match conf.maxwait
with
3075 conf.maxwait
<- Some infinity
;
3076 "always wait for page to complete"
3078 conf.maxwait
<- None
;
3079 "show placeholder if page is not ready"
3084 conf.underinfo
<- not
conf.underinfo
;
3085 TEdone
("underinfo " ^
btos conf.underinfo
)
3088 conf.savebmarks
<- not
conf.savebmarks
;
3089 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3095 match state.layout with
3100 conf.interpagespace
<- int_of_string
s;
3101 docolumns conf.columns
;
3102 state.maxy
<- calcheight ();
3103 let y = getpagey pageno in
3106 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3108 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3112 match conf.fitmodel
with
3113 | FitProportional
-> FitWidth
3114 | _ -> FitProportional
3116 reqlayout conf.angle
fm;
3117 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3120 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3121 TEdone
("trim margins " ^
btos conf.trimmargins
)
3124 conf.invert
<- not
conf.invert
;
3125 TEdone
("invert colors " ^
btos conf.invert
)
3129 cbput state.hists
.sel
s;
3132 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3133 textentry, ondone, true)
3136 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3142 class type lvsource
= object
3143 method getitemcount
: int
3144 method getitem
: int -> (string * int)
3145 method hasaction
: int -> bool
3154 method getactive
: int
3155 method getfirst
: int
3156 method getqsearch
: string
3157 method setqsearch
: string -> unit
3161 class virtual lvsourcebase
= object
3162 val mutable m_active
= 0
3163 val mutable m_first
= 0
3164 val mutable m_qsearch
= ""
3165 val mutable m_pan
= 0
3166 method getactive
= m_active
3167 method getfirst
= m_first
3168 method getqsearch
= m_qsearch
3169 method getpan
= m_pan
3170 method setqsearch
s = m_qsearch
<- s
3173 let withoutlastutf8 s =
3174 let len = String.length
s in
3182 let b = Char.code
s.[pos
] in
3183 if b land 0b11000000 = 0b11000000
3188 if Char.code
s.[len-1] land 0x80 = 0
3192 String.sub
s 0 first;
3195 let textentrykeyboard
3196 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3198 if key >= 0xffb0 && key <= 0xffb9
3199 then key - 0xffb0 + 48 else key
3202 state.mode
<- Textentry
(te
, onleave
);
3205 G.postRedisplay "textentrykeyboard enttext";
3207 let histaction cmd
=
3210 | Some
(action, _) ->
3211 state.mode
<- Textentry
(
3212 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3214 G.postRedisplay "textentry histaction"
3217 | 0xff08 -> (* backspace *)
3218 let s = withoutlastutf8 text in
3219 let len = String.length
s in
3220 if cancelonempty
&& len = 0
3223 G.postRedisplay "textentrykeyboard after cancel";
3226 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3229 | 0xff0d | 0xff8d -> (* (kp) enter *)
3232 G.postRedisplay "textentrykeyboard after confirm"
3234 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3235 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3236 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3237 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3239 | 0xff1b -> (* escape*)
3240 if String.length
text = 0
3242 begin match opthist
with
3244 | Some
(_, onhistcancel
) -> onhistcancel
()
3248 G.postRedisplay "textentrykeyboard after cancel2"
3251 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3254 | 0xff9f | 0xffff -> () (* delete *)
3257 && key land 0xff00 != 0xff00 (* keyboard *)
3258 && key land 0xfe00 != 0xfe00 (* xkb *)
3259 && key land 0xfd00 != 0xfd00 (* 3270 *)
3261 begin match onkey
text key with
3265 G.postRedisplay "textentrykeyboard after confirm2";
3268 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3272 G.postRedisplay "textentrykeyboard after cancel3"
3275 state.mode
<- Textentry
(te
, onleave
);
3276 G.postRedisplay "textentrykeyboard switch";
3280 vlog "unhandled key %s" (Wsi.keyname
key)
3283 let firstof first active
=
3284 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3285 then max
0 (active
- (fstate.maxrows
/2))
3289 let calcfirst first active
=
3292 let rows = active
- first in
3293 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3297 let scrollph y maxy
=
3298 let sh = (float (maxy
+ state.winh
) /. float state.winh
) in
3299 let sh = float state.winh
/. sh in
3300 let sh = max
sh (float conf.scrollh
) in
3305 else float y /. float maxy
3307 let position = (float state.winh
-. sh) *. percent in
3310 if position +. sh > float state.winh
3311 then float state.winh
-. sh
3317 let coe s = (s :> uioh
);;
3319 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3321 val m_pan
= source#getpan
3322 val m_first
= source#getfirst
3323 val m_active
= source#getactive
3324 val m_qsearch
= source#getqsearch
3325 val m_prev_uioh
= state.uioh
3327 method private elemunder
y =
3328 let n = y / (fstate.fontsize
+1) in
3329 if m_first
+ n < source#getitemcount
3331 if source#hasaction
(m_first
+ n)
3332 then Some
(m_first
+ n)
3339 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3340 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3341 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3342 GlDraw.color
(1., 1., 1.);
3343 Gl.enable `texture_2d
;
3344 let fs = fstate.fontsize
in
3346 let ww = fstate.wwidth
in
3347 let tabw = 30.0*.ww in
3348 let itemcount = source#getitemcount
in
3350 if (row - m_first
) > fstate.maxrows
3353 if row >= 0 && row < itemcount
3355 let (s, level
) = source#getitem
row in
3356 let y = (row - m_first
) * nfs in
3357 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3360 Gl.disable `texture_2d
;
3361 GlDraw.polygon_mode `both `line
;
3362 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3363 GlDraw.color
(1., 1., 1.) ~
alpha;
3364 GlDraw.rect (1., float (y + 1))
3365 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3366 GlDraw.polygon_mode `both `fill
;
3367 GlDraw.color
(1., 1., 1.);
3368 Gl.enable `texture_2d
;
3371 let drawtabularstring s =
3372 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3375 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3378 let len = String.length
s - tabpos - 1 in
3379 let s1 = String.sub
s 0 tabpos
3380 and s2
= String.sub
s (tabpos + 1) len in
3381 let nx = drawstr x s1 in
3383 let x = x +. (max
tabw sw) in
3390 let _ = drawtabularstring s in
3397 Gl.disable `texture_2d
;
3399 method updownlevel incr
=
3400 let len = source#getitemcount
in
3402 if m_active
>= 0 && m_active
< len
3403 then snd
(source#getitem m_active
)
3407 if i
= len then i
-1 else if i
= -1 then 0 else
3408 let _, l = source#getitem i
in
3409 if l != curlevel then i
else flow (i
+incr
)
3411 let active = flow m_active
in
3412 let first = calcfirst m_first
active in
3413 G.postRedisplay "outline updownlevel";
3414 {< m_active
= active; m_first
= first >}
3416 method private key1
key mask
=
3417 let set1 active first qsearch
=
3418 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3420 let search active pattern incr
=
3421 let active = if active = -1 then m_first
else active in
3424 if n >= 0 && n < source#getitemcount
3426 let s, _ = source#getitem
n in
3428 (try ignore
(Str.search_forward
re s 0); true
3429 with Not_found
-> false)
3431 else loop (n + incr
)
3438 let re = Str.regexp_case_fold pattern
in
3444 let itemcount = source#getitemcount
in
3445 let find start incr
=
3447 if i
= -1 || i
= itemcount
3450 if source#hasaction i
3452 else find (i
+ incr
)
3457 let set active first =
3458 let first = bound first 0 (itemcount - fstate.maxrows
) in
3460 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3463 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3465 let incr1 = if incr
> 0 then 1 else -1 in
3466 if isvisible m_first m_active
3469 let next = m_active
+ incr
in
3471 if next < 0 || next >= itemcount
3473 else find next incr1
3475 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3481 let first = m_first
+ incr
in
3482 let first = bound first 0 (itemcount - 1) in
3484 let next = m_active
+ incr
in
3485 let next = bound next 0 (itemcount - 1) in
3488 let active = if next = -1 then m_active
else next in
3491 let first = min
next m_first
in
3493 if abs
(next - first) > fstate.maxrows
3499 let first = m_first
+ incr
in
3500 let first = bound first 0 (itemcount - 1) in
3502 let next = m_active
+ incr
in
3503 let next = bound next 0 (itemcount - 1) in
3504 let next = find next incr1 in
3506 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3508 let active = if m_active
= -1 then next else m_active
in
3513 if isvisible first active
3519 G.postRedisplay "listview navigate";
3523 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3524 let incr = if key = 0x72 then -1 else 1 in
3526 match search (m_active
+ incr) m_qsearch
incr with
3528 state.text <- m_qsearch ^
" [not found]";
3531 state.text <- m_qsearch
;
3532 active, firstof m_first
active
3534 G.postRedisplay "listview ctrl-r/s";
3535 set1 active first m_qsearch
;
3537 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3538 if m_active
>= 0 && m_active
< source#getitemcount
3540 let s, _ = source#getitem m_active
in
3545 | 0xff08 -> (* backspace *)
3546 if String.length m_qsearch
= 0
3549 let qsearch = withoutlastutf8 m_qsearch
in
3550 let len = String.length
qsearch in
3554 G.postRedisplay "listview empty qsearch";
3555 set1 m_active m_first
"";
3559 match search m_active
qsearch ~
-1 with
3561 state.text <- qsearch ^
" [not found]";
3564 state.text <- qsearch;
3565 active, firstof m_first
active
3567 G.postRedisplay "listview backspace qsearch";
3568 set1 active first qsearch
3571 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3572 let pattern = m_qsearch ^ toutf8
key in
3574 match search m_active
pattern 1 with
3576 state.text <- pattern ^
" [not found]";
3579 state.text <- pattern;
3580 active, firstof m_first
active
3582 G.postRedisplay "listview qsearch add";
3583 set1 active first pattern;
3585 | 0xff1b -> (* escape *)
3587 if String.length m_qsearch
= 0
3589 G.postRedisplay "list view escape";
3592 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3594 | None
-> m_prev_uioh
3599 G.postRedisplay "list view kill qsearch";
3600 source#setqsearch
"";
3601 coe {< m_qsearch
= "" >}
3604 | 0xff0d | 0xff8d -> (* (kp) enter *)
3606 let self = {< m_qsearch
= "" >} in
3607 source#setqsearch
"";
3609 G.postRedisplay "listview enter";
3610 if m_active
>= 0 && m_active
< source#getitemcount
3612 source#exit
(coe self) false m_active m_first m_pan
"";
3615 source#exit
(coe self) true m_active m_first m_pan
"";
3618 begin match opt with
3619 | None
-> m_prev_uioh
3623 | 0xff9f | 0xffff -> (* (kp) delete *)
3626 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3627 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3628 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3629 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3631 | 0xff53 | 0xff98 -> (* (kp) right *)
3633 G.postRedisplay "listview right";
3634 coe {< m_pan
= m_pan
- 1 >}
3636 | 0xff51 | 0xff96 -> (* (kp) left *)
3638 G.postRedisplay "listview left";
3639 coe {< m_pan
= m_pan
+ 1 >}
3641 | 0xff50 | 0xff95 -> (* (kp) home *)
3642 let active = find 0 1 in
3643 G.postRedisplay "listview home";
3646 | 0xff57 | 0xff9c -> (* (kp) end *)
3647 let first = max
0 (itemcount - fstate.maxrows
) in
3648 let active = find (itemcount - 1) ~
-1 in
3649 G.postRedisplay "listview end";
3652 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3656 dolog
"listview unknown key %#x" key; coe self
3658 method key key mask
=
3659 match state.mode
with
3660 | Textentry te
-> textentrykeyboard key mask te
; coe self
3661 | _ -> self#key1
key mask
3663 method button button down
x y _ =
3666 | 1 when x > state.winw
- conf.scrollbw
->
3667 G.postRedisplay "listview scroll";
3670 let _, position, sh = self#
scrollph in
3671 if y > truncate
position && y < truncate
(position +. sh)
3673 state.mstate
<- Mscrolly
;
3677 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3678 let first = truncate
(s *. float source#getitemcount
) in
3679 let first = min source#getitemcount
first in
3680 Some
(coe {< m_first
= first; m_active
= first >})
3682 state.mstate
<- Mnone
;
3685 | 1 when not down
->
3686 begin match self#elemunder
y with
3688 G.postRedisplay "listview click";
3690 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3694 | n when (n == 4 || n == 5) && not down
->
3695 let len = source#getitemcount
in
3697 if n = 5 && m_first
+ fstate.maxrows
>= len
3701 let first = m_first
+ (if n == 4 then -1 else 1) in
3702 bound first 0 (len - 1)
3704 G.postRedisplay "listview wheel";
3705 Some
(coe {< m_first
= first >})
3706 | n when (n = 6 || n = 7) && not down
->
3707 let inc = m_first
+ (if n = 7 then -1 else 1) in
3708 G.postRedisplay "listview hwheel";
3709 Some
(coe {< m_pan
= m_pan
+ inc >})
3714 | None
-> m_prev_uioh
3718 match state.mstate
with
3720 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3721 let first = truncate
(s *. float source#getitemcount
) in
3722 let first = min source#getitemcount
first in
3723 G.postRedisplay "listview motion";
3724 coe {< m_first
= first; m_active
= first >}
3727 method pmotion
x y =
3728 if x < state.winw
- conf.scrollbw
3731 match self#elemunder
y with
3732 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3733 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3737 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3742 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3746 method infochanged
_ = ()
3748 method scrollpw
= (0, 0.0, 0.0)
3750 let nfs = fstate.fontsize
+ 1 in
3751 let y = m_first
* nfs in
3752 let itemcount = source#getitemcount
in
3753 let maxi = max
0 (itemcount - fstate.maxrows
) in
3754 let maxy = maxi * nfs in
3755 let p, h = scrollph y maxy in
3758 method modehash
= modehash
3759 method eformsgs
= false
3762 class outlinelistview ~source
=
3765 ~source
:(source
:> lvsource
)
3767 ~modehash
:(findkeyhash conf "outline")
3770 method key key mask
=
3771 let calcfirst first active =
3774 let rows = active - first in
3776 if String.length
state.text = 0
3778 else fstate.maxrows - 2
3780 if rows > maxrows then active - maxrows else first
3784 let active = m_active
+ incr in
3785 let active = bound active 0 (source#getitemcount
- 1) in
3786 let first = calcfirst m_first
active in
3787 G.postRedisplay "outline navigate";
3788 coe {< m_active
= active; m_first
= first >}
3790 let ctrl = Wsi.withctrl mask
in
3792 | 110 when ctrl -> (* ctrl-n *)
3793 source#narrow m_qsearch
;
3794 G.postRedisplay "outline ctrl-n";
3795 coe {< m_first
= 0; m_active
= 0 >}
3797 | 117 when ctrl -> (* ctrl-u *)
3799 G.postRedisplay "outline ctrl-u";
3801 coe {< m_first
= 0; m_active
= 0 >}
3803 | 108 when ctrl -> (* ctrl-l *)
3804 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3805 G.postRedisplay "outline ctrl-l";
3806 coe {< m_first
= first >}
3808 | 0xff9f | 0xffff -> (* (kp) delete *)
3809 source#remove m_active
;
3810 G.postRedisplay "outline delete";
3811 let active = max
0 (m_active
-1) in
3812 coe {< m_first
= firstof m_first
active;
3813 m_active
= active >}
3815 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3816 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3817 | 0xff55 | 0xff9a -> (* (kp) prior *)
3818 navigate ~
-(fstate.maxrows)
3819 | 0xff56 | 0xff9b -> (* (kp) next *)
3820 navigate fstate.maxrows
3822 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3826 G.postRedisplay "outline ctrl right";
3827 {< m_pan
= m_pan
+ 1 >}
3829 else self#updownlevel
1
3833 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3837 G.postRedisplay "outline ctrl left";
3838 {< m_pan
= m_pan
- 1 >}
3840 else self#updownlevel ~
-1
3844 | 0xff50 | 0xff95 -> (* (kp) home *)
3845 G.postRedisplay "outline home";
3846 coe {< m_first
= 0; m_active
= 0 >}
3848 | 0xff57 | 0xff9c -> (* (kp) end *)
3849 let active = source#getitemcount
- 1 in
3850 let first = max
0 (active - fstate.maxrows) in
3851 G.postRedisplay "outline end";
3852 coe {< m_active
= active; m_first
= first >}
3854 | _ -> super#
key key mask
3857 let outlinesource usebookmarks
=
3860 inherit lvsourcebase
3861 val mutable m_items
= empty
3862 val mutable m_orig_items
= empty
3863 val mutable m_prev_items
= empty
3864 val mutable m_narrow_pattern
= ""
3865 val mutable m_hadremovals
= false
3867 method getitemcount
=
3868 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3871 if n == Array.length m_items
&& m_hadremovals
3873 ("[Confirm removal]", 0)
3875 let s, n, _ = m_items
.(n) in
3878 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3879 ignore
(uioh
, first, qsearch);
3880 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3882 if String.length m_narrow_pattern
= 0
3888 if not
confrimremoval
3890 let _, _, anchor = m_items
.(active) in
3891 gotoghyll (getanchory anchor);
3895 state.bookmarks
<- Array.to_list m_items
;
3896 m_orig_items
<- m_items
;
3899 else m_items
<- items;
3903 method hasaction
_ = true
3906 if Array.length m_items
!= Array.length m_orig_items
3907 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3910 method narrow
pattern =
3911 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3915 let rec loop accu n =
3918 m_narrow_pattern
<- pattern;
3919 m_items
<- Array.of_list
accu
3922 let (s, _, _) as o = m_items
.(n) in
3924 if (try ignore
(Str.search_forward
re s 0); true
3925 with Not_found
-> false)
3931 loop [] (Array.length m_items
- 1)
3936 then Array.of_list
state.bookmarks
3939 m_items
<- m_orig_items
3944 if m >= 0 && m < Array.length m_items
3946 m_hadremovals
<- true;
3947 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3948 let n = if n >= m then n+1 else n in
3953 method reset
anchor items =
3954 m_hadremovals
<- false;
3955 if m_orig_items
== empty || m_prev_items
!= items
3957 m_orig_items
<- items;
3958 if String.length m_narrow_pattern
= 0
3959 then m_items
<- items;
3961 m_prev_items
<- items;
3962 let rely = getanchory anchor in
3964 let rec loop n best bestd
=
3965 if n = Array.length m_items
3968 let (_, _, anchor) = m_items
.(n) in
3969 let orely = getanchory anchor in
3970 let d = abs
(orely - rely) in
3973 else loop (n+1) best bestd
3978 m_first
<- firstof m_first
active
3982 let enterselector usebookmarks
=
3983 let source = outlinesource usebookmarks
in
3987 then Array.of_list
state.bookmarks
3990 if Array.length
outlines = 0
3992 showtext ' ' errmsg
;
3995 state.text <- source#greetmsg
;
3996 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3997 let anchor = getanchor () in
3998 source#reset
anchor outlines;
3999 state.uioh
<- coe (new outlinelistview ~
source);
4000 G.postRedisplay "enter selector";
4004 let enteroutlinemode =
4005 let f = enterselector false in
4006 fun ()-> f "Document has no outline";
4009 let enterbookmarkmode =
4010 let f = enterselector true in
4011 fun () -> f "Document has no bookmarks (yet)";
4014 let color_of_string s =
4015 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4016 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4020 let color_to_string (r, g, b) =
4021 let r = truncate
(r *. 256.0)
4022 and g = truncate
(g *. 256.0)
4023 and b = truncate
(b *. 256.0) in
4024 Printf.sprintf
"%d/%d/%d" r g b
4027 let irect_of_string s =
4028 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4031 let irect_to_string (x0,y0,x1,y1) =
4032 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4035 let makecheckers () =
4036 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4038 converted by Issac Trotts. July 25, 2002 *)
4039 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4040 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4041 let id = GlTex.gen_texture
() in
4042 GlTex.bind_texture `texture_2d
id;
4043 GlPix.store
(`unpack_alignment
1);
4044 GlTex.image2d
image;
4045 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4046 [ `mag_filter `nearest
; `min_filter `nearest
];
4050 let setcheckers enabled
=
4051 match state.texid
with
4053 if enabled
then state.texid
<- Some
(makecheckers ())
4058 GlTex.delete_texture texid
;
4059 state.texid
<- None
;
4063 let int_of_string_with_suffix s =
4064 let l = String.length
s in
4068 let suffix = Char.lowercase
s.[l-1] in
4070 | 'k'
-> String.sub
s 0 (l-1), 10
4071 | '
m'
-> String.sub
s 0 (l-1), 20
4072 | '
g'
-> String.sub
s 0 (l-1), 30
4076 let n = int_of_string
s1 in
4077 let m = n lsl shift
in
4079 then raise
(Failure
"value too large")
4083 let string_with_suffix_of_int n =
4088 if n land ((1 lsl 30) - 1) = 0
4091 if n land ((1 lsl 20) - 1) = 0
4094 if n land ((1 lsl 10) - 1) = 0
4101 let h = n mod 1000 in
4104 then string_of_int
h ^
s
4106 let s = Printf.sprintf
"_%03d%s" h s in
4113 let defghyllscroll = (40, 8, 32);;
4114 let ghyllscroll_of_string s =
4115 let (n, a, b) as nab
=
4118 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4120 if n <= a || n <= b || a >= b
4121 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4125 let ghyllscroll_to_string ((n, a, b) as nab
) =
4126 if nab
= defghyllscroll
4128 else Printf.sprintf
"%d,%d,%d" n a b;
4131 let describe_location () =
4132 let fn = page_of_y state.y in
4133 let ln = page_of_y (state.y + state.winh
- state.hscrollh - 1) in
4134 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4138 else (100. *. (float state.y /. float maxy))
4142 Printf.sprintf
"page %d of %d [%.2f%%]"
4143 (fn+1) state.pagecount
percent
4146 "pages %d-%d of %d [%.2f%%]"
4147 (fn+1) (ln+1) state.pagecount
percent
4150 let setpresentationmode v
=
4151 let n = page_of_y state.y in
4152 state.anchor <- (n, 0.0, 1.0);
4153 conf.presentation
<- v
;
4154 if conf.presentation
4156 if not
conf.scrollbarinpm
4157 then state.scrollw
<- 0;
4159 else state.scrollw
<- conf.scrollbw
;
4164 let btos b = if b then "\xe2\x88\x9a" else "" in
4165 let showextended = ref false in
4166 let leave mode
= function
4167 | Confirm
-> state.mode
<- mode
4168 | Cancel
-> state.mode
<- mode
in
4171 val mutable m_first_time
= true
4172 val mutable m_l
= []
4173 val mutable m_a
= [||]
4174 val mutable m_prev_uioh
= nouioh
4175 val mutable m_prev_mode
= View
4177 inherit lvsourcebase
4179 method reset prev_mode prev_uioh
=
4180 m_a
<- Array.of_list
(List.rev m_l
);
4182 m_prev_mode
<- prev_mode
;
4183 m_prev_uioh
<- prev_uioh
;
4187 if n >= Array.length m_a
4191 | _, _, _, Action
_ -> m_active
<- n
4195 m_first_time
<- false;
4198 method int name get
set =
4200 (name
, `
int get
, 1, Action
(
4203 try set (int_of_string
s)
4205 state.text <- Printf.sprintf
"bad integer `%s': %s"
4209 let te = name ^
": ", "", None
, intentry, ondone, true in
4210 state.mode
<- Textentry
(te, leave m_prev_mode
);
4214 method int_with_suffix name get
set =
4216 (name
, `intws get
, 1, Action
(
4219 try set (int_of_string_with_suffix s)
4221 state.text <- Printf.sprintf
"bad integer `%s': %s"
4226 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4228 state.mode
<- Textentry
(te, leave m_prev_mode
);
4232 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4234 (name
, `
bool (btos, get
), offset
, Action
(
4241 method color name get
set =
4243 (name
, `color get
, 1, Action
(
4245 let invalid = (nan
, nan
, nan
) in
4248 try color_of_string s
4250 state.text <- Printf.sprintf
"bad color `%s': %s"
4257 let te = name ^
": ", "", None
, textentry, ondone, true in
4258 state.text <- color_to_string (get
());
4259 state.mode
<- Textentry
(te, leave m_prev_mode
);
4263 method string name get
set =
4265 (name
, `
string get
, 1, Action
(
4267 let ondone s = set s in
4268 let te = name ^
": ", "", None
, textentry, ondone, true in
4269 state.mode
<- Textentry
(te, leave m_prev_mode
);
4273 method colorspace name get
set =
4275 (name
, `
string get
, 1, Action
(
4278 let vals = [| "rgb"; "bgr"; "gray" |] in
4280 inherit lvsourcebase
4283 m_active
<- int_of_colorspace conf.colorspace
;
4286 method getitemcount
= Array.length
vals
4287 method getitem
n = (vals.(n), 0)
4288 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4289 ignore
(uioh
, first, pan
, qsearch);
4290 if not cancel
then set active;
4292 method hasaction
_ = true
4296 let modehash = findkeyhash conf "info" in
4297 coe (new listview ~
source ~trusted
:true ~
modehash)
4300 method fitmodel name get
set =
4302 (name
, `
string get
, 1, Action
(
4305 let vals = [| "fit width"; "proportional"; "fit page" |] in
4307 inherit lvsourcebase
4310 m_active
<- int_of_fitmodel conf.fitmodel
;
4313 method getitemcount
= Array.length
vals
4314 method getitem
n = (vals.(n), 0)
4315 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4316 ignore
(uioh
, first, pan
, qsearch);
4317 if not cancel
then set active;
4319 method hasaction
_ = true
4323 let modehash = findkeyhash conf "info" in
4324 coe (new listview ~
source ~trusted
:true ~
modehash)
4327 method caption
s offset
=
4328 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4330 method caption2
s f offset
=
4331 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4333 method getitemcount
= Array.length m_a
4336 let tostr = function
4337 | `
int f -> string_of_int
(f ())
4338 | `intws
f -> string_with_suffix_of_int (f ())
4340 | `color
f -> color_to_string (f ())
4341 | `
bool (btos, f) -> btos (f ())
4344 let name, t
, offset
, _ = m_a
.(n) in
4345 ((let s = tostr t
in
4346 if String.length
s > 0
4347 then Printf.sprintf
"%s\t%s" name s
4351 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4355 m_qsearch
<- qsearch;
4357 match m_a
.(active) with
4358 | _, _, _, Action
f -> f uioh
4370 method hasaction
n =
4372 | _, _, _, Action
_ -> true
4376 let rec fillsrc prevmode prevuioh
=
4377 let sep () = src#caption
"" 0 in
4378 let colorp name get
set =
4380 (fun () -> color_to_string (get
()))
4383 let c = color_of_string v in
4386 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4389 let oldmode = state.mode
in
4390 let birdseye = isbirdseye state.mode
in
4392 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4394 src#
bool "presentation mode"
4395 (fun () -> conf.presentation
)
4396 (fun v -> setpresentationmode v);
4398 src#
bool "ignore case in searches"
4399 (fun () -> conf.icase
)
4400 (fun v -> conf.icase
<- v);
4403 (fun () -> conf.preload)
4404 (fun v -> conf.preload <- v);
4406 src#
bool "highlight links"
4407 (fun () -> conf.hlinks
)
4408 (fun v -> conf.hlinks
<- v);
4410 src#
bool "under info"
4411 (fun () -> conf.underinfo
)
4412 (fun v -> conf.underinfo
<- v);
4414 src#
bool "persistent bookmarks"
4415 (fun () -> conf.savebmarks
)
4416 (fun v -> conf.savebmarks
<- v);
4418 src#fitmodel
"fit model"
4419 (fun () -> fitmodel_to_string conf.fitmodel
)
4420 (fun v -> reqlayout conf.angle
(fitmodel_of_int v));
4422 src#
bool "trim margins"
4423 (fun () -> conf.trimmargins
)
4424 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4426 src#
bool "persistent location"
4427 (fun () -> conf.jumpback
)
4428 (fun v -> conf.jumpback
<- v);
4431 src#
int "inter-page space"
4432 (fun () -> conf.interpagespace
)
4434 conf.interpagespace
<- n;
4435 docolumns conf.columns
;
4437 match state.layout with
4442 state.maxy <- calcheight ();
4443 let y = getpagey pageno in
4448 (fun () -> conf.pagebias
)
4449 (fun v -> conf.pagebias
<- v);
4451 src#
int "scroll step"
4452 (fun () -> conf.scrollstep
)
4453 (fun n -> conf.scrollstep
<- n);
4455 src#
int "horizontal scroll step"
4456 (fun () -> conf.hscrollstep
)
4457 (fun v -> conf.hscrollstep
<- v);
4459 src#
int "auto scroll step"
4461 match state.autoscroll
with
4463 | _ -> conf.autoscrollstep
)
4465 if state.autoscroll
<> None
4466 then state.autoscroll
<- Some
n;
4467 conf.autoscrollstep
<- n);
4470 (fun () -> truncate
(conf.zoom *. 100.))
4471 (fun v -> setzoom ((float v) /. 100.));
4474 (fun () -> conf.angle
)
4475 (fun v -> reqlayout v conf.fitmodel
);
4477 src#
int "scroll bar width"
4478 (fun () -> state.scrollw
)
4482 reshape state.winw
state.winh
;
4485 src#
int "scroll handle height"
4486 (fun () -> conf.scrollh
)
4487 (fun v -> conf.scrollh
<- v;);
4489 src#
int "thumbnail width"
4490 (fun () -> conf.thumbw
)
4492 conf.thumbw
<- min
4096 v;
4495 leavebirdseye beye
false;
4500 let mode = state.mode in
4501 src#
string "columns"
4503 match conf.columns
with
4505 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4506 | Csplit
(count
, _) -> "-" ^ string_of_int count
4509 let n, a, b = multicolumns_of_string v in
4510 setcolumns mode n a b);
4513 src#caption
"Presentation mode" 0;
4514 src#
bool "scrollbar visible"
4515 (fun () -> conf.scrollbarinpm
)
4517 if v != conf.scrollbarinpm
4519 conf.scrollbarinpm
<- v;
4520 if conf.presentation
4522 state.scrollw
<- if v then conf.scrollbw
else 0;
4523 reshape state.winw
state.winh
;
4529 src#caption
"Pixmap cache" 0;
4530 src#int_with_suffix
"size (advisory)"
4531 (fun () -> conf.memlimit
)
4532 (fun v -> conf.memlimit
<- v);
4535 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4536 (string_with_suffix_of_int state.memused
)
4537 (Hashtbl.length
state.tilemap
)) 1;
4540 src#caption
"Layout" 0;
4541 src#caption2
"Dimension"
4543 Printf.sprintf
"%dx%d (virtual %dx%d)"
4544 state.winw
state.winh
4549 src#caption2
"Position" (fun () ->
4550 Printf.sprintf
"%dx%d" state.x state.y
4553 src#caption2
"Position" (fun () -> describe_location ()) 1
4557 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4558 "Save these parameters as global defaults at exit"
4559 (fun () -> conf.bedefault
)
4560 (fun v -> conf.bedefault
<- v)
4564 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4565 src#
bool ~offset
:0 ~
btos "Extended parameters"
4566 (fun () -> !showextended)
4567 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4571 (fun () -> conf.checkers
)
4572 (fun v -> conf.checkers
<- v; setcheckers v);
4573 src#
bool "update cursor"
4574 (fun () -> conf.updatecurs
)
4575 (fun v -> conf.updatecurs
<- v);
4577 (fun () -> conf.verbose
)
4578 (fun v -> conf.verbose
<- v);
4579 src#
bool "invert colors"
4580 (fun () -> conf.invert
)
4581 (fun v -> conf.invert
<- v);
4583 (fun () -> conf.maxhfit
)
4584 (fun v -> conf.maxhfit
<- v);
4585 src#
bool "redirect stderr"
4586 (fun () -> conf.redirectstderr)
4587 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4588 src#
string "uri launcher"
4589 (fun () -> conf.urilauncher
)
4590 (fun v -> conf.urilauncher
<- v);
4591 src#
string "path launcher"
4592 (fun () -> conf.pathlauncher
)
4593 (fun v -> conf.pathlauncher
<- v);
4594 src#
string "tile size"
4595 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4598 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4599 conf.tilew
<- max
64 w;
4600 conf.tileh
<- max
64 h;
4603 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4606 src#
int "texture count"
4607 (fun () -> conf.texcount
)
4610 then conf.texcount
<- v
4611 else showtext '
!'
" Failed to set texture count please retry later"
4613 src#
int "slice height"
4614 (fun () -> conf.sliceheight
)
4616 conf.sliceheight
<- v;
4617 wcmd "sliceh %d" conf.sliceheight
;
4619 src#
int "anti-aliasing level"
4620 (fun () -> conf.aalevel
)
4622 conf.aalevel
<- bound v 0 8;
4623 state.anchor <- getanchor ();
4624 opendoc state.path
state.password
;
4626 src#
string "page scroll scaling factor"
4627 (fun () -> string_of_float
conf.pgscale)
4630 let s = float_of_string
v in
4633 state.text <- Printf.sprintf
4634 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4637 src#
int "ui font size"
4638 (fun () -> fstate.fontsize
)
4639 (fun v -> setfontsize (bound v 5 100));
4640 src#
int "hint font size"
4641 (fun () -> conf.hfsize
)
4642 (fun v -> conf.hfsize
<- bound v 5 100);
4643 colorp "background color"
4644 (fun () -> conf.bgcolor
)
4645 (fun v -> conf.bgcolor
<- v);
4646 src#
bool "crop hack"
4647 (fun () -> conf.crophack
)
4648 (fun v -> conf.crophack
<- v);
4649 src#
string "trim fuzz"
4650 (fun () -> irect_to_string conf.trimfuzz
)
4653 conf.trimfuzz
<- irect_of_string v;
4655 then settrim true conf.trimfuzz
;
4657 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4659 src#
string "throttle"
4661 match conf.maxwait
with
4662 | None
-> "show place holder if page is not ready"
4665 then "wait for page to fully render"
4667 "wait " ^ string_of_float
time
4668 ^
" seconds before showing placeholder"
4672 let f = float_of_string
v in
4674 then conf.maxwait
<- None
4675 else conf.maxwait
<- Some
f
4677 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4679 src#
string "ghyll scroll"
4681 match conf.ghyllscroll
with
4683 | Some nab
-> ghyllscroll_to_string nab
4688 if String.length
v = 0
4690 else Some
(ghyllscroll_of_string v)
4692 conf.ghyllscroll
<- gs
4694 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4696 src#
string "selection command"
4697 (fun () -> conf.selcmd
)
4698 (fun v -> conf.selcmd
<- v);
4699 src#
string "synctex command"
4700 (fun () -> conf.stcmd
)
4701 (fun v -> conf.stcmd
<- v);
4702 src#colorspace
"color space"
4703 (fun () -> colorspace_to_string conf.colorspace
)
4705 conf.colorspace
<- colorspace_of_int v;
4712 (fun () -> conf.usepbo
)
4713 (fun v -> conf.usepbo
<- v);
4714 src#
bool "mouse wheel scrolls pages"
4715 (fun () -> conf.wheelbypage
)
4716 (fun v -> conf.wheelbypage
<- v);
4720 src#caption
"Document" 0;
4721 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4722 src#caption2
"Pages"
4723 (fun () -> string_of_int
state.pagecount
) 1;
4724 src#caption2
"Dimensions"
4725 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4729 src#caption
"Trimmed margins" 0;
4730 src#caption2
"Dimensions"
4731 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4735 src#caption
"OpenGL" 0;
4736 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4737 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4740 src#caption
"Location" 0;
4741 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4742 if String.length
state.origin
> 0
4743 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4745 src#reset prevmode prevuioh
;
4749 let prevmode = state.mode
4750 and prevuioh
= state.uioh in
4751 fillsrc prevmode prevuioh
;
4752 let source = (src :> lvsource
) in
4753 let modehash = findkeyhash conf "info" in
4754 state.uioh <- coe (object (self)
4755 inherit listview ~
source ~trusted
:true ~
modehash as super
4756 val mutable m_prevmemused
= 0
4757 method infochanged
= function
4759 if m_prevmemused
!= state.memused
4761 m_prevmemused
<- state.memused
;
4762 G.postRedisplay "memusedchanged";
4764 | Pdim
-> G.postRedisplay "pdimchanged"
4765 | Docinfo
-> fillsrc prevmode prevuioh
4767 method key key mask
=
4768 if not
(Wsi.withctrl mask
)
4771 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4772 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4773 | _ -> super#
key key mask
4774 else super#
key key mask
4776 G.postRedisplay "info";
4782 inherit lvsourcebase
4783 method getitemcount
= Array.length
state.help
4785 let s, l, _ = state.help
.(n) in
4788 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4792 m_qsearch
<- qsearch;
4793 match state.help
.(active) with
4794 | _, _, Action
f -> Some
(f uioh)
4804 method hasaction
n =
4805 match state.help
.(n) with
4806 | _, _, Action
_ -> true
4813 let modehash = findkeyhash conf "help" in
4814 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4815 G.postRedisplay "help";
4820 let re = Str.regexp
"[\r\n]" in
4822 inherit lvsourcebase
4823 val mutable m_items
= [||]
4825 method getitemcount
= 1 + Array.length m_items
4830 else m_items
.(n-1), 0
4832 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4837 then Buffer.clear
state.errmsgs
;
4838 m_qsearch
<- qsearch;
4845 method hasaction
n =
4849 state.newerrmsgs
<- false;
4850 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4851 m_items
<- Array.of_list
l
4859 let source = (msgsource :> lvsource
) in
4860 let modehash = findkeyhash conf "listview" in
4861 state.uioh <- coe (object
4862 inherit listview ~
source ~trusted
:false ~
modehash as super
4865 then msgsource#reset
;
4868 G.postRedisplay "msgs";
4871 let quickbookmark ?title
() =
4872 match state.layout with
4878 let sec = Unix.gettimeofday
() in
4879 let tm = Unix.localtime
sec in
4880 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4884 (tm.Unix.tm_year
+ 1900)
4887 | Some
title -> title
4889 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4892 let setautoscrollspeed step goingdown
=
4893 let incr = max
1 ((abs step
) / 2) in
4894 let incr = if goingdown
then incr else -incr in
4895 let astep = step
+ incr in
4896 state.autoscroll
<- Some
astep;
4899 let gotounder = function
4900 | Ulinkgoto
(pageno, top) ->
4904 gotopage1 pageno top;
4910 | Uremote
(filename
, pageno) ->
4912 if Sys.file_exists filename
4915 let dir = Filename.dirname
state.path in
4916 let path = Filename.concat
dir filename
in
4917 if Sys.file_exists
path
4921 if String.length
path > 0
4923 let anchor = getanchor () in
4924 let ranchor = state.path, state.password
, anchor, state.origin
in
4926 state.anchor <- (pageno, 0.0, 0.0);
4927 state.ranchors
<- ranchor :: state.ranchors
;
4930 else showtext '
!'
("Could not find " ^ filename
)
4932 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4936 match conf.columns
with
4938 | _ -> state.x != 0 || conf.zoom > 1.0
4941 let existsinrow pageno (columns
, coverA
, coverB
) p =
4942 let last = ((pageno - coverA
) mod columns
) + columns
in
4943 let rec any = function
4946 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4950 then (if l.pageno = last then false else any rest
)
4958 match state.layout with
4960 let pageno = page_of_y state.y in
4961 gotoghyll (getpagey (pageno+1))
4963 match conf.columns
with
4965 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4967 let y = clamp (pgscale state.winh
) in
4970 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4971 gotoghyll (getpagey pageno)
4972 | Cmulti
((c, _, _) as cl, _) ->
4973 if conf.presentation
4974 && (existsinrow l.pageno cl
4975 (fun l -> l.pageh
> l.pagey + l.pagevh))
4977 let y = clamp (pgscale state.winh
) in
4980 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
4981 gotoghyll (getpagey pageno)
4983 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
4985 let pagey, pageh
= getpageyh l.pageno in
4986 let pagey = pagey + pageh
* l.pagecol
in
4987 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
4988 gotoghyll (pagey + pageh
+ ips)
4992 match state.layout with
4994 let pageno = page_of_y state.y in
4995 gotoghyll (getpagey (pageno-1))
4997 match conf.columns
with
4999 if conf.presentation
&& l.pagey != 0
5001 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5003 let pageno = max
0 (l.pageno-1) in
5004 gotoghyll (getpagey pageno)
5005 | Cmulti
((c, _, coverB
) as cl, _) ->
5006 if conf.presentation
&&
5007 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5009 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5012 if l.pageno = state.pagecount
- coverB
5016 let pageno = max
0 (l.pageno-decr) in
5017 gotoghyll (getpagey pageno)
5025 let pageno = max
0 (l.pageno-1) in
5026 let pagey, pageh
= getpageyh pageno in
5029 let pagey, pageh
= getpageyh l.pageno in
5030 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5035 let viewkeyboard key mask
=
5037 let mode = state.mode in
5038 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5041 G.postRedisplay "view:enttext"
5043 let ctrl = Wsi.withctrl mask
in
5045 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5051 | 0xff63 -> (* insert *)
5052 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5054 state.mode <- LinkNav
(Ltgendir
0);
5057 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5059 | 0xff1b | 113 -> (* escape / q *)
5060 begin match state.mstate
with
5062 state.mstate
<- Mnone
;
5063 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5064 G.postRedisplay "kill zoom rect";
5066 begin match state.mode with
5069 G.postRedisplay "esc leave linknav"
5071 match state.ranchors
with
5073 | (path, password
, anchor, origin
) :: rest
->
5074 state.ranchors
<- rest
;
5075 state.anchor <- anchor;
5076 state.origin
<- origin
;
5077 opendoc path password
5081 | 0xff08 -> (* backspace *)
5082 gotoghyll (getnav ~
-1)
5090 G.postRedisplay "dehighlight";
5092 | 47 | 63 -> (* / ? *)
5093 let ondone isforw
s =
5094 cbput state.hists
.pat
s;
5095 state.searchpattern
<- s;
5098 let s = String.create
1 in
5099 s.[0] <- Char.chr
key;
5100 enttext (s, "", Some
(onhist state.hists
.pat
),
5101 textentry, ondone (key = 47), true)
5103 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5104 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5105 setzoom (conf.zoom +. incr)
5107 | 43 | 0xffab -> (* + *)
5110 try int_of_string
s with exc
->
5111 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5117 state.text <- "page bias is now " ^ string_of_int
n;
5120 enttext ("page bias: ", "", None
, intentry, ondone, true)
5122 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5123 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5124 setzoom (max
0.01 (conf.zoom -. decr))
5126 | 45 | 0xffad -> (* - *)
5127 let ondone msg
= state.text <- msg
in
5129 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
5130 optentry state.mode, ondone, true
5133 | 48 when ctrl -> (* ctrl-0 *)
5138 if state.w <= state.winw
- state.scrollw
5146 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5148 match conf.columns
with
5149 | Csingle
_ | Cmulti
_ -> 1
5150 | Csplit
(n, _) -> n
5152 let h = state.winh
-
5153 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5155 let zoom = zoomforh
state.winw
h state.scrollw
cols in
5156 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5159 | 51 when ctrl -> (* ctrl-3 *)
5161 match conf.fitmodel
with
5162 | FitWidth
-> FitProportional
5163 | FitProportional
-> FitPage
5164 | FitPage
-> FitWidth
5166 state.text <- "fit model: " ^
fitmodel_to_string fm;
5167 reqlayout conf.angle
fm
5169 | 0xffc6 -> (* f9 *)
5172 | 57 when ctrl -> (* ctrl-9 *)
5175 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5176 when not
ctrl -> (* 0..9 *)
5179 try int_of_string
s with exc
->
5180 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5186 cbput state.hists
.pag
(string_of_int
n);
5187 gotopage1 (n + conf.pagebias
- 1) 0;
5190 let pageentry text key =
5191 match Char.unsafe_chr
key with
5192 | '
g'
-> TEdone
text
5193 | _ -> intentry text key
5195 let text = "x" in text.[0] <- Char.chr
key;
5196 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5199 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
5200 reshape state.winw
state.winh
;
5203 conf.hlinks
<- not
conf.hlinks
;
5204 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5205 G.postRedisplay "toggle highlightlinks";
5208 state.glinks
<- true;
5209 let mode = state.mode in
5210 state.mode <- Textentry
(
5211 (":", "", None
, linknentry, linkndone gotounder, false),
5213 state.glinks
<- false;
5217 G.postRedisplay "view:linkent(F)"
5220 state.glinks
<- true;
5221 let mode = state.mode in
5222 state.mode <- Textentry
(
5224 ":", "", None
, linknentry, linkndone (fun under ->
5225 selstring (undertext under);
5229 state.glinks
<- false;
5233 G.postRedisplay "view:linkent"
5236 begin match state.autoscroll
with
5238 conf.autoscrollstep
<- step
;
5239 state.autoscroll
<- None
5241 if conf.autoscrollstep
= 0
5242 then state.autoscroll
<- Some
1
5243 else state.autoscroll
<- Some
conf.autoscrollstep
5246 | 112 when ctrl -> (* ctrl-p *)
5250 setpresentationmode (not
conf.presentation
);
5251 showtext ' '
("presentation mode " ^
5252 if conf.presentation
then "on" else "off");
5255 if List.mem
Wsi.Fullscreen
state.winstate
5256 then Wsi.reshape conf.cwinw
conf.cwinh
5257 else Wsi.fullscreen
()
5259 | 112 | 78 -> (* p|N *)
5260 search state.searchpattern
false
5262 | 110 | 0xffc0 -> (* n|F3 *)
5263 search state.searchpattern
true
5266 begin match state.layout with
5269 gotoghyll (getpagey l.pageno)
5275 | 0xff9f | 0xffff -> (* delete *)
5279 showtext ' '
(describe_location ());
5282 begin match state.layout with
5285 Wsi.reshape (l.pagew
+ state.scrollw
) l.pageh
;
5290 enterbookmarkmode ()
5292 | 104 | 0xffbe -> (* h|F1 *)
5298 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5303 match state.layout with
5305 if String.length
s > 0
5307 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5310 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5314 showtext ' '
"Quick bookmark added";
5317 begin match state.layout with
5319 let rect = getpdimrect
l.pagedimno
in
5323 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5324 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5326 (truncate
(rect.(1) -. rect.(0)),
5327 truncate
(rect.(3) -. rect.(0)))
5329 let w = truncate
((float w)*.conf.zoom)
5330 and h = truncate
((float h)*.conf.zoom) in
5333 state.anchor <- getanchor ();
5334 Wsi.reshape (w + state.scrollw
) (h + conf.interpagespace
)
5336 G.postRedisplay "z";
5341 | 60 | 62 -> (* < > *)
5342 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5344 | 91 | 93 -> (* [ ] *)
5346 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5348 G.postRedisplay "brightness";
5350 | 99 when state.mode = View
-> (* c *)
5352 match state.prevcolumns
with
5353 | None
-> (1, 0, 0), 1.0
5354 | Some
(columns
, z
) ->
5357 | Csplit
(c, _) -> -c, 0, 0
5358 | Cmulti
((c, a, b), _) -> c, a, b
5359 | Csingle
_ -> 1, 0, 0
5363 setcolumns View
c a b;
5366 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5367 setzoom state.prevzoom
5369 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5370 begin match state.autoscroll
with
5372 begin match state.mode with
5373 | Birdseye beye
-> upbirdseye 1 beye
5376 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5378 if not
(Wsi.withshift mask
) && conf.presentation
5380 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5384 setautoscrollspeed n false
5387 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5388 begin match state.autoscroll
with
5390 begin match state.mode with
5391 | Birdseye beye
-> downbirdseye 1 beye
5394 then gotoy_and_clear_text (clamp (state.winh
/2))
5396 if not
(Wsi.withshift mask
) && conf.presentation
5398 else gotoy_and_clear_text (clamp conf.scrollstep
)
5402 setautoscrollspeed n true
5405 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5406 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5412 else conf.hscrollstep
5414 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5415 state.x <- state.x + dx;
5416 gotoy_and_clear_text state.y
5419 G.postRedisplay "lef/right"
5422 | 0xff55 | 0xff9a -> (* (kp) prior *)
5426 match state.layout with
5428 | l :: _ -> state.y - l.pagey
5430 clamp (pgscale (-state.winh
))
5434 | 0xff56 | 0xff9b -> (* (kp) next *)
5438 match List.rev
state.layout with
5440 | l :: _ -> getpagey l.pageno
5442 clamp (pgscale state.winh
)
5446 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5448 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5449 gotoghyll (clamp state.maxy)
5452 when Wsi.withalt mask
-> (* alt-(kp) right *)
5453 gotoghyll (getnav 1)
5455 when Wsi.withalt mask
-> (* alt-(kp) left *)
5456 gotoghyll (getnav ~
-1)
5461 | 118 when conf.debug
-> (* v *)
5464 match getopaque l.pageno with
5467 let x0, y0, x1, y1 = pagebbox opaque
in
5468 let a,b = float x0, float y0 in
5469 let c,d = float x1, float y0 in
5470 let e,f = float x1, float y1 in
5471 let h,j
= float x0, float y1 in
5472 let rect = (a,b,c,d,e,f,h,j
) in
5474 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5476 G.postRedisplay "v";
5479 vlog "huh? %s" (Wsi.keyname
key)
5482 let linknavkeyboard key mask
linknav =
5483 let getpage pageno =
5484 let rec loop = function
5486 | l :: _ when l.pageno = pageno -> Some
l
5487 | _ :: rest
-> loop rest
5488 in loop state.layout
5490 let doexact (pageno, n) =
5491 match getopaque pageno, getpage pageno with
5492 | Some opaque
, Some
l ->
5493 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5495 let under = getlink opaque
n in
5496 G.postRedisplay "link gotounder";
5502 | 0xff50 -> (* home *)
5503 Some
(findlink opaque LDfirst
), -1
5505 | 0xff57 -> (* end *)
5506 Some
(findlink opaque LDlast
), 1
5508 | 0xff51 -> (* left *)
5509 Some
(findlink opaque
(LDleft
n)), -1
5511 | 0xff53 -> (* right *)
5512 Some
(findlink opaque
(LDright
n)), 1
5514 | 0xff52 -> (* up *)
5515 Some
(findlink opaque
(LDup
n)), -1
5517 | 0xff54 -> (* down *)
5518 Some
(findlink opaque
(LDdown
n)), 1
5523 begin match findpwl
l.pageno dir with
5527 state.mode <- LinkNav
(Ltgendir
dir);
5528 let y, h = getpageyh pageno in
5531 then y + h - state.winh
5536 begin match getopaque pageno, getpage pageno with
5537 | Some opaque
, Some
_ ->
5539 let ld = if dir > 0 then LDfirst
else LDlast
in
5542 begin match link with
5544 showlinktype (getlink opaque
m);
5545 state.mode <- LinkNav
(Ltexact
(pageno, m));
5546 G.postRedisplay "linknav jpage";
5553 begin match opt with
5554 | Some Lnotfound
-> pwl l dir;
5555 | Some
(Lfound
m) ->
5559 let _, y0, _, y1 = getlinkrect opaque
m in
5561 then gotopage1 l.pageno y0
5563 let d = fstate.fontsize
+ 1 in
5564 if y1 - l.pagey > l.pagevh - d
5565 then gotopage1 l.pageno (y1 - state.winh
- state.hscrollh + d)
5566 else G.postRedisplay "linknav";
5568 showlinktype (getlink opaque
m);
5569 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5572 | None
-> viewkeyboard key mask
5574 | _ -> viewkeyboard key mask
5579 G.postRedisplay "leave linknav"
5583 | Ltgendir
_ -> viewkeyboard key mask
5584 | Ltexact exact
-> doexact exact
5587 let keyboard key mask
=
5588 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5589 then wcmd "interrupt"
5590 else state.uioh <- state.uioh#
key key mask
5593 let birdseyekeyboard key mask
5594 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5596 match conf.columns
with
5598 | Cmulti
((c, _, _), _) -> c
5599 | Csplit
_ -> failwith
"bird's eye split mode"
5601 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5603 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5604 let y, h = getpageyh pageno in
5605 let top = (state.winh
- h) / 2 in
5606 gotoy (max
0 (y - top))
5607 | 0xff0d (* enter *)
5608 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5609 | 0xff1b -> leavebirdseye beye
true (* escape *)
5610 | 0xff52 -> upbirdseye incr beye
(* up *)
5611 | 0xff54 -> downbirdseye incr beye
(* down *)
5612 | 0xff51 -> upbirdseye 1 beye
(* left *)
5613 | 0xff53 -> downbirdseye 1 beye
(* right *)
5615 | 0xff55 -> (* prior *)
5616 begin match state.layout with
5620 state.mode <- Birdseye
(
5621 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5623 gotopage1 l.pageno 0;
5626 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5628 | [] -> gotoy (clamp (-state.winh
))
5630 state.mode <- Birdseye
(
5631 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5633 gotopage1 l.pageno 0
5636 | [] -> gotoy (clamp (-state.winh
))
5639 | 0xff56 -> (* next *)
5640 begin match List.rev
state.layout with
5642 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5643 begin match layout with
5645 let incr = l.pageh
- l.pagevh in
5650 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5652 G.postRedisplay "birdseye pagedown";
5654 else gotoy (clamp (incr + conf.interpagespace
*2));
5658 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5659 gotopage1 l.pageno 0;
5662 | [] -> gotoy (clamp state.winh
)
5665 | 0xff50 -> (* home *)
5666 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5669 | 0xff57 -> (* end *)
5670 let pageno = state.pagecount
- 1 in
5671 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5672 if not
(pagevisible state.layout pageno)
5675 match List.rev
state.pdims
with
5677 | (_, _, h, _) :: _ -> h
5679 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5680 else G.postRedisplay "birdseye end";
5681 | _ -> viewkeyboard key mask
5684 let drawpage l linkindexbase
=
5686 match state.mode with
5687 | Textentry
_ -> scalecolor 0.4
5689 | View
-> scalecolor 1.0
5690 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5691 if l.pageno = hooverpageno
5694 if l.pageno = pageno
5700 begin match getopaque l.pageno with
5702 if tileready l l.pagex
l.pagey
5704 let x = l.pagedispx - l.pagex
5705 and y = l.pagedispy - l.pagey in
5707 match conf.columns
with
5708 | Csingle
_ | Cmulti
_ ->
5709 (if conf.hlinks
then 1 else 0)
5711 && not
(isbirdseye state.mode) then 2 else 0)
5715 match state.mode with
5716 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5719 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5726 let scrollindicator () =
5727 let sbw, ph
, sh = state.uioh#
scrollph in
5728 let sbh, pw, sw = state.uioh#scrollpw
in
5730 GlDraw.color (0.64, 0.64, 0.64);
5732 (float (state.winw
- sbw), 0.)
5733 (float state.winw
, float state.winh
)
5736 (0., float (state.winh
- sbh))
5737 (float (state.winw
- state.scrollw
- 1), float state.winh
)
5739 GlDraw.color (0.0, 0.0, 0.0);
5742 (float (state.winw
- sbw), ph
)
5743 (float state.winw
, ph
+. sh)
5746 (pw, float (state.winh
- sbh))
5747 (pw +. sw, float state.winh
)
5752 match state.mstate
with
5753 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5756 | Msel
((x0, y0), (x1, y1)) ->
5757 let rec loop = function
5759 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5760 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5761 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5762 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5764 match getopaque l.pageno with
5766 let x0, y0 = pagetranslatepoint l x0 y0 in
5767 let x1, y1 = pagetranslatepoint l x1 y1 in
5768 seltext opaque
(x0, y0, x1, y1);
5776 let showrects rects
=
5778 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5779 GlDraw.polygon_mode `both `fill
;
5780 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5782 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5784 if l.pageno = pageno
5786 let dx = float (l.pagedispx - l.pagex
) in
5787 let dy = float (l.pagedispy - l.pagey) in
5788 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5789 GlDraw.begins `quads
;
5791 GlDraw.vertex2
(x0+.dx, y0+.dy);
5792 GlDraw.vertex2
(x1+.dx, y1+.dy);
5793 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5794 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5805 GlClear.color (scalecolor2 conf.bgcolor
);
5806 GlClear.clear
[`
color];
5807 let rec loop linkindexbase
= function
5809 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5810 loop linkindexbase rest
5813 loop 0 state.layout;
5815 match state.mode with
5816 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5817 begin match getopaque pageno with
5819 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5826 | None
-> state.rects
5833 begin match state.mstate
with
5834 | Mzoomrect
((x0, y0), (x1, y1)) ->
5836 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5837 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5838 GlDraw.rect (float x0, float y0)
5839 (float x1, float y1);
5848 let zoomrect x y x1 y1 =
5851 and y0 = min
y y1 in
5852 gotoy (state.y + y0);
5853 state.anchor <- getanchor ();
5854 let zoom = (float state.winw
*. conf.zoom) /. float (x1 - x0) in
5856 if state.w < state.winw
- state.scrollw
5857 then (state.winw
- state.scrollw
- state.w) / 2
5860 state.x <- (state.x + margin) - x0;
5862 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5863 state.mstate
<- Mnone
;
5867 let winw = state.winw - state.scrollw
- 1 in
5868 let s = float x /. float winw in
5869 let destx = truncate
(float (state.w + winw) *. s) in
5870 state.x <- winw - destx;
5871 gotoy_and_clear_text state.y;
5872 state.mstate
<- Mscrollx
;
5876 let s = float y /. float state.winh
in
5877 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5878 gotoy_and_clear_text desty;
5879 state.mstate
<- Mscrolly
;
5882 let viewmouse button down
x y mask
=
5884 | n when (n == 4 || n == 5) && not down
->
5885 if Wsi.withctrl mask
5887 match state.mstate
with
5888 | Mzoom
(oldn
, i
) ->
5896 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5898 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5900 let zoom = conf.zoom -. incr in
5902 state.mstate
<- Mzoom
(n, 0);
5904 state.mstate
<- Mzoom
(n, i
+1);
5906 else state.mstate
<- Mzoom
(n, 0)
5908 | _ -> state.mstate
<- Mzoom
(n, 0)
5911 match state.autoscroll
with
5912 | Some step
-> setautoscrollspeed step
(n=4)
5914 if conf.wheelbypage
|| conf.presentation
5923 then -conf.scrollstep
5924 else conf.scrollstep
5926 let incr = incr * 2 in
5927 let y = clamp incr in
5928 gotoy_and_clear_text y
5931 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5932 state.x <- state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
;
5933 gotoy_and_clear_text state.y
5935 | 1 when Wsi.withshift mask
->
5936 state.mstate
<- Mnone
;
5939 match unproject x y with
5940 | Some
(pageno, ux
, uy
) ->
5941 let cmd = Printf.sprintf
5943 conf.stcmd
state.path pageno ux uy
5949 | 1 when Wsi.withctrl mask
->
5952 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5953 state.mstate
<- Mpan
(x, y)
5956 state.mstate
<- Mnone
5961 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5963 state.mstate
<- Mzoomrect
(p, p)
5966 match state.mstate
with
5967 | Mzoomrect
((x0, y0), _) ->
5968 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5969 then zoomrect x0 y0 x y
5971 state.mstate
<- Mnone
;
5972 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5973 G.postRedisplay "kill accidental zoom rect";
5976 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5977 state.mstate
<- Mnone
5980 | 1 when x > state.winw - state.scrollw
->
5983 let _, position, sh = state.uioh#
scrollph in
5984 if y > truncate
position && y < truncate
(position +. sh)
5985 then state.mstate
<- Mscrolly
5988 state.mstate
<- Mnone
5990 | 1 when y > state.winh
- state.hscrollh ->
5993 let _, position, sw = state.uioh#scrollpw
in
5994 if x > truncate
position && x < truncate
(position +. sw)
5995 then state.mstate
<- Mscrollx
5998 state.mstate
<- Mnone
6001 let dest = if down
then getunder x y else Unone
in
6002 begin match dest with
6006 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6009 | Unone
when down
->
6010 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6011 state.mstate
<- Mpan
(x, y);
6013 | Unone
| Utext
_ ->
6016 if conf.angle
mod 360 = 0
6018 state.mstate
<- Msel
((x, y), (x, y));
6019 G.postRedisplay "mouse select";
6023 match state.mstate
with
6026 | Mzoom
_ | Mscrollx
| Mscrolly
->
6027 state.mstate
<- Mnone
6029 | Mzoomrect
((x0, y0), _) ->
6033 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6034 state.mstate
<- Mnone
6036 | Msel
((x0, y0), (x1, y1)) ->
6037 let rec loop = function
6041 let a0 = l.pagedispy in
6042 let a1 = a0 + l.pagevh in
6043 let b0 = l.pagedispx in
6044 let b1 = b0 + l.pagevw in
6045 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6046 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6050 match getopaque l.pageno with
6053 match Ne.pipe () with
6057 "can not create sel pipe: %s"
6060 let doclose what fd
=
6061 Ne.clo fd
(fun msg
->
6062 dolog
"%s close failed: %s" what msg
)
6065 popen conf.selcmd
[r, 0; w, -1];
6068 G.postRedisplay "copysel";
6070 dolog
"can not execute %S: %s"
6071 conf.selcmd
(exntos exn
);
6079 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6080 state.mstate
<- Mnone
;
6087 let birdseyemouse button down
x y mask
6088 (conf, leftx
, _, hooverpageno
, anchor) =
6091 let rec loop = function
6094 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6095 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6097 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6103 | _ -> viewmouse button down
x y mask
6106 let mouse button down
x y mask
=
6107 state.uioh <- state.uioh#button button down
x y mask
;
6111 state.uioh <- state.uioh#
motion x y
6115 state.uioh <- state.uioh#
pmotion x y;
6121 method key key mask
=
6122 begin match state.mode with
6123 | Textentry
textentry -> textentrykeyboard key mask
textentry
6124 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6125 | View
-> viewkeyboard key mask
6126 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6130 method button button bstate
x y mask
=
6131 begin match state.mode with
6133 | View
-> viewmouse button bstate
x y mask
6134 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6140 begin match state.mode with
6142 | View
| Birdseye
_ | LinkNav
_ ->
6143 match state.mstate
with
6144 | Mzoom
_ | Mnone
-> ()
6149 state.mstate
<- Mpan
(x, y);
6151 then state.x <- state.x + dx;
6153 gotoy_and_clear_text y
6156 state.mstate
<- Msel
(a, (x, y));
6157 G.postRedisplay "motion select";
6160 let y = min
state.winh
(max
0 y) in
6164 let x = min
state.winw (max
0 x) in
6167 | Mzoomrect
(p0
, _) ->
6168 state.mstate
<- Mzoomrect
(p0
, (x, y));
6169 G.postRedisplay "motion zoomrect";
6173 method pmotion x y =
6174 begin match state.mode with
6175 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6176 let rec loop = function
6178 if hooverpageno
!= -1
6180 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6181 G.postRedisplay "pmotion birdseye no hoover";
6184 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6185 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6187 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6188 G.postRedisplay "pmotion birdseye hoover";
6198 match state.mstate
with
6199 | Mnone
-> updateunder x y
6200 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6205 method infochanged
_ = ()
6208 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6211 then 0.0, float state.winh
6212 else scrollph state.y maxy
6217 let winw = state.winw - state.scrollw
- 1 in
6218 let fwinw = float winw in
6220 let sw = fwinw /. float state.w in
6221 let sw = fwinw *. sw in
6222 max
sw (float conf.scrollh
)
6225 let f = state.w+winw in
6226 let r = float (winw-state.x) /. float f in
6227 let p = fwinw *. r in
6231 if position +. sw > fwinw
6232 then fwinw -. position
6235 state.hscrollh, position, sw
6239 match state.mode with
6240 | LinkNav
_ -> "links"
6241 | Textentry
_ -> "textentry"
6242 | Birdseye
_ -> "birdseye"
6245 findkeyhash conf modename
6247 method eformsgs
= true
6254 let fontpath = ref "";;
6257 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6260 let l = String.length
s in
6261 let b = Buffer.create
l in
6267 try Sys.getenv
"HOME"
6270 ("Can not determine home directory location: " ^ exntos exn
);
6274 let modifier_of_string = function
6275 | "alt" -> Wsi.altmask
6276 | "shift" -> Wsi.shiftmask
6277 | "ctrl" | "control" -> Wsi.ctrlmask
6278 | "meta" -> Wsi.metamask
6283 let r = Str.regexp
"-" in
6285 let elems = Str.full_split
r s in
6288 let m1 = modifier_of_string s in
6290 then (Wsi.namekey
s, m)
6293 | Str.Delim
s when n land 1 = 0 -> g s
6295 | Str.Delim
_ -> (k
, m)
6297 let rec loop n k
m = function
6300 let k, m = f n k m x in
6306 let keys_of_string =
6307 let r = Str.regexp
"[ \t]" in
6309 let elems = Str.split
r s in
6310 List.map
key_of_string elems
6313 let copykeyhashes c =
6314 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6317 let config_of c attrs
=
6321 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6322 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6323 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6324 | "preload" -> { c with preload = bool_of_string
v }
6325 | "page-bias" -> { c with pagebias
= int_of_string
v }
6326 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6327 | "horizontal-scroll-step" ->
6328 { c with hscrollstep
= max
(int_of_string
v) 1 }
6329 | "auto-scroll-step" ->
6330 { c with autoscrollstep
= max
0 (int_of_string
v) }
6331 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6332 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6335 match String.lowercase
v with
6336 | "true" -> Some infinity
6338 | f -> Some
(float_of_string
f)
6340 { c with maxwait
= mw}
6341 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6342 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6343 | "vertical-margin" ->
6344 { c with interpagespace
= max
0 (int_of_string
v) }
6346 let zoom = float_of_string
v /. 100. in
6347 let zoom = max
zoom 0.0 in
6348 { c with zoom = zoom }
6349 | "presentation" -> { c with presentation
= bool_of_string
v }
6350 | "rotation-angle" -> { c with angle
= int_of_string
v }
6351 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6352 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6353 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6354 | "proportional-display" ->
6357 then FitProportional
6360 { c with fitmodel
= fm }
6361 | "fit-model" -> { c with fitmodel
= fitmodel_of_string v }
6362 | "pixmap-cache-size" ->
6363 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6364 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6365 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6366 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6367 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6368 | "background-color" -> { c with bgcolor
= color_of_string v }
6369 | "scrollbar-in-presentation" ->
6370 { c with scrollbarinpm
= bool_of_string
v }
6371 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6372 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6373 | "mupdf-store-size" ->
6374 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6375 | "checkers" -> { c with checkers
= bool_of_string
v }
6376 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6377 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6378 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6379 | "uri-launcher" -> { c with urilauncher
= unent v }
6380 | "path-launcher" -> { c with pathlauncher
= unent v }
6381 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6382 | "invert-colors" -> { c with invert
= bool_of_string
v }
6383 | "brightness" -> { c with colorscale
= float_of_string
v }
6384 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6386 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6388 let (n, _, _) as nab
= multicolumns_of_string v in
6390 then { c with columns
= Csplit
(-n, [||]) }
6391 else { c with columns
= Cmulti
(nab
, [||]) }
6392 | "birds-eye-columns" ->
6393 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6394 | "selection-command" -> { c with selcmd
= unent v }
6395 | "synctex-command" -> { c with stcmd
= unent v }
6396 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6397 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6398 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6399 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6400 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6403 prerr_endline
("Error processing attribute (`" ^
6404 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6407 let rec fold c = function
6410 let c = apply c k v in
6413 fold { c with keyhashes
= copykeyhashes c } attrs
;
6416 let fromstring f pos
n v d =
6419 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6420 n v pos
(exntos exn
)
6425 let bookmark_of attrs
=
6426 let rec fold title page
rely visy
= function
6427 | ("title", v) :: rest
-> fold v page
rely visy rest
6428 | ("page", v) :: rest
-> fold title v rely visy rest
6429 | ("rely", v) :: rest
-> fold title page
v visy rest
6430 | ("visy", v) :: rest
-> fold title page
rely v rest
6431 | _ :: rest
-> fold title page
rely visy rest
6432 | [] -> title, page
, rely, visy
6434 fold "invalid" "0" "0" "0" attrs
6438 let rec fold path page
rely pan visy
= function
6439 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6440 | ("page", v) :: rest
-> fold path v rely pan visy rest
6441 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6442 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6443 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6444 | _ :: rest
-> fold path page
rely pan visy rest
6445 | [] -> path, page
, rely, pan
, visy
6447 fold "" "0" "0" "0" "0" attrs
6451 let rec fold rs ls
= function
6452 | ("out", v) :: rest
-> fold v ls rest
6453 | ("in", v) :: rest
-> fold rs
v rest
6454 | _ :: rest
-> fold ls rs rest
6460 let setconf dst
src =
6461 dst
.scrollbw
<- src.scrollbw
;
6462 dst
.scrollh
<- src.scrollh
;
6463 dst
.icase
<- src.icase
;
6464 dst
.preload <- src.preload;
6465 dst
.pagebias
<- src.pagebias
;
6466 dst
.verbose
<- src.verbose
;
6467 dst
.scrollstep
<- src.scrollstep
;
6468 dst
.maxhfit
<- src.maxhfit
;
6469 dst
.crophack
<- src.crophack
;
6470 dst
.autoscrollstep
<- src.autoscrollstep
;
6471 dst
.maxwait
<- src.maxwait
;
6472 dst
.hlinks
<- src.hlinks
;
6473 dst
.underinfo
<- src.underinfo
;
6474 dst
.interpagespace
<- src.interpagespace
;
6475 dst
.zoom <- src.zoom;
6476 dst
.presentation
<- src.presentation
;
6477 dst
.angle
<- src.angle
;
6478 dst
.cwinw
<- src.cwinw
;
6479 dst
.cwinh
<- src.cwinh
;
6480 dst
.savebmarks
<- src.savebmarks
;
6481 dst
.memlimit
<- src.memlimit
;
6482 dst
.fitmodel
<- src.fitmodel
;
6483 dst
.texcount
<- src.texcount
;
6484 dst
.sliceheight
<- src.sliceheight
;
6485 dst
.thumbw
<- src.thumbw
;
6486 dst
.jumpback
<- src.jumpback
;
6487 dst
.bgcolor
<- src.bgcolor
;
6488 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6489 dst
.tilew
<- src.tilew
;
6490 dst
.tileh
<- src.tileh
;
6491 dst
.mustoresize
<- src.mustoresize
;
6492 dst
.checkers
<- src.checkers
;
6493 dst
.aalevel
<- src.aalevel
;
6494 dst
.trimmargins
<- src.trimmargins
;
6495 dst
.trimfuzz
<- src.trimfuzz
;
6496 dst
.urilauncher
<- src.urilauncher
;
6497 dst
.colorspace
<- src.colorspace
;
6498 dst
.invert
<- src.invert
;
6499 dst
.colorscale
<- src.colorscale
;
6500 dst
.redirectstderr <- src.redirectstderr;
6501 dst
.ghyllscroll
<- src.ghyllscroll
;
6502 dst
.columns
<- src.columns
;
6503 dst
.beyecolumns
<- src.beyecolumns
;
6504 dst
.selcmd
<- src.selcmd
;
6505 dst
.updatecurs
<- src.updatecurs
;
6506 dst
.pathlauncher
<- src.pathlauncher
;
6507 dst
.keyhashes
<- copykeyhashes src;
6508 dst
.hfsize
<- src.hfsize
;
6509 dst
.hscrollstep
<- src.hscrollstep
;
6510 dst
.pgscale <- src.pgscale;
6511 dst
.usepbo
<- src.usepbo
;
6512 dst
.wheelbypage
<- src.wheelbypage
;
6513 dst
.stcmd
<- src.stcmd
;
6517 let h = Hashtbl.create
10 in
6518 let dc = { defconf with angle
= defconf.angle
} in
6519 let rec toplevel v t spos
_ =
6521 | Vdata
| Vcdata
| Vend
-> v
6522 | Vopen
("llppconfig", _, closed
) ->
6525 else { v with f = llppconfig
}
6527 error
"unexpected subelement at top level" s spos
6528 | Vclose
_ -> error
"unexpected close at top level" s spos
6530 and llppconfig
v t spos
_ =
6532 | Vdata
| Vcdata
-> v
6533 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6534 | Vopen
("defaults", attrs
, closed
) ->
6535 let c = config_of dc attrs
in
6539 else { v with f = defaults
}
6541 | Vopen
("ui-font", attrs
, closed
) ->
6542 let rec getsize size
= function
6544 | ("size", v) :: rest
->
6546 fromstring int_of_string spos
"size" v fstate.fontsize
in
6548 | l -> getsize size l
6550 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6553 else { v with f = uifont
(Buffer.create
10) }
6555 | Vopen
("doc", attrs
, closed
) ->
6556 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6557 let path = unent pathent
6558 and pageno = fromstring int_of_string spos
"page" spage
0
6559 and rely = fromstring float_of_string spos
"rely" srely
0.0
6560 and pan
= fromstring int_of_string spos
"pan" span
0
6561 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6562 let c = config_of dc attrs
in
6563 let anchor = (pageno, rely, visy
) in
6565 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6566 else { v with f = doc
path pan
anchor c [] }
6569 error
"unexpected subelement in llppconfig" s spos
6571 | Vclose
"llppconfig" -> { v with f = toplevel }
6572 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6574 and defaults
v t spos
_ =
6576 | Vdata
| Vcdata
-> v
6577 | Vend
-> error
"unexpected end of input in defaults" s spos
6578 | Vopen
("keymap", attrs
, closed
) ->
6580 try List.assoc
"mode" attrs
6581 with Not_found
-> "global" in
6586 let h = findkeyhash dc modename in
6587 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6590 { v with f = pkeymap
ret KeyMap.empty }
6592 | Vopen
(_, _, _) ->
6593 error
"unexpected subelement in defaults" s spos
6595 | Vclose
"defaults" ->
6596 { v with f = llppconfig
}
6598 | Vclose
_ -> error
"unexpected close in defaults" s spos
6600 and uifont
b v t spos
epos =
6603 Buffer.add_substring
b s spos
(epos - spos
);
6605 | Vopen
(_, _, _) ->
6606 error
"unexpected subelement in ui-font" s spos
6607 | Vclose
"ui-font" ->
6608 if String.length
!fontpath = 0
6609 then fontpath := Buffer.contents
b;
6610 { v with f = llppconfig
}
6611 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6612 | Vend
-> error
"unexpected end of input in ui-font" s spos
6614 and doc
path pan
anchor c bookmarks
v t spos
_ =
6616 | Vdata
| Vcdata
-> v
6617 | Vend
-> error
"unexpected end of input in doc" s spos
6618 | Vopen
("bookmarks", _, closed
) ->
6621 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6623 | Vopen
("keymap", attrs
, closed
) ->
6625 try List.assoc
"mode" attrs
6626 with Not_found
-> "global"
6632 let h = findkeyhash c modename in
6633 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6634 doc
path pan
anchor c bookmarks
6636 { v with f = pkeymap
ret KeyMap.empty }
6638 | Vopen
(_, _, _) ->
6639 error
"unexpected subelement in doc" s spos
6642 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6643 { v with f = llppconfig
}
6645 | Vclose
_ -> error
"unexpected close in doc" s spos
6647 and pkeymap
ret keymap
v t spos
_ =
6649 | Vdata
| Vcdata
-> v
6650 | Vend
-> error
"unexpected end of input in keymap" s spos
6651 | Vopen
("map", attrs
, closed
) ->
6652 let r, l = map_of attrs
in
6653 let kss = fromstring keys_of_string spos
"in" r [] in
6654 let lss = fromstring keys_of_string spos
"out" l [] in
6658 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6659 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6662 then { v with f = pkeymap
ret keymap }
6665 { v with f = skip
"map" f }
6668 error
"unexpected subelement in keymap" s spos
6670 | Vclose
"keymap" ->
6671 { v with f = ret keymap }
6673 | Vclose
_ -> error
"unexpected close in keymap" s spos
6675 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6677 | Vdata
| Vcdata
-> v
6678 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6679 | Vopen
("item", attrs
, closed
) ->
6680 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6681 let page = fromstring int_of_string spos
"page" spage
0
6682 and rely = fromstring float_of_string spos
"rely" srely
0.0
6683 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6685 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6688 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6691 { v with f = skip
"item" f }
6694 error
"unexpected subelement in bookmarks" s spos
6696 | Vclose
"bookmarks" ->
6697 { v with f = doc
path pan
anchor c bookmarks }
6699 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6701 and skip tag
f v t spos
_ =
6703 | Vdata
| Vcdata
-> v
6705 error
("unexpected end of input in skipped " ^ tag
) s spos
6706 | Vopen
(tag'
, _, closed
) ->
6710 let f'
() = { v with f = skip tag
f } in
6711 { v with f = skip tag'
f'
}
6715 else error
("unexpected close in skipped " ^ tag
) s spos
6718 parse
{ f = toplevel; accu = () } s;
6724 let len = in_channel_length ic
in
6725 let s = String.create
len in
6726 really_input ic
s 0 len;
6729 | Parse_error
(msg
, s, pos
) ->
6730 let subs = subs s pos
in
6731 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6732 failwith
("parse error: " ^
s)
6735 failwith
("config load error: " ^ exntos exn
)
6741 let dir = Filename.concat
home ".config" in
6742 if Sys.is_directory
dir then dir else home
6745 Filename.concat
dir "llpp.conf"
6748 let confpath = ref defconfpath;;
6751 if Sys.file_exists
!confpath
6754 (try Some
(open_in_bin
!confpath)
6757 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6768 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6777 f (Hashtbl.create
0, defconf)
6782 let pc, pb
, px, pa
=
6785 if String.length
state.origin
= 0
6789 Hashtbl.find h (Filename.basename
key)
6790 with Not_found
-> dc, [], 0, emptyanchor
6794 state.bookmarks <- pb
;
6796 state.scrollw
<- conf.scrollbw
;
6798 then state.anchor <- pa
;
6799 cbput state.hists
.nav pa
;
6805 let add_attrs bb always
dc c =
6808 then Printf.bprintf bb
"\n %s='%b'" s a
6811 then Printf.bprintf bb
"\n %s='%d'" s a
6814 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6817 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6820 then Printf.bprintf bb
"\n %s='%f'" s a
6824 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6828 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6832 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6836 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6842 | Some
(_N
, _A
, _B
) ->
6843 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6853 else string_of_float
f
6855 Printf.bprintf bb
"\n %s='%s'" s v
6860 | Cmulti
((n, a, b), _) when n > 1 ->
6861 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6862 | Csplit
(n, _) when n > 1 ->
6863 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6869 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6874 Printf.bprintf bb
"\n %s='%s'" s (fitmodel_to_string a)
6876 oi
"width" c.cwinw
dc.cwinw
;
6877 oi
"height" c.cwinh
dc.cwinh
;
6878 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6879 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6880 ob "case-insensitive-search" c.icase
dc.icase
;
6881 ob "preload" c.preload dc.preload;
6882 oi
"page-bias" c.pagebias
dc.pagebias
;
6883 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6884 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6885 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6886 ob "crop-hack" c.crophack
dc.crophack
;
6887 oW
"throttle" c.maxwait
dc.maxwait
;
6888 ob "highlight-links" c.hlinks
dc.hlinks
;
6889 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6890 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6891 oz
"zoom" c.zoom dc.zoom;
6892 ob "presentation" c.presentation
dc.presentation
;
6893 oi
"rotation-angle" c.angle
dc.angle
;
6894 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6895 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
6896 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6897 oi
"tex-count" c.texcount
dc.texcount
;
6898 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6899 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6900 ob "persistent-location" c.jumpback
dc.jumpback
;
6901 oc
"background-color" c.bgcolor
dc.bgcolor
;
6902 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6903 oi
"tile-width" c.tilew
dc.tilew
;
6904 oi
"tile-height" c.tileh
dc.tileh
;
6905 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6906 ob "checkers" c.checkers
dc.checkers
;
6907 oi
"aalevel" c.aalevel
dc.aalevel
;
6908 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6909 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6910 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6911 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6912 oC
"color-space" c.colorspace
dc.colorspace
;
6913 ob "invert-colors" c.invert
dc.invert
;
6914 oF
"brightness" c.colorscale
dc.colorscale
;
6915 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6916 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6917 oco
"columns" c.columns
dc.columns
;
6918 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6919 os
"selection-command" c.selcmd
dc.selcmd
;
6920 os
"synctex-command" c.stcmd
dc.stcmd
;
6921 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6922 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6923 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6924 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6925 ob "use-pbo" c.usepbo
dc.usepbo
;
6926 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6929 let keymapsbuf always
dc c =
6930 let bb = Buffer.create
16 in
6931 let rec loop = function
6933 | (modename, h) :: rest
->
6934 let dh = findkeyhash dc modename in
6935 if always
|| h <> dh
6937 if Hashtbl.length
h > 0
6939 if Buffer.length
bb > 0
6940 then Buffer.add_char
bb '
\n'
;
6941 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6942 Hashtbl.iter
(fun i
o ->
6943 let isdifferent = always
||
6945 let dO = Hashtbl.find dh i
in
6947 with Not_found
-> true
6952 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6953 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6954 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6955 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6956 Buffer.add_string
bb (Wsi.keyname
k);
6959 let rec loop = function
6961 | km
:: [] -> addkm km
6962 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6966 Buffer.add_string
bb "<map in='";
6970 Buffer.add_string
bb "' out='";
6972 Buffer.add_string
bb "'/>\n"
6975 Buffer.add_string
bb "' out='";
6977 Buffer.add_string
bb "'/>\n"
6979 | KMmulti
(ins, kms
) ->
6980 Buffer.add_char
bb ' '
;
6982 Buffer.add_string
bb "' out='";
6984 Buffer.add_string
bb "'/>\n"
6986 Buffer.add_string
bb "</keymap>";
6996 let uifontsize = fstate.fontsize
in
6997 let bb = Buffer.create
32768 in
7002 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
)
7003 | Wsi.MaxVert
-> (w, conf.cwinh
)
7004 | Wsi.MaxHorz
-> (conf.cwinw
, h)
7006 (state.winw, state.winh
) state.winstate
7011 let dc = if conf.bedefault
then conf else dc in
7012 Buffer.add_string
bb "<llppconfig>\n";
7014 if String.length
!fontpath > 0
7016 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7022 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7025 Buffer.add_string
bb "<defaults ";
7026 add_attrs bb true dc dc;
7027 let kb = keymapsbuf true dc dc in
7028 if Buffer.length
kb > 0
7030 Buffer.add_string
bb ">\n";
7031 Buffer.add_buffer
bb kb;
7032 Buffer.add_string
bb "\n</defaults>\n";
7034 else Buffer.add_string
bb "/>\n";
7036 let adddoc path pan
anchor c bookmarks =
7037 if bookmarks == [] && c = dc && anchor = emptyanchor
7040 Printf.bprintf
bb "<doc path='%s'"
7041 (enent
path 0 (String.length
path));
7043 if anchor <> emptyanchor
7045 let n, rely, visy
= anchor in
7046 Printf.bprintf
bb " page='%d'" n;
7049 Printf.bprintf
bb " rely='%f'" rely
7051 if abs_float visy
> 1e-6
7053 Printf.bprintf
bb " visy='%f'" visy
7058 then Printf.bprintf
bb " pan='%d'" pan
;
7060 add_attrs bb false dc c;
7061 let kb = keymapsbuf false dc c in
7063 begin match bookmarks with
7065 if Buffer.length
kb > 0
7067 Buffer.add_string
bb ">\n";
7068 Buffer.add_buffer
bb kb;
7069 Buffer.add_string
bb "\n</doc>\n";
7071 else Buffer.add_string
bb "/>\n"
7073 Buffer.add_string
bb ">\n<bookmarks>\n";
7074 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7076 "<item title='%s' page='%d'"
7077 (enent
title 0 (String.length
title))
7082 Printf.bprintf
bb " rely='%f'" rely
7084 if abs_float visy
> 1e-6
7086 Printf.bprintf
bb " visy='%f'" visy
7088 Buffer.add_string
bb "/>\n";
7090 Buffer.add_string
bb "</bookmarks>";
7091 if Buffer.length
kb > 0
7093 Buffer.add_string
bb "\n";
7094 Buffer.add_buffer
bb kb;
7096 Buffer.add_string
bb "\n</doc>\n";
7102 match state.mode with
7103 | Birdseye
(c, pan, _, _, _) ->
7105 match conf.columns
with
7106 | Cmulti
((c, _, _), _) -> Some
c
7110 match c.columns
with
7111 | Cmulti
(c, _) -> Cmulti
(c, [||])
7112 | Csingle
_ -> Csingle
[||]
7113 | Csplit
_ -> failwith
"quit from bird's eye while split"
7115 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7116 | _ -> state.x, conf
7118 let basename = Filename.basename
7119 (if String.length
state.origin
= 0 then state.path else state.origin
)
7121 adddoc basename pan (getanchor ())
7123 let autoscrollstep =
7124 match state.autoscroll
with
7126 | None
-> conf.autoscrollstep
7128 match state.mode with
7129 | Birdseye
(bc
, _, _, _, _) ->
7132 presentation
= bc
.presentation
;
7133 interpagespace
= bc
.interpagespace
;
7134 maxwait
= bc
.maxwait
;
7135 autoscrollstep = autoscrollstep }
7136 | _ -> { conf with autoscrollstep = autoscrollstep }
7138 (if conf.savebmarks
then state.bookmarks else []);
7140 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7142 then adddoc path x anchor c bookmarks
7144 Buffer.add_string
bb "</llppconfig>\n";
7147 if load1 f && Buffer.length
bb > 0
7150 let tmp = !confpath ^
".tmp" in
7151 let oc = open_out_bin
tmp in
7152 Buffer.output_buffer
oc bb;
7154 Unix.rename
tmp !confpath;
7157 ("error while saving configuration: " ^ exntos exn
)
7161 let adderrmsg src msg
=
7162 Buffer.add_string
state.errmsgs msg
;
7163 state.newerrmsgs
<- true;
7167 let adderrfmt src fmt
=
7168 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7172 let cl = splitatspace cmds
in
7174 try Scanf.sscanf
s fmt
f
7176 adderrfmt "remote exec"
7177 "error processing '%S': %s\n" cmds
(exntos exn
)
7180 | "reload" :: [] -> reload ()
7181 | "goto" :: args :: [] ->
7182 scan args "%u %f %f"
7184 let cmd, _ = state.geomcmds
in
7185 if String.length
cmd = 0
7186 then gotopagexy pageno x y
7189 gotopagexy pageno x y;
7192 state.reprf
<- f state.reprf
7194 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7195 | "rect" :: args :: [] ->
7196 scan args "%u %u %f %f %f %f"
7197 (fun pageno color x0 y0 x1 y1 ->
7198 onpagerect pageno (fun w h ->
7199 let _,w1,h1
,_ = getpagedim pageno in
7200 let sw = float w1 /. w
7201 and sh = float h1
/. h in
7205 and y1s
= y1 *. sh in
7206 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7208 state.rects <- (pageno, color, rect) :: state.rects;
7209 G.postRedisplay "rect";
7212 | "activatewin" :: [] -> Wsi.activatewin
()
7213 | "quit" :: [] -> raise Quit
7215 adderrfmt "remote command"
7216 "error processing remote command: %S\n" cmds
;
7220 let scratch = String.create
80 in
7221 let buf = Buffer.create
80 in
7224 try Some
(Unix.read fd
scratch 0 80)
7226 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7227 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7230 match tempfr () with
7236 if Buffer.length
buf > 0
7238 let s = Buffer.contents
buf in
7248 let pos = String.index_from
scratch ppos '
\n'
in
7249 if pos >= n then -1 else pos
7250 with Not_found
-> -1
7254 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7255 let s = Buffer.contents
buf in
7261 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7267 let remoteopen path =
7268 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7270 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7275 let trimcachepath = ref "" in
7276 let rcmdpath = ref "" in
7279 [("-p", Arg.String
(fun s -> state.password
<- s),
7280 "<password> Set password");
7282 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7283 "<path> Set path to the user interface font");
7285 ("-c", Arg.String
(fun s -> Config.confpath := s),
7286 "<path> Set path to the configuration file");
7288 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7289 "<path> Set path to the trim cache file");
7291 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7292 "<named-destination> Set named destination");
7294 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7296 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7297 "<path> Set path to the remote commands source");
7299 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7300 "<original path> Set original path");
7302 ("-v", Arg.Unit
(fun () ->
7304 "%s\nconfiguration path: %s\n"
7308 exit
0), " Print version and exit");
7311 (fun s -> state.path <- s)
7312 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7314 if String.length
state.path = 0
7315 then (prerr_endline
"file name missing"; exit
1);
7317 if not
(Config.load ())
7318 then prerr_endline
"failed to load configuration";
7320 let globalkeyhash = findkeyhash conf "global" in
7321 let wsfd, winw, winh
= Wsi.init
(object
7323 if nogeomcmds state.geomcmds
|| platform == Posx
7326 GlClear.color (scalecolor2 conf.bgcolor
);
7327 GlClear.clear
[`
color];
7329 method display = display ()
7330 method reshape w h = reshape w h
7331 method mouse b d x y m = mouse b d x y m
7332 method motion x y = state.mpos
<- (x, y); motion x y
7333 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7335 let mascm = m land (
7336 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7338 match state.keystate
with
7340 let km = k, mascm in
7343 let modehash = state.uioh#
modehash in
7344 try Hashtbl.find modehash km
7346 try Hashtbl.find globalkeyhash km
7347 with Not_found
-> KMinsrt
(k, m)
7349 | KMinsrt
(k, m) -> keyboard k m
7350 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7351 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7353 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7354 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7355 state.keystate
<- KSnone
7356 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7357 state.keystate
<- KSinto
(keys
, insrt
)
7359 state.keystate
<- KSnone
7361 method enter
x y = state.mpos
<- (x, y); pmotion x y
7362 method leave = state.mpos
<- (-1, -1)
7363 method winstate wsl
= state.winstate
<- wsl
7364 method quit
= raise Quit
7365 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7370 List.exists
GlMisc.check_extension
7371 [ "GL_ARB_texture_rectangle"
7372 ; "GL_EXT_texture_recangle"
7373 ; "GL_NV_texture_rectangle" ]
7375 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7378 match Ne.pipe () with
7380 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7384 match Ne.pipe () with
7386 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7396 setcheckers conf.checkers
;
7400 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7401 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7402 !Config.fontpath, !trimcachepath,
7403 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7407 state.text <- "Opening " ^
(mbtoutf8
state.path);
7409 opendoc state.path state.password
;
7412 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7415 if String.length
!rcmdpath > 0
7416 then remoteopen !rcmdpath
7421 let rec loop deadline
=
7423 match state.errfd
with
7424 | None
-> [state.sr
; state.wsfd]
7425 | Some fd
-> [state.sr
; state.wsfd; fd
]
7430 | Some fd
-> fd
:: r
7434 state.redisplay
<- false;
7441 if deadline
= infinity
7443 else max
0.0 (deadline
-. now)
7448 try Unix.select
r [] [] timeout
7449 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7455 if state.ghyll
== noghyll
7457 match state.autoscroll
with
7458 | Some step
when step
!= 0 ->
7459 let y = state.y + step
in
7463 else if y >= state.maxy then 0 else y
7466 if state.mode = View
7467 then state.text <- "";
7470 else deadline
+. 0.01
7475 let rec checkfds = function
7477 | fd
:: rest
when fd
= state.sr
->
7478 let cmd = readcmd state.sr
in
7482 | fd
:: rest
when fd
= state.wsfd ->
7486 | fd
:: rest
when Some fd
= !optrfd ->
7487 begin match remote fd
with
7488 | None
-> optrfd := remoteopen !rcmdpath;
7489 | opt -> optrfd := opt
7494 let s = String.create
80 in
7495 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7496 if conf.redirectstderr
7498 Buffer.add_substring
state.errmsgs
s 0 n;
7499 state.newerrmsgs
<- true;
7500 state.redisplay
<- true;
7503 prerr_string
(String.sub
s 0 n);
7511 if deadline
= infinity
7515 match state.autoscroll
with
7516 | Some step
when step
!= 0 -> deadline1
7517 | _ -> if state.ghyll
== noghyll then infinity
else deadline1