8 | Ulinkgoto
of (int * int)
10 | Uunexpected
of string
13 | Uremote
of (string * int)
14 and facename
= string;;
16 type params
= (angle
* fitmodel
* trimparams
17 * texcount
* sliceheight
* memsize
18 * colorspace
* fontpath
* trimcachepath
28 and trimmargins
= bool
29 and interpagespace
= int
36 and trimcachepath
= string
39 and irect
= (int * int * int * int)
40 and trimparams
= (trimmargins
* irect
)
41 and colorspace
= | Rgb
| Bgr
| Gray
42 and fitmodel
= | FitWidth
| FitProportional
| FitPage
50 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
59 | LDfirstvisible
of (int * int * int)
74 | KMmulti
of key list
* key list
76 and keyhash
= (key
, keymap
) Hashtbl.t
79 | KSinto
of (key list
* key list
)
82 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
83 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
85 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
87 external init
: pipe
-> params
-> unit = "ml_init";;
88 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
89 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
90 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
91 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
92 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
93 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
94 external measurestr
: int -> string -> float = "ml_measure_string";;
95 external postprocess
:
96 opaque
-> int -> int -> int -> (int * string * int) -> int
98 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
99 external platform
: unit -> platform
= "ml_platform";;
100 external setaalevel
: int -> unit = "ml_setaalevel";;
101 external realloctexts
: int -> bool = "ml_realloctexts";;
102 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
103 external getlink
: opaque
-> int -> under
= "ml_getlink";;
104 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
105 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
106 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
107 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
108 external getpbo
: width
-> height
-> colorspace
-> string = "ml_getpbo";;
109 external freepbo
: string -> unit = "ml_freepbo";;
110 external unmappbo
: string -> unit = "ml_unmappbo";;
111 external pbousable
: unit -> bool = "ml_pbo_usable";;
112 external unproject
: opaque
-> int -> int -> (int * int) option
114 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
116 let platform_to_string = function
117 | Punknown
-> "unknown"
121 | Pfreebsd
-> "FreeBSD"
122 | Pdragonflybsd
-> "DragonflyBSD"
123 | Popenbsd
-> "OpenBSD"
124 | Pnetbsd
-> "NetBSD"
125 | Pcygwin
-> "Cygwin"
128 let platform = platform ();;
130 let now = Unix.gettimeofday
;;
133 if platform = Pcygwin
135 let sh = "/bin/sh" in
136 let args = [|sh; "-c"; cmd
|] in
137 let rec std si so se
= function
139 | (fd
, 0) :: rest
-> std fd so se rest
140 | (fd
, -1) :: rest
->
141 Unix.set_close_on_exec fd
;
144 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
146 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
147 ignore
(Unix.create_process
sh args si so se
)
152 type mpos
= int * int
154 | Msel
of (mpos
* mpos
)
156 | Mscrolly
| Mscrollx
157 | Mzoom
of (int * int)
158 | Mzoomrect
of (mpos
* mpos
)
162 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
163 and onkey
= string -> int -> te
164 and ondone
= string -> unit
165 and histcancel
= unit -> unit
166 and onhist
= ((histcmd
-> string) * histcancel
)
167 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
168 and cancelonempty
= bool
173 | TEswitch
of textentry
184 let bound v minv maxv
=
185 max minv
(min maxv v
);
189 { store
= Array.create n v
196 let cbcap b
= Array.length b
.store
;;
201 b
.wc
<- (b
.wc
+ 1) mod cap;
203 b
.len
<- min
(b
.len
+ 1) cap;
206 let cbempty b
= b
.len
= 0;;
208 let cbgetg b circular dir
=
212 let rc = b
.rc + dir
in
224 else bound rc 0 (b
.len
-1)
230 let cbget b
= cbgetg b
false;;
231 let cbgetc b
= cbgetg b
true;;
233 let drawstring size x y s
=
235 Gl.enable `texture_2d
;
236 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
237 ignore
(drawstr size x y s
);
239 Gl.disable `texture_2d
;
242 let drawstring1 size x y s
=
246 let drawstring2 size x y fmt
=
247 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
266 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
267 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
268 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
269 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
270 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
271 dolog
" column %d" l
.pagecol
;
275 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
277 dolog
" x0,y0=(% f, % f)" x0 y0
;
278 dolog
" x1,y1=(% f, % f)" x1 y1
;
279 dolog
" x2,y2=(% f, % f)" x2 y2
;
280 dolog
" x3,y3=(% f, % f)" x3 y3
;
284 type multicolumns
= multicol
* pagegeom
285 and singlecolumn
= pagegeom
286 and splitcolumns
= columncount
* pagegeom
287 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
288 and multicol
= columncount
* covercount
* covercount
290 and columncount
= int
291 and covercount
= int;;
298 { mutable scrollbw
: int
299 ; mutable scrollh
: int
300 ; mutable scrollb
: scrollb
301 ; mutable icase
: bool
302 ; mutable preload
: bool
303 ; mutable pagebias
: int
304 ; mutable verbose
: bool
305 ; mutable debug
: bool
306 ; mutable scrollstep
: int
307 ; mutable hscrollstep
: int
308 ; mutable maxhfit
: bool
309 ; mutable crophack
: bool
310 ; mutable autoscrollstep
: int
311 ; mutable maxwait
: float option
312 ; mutable hlinks
: bool
313 ; mutable underinfo
: bool
314 ; mutable interpagespace
: interpagespace
315 ; mutable zoom
: float
316 ; mutable presentation
: bool
317 ; mutable angle
: angle
318 ; mutable cwinw
: int
319 ; mutable cwinh
: int
320 ; mutable savebmarks
: bool
321 ; mutable fitmodel
: fitmodel
322 ; mutable trimmargins
: trimmargins
323 ; mutable trimfuzz
: irect
324 ; mutable memlimit
: memsize
325 ; mutable texcount
: texcount
326 ; mutable sliceheight
: sliceheight
327 ; mutable thumbw
: width
328 ; mutable jumpback
: bool
329 ; mutable bgcolor
: (float * float * float)
330 ; mutable bedefault
: bool
331 ; mutable tilew
: int
332 ; mutable tileh
: int
333 ; mutable mustoresize
: memsize
334 ; mutable checkers
: bool
335 ; mutable aalevel
: int
336 ; mutable urilauncher
: string
337 ; mutable pathlauncher
: string
338 ; mutable colorspace
: colorspace
339 ; mutable invert
: bool
340 ; mutable colorscale
: float
341 ; mutable redirectstderr
: bool
342 ; mutable ghyllscroll
: (int * int * int) option
343 ; mutable columns
: columns
344 ; mutable beyecolumns
: columncount
option
345 ; mutable selcmd
: string
346 ; mutable updatecurs
: bool
347 ; mutable keyhashes
: (string * keyhash
) list
348 ; mutable hfsize
: int
349 ; mutable pgscale
: float
350 ; mutable usepbo
: bool
351 ; mutable wheelbypage
: bool
352 ; mutable stcmd
: string
353 ; mutable riani
: bool
356 | Csingle
of singlecolumn
357 | Cmulti
of multicolumns
358 | Csplit
of splitcolumns
361 type anchor
= pageno
* top
* dtop
;;
363 type outline
= string * int * anchor
;;
365 type rect
= float * float * float * float * float * float * float * float;;
367 type tile
= opaque
* pixmapsize
* elapsed
368 and elapsed
= float;;
369 type pagemapkey
= pageno
* gen
;;
370 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
374 let emptyanchor = (0, 0.0, 0.0);;
376 type infochange
= | Memused
| Docinfo
| Pdim
;;
378 class type uioh
= object
379 method display
: unit
380 method key
: int -> int -> uioh
381 method button
: int -> bool -> int -> int -> int -> uioh
382 method motion
: int -> int -> uioh
383 method pmotion
: int -> int -> uioh
384 method infochanged
: infochange
-> unit
385 method scrollpw
: (int * float * float)
386 method scrollph
: (int * float * float)
387 method modehash
: keyhash
388 method eformsgs
: bool
392 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
393 | Textentry
of (textentry
* onleave
)
395 | LinkNav
of linktarget
396 and onleave
= leavetextentrystatus
-> unit
397 and leavetextentrystatus
= | Cancel
| Confirm
398 and helpitem
= string * int * action
401 | Action
of (uioh
-> uioh
)
403 | Ltexact
of (pageno
* int)
407 let isbirdseye = function Birdseye _
-> true | _
-> false;;
408 let istextentry = function Textentry _
-> true | _
-> false;;
412 | Loading
of (page
* gen
)
414 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
416 | Outlining
of outline list
419 let emptykeyhash = Hashtbl.create
0;;
420 let nouioh : uioh
= object (self
)
422 method key _ _
= self
423 method button _ _ _ _ _
= self
424 method motion _ _
= self
425 method pmotion _ _
= self
426 method infochanged _
= ()
427 method scrollpw
= (0, nan
, nan
)
428 method scrollph
= (0, nan
, nan
)
429 method modehash
= emptykeyhash
430 method eformsgs
= false
434 { mutable sr
: Unix.file_descr
435 ; mutable sw
: Unix.file_descr
436 ; mutable wsfd
: Unix.file_descr
437 ; mutable errfd
: Unix.file_descr
option
438 ; mutable stderr
: Unix.file_descr
439 ; mutable errmsgs
: Buffer.t
440 ; mutable newerrmsgs
: bool
444 ; mutable anchor
: anchor
445 ; mutable ranchors
: (string * string * anchor
* string) list
447 ; mutable layout
: page list
448 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
449 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
450 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
451 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
452 ; mutable pagecount
: int
453 ; mutable currently
: currently
454 ; mutable mstate
: mstate
455 ; mutable searchpattern
: string
456 ; mutable rects
: (pageno
* recttype
* rect
) list
457 ; mutable rects1
: (pageno
* recttype
* rect
) list
458 ; mutable text
: string
459 ; mutable winstate
: Wsi.winstate list
460 ; mutable mode
: mode
461 ; mutable uioh
: uioh
462 ; mutable outlines
: outline array
463 ; mutable bookmarks
: outline list
464 ; mutable path
: string
465 ; mutable password
: string
466 ; mutable nameddest
: string
467 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
468 ; mutable memused
: memsize
470 ; mutable throttle
: (page list
* int * float) option
471 ; mutable autoscroll
: int option
472 ; mutable ghyll
: (int option -> unit)
473 ; mutable help
: helpitem array
474 ; mutable docinfo
: (int * string) list
475 ; mutable texid
: GlTex.texture_id
option
477 ; mutable prevzoom
: float
478 ; mutable progress
: float
479 ; mutable redisplay
: bool
480 ; mutable mpos
: mpos
481 ; mutable keystate
: keystate
482 ; mutable glinks
: bool
483 ; mutable prevcolumns
: (columns
* float) option
486 ; mutable reprf
: (unit -> unit)
487 ; mutable origin
: string
490 { pat
: string circbuf
491 ; pag
: string circbuf
492 ; nav
: anchor circbuf
493 ; sel
: string circbuf
500 ; scrollb
= scrollbhv lor scrollbvv
516 ; presentation
= false
521 ; fitmodel
= FitProportional
522 ; trimmargins
= false
523 ; trimfuzz
= (0,0,0,0)
524 ; memlimit
= 32 lsl 20
529 ; bgcolor
= (0.5, 0.5, 0.5)
533 ; mustoresize
= 256 lsl 20
538 | Plinux
| Pfreebsd
| Pdragonflybsd
539 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
540 | Posx
-> "open \"%s\""
541 | Pcygwin
-> "cygstart \"%s\""
542 | Punknown
-> "echo %s")
543 ; pathlauncher
= "lp \"%s\""
546 | Plinux
| Pfreebsd
| Pdragonflybsd
547 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
554 ; redirectstderr
= false
556 ; columns
= Csingle
[||]
562 ; wheelbypage
= false
563 ; stcmd
= "echo SyncTex"
566 let mk n
= (n
, Hashtbl.create
1) in
580 let wtmode = ref false;;
582 let findkeyhash c name
=
583 try List.assoc name c
.keyhashes
584 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
587 let conf = { defconf with angle
= defconf.angle
};;
589 let pgscale h
= truncate
(float h
*. conf.pgscale);;
592 { mutable fontsize
: int
593 ; mutable wwidth
: float
594 ; mutable maxrows
: int
606 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
607 let len = String.length s
in
608 if colonpos >= 0 && colonpos + 3 < len
610 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
613 try String.rindex_from s
colonpos ' '
617 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
620 | "http" | "ftp" | "mailto" ->
622 try String.index_from s
colonpos ' '
623 with Not_found
-> len
625 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
633 if String.length
conf.urilauncher
= 0
634 then print_endline uri
636 let url = geturl uri
in
637 if String.length
url = 0
638 then Printf.eprintf
"obtained empty url from uri %S" uri
640 let re = Str.regexp
"%s" in
641 let command = Str.global_replace
re url conf.urilauncher
in
645 "failed to execute `%s': %s\n" command (exntos exn
);
651 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
652 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
656 let strings = version () :: "" :: Help.keys
in
659 let url = geturl s
in
660 if String.length
url > 0
661 then (s
, 0, Action
(fun u
-> gotouri url; u
))
662 else (s
, 0, Noaction
)
667 let firstgeomcmds = "", [];;
668 let noreprf () = ();;
675 ; stderr
= Unix.stderr
676 ; errmsgs
= Buffer.create
0
681 ; anchor
= emptyanchor
685 ; tilelru
= Queue.create
()
686 ; pagemap
= Hashtbl.create
10
687 ; tilemap
= Hashtbl.create
10
703 ; geomcmds
= firstgeomcmds
705 { nav
= cbnew 10 emptyanchor
734 if (conf.scrollb
land scrollbhv = 0)
735 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
741 if (conf.scrollb
land scrollbvv = 0)
746 let wadjsb w
= w
- vscrollw ();;
749 fstate.fontsize
<- n
;
750 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
751 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
757 Printf.kprintf prerr_endline fmt
759 Printf.kprintf ignore fmt
763 if String.length
conf.pathlauncher
= 0
764 then print_endline
state.path
766 let re = Str.regexp
"%s" in
767 let command = Str.global_replace
re state.path
conf.pathlauncher
in
770 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
776 type 'a t
= | Res
of 'a
| Exn
of exn
;;
779 try Res
(Unix.pipe ())
784 try tempfailureretry
Unix.close fd
785 with exn
-> f
(exntos exn
)
789 try Res
(tempfailureretry
Unix.dup fd
)
794 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
799 let redirectstderr () =
800 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
801 if conf.redirectstderr
803 match Ne.pipe () with
805 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
808 begin match Ne.dup Unix.stderr
with
810 dolog
"failed to dup stderr: %s" (exntos exn
);
811 Ne.clo r
(clofail "pipe/r");
812 Ne.clo w
(clofail "pipe/w");
814 | Ne.Res dupstderr
->
815 begin match Ne.dup2 w
Unix.stderr
with
817 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
818 Ne.clo dupstderr
(clofail "stderr duplicate");
819 Ne.clo r
(clofail "redir pipe/r");
820 Ne.clo w
(clofail "redir pipe/w");
823 state.stderr
<- dupstderr
;
824 state.errfd
<- Some r
;
828 state.newerrmsgs
<- false;
829 begin match state.errfd
with
831 begin match Ne.dup2 state.stderr
Unix.stderr
with
833 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
835 Ne.clo fd
(clofail "dup of stderr");
840 prerr_string
(Buffer.contents
state.errmsgs
);
842 Buffer.clear
state.errmsgs
;
848 let postRedisplay who
=
850 then prerr_endline
("redisplay for " ^ who
);
851 state.redisplay
<- true;
855 let getopaque pageno
=
856 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
857 with Not_found
-> None
860 let putopaque pageno opaque
=
861 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
864 let pagetranslatepoint l x y
=
865 let dy = y
- l
.pagedispy
in
866 let y = dy + l
.pagey
in
867 let dx = x
- l
.pagedispx
in
868 let x = dx + l
.pagex
in
872 let onppundermouse g
x y d
=
875 begin match getopaque l
.pageno
with
877 let x0 = l
.pagedispx
in
878 let x1 = x0 + l
.pagevw
in
879 let y0 = l
.pagedispy
in
880 let y1 = y0 + l
.pagevh
in
881 if y >= y0 && y <= y1 && x >= x0 && x <= x1
883 let px, py
= pagetranslatepoint l
x y in
884 match g opaque l
px py
with
897 let g opaque _
px py
=
898 match whatsunder opaque
px py
with
900 | under
-> Some under
902 onppundermouse g x y Unone
907 match unproject opaque
x y with
908 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
911 onppundermouse g x y None
;
915 state.text
<- Printf.sprintf
"%c%s" c s
;
916 G.postRedisplay "showtext";
920 match Ne.pipe () with
922 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
925 try popen conf.selcmd
[r
, 0; w
, -1]; true
928 (Printf.sprintf
"failed to execute %s: %s"
929 conf.selcmd
(exntos exn
));
933 Ne.clo fd
(fun msg
->
934 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
940 let l = String.length s
in
941 let n = tempfailureretry
(Unix.write w s
0) l in
946 "failed to write %d characters to sel pipe, wrote %d"
951 (Printf.sprintf
"failed to write to sel pipe: %s"
960 let undertext = function
963 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
964 | Utext s
-> "font: " ^ s
965 | Uunexpected s
-> "unexpected: " ^ s
966 | Ulaunch s
-> "launch: " ^ s
967 | Unamed s
-> "named: " ^ s
968 | Uremote
(filename
, pageno
) ->
969 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
972 let updateunder x y =
973 match getunder x y with
974 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
976 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
977 Wsi.setcursor
Wsi.CURSOR_INFO
978 | Ulinkgoto
(pageno
, _
) ->
980 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
981 Wsi.setcursor
Wsi.CURSOR_INFO
983 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
984 Wsi.setcursor
Wsi.CURSOR_TEXT
986 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
987 Wsi.setcursor
Wsi.CURSOR_INHERIT
989 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
990 Wsi.setcursor
Wsi.CURSOR_INHERIT
992 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
993 Wsi.setcursor
Wsi.CURSOR_INHERIT
994 | Uremote
(filename
, pageno
) ->
995 if conf.underinfo
then showtext 'r'
996 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
997 Wsi.setcursor
Wsi.CURSOR_INFO
1000 let showlinktype under
=
1006 let s = undertext under
in
1011 let b = Buffer.create
(String.length
s + 1) in
1012 Buffer.add_string
b s;
1013 Buffer.add_char
b c
;
1017 let colorspace_of_string s =
1018 match String.lowercase
s with
1022 | _
-> failwith
"invalid colorspace"
1025 let int_of_colorspace = function
1031 let colorspace_of_int = function
1035 | n -> failwith
("invalid colorspace index " ^ string_of_int
n)
1038 let colorspace_to_string = function
1044 let fitmodel_of_string s =
1045 match String.lowercase
s with
1046 | "width" -> FitWidth
1047 | "proportional" -> FitProportional
1049 | _
-> failwith
"invalid fit model"
1052 let int_of_fitmodel = function
1054 | FitProportional
-> 1
1058 let fitmodel_of_int = function
1060 | 1 -> FitProportional
1062 | n -> failwith
("invalid fit model index " ^ string_of_int
n)
1065 let fitmodel_to_string = function
1066 | FitWidth
-> "width"
1067 | FitProportional
-> "proportional"
1071 let intentry_with_suffix text key
=
1073 if key
>= 32 && key
< 127
1077 match Char.lowercase
c with
1079 let text = addchar text c in
1082 | 'k'
| 'm'
| '
g'
->
1083 let text = addchar text c in
1087 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1091 let multicolumns_to_string (n, a
, b) =
1093 then Printf.sprintf
"%d" n
1094 else Printf.sprintf
"%d,%d,%d" n a
b;
1097 let multicolumns_of_string s =
1099 (int_of_string
s, 0, 0)
1101 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1103 then failwith
"subtly broken"; (n, a
, b)
1109 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1110 if n != 4 then failwith
"incomplete read(len)";
1112 lor (Char.code
s.[0] lsl 24)
1113 lor (Char.code
s.[1] lsl 16)
1114 lor (Char.code
s.[2] lsl 8)
1115 lor (Char.code
s.[3] lsl 0)
1117 let s = String.create
len in
1118 let n = tempfailureretry
(Unix.read fd
s 0) len in
1119 if n != len then failwith
"incomplete read(data)";
1123 let btod b = if b then 1 else 0;;
1126 let b = Buffer.create
16 in
1127 Buffer.add_string
b "llll";
1130 let s = Buffer.contents
b in
1131 let n = String.length
s in
1133 (* dolog "wcmd %S" (String.sub s 4 len); *)
1134 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1135 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1136 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1137 s.[3] <- Char.chr
(len land 0xff);
1138 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1139 if n'
!= n then failwith
"write failed";
1144 let d = state.winh
- h
in
1145 max
conf.interpagespace
((d + 1) / 2)
1148 let rowyh (c, coverA
, coverB
) b n =
1149 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1151 let _, _, vy
, (_, _, h
, _) = b.(n) in
1154 let n'
= n - coverA
in
1157 let e = min
state.pagecount
(s + c) in
1158 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1159 let _, _, y, (_, _, h
, _) = b.(m
) in
1160 let miny = min
miny y in
1161 let maxh = max
maxh h
in
1162 find (m
+1) miny maxh
1167 match conf.columns
with
1168 | Cmulti
((_, _, _) as cl
, b) ->
1169 if Array.length
b > 0
1171 let y, h
= rowyh cl
b (Array.length
b - 1) in
1172 y + h
+ (if conf.presentation
then calcips h
else 0)
1175 if Array.length
b > 0
1177 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1178 y + h
+ (if conf.presentation
then calcips h
else 0)
1181 if Array.length
b > 0
1183 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1188 let getpageyh pageno
=
1189 let pageno = bound pageno 0 (state.pagecount
-1) in
1190 match conf.columns
with
1192 if Array.length
b = 0
1195 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1197 if conf.presentation
1203 if Array.length
b = 0
1206 let y, h
= rowyh cl
b pageno in
1208 if conf.presentation
1214 if Array.length
b = 0
1218 let (_, _, y, (_, _, h
, _)) = b.(n) in
1222 let getpagedim pageno =
1225 | (n, _, _, _) as pdim
:: rest
->
1227 then (if n = pageno then pdim
else ppdim
)
1232 f (-1, -1, -1, -1) state.pdims
1235 let getpagey pageno = fst
(getpageyh pageno);;
1237 let nogeomcmds cmds
=
1239 | s, [] -> String.length
s = 0
1244 let ((c, coverA
, coverB
) as cl
), b =
1245 match conf.columns
with
1246 | Csingle
b -> (1, 0, 0), b
1247 | Cmulti
(c, b) -> c, b
1248 | Csplit
(_, b) -> (1, 0, 0), b
1250 if Array.length
b = 0
1253 let rec bsearch nmin nmax
=
1255 then bound nmin
0 (state.pagecount
-1)
1257 let n = (nmax
+ nmin
) / 2 in
1258 let vy, h
= rowyh cl
b n in
1260 if conf.presentation
1262 let ips = calcips h
in
1263 let y0 = vy - ips in
1264 let y1 = vy + h
+ ips in
1268 then 0, vy + h
+ conf.interpagespace
1270 let y0 = vy - conf.interpagespace
in
1271 y0, y0 + h
+ conf.interpagespace
1274 if y >= y0 && y < y1
1281 if n < state.pagecount
- coverB
1282 then ((n-coverA
)/c)*c + coverA
1289 then bsearch (n+1) nmax
1290 else bsearch nmin
(n-1)
1293 let r = bsearch 0 (state.pagecount
-1) in
1297 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1298 let sh = sh - (hscrollh ()) in
1299 let rec fold accu
n =
1300 if n = Array.length
b
1303 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1306 || n = state.pagecount
- coverB
1307 || (n - coverA
) mod columns
= columns
- 1)
1313 let pagey = max
0 (y - vy) in
1314 let pagedispy = if pagey > 0 then 0 else vy - y in
1315 let pagedispx, pagex
=
1317 if n = coverA
- 1 || n = state.pagecount
- coverB
1318 then state.x + (wadjsb state.winw
- w
) / 2
1319 else dx + xoff
+ state.x
1326 let vw = wadjsb state.winw
- pagedispx in
1327 let pw = w
- pagex
in
1330 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1331 if pagevw > 0 && pagevh > 0
1335 ; pagedimno
= pdimno
1342 ; pagedispx = pagedispx
1343 ; pagedispy = pagedispy
1355 List.rev
(fold [] (page_of_y y));
1358 let layoutS (columns
, b) y sh =
1359 let sh = sh - hscrollh () in
1360 let rec fold accu n =
1361 if n = Array.length
b
1364 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1371 let x = xoff
+ state.x in
1372 let pagey = max
0 (y - vy) in
1373 let pagedispy = if pagey > 0 then 0 else vy - y in
1374 let pagedispx, pagex
=
1388 let pagecolw = pagew
/columns
in
1390 if pagecolw < state.winw
1391 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1395 let vw = wadjsb state.winw
- pagedispx in
1396 let pw = pagew
- pagex
in
1399 let pagevw = min
pagevw pagecolw in
1400 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1401 if pagevw > 0 && pagevh > 0
1404 { pageno = n/columns
1405 ; pagedimno
= pdimno
1412 ; pagedispx = pagedispx
1413 ; pagedispy = pagedispy
1414 ; pagecol
= n mod columns
1425 List.rev
(fold [] 0)
1429 if nogeomcmds state.geomcmds
1431 match conf.columns
with
1432 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1433 | Cmulti
c -> layoutN c y sh
1434 | Csplit
s -> layoutS s y sh
1439 let y = state.y + incr
in
1441 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1446 let tilex = l.pagex
mod conf.tilew
in
1447 let tiley = l.pagey mod conf.tileh
in
1449 let col = l.pagex
/ conf.tilew
in
1450 let row = l.pagey / conf.tileh
in
1452 let rec rowloop row y0 dispy h
=
1456 let dh = conf.tileh
- y0 in
1457 let dh = min h
dh in
1458 let rec colloop col x0 dispx w
=
1462 let dw = conf.tilew
- x0 in
1463 let dw = min w
dw in
1465 f col row dispx dispy
x0 y0 dw dh;
1466 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1469 colloop col tilex l.pagedispx l.pagevw;
1470 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1473 if l.pagevw > 0 && l.pagevh > 0
1474 then rowloop row tiley l.pagedispy l.pagevh;
1477 let gettileopaque l col row =
1479 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1481 try Some
(Hashtbl.find state.tilemap
key)
1482 with Not_found
-> None
1485 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1486 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1487 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1490 let drawtiles l color
=
1492 let f col row x y tilex tiley w h
=
1493 match gettileopaque l col row with
1494 | Some
(opaque
, _, t
) ->
1495 let params = x, y, w
, h
, tilex, tiley in
1499 GlFunc.blend_func `zero `one_minus_src_color
;
1501 drawtile
params opaque
;
1503 then Gl.disable `blend
;
1506 let s = Printf.sprintf
1510 let w = measurestr
fstate.fontsize
s in
1511 GlMisc.push_attrib
[`current
];
1512 GlDraw.color
(0.0, 0.0, 0.0);
1514 (float (x-2), float (y-2))
1515 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1516 GlDraw.color
(1.0, 1.0, 1.0);
1517 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1518 GlMisc.pop_attrib
();
1523 let lw = wadjsb state.winw
- x in
1526 let lh = state.winh
- y in
1529 begin match state.texid
with
1531 Gl.enable `texture_2d
;
1532 GlTex.bind_texture `texture_2d id
;
1535 and x1 = float (x+w)
1536 and y1 = float (y+h
) in
1538 let tw = float w /. 16.0
1539 and th
= float h
/. 16.0 in
1540 let tx0 = float tilex /. 16.0
1541 and ty0
= float tiley /. 16.0 in
1543 and ty1
= ty0
+. th
in
1544 GlDraw.begins `quads
;
1545 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1546 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1547 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1548 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1551 Gl.disable `texture_2d
;
1553 GlDraw.color
(1.0, 1.0, 1.0);
1556 (float (x+w), float (y+h
));
1558 if w > 128 && h
> fstate.fontsize
+ 10
1560 GlDraw.color
(0.0, 0.0, 0.0);
1563 then (col*conf.tilew
, row*conf.tileh
)
1566 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1573 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1575 let tilevisible1 l x y =
1577 and ax1
= l.pagex
+ l.pagevw
1579 and ay1
= l.pagey + l.pagevh in
1583 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1584 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1586 let rx0 = max
ax0 bx0
1587 and ry0
= max ay0 by0
1588 and rx1
= min ax1
bx1
1589 and ry1
= min ay1 by1
in
1591 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1592 nonemptyintersection
1595 let tilevisible layout n x y =
1596 let rec findpageinlayout m
= function
1597 | l :: rest
when l.pageno = n ->
1598 tilevisible1 l x y || (
1599 match conf.columns
with
1600 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1603 | _ :: rest
-> findpageinlayout 0 rest
1606 findpageinlayout 0 layout;
1609 let tileready l x y =
1610 tilevisible1 l x y &&
1611 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1614 let tilepage n p
layout =
1615 let rec loop = function
1619 let f col row _ _ _ _ _ _ =
1620 if state.currently
= Idle
1622 match gettileopaque l col row with
1625 let x = col*conf.tilew
1626 and y = row*conf.tileh
in
1628 let w = l.pagew
- x in
1632 let h = l.pageh
- y in
1637 then getpbo
w h conf.colorspace
1640 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1643 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1644 conf.tilew
, conf.tileh
1653 if nogeomcmds state.geomcmds
1657 let preloadlayout y =
1658 let y = if y < state.winh
then 0 else y - state.winh
in
1659 let h = state.winh
*3 in
1664 let rec loop pages
=
1665 if state.currently
!= Idle
1670 begin match getopaque l.pageno with
1672 wcmd "page %d %d" l.pageno l.pagedimno
;
1673 state.currently
<- Loading
(l, state.gen
);
1675 tilepage l.pageno opaque pages
;
1680 if nogeomcmds state.geomcmds
1686 if conf.preload && state.currently
= Idle
1687 then load (preloadlayout state.y);
1690 let layoutready layout =
1691 let rec fold all ls
=
1692 all
&& match ls
with
1694 let seen = ref false in
1695 let allvisible = ref true in
1696 let foo col row _ _ _ _ _ _ =
1698 allvisible := !allvisible &&
1699 begin match gettileopaque l col row with
1705 fold (!seen && !allvisible) rest
1708 let alltilesvisible = fold true layout in
1713 let y = bound y 0 state.maxy
in
1714 let y, layout, proceed
=
1715 match conf.maxwait
with
1716 | Some time
when state.ghyll
== noghyll ->
1717 begin match state.throttle
with
1719 let layout = layout y state.winh
in
1720 let ready = layoutready layout in
1724 state.throttle
<- Some
(layout, y, now ());
1726 else G.postRedisplay "gotoy showall (None)";
1728 | Some
(_, _, started
) ->
1729 let dt = now () -. started
in
1732 state.throttle
<- None
;
1733 let layout = layout y state.winh
in
1735 G.postRedisplay "maxwait";
1742 let layout = layout y state.winh
in
1743 if not
!wtmode || layoutready layout
1744 then G.postRedisplay "gotoy ready";
1750 state.layout <- layout;
1751 begin match state.mode
with
1752 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1753 let rec loop = function
1755 state.mode
<- LinkNav
(Ltgendir
0)
1756 | l :: _ when l.pageno = pageno ->
1757 begin match getopaque pageno with
1759 state.mode
<- LinkNav
(Ltgendir
0)
1761 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1762 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1763 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1764 then state.mode
<- LinkNav
(Ltgendir
0)
1766 | _ :: rest
-> loop rest
1771 begin match state.mode
with
1772 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1773 if not
(pagevisible layout pageno)
1775 match state.layout with
1778 state.mode
<- Birdseye
(
1779 conf, leftx
, l.pageno, hooverpageno
, anchor
1782 | LinkNav
(Ltgendir dir
as lt
) ->
1784 let rec loop = function
1787 match getopaque l.pageno with
1793 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1795 if dir
> 0 then LDfirst
else LDlast
1801 | Lnotfound
-> loop rest
1803 showlinktype (getlink opaque
n);
1804 Ltexact
(l.pageno, n)
1808 state.mode
<- LinkNav
linknav
1813 state.ghyll
<- noghyll;
1816 let mx, my
= state.mpos
in
1821 let conttiling pageno opaque
=
1822 tilepage pageno opaque
1823 (if conf.preload then preloadlayout state.y else state.layout)
1826 let gotoy_and_clear_text y =
1827 if not
conf.verbose
then state.text <- "";
1833 let coloff = l.pagecol
* l.pageh
in
1834 float (l.pagey + coloff) /. float l.pageh
1841 if conf.presentation
1842 then float l.pagedispy /. float (calcips l.pageh
)
1843 else float l.pagedispy /. float conf.interpagespace
1846 (l.pageno, top, dtop)
1850 match state.layout with
1851 | l :: _ -> getanchor1 l
1853 let n = page_of_y state.y in
1857 let y, h = getpageyh n in
1858 let dy = y - state.y in
1860 if conf.presentation
1862 let ips = calcips h in
1863 float (dy + ips) /. float ips
1865 float dy /. float conf.interpagespace
1870 let getanchory (n, top, dtop) =
1871 let y, h = getpageyh n in
1872 if conf.presentation
1874 let ips = calcips h in
1875 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1877 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1880 let gotoanchor anchor
=
1881 gotoy (getanchory anchor
);
1885 cbput state.hists
.nav
(getanchor ());
1889 let anchor = cbgetc state.hists
.nav dir
in
1894 let scroll f n a
b =
1895 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1897 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1899 then s (float f /. float a
)
1902 then 1.0 -. s ((float (f-b) /. float (n-b)))
1908 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1909 let iv x = x**3.-.0.5*.x**4. in
1911 let ins = float a
*. iv1
1912 and outs
= float (n-b) *. iv1 in
1914 ins +. outs
+. float ones
1916 let rec set (_N
, _A
, _B
) y sy
=
1917 let sum = summa
1.0 _N _A _B
in
1918 let dy = float (y - sy
) in
1922 then state.ghyll
<- noghyll
1925 let s = scroll n _N _A _B
in
1926 let y1 = y1 +. ((s *. dy) /. sum) in
1927 gotoy_and_clear_text (truncate
y1);
1928 state.ghyll
<- gf (n+1) y1;
1932 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1934 gf 0 (float state.y)
1937 match conf.ghyllscroll
with
1939 gotoy_and_clear_text y
1941 if state.ghyll
== noghyll
1942 then set nab
y state.y
1943 else state.ghyll
(Some
y)
1946 let gotopage n top =
1947 let y, h = getpageyh n in
1948 let y = y + (truncate
(top *. float h)) in
1952 let gotopage1 n top =
1953 let y = getpagey n in
1958 let invalidate s f =
1963 match state.geomcmds
with
1964 | ps
, [] when String.length ps
= 0 ->
1966 state.geomcmds
<- s, [];
1969 state.geomcmds
<- ps
, [s, f];
1971 | ps
, (s'
, _) :: rest
when s'
= s ->
1972 state.geomcmds
<- ps
, ((s, f) :: rest
);
1975 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1979 Hashtbl.iter
(fun _ opaque
->
1980 wcmd "freepage %s" opaque
;
1982 Hashtbl.clear
state.pagemap
;
1986 if not
(Queue.is_empty
state.tilelru
)
1988 Queue.iter
(fun (k
, p
, s) ->
1989 wcmd "freetile %s" p
;
1990 state.memused
<- state.memused
- s;
1991 Hashtbl.remove
state.tilemap k
;
1993 state.uioh#infochanged Memused
;
1994 Queue.clear
state.tilelru
;
2000 let h = truncate
(float h*.conf.zoom
) in
2001 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2005 let opendoc path password
=
2007 state.password
<- password
;
2008 state.gen
<- state.gen
+ 1;
2009 state.docinfo
<- [];
2012 setaalevel
conf.aalevel
;
2014 if String.length
state.origin
= 0
2018 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2019 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
2020 invalidate "reqlayout"
2022 wcmd "reqlayout %d %d %d %s\000"
2023 conf.angle
(int_of_fitmodel conf.fitmodel
)
2024 (stateh state.winh
) state.nameddest
2029 state.anchor <- getanchor ();
2030 opendoc state.path
state.password
;
2034 let c = c *. conf.colorscale
in
2038 let scalecolor2 (r, g, b) =
2039 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2042 let docolumns = function
2044 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2045 let rec loop pageno pdimno pdim
y ph pdims
=
2046 if pageno = state.pagecount
2049 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2051 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2052 pdimno+1, pdim
, rest
2056 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2058 (if conf.presentation
2059 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2060 else (if pageno = 0 then 0 else conf.interpagespace
)
2063 a.(pageno) <- (pdimno, x, y, pdim
);
2064 loop (pageno+1) pdimno pdim
(y + h) h pdims
2066 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2067 conf.columns
<- Csingle
a;
2069 | Cmulti
((columns
, coverA
, coverB
), _) ->
2070 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2071 let rec loop pageno pdimno pdim
x y rowh pdims
=
2072 let rec fixrow m
= if m
= pageno then () else
2073 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2076 let y = y + (rowh
- h) / 2 in
2077 a.(m
) <- (pdimno, x, y, pdim
);
2081 if pageno = state.pagecount
2082 then fixrow (((pageno - 1) / columns
) * columns
)
2084 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2086 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2087 pdimno+1, pdim
, rest
2092 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2094 let x = (wadjsb state.winw
- w) / 2 in
2096 if conf.presentation
then calcips h else conf.interpagespace
in
2097 x, y + ips + rowh
, h
2100 if (pageno - coverA
) mod columns
= 0
2102 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2104 if conf.presentation
2106 let ips = calcips h in
2107 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2109 y + (if pageno = 0 then 0 else conf.interpagespace
)
2113 else x, y, max rowh
h
2117 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2120 if pageno = columns
&& conf.presentation
2122 let ips = calcips rowh
in
2123 for i
= 0 to pred columns
2125 let (pdimno, x, y, pdim
) = a.(i
) in
2126 a.(i
) <- (pdimno, x, y+ips, pdim
)
2132 fixrow (pageno - columns
);
2137 a.(pageno) <- (pdimno, x, y, pdim
);
2138 let x = x + w + xoff
*2 + conf.interpagespace
in
2139 loop (pageno+1) pdimno pdim
x y rowh' pdims
2141 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2142 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2145 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2146 let rec loop pageno pdimno pdim
y pdims
=
2147 if pageno = state.pagecount
2150 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2152 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2153 pdimno+1, pdim
, rest
2158 let rec loop1 n x y =
2159 if n = c then y else (
2160 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2161 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2164 let y = loop1 0 0 y in
2165 loop (pageno+1) pdimno pdim
y pdims
2167 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2168 conf.columns
<- Csplit
(c, a);
2172 docolumns conf.columns
;
2173 state.maxy
<- calcheight ();
2174 if state.reprf
== noreprf
2176 match state.mode
with
2177 | Birdseye
(_, _, pageno, _, _) ->
2178 let y, h = getpageyh pageno in
2179 let top = (state.winh
- h) / 2 in
2180 gotoy (max
0 (y - top))
2181 | _ -> gotoanchor state.anchor
2185 state.reprf
<- noreprf;
2190 GlDraw.viewport
0 0 w h;
2191 let firsttime = state.geomcmds
== firstgeomcmds in
2192 if not
firsttime && nogeomcmds state.geomcmds
2193 then state.anchor <- getanchor ();
2196 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2199 setfontsize fstate.fontsize
;
2200 GlMat.mode `modelview
;
2201 GlMat.load_identity
();
2203 GlMat.mode `projection
;
2204 GlMat.load_identity
();
2205 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2206 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2207 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2212 else float state.x /. float state.w
2214 invalidate "geometry"
2218 then state.x <- truncate
(relx *. float w);
2220 match conf.columns
with
2222 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2223 | Csplit
(c, _) -> w * c
2225 wcmd "geometry %d %d %d"
2226 w (stateh h) (int_of_fitmodel conf.fitmodel
)
2231 let len = String.length
state.text in
2234 match state.mode
with
2235 | Textentry
_ | View
| LinkNav
_ ->
2236 let h, _, _ = state.uioh#scrollpw
in
2242 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2243 (x+.w, float (state.winh
- hscrollh))
2246 let w = float (wadjsb state.winw
- 1) in
2247 if state.progress
>= 0.0 && state.progress
< 1.0
2249 GlDraw.color
(0.3, 0.3, 0.3);
2250 let w1 = w *. state.progress
in
2252 GlDraw.color
(0.0, 0.0, 0.0);
2256 GlDraw.color
(0.0, 0.0, 0.0);
2260 GlDraw.color
(1.0, 1.0, 1.0);
2261 drawstring fstate.fontsize
2262 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2265 match state.mode
with
2266 | Textentry
((prefix
, text, _, _, _, _), _) ->
2270 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2272 Printf.sprintf
"%s%s_" prefix
text
2281 if not
(istextentry state.mode
) && state.uioh#eformsgs
2283 let s1 = "(press 'e' to review error messasges)" in
2284 if String.length
s > 0 then s ^
" " ^
s1 else s1
2289 if String.length
s > 0
2294 let len = Queue.length
state.tilelru
in
2296 match state.throttle
with
2299 then preloadlayout state.y
2301 | Some
(layout, _, _) ->
2305 if state.memused
<= conf.memlimit
2310 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2311 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2312 let (_, pw, ph
, _) = getpagedim n in
2315 && colorspace
= conf.colorspace
2316 && angle
= conf.angle
2320 let x = col*conf.tilew
2321 and y = row*conf.tileh
in
2322 tilevisible (Lazy.force_val
layout) n x y
2324 then Queue.push lruitem
state.tilelru
2327 wcmd "freetile %s" p
;
2328 state.memused
<- state.memused
- s;
2329 state.uioh#infochanged Memused
;
2330 Hashtbl.remove
state.tilemap k
;
2338 let logcurrently = function
2339 | Idle
-> dolog
"Idle"
2340 | Loading
(l, gen
) ->
2341 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2342 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2344 "Tiling %d[%d,%d] page=%s cs=%s angle"
2345 l.pageno col row pageopaque
2346 (colorspace_to_string colorspace
)
2348 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2349 angle gen
conf.angle
state.gen
2351 conf.tilew
conf.tileh
2358 let r = Str.regexp
" " in
2359 fun s -> Str.bounded_split
r s 2;
2362 let onpagerect pageno f =
2364 match conf.columns
with
2365 | Cmulti
(_, b) -> b
2367 | Csplit
(_, b) -> b
2369 if pageno >= 0 && pageno < Array.length
b
2371 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2372 let r = getpdimrect
pdimno in
2373 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2376 let gotopagexy1 pageno x y =
2377 onpagerect pageno (fun w h ->
2379 let _,w1,_,leftx
= getpagedim pageno in
2380 let wh = state.winh
- hscrollh () in
2381 let sw = float w1 /. w in
2383 let x = leftx
+ state.x + truncate
x in
2385 if x < 0 || x >= wadjsb state.winw
2389 let py, h = getpageyh pageno in
2390 let pdy = truncate
(top *. float h) in
2391 let y'
= py + pdy in
2392 let dy = y'
- state.y in
2394 if x != state.x || not
(dy > 0 && dy < wh)
2396 if conf.presentation
2398 if abs
(py - y'
) > wh
2405 if state.x != sx || state.y != sy
2410 let ww = wadjsb state.winw
in
2412 and qy
= pdy / wh in
2414 and y = py + qy
* wh in
2415 let x = if -x + ww > w1 then -(w1-ww) else x
2416 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2418 if conf.presentation
2420 if abs
(py - y'
) > wh
2430 gotoy_and_clear_text y;
2432 else gotoy_and_clear_text state.y;
2436 let gotopagexy pageno x y =
2437 match state.mode
with
2438 | Birdseye
_ -> gotopage pageno 0.0
2439 | _ -> gotopagexy1 pageno x y
2443 (* dolog "%S" cmds; *)
2444 let cl = splitatspace cmds
in
2446 try Scanf.sscanf
s fmt
f
2448 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2453 state.uioh#infochanged Pdim
;
2456 | "clearrects" :: [] ->
2457 state.rects
<- state.rects1
;
2458 G.postRedisplay "clearrects";
2460 | "continue" :: args :: [] ->
2461 let n = scan args "%u" (fun n -> n) in
2462 state.pagecount
<- n;
2463 begin match state.currently
with
2465 state.currently
<- Idle
;
2466 state.outlines
<- Array.of_list
(List.rev
l)
2470 let cur, cmds
= state.geomcmds
in
2471 if String.length
cur = 0
2472 then failwith
"umpossible";
2474 begin match List.rev cmds
with
2476 state.geomcmds
<- "", [];
2480 state.geomcmds
<- s, List.rev rest
;
2482 if conf.maxwait
= None
&& not
!wtmode
2483 then G.postRedisplay "continue";
2485 | "title" :: args :: [] ->
2488 | "msg" :: args :: [] ->
2491 | "vmsg" :: args :: [] ->
2493 then showtext ' '
args
2495 | "emsg" :: args :: [] ->
2496 Buffer.add_string
state.errmsgs
args;
2497 state.newerrmsgs
<- true;
2498 G.postRedisplay "error message"
2500 | "progress" :: args :: [] ->
2501 let progress, text =
2504 f, String.sub
args pos
(String.length
args - pos
))
2507 state.progress <- progress;
2508 G.postRedisplay "progress"
2510 | "firstmatch" :: args :: [] ->
2511 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2512 scan args "%u %d %f %f %f %f %f %f %f %f"
2513 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2514 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2516 let y = (getpagey pageno) + truncate
y0 in
2519 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2521 | "match" :: args :: [] ->
2522 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2523 scan args "%u %d %f %f %f %f %f %f %f %f"
2524 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2525 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2528 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2530 | "page" :: args :: [] ->
2531 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2532 begin match state.currently
with
2533 | Loading
(l, gen
) ->
2534 vlog "page %d took %f sec" l.pageno t
;
2535 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2536 begin match state.throttle
with
2538 let preloadedpages =
2540 then preloadlayout state.y
2545 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2546 IntSet.empty
preloadedpages
2549 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2550 if not
(IntSet.mem
pageno set)
2552 wcmd "freepage %s" opaque
;
2558 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2561 state.currently
<- Idle
;
2564 tilepage l.pageno pageopaque state.layout;
2566 load preloadedpages;
2567 if pagevisible state.layout l.pageno
2568 && layoutready state.layout
2569 then G.postRedisplay "page";
2572 | Some
(layout, _, _) ->
2573 state.currently
<- Idle
;
2574 tilepage l.pageno pageopaque layout;
2579 dolog
"Inconsistent loading state";
2580 logcurrently state.currently
;
2584 | "tile" :: args :: [] ->
2585 let (x, y, opaque
, size
, t
) =
2586 scan args "%u %u %s %u %f"
2587 (fun x y p size t
-> (x, y, p
, size
, t
))
2589 begin match state.currently
with
2590 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2591 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2594 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2596 wcmd "freetile %s" opaque
;
2597 state.currently
<- Idle
;
2601 puttileopaque l col row gen cs angle opaque size t
;
2602 state.memused
<- state.memused
+ size
;
2603 state.uioh#infochanged Memused
;
2605 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2606 opaque
, size
) state.tilelru
;
2609 match state.throttle
with
2610 | None
-> state.layout
2611 | Some
(layout, _, _) -> layout
2614 state.currently
<- Idle
;
2616 && conf.colorspace
= cs
2617 && conf.angle
= angle
2618 && tilevisible layout l.pageno x y
2619 then conttiling l.pageno pageopaque;
2621 begin match state.throttle
with
2623 preload state.layout;
2625 && conf.colorspace
= cs
2626 && conf.angle
= angle
2627 && tilevisible state.layout l.pageno x y
2628 && (not
!wtmode || layoutready state.layout)
2629 then G.postRedisplay "tile nothrottle";
2631 | Some
(layout, y, _) ->
2632 let ready = layoutready layout in
2636 state.layout <- layout;
2637 state.throttle
<- None
;
2638 G.postRedisplay "throttle";
2645 dolog
"Inconsistent tiling state";
2646 logcurrently state.currently
;
2650 | "pdim" :: args :: [] ->
2651 let (n, w, h, _) as pdim
=
2652 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2655 match conf.fitmodel
, conf.columns
with
2656 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2659 state.uioh#infochanged Pdim
;
2660 state.pdims
<- pdim :: state.pdims
2662 | "o" :: args :: [] ->
2663 let (l, n, t
, h, pos
) =
2664 scan args "%u %u %d %u %n"
2665 (fun l n t
h pos
-> l, n, t
, h, pos
)
2667 let s = String.sub
args pos
(String.length
args - pos
) in
2668 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2669 begin match state.currently
with
2670 | Outlining outlines
->
2671 state.currently
<- Outlining
(outline :: outlines
)
2673 state.currently
<- Outlining
[outline]
2675 dolog
"invalid outlining state";
2676 logcurrently currently
2679 | "a" :: args :: [] ->
2681 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2683 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2685 | "info" :: args :: [] ->
2686 state.docinfo
<- (1, args) :: state.docinfo
2688 | "infoend" :: [] ->
2689 state.uioh#infochanged Docinfo
;
2690 state.docinfo
<- List.rev
state.docinfo
2693 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2698 let action = function
2699 | HCprev
-> cbget cb ~
-1
2700 | HCnext
-> cbget cb
1
2701 | HCfirst
-> cbget cb ~
-(cb
.rc)
2702 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2703 and cancel
() = cb
.rc <- rc
2707 let search pattern forward
=
2708 match conf.columns
with
2710 showtext '
!'
"searching does not work properly in split columns mode"
2712 if String.length pattern
> 0
2715 match state.layout with
2718 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2720 wcmd "search %d %d %d %d,%s\000"
2721 (btod conf.icase
) pn py (btod forward
) pattern
;
2724 let intentry text key =
2726 if key >= 32 && key < 127
2732 let text = addchar text c in
2736 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2740 let linknentry text key =
2742 if key >= 32 && key < 127
2748 let text = addchar text c in
2752 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2757 if String.length
s > 0
2760 let l = String.length
s in
2761 let rec loop pos
n = if pos
= l then n else
2762 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2763 loop (pos
+1) (n*26 + m)
2766 let rec loop n = function
2769 match getopaque l.pageno with
2770 | None
-> loop n rest
2772 let m = getlinkcount opaque
in
2775 let under = getlink opaque
n in
2778 else loop (n-m) rest
2780 loop n state.layout;
2784 let textentry text key =
2785 if key land 0xff00 = 0xff00
2787 else TEcont
(text ^ toutf8
key)
2790 let reqlayout angle fitmodel
=
2791 match state.throttle
with
2793 if nogeomcmds state.geomcmds
2794 then state.anchor <- getanchor ();
2795 conf.angle
<- angle
mod 360;
2798 match state.mode
with
2799 | LinkNav
_ -> state.mode
<- View
2802 conf.fitmodel
<- fitmodel
;
2803 invalidate "reqlayout"
2805 wcmd "reqlayout %d %d %d"
2806 conf.angle
(int_of_fitmodel conf.fitmodel
) (stateh state.winh
)
2811 let settrim trimmargins trimfuzz
=
2812 if nogeomcmds state.geomcmds
2813 then state.anchor <- getanchor ();
2814 conf.trimmargins
<- trimmargins
;
2815 conf.trimfuzz
<- trimfuzz
;
2816 let x0, y0, x1, y1 = trimfuzz
in
2817 invalidate "settrim"
2819 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2824 match state.throttle
with
2826 let zoom = max
0.0001 zoom in
2827 if zoom <> conf.zoom
2829 state.prevzoom
<- conf.zoom;
2831 reshape state.winw
state.winh
;
2832 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2835 | Some
(layout, y, started
) ->
2837 match conf.maxwait
with
2841 let dt = now () -. started
in
2849 let setcolumns mode columns coverA coverB
=
2850 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2854 then showtext '
!'
"split mode doesn't work in bird's eye"
2856 conf.columns
<- Csplit
(-columns
, [||]);
2864 conf.columns
<- Csingle
[||];
2869 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2873 reshape state.winw
state.winh
;
2876 let enterbirdseye () =
2877 let zoom = float conf.thumbw
/. float state.winw
in
2878 let birdseyepageno =
2879 let cy = state.winh
/ 2 in
2883 let rec fold best
= function
2886 let d = cy - (l.pagedispy + l.pagevh/2)
2887 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2888 if abs
d < abs dbest
2895 state.mode
<- Birdseye
(
2896 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2899 conf.presentation
<- false;
2900 conf.interpagespace
<- 10;
2901 conf.hlinks
<- false;
2902 conf.fitmodel
<- FitProportional
;
2904 state.mstate
<- Mnone
;
2905 conf.maxwait
<- None
;
2907 match conf.beyecolumns
with
2910 Cmulti
((c, 0, 0), [||])
2911 | None
-> Csingle
[||]
2913 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2916 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2921 reshape state.winw
state.winh
;
2924 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2926 conf.zoom <- c.zoom;
2927 conf.presentation
<- c.presentation
;
2928 conf.interpagespace
<- c.interpagespace
;
2929 conf.maxwait
<- c.maxwait
;
2930 conf.hlinks
<- c.hlinks
;
2931 conf.fitmodel
<- c.fitmodel
;
2932 conf.beyecolumns
<- (
2933 match conf.columns
with
2934 | Cmulti
((c, _, _), _) -> Some
c
2936 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2939 match c.columns
with
2940 | Cmulti
(c, _) -> Cmulti
(c, [||])
2941 | Csingle
_ -> Csingle
[||]
2942 | Csplit
(c, _) -> Csplit
(c, [||])
2947 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2950 reshape state.winw
state.winh
;
2951 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2954 let togglebirdseye () =
2955 match state.mode
with
2956 | Birdseye vals
-> leavebirdseye vals
true
2957 | View
-> enterbirdseye ()
2961 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2962 let pageno = max
0 (pageno - incr
) in
2963 let rec loop = function
2964 | [] -> gotopage1 pageno 0
2965 | l :: _ when l.pageno = pageno ->
2966 if l.pagedispy >= 0 && l.pagey = 0
2967 then G.postRedisplay "upbirdseye"
2968 else gotopage1 pageno 0
2969 | _ :: rest
-> loop rest
2972 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2975 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2976 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2977 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2978 let rec loop = function
2980 let y, h = getpageyh pageno in
2981 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2983 | l :: _ when l.pageno = pageno ->
2984 if l.pagevh != l.pageh
2985 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2986 else G.postRedisplay "downbirdseye"
2987 | _ :: rest
-> loop rest
2992 let optentry mode
_ key =
2993 let btos b = if b then "on" else "off" in
2994 if key >= 32 && key < 127
2996 let c = Char.chr
key in
3000 try conf.scrollstep
<- int_of_string
s with exc
->
3001 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3003 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3008 conf.autoscrollstep
<- int_of_string
s;
3009 if state.autoscroll
<> None
3010 then state.autoscroll
<- Some
conf.autoscrollstep
3012 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3014 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3019 let n, a, b = multicolumns_of_string s in
3020 setcolumns mode
n a b;
3022 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3024 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3029 let zoom = float (int_of_string
s) /. 100.0 in
3032 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3034 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3039 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3041 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3042 begin match mode
with
3044 leavebirdseye beye
false;
3049 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3051 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3056 Some
(int_of_string
s)
3058 state.text <- Printf.sprintf
"bad integer `%s': %s"
3062 | Some angle
-> reqlayout angle
conf.fitmodel
3065 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3068 conf.icase
<- not
conf.icase
;
3069 TEdone
("case insensitive search " ^
(btos conf.icase
))
3072 conf.preload <- not
conf.preload;
3074 TEdone
("preload " ^
(btos conf.preload))
3077 conf.verbose
<- not
conf.verbose
;
3078 TEdone
("verbose " ^
(btos conf.verbose
))
3081 conf.debug
<- not
conf.debug
;
3082 TEdone
("debug " ^
(btos conf.debug
))
3085 conf.maxhfit
<- not
conf.maxhfit
;
3086 state.maxy
<- calcheight ();
3087 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3090 conf.crophack
<- not
conf.crophack
;
3091 TEdone
("crophack " ^
btos conf.crophack
)
3095 match conf.maxwait
with
3097 conf.maxwait
<- Some infinity
;
3098 "always wait for page to complete"
3100 conf.maxwait
<- None
;
3101 "show placeholder if page is not ready"
3106 conf.underinfo
<- not
conf.underinfo
;
3107 TEdone
("underinfo " ^
btos conf.underinfo
)
3110 conf.savebmarks
<- not
conf.savebmarks
;
3111 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3117 match state.layout with
3122 conf.interpagespace
<- int_of_string
s;
3123 docolumns conf.columns
;
3124 state.maxy
<- calcheight ();
3125 let y = getpagey pageno in
3128 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3130 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3134 match conf.fitmodel
with
3135 | FitProportional
-> FitWidth
3136 | _ -> FitProportional
3138 reqlayout conf.angle
fm;
3139 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3142 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3143 TEdone
("trim margins " ^
btos conf.trimmargins
)
3146 conf.invert
<- not
conf.invert
;
3147 TEdone
("invert colors " ^
btos conf.invert
)
3151 cbput state.hists
.sel
s;
3154 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3155 textentry, ondone, true)
3158 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3164 class type lvsource
= object
3165 method getitemcount
: int
3166 method getitem
: int -> (string * int)
3167 method hasaction
: int -> bool
3176 method getactive
: int
3177 method getfirst
: int
3178 method getqsearch
: string
3179 method setqsearch
: string -> unit
3183 class virtual lvsourcebase
= object
3184 val mutable m_active
= 0
3185 val mutable m_first
= 0
3186 val mutable m_qsearch
= ""
3187 val mutable m_pan
= 0
3188 method getactive
= m_active
3189 method getfirst
= m_first
3190 method getqsearch
= m_qsearch
3191 method getpan
= m_pan
3192 method setqsearch
s = m_qsearch
<- s
3195 let withoutlastutf8 s =
3196 let len = String.length
s in
3204 let b = Char.code
s.[pos
] in
3205 if b land 0b11000000 = 0b11000000
3210 if Char.code
s.[len-1] land 0x80 = 0
3214 String.sub
s 0 first;
3217 let textentrykeyboard
3218 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3220 if key >= 0xffb0 && key <= 0xffb9
3221 then key - 0xffb0 + 48 else key
3224 state.mode
<- Textentry
(te
, onleave
);
3227 G.postRedisplay "textentrykeyboard enttext";
3229 let histaction cmd
=
3232 | Some
(action, _) ->
3233 state.mode
<- Textentry
(
3234 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3236 G.postRedisplay "textentry histaction"
3239 | 0xff08 -> (* backspace *)
3240 let s = withoutlastutf8 text in
3241 let len = String.length
s in
3242 if cancelonempty
&& len = 0
3245 G.postRedisplay "textentrykeyboard after cancel";
3248 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3251 | 0xff0d | 0xff8d -> (* (kp) enter *)
3254 G.postRedisplay "textentrykeyboard after confirm"
3256 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3257 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3258 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3259 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3261 | 0xff1b -> (* escape*)
3262 if String.length
text = 0
3264 begin match opthist
with
3266 | Some
(_, onhistcancel
) -> onhistcancel
()
3270 G.postRedisplay "textentrykeyboard after cancel2"
3273 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3276 | 0xff9f | 0xffff -> () (* delete *)
3279 && key land 0xff00 != 0xff00 (* keyboard *)
3280 && key land 0xfe00 != 0xfe00 (* xkb *)
3281 && key land 0xfd00 != 0xfd00 (* 3270 *)
3283 begin match onkey
text key with
3287 G.postRedisplay "textentrykeyboard after confirm2";
3290 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3294 G.postRedisplay "textentrykeyboard after cancel3"
3297 state.mode
<- Textentry
(te
, onleave
);
3298 G.postRedisplay "textentrykeyboard switch";
3302 vlog "unhandled key %s" (Wsi.keyname
key)
3305 let firstof first active
=
3306 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3307 then max
0 (active
- (fstate.maxrows
/2))
3311 let calcfirst first active
=
3314 let rows = active
- first in
3315 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3319 let scrollph y maxy
=
3320 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3321 let sh = float state.winh
/. sh in
3322 let sh = max
sh (float conf.scrollh
) in
3324 let percent = float y /. float maxy
in
3325 let position = (float state.winh
-. sh) *. percent in
3328 if position +. sh > float state.winh
3329 then float state.winh
-. sh
3335 let coe s = (s :> uioh
);;
3337 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3339 val m_pan
= source#getpan
3340 val m_first
= source#getfirst
3341 val m_active
= source#getactive
3342 val m_qsearch
= source#getqsearch
3343 val m_prev_uioh
= state.uioh
3345 method private elemunder
y =
3346 let n = y / (fstate.fontsize
+1) in
3347 if m_first
+ n < source#getitemcount
3349 if source#hasaction
(m_first
+ n)
3350 then Some
(m_first
+ n)
3357 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3358 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3359 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3360 GlDraw.color
(1., 1., 1.);
3361 Gl.enable `texture_2d
;
3362 let fs = fstate.fontsize
in
3364 let ww = fstate.wwidth
in
3365 let tabw = 30.0*.ww in
3366 let itemcount = source#getitemcount
in
3368 if (row - m_first
) > fstate.maxrows
3371 if row >= 0 && row < itemcount
3373 let (s, level
) = source#getitem
row in
3374 let y = (row - m_first
) * nfs in
3375 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3378 Gl.disable `texture_2d
;
3379 GlDraw.polygon_mode `both `line
;
3380 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3381 GlDraw.color
(1., 1., 1.) ~
alpha;
3382 GlDraw.rect (1., float (y + 1))
3383 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3384 GlDraw.polygon_mode `both `fill
;
3385 GlDraw.color
(1., 1., 1.);
3386 Gl.enable `texture_2d
;
3389 let drawtabularstring s =
3390 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3393 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3396 let len = String.length
s - tabpos - 1 in
3397 let s1 = String.sub
s 0 tabpos
3398 and s2
= String.sub
s (tabpos + 1) len in
3399 let nx = drawstr x s1 in
3401 let x = x +. (max
tabw sw) in
3408 let _ = drawtabularstring s in
3415 Gl.disable `texture_2d
;
3417 method updownlevel incr
=
3418 let len = source#getitemcount
in
3420 if m_active
>= 0 && m_active
< len
3421 then snd
(source#getitem m_active
)
3425 if i
= len then i
-1 else if i
= -1 then 0 else
3426 let _, l = source#getitem i
in
3427 if l != curlevel then i
else flow (i
+incr
)
3429 let active = flow m_active
in
3430 let first = calcfirst m_first
active in
3431 G.postRedisplay "outline updownlevel";
3432 {< m_active
= active; m_first
= first >}
3434 method private key1
key mask
=
3435 let set1 active first qsearch
=
3436 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3438 let search active pattern incr
=
3439 let active = if active = -1 then m_first
else active in
3442 if n >= 0 && n < source#getitemcount
3444 let s, _ = source#getitem
n in
3446 (try ignore
(Str.search_forward
re s 0); true
3447 with Not_found
-> false)
3449 else loop (n + incr
)
3456 let re = Str.regexp_case_fold pattern
in
3462 let itemcount = source#getitemcount
in
3463 let find start incr
=
3465 if i
= -1 || i
= itemcount
3468 if source#hasaction i
3470 else find (i
+ incr
)
3475 let set active first =
3476 let first = bound first 0 (itemcount - fstate.maxrows
) in
3478 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3481 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3483 let incr1 = if incr
> 0 then 1 else -1 in
3484 if isvisible m_first m_active
3487 let next = m_active
+ incr
in
3489 if next < 0 || next >= itemcount
3491 else find next incr1
3493 if abs
(m_active
- next) > fstate.maxrows
3499 let first = m_first
+ incr
in
3500 let first = bound first 0 (itemcount - fstate.maxrows
) in
3502 let next = m_active
+ incr
in
3503 let next = bound next 0 (itemcount - 1) in
3510 if isvisible first next
3517 let first = min
next m_first
in
3519 if abs
(next - first) > fstate.maxrows
3525 let first = m_first
+ incr
in
3526 let first = bound first 0 (itemcount - 1) in
3528 let next = m_active
+ incr
in
3529 let next = bound next 0 (itemcount - 1) in
3530 let next = find next incr1 in
3532 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3534 let active = if m_active
= -1 then next else m_active
in
3539 if isvisible first active
3545 G.postRedisplay "listview navigate";
3549 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3550 let incr = if key = 0x72 then -1 else 1 in
3552 match search (m_active
+ incr) m_qsearch
incr with
3554 state.text <- m_qsearch ^
" [not found]";
3557 state.text <- m_qsearch
;
3558 active, firstof m_first
active
3560 G.postRedisplay "listview ctrl-r/s";
3561 set1 active first m_qsearch
;
3563 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3564 if m_active
>= 0 && m_active
< source#getitemcount
3566 let s, _ = source#getitem m_active
in
3571 | 0xff08 -> (* backspace *)
3572 if String.length m_qsearch
= 0
3575 let qsearch = withoutlastutf8 m_qsearch
in
3576 let len = String.length
qsearch in
3580 G.postRedisplay "listview empty qsearch";
3581 set1 m_active m_first
"";
3585 match search m_active
qsearch ~
-1 with
3587 state.text <- qsearch ^
" [not found]";
3590 state.text <- qsearch;
3591 active, firstof m_first
active
3593 G.postRedisplay "listview backspace qsearch";
3594 set1 active first qsearch
3597 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3598 let pattern = m_qsearch ^ toutf8
key in
3600 match search m_active
pattern 1 with
3602 state.text <- pattern ^
" [not found]";
3605 state.text <- pattern;
3606 active, firstof m_first
active
3608 G.postRedisplay "listview qsearch add";
3609 set1 active first pattern;
3611 | 0xff1b -> (* escape *)
3613 if String.length m_qsearch
= 0
3615 G.postRedisplay "list view escape";
3618 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3620 | None
-> m_prev_uioh
3625 G.postRedisplay "list view kill qsearch";
3626 source#setqsearch
"";
3627 coe {< m_qsearch
= "" >}
3630 | 0xff0d | 0xff8d -> (* (kp) enter *)
3632 let self = {< m_qsearch
= "" >} in
3633 source#setqsearch
"";
3635 G.postRedisplay "listview enter";
3636 if m_active
>= 0 && m_active
< source#getitemcount
3638 source#exit
(coe self) false m_active m_first m_pan
"";
3641 source#exit
(coe self) true m_active m_first m_pan
"";
3644 begin match opt with
3645 | None
-> m_prev_uioh
3649 | 0xff9f | 0xffff -> (* (kp) delete *)
3652 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3653 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3654 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3655 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3657 | 0xff53 | 0xff98 -> (* (kp) right *)
3659 G.postRedisplay "listview right";
3660 coe {< m_pan
= m_pan
- 1 >}
3662 | 0xff51 | 0xff96 -> (* (kp) left *)
3664 G.postRedisplay "listview left";
3665 coe {< m_pan
= m_pan
+ 1 >}
3667 | 0xff50 | 0xff95 -> (* (kp) home *)
3668 let active = find 0 1 in
3669 G.postRedisplay "listview home";
3672 | 0xff57 | 0xff9c -> (* (kp) end *)
3673 let first = max
0 (itemcount - fstate.maxrows
) in
3674 let active = find (itemcount - 1) ~
-1 in
3675 G.postRedisplay "listview end";
3678 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3682 dolog
"listview unknown key %#x" key; coe self
3684 method key key mask
=
3685 match state.mode
with
3686 | Textentry te
-> textentrykeyboard key mask te
; coe self
3687 | _ -> self#key1
key mask
3689 method button button down
x y _ =
3692 | 1 when x > state.winw
- conf.scrollbw
->
3693 G.postRedisplay "listview scroll";
3696 let _, position, sh = self#
scrollph in
3697 if y > truncate
position && y < truncate
(position +. sh)
3699 state.mstate
<- Mscrolly
;
3703 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3704 let first = truncate
(s *. float source#getitemcount
) in
3705 let first = min source#getitemcount
first in
3706 Some
(coe {< m_first
= first; m_active
= first >})
3708 state.mstate
<- Mnone
;
3711 | 1 when not down
->
3712 begin match self#elemunder
y with
3714 G.postRedisplay "listview click";
3716 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3720 | n when (n == 4 || n == 5) && not down
->
3721 let len = source#getitemcount
in
3723 if n = 5 && m_first
+ fstate.maxrows
>= len
3727 let first = m_first
+ (if n == 4 then -1 else 1) in
3728 bound first 0 (len - 1)
3730 G.postRedisplay "listview wheel";
3731 Some
(coe {< m_first
= first >})
3732 | n when (n = 6 || n = 7) && not down
->
3733 let inc = m_first
+ (if n = 7 then -1 else 1) in
3734 G.postRedisplay "listview hwheel";
3735 Some
(coe {< m_pan
= m_pan
+ inc >})
3740 | None
-> m_prev_uioh
3744 match state.mstate
with
3746 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3747 let first = truncate
(s *. float source#getitemcount
) in
3748 let first = min source#getitemcount
first in
3749 G.postRedisplay "listview motion";
3750 coe {< m_first
= first; m_active
= first >}
3753 method pmotion
x y =
3754 if x < state.winw
- conf.scrollbw
3757 match self#elemunder
y with
3758 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3759 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3763 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3768 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3772 method infochanged
_ = ()
3774 method scrollpw
= (0, 0.0, 0.0)
3776 let nfs = fstate.fontsize
+ 1 in
3777 let y = m_first
* nfs in
3778 let itemcount = source#getitemcount
in
3779 let maxi = max
0 (itemcount - fstate.maxrows
) in
3780 let maxy = maxi * nfs in
3781 let p, h = scrollph y maxy in
3784 method modehash
= modehash
3785 method eformsgs
= false
3788 class outlinelistview ~source
=
3791 ~source
:(source
:> lvsource
)
3793 ~modehash
:(findkeyhash conf "outline")
3796 method key key mask
=
3797 let calcfirst first active =
3800 let rows = active - first in
3802 if String.length
state.text = 0
3804 else fstate.maxrows - 2
3806 if rows > maxrows then active - maxrows else first
3810 let active = m_active
+ incr in
3811 let active = bound active 0 (source#getitemcount
- 1) in
3812 let first = calcfirst m_first
active in
3813 G.postRedisplay "outline navigate";
3814 coe {< m_active
= active; m_first
= first >}
3816 let ctrl = Wsi.withctrl mask
in
3818 | 110 when ctrl -> (* ctrl-n *)
3819 source#narrow m_qsearch
;
3820 G.postRedisplay "outline ctrl-n";
3821 coe {< m_first
= 0; m_active
= 0 >}
3823 | 117 when ctrl -> (* ctrl-u *)
3825 G.postRedisplay "outline ctrl-u";
3827 coe {< m_first
= 0; m_active
= 0 >}
3829 | 108 when ctrl -> (* ctrl-l *)
3830 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3831 G.postRedisplay "outline ctrl-l";
3832 coe {< m_first
= first >}
3834 | 0xff9f | 0xffff -> (* (kp) delete *)
3835 source#remove m_active
;
3836 G.postRedisplay "outline delete";
3837 let active = max
0 (m_active
-1) in
3838 coe {< m_first
= firstof m_first
active;
3839 m_active
= active >}
3841 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3842 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3843 | 0xff55 | 0xff9a -> (* (kp) prior *)
3844 navigate ~
-(fstate.maxrows)
3845 | 0xff56 | 0xff9b -> (* (kp) next *)
3846 navigate fstate.maxrows
3848 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3852 G.postRedisplay "outline ctrl right";
3853 {< m_pan
= m_pan
+ 1 >}
3855 else self#updownlevel
1
3859 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3863 G.postRedisplay "outline ctrl left";
3864 {< m_pan
= m_pan
- 1 >}
3866 else self#updownlevel ~
-1
3870 | 0xff50 | 0xff95 -> (* (kp) home *)
3871 G.postRedisplay "outline home";
3872 coe {< m_first
= 0; m_active
= 0 >}
3874 | 0xff57 | 0xff9c -> (* (kp) end *)
3875 let active = source#getitemcount
- 1 in
3876 let first = max
0 (active - fstate.maxrows) in
3877 G.postRedisplay "outline end";
3878 coe {< m_active
= active; m_first
= first >}
3880 | _ -> super#
key key mask
3883 let outlinesource usebookmarks
=
3886 inherit lvsourcebase
3887 val mutable m_items
= empty
3888 val mutable m_orig_items
= empty
3889 val mutable m_prev_items
= empty
3890 val mutable m_narrow_pattern
= ""
3891 val mutable m_hadremovals
= false
3893 method getitemcount
=
3894 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3897 if n == Array.length m_items
&& m_hadremovals
3899 ("[Confirm removal]", 0)
3901 let s, n, _ = m_items
.(n) in
3904 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3905 ignore
(uioh
, first, qsearch);
3906 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3908 if String.length m_narrow_pattern
= 0
3914 if not
confrimremoval
3916 let _, _, anchor = m_items
.(active) in
3917 gotoghyll (getanchory anchor);
3921 state.bookmarks
<- Array.to_list m_items
;
3922 m_orig_items
<- m_items
;
3925 else m_items
<- items;
3929 method hasaction
_ = true
3932 if Array.length m_items
!= Array.length m_orig_items
3933 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3936 method narrow
pattern =
3937 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3941 let rec loop accu n =
3944 m_narrow_pattern
<- pattern;
3945 m_items
<- Array.of_list
accu
3948 let (s, _, _) as o = m_items
.(n) in
3950 if (try ignore
(Str.search_forward
re s 0); true
3951 with Not_found
-> false)
3957 loop [] (Array.length m_items
- 1)
3962 then Array.of_list
state.bookmarks
3965 m_items
<- m_orig_items
3970 if m >= 0 && m < Array.length m_items
3972 m_hadremovals
<- true;
3973 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3974 let n = if n >= m then n+1 else n in
3979 method reset
anchor items =
3980 m_hadremovals
<- false;
3981 if m_orig_items
== empty || m_prev_items
!= items
3983 m_orig_items
<- items;
3984 if String.length m_narrow_pattern
= 0
3985 then m_items
<- items;
3987 m_prev_items
<- items;
3988 let rely = getanchory anchor in
3990 let rec loop n best bestd
=
3991 if n = Array.length m_items
3994 let (_, _, anchor) = m_items
.(n) in
3995 let orely = getanchory anchor in
3996 let d = abs
(orely - rely) in
3999 else loop (n+1) best bestd
4004 m_first
<- firstof m_first
active
4008 let enterselector usebookmarks
=
4009 let source = outlinesource usebookmarks
in
4013 then Array.of_list
state.bookmarks
4016 if Array.length
outlines = 0
4018 showtext ' ' errmsg
;
4021 state.text <- source#greetmsg
;
4022 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4023 let anchor = getanchor () in
4024 source#reset
anchor outlines;
4025 state.uioh
<- coe (new outlinelistview ~
source);
4026 G.postRedisplay "enter selector";
4030 let enteroutlinemode =
4031 let f = enterselector false in
4032 fun ()-> f "Document has no outline";
4035 let enterbookmarkmode =
4036 let f = enterselector true in
4037 fun () -> f "Document has no bookmarks (yet)";
4040 let color_of_string s =
4041 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4042 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4046 let color_to_string (r, g, b) =
4047 let r = truncate
(r *. 256.0)
4048 and g = truncate
(g *. 256.0)
4049 and b = truncate
(b *. 256.0) in
4050 Printf.sprintf
"%d/%d/%d" r g b
4053 let irect_of_string s =
4054 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4057 let irect_to_string (x0,y0,x1,y1) =
4058 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4061 let makecheckers () =
4062 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4064 converted by Issac Trotts. July 25, 2002 *)
4065 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4066 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4067 let id = GlTex.gen_texture
() in
4068 GlTex.bind_texture `texture_2d
id;
4069 GlPix.store
(`unpack_alignment
1);
4070 GlTex.image2d
image;
4071 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4072 [ `mag_filter `nearest
; `min_filter `nearest
];
4076 let setcheckers enabled
=
4077 match state.texid
with
4079 if enabled
then state.texid
<- Some
(makecheckers ())
4084 GlTex.delete_texture texid
;
4085 state.texid
<- None
;
4089 let int_of_string_with_suffix s =
4090 let l = String.length
s in
4094 let suffix = Char.lowercase
s.[l-1] in
4096 | 'k'
-> String.sub
s 0 (l-1), 10
4097 | '
m'
-> String.sub
s 0 (l-1), 20
4098 | '
g'
-> String.sub
s 0 (l-1), 30
4102 let n = int_of_string
s1 in
4103 let m = n lsl shift
in
4105 then raise
(Failure
"value too large")
4109 let string_with_suffix_of_int n =
4114 if n land ((1 lsl 30) - 1) = 0
4117 if n land ((1 lsl 20) - 1) = 0
4120 if n land ((1 lsl 10) - 1) = 0
4127 let h = n mod 1000 in
4130 then string_of_int
h ^
s
4132 let s = Printf.sprintf
"_%03d%s" h s in
4139 let defghyllscroll = (40, 8, 32);;
4140 let ghyllscroll_of_string s =
4141 let (n, a, b) as nab
=
4144 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4146 if n <= a || n <= b || a >= b
4147 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4151 let ghyllscroll_to_string ((n, a, b) as nab
) =
4152 if nab
= defghyllscroll
4154 else Printf.sprintf
"%d,%d,%d" n a b;
4157 let describe_location () =
4158 let fn = page_of_y state.y in
4159 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4160 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4164 else (100. *. (float state.y /. float maxy))
4168 Printf.sprintf
"page %d of %d [%.2f%%]"
4169 (fn+1) state.pagecount
percent
4172 "pages %d-%d of %d [%.2f%%]"
4173 (fn+1) (ln+1) state.pagecount
percent
4176 let setpresentationmode v
=
4177 let n = page_of_y state.y in
4178 state.anchor <- (n, 0.0, 1.0);
4179 conf.presentation
<- v
;
4180 if conf.fitmodel
= FitPage
4181 then reqlayout conf.angle
conf.fitmodel
;
4186 let btos b = if b then "\xe2\x88\x9a" else "" in
4187 let showextended = ref false in
4188 let leave mode
= function
4189 | Confirm
-> state.mode
<- mode
4190 | Cancel
-> state.mode
<- mode
in
4193 val mutable m_first_time
= true
4194 val mutable m_l
= []
4195 val mutable m_a
= [||]
4196 val mutable m_prev_uioh
= nouioh
4197 val mutable m_prev_mode
= View
4199 inherit lvsourcebase
4201 method reset prev_mode prev_uioh
=
4202 m_a
<- Array.of_list
(List.rev m_l
);
4204 m_prev_mode
<- prev_mode
;
4205 m_prev_uioh
<- prev_uioh
;
4209 if n >= Array.length m_a
4213 | _, _, _, Action
_ -> m_active
<- n
4217 m_first_time
<- false;
4220 method int name get
set =
4222 (name
, `
int get
, 1, Action
(
4225 try set (int_of_string
s)
4227 state.text <- Printf.sprintf
"bad integer `%s': %s"
4231 let te = name ^
": ", "", None
, intentry, ondone, true in
4232 state.mode
<- Textentry
(te, leave m_prev_mode
);
4236 method int_with_suffix name get
set =
4238 (name
, `intws get
, 1, Action
(
4241 try set (int_of_string_with_suffix s)
4243 state.text <- Printf.sprintf
"bad integer `%s': %s"
4248 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4250 state.mode
<- Textentry
(te, leave m_prev_mode
);
4254 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4256 (name
, `
bool (btos, get
), offset
, Action
(
4263 method color name get
set =
4265 (name
, `color get
, 1, Action
(
4267 let invalid = (nan
, nan
, nan
) in
4270 try color_of_string s
4272 state.text <- Printf.sprintf
"bad color `%s': %s"
4279 let te = name ^
": ", "", None
, textentry, ondone, true in
4280 state.text <- color_to_string (get
());
4281 state.mode
<- Textentry
(te, leave m_prev_mode
);
4285 method string name get
set =
4287 (name
, `
string get
, 1, Action
(
4289 let ondone s = set s in
4290 let te = name ^
": ", "", None
, textentry, ondone, true in
4291 state.mode
<- Textentry
(te, leave m_prev_mode
);
4295 method colorspace name get
set =
4297 (name
, `
string get
, 1, Action
(
4300 let vals = [| "rgb"; "bgr"; "gray" |] in
4302 inherit lvsourcebase
4305 m_active
<- int_of_colorspace conf.colorspace
;
4308 method getitemcount
= Array.length
vals
4309 method getitem
n = (vals.(n), 0)
4310 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4311 ignore
(uioh
, first, pan
, qsearch);
4312 if not cancel
then set active;
4314 method hasaction
_ = true
4318 let modehash = findkeyhash conf "info" in
4319 coe (new listview ~
source ~trusted
:true ~
modehash)
4322 method fitmodel name get
set =
4324 (name
, `
string get
, 1, Action
(
4327 let vals = [| "fit width"; "proportional"; "fit page" |] in
4329 inherit lvsourcebase
4332 m_active
<- int_of_fitmodel conf.fitmodel
;
4335 method getitemcount
= Array.length
vals
4336 method getitem
n = (vals.(n), 0)
4337 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4338 ignore
(uioh
, first, pan
, qsearch);
4339 if not cancel
then set active;
4341 method hasaction
_ = true
4345 let modehash = findkeyhash conf "info" in
4346 coe (new listview ~
source ~trusted
:true ~
modehash)
4349 method caption
s offset
=
4350 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4352 method caption2
s f offset
=
4353 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4355 method getitemcount
= Array.length m_a
4358 let tostr = function
4359 | `
int f -> string_of_int
(f ())
4360 | `intws
f -> string_with_suffix_of_int (f ())
4362 | `color
f -> color_to_string (f ())
4363 | `
bool (btos, f) -> btos (f ())
4366 let name, t
, offset
, _ = m_a
.(n) in
4367 ((let s = tostr t
in
4368 if String.length
s > 0
4369 then Printf.sprintf
"%s\t%s" name s
4373 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4377 m_qsearch
<- qsearch;
4379 match m_a
.(active) with
4380 | _, _, _, Action
f -> f uioh
4392 method hasaction
n =
4394 | _, _, _, Action
_ -> true
4398 let rec fillsrc prevmode prevuioh
=
4399 let sep () = src#caption
"" 0 in
4400 let colorp name get
set =
4402 (fun () -> color_to_string (get
()))
4405 let c = color_of_string v in
4408 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4411 let oldmode = state.mode
in
4412 let birdseye = isbirdseye state.mode
in
4414 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4416 src#
bool "presentation mode"
4417 (fun () -> conf.presentation
)
4418 (fun v -> setpresentationmode v);
4420 src#
bool "ignore case in searches"
4421 (fun () -> conf.icase
)
4422 (fun v -> conf.icase
<- v);
4425 (fun () -> conf.preload)
4426 (fun v -> conf.preload <- v);
4428 src#
bool "highlight links"
4429 (fun () -> conf.hlinks
)
4430 (fun v -> conf.hlinks
<- v);
4432 src#
bool "under info"
4433 (fun () -> conf.underinfo
)
4434 (fun v -> conf.underinfo
<- v);
4436 src#
bool "persistent bookmarks"
4437 (fun () -> conf.savebmarks
)
4438 (fun v -> conf.savebmarks
<- v);
4440 src#fitmodel
"fit model"
4441 (fun () -> fitmodel_to_string conf.fitmodel
)
4442 (fun v -> reqlayout conf.angle
(fitmodel_of_int v));
4444 src#
bool "trim margins"
4445 (fun () -> conf.trimmargins
)
4446 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4448 src#
bool "persistent location"
4449 (fun () -> conf.jumpback
)
4450 (fun v -> conf.jumpback
<- v);
4453 src#
int "inter-page space"
4454 (fun () -> conf.interpagespace
)
4456 conf.interpagespace
<- n;
4457 docolumns conf.columns
;
4459 match state.layout with
4464 state.maxy <- calcheight ();
4465 let y = getpagey pageno in
4470 (fun () -> conf.pagebias
)
4471 (fun v -> conf.pagebias
<- v);
4473 src#
int "scroll step"
4474 (fun () -> conf.scrollstep
)
4475 (fun n -> conf.scrollstep
<- n);
4477 src#
int "horizontal scroll step"
4478 (fun () -> conf.hscrollstep
)
4479 (fun v -> conf.hscrollstep
<- v);
4481 src#
int "auto scroll step"
4483 match state.autoscroll
with
4485 | _ -> conf.autoscrollstep
)
4487 if state.autoscroll
<> None
4488 then state.autoscroll
<- Some
n;
4489 conf.autoscrollstep
<- n);
4492 (fun () -> truncate
(conf.zoom *. 100.))
4493 (fun v -> setzoom ((float v) /. 100.));
4496 (fun () -> conf.angle
)
4497 (fun v -> reqlayout v conf.fitmodel
);
4499 src#
int "scroll bar width"
4500 (fun () -> conf.scrollbw
)
4503 reshape state.winw
state.winh
;
4506 src#
int "scroll handle height"
4507 (fun () -> conf.scrollh
)
4508 (fun v -> conf.scrollh
<- v;);
4510 src#
int "thumbnail width"
4511 (fun () -> conf.thumbw
)
4513 conf.thumbw
<- min
4096 v;
4516 leavebirdseye beye
false;
4521 let mode = state.mode in
4522 src#
string "columns"
4524 match conf.columns
with
4526 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4527 | Csplit
(count
, _) -> "-" ^ string_of_int count
4530 let n, a, b = multicolumns_of_string v in
4531 setcolumns mode n a b);
4534 src#caption
"Pixmap cache" 0;
4535 src#int_with_suffix
"size (advisory)"
4536 (fun () -> conf.memlimit
)
4537 (fun v -> conf.memlimit
<- v);
4540 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4541 (string_with_suffix_of_int state.memused
)
4542 (Hashtbl.length
state.tilemap
)) 1;
4545 src#caption
"Layout" 0;
4546 src#caption2
"Dimension"
4548 Printf.sprintf
"%dx%d (virtual %dx%d)"
4549 state.winw
state.winh
4554 src#caption2
"Position" (fun () ->
4555 Printf.sprintf
"%dx%d" state.x state.y
4558 src#caption2
"Position" (fun () -> describe_location ()) 1
4562 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4563 "Save these parameters as global defaults at exit"
4564 (fun () -> conf.bedefault
)
4565 (fun v -> conf.bedefault
<- v)
4569 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4570 src#
bool ~offset
:0 ~
btos "Extended parameters"
4571 (fun () -> !showextended)
4572 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4576 (fun () -> conf.checkers
)
4577 (fun v -> conf.checkers
<- v; setcheckers v);
4578 src#
bool "update cursor"
4579 (fun () -> conf.updatecurs
)
4580 (fun v -> conf.updatecurs
<- v);
4582 (fun () -> conf.verbose
)
4583 (fun v -> conf.verbose
<- v);
4584 src#
bool "invert colors"
4585 (fun () -> conf.invert
)
4586 (fun v -> conf.invert
<- v);
4588 (fun () -> conf.maxhfit
)
4589 (fun v -> conf.maxhfit
<- v);
4590 src#
bool "redirect stderr"
4591 (fun () -> conf.redirectstderr)
4592 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4593 src#
string "uri launcher"
4594 (fun () -> conf.urilauncher
)
4595 (fun v -> conf.urilauncher
<- v);
4596 src#
string "path launcher"
4597 (fun () -> conf.pathlauncher
)
4598 (fun v -> conf.pathlauncher
<- v);
4599 src#
string "tile size"
4600 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4603 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4604 conf.tilew
<- max
64 w;
4605 conf.tileh
<- max
64 h;
4608 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4611 src#
int "texture count"
4612 (fun () -> conf.texcount
)
4615 then conf.texcount
<- v
4616 else showtext '
!'
" Failed to set texture count please retry later"
4618 src#
int "slice height"
4619 (fun () -> conf.sliceheight
)
4621 conf.sliceheight
<- v;
4622 wcmd "sliceh %d" conf.sliceheight
;
4624 src#
int "anti-aliasing level"
4625 (fun () -> conf.aalevel
)
4627 conf.aalevel
<- bound v 0 8;
4628 state.anchor <- getanchor ();
4629 opendoc state.path
state.password
;
4631 src#
string "page scroll scaling factor"
4632 (fun () -> string_of_float
conf.pgscale)
4635 let s = float_of_string
v in
4638 state.text <- Printf.sprintf
4639 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4642 src#
int "ui font size"
4643 (fun () -> fstate.fontsize
)
4644 (fun v -> setfontsize (bound v 5 100));
4645 src#
int "hint font size"
4646 (fun () -> conf.hfsize
)
4647 (fun v -> conf.hfsize
<- bound v 5 100);
4648 colorp "background color"
4649 (fun () -> conf.bgcolor
)
4650 (fun v -> conf.bgcolor
<- v);
4651 src#
bool "crop hack"
4652 (fun () -> conf.crophack
)
4653 (fun v -> conf.crophack
<- v);
4654 src#
string "trim fuzz"
4655 (fun () -> irect_to_string conf.trimfuzz
)
4658 conf.trimfuzz
<- irect_of_string v;
4660 then settrim true conf.trimfuzz
;
4662 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4664 src#
string "throttle"
4666 match conf.maxwait
with
4667 | None
-> "show place holder if page is not ready"
4670 then "wait for page to fully render"
4672 "wait " ^ string_of_float
time
4673 ^
" seconds before showing placeholder"
4677 let f = float_of_string
v in
4679 then conf.maxwait
<- None
4680 else conf.maxwait
<- Some
f
4682 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4684 src#
string "ghyll scroll"
4686 match conf.ghyllscroll
with
4688 | Some nab
-> ghyllscroll_to_string nab
4693 if String.length
v = 0
4695 else Some
(ghyllscroll_of_string v)
4697 conf.ghyllscroll
<- gs
4699 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4701 src#
string "selection command"
4702 (fun () -> conf.selcmd
)
4703 (fun v -> conf.selcmd
<- v);
4704 src#
string "synctex command"
4705 (fun () -> conf.stcmd
)
4706 (fun v -> conf.stcmd
<- v);
4707 src#colorspace
"color space"
4708 (fun () -> colorspace_to_string conf.colorspace
)
4710 conf.colorspace
<- colorspace_of_int v;
4717 (fun () -> conf.usepbo
)
4718 (fun v -> conf.usepbo
<- v);
4719 src#
bool "mouse wheel scrolls pages"
4720 (fun () -> conf.wheelbypage
)
4721 (fun v -> conf.wheelbypage
<- v);
4722 src#
bool "open remote links in a new instance"
4723 (fun () -> conf.riani
)
4724 (fun v -> conf.riani
<- v);
4728 src#caption
"Document" 0;
4729 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4730 src#caption2
"Pages"
4731 (fun () -> string_of_int
state.pagecount
) 1;
4732 src#caption2
"Dimensions"
4733 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4737 src#caption
"Trimmed margins" 0;
4738 src#caption2
"Dimensions"
4739 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4743 src#caption
"OpenGL" 0;
4744 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4745 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4748 src#caption
"Location" 0;
4749 if String.length
state.origin
> 0
4750 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4751 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4753 src#reset prevmode prevuioh
;
4757 let prevmode = state.mode
4758 and prevuioh
= state.uioh in
4759 fillsrc prevmode prevuioh
;
4760 let source = (src :> lvsource
) in
4761 let modehash = findkeyhash conf "info" in
4762 state.uioh <- coe (object (self)
4763 inherit listview ~
source ~trusted
:true ~
modehash as super
4764 val mutable m_prevmemused
= 0
4765 method infochanged
= function
4767 if m_prevmemused
!= state.memused
4769 m_prevmemused
<- state.memused
;
4770 G.postRedisplay "memusedchanged";
4772 | Pdim
-> G.postRedisplay "pdimchanged"
4773 | Docinfo
-> fillsrc prevmode prevuioh
4775 method key key mask
=
4776 if not
(Wsi.withctrl mask
)
4779 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4780 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4781 | _ -> super#
key key mask
4782 else super#
key key mask
4784 G.postRedisplay "info";
4790 inherit lvsourcebase
4791 method getitemcount
= Array.length
state.help
4793 let s, l, _ = state.help
.(n) in
4796 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4800 m_qsearch
<- qsearch;
4801 match state.help
.(active) with
4802 | _, _, Action
f -> Some
(f uioh)
4812 method hasaction
n =
4813 match state.help
.(n) with
4814 | _, _, Action
_ -> true
4821 let modehash = findkeyhash conf "help" in
4822 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4823 G.postRedisplay "help";
4828 let re = Str.regexp
"[\r\n]" in
4830 inherit lvsourcebase
4831 val mutable m_items
= [||]
4833 method getitemcount
= 1 + Array.length m_items
4838 else m_items
.(n-1), 0
4840 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4845 then Buffer.clear
state.errmsgs
;
4846 m_qsearch
<- qsearch;
4853 method hasaction
n =
4857 state.newerrmsgs
<- false;
4858 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4859 m_items
<- Array.of_list
l
4867 let source = (msgsource :> lvsource
) in
4868 let modehash = findkeyhash conf "listview" in
4869 state.uioh <- coe (object
4870 inherit listview ~
source ~trusted
:false ~
modehash as super
4873 then msgsource#reset
;
4876 G.postRedisplay "msgs";
4879 let quickbookmark ?title
() =
4880 match state.layout with
4886 let sec = Unix.gettimeofday
() in
4887 let tm = Unix.localtime
sec in
4888 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4892 (tm.Unix.tm_year
+ 1900)
4895 | Some
title -> title
4897 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4900 let setautoscrollspeed step goingdown
=
4901 let incr = max
1 ((abs step
) / 2) in
4902 let incr = if goingdown
then incr else -incr in
4903 let astep = step
+ incr in
4904 state.autoscroll
<- Some
astep;
4907 let gotounder = function
4908 | Ulinkgoto
(pageno, top) ->
4912 gotopage1 pageno top;
4918 | Uremote
(filename
, pageno) ->
4920 if String.length filename
> 0
4922 if Filename.is_relative filename
4924 let dir = Filename.dirname
state.path in
4926 if Filename.is_implicit
dir
4927 then Filename.concat
(Sys.getcwd
()) dir
4930 Filename.concat
dir filename
4935 if Sys.file_exists
path
4939 if String.length
path > 0
4943 let command = Printf.sprintf
"%s '%s'" Sys.argv
.(0) path in
4944 try popen command []
4947 "failed to execute `%s': %s\n" command (exntos exn
);
4950 let anchor = getanchor () in
4951 let ranchor = state.path, state.password
, anchor, state.origin
in
4953 state.anchor <- (pageno, 0.0, 0.0);
4954 state.ranchors
<- ranchor :: state.ranchors
;
4957 else showtext '
!'
("Could not find " ^ filename
)
4959 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4963 match conf.columns
with
4965 | _ -> state.x != 0 || conf.zoom > 1.0
4968 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
4970 let existsinrow pageno (columns
, coverA
, coverB
) p =
4971 let last = ((pageno - coverA
) mod columns
) + columns
in
4972 let rec any = function
4975 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4979 then (if l.pageno = last then false else any rest
)
4987 match state.layout with
4989 let pageno = page_of_y state.y in
4990 gotoghyll (getpagey (pageno+1))
4992 match conf.columns
with
4994 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4996 let y = clamp (pgscale state.winh
) in
4999 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5000 gotoghyll (getpagey pageno)
5001 | Cmulti
((c, _, _) as cl, _) ->
5002 if conf.presentation
5003 && (existsinrow l.pageno cl
5004 (fun l -> l.pageh
> l.pagey + l.pagevh))
5006 let y = clamp (pgscale state.winh
) in
5009 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5010 gotoghyll (getpagey pageno)
5012 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5014 let pagey, pageh
= getpageyh l.pageno in
5015 let pagey = pagey + pageh
* l.pagecol
in
5016 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5017 gotoghyll (pagey + pageh
+ ips)
5021 match state.layout with
5023 let pageno = page_of_y state.y in
5024 gotoghyll (getpagey (pageno-1))
5026 match conf.columns
with
5028 if conf.presentation
&& l.pagey != 0
5030 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5032 let pageno = max
0 (l.pageno-1) in
5033 gotoghyll (getpagey pageno)
5034 | Cmulti
((c, _, coverB
) as cl, _) ->
5035 if conf.presentation
&&
5036 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5038 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5041 if l.pageno = state.pagecount
- coverB
5045 let pageno = max
0 (l.pageno-decr) in
5046 gotoghyll (getpagey pageno)
5054 let pageno = max
0 (l.pageno-1) in
5055 let pagey, pageh
= getpageyh pageno in
5058 let pagey, pageh
= getpageyh l.pageno in
5059 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5064 let viewkeyboard key mask
=
5066 let mode = state.mode in
5067 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5070 G.postRedisplay "view:enttext"
5072 let ctrl = Wsi.withctrl mask
in
5074 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5080 | 0xff63 -> (* insert *)
5081 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5083 state.mode <- LinkNav
(Ltgendir
0);
5086 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5088 | 0xff1b | 113 -> (* escape / q *)
5089 begin match state.mstate
with
5091 state.mstate
<- Mnone
;
5092 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5093 G.postRedisplay "kill zoom rect";
5095 begin match state.mode with
5098 G.postRedisplay "esc leave linknav"
5100 match state.ranchors
with
5102 | (path, password
, anchor, origin
) :: rest
->
5103 state.ranchors
<- rest
;
5104 state.anchor <- anchor;
5105 state.origin
<- origin
;
5106 opendoc path password
5110 | 0xff08 -> (* backspace *)
5111 gotoghyll (getnav ~
-1)
5119 G.postRedisplay "dehighlight";
5121 | 47 | 63 -> (* / ? *)
5122 let ondone isforw
s =
5123 cbput state.hists
.pat
s;
5124 state.searchpattern
<- s;
5127 let s = String.create
1 in
5128 s.[0] <- Char.chr
key;
5129 enttext (s, "", Some
(onhist state.hists
.pat
),
5130 textentry, ondone (key = 47), true)
5132 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5133 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5134 setzoom (conf.zoom +. incr)
5136 | 43 | 0xffab -> (* + *)
5139 try int_of_string
s with exc
->
5140 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5146 state.text <- "page bias is now " ^ string_of_int
n;
5149 enttext ("page bias: ", "", None
, intentry, ondone, true)
5151 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5152 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5153 setzoom (max
0.01 (conf.zoom -. decr))
5155 | 45 | 0xffad -> (* - *)
5156 let ondone msg
= state.text <- msg
in
5158 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
5159 optentry state.mode, ondone, true
5162 | 48 when ctrl -> (* ctrl-0 *)
5170 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5172 match conf.columns
with
5173 | Csingle
_ | Cmulti
_ -> 1
5174 | Csplit
(n, _) -> n
5176 let h = state.winh
-
5177 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5179 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5180 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5183 | 51 when ctrl -> (* ctrl-3 *)
5185 match conf.fitmodel
with
5186 | FitWidth
-> FitProportional
5187 | FitProportional
-> FitPage
5188 | FitPage
-> FitWidth
5190 state.text <- "fit model: " ^
fitmodel_to_string fm;
5191 reqlayout conf.angle
fm
5193 | 0xffc6 -> (* f9 *)
5196 | 57 when ctrl -> (* ctrl-9 *)
5199 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5200 when not
ctrl -> (* 0..9 *)
5203 try int_of_string
s with exc
->
5204 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5210 cbput state.hists
.pag
(string_of_int
n);
5211 gotopage1 (n + conf.pagebias
- 1) 0;
5214 let pageentry text key =
5215 match Char.unsafe_chr
key with
5216 | '
g'
-> TEdone
text
5217 | _ -> intentry text key
5219 let text = "x" in text.[0] <- Char.chr
key;
5220 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5223 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5224 reshape state.winw
state.winh
;
5227 conf.hlinks
<- not
conf.hlinks
;
5228 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5229 G.postRedisplay "toggle highlightlinks";
5232 state.glinks
<- true;
5233 let mode = state.mode in
5234 state.mode <- Textentry
(
5235 (":", "", None
, linknentry, linkndone gotounder, false),
5237 state.glinks
<- false;
5241 G.postRedisplay "view:linkent(F)"
5244 state.glinks
<- true;
5245 let mode = state.mode in
5246 state.mode <- Textentry
(
5248 ":", "", None
, linknentry, linkndone (fun under ->
5249 selstring (undertext under);
5253 state.glinks
<- false;
5257 G.postRedisplay "view:linkent"
5260 begin match state.autoscroll
with
5262 conf.autoscrollstep
<- step
;
5263 state.autoscroll
<- None
5265 if conf.autoscrollstep
= 0
5266 then state.autoscroll
<- Some
1
5267 else state.autoscroll
<- Some
conf.autoscrollstep
5270 | 112 when ctrl -> (* ctrl-p *)
5274 setpresentationmode (not
conf.presentation
);
5275 showtext ' '
("presentation mode " ^
5276 if conf.presentation
then "on" else "off");
5279 if List.mem
Wsi.Fullscreen
state.winstate
5280 then Wsi.reshape conf.cwinw
conf.cwinh
5281 else Wsi.fullscreen
()
5283 | 112 | 78 -> (* p|N *)
5284 search state.searchpattern
false
5286 | 110 | 0xffc0 -> (* n|F3 *)
5287 search state.searchpattern
true
5290 begin match state.layout with
5293 gotoghyll (getpagey l.pageno)
5299 | 0xff9f | 0xffff -> (* delete *)
5303 showtext ' '
(describe_location ());
5306 begin match state.layout with
5309 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5314 enterbookmarkmode ()
5316 | 104 | 0xffbe -> (* h|F1 *)
5322 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5327 match state.layout with
5329 if String.length
s > 0
5331 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5334 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5338 showtext ' '
"Quick bookmark added";
5341 begin match state.layout with
5343 let rect = getpdimrect
l.pagedimno
in
5347 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5348 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5350 (truncate
(rect.(1) -. rect.(0)),
5351 truncate
(rect.(3) -. rect.(0)))
5353 let w = truncate
((float w)*.conf.zoom)
5354 and h = truncate
((float h)*.conf.zoom) in
5357 state.anchor <- getanchor ();
5358 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5360 G.postRedisplay "z";
5365 | 60 | 62 -> (* < > *)
5366 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5368 | 91 | 93 -> (* [ ] *)
5370 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5372 G.postRedisplay "brightness";
5374 | 99 when state.mode = View
-> (* [alt]-c *)
5379 let m = (wadjsb state.winw
- state.w) / 2 in
5381 gotoy_and_clear_text state.y
5385 match state.prevcolumns
with
5386 | None
-> (1, 0, 0), 1.0
5387 | Some
(columns
, z
) ->
5390 | Csplit
(c, _) -> -c, 0, 0
5391 | Cmulti
((c, a, b), _) -> c, a, b
5392 | Csingle
_ -> 1, 0, 0
5396 setcolumns View
c a b;
5399 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5400 setzoom state.prevzoom
5402 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5403 begin match state.autoscroll
with
5405 begin match state.mode with
5406 | Birdseye beye
-> upbirdseye 1 beye
5409 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5411 if not
(Wsi.withshift mask
) && conf.presentation
5413 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5417 setautoscrollspeed n false
5420 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5421 begin match state.autoscroll
with
5423 begin match state.mode with
5424 | Birdseye beye
-> downbirdseye 1 beye
5427 then gotoy_and_clear_text (clamp (state.winh
/2))
5429 if not
(Wsi.withshift mask
) && conf.presentation
5431 else gotoy_and_clear_text (clamp conf.scrollstep
)
5435 setautoscrollspeed n true
5438 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5439 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5445 else conf.hscrollstep
5447 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5448 state.x <- panbound (state.x + dx);
5449 gotoy_and_clear_text state.y
5452 G.postRedisplay "left/right"
5455 | 0xff55 | 0xff9a -> (* (kp) prior *)
5459 match state.layout with
5461 | l :: _ -> state.y - l.pagey
5463 clamp (pgscale (-state.winh
))
5467 | 0xff56 | 0xff9b -> (* (kp) next *)
5471 match List.rev
state.layout with
5473 | l :: _ -> getpagey l.pageno
5475 clamp (pgscale state.winh
)
5479 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5481 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5482 gotoghyll (clamp state.maxy)
5485 when Wsi.withalt mask
-> (* alt-(kp) right *)
5486 gotoghyll (getnav 1)
5488 when Wsi.withalt mask
-> (* alt-(kp) left *)
5489 gotoghyll (getnav ~
-1)
5494 | 118 when conf.debug
-> (* v *)
5497 match getopaque l.pageno with
5500 let x0, y0, x1, y1 = pagebbox opaque
in
5501 let a,b = float x0, float y0 in
5502 let c,d = float x1, float y0 in
5503 let e,f = float x1, float y1 in
5504 let h,j
= float x0, float y1 in
5505 let rect = (a,b,c,d,e,f,h,j
) in
5507 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5509 G.postRedisplay "v";
5512 vlog "huh? %s" (Wsi.keyname
key)
5515 let linknavkeyboard key mask
linknav =
5516 let getpage pageno =
5517 let rec loop = function
5519 | l :: _ when l.pageno = pageno -> Some
l
5520 | _ :: rest
-> loop rest
5521 in loop state.layout
5523 let doexact (pageno, n) =
5524 match getopaque pageno, getpage pageno with
5525 | Some opaque
, Some
l ->
5526 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5528 let under = getlink opaque
n in
5529 G.postRedisplay "link gotounder";
5535 | 0xff50 -> (* home *)
5536 Some
(findlink opaque LDfirst
), -1
5538 | 0xff57 -> (* end *)
5539 Some
(findlink opaque LDlast
), 1
5541 | 0xff51 -> (* left *)
5542 Some
(findlink opaque
(LDleft
n)), -1
5544 | 0xff53 -> (* right *)
5545 Some
(findlink opaque
(LDright
n)), 1
5547 | 0xff52 -> (* up *)
5548 Some
(findlink opaque
(LDup
n)), -1
5550 | 0xff54 -> (* down *)
5551 Some
(findlink opaque
(LDdown
n)), 1
5556 begin match findpwl
l.pageno dir with
5560 state.mode <- LinkNav
(Ltgendir
dir);
5561 let y, h = getpageyh pageno in
5564 then y + h - state.winh
5569 begin match getopaque pageno, getpage pageno with
5570 | Some opaque
, Some
_ ->
5572 let ld = if dir > 0 then LDfirst
else LDlast
in
5575 begin match link with
5577 showlinktype (getlink opaque
m);
5578 state.mode <- LinkNav
(Ltexact
(pageno, m));
5579 G.postRedisplay "linknav jpage";
5586 begin match opt with
5587 | Some Lnotfound
-> pwl l dir;
5588 | Some
(Lfound
m) ->
5592 let _, y0, _, y1 = getlinkrect opaque
m in
5594 then gotopage1 l.pageno y0
5596 let d = fstate.fontsize
+ 1 in
5597 if y1 - l.pagey > l.pagevh - d
5598 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5599 else G.postRedisplay "linknav";
5601 showlinktype (getlink opaque
m);
5602 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5605 | None
-> viewkeyboard key mask
5607 | _ -> viewkeyboard key mask
5612 G.postRedisplay "leave linknav"
5616 | Ltgendir
_ -> viewkeyboard key mask
5617 | Ltexact exact
-> doexact exact
5620 let keyboard key mask
=
5621 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5622 then wcmd "interrupt"
5623 else state.uioh <- state.uioh#
key key mask
5626 let birdseyekeyboard key mask
5627 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5629 match conf.columns
with
5631 | Cmulti
((c, _, _), _) -> c
5632 | Csplit
_ -> failwith
"bird's eye split mode"
5634 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5636 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5637 let y, h = getpageyh pageno in
5638 let top = (state.winh
- h) / 2 in
5639 gotoy (max
0 (y - top))
5640 | 0xff0d (* enter *)
5641 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5642 | 0xff1b -> leavebirdseye beye
true (* escape *)
5643 | 0xff52 -> upbirdseye incr beye
(* up *)
5644 | 0xff54 -> downbirdseye incr beye
(* down *)
5645 | 0xff51 -> upbirdseye 1 beye
(* left *)
5646 | 0xff53 -> downbirdseye 1 beye
(* right *)
5648 | 0xff55 -> (* prior *)
5649 begin match state.layout with
5653 state.mode <- Birdseye
(
5654 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5656 gotopage1 l.pageno 0;
5659 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5661 | [] -> gotoy (clamp (-state.winh
))
5663 state.mode <- Birdseye
(
5664 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5666 gotopage1 l.pageno 0
5669 | [] -> gotoy (clamp (-state.winh
))
5672 | 0xff56 -> (* next *)
5673 begin match List.rev
state.layout with
5675 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5676 begin match layout with
5678 let incr = l.pageh
- l.pagevh in
5683 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5685 G.postRedisplay "birdseye pagedown";
5687 else gotoy (clamp (incr + conf.interpagespace
*2));
5691 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5692 gotopage1 l.pageno 0;
5695 | [] -> gotoy (clamp state.winh
)
5698 | 0xff50 -> (* home *)
5699 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5702 | 0xff57 -> (* end *)
5703 let pageno = state.pagecount
- 1 in
5704 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5705 if not
(pagevisible state.layout pageno)
5708 match List.rev
state.pdims
with
5710 | (_, _, h, _) :: _ -> h
5712 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5713 else G.postRedisplay "birdseye end";
5714 | _ -> viewkeyboard key mask
5719 match state.mode with
5720 | Textentry
_ -> scalecolor 0.4
5722 | View
-> scalecolor 1.0
5723 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5724 if l.pageno = hooverpageno
5727 if l.pageno = pageno
5735 let postdrawpage l linkindexbase
=
5736 match getopaque l.pageno with
5738 if tileready l l.pagex
l.pagey
5740 let x = l.pagedispx - l.pagex
5741 and y = l.pagedispy - l.pagey in
5743 match conf.columns
with
5744 | Csingle
_ | Cmulti
_ ->
5745 (if conf.hlinks
then 1 else 0)
5747 && not
(isbirdseye state.mode) then 2 else 0)
5751 match state.mode with
5752 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5755 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5760 let scrollindicator () =
5761 let sbw, ph
, sh = state.uioh#
scrollph in
5762 let sbh, pw, sw = state.uioh#scrollpw
in
5764 GlDraw.color (0.64, 0.64, 0.64);
5766 (float (state.winw
- sbw), 0.)
5767 (float state.winw
, float state.winh
)
5770 (0., float (state.winh
- sbh))
5771 (float (wadjsb state.winw
- 1), float state.winh
)
5773 GlDraw.color (0.0, 0.0, 0.0);
5776 (float (state.winw
- sbw), ph
)
5777 (float state.winw
, ph
+. sh)
5780 (pw, float (state.winh
- sbh))
5781 (pw +. sw, float state.winh
)
5786 match state.mstate
with
5787 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5790 | Msel
((x0, y0), (x1, y1)) ->
5791 let rec loop = function
5793 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5794 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5795 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5796 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5798 match getopaque l.pageno with
5800 let x0, y0 = pagetranslatepoint l x0 y0 in
5801 let x1, y1 = pagetranslatepoint l x1 y1 in
5802 seltext opaque
(x0, y0, x1, y1);
5810 let showrects rects
=
5812 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5813 GlDraw.polygon_mode `both `fill
;
5814 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5816 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5818 if l.pageno = pageno
5820 let dx = float (l.pagedispx - l.pagex
) in
5821 let dy = float (l.pagedispy - l.pagey) in
5822 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5823 GlDraw.begins `quads
;
5825 GlDraw.vertex2
(x0+.dx, y0+.dy);
5826 GlDraw.vertex2
(x1+.dx, y1+.dy);
5827 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5828 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5839 GlClear.color (scalecolor2 conf.bgcolor
);
5840 GlClear.clear
[`
color];
5841 List.iter
drawpage state.layout;
5843 match state.mode with
5844 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5845 begin match getopaque pageno with
5847 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5854 | None
-> state.rects
5859 let rec postloop linkindexbase
= function
5861 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5862 postloop linkindexbase rest
5866 postloop 0 state.layout;
5868 begin match state.mstate
with
5869 | Mzoomrect
((x0, y0), (x1, y1)) ->
5871 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5872 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5873 GlDraw.rect (float x0, float y0)
5874 (float x1, float y1);
5883 let zoomrect x y x1 y1 =
5886 and y0 = min
y y1 in
5887 gotoy (state.y + y0);
5888 state.anchor <- getanchor ();
5889 let zoom = (float state.w) /. float (x1 - x0) in
5891 match conf.fitmodel
, conf.columns
with
5892 | FitPage
, Csplit
_ ->
5893 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5896 let adjw = wadjsb state.winw
in
5898 then (adjw - state.w) / 2
5901 state.x <- (state.x + margin) - x0;
5903 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5904 state.mstate
<- Mnone
;
5908 let winw = wadjsb state.winw - 1 in
5909 let s = float x /. float winw in
5910 let destx = truncate
(float (state.w + winw) *. s) in
5911 state.x <- winw - destx;
5912 gotoy_and_clear_text state.y;
5913 state.mstate
<- Mscrollx
;
5917 let s = float y /. float state.winh
in
5918 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5919 gotoy_and_clear_text desty;
5920 state.mstate
<- Mscrolly
;
5923 let viewmouse button down
x y mask
=
5925 | n when (n == 4 || n == 5) && not down
->
5926 if Wsi.withctrl mask
5928 match state.mstate
with
5929 | Mzoom
(oldn
, i
) ->
5937 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5939 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5941 let zoom = conf.zoom -. incr in
5943 state.mstate
<- Mzoom
(n, 0);
5945 state.mstate
<- Mzoom
(n, i
+1);
5947 else state.mstate
<- Mzoom
(n, 0)
5949 | _ -> state.mstate
<- Mzoom
(n, 0)
5952 match state.autoscroll
with
5953 | Some step
-> setautoscrollspeed step
(n=4)
5955 if conf.wheelbypage
|| conf.presentation
5964 then -conf.scrollstep
5965 else conf.scrollstep
5967 let incr = incr * 2 in
5968 let y = clamp incr in
5969 gotoy_and_clear_text y
5972 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5974 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
5975 gotoy_and_clear_text state.y
5977 | 1 when Wsi.withshift mask
->
5978 state.mstate
<- Mnone
;
5981 match unproject x y with
5982 | Some
(pageno, ux
, uy
) ->
5983 let cmd = Printf.sprintf
5985 conf.stcmd
state.path pageno ux uy
5991 | 1 when Wsi.withctrl mask
->
5994 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5995 state.mstate
<- Mpan
(x, y)
5998 state.mstate
<- Mnone
6003 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6005 state.mstate
<- Mzoomrect
(p, p)
6008 match state.mstate
with
6009 | Mzoomrect
((x0, y0), _) ->
6010 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6011 then zoomrect x0 y0 x y
6013 state.mstate
<- Mnone
;
6014 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6015 G.postRedisplay "kill accidental zoom rect";
6018 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6019 state.mstate
<- Mnone
6022 | 1 when x > state.winw - vscrollw () ->
6025 let _, position, sh = state.uioh#
scrollph in
6026 if y > truncate
position && y < truncate
(position +. sh)
6027 then state.mstate
<- Mscrolly
6030 state.mstate
<- Mnone
6032 | 1 when y > state.winh
- hscrollh () ->
6035 let _, position, sw = state.uioh#scrollpw
in
6036 if x > truncate
position && x < truncate
(position +. sw)
6037 then state.mstate
<- Mscrollx
6040 state.mstate
<- Mnone
6043 let dest = if down
then getunder x y else Unone
in
6044 begin match dest with
6048 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6051 | Unone
when down
->
6052 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6053 state.mstate
<- Mpan
(x, y);
6055 | Unone
| Utext
_ ->
6058 if conf.angle
mod 360 = 0
6060 state.mstate
<- Msel
((x, y), (x, y));
6061 G.postRedisplay "mouse select";
6065 match state.mstate
with
6068 | Mzoom
_ | Mscrollx
| Mscrolly
->
6069 state.mstate
<- Mnone
6071 | Mzoomrect
((x0, y0), _) ->
6075 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6076 state.mstate
<- Mnone
6078 | Msel
((x0, y0), (x1, y1)) ->
6079 let rec loop = function
6083 let a0 = l.pagedispy in
6084 let a1 = a0 + l.pagevh in
6085 let b0 = l.pagedispx in
6086 let b1 = b0 + l.pagevw in
6087 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6088 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6092 match getopaque l.pageno with
6095 match Ne.pipe () with
6099 "can not create sel pipe: %s"
6102 let doclose what fd
=
6103 Ne.clo fd
(fun msg
->
6104 dolog
"%s close failed: %s" what msg
)
6107 popen conf.selcmd
[r, 0; w, -1];
6110 G.postRedisplay "copysel";
6112 dolog
"can not execute %S: %s"
6113 conf.selcmd
(exntos exn
);
6121 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6122 state.mstate
<- Mnone
;
6129 let birdseyemouse button down
x y mask
6130 (conf, leftx
, _, hooverpageno
, anchor) =
6133 let rec loop = function
6136 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6137 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6139 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6145 | _ -> viewmouse button down
x y mask
6148 let mouse button down
x y mask
=
6149 state.uioh <- state.uioh#button button down
x y mask
;
6153 state.uioh <- state.uioh#
motion x y
6157 state.uioh <- state.uioh#
pmotion x y;
6163 method key key mask
=
6164 begin match state.mode with
6165 | Textentry
textentry -> textentrykeyboard key mask
textentry
6166 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6167 | View
-> viewkeyboard key mask
6168 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6172 method button button bstate
x y mask
=
6173 begin match state.mode with
6175 | View
-> viewmouse button bstate
x y mask
6176 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6182 begin match state.mode with
6184 | View
| Birdseye
_ | LinkNav
_ ->
6185 match state.mstate
with
6186 | Mzoom
_ | Mnone
-> ()
6191 state.mstate
<- Mpan
(x, y);
6193 then state.x <- panbound (state.x + dx);
6195 gotoy_and_clear_text y
6198 state.mstate
<- Msel
(a, (x, y));
6199 G.postRedisplay "motion select";
6202 let y = min
state.winh
(max
0 y) in
6206 let x = min
state.winw (max
0 x) in
6209 | Mzoomrect
(p0
, _) ->
6210 state.mstate
<- Mzoomrect
(p0
, (x, y));
6211 G.postRedisplay "motion zoomrect";
6215 method pmotion x y =
6216 begin match state.mode with
6217 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6218 let rec loop = function
6220 if hooverpageno
!= -1
6222 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6223 G.postRedisplay "pmotion birdseye no hoover";
6226 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6227 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6229 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6230 G.postRedisplay "pmotion birdseye hoover";
6240 match state.mstate
with
6241 | Mnone
-> updateunder x y
6242 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6247 method infochanged
_ = ()
6250 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6253 then 0.0, float state.winh
6254 else scrollph state.y maxy
6259 let winw = wadjsb state.winw in
6260 let fwinw = float winw in
6262 let sw = fwinw /. float state.w in
6263 let sw = fwinw *. sw in
6264 max
sw (float conf.scrollh
)
6267 let maxx = state.w + winw in
6268 let x = winw - state.x in
6269 let percent = float x /. float maxx in
6270 (fwinw -. sw) *. percent
6272 hscrollh (), position, sw
6276 match state.mode with
6277 | LinkNav
_ -> "links"
6278 | Textentry
_ -> "textentry"
6279 | Birdseye
_ -> "birdseye"
6282 findkeyhash conf modename
6284 method eformsgs
= true
6291 let fontpath = ref "";;
6294 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6297 let l = String.length
s in
6298 let b = Buffer.create
l in
6304 try Sys.getenv
"HOME"
6307 ("Can not determine home directory location: " ^ exntos exn
);
6311 let modifier_of_string = function
6312 | "alt" -> Wsi.altmask
6313 | "shift" -> Wsi.shiftmask
6314 | "ctrl" | "control" -> Wsi.ctrlmask
6315 | "meta" -> Wsi.metamask
6320 let r = Str.regexp
"-" in
6322 let elems = Str.full_split
r s in
6325 let m1 = modifier_of_string s in
6327 then (Wsi.namekey
s, m)
6330 | Str.Delim
s when n land 1 = 0 -> g s
6332 | Str.Delim
_ -> (k
, m)
6334 let rec loop n k
m = function
6337 let k, m = f n k m x in
6343 let keys_of_string =
6344 let r = Str.regexp
"[ \t]" in
6346 let elems = Str.split
r s in
6347 List.map
key_of_string elems
6350 let copykeyhashes c =
6351 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6354 let config_of c attrs
=
6358 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6359 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6360 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6361 | "preload" -> { c with preload = bool_of_string
v }
6362 | "page-bias" -> { c with pagebias
= int_of_string
v }
6363 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6364 | "horizontal-scroll-step" ->
6365 { c with hscrollstep
= max
(int_of_string
v) 1 }
6366 | "auto-scroll-step" ->
6367 { c with autoscrollstep
= max
0 (int_of_string
v) }
6368 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6369 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6372 match String.lowercase
v with
6373 | "true" -> Some infinity
6375 | f -> Some
(float_of_string
f)
6377 { c with maxwait
= mw}
6378 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6379 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6380 | "vertical-margin" ->
6381 { c with interpagespace
= max
0 (int_of_string
v) }
6383 let zoom = float_of_string
v /. 100. in
6384 let zoom = max
zoom 0.0 in
6385 { c with zoom = zoom }
6386 | "presentation" -> { c with presentation
= bool_of_string
v }
6387 | "rotation-angle" -> { c with angle
= int_of_string
v }
6388 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6389 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6390 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6391 | "proportional-display" ->
6394 then FitProportional
6397 { c with fitmodel
= fm }
6398 | "fit-model" -> { c with fitmodel
= fitmodel_of_string v }
6399 | "pixmap-cache-size" ->
6400 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6401 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6402 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6403 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6404 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6405 | "background-color" -> { c with bgcolor
= color_of_string v }
6406 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6407 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6408 | "mupdf-store-size" ->
6409 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6410 | "checkers" -> { c with checkers
= bool_of_string
v }
6411 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6412 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6413 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6414 | "uri-launcher" -> { c with urilauncher
= unent v }
6415 | "path-launcher" -> { c with pathlauncher
= unent v }
6416 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6417 | "invert-colors" -> { c with invert
= bool_of_string
v }
6418 | "brightness" -> { c with colorscale
= float_of_string
v }
6419 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6421 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6423 let (n, _, _) as nab
= multicolumns_of_string v in
6425 then { c with columns
= Csplit
(-n, [||]) }
6426 else { c with columns
= Cmulti
(nab
, [||]) }
6427 | "birds-eye-columns" ->
6428 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6429 | "selection-command" -> { c with selcmd
= unent v }
6430 | "synctex-command" -> { c with stcmd
= unent v }
6431 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6432 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6433 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6434 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6435 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6436 | "horizontal-scrollbar-visible" ->
6439 then c.scrollb
lor scrollbhv
6440 else c.scrollb
land (lnot
scrollbhv)
6442 { c with scrollb
= b }
6443 | "vertical-scrollbar-visible" ->
6446 then c.scrollb
lor scrollbvv
6447 else c.scrollb
land (lnot
scrollbvv)
6449 { c with scrollb
= b }
6450 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6453 prerr_endline
("Error processing attribute (`" ^
6454 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6457 let rec fold c = function
6460 let c = apply c k v in
6463 fold { c with keyhashes
= copykeyhashes c } attrs
;
6466 let fromstring f pos
n v d =
6469 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6470 n v pos
(exntos exn
)
6475 let bookmark_of attrs
=
6476 let rec fold title page
rely visy
= function
6477 | ("title", v) :: rest
-> fold v page
rely visy rest
6478 | ("page", v) :: rest
-> fold title v rely visy rest
6479 | ("rely", v) :: rest
-> fold title page
v visy rest
6480 | ("visy", v) :: rest
-> fold title page
rely v rest
6481 | _ :: rest
-> fold title page
rely visy rest
6482 | [] -> title, page
, rely, visy
6484 fold "invalid" "0" "0" "0" attrs
6488 let rec fold path page
rely pan visy
= function
6489 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6490 | ("page", v) :: rest
-> fold path v rely pan visy rest
6491 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6492 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6493 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6494 | _ :: rest
-> fold path page
rely pan visy rest
6495 | [] -> path, page
, rely, pan
, visy
6497 fold "" "0" "0" "0" "0" attrs
6501 let rec fold rs ls
= function
6502 | ("out", v) :: rest
-> fold v ls rest
6503 | ("in", v) :: rest
-> fold rs
v rest
6504 | _ :: rest
-> fold ls rs rest
6510 let setconf dst
src =
6511 dst
.scrollbw
<- src.scrollbw
;
6512 dst
.scrollh
<- src.scrollh
;
6513 dst
.icase
<- src.icase
;
6514 dst
.preload <- src.preload;
6515 dst
.pagebias
<- src.pagebias
;
6516 dst
.verbose
<- src.verbose
;
6517 dst
.scrollstep
<- src.scrollstep
;
6518 dst
.maxhfit
<- src.maxhfit
;
6519 dst
.crophack
<- src.crophack
;
6520 dst
.autoscrollstep
<- src.autoscrollstep
;
6521 dst
.maxwait
<- src.maxwait
;
6522 dst
.hlinks
<- src.hlinks
;
6523 dst
.underinfo
<- src.underinfo
;
6524 dst
.interpagespace
<- src.interpagespace
;
6525 dst
.zoom <- src.zoom;
6526 dst
.presentation
<- src.presentation
;
6527 dst
.angle
<- src.angle
;
6528 dst
.cwinw
<- src.cwinw
;
6529 dst
.cwinh
<- src.cwinh
;
6530 dst
.savebmarks
<- src.savebmarks
;
6531 dst
.memlimit
<- src.memlimit
;
6532 dst
.fitmodel
<- src.fitmodel
;
6533 dst
.texcount
<- src.texcount
;
6534 dst
.sliceheight
<- src.sliceheight
;
6535 dst
.thumbw
<- src.thumbw
;
6536 dst
.jumpback
<- src.jumpback
;
6537 dst
.bgcolor
<- src.bgcolor
;
6538 dst
.tilew
<- src.tilew
;
6539 dst
.tileh
<- src.tileh
;
6540 dst
.mustoresize
<- src.mustoresize
;
6541 dst
.checkers
<- src.checkers
;
6542 dst
.aalevel
<- src.aalevel
;
6543 dst
.trimmargins
<- src.trimmargins
;
6544 dst
.trimfuzz
<- src.trimfuzz
;
6545 dst
.urilauncher
<- src.urilauncher
;
6546 dst
.colorspace
<- src.colorspace
;
6547 dst
.invert
<- src.invert
;
6548 dst
.colorscale
<- src.colorscale
;
6549 dst
.redirectstderr <- src.redirectstderr;
6550 dst
.ghyllscroll
<- src.ghyllscroll
;
6551 dst
.columns
<- src.columns
;
6552 dst
.beyecolumns
<- src.beyecolumns
;
6553 dst
.selcmd
<- src.selcmd
;
6554 dst
.updatecurs
<- src.updatecurs
;
6555 dst
.pathlauncher
<- src.pathlauncher
;
6556 dst
.keyhashes
<- copykeyhashes src;
6557 dst
.hfsize
<- src.hfsize
;
6558 dst
.hscrollstep
<- src.hscrollstep
;
6559 dst
.pgscale <- src.pgscale;
6560 dst
.usepbo
<- src.usepbo
;
6561 dst
.wheelbypage
<- src.wheelbypage
;
6562 dst
.stcmd
<- src.stcmd
;
6563 dst
.scrollb
<- src.scrollb
;
6564 dst
.riani
<- src.riani
;
6568 let h = Hashtbl.create
10 in
6569 let dc = { defconf with angle
= defconf.angle
} in
6570 let rec toplevel v t spos
_ =
6572 | Vdata
| Vcdata
| Vend
-> v
6573 | Vopen
("llppconfig", _, closed
) ->
6576 else { v with f = llppconfig
}
6578 error
"unexpected subelement at top level" s spos
6579 | Vclose
_ -> error
"unexpected close at top level" s spos
6581 and llppconfig
v t spos
_ =
6583 | Vdata
| Vcdata
-> v
6584 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6585 | Vopen
("defaults", attrs
, closed
) ->
6586 let c = config_of dc attrs
in
6590 else { v with f = defaults
}
6592 | Vopen
("ui-font", attrs
, closed
) ->
6593 let rec getsize size
= function
6595 | ("size", v) :: rest
->
6597 fromstring int_of_string spos
"size" v fstate.fontsize
in
6599 | l -> getsize size l
6601 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6604 else { v with f = uifont
(Buffer.create
10) }
6606 | Vopen
("doc", attrs
, closed
) ->
6607 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6608 let path = unent pathent
6609 and pageno = fromstring int_of_string spos
"page" spage
0
6610 and rely = fromstring float_of_string spos
"rely" srely
0.0
6611 and pan
= fromstring int_of_string spos
"pan" span
0
6612 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6613 let c = config_of dc attrs
in
6614 let anchor = (pageno, rely, visy
) in
6616 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6617 else { v with f = doc
path pan
anchor c [] }
6620 error
"unexpected subelement in llppconfig" s spos
6622 | Vclose
"llppconfig" -> { v with f = toplevel }
6623 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6625 and defaults
v t spos
_ =
6627 | Vdata
| Vcdata
-> v
6628 | Vend
-> error
"unexpected end of input in defaults" s spos
6629 | Vopen
("keymap", attrs
, closed
) ->
6631 try List.assoc
"mode" attrs
6632 with Not_found
-> "global" in
6637 let h = findkeyhash dc modename in
6638 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6641 { v with f = pkeymap
ret KeyMap.empty }
6643 | Vopen
(_, _, _) ->
6644 error
"unexpected subelement in defaults" s spos
6646 | Vclose
"defaults" ->
6647 { v with f = llppconfig
}
6649 | Vclose
_ -> error
"unexpected close in defaults" s spos
6651 and uifont
b v t spos
epos =
6654 Buffer.add_substring
b s spos
(epos - spos
);
6656 | Vopen
(_, _, _) ->
6657 error
"unexpected subelement in ui-font" s spos
6658 | Vclose
"ui-font" ->
6659 if String.length
!fontpath = 0
6660 then fontpath := Buffer.contents
b;
6661 { v with f = llppconfig
}
6662 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6663 | Vend
-> error
"unexpected end of input in ui-font" s spos
6665 and doc
path pan
anchor c bookmarks
v t spos
_ =
6667 | Vdata
| Vcdata
-> v
6668 | Vend
-> error
"unexpected end of input in doc" s spos
6669 | Vopen
("bookmarks", _, closed
) ->
6672 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6674 | Vopen
("keymap", attrs
, closed
) ->
6676 try List.assoc
"mode" attrs
6677 with Not_found
-> "global"
6683 let h = findkeyhash c modename in
6684 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6685 doc
path pan
anchor c bookmarks
6687 { v with f = pkeymap
ret KeyMap.empty }
6689 | Vopen
(_, _, _) ->
6690 error
"unexpected subelement in doc" s spos
6693 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6694 { v with f = llppconfig
}
6696 | Vclose
_ -> error
"unexpected close in doc" s spos
6698 and pkeymap
ret keymap
v t spos
_ =
6700 | Vdata
| Vcdata
-> v
6701 | Vend
-> error
"unexpected end of input in keymap" s spos
6702 | Vopen
("map", attrs
, closed
) ->
6703 let r, l = map_of attrs
in
6704 let kss = fromstring keys_of_string spos
"in" r [] in
6705 let lss = fromstring keys_of_string spos
"out" l [] in
6709 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6710 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6713 then { v with f = pkeymap
ret keymap }
6716 { v with f = skip
"map" f }
6719 error
"unexpected subelement in keymap" s spos
6721 | Vclose
"keymap" ->
6722 { v with f = ret keymap }
6724 | Vclose
_ -> error
"unexpected close in keymap" s spos
6726 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6728 | Vdata
| Vcdata
-> v
6729 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6730 | Vopen
("item", attrs
, closed
) ->
6731 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6732 let page = fromstring int_of_string spos
"page" spage
0
6733 and rely = fromstring float_of_string spos
"rely" srely
0.0
6734 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6736 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6739 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6742 { v with f = skip
"item" f }
6745 error
"unexpected subelement in bookmarks" s spos
6747 | Vclose
"bookmarks" ->
6748 { v with f = doc
path pan
anchor c bookmarks }
6750 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6752 and skip tag
f v t spos
_ =
6754 | Vdata
| Vcdata
-> v
6756 error
("unexpected end of input in skipped " ^ tag
) s spos
6757 | Vopen
(tag'
, _, closed
) ->
6761 let f'
() = { v with f = skip tag
f } in
6762 { v with f = skip tag'
f'
}
6766 else error
("unexpected close in skipped " ^ tag
) s spos
6769 parse
{ f = toplevel; accu = () } s;
6775 let len = in_channel_length ic
in
6776 let s = String.create
len in
6777 really_input ic
s 0 len;
6780 | Parse_error
(msg
, s, pos
) ->
6781 let subs = subs s pos
in
6782 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6783 failwith
("parse error: " ^
s)
6786 failwith
("config load error: " ^ exntos exn
)
6792 let dir = Filename.concat
home ".config" in
6793 if Sys.is_directory
dir then dir else home
6796 Filename.concat
dir "llpp.conf"
6799 let confpath = ref defconfpath;;
6802 if Sys.file_exists
!confpath
6805 (try Some
(open_in_bin
!confpath)
6808 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6819 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6828 f (Hashtbl.create
0, defconf)
6833 let pc, pb
, px, pa
=
6836 if String.length
state.origin
= 0
6840 Hashtbl.find h (Filename.basename
key)
6841 with Not_found
-> dc, [], 0, emptyanchor
6845 state.bookmarks <- pb
;
6848 then state.anchor <- pa
;
6849 cbput state.hists
.nav pa
;
6855 let add_attrs bb always
dc c =
6858 then Printf.bprintf bb
"\n %s='%b'" s a
6861 then Printf.bprintf bb
"\n %s='%d'" s a
6864 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6867 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6870 then Printf.bprintf bb
"\n %s='%f'" s a
6874 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6878 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6882 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6886 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6892 | Some
(_N
, _A
, _B
) ->
6893 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6903 else string_of_float
f
6905 Printf.bprintf bb
"\n %s='%s'" s v
6910 | Cmulti
((n, a, b), _) when n > 1 ->
6911 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6912 | Csplit
(n, _) when n > 1 ->
6913 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6919 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6924 Printf.bprintf bb
"\n %s='%s'" s (fitmodel_to_string a)
6928 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
6930 oi
"width" c.cwinw
dc.cwinw
;
6931 oi
"height" c.cwinh
dc.cwinh
;
6932 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6933 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6934 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
6935 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
6936 ob "case-insensitive-search" c.icase
dc.icase
;
6937 ob "preload" c.preload dc.preload;
6938 oi
"page-bias" c.pagebias
dc.pagebias
;
6939 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6940 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6941 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6942 ob "crop-hack" c.crophack
dc.crophack
;
6943 oW
"throttle" c.maxwait
dc.maxwait
;
6944 ob "highlight-links" c.hlinks
dc.hlinks
;
6945 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6946 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6947 oz
"zoom" c.zoom dc.zoom;
6948 ob "presentation" c.presentation
dc.presentation
;
6949 oi
"rotation-angle" c.angle
dc.angle
;
6950 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6951 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
6952 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6953 oi
"tex-count" c.texcount
dc.texcount
;
6954 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6955 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6956 ob "persistent-location" c.jumpback
dc.jumpback
;
6957 oc
"background-color" c.bgcolor
dc.bgcolor
;
6958 oi
"tile-width" c.tilew
dc.tilew
;
6959 oi
"tile-height" c.tileh
dc.tileh
;
6960 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6961 ob "checkers" c.checkers
dc.checkers
;
6962 oi
"aalevel" c.aalevel
dc.aalevel
;
6963 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6964 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6965 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6966 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6967 oC
"color-space" c.colorspace
dc.colorspace
;
6968 ob "invert-colors" c.invert
dc.invert
;
6969 oF
"brightness" c.colorscale
dc.colorscale
;
6970 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6971 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6972 oco
"columns" c.columns
dc.columns
;
6973 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6974 os
"selection-command" c.selcmd
dc.selcmd
;
6975 os
"synctex-command" c.stcmd
dc.stcmd
;
6976 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6977 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6978 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6979 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6980 ob "use-pbo" c.usepbo
dc.usepbo
;
6981 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6982 ob "remote-in-a-new-instance" c.riani
dc.riani
;
6985 let keymapsbuf always
dc c =
6986 let bb = Buffer.create
16 in
6987 let rec loop = function
6989 | (modename, h) :: rest
->
6990 let dh = findkeyhash dc modename in
6991 if always
|| h <> dh
6993 if Hashtbl.length
h > 0
6995 if Buffer.length
bb > 0
6996 then Buffer.add_char
bb '
\n'
;
6997 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6998 Hashtbl.iter
(fun i
o ->
6999 let isdifferent = always
||
7001 let dO = Hashtbl.find dh i
in
7003 with Not_found
-> true
7008 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7009 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7010 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7011 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7012 Buffer.add_string
bb (Wsi.keyname
k);
7015 let rec loop = function
7017 | km
:: [] -> addkm km
7018 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7022 Buffer.add_string
bb "<map in='";
7026 Buffer.add_string
bb "' out='";
7028 Buffer.add_string
bb "'/>\n"
7031 Buffer.add_string
bb "' out='";
7033 Buffer.add_string
bb "'/>\n"
7035 | KMmulti
(ins, kms
) ->
7036 Buffer.add_char
bb ' '
;
7038 Buffer.add_string
bb "' out='";
7040 Buffer.add_string
bb "'/>\n"
7042 Buffer.add_string
bb "</keymap>";
7052 let uifontsize = fstate.fontsize
in
7053 let bb = Buffer.create
32768 in
7054 let relx = float state.x /. float state.winw in
7056 let cx w = truncate
(relx *. float w) in
7058 (fun (w, h, x) ws
->
7060 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7061 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7062 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7064 (state.winw, state.winh
, state.x) state.winstate
7069 let dc = if conf.bedefault
then conf else dc in
7070 Buffer.add_string
bb "<llppconfig>\n";
7072 if String.length
!fontpath > 0
7074 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7080 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7083 Buffer.add_string
bb "<defaults ";
7084 add_attrs bb true dc dc;
7085 let kb = keymapsbuf true dc dc in
7086 if Buffer.length
kb > 0
7088 Buffer.add_string
bb ">\n";
7089 Buffer.add_buffer
bb kb;
7090 Buffer.add_string
bb "\n</defaults>\n";
7092 else Buffer.add_string
bb "/>\n";
7094 let adddoc path pan
anchor c bookmarks =
7095 if bookmarks == [] && c = dc && anchor = emptyanchor
7098 Printf.bprintf
bb "<doc path='%s'"
7099 (enent
path 0 (String.length
path));
7101 if anchor <> emptyanchor
7103 let n, rely, visy
= anchor in
7104 Printf.bprintf
bb " page='%d'" n;
7107 Printf.bprintf
bb " rely='%f'" rely
7109 if abs_float visy
> 1e-6
7111 Printf.bprintf
bb " visy='%f'" visy
7116 then Printf.bprintf
bb " pan='%d'" pan
;
7118 add_attrs bb false dc c;
7119 let kb = keymapsbuf false dc c in
7121 begin match bookmarks with
7123 if Buffer.length
kb > 0
7125 Buffer.add_string
bb ">\n";
7126 Buffer.add_buffer
bb kb;
7127 Buffer.add_string
bb "\n</doc>\n";
7129 else Buffer.add_string
bb "/>\n"
7131 Buffer.add_string
bb ">\n<bookmarks>\n";
7132 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7134 "<item title='%s' page='%d'"
7135 (enent
title 0 (String.length
title))
7140 Printf.bprintf
bb " rely='%f'" rely
7142 if abs_float visy
> 1e-6
7144 Printf.bprintf
bb " visy='%f'" visy
7146 Buffer.add_string
bb "/>\n";
7148 Buffer.add_string
bb "</bookmarks>";
7149 if Buffer.length
kb > 0
7151 Buffer.add_string
bb "\n";
7152 Buffer.add_buffer
bb kb;
7154 Buffer.add_string
bb "\n</doc>\n";
7160 match state.mode with
7161 | Birdseye
(c, pan, _, _, _) ->
7163 match conf.columns
with
7164 | Cmulti
((c, _, _), _) -> Some
c
7168 match c.columns
with
7169 | Cmulti
(c, _) -> Cmulti
(c, [||])
7170 | Csingle
_ -> Csingle
[||]
7171 | Csplit
_ -> failwith
"quit from bird's eye while split"
7173 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7176 let basename = Filename.basename
7177 (if String.length
state.origin
= 0 then state.path else state.origin
)
7179 adddoc basename pan (getanchor ())
7181 let autoscrollstep =
7182 match state.autoscroll
with
7184 | None
-> conf.autoscrollstep
7186 match state.mode with
7187 | Birdseye
(bc
, _, _, _, _) ->
7190 presentation
= bc
.presentation
;
7191 interpagespace
= bc
.interpagespace
;
7192 maxwait
= bc
.maxwait
;
7193 autoscrollstep = autoscrollstep }
7194 | _ -> { conf with autoscrollstep = autoscrollstep }
7196 (if conf.savebmarks
then state.bookmarks else []);
7198 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7200 then adddoc path x anchor c bookmarks
7202 Buffer.add_string
bb "</llppconfig>\n";
7205 if load1 f && Buffer.length
bb > 0
7208 let tmp = !confpath ^
".tmp" in
7209 let oc = open_out_bin
tmp in
7210 Buffer.output_buffer
oc bb;
7212 Unix.rename
tmp !confpath;
7215 ("error while saving configuration: " ^ exntos exn
)
7219 let adderrmsg src msg
=
7220 Buffer.add_string
state.errmsgs msg
;
7221 state.newerrmsgs
<- true;
7225 let adderrfmt src fmt
=
7226 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7230 let cl = splitatspace cmds
in
7232 try Scanf.sscanf
s fmt
f
7234 adderrfmt "remote exec"
7235 "error processing '%S': %s\n" cmds
(exntos exn
)
7238 | "reload" :: [] -> reload ()
7239 | "goto" :: args :: [] ->
7240 scan args "%u %f %f"
7242 let cmd, _ = state.geomcmds
in
7243 if String.length
cmd = 0
7244 then gotopagexy pageno x y
7247 gotopagexy pageno x y;
7250 state.reprf
<- f state.reprf
7252 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7253 | "rect" :: args :: [] ->
7254 scan args "%u %u %f %f %f %f"
7255 (fun pageno color x0 y0 x1 y1 ->
7256 onpagerect pageno (fun w h ->
7257 let _,w1,h1
,_ = getpagedim pageno in
7258 let sw = float w1 /. w
7259 and sh = float h1
/. h in
7263 and y1s
= y1 *. sh in
7264 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7266 state.rects <- (pageno, color, rect) :: state.rects;
7267 G.postRedisplay "rect";
7270 | "activatewin" :: [] -> Wsi.activatewin
()
7271 | "quit" :: [] -> raise Quit
7273 adderrfmt "remote command"
7274 "error processing remote command: %S\n" cmds
;
7278 let scratch = String.create
80 in
7279 let buf = Buffer.create
80 in
7282 try Some
(Unix.read fd
scratch 0 80)
7284 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7285 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7288 match tempfr () with
7294 if Buffer.length
buf > 0
7296 let s = Buffer.contents
buf in
7306 let pos = String.index_from
scratch ppos '
\n'
in
7307 if pos >= n then -1 else pos
7308 with Not_found
-> -1
7312 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7313 let s = Buffer.contents
buf in
7319 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7325 let remoteopen path =
7326 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7328 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7333 let trimcachepath = ref "" in
7334 let rcmdpath = ref "" in
7337 [("-p", Arg.String
(fun s -> state.password
<- s),
7338 "<password> Set password");
7340 ("-f", Arg.String
(fun s -> Config.fontpath := s),
7341 "<path> Set path to the user interface font");
7343 ("-c", Arg.String
(fun s -> Config.confpath := s),
7344 "<path> Set path to the configuration file");
7346 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7347 "<path> Set path to the trim cache file");
7349 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7350 "<named-destination> Set named destination");
7352 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7354 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7355 "<path> Set path to the remote commands source");
7357 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7358 "<original-path> Set original path");
7360 ("-v", Arg.Unit
(fun () ->
7362 "%s\nconfiguration path: %s\n"
7366 exit
0), " Print version and exit");
7369 (fun s -> state.path <- s)
7370 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7372 if String.length
state.path = 0
7373 then (prerr_endline
"file name missing"; exit
1);
7375 if not
(Config.load ())
7376 then prerr_endline
"failed to load configuration";
7378 let wsfd, winw, winh
= Wsi.init
(object
7379 val mutable m_hack
= false
7380 method expose
= if not m_hack
then G.postRedisplay "expose"
7381 method visible
= G.postRedisplay "visible"
7382 method display = m_hack
<- false; display ()
7383 method reshape w h =
7384 m_hack
<- w < state.winw && h < state.winh
;
7386 method mouse b d x y m = mouse b d x y m
7387 method motion x y = state.mpos
<- (x, y); motion x y
7388 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7390 let mascm = m land (
7391 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7393 match state.keystate
with
7395 let km = k, mascm in
7398 let modehash = state.uioh#
modehash in
7399 try Hashtbl.find modehash km
7401 try Hashtbl.find (findkeyhash conf "global") km
7402 with Not_found
-> KMinsrt
(k, m)
7404 | KMinsrt
(k, m) -> keyboard k m
7405 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7406 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7408 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7409 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7410 state.keystate
<- KSnone
7411 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7412 state.keystate
<- KSinto
(keys
, insrt
)
7414 state.keystate
<- KSnone
7416 method enter
x y = state.mpos
<- (x, y); pmotion x y
7417 method leave = state.mpos
<- (-1, -1)
7418 method winstate wsl
= state.winstate
<- wsl
7419 method quit
= raise Quit
7420 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7425 List.exists
GlMisc.check_extension
7426 [ "GL_ARB_texture_rectangle"
7427 ; "GL_EXT_texture_recangle"
7428 ; "GL_NV_texture_rectangle" ]
7430 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7433 let r = GlMisc.get_string `renderer
in
7434 let p = "Mesa DRI Intel(" in
7435 let l = String.length
p in
7436 String.length
r > l && String.sub
r 0 l = p
7438 then defconf.sliceheight
<- 1024;
7441 match Ne.pipe () with
7443 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7447 match Ne.pipe () with
7449 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7459 setcheckers conf.checkers
;
7463 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7464 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7465 !Config.fontpath, !trimcachepath,
7466 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7470 state.text <- "Opening " ^
(mbtoutf8
state.path);
7472 opendoc state.path state.password
;
7476 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7479 if String.length
!rcmdpath > 0
7480 then remoteopen !rcmdpath
7485 let rec loop deadline
=
7487 match state.errfd
with
7488 | None
-> [state.sr
; state.wsfd]
7489 | Some fd
-> [state.sr
; state.wsfd; fd
]
7494 | Some fd
-> fd
:: r
7498 state.redisplay
<- false;
7505 if deadline
= infinity
7507 else max
0.0 (deadline
-. now)
7512 try Unix.select
r [] [] timeout
7513 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7519 if state.ghyll
== noghyll
7521 match state.autoscroll
with
7522 | Some step
when step
!= 0 ->
7523 let y = state.y + step
in
7527 else if y >= state.maxy then 0 else y
7530 if state.mode = View
7531 then state.text <- "";
7534 else deadline
+. 0.01
7539 let rec checkfds = function
7541 | fd
:: rest
when fd
= state.sr
->
7542 let cmd = readcmd state.sr
in
7546 | fd
:: rest
when fd
= state.wsfd ->
7550 | fd
:: rest
when Some fd
= !optrfd ->
7551 begin match remote fd
with
7552 | None
-> optrfd := remoteopen !rcmdpath;
7553 | opt -> optrfd := opt
7558 let s = String.create
80 in
7559 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7560 if conf.redirectstderr
7562 Buffer.add_substring
state.errmsgs
s 0 n;
7563 state.newerrmsgs
<- true;
7564 state.redisplay
<- true;
7567 prerr_string
(String.sub
s 0 n);
7575 if deadline
= infinity
7579 match state.autoscroll
with
7580 | Some step
when step
!= 0 -> deadline1
7581 | _ -> if state.ghyll
== noghyll then infinity
else deadline1